/* ============================================================
   Age Standardization Dashboard — stylesheet  v2.1
   ============================================================ */

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

:root {
  --bg:          #f5f4f0;
  --surface:     #ffffff;
  --surface-2:   #f9f8f5;
  --border:      #e2e0d9;
  --border-mid:  #c8c5bc;
  --text:        #1a1917;
  --text-2:      #5c5a55;
  --text-3:      #9c9a94;
  --accent:      #2563eb;
  --accent-bg:   #eff6ff;
  --accent-text: #1d4ed8;

  /* Standard population — blue */
  --std-bg:      #eff6ff;
  --std-border:  #bfdbfe;
  --std-text:    #1d4ed8;
  --std-light:   #f0f7ff;

  /* Study population — amber/orange */
  --study-bg:    #fff7ed;
  --study-border:#fed7aa;
  --study-text:  #c2410c;
  --study-light: #fffbf5;

  /* Warn (SMR > 1) */
  --warn-bg:     #fffbeb;
  --warn-bdr:    #fcd34d;
  --warn-txt:    #92400e;

  --success-bg:  #f0fdf4;
  --success-bdr: #86efac;
  --success-txt: #166534;
  --danger-bg:   #fef2f2;
  --danger-bdr:  #fca5a5;
  --danger-txt:  #991b1b;

  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --font:        'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:   'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-title { font-size: 18px; font-weight: 600; color: var(--text); }
.site-sub   { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.header-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.header-link:hover { text-decoration: underline; }

/* ── Main shell ── */
.app-shell { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }
.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}

/* ── Left panel ── */
.left-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}
.panel-intro .panel-sub { font-size: 12px; color: var(--text-2); line-height: 1.6; }

.section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}
.form-block { display: flex; flex-direction: column; }
.block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.block-header .section-label { margin-bottom: 0; }

/* ── Preset dropdown ── */
.preset-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  appearance: auto;
}
.preset-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}

/* ── Hidden badge ── */
.hidden-badge {
  display: inline-block;
  background: var(--warn-bg);
  border: 1px solid var(--warn-bdr);
  color: var(--warn-txt);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
}

/* ── Method toggle ── */
.method-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.method-btn {
  padding: 8px 6px;
  border: 1px solid var(--border-mid);
  background: var(--surface-2);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-2);
  font-family: var(--font);
  text-align: center;
  transition: all 0.15s;
  line-height: 1.4;
}
.method-btn:hover { background: var(--accent-bg); border-color: var(--accent); }
.method-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* ── Method description ── */
.formula-box {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.7;
}
.formula-box strong { color: var(--text); }
.method-plain { font-size: 12px; color: var(--text-2); line-height: 1.7; }
.method-plain strong { color: var(--text); }
.method-plain em { color: var(--accent-text); font-style: italic; }

/* ── Card ── */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

/* ── Population color chips in input headers ── */
.pop-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 5px;
  vertical-align: middle;
}
.pop-badge-std   { background: var(--std-bg);   color: var(--std-text);   border: 1px solid var(--std-border); }
.pop-badge-study { background: var(--study-bg); color: var(--study-text); border: 1px solid var(--study-border); }

/* ── Column color tinting ── */
.col-std   { color: var(--std-text); }
.col-study { color: var(--study-text); }

.input-std {
  border-left: 2px solid var(--std-border) !important;
  background: var(--std-light) !important;
}
.input-std:focus {
  border-color: var(--std-text) !important;
  box-shadow: 0 0 0 2px rgba(29,78,216,0.1) !important;
}
.input-study {
  border-left: 2px solid var(--study-border) !important;
  background: var(--study-light) !important;
}
.input-study:focus {
  border-color: var(--study-text) !important;
  box-shadow: 0 0 0 2px rgba(194,65,12,0.1) !important;
}

/* ── Input rows ── */
.ag-header-row {
  display: grid;
  gap: 4px;
  margin-bottom: 5px;
  font-size: 10px;
  color: var(--text-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ag-row {
  display: grid;
  gap: 4px;
  margin-bottom: 4px;
  align-items: center;
}
.ag-row-hidden { opacity: 0.45; }
.ag-row input {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  transition: border-color 0.15s;
}
.ag-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}
.ag-row input.readonly {
  background: var(--bg);
  color: var(--text-2);
  cursor: default;
}

/* ── Rate label row ── */
.rate-label-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.rate-label-text {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}
.rate-label-input {
  flex: 1;
  min-width: 0;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
}
.rate-label-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}

.rate-base-select {
  flex: 0 0 auto;
  width: auto;
  max-width: 110px;
}

/* ── Icon buttons ── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border-mid);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  color: var(--text-3);
  font-size: 11px;
  transition: all 0.12s;
  padding: 0;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-2); }
.btn-icon-muted { opacity: 0.5; }
.btn-icon-danger { border-color: var(--danger-bdr); color: var(--danger-txt); }
.btn-icon-danger:hover { background: var(--danger-bg); }

.btn-small {
  padding: 4px 10px;
  border: 1px solid var(--border-mid);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-2);
  font-family: var(--font);
  transition: all 0.12s;
}
.btn-small:hover { background: var(--surface-2); }

/* ── Buttons ── */
.compute-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  letter-spacing: 0.02em;
  transition: background 0.15s, transform 0.1s;
}
.compute-btn:hover  { background: #1d4ed8; }
.compute-btn:active { transform: scale(0.98); }

.reset-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.reset-btn {
  width: 100%;
  padding: 7px 6px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font);
  text-align: center;
  transition: all 0.12s;
  line-height: 1.4;
}
.reset-btn:hover { background: var(--surface-2); color: var(--text-2); }

.undo-btn {
  width: 100%;
  padding: 7px;
  border: 1px dashed var(--border-mid);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font);
  transition: all 0.12s;
}
.undo-btn:not(:disabled):hover { background: var(--surface-2); color: var(--text-2); border-style: solid; }
.undo-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Error ── */
.error-box {
  background: var(--danger-bg);
  border: 1px solid var(--danger-bdr);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--danger-txt);
  line-height: 1.5;
}

/* ── Right panel ── */
.right-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-height: 520px;
  box-shadow: var(--shadow);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 420px;
  gap: 8px;
  text-align: center;
}
.empty-icon  { font-size: 52px; color: var(--border-mid); font-weight: 300; line-height: 1; }
.empty-title { font-size: 16px; font-weight: 500; color: var(--text-2); }
.empty-sub   { font-size: 13px; color: var(--text-3); max-width: 240px; line-height: 1.6; }

/* ── Result sections ── */
.result-section { margin-bottom: 28px; }
.result-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── Metric cards ── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.metric-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.metric-card-std   { background: var(--std-bg);   border-color: var(--std-border); }
.metric-card-study { background: var(--study-bg); border-color: var(--study-border); }
.metric-card-warn  { background: var(--warn-bg);  border-color: var(--warn-bdr); }

.metric-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.metric-card-std   .metric-label { color: var(--std-text); }
.metric-card-study .metric-label { color: var(--study-text); }
.metric-card-warn  .metric-label { color: var(--warn-txt); }

.metric-value { font-size: 22px; font-weight: 600; color: var(--text); line-height: 1.2; }
.metric-unit  { font-size: 10px; color: var(--text-3); margin-top: 3px; }

/* ── Formula block ── */
.formula-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
}
.formula-block-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
}
.formula-step {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.formula-step:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.formula-step-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}
.formula-step-num {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent-bg);
  border: 1px solid var(--std-border);
  padding: 1px 7px;
  border-radius: 10px;
  white-space: nowrap;
}
.formula-step-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.formula-eq {
  font-size: 12px;
  color: var(--text-2);
  font-family: var(--font-mono);
  background: var(--surface);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  border-radius: 0 5px 5px 0;
  margin-bottom: 6px;
  line-height: 1.6;
}
.formula-sub {
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--text-2);
  background: transparent;
  padding: 0 4px;
  white-space: pre-wrap;
  line-height: 1.8;
}

/* ── Results table ── */
.table-wrap { overflow-x: auto; margin-bottom: 16px; }
.result-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.result-table th {
  background: var(--surface-2);
  padding: 7px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.result-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.result-table tr:last-child td { border-bottom: none; }
.result-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.result-table tr:hover td { background: var(--surface-2); }

/* Table header color coding */
.th-std   { background: var(--std-bg)   !important; color: var(--std-text)   !important; }
.th-study { background: var(--study-bg) !important; color: var(--study-text) !important; }
.th-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.th-badge-std   { background: var(--std-bg);   color: var(--std-text);   border: 1px solid var(--std-border); }
.th-badge-study { background: var(--study-bg); color: var(--study-text); border: 1px solid var(--study-border); }

/* Table cell color tinting */
.td-std   { background: var(--std-light);   }
.td-study { background: var(--study-light); }

/* ── Interpretation box ── */
.interpretation-box {
  background: var(--success-bg);
  border: 1px solid var(--success-bdr);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--success-txt);
  line-height: 1.65;
}
.interpretation-box.warn {
  background: var(--warn-bg);
  border-color: var(--warn-bdr);
  color: var(--warn-txt);
}

/* ── Download bar ── */
.download-bar {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.dl-btn {
  flex: 1;
  padding: 9px 6px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  font-family: var(--font);
  transition: all 0.12s;
}
.dl-btn:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 20px;
  font-size: 11px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

/* ── Observed input (indirect) ── */
.obs-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.obs-block .section-label { margin-bottom: 5px; }
.obs-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--study-border);
  border-left: 2px solid var(--study-border);
  border-radius: 5px;
  background: var(--study-light);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}
.obs-input:focus {
  outline: none;
  border-color: var(--study-text);
  box-shadow: 0 0 0 2px rgba(194,65,12,0.1);
}

/* ── Responsive ── */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr; }
  .method-toggle { grid-template-columns: 1fr; }
  .reset-row { grid-template-columns: 1fr; }
}
