/* Demo theme aligned with the reference layout */
:root {
  --primary: #0d4f7c;
  --primary-light: #1e6fa3;
  --primary-hover: #0a3f63;
  --primary-bg: #e8f2fa;
  --primary-rgb: 13, 79, 124;
  --accent: #c9a020;
  --accent-hover: #a6841a;
  --danger: #cb2431;
  --danger-bg: #fff2f2;
  --border: #e5e6eb;
  --border-hover: #c9cdd4;
  --text: #1d2129;
  --text-sub: #4e5969;
  --text-muted: #86909c;
  --bg: #f2f3f5;
  --card: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --header-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

/* Header */
.header {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  padding-top: var(--safe-top);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-brand {
  min-width: 0;
  flex: 1 1 auto;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.header-subtitle {
  margin-top: 1px;
  font-size: 12px;
  opacity: 0.78;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 0 1 auto;
  max-width: 100%;
}

.btn-history {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.95);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-history:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.5);
}

.btn-history:active {
  transform: scale(0.98);
}

.header-badge {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.28);
  padding: 0 10px;
  height: 28px;
  line-height: 26px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  height: 22px;
  min-width: 48px;
  padding: 0 8px;
  border-radius: 2px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn.active {
  background: white;
  color: var(--primary);
  font-weight: 600;
}

/* Main two-column layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 56px;
  padding-bottom: calc(56px + var(--safe-bottom));
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.col-left,
.col-right {
  min-width: 0;
}

@media (min-width: 900px) {
  .row {
    grid-template-columns: 1fr 280px;
    align-items: start;
  }
  .col-right {
    position: sticky;
    top: calc(var(--header-h) + 12px);
  }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

.card-header {
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  min-height: 48px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.card-header-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.card-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.step-num {
  background: var(--primary);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.card-body {
  padding: 16px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-title svg {
  width: 18px;
  height: 18px;
  fill: var(--primary);
}

/* Forms */
.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 500;
}

.form-input,
.form-select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  outline: none;
  background: white;
  transition: border-color 0.1s, box-shadow 0.1s;
}

.form-input:hover,
.form-select:hover {
  border-color: var(--border-hover);
}

.form-input:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.12);
}

/* Tabs + search */
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.category-tab {
  padding: 0 10px;
  height: 26px;
  line-height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-sub);
  font-size: 12px;
  cursor: pointer;
}

.category-tab:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

.category-tab.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: rgba(var(--primary-rgb), 0.2);
  font-weight: 600;
}

.search-container {
  position: relative;
  margin-bottom: 0;
}

.search-container .form-input {
  padding-right: 110px;
}

.search-count {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
}

/* Material list dropdown */
.material-list {
  max-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: white;
  transition: max-height 0.2s ease;
}

.material-list.show {
  max-height: 260px;
  overflow-y: auto;
}

.material-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-bottom: 1px solid #f2f3f5;
  cursor: pointer;
}

.material-item:last-child {
  border-bottom: none;
}

.material-item:hover {
  background: var(--primary-bg);
}

.material-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 500;
}

.material-info {
  min-width: 70px;
  text-align: right;
  color: var(--text-muted);
  font-size: 11px;
}

.material-add {
  font-size: 12px;
  color: var(--primary);
  border: 1px solid rgba(var(--primary-rgb), 0.25);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

.material-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
}

/* tags */
.tag {
  display: inline-block;
  font-size: 11px;
  border-radius: 2px;
  padding: 0 6px;
  line-height: 18px;
  height: 18px;
}

.tag-success {
  background: #e3f2fd;
  color: #0d4f7c;
}

.tag-info {
  background: #f0f0f0;
  color: #666;
}

.tag-warning {
  background: #fff3e0;
  color: #e65100;
}

/* formula hint + summary */
.formula-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-sub);
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.hint-valid,
.total-valid {
  color: var(--primary);
  font-weight: 600;
}

.hint-invalid,
.total-invalid {
  color: var(--danger);
  font-weight: 600;
}

.hint-requirement {
  margin-left: 4px;
  color: var(--text-muted);
}

.summary-bar {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-size: 12px;
  color: var(--text-sub);
}

/* table */
.table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.table th {
  background: #fafafa;
  height: 34px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
  text-align: left;
}

.table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f2f3f5;
  font-size: 13px;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover td {
  background: var(--primary-bg);
}

/* Horizontal scroll for wide tables on narrow screens */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

.table-scroll .table {
  min-width: 320px;
}

/* buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-small {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-danger {
  color: white;
  background: var(--danger);
}

.btn-detail {
  margin-left: 6px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  color: var(--text-sub);
  font-size: 12px;
  cursor: pointer;
}

.btn-detail:hover {
  border-color: var(--border-hover);
}

/* device and process */
.radio-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.radio-item input {
  display: none;
}

.radio-item label {
  display: block;
  text-align: center;
  padding: 9px 8px;
  border-right: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-sub);
  cursor: pointer;
}

.radio-item:last-child label {
  border-right: none;
}

.radio-item input:checked + label {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.params-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* indicator cards */
.indicators-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.indicator-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  text-align: center;
  padding: 10px 8px;
}

.indicator-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.indicator-value {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
}

.indicator-unit {
  font-size: 11px;
  color: var(--text-muted);
}

/* predict + loading */
.predict-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 16px;
}

.predict-btn {
  height: 44px;
  min-height: 44px;
  padding: 0 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.predict-btn-secondary {
  background: var(--accent);
}

.predict-btn:hover {
  background: var(--accent-hover);
}

.predict-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

#predict-hint {
  color: var(--text-muted) !important;
  font-size: 12px !important;
  margin-top: 0 !important;
  flex: 1 1 220px;
  min-width: 0;
  line-height: 1.45;
}

.loading {
  display: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  color: var(--text-sub);
  font-size: 13px;
  text-align: center;
  padding: 10px;
  margin-bottom: 12px;
}

.loading.show {
  display: block;
}

/* result hero cards */
.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.result-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: white;
}

.result-card-grad {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
}

.result-card-content {
  position: relative;
  z-index: 1;
  padding: 18px 18px 22px;
}

.result-card-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
}

.result-card-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.result-card-icon.density-icon {
  background: rgba(var(--primary-rgb), 0.1);
  color: var(--primary);
}

.result-card-icon.soak-icon {
  background: rgba(201, 160, 32, 0.1);
  color: var(--accent);
}

.result-card-label {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
}

.result-value-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.result-value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.result-value.density-val {
  color: var(--primary);
}

.result-value.soak-val {
  color: var(--accent);
}

.result-unit {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 500;
}

.result-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-sub);
}

.result-timestamp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 0 2px;
}

.alert {
  margin-top: 10px;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
}

.alert-warning {
  border: 1px solid #ffd9b5;
  background: #fff7ef;
  color: #a35a12;
}

/* footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 310;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: white;
  padding: 6px 16px calc(6px + var(--safe-bottom));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

/* scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.2s ease; }

@keyframes progress-slide { 0% { left: -45%; width: 45%; } 100% { left: 105%; width: 45%; } }
.predict-btn.predicting { pointer-events: none; position: relative; overflow: hidden; }
.predict-btn.predicting::after {
  content: '';
  position: absolute;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 2px;
  animation: progress-slide 1.1s ease-in-out infinite;
}

/* modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 400;
  justify-content: center;
  align-items: center;
  padding: max(12px, var(--safe-top)) max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal.show {
  display: flex;
}

.modal-content {
  width: min(92vw, 560px);
  max-width: 100%;
  max-height: min(84vh, 100dvh - 2rem);
  overflow-y: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
}

.modal-content-gradient {
  width: min(95vw, 900px);
  max-width: 100%;
}

.modal-content-wide {
  width: min(95vw, 600px);
}

.modal-content-xwide {
  width: min(95vw, 700px);
}

.modal-content-narrow {
  width: min(95vw, 400px);
}

.material-manager-toolbar {
  margin-bottom: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-header {
  height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fafafa;
  padding: 8px;
}

.detail-label {
  font-size: 11px;
  color: var(--text-muted);
}

.detail-value {
  margin-top: 2px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.detail-value.na {
  color: var(--text-muted);
  font-weight: 500;
}

/* add-ingredient button */
.btn-add-ing {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0 14px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-add-ing:hover { background: var(--primary-light); }
.btn-add-ing svg { flex-shrink: 0; }

.formula-empty {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted);
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ingredient transfer modal */
.ing-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: max(8px, var(--safe-top)) max(8px, var(--safe-right)) max(8px, var(--safe-bottom)) max(8px, var(--safe-left));
  box-sizing: border-box;
}
.ing-modal.open { display: flex; }

.ing-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.ing-modal-dialog {
  position: relative;
  z-index: 1;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  width: min(92vw, 860px);
  max-width: 100%;
  height: min(88vh, 620px);
  max-height: min(88dvh, 620px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity:0; transform:scale(0.97) translateY(8px); } to { opacity:1; transform:scale(1) translateY(0); } }

.ing-modal-header {
  background: var(--primary);
  color: white;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.ing-modal-header h3 { font-size: 15px; font-weight: 600; margin: 0; }

.btn-modal-close {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-modal-close:hover { background: rgba(255,255,255,0.3); }

.ing-modal-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.transfer-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.transfer-panel:first-child { border-right: 1px solid var(--border); }

.transfer-panel-header {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  flex-shrink: 0;
}

.transfer-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.transfer-count {
  font-size: 11px;
  font-weight: 500;
  padding: 0 7px;
  height: 18px;
  line-height: 18px;
  border-radius: 9px;
  background: var(--primary-bg);
  color: var(--primary);
}

.transfer-search {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  margin-bottom: 8px;
  transition: border-color 0.1s;
}
.transfer-search:hover { border-color: var(--border-hover); }
.transfer-search:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.1); }

.modal-cat-tabs { display: flex; flex-wrap: wrap; gap: 4px; }

.modal-cat-tab {
  padding: 0 8px;
  height: 24px;
  line-height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-sub);
  transition: all 0.1s;
}
.modal-cat-tab:hover { background: var(--primary-bg); color: var(--primary); }
.modal-cat-tab.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; border-color: rgba(var(--primary-rgb), 0.2); }

.transfer-list { flex: 1; overflow-y: auto; }

.transfer-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #f2f3f5;
  gap: 6px;
  transition: background 0.1s;
}
.transfer-item:last-child { border-bottom: none; }
.transfer-item:hover { background: var(--primary-bg); }
.transfer-item.is-selected { opacity: 0.5; }
.transfer-item .ing-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ing-stat {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
  flex-shrink: 0;
}

.btn-transfer-add {
  background: var(--primary);
  color: white;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}
.btn-transfer-add:hover { background: var(--primary-light); }
.btn-transfer-add:disabled { background: var(--border); cursor: default; }

.selected-empty {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.selected-item {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid #f2f3f5;
  gap: 8px;
  transition: background 0.1s;
}
.selected-item:last-child { border-bottom: none; }
.selected-item:hover { background: #fef9f0; }
.selected-item .ing-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-sel-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: all 0.1s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.btn-sel-remove:hover { background: var(--danger-bg); color: var(--danger); }

.ing-modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
  flex-shrink: 0;
}

.modal-footer-info { font-size: 12px; color: var(--text-muted); }

.btn-modal-confirm {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0 24px;
  height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-modal-confirm:hover { background: var(--primary-light); }

@media (max-width: 600px) {
  .ing-modal-body { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .transfer-panel:first-child { border-right: none; border-bottom: 1px solid var(--border); }
}

/* responsive */
@media (max-width: 900px) {
  .header {
    padding: 0 12px;
  }
  .header-title {
    font-size: 14px;
  }
  .header-subtitle {
    display: none;
  }
  .header-badge {
    display: none;
  }
  .params-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .container {
    padding: 14px 10px calc(50px + var(--safe-bottom));
  }
  .card-header {
    padding: 10px 12px;
    align-items: flex-start;
  }
  .card-header-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }
  .btn-add-ing {
    flex: 1 1 auto;
    min-height: 44px;
    justify-content: center;
  }
  .radio-group {
    grid-template-columns: 1fr;
  }
  .radio-item label {
    border-right: none;
    border-bottom: 1px solid var(--border);
    text-align: left;
    padding: 12px 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .radio-item:last-child label {
    border-bottom: none;
  }
  .params-grid {
    grid-template-columns: 1fr;
  }
  .result-grid {
    grid-template-columns: 1fr;
  }
  .summary-bar {
    flex-direction: column;
    align-items: flex-start;
  }
  .predict-panel {
    flex-direction: column;
    align-items: stretch;
  }
  .predict-panel .predict-btn {
    width: 100%;
  }
  #predict-hint {
    flex: none;
    width: 100%;
    order: 3;
  }
  .search-container .form-input {
    padding-right: 12px;
  }
  .search-count {
    position: static;
    transform: none;
    display: block;
    margin-top: 6px;
    text-align: right;
  }
  .form-input,
  .form-select,
  .transfer-search {
    font-size: 16px;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .modal .modal-body {
    padding: 12px;
  }
  .user-name {
    display: none;
  }
  .header-title {
    white-space: normal;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .history-drawer {
    width: 100%;
    right: -100%;
  }
  .history-drawer.open {
    right: 0;
  }
  .btn-history span {
    display: none;
  }
  .btn-history {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    justify-content: center;
  }
  .login-gate .login-card {
    padding: 32px 22px 28px;
  }
  .login-input {
    font-size: 16px;
  }
  #gradient-chart {
    height: 280px !important;
  }
  .recipe-item {
    flex-wrap: wrap;
  }
  .recipe-item-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 4px;
  }
  .ing-modal-footer {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
  }
  .ing-modal-dialog {
    width: 100%;
    height: min(88dvh, 620px);
    max-height: calc(100dvh - max(16px, var(--safe-top)) - max(16px, var(--safe-bottom)));
  }
  .material-manager-toolbar {
    justify-content: stretch;
  }
  .material-manager-toolbar .btn-add-ing {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
  }
}

/* ===== Recipe History ===== */
.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
}
.recipe-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.recipe-item:hover {
  border-color: var(--primary);
  box-shadow: 0 1px 4px rgba(var(--primary-rgb), 0.1);
}
.recipe-item-body {
  flex: 1;
  min-width: 0;
}
.recipe-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recipe-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.recipe-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
}
.recipe-badge-auto {
  background: var(--primary-bg);
  color: var(--primary);
}
.recipe-badge-manual {
  background: #fff8e6;
  color: #b8860b;
}
.recipe-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.btn-recipe-load {
  padding: 4px 10px;
  font-size: 11px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  transition: all .15s;
}
.btn-recipe-load:hover {
  background: var(--primary);
  color: #fff;
}
.btn-recipe-del {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.btn-recipe-del:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.recipe-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.btn-save-recipe {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}
.btn-save-recipe:hover {
  background: var(--primary);
  color: #fff;
}
.btn-save-recipe:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ===== Login（布局对齐 pelleting.caasifr.cn，配色沿用 :root） ===== */
.login-gate {
  --login-btn-h: 48px;
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(165deg, #dbe8f5 0%, #f2f4f8 45%, #e8f2fa 100%);
}

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px 32px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 32px 24px 28px;
  text-align: center;
  box-sizing: border-box;
}

.login-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 26px;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.28);
}

.login-logo svg {
  width: 30px;
  height: 30px;
  opacity: 0.98;
}

.login-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
  line-height: 1.35;
  margin: 0;
}

.login-sub,
.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 8px 0 0;
  font-weight: 400;
  line-height: 1.45;
}

.login-en-line {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-form {
  text-align: left;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.login-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
  background: #fafbfc;
  box-sizing: border-box;
}

.login-input:hover {
  border-color: var(--border-hover);
  background: #fff;
}

.login-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
  background: #fff;
}

.login-input::placeholder {
  color: var(--text-muted);
}

.login-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 18px;
  margin-bottom: 4px;
  text-align: center;
}

.btn-login-submit {
  width: 100%;
  height: var(--login-btn-h);
  min-height: var(--login-btn-h);
  max-height: var(--login-btn-h);
  margin-top: 4px;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.12em;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 10px rgba(var(--primary-rgb), 0.28);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  vertical-align: middle;
}

.btn-login-submit:hover {
  background: var(--primary-light);
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.32);
}

.btn-login-submit:active {
  transform: translateY(0.5px);
}

.btn-login-submit::-moz-focus-inner,
.login-sec-card::-moz-focus-inner {
  border: 0;
  padding: 0;
}

.login-secondary-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  margin-top: 12px;
  height: var(--login-btn-h);
  box-sizing: border-box;
  align-items: stretch;
}

.login-sec-card {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  margin: 0;
  line-height: 1;
  box-sizing: border-box;
  border-radius: 12px;
  background: #f5f6f8;
  border: 1px solid #e3e5e8;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  -webkit-appearance: none;
  appearance: none;
  color: var(--text-sub);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
}

.login-sec-card:hover {
  background: #eef1f4;
  border-color: #d4d8de;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.login-sec-card:active {
  transform: translateY(0.5px);
}

.login-sec-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  line-height: 0;
  overflow: hidden;
}

.login-sec-icon svg {
  display: block;
  width: 22px;
  height: 22px;
  overflow: hidden;
}

.login-sec-icon svg circle,
.login-sec-icon svg path {
  fill: none;
  stroke: var(--primary);
  vector-effect: non-scaling-stroke;
}

.login-sec-icon svg circle {
  stroke-width: 1.5;
}

.login-sec-icon svg path {
  stroke-width: 1.5;
}

.login-sec-icon svg path.doc-lines {
  stroke-width: 1.25;
}

.login-sec-card span:not(.login-sec-icon) {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  color: var(--text-sub);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login-sec-card:hover span:not(.login-sec-icon) {
  color: var(--text);
}

.login-foot {
  padding: 14px 20px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.5);
  line-height: 1.45;
  flex-shrink: 0;
  padding-bottom: calc(14px + var(--safe-bottom));
}

/* 试用申请：居中弹层，背景与登录门一致 */
.login-overlay-trial {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  background: linear-gradient(165deg, #dbe8f5 0%, #f2f4f8 45%, #e8f2fa 100%);
}

.login-card-trial {
  max-height: min(90dvh, 640px);
  overflow-y: auto;
  text-align: center;
}

.login-card-trial .login-form {
  text-align: left;
}

.login-footer-trial {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.45;
}

/* ===== User Info in Header ===== */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 4px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  white-space: nowrap;
}

.btn-logout {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: rgba(255, 255, 255, 0.85);
  padding: 0 10px;
  height: 26px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.3);
  color: white;
}

.recipe-badge-guest {
  background: #e3f2fd;
  color: var(--primary);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
  font-weight: 500;
}

/* ===== History Drawer ===== */
.history-drawer {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  bottom: calc(40px + var(--safe-bottom));
  right: -360px; /* Hidden by default */
  width: 360px;
  max-width: 100vw;
  height: auto;
  background: white;
  z-index: 195; /* Below header (200), above content */
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.history-drawer.open {
  right: 0;
}

.history-drawer-header {
  height: 60px;
  padding: 0 20px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.drawer-title {
  font-size: 16px;
  font-weight: 600;
}

.drawer-close {
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.drawer-close:hover {
  opacity: 1;
}

.history-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  flex-shrink: 0;
}

.history-tab {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  font-size: 13px;
  color: var(--text-sub);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.history-tab:hover {
  color: var(--primary);
  background: rgba(var(--primary-rgb), 0.05);
}

.history-tab.active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
  background: white;
}

.history-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #fcfcfc;
}

.history-pane {
  display: none;
}

.history-pane.active {
  display: block;
}

.history-content .recipe-list {
  max-height: none;
  overflow-y: visible;
}

.history-section-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
  padding-left: 4px;
}
.save-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}
.save-modal-overlay.open {
  display: flex;
}
.save-modal-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 24px;
  width: 360px;
  max-width: 90vw;
}
.save-modal-box h3 {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--text);
}
.save-modal-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}
.save-modal-box input:focus {
  border-color: var(--primary);
}
.save-modal-btns {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.save-modal-btns button {
  padding: 6px 18px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
.save-modal-btns .btn-confirm {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.save-modal-btns .btn-confirm:hover {
  background: var(--primary-hover);
}
