/* ===========================================================================
   VCF MRI2BMD — design system
   Brand tokens are the DeepMathAI group standard (blueprint §4).
   =========================================================================== */

:root {
  --brand: #2a78d6;
  --brand-deep: #1b5cab;
  --aqua: #1baf7a;
  --amber: #d98324;
  --danger: #d1495b;

  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #dbe3ec;
  --text: #16202c;
  --muted: #5d6b7c;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 8px 24px rgba(16, 32, 48, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 254px;
}

[data-theme="dark"] {
  --bg: #0e141b;
  --surface: #161e27;
  --surface-2: #1d2732;
  --border: #2a3743;
  --text: #e8eef5;
  --muted: #97a6b6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b;
    --surface: #161e27;
    --surface-2: #1d2732;
    --border: #2a3743;
    --text: #e8eef5;
    --muted: #97a6b6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "IBM Plex Sans Thai", -apple-system, BlinkMacSystemFont,
               "Segoe UI", "Noto Sans Thai", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
code, pre { font-family: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: .84em; }

/* ------------------------------------------------------------------ layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.1rem .85rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: .6rem; padding: .1rem .35rem .2rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  overflow: hidden; display: block;
  box-shadow: 0 1px 3px rgba(16, 32, 48, .22);
}
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: cover; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: .95rem; }
.brand-sub { font-size: .68rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .52rem .6rem; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--muted); font-size: .9rem; font-weight: 500;
  border: 1px solid transparent; user-select: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand-deep); border-color: color-mix(in srgb, var(--brand) 26%, transparent); font-weight: 620; }
[data-theme="dark"] .nav-item.active { color: #8dc0ff; }
.nav-num { width: 19px; height: 19px; flex: none; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-size: .68rem; font-weight: 700; }
.nav-item.active .nav-num { background: var(--brand); color: #fff; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .8rem; }

.seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: .32rem .3rem; border-radius: 7px; font: inherit; font-size: .8rem; font-weight: 600;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.dmai-credit {
  display: flex; align-items: center; gap: .55rem; padding: .55rem .5rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); text-decoration: none !important;
}
.dmai-credit img { width: 30px; height: 30px; object-fit: contain; flex: none; }
.dmai-txt { line-height: 1.1; }
.dmai-wm { font-weight: 750; font-size: .82rem; color: var(--text); }
.dmai-wm span { color: var(--aqua); }
.dmai-sub { font-size: .58rem; letter-spacing: .1em; color: var(--muted); }

.main { flex: 1; min-width: 0; padding: 1.6rem 2rem 4rem; max-width: 1180px; }
.page { display: none; }
.page.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: 1.2rem; }
.page-head p { color: var(--muted); max-width: 78ch; margin: 0; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1.1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.stat-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; margin-top: .15rem; }
.stat-note { font-size: .78rem; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: .85em; }
.center { text-align: center; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .16rem .55rem; border-radius: 999px;
  font-size: .76rem; font-weight: 650; border: 1px solid transparent;
}
.badge.ok { background: color-mix(in srgb, var(--aqua) 15%, transparent); color: #0d7d55; border-color: color-mix(in srgb, var(--aqua) 35%, transparent); }
.badge.warn { background: color-mix(in srgb, var(--amber) 16%, transparent); color: #9a5b12; border-color: color-mix(in srgb, var(--amber) 38%, transparent); }
.badge.bad { background: color-mix(in srgb, var(--danger) 15%, transparent); color: #9d2436; border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.badge.info { background: color-mix(in srgb, var(--brand) 13%, transparent); color: var(--brand-deep); border-color: color-mix(in srgb, var(--brand) 32%, transparent); }
[data-theme="dark"] .badge.ok { color: #5fe0ab; }
[data-theme="dark"] .badge.warn { color: #f0b46a; }
[data-theme="dark"] .badge.bad { color: #ff8b9c; }
[data-theme="dark"] .badge.info { color: #8dc0ff; }

/* ----------------------------------------------------------------- buttons */
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: .5rem .95rem;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--brand); color: var(--brand-deep); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.btn-ghost { background: transparent; }

/* --------------------------------------------------------------- dropzones */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 1.1rem; text-align: center; cursor: pointer; background: var(--surface-2);
  transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, var(--surface-2)); }
.dropzone input { display: none; }
.dropzone .dz-title { font-weight: 650; font-size: .92rem; }
.dropzone .dz-hint { font-size: .78rem; color: var(--muted); }
.dropzone img.thumb { max-height: 130px; border-radius: 8px; margin-top: .5rem; }

/* ------------------------------------------------------------------ tables */
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trunc { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* -------------------------------------------------------------- progress */
.bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--aqua)); transition: width .3s; }

/* --------------------------------------------------------------- notices */
.notice {
  border-radius: var(--radius-sm); padding: .7rem .9rem; font-size: .85rem;
  border: 1px solid var(--border); background: var(--surface-2); margin-bottom: .8rem;
}
.notice.warn { background: color-mix(in srgb, var(--amber) 10%, var(--surface)); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }
.notice.danger { background: color-mix(in srgb, var(--danger) 9%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 38%, transparent); }
.notice.info { background: color-mix(in srgb, var(--brand) 8%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 32%, transparent); }
.notice ul { margin: .4rem 0 0; padding-left: 1.15rem; }
.notice li { margin-bottom: .25rem; }

.disclaimer {
  border-left: 3px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 9%, var(--surface));
  padding: .65rem .85rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .85rem; margin: .9rem 0;
}

/* ---------------------------------------------------------- expert panel */
.expert {
  border: 1px solid color-mix(in srgb, var(--brand) 34%, transparent);
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
  border-radius: var(--radius); padding: 1rem 1.1rem;
}
.expert textarea, .expert input[type="text"] {
  width: 100%; font: inherit; font-size: .88rem; padding: .5rem .65rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); resize: vertical;
}
.expert label { display: block; font-size: .8rem; font-weight: 650; margin: .6rem 0 .25rem; }
.expert .choices { display: flex; gap: .5rem; flex-wrap: wrap; }
.expert .choices button.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ------------------------------------------------------------------ media */
.imgbox { background: #000; border-radius: var(--radius-sm); overflow: hidden; position: relative; display: inline-block; max-width: 100%; }
.imgbox img { display: block; max-width: 100%; height: auto; }
.imgbox svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.vert-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .7rem; }
.vert-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem; text-align: center; background: var(--surface); }
.vert-card img { width: 100%; border-radius: 6px; display: block; }

/* ----------------------------------------------------------------- charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: inherit; fill: var(--muted); font-size: 10px; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; opacity: .6; }
.chart .barfill { fill: var(--brand); }
.chart .barfill.alt { fill: var(--aqua); }
.chart .value-label { fill: var(--text); font-size: 10px; font-weight: 600; }

.gauge-value { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; }

pre.bibtex {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .8rem .9rem; overflow-x: auto;
  font-size: .78rem; line-height: 1.45; margin: 0;
}

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: .35rem .9rem; font-size: .87rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--brand);
  animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 6px; height: 1em; }
@keyframes sk { to { background-position: -200% 0; } }

/* ------------------------------------------------------------------ mobile */
.menu-btn { display: none; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: static; width: 100%; flex: none; height: auto;
    border-right: 0; border-bottom: 1px solid var(--border); padding: .8rem 1rem;
  }
  .sidebar.collapsed .nav, .sidebar.collapsed .sidebar-foot { display: none; }
  .menu-btn { display: inline-flex; }
  .brand { padding: 0; }
  .main { padding: 1.1rem 1rem 3rem; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: .4rem; }
}

@media print {
  .sidebar { display: none; }
  .card { break-inside: avoid; box-shadow: none; }
}
