:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e2ef;
  --primary: #1f5eff;
  --primary-dark: #1644ba;
  --danger: #d92d20;
  --warning: #dc6803;
  --success: #039855;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background: linear-gradient(180deg, #edf3ff 0%, var(--bg) 30%, #f8fafc 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 28px 32px 18px;
  border-bottom: 1px solid rgba(217, 226, 239, 0.8);
}

.eyebrow {
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.app-header p {
  margin: 8px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 6px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 450px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 28px 36px;
}

.side-panel,
.main-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel,
.metric-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(217, 226, 239, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title-row h2 {
  margin-bottom: 4px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two {
  grid-template-columns: 1fr 1fr;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  border: 1px solid #cfd8e6;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 94, 255, 0.12);
}

.primary-btn,
.secondary-btn,
.small-btn,
.ghost-link {
  border-radius: 10px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 14px;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn,
.small-btn,
.ghost-link {
  background: #eef4ff;
  color: #1d4ed8;
  border-color: #c7d7fe;
}

.secondary-btn:hover,
.small-btn:hover,
.ghost-link:hover {
  background: #dce8ff;
}

.small-btn {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.full {
  width: 100%;
  margin-top: 14px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.compact-buttons {
  margin-top: 0;
}

.status-pill,
.mini-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-pill.ok,
.mini-status.ok {
  color: #027a48;
  background: #ecfdf3;
  border-color: #abefc6;
}

.status-pill.warn,
.mini-status.warn {
  color: #b54708;
  background: #fffaeb;
  border-color: #fedf89;
}

.status-pill.danger,
.mini-status.danger {
  color: #b42318;
  background: #fef3f2;
  border-color: #fecdca;
}

.status-pill.muted,
.mini-status.muted {
  color: #475467;
  background: #f2f4f7;
  border-color: #eaecf0;
}

.ingredient-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.ingredient-wrap {
  max-height: 240px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
}

.data-table.compact th,
.data-table.compact td {
  padding: 8px 9px;
  font-size: 12px;
}

.data-table input {
  min-width: 82px;
  padding: 6px 8px;
}

.empty-cell,
.empty-box {
  color: #98a2b3;
  text-align: center;
  padding: 20px;
}

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

.metric-card {
  min-height: 108px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 24px;
  line-height: 1.1;
  margin-top: 6px;
}

.metric-card em {
  color: #98a2b3;
  font-style: normal;
  font-size: 12px;
}

.status-card strong.normal {
  color: var(--success);
}

.status-card strong.warning {
  color: var(--warning);
}

.status-card strong.danger {
  color: var(--danger);
}

.chart-panel {
  min-height: 520px;
}

.chart {
  width: 100%;
  height: 440px;
}

.chart-status {
  margin: 8px 0 12px;
  border-radius: 12px;
  padding: 10px 12px;
  background: #eef4ff;
  border: 1px solid #c7d7fe;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 650;
}

.chart-status.ok {
  color: #027a48;
  background: #ecfdf3;
  border-color: #abefc6;
}

.chart-status.warn {
  color: #b54708;
  background: #fffaeb;
  border-color: #fedf89;
}

.chart-status.danger {
  color: #b42318;
  background: #fef3f2;
  border-color: #fecdca;
}

.hidden {
  display: none !important;
}

.results-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
}

.summary-list {
  display: block;
  text-align: left;
}

.summary-section + .summary-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed #d0d5dd;
}

.summary-section-title {
  color: #101828;
  font-size: 15px;
  font-weight: 800;
}

.summary-section-hint {
  margin: 3px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

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

.summary-item {
  background: var(--panel-2);
  border: 1px solid #e4e7ec;
  border-radius: 12px;
  padding: 10px 12px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.summary-item strong {
  font-size: 16px;
}

.summary-item.theory-item {
  background: #f5f8ff;
  border-left: 4px solid #84adff;
}

.summary-item.test-item {
  border-left: 4px solid #d0d5dd;
}

.finding-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.finding {
  border: 1px solid #e4e7ec;
  border-left-width: 5px;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}

.finding.normal {
  border-left-color: var(--success);
}

.finding.warning {
  border-left-color: var(--warning);
}

.finding.danger {
  border-left-color: var(--danger);
}

.finding h3 {
  margin: 0 0 5px;
  font-size: 14px;
}

.finding p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.note-block {
  background: #f8fafc;
  border: 1px solid #e4e7ec;
  border-radius: 12px;
  padding: 14px;
  color: #475467;
  line-height: 1.7;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.25);
  z-index: 20;
  font-size: 14px;
}

@media (max-width: 1300px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-header {
    flex-direction: column;
    padding: 22px 18px 14px;
  }

  .layout {
    padding: 16px;
  }

  .form-grid.two,
  .results-grid,
  .cards,
  .summary-section-grid {
    grid-template-columns: 1fr;
  }

  .chart {
    height: 360px;
  }
}

/* V1.1：总组分数据库选择框 */
body.modal-open {
  overflow: hidden;
}

.ingredient-toolbar-stacked {
  align-items: center;
}

.inline-actions,
.modal-quick-actions {
  margin-top: 0;
}

.tiny-btn,
.row-remove-btn,
.icon-btn {
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #eef4ff;
  color: #1d4ed8;
  font-weight: 700;
  padding: 5px 9px;
  font-size: 12px;
}

.tiny-btn:hover,
.row-remove-btn:hover {
  background: #dce8ff;
}

.danger-outline,
.row-remove-btn {
  color: #b42318;
  background: #fff5f4;
  border-color: #fecdca;
}

.danger-outline:hover,
.row-remove-btn:hover {
  background: #fee4e2;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: min(1080px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: #fff;
  border-radius: 18px;
  border: 1px solid #d9e2ef;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-header,
.modal-toolbar,
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 21px;
}

.modal-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  color: #475467;
  background: #f2f4f7;
  border-color: #e4e7ec;
}

.search-label {
  flex: 1;
  max-width: 520px;
}

.modal-stats {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.material-library-wrap {
  min-height: 280px;
  max-height: 56vh;
}

.material-library-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.material-library-wrap input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  padding: 0;
  accent-color: var(--primary);
}

.modal-help {
  color: #475467;
  background: #f8fafc;
  border: 1px solid #e4e7ec;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
}

.modal-footer {
  justify-content: flex-end;
}

.toast {
  z-index: 200;
}

@media (max-width: 760px) {
  .modal-backdrop {
    padding: 8px;
  }

  .modal-card {
    width: 100%;
    max-height: 96vh;
    padding: 14px;
  }

  .modal-toolbar,
  .modal-header {
    align-items: flex-start;
  }

  .modal-toolbar {
    flex-direction: column;
  }

  .ingredient-toolbar-stacked {
    align-items: flex-start;
    flex-direction: column;
  }
}
