/* =========================================================================
   MH Usage — design system
   A calm, trustworthy medical-software look. White cards on a soft neutral
   background, one blue accent, generous spacing, large readable type.
   ========================================================================= */

/* ----------------------------- Tokens ---------------------------------- */
:root {
  /* Brand / accent (calm medical blue) */
  --blue-700: #0d47a1;
  --blue-600: #1565c0;
  --blue-500: #1e88e5;
  --blue-100: #d7e6f7;
  --blue-050: #eff5fc;

  /* Neutrals */
  --ink-900: #16242b;   /* primary text */
  --ink-700: #34474f;
  --ink-500: #5d6e75;   /* secondary text */
  --ink-300: #93a1a7;
  --line:    #e2e8ea;   /* borders / hairlines */
  --bg:      #f4f6f7;   /* page background */
  --card:    #ffffff;

  /* Status */
  --green-600: #1f8b56;
  --green-050: #e9f6ef;
  --amber-cell: #fff2cc;   /* exact legend amber */
  --amber-line: #d9a300;
  --red-cell:  #f4cccc;    /* exact legend red */
  --red-600:   #c0392b;
  --red-050:   #fdecea;

  /* Typography */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fs-base: 16px;

  /* Spacing scale */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-7: 32px; --s-8: 40px; --s-9: 56px;

  /* Radius */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;

  /* Shadow / focus */
  --shadow-sm: 0 1px 2px rgba(22,36,43,.06), 0 1px 3px rgba(22,36,43,.04);
  --shadow-md: 0 2px 6px rgba(22,36,43,.07), 0 8px 24px rgba(22,36,43,.06);
  --focus: 0 0 0 3px rgba(30,136,229,.45);

  --maxw: 1180px;
}

/* ----------------------------- Reset ----------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--ink-900);
  background: var(--bg);
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; }
a { color: var(--blue-600); }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--s-6); }

/* Accessibility helpers */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--s-4); top: -48px;
  background: var(--blue-600); color: #fff; padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm); z-index: 100; transition: top .15s ease;
}
.skip-link:focus { top: var(--s-4); }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

/* ----------------------------- Header ---------------------------------- */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); padding: var(--s-5) var(--s-6);
}
.brand { display: flex; align-items: center; gap: var(--s-4); }
.brand-mark { color: var(--blue-600); display: inline-flex; flex: none; }
.brand-name { font-size: 1.5rem; line-height: 1.1; letter-spacing: -.01em; }
.brand-tagline { color: var(--ink-500); font-size: .95rem; }

.header-status { display: flex; align-items: center; gap: var(--s-2); color: var(--ink-500); font-size: .9rem; white-space: nowrap; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-300); flex: none; }
.health-dot.is-ok   { background: var(--green-600); box-shadow: 0 0 0 3px var(--green-050); }
.health-dot.is-down { background: var(--red-600);   box-shadow: 0 0 0 3px var(--red-050); }
.health-dot.is-unknown { background: var(--ink-300); }

/* ----------------------------- Help panel ------------------------------ */
.help-wrap { margin-top: var(--s-6); }
.help-panel {
  background: var(--blue-050);
  border: 1px solid var(--blue-100);
  border-radius: var(--r-md);
  overflow: hidden;
}
.help-summary {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); cursor: pointer; font-weight: 600;
  color: var(--blue-700); list-style: none; user-select: none;
}
.help-summary::-webkit-details-marker { display: none; }
.help-icon { display: inline-flex; color: var(--blue-600); }
.help-chevron { margin-left: auto; display: inline-flex; transition: transform .2s ease; color: var(--blue-600); }
.help-panel[open] .help-chevron { transform: rotate(180deg); }
.help-body { padding: 0 var(--s-5) var(--s-5) var(--s-5); color: var(--ink-700); }
.help-steps { display: grid; gap: var(--s-2); margin-top: var(--s-3); }
.help-steps li { padding-left: var(--s-5); position: relative; }
.help-steps li::before {
  content: ""; position: absolute; left: 0; top: .55em;
  width: 8px; height: 8px; border-radius: 50%; background: var(--blue-500);
}

/* ----------------------------- Layout ---------------------------------- */
.main-grid { padding-bottom: var(--s-9); display: grid; gap: var(--s-6); }

/* ----------------------------- Tabs ------------------------------------ */
/* Segmented control sitting above the two pipeline panels. */
.tabs {
  display: inline-flex; gap: var(--s-1);
  margin: var(--s-7) 0 var(--s-6);
  padding: var(--s-1);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
}
.tab {
  appearance: none; border: none; background: transparent;
  padding: var(--s-2) var(--s-5); min-height: 40px;
  border-radius: var(--r-pill);
  font-weight: 600; color: var(--ink-500); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tab:hover { color: var(--ink-700); }
.tab[aria-selected="true"] { background: var(--blue-600); color: #fff; }
.tab:focus-visible { box-shadow: var(--focus); outline: none; }

.tab-panel[hidden] { display: none; }

/* ----------------------------- Cards ----------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--s-6);
}
.step-card { padding: var(--s-7); }

.step-head { display: flex; gap: var(--s-4); align-items: flex-start; margin-bottom: var(--s-5); }
.step-number {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--blue-600); color: #fff; font-weight: 700; font-size: 1.15rem;
  display: grid; place-items: center;
}
.step-title { font-size: 1.3rem; letter-spacing: -.01em; }
.step-help { color: var(--ink-500); margin-top: var(--s-1); max-width: 62ch; }
.step-body { display: grid; gap: var(--s-4); }
.step-actions { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: center; }

/* ----------------------------- Buttons --------------------------------- */
.btn {
  --btn-bg: var(--blue-600);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-5); min-height: 44px;
  border: 1px solid transparent; border-radius: var(--r-md);
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .15s ease, box-shadow .15s ease, opacity .15s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-icon { display: inline-flex; }

.btn-primary { background: var(--btn-bg); color: #fff; }
.btn-primary:hover { background: var(--blue-700); }

.btn-secondary { background: var(--blue-050); color: var(--blue-700); border-color: var(--blue-100); }
.btn-secondary:hover { background: var(--blue-100); }

.btn-ghost { background: transparent; color: var(--ink-700); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }

.btn-lg { min-height: 56px; padding: var(--s-4) var(--s-7); font-size: 1.1rem; }
.btn-sm { min-height: 36px; padding: var(--s-2) var(--s-4); font-size: .9rem; }

/* Disabled / not-ready controls: clearly greyed out (never faded blue), so
   the user can tell a step isn't actionable yet. Targets both native
   :disabled buttons and aria-disabled anchors. The .btn-primary variants are
   listed explicitly so the grey background wins over the blue --btn-bg. */
.btn:disabled, .btn[aria-disabled="true"],
.btn-primary:disabled, .btn-primary[aria-disabled="true"] {
  background: var(--line);
  color: var(--ink-300);
  border-color: var(--line);
  box-shadow: none;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-primary:disabled:hover, .btn-primary[aria-disabled="true"]:hover,
.btn:disabled:hover, .btn[aria-disabled="true"]:hover {
  background: var(--line);
  color: var(--ink-300);
}

/* The HTML `hidden` attribute must always win. Author display rules (e.g.
   `.btn { display: inline-flex }`) otherwise override it, which left "Clear
   list" / the download button visible when they should be hidden. */
[hidden] { display: none !important; }

/* ----------------------------- Dropzone -------------------------------- */
.dropzone {
  display: grid; place-items: center; gap: var(--s-2); text-align: center;
  padding: var(--s-8) var(--s-5);
  border: 2px dashed var(--blue-100);
  border-radius: var(--r-md);
  background: var(--blue-050);
  color: var(--ink-700); cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover { border-color: var(--blue-500); }
.dropzone.is-dragover {
  border-color: var(--blue-600); background: var(--blue-100);
  box-shadow: inset 0 0 0 2px rgba(16,122,139,.15);
}
.dropzone-sm { padding: var(--s-6) var(--s-5); }
.dropzone-icon { color: var(--blue-600); }
.dropzone-title { font-weight: 600; font-size: 1.05rem; }
.dropzone-sub { color: var(--ink-500); font-size: .95rem; }
.link-like { color: var(--blue-600); text-decoration: underline; font-weight: 600; }

/* ----------------------------- File list ------------------------------- */
.file-list { display: grid; gap: var(--s-2); }
.file-list:empty { display: none; }
.file-row {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.file-row .file-thumb {
  width: 40px; height: 40px; border-radius: var(--r-sm); object-fit: cover;
  flex: none; background: var(--line);
}
.file-row .file-meta { min-width: 0; flex: 1; }
.file-row .file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .file-size { color: var(--ink-500); font-size: .85rem; }
.file-remove {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--ink-500);
  cursor: pointer; display: grid; place-items: center; font-size: 1.1rem; line-height: 1;
}
.file-remove:hover { color: var(--red-600); border-color: var(--red-600); background: var(--red-050); }

/* ----------------------------- Results / states ------------------------ */
.result-area { margin-top: var(--s-5); display: grid; gap: var(--s-3); }

.notice {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-4) var(--s-5); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--bg);
}
.notice-icon { flex: none; margin-top: 2px; }
.notice-body { min-width: 0; }
.notice-title { font-weight: 700; }
.notice-text { color: var(--ink-700); }

.notice.is-success { background: var(--green-050); border-color: #c6e6d3; }
.notice.is-success .notice-icon { color: var(--green-600); }
.notice.is-warn { background: var(--amber-cell); border-color: #ecd9a0; }
.notice.is-warn .notice-icon { color: var(--amber-line); }
.notice.is-error { background: var(--red-050); border-color: #f3c2bd; }
.notice.is-error .notice-icon { color: var(--red-600); }

.detail-toggle {
  margin-top: var(--s-2); font-size: .85rem; color: var(--ink-500);
  background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline;
}
.detail-pre {
  margin-top: var(--s-2); padding: var(--s-3); background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8rem; color: var(--ink-700); white-space: pre-wrap; word-break: break-word;
}

/* Ticket / stat chips */
.ticket-list { display: grid; gap: var(--s-2); }
.ticket-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); border: 1px solid var(--line);
  border-radius: var(--r-sm); background: #fff;
}
.ticket-id { font-weight: 600; }
.tag {
  font-size: .8rem; font-weight: 600; padding: 2px var(--s-3);
  border-radius: var(--r-pill); white-space: nowrap;
}
.tag-review { background: var(--green-050); color: var(--green-600); }
.tag-manual { background: var(--amber-cell); color: #8a6d00; }
.tag-error { background: var(--red-050, #fdecec); color: var(--red-600, #b42318); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }
.stat {
  text-align: center; padding: var(--s-4); border: 1px solid var(--line);
  border-radius: var(--r-md); background: #fff;
}
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--blue-700); line-height: 1; }
.stat-label { color: var(--ink-500); font-size: .85rem; margin-top: var(--s-1); }

/* ----------------------------- Working / progress ---------------------- */
.working {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-4) var(--s-5); border: 1px solid var(--blue-100);
  background: var(--blue-050); border-radius: var(--r-md);
}
.working-title { font-weight: 600; }
.working-sub { color: var(--ink-500); font-size: .9rem; }
.spinner {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  border: 3px solid var(--blue-100); border-top-color: var(--blue-600);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ----------------------------- Legend ---------------------------------- */
.legend {
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s-5); background: var(--bg);
}
.legend-title { font-weight: 700; margin-bottom: var(--s-3); }
.legend-list { display: grid; gap: var(--s-3); }
.legend-item { display: flex; align-items: center; gap: var(--s-3); }
.swatch {
  width: 28px; height: 28px; flex: none; border-radius: var(--r-sm);
  border: 1px solid rgba(22,36,43,.18);
}
.swatch-white { background: #ffffff; }
.swatch-amber { background: var(--amber-cell); }
.swatch-red   { background: var(--red-cell); }
.legend-icon { display: inline-flex; color: var(--ink-500); flex: none; }
.legend-text { color: var(--ink-700); }
.legend-foot { margin-top: var(--s-4); color: var(--ink-500); font-size: .9rem; }

.muted-note { color: var(--ink-500); font-size: .95rem; }

/* ----------------------------- Secondary grid -------------------------- */
.secondary-grid {
  display: grid; gap: var(--s-6);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.secondary-wide { grid-column: 1 / -1; }
.secondary-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.secondary-title { font-size: 1.15rem; margin-bottom: var(--s-2); }
.secondary-card .step-body { margin-top: var(--s-4); }

/* ----------------------------- Past batches ---------------------------- */
.batches { display: grid; gap: var(--s-2); margin-top: var(--s-4); }
.batch-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); border: 1px solid var(--line);
  border-radius: var(--r-sm); background: #fff;
}
.batch-meta { min-width: 0; }
.batch-date { font-weight: 600; }
.batch-sub { color: var(--ink-500); font-size: .85rem; }

/* Month-grouped History lists (batches, retraining activity) */
.month-group {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--card);
  margin-top: var(--s-2);
}
.month-group:first-of-type { margin-top: var(--s-4); }
.month-summary {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); cursor: pointer; list-style: none; user-select: none;
}
.month-summary::-webkit-details-marker { display: none; }
.month-summary:hover { background: var(--bg); }
.month-summary-label { font-weight: 600; color: var(--ink-900); }
.month-summary-count { color: var(--ink-500); font-size: .82rem; flex: 1; }
.month-summary-chevron {
  flex-shrink: 0; color: var(--ink-300); font-size: 0.75rem; transition: transform 0.15s;
}
.month-group[open] .month-summary-chevron { transform: rotate(90deg); }
.month-group-body {
  padding: 0 var(--s-4) var(--s-4);
  margin-top: 0;
}

.empty-state {
  text-align: center; padding: var(--s-6); color: var(--ink-500);
  border: 1px dashed var(--line); border-radius: var(--r-md); background: var(--bg);
}
.empty-state strong { color: var(--ink-700); display: block; margin-bottom: var(--s-1); }

/* ----------------------------- Metrics chart --------------------------- */
.metrics { margin-top: var(--s-4); }
.metric-bars {
  display: flex; align-items: flex-end; gap: var(--s-3);
  height: 180px; padding: var(--s-4) 0 0; border-bottom: 1px solid var(--line);
}
.metric-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: var(--s-2); min-width: 0; }
.metric-bar-wrap { width: 100%; max-width: 56px; display: flex; align-items: flex-end; height: 140px; }
.metric-bar {
  width: 100%; background: linear-gradient(180deg, var(--blue-500), var(--blue-600));
  border-radius: var(--r-sm) var(--r-sm) 0 0; min-height: 4px;
  transition: height .4s ease;
}
.metric-val { font-weight: 700; color: var(--blue-700); font-size: .9rem; }
.metric-week { color: var(--ink-500); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ----------------------------- Toasts ---------------------------------- */
.toast-region {
  position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 200;
  display: grid; gap: var(--s-3); width: min(360px, calc(100vw - 32px));
}
.toast {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-4); border-radius: var(--r-md); background: #fff;
  border: 1px solid var(--line); box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
}
.toast.is-success { border-left: 4px solid var(--green-600); }
.toast.is-error { border-left: 4px solid var(--red-600); }
.toast.is-info { border-left: 4px solid var(--blue-600); }
.toast-icon { flex: none; margin-top: 1px; }
.toast.is-success .toast-icon { color: var(--green-600); }
.toast.is-error .toast-icon { color: var(--red-600); }
.toast.is-info .toast-icon { color: var(--blue-600); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 700; }
.toast-text { color: var(--ink-700); font-size: .92rem; }
.toast-close {
  flex: none; border: none; background: none; cursor: pointer;
  color: var(--ink-300); font-size: 1.2rem; line-height: 1; padding: 0 var(--s-1);
}
.toast-close:hover { color: var(--ink-700); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ----------------------------- Footer ---------------------------------- */
.site-footer { border-top: 1px solid var(--line); background: var(--card); padding: var(--s-6) 0; }
.site-footer p { color: var(--ink-500); font-size: .9rem; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.footer-version { font-size: .82rem; color: var(--ink-300); font-variant-numeric: tabular-nums; }

/* ----------------------- Header right cluster -------------------------- */
.header-right { display: flex; align-items: center; gap: var(--s-5); }

/* What's New button */
.whats-new-btn {
  border: 1px solid var(--blue-100);
  background: var(--blue-050);
  color: var(--blue-700);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .01em;
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease;
}
.whats-new-btn:hover { background: var(--blue-100); border-color: var(--blue-500); }
.whats-new-btn:focus-visible { box-shadow: var(--focus); outline: none; }

/* ----------------------- Changelog modal ------------------------------- */
/* Plain overlay: full-screen tint + centered card. Toggled via the [hidden]
   attribute, so there are no <dialog> user-agent quirks to fight. */
.changelog-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
  background: rgba(22,36,43,.45);
}
.changelog-modal[hidden] { display: none; }
.changelog-inner {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 40px rgba(22,36,43,.18);
  width: min(560px, 100%);
  max-height: min(80vh, 600px);
  overflow: hidden;
}
.changelog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.changelog-title { font-size: 1.15rem; font-weight: 700; }
.changelog-close {
  border: none; background: none; cursor: pointer;
  color: var(--ink-300); display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--r-sm); transition: color .15s, background .15s;
}
.changelog-close:hover { color: var(--ink-700); background: var(--bg); }
.changelog-close:focus-visible { box-shadow: var(--focus); outline: none; }
.changelog-body { overflow-y: auto; padding: var(--s-5) var(--s-6); display: flex; flex-direction: column; gap: var(--s-6); }

/* Changelog entries */
.cl-entry { display: flex; flex-direction: column; gap: var(--s-3); }
.cl-header { display: flex; align-items: baseline; gap: var(--s-3); }
.cl-version {
  font-size: 1rem; font-weight: 700; color: var(--blue-700);
  background: var(--blue-050); border: 1px solid var(--blue-100);
  padding: 2px var(--s-2); border-radius: var(--r-pill);
  font-variant-numeric: tabular-nums;
}
.cl-date { font-size: .85rem; color: var(--ink-500); }
.cl-notes { display: flex; flex-direction: column; gap: var(--s-2); padding-left: var(--s-4); list-style: disc; }
.cl-notes li { font-size: .95rem; color: var(--ink-700); }

/* ----------------------- Reference log status -------------------------- */
.ref-status:empty { display: none; }
.ref-status {
  display: flex; align-items: baseline; gap: var(--s-2); flex-wrap: wrap;
  margin: 0 0 var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--blue-050);
  border: 1px solid var(--blue-100);
  border-radius: var(--r-sm);
  font-size: .85rem; color: var(--ink-700);
}
.ref-status .ref-status-when { font-weight: 600; color: var(--blue-700); }
.ref-status .ref-status-counts { color: var(--ink-500); }
.ref-status.is-empty { background: var(--bg); border-color: var(--line); color: var(--ink-500); }

/* ----------------------- Reference data tiles -------------------------- */
.reference-grid {
  display: grid; gap: var(--s-6); margin-top: var(--s-6);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ref-tile {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-5);
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg);
}
.ref-tile-title { font-size: 1.1rem; letter-spacing: -.01em; }
.ref-tile-help { color: var(--ink-500); font-size: .92rem; }
.ref-tile-form { display: grid; gap: var(--s-4); }

/* Per-tile freshness line — same look as the old reference-log status. */
.ref-fresh {
  display: flex; align-items: baseline; gap: var(--s-2); flex-wrap: wrap;
  padding: var(--s-2) var(--s-3);
  background: var(--blue-050);
  border: 1px solid var(--blue-100);
  border-radius: var(--r-sm);
  font-size: .85rem; color: var(--ink-700);
}
.ref-fresh:empty { display: none; }
.ref-fresh .ref-status-when { font-weight: 600; color: var(--blue-700); }
.ref-fresh .ref-status-counts { color: var(--ink-500); }
.ref-fresh.is-empty { background: var(--bg); border-color: var(--line); color: var(--ink-500); }

/* Single-stat result for the masters tiles. */
.stat-grid-1 { grid-template-columns: 1fr; max-width: 180px; }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ----------------------- Clickable stat buttons (learning totals) --------- */
/* A <button> that looks like a .stat card but lifts on hover and signals
   it's clickable with a blue tint and "See all" hint. */
.stat-btn {
  appearance: none;
  border: 1px solid var(--blue-100);
  background: var(--blue-050);
  border-radius: var(--r-md);
  padding: var(--s-4);
  text-align: center;
  cursor: pointer;
  font: inherit;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.stat-btn:hover {
  background: var(--blue-100);
  border-color: var(--blue-500);
  box-shadow: var(--shadow-sm);
}
.stat-btn:focus-visible { box-shadow: var(--focus); outline: none; }
.stat-btn .stat-num { font-size: 1.8rem; font-weight: 700; color: var(--blue-700); line-height: 1; }
.stat-btn .stat-label { color: var(--ink-500); font-size: .85rem; margin-top: var(--s-1); }
.stat-hint { display: block; margin-top: var(--s-2); font-size: .75rem; color: var(--blue-600); font-weight: 500; }

/* ----------------------- Learning detail modal ---------------------------- */
/* Shares .changelog-modal / .changelog-inner / .changelog-head / .changelog-close.
   .learn-inner is wider to fit the table; .learn-body removes extra padding so
   the sticky header row sits flush. */
.learn-inner { width: min(680px, 100%); }
.learn-body { overflow-y: auto; padding: 0 !important; }

.learn-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.learn-table thead th {
  position: sticky; top: 0;
  background: var(--bg);
  text-align: left;
  padding: var(--s-3) var(--s-4);
  font-weight: 600;
  color: var(--ink-500);
  border-bottom: 2px solid var(--line);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.learn-table tbody tr { border-bottom: 1px solid var(--line); }
.learn-table tbody tr:last-child { border-bottom: none; }
.learn-table tbody tr:hover { background: var(--blue-050); }
.learn-table tbody td {
  padding: var(--s-3) var(--s-4);
  color: var(--ink-700);
  vertical-align: top;
}
.learn-table .learn-key { font-weight: 600; color: var(--ink-900); white-space: nowrap; }
.learn-table .learn-desc { max-width: 240px; }
.learn-table .learn-price { font-variant-numeric: tabular-nums; }
.learn-table .learn-conf { color: var(--ink-500); font-size: .82rem; white-space: nowrap; }
.learn-table .learn-date { color: var(--ink-500); font-size: .82rem; white-space: nowrap; }
.learn-empty { text-align: center; padding: var(--s-8) var(--s-6); color: var(--ink-500); }

/* ----------------------------- Debug Console --------------------------- */
.tab-debug { border-left: 1px solid var(--line); padding-left: 1.25rem; margin-left: 0.25rem; }

.debug-card { padding: var(--s-7); }

.debug-form { margin-top: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
.debug-dropzone { max-width: 560px; }
.debug-file-name {
  font-size: 0.875rem;
  color: var(--ink-700);
  padding: var(--s-2) var(--s-3);
  background: var(--blue-050);
  border: 1px solid var(--blue-100);
  border-radius: var(--r-sm);
  max-width: 560px;
}

/* Result area */
#debug-result {
  margin-top: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}
.debug-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  font-size: 0.82rem;
  padding: var(--s-2) var(--s-4);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.debug-meta-file { color: var(--ink-700); font-weight: 500; }
.debug-meta-id { font-family: monospace; color: var(--ink-500); }
.debug-meta-status { color: var(--amber-line); }

/* Timeline */
.debug-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.debug-step {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--card);
}
.debug-step.is-ok   { border-left: 4px solid var(--blue-500); }
.debug-step.is-warn { border-left: 4px solid var(--amber-line); }
.debug-step.is-miss { border-left: 4px solid var(--ink-300); }
.debug-step.is-fail { border-left: 4px solid var(--red-600); }
.debug-step.is-skip { border-left: 4px solid var(--ink-300); }

.debug-step-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.debug-step-head::-webkit-details-marker { display: none; }
.debug-step-head:hover { background: var(--bg); }

.debug-step-icon {
  flex-shrink: 0;
  display: flex;
  margin-top: 1px;
}
.is-ok   .debug-step-icon { color: var(--blue-600); }
.is-warn .debug-step-icon { color: var(--amber-line); }
.is-fail .debug-step-icon { color: var(--red-600); }
.is-miss .debug-step-icon,
.is-skip .debug-step-icon { color: var(--ink-300); }

.debug-step-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--ink-900);
  flex: 0 0 auto;
  min-width: 220px;
  padding-top: 1px;
}
.debug-step-summary {
  font-size: 0.82rem;
  color: var(--ink-500);
  flex: 1;
  padding-top: 2px;
}
.debug-step-chevron {
  flex-shrink: 0;
  color: var(--ink-300);
  font-size: 0.75rem;
  margin-top: 3px;
  transition: transform 0.15s;
}
.debug-step[open] .debug-step-chevron { transform: rotate(90deg); }

.debug-step-body {
  border-top: 1px solid var(--line);
  background: #f8fafb;
  padding: var(--s-4);
  overflow-x: auto;
}
.debug-detail {
  margin: 0;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.76rem;
  line-height: 1.6;
  white-space: pre;
  color: var(--ink-700);
  max-height: 480px;
  overflow-y: auto;
}

.debug-summary {
  padding: var(--s-3) var(--s-4);
  font-size: 0.875rem;
  color: var(--ink-700);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.debug-summary-text { display: block; font-weight: 500; }
.debug-flags {
  margin-top: var(--s-2);
  padding-left: var(--s-5);
  list-style: disc;
  color: var(--amber-line);
  font-size: 0.82rem;
}

/* Review & correct — inline training from the Debug Console */
.debug-review {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-4);
  background: var(--card);
  margin-bottom: var(--s-4);
}
.debug-review-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-4);
}
.debug-review-head h3 { margin: 0; font-size: 1rem; color: var(--ink-900); }
.debug-review-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

.debug-review-header { border: none; padding: 0; margin: 0 0 var(--s-4); }
.debug-review-header legend {
  font-weight: 600; font-size: 0.85rem; color: var(--ink-500);
  padding: 0 0 var(--s-2);
}
.review-field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--s-3);
}
.review-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; }
.review-field-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--ink-500); font-weight: 500;
}
.review-field-input {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--card);
  color: var(--ink-900);
}
.review-field-input.is-dirty { border-color: var(--blue-500); background: var(--blue-050); }
.review-field-input:disabled { background: var(--bg); color: var(--ink-500); }

.conf-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 1px solid rgba(22, 36, 43, 0.18);
}
.conf-dot.is-high   { background: #ffffff; }
.conf-dot.is-medium { background: var(--amber-cell); }
.conf-dot.is-low    { background: var(--red-cell); }

.debug-line-card {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s-3);
  margin-bottom: var(--s-3);
}
.debug-line-card-head {
  font-weight: 600; font-size: 0.85rem;
  margin-bottom: var(--s-2); color: var(--ink-900);
}
.debug-line-badges {
  display: flex; flex-wrap: wrap; gap: var(--s-2);
  margin-top: var(--s-3);
}
.line-badge {
  font-size: 0.75rem; padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--bg); color: var(--ink-500); border: 1px solid var(--line);
}
.line-badge.is-wasted { color: var(--amber-line); border-color: var(--amber-line); }

.debug-raw-toggle > summary {
  cursor: pointer; font-weight: 600; font-size: 0.9rem;
  color: var(--ink-500); padding: var(--s-2) 0; list-style: none;
}
.debug-raw-toggle > summary::-webkit-details-marker { display: none; }

.debug-review-result {
  margin-top: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg);
  font-size: 0.85rem;
  color: var(--ink-700);
}

/* ----------------------------- Responsive ------------------------------ */
@media (max-width: 860px) {
  .secondary-grid { grid-template-columns: 1fr; }
  .reference-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .header-inner { flex-wrap: wrap; }
  .step-card { padding: var(--s-6); }
}
@media (max-width: 560px) {
  .container { padding: 0 var(--s-4); }
  .brand-tagline { display: none; }
  .toast-region { right: var(--s-3); left: var(--s-3); width: auto; }
  .whats-new-btn { font-size: .78rem; }
  .footer-inner { flex-direction: column; align-items: flex-start; }
}
