/* ============================================================================
   StrategyTools UI Framework — /ui/st-ui.css (v1.0)
   Design System: Document Intelligence Studio (DIS)
   Specification: DESIGN.md
   ----------------------------------------------------------------------------
   Hard Rules (Anti-AI-Slop):
   1. NO colored border stripes on cards/containers (no ::before top/left bars).
   2. NO decorative gradients on backgrounds, buttons, or brand marks.
   3. NO decorative emojis or filler icons.
   4. MANDATORY font-variant-numeric: tabular-nums on all numeric elements.
   5. Hairline 1px solid borders define structure; shadows only on floating popovers/toasts.
   6. Strict border-radius scale: 5px (--r-sm), 6px (--r-md), 8px (--r-lg), 10px (--r-xl).
   ============================================================================ */

:root {
  /* Surfaces & Hairlines (Default: Studio Light) */
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e6e9ef;
  --surface-hover: #fafbfc;

  --border: #e2e5ea;
  --line: #eef0f4;
  --line-2: #f2f4f7;
  --border-strong: #cbd0d8;
  --line-strong: #cbd0d8;

  /* Typography Ink */
  --ink: #111418;
  --text: #1a1d21;
  --muted: #6b7280;
  --faint: #9aa1ab;

  /* Interactive Primary (Solid — Never Gradient) */
  --primary: #0066ff;
  --primary-h: #0052cc;
  --primary-hover: #0052cc;
  --soft: #edf4ff;
  --primary-line: #cfe0ff;
  --focus-ring: 0 0 0 3px rgba(0, 102, 255, 0.14);

  /* Semantic Data Tokens (Strictly for Data Status / SWOT / Categories) */
  --S: #15803d; --Sbg: #f0fdf4; --Sbd: #bbf7d0;
  --W: #b45309; --Wbg: #fffbeb; --Wbd: #fde68a;
  --O: #0066ff; --Obg: #edf4ff; --Obd: #bfdbfe;
  --T: #b91c1c; --Tbg: #fef2f2; --Tbd: #fecaca;

  --ok: #15803d;     --ok-soft: #f0fdf4;     --ok-line: #bbf7d0;
  --warn: #b45309;   --warn-soft: #fffbeb;   --warn-line: #fde68a;
  --info: #0066ff;   --info-soft: #edf4ff;   --info-line: #bfdbfe;
  --danger: #b91c1c; --danger-soft: #fef2f2; --danger-line: #fecaca;

  /* Strict Geometry & Radius Scale (No Pill Shapes for Structural Controls) */
  --r-sm: 5px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-xl: 10px;
  --r-2xl: 10px;

  /* Elevation (Structure uses 1px borders; shadows only for popovers/toasts) */
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow: none;
  --shadow-md: 0 2px 6px rgba(17, 20, 24, 0.05);
  --shadow-pop: 0 8px 24px rgba(17, 20, 24, 0.12);
  --shadow-lg: 0 16px 40px rgba(17, 20, 24, 0.14);

  /* Spacing Scale */
  --sp-1: 4px;
  --sp-2: 6px;
  --sp-3: 8px;
  --sp-4: 10px;
  --sp-5: 12px;
  --sp-6: 16px;
  --sp-7: 20px;
  --sp-8: 28px;

  /* Font Stacks & Type Scale */
  --font-th: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', 'Thonburi', Tahoma, sans-serif;
  --font: 'Inter', var(--font-th), -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  --fs-body: 13.5px;
  --fs-label: 12.5px;
  --fs-cap: 12px;
  --fs-badge: 11px;
  --fs-kicker: 10.5px;
  --lh-body: 1.5;

  --sc-off: #e2e5ea;
  --ease: 140ms ease;
  color-scheme: light;
}

/* ============================================================================
   SURFACE MODE 2: WARM PAPER / EDITORIAL LEDGER
   ============================================================================ */
html[data-design="editorial"],
html[data-theme="paper"] {
  --bg: #f5f4f0;
  --surface: #faf9f6;
  --surface-2: #eceae3;
  --surface-3: #e0ddd4;
  --surface-hover: #ffffff;

  --border: #dcd9d0;
  --line: #e7e4dc;
  --line-2: #eceae3;
  --border-strong: #181816;
  --line-strong: #b8b4a8;

  --ink: #111110;
  --text: #1f1f1d;
  --muted: #62605a;
  --faint: #8f8c84;

  --primary: #0044cc;
  --primary-h: #003399;
  --primary-hover: #003399;
  --soft: #e6eefc;
  --sc-off: #dcd9d0;
}

/* ============================================================================
   SURFACE MODE 3: DARK STUDIO
   ============================================================================ */
html[data-design="dark"],
html[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #121721;
  --surface-2: #181f2c;
  --surface-3: #222b3b;
  --surface-hover: #161d2a;

  --border: #232c3d;
  --line: #1a2230;
  --line-2: #161d29;
  --border-strong: #38465f;
  --line-strong: #38465f;

  --ink: #f3f5f8;
  --text: #d0d7e2;
  --muted: #8b95a7;
  --faint: #5d6778;

  --primary: #3b82f6;
  --primary-h: #2563eb;
  --primary-hover: #2563eb;
  --soft: rgba(59, 130, 246, 0.14);
  --primary-line: rgba(59, 130, 246, 0.32);

  --S: #22c55e; --Sbg: rgba(34, 197, 94, 0.12);  --Sbd: rgba(34, 197, 94, 0.3);
  --W: #f59e0b; --Wbg: rgba(245, 158, 11, 0.12); --Wbd: rgba(245, 158, 11, 0.3);
  --O: #3b82f6; --Obg: rgba(59, 130, 246, 0.12); --Obd: rgba(59, 130, 246, 0.3);
  --T: #ef4444; --Tbg: rgba(239, 68, 68, 0.12);  --Tbd: rgba(239, 68, 68, 0.3);

  --ok: #22c55e;     --ok-soft: rgba(34, 197, 94, 0.12);  --ok-line: rgba(34, 197, 94, 0.3);
  --warn: #f59e0b;   --warn-soft: rgba(245, 158, 11, 0.12); --warn-line: rgba(245, 158, 11, 0.3);
  --info: #3b82f6;   --info-soft: rgba(59, 130, 246, 0.12); --info-line: rgba(59, 130, 246, 0.3);
  --danger: #ef4444; --danger-soft: rgba(239, 68, 68, 0.12); --danger-line: rgba(239, 68, 68, 0.3);

  --sc-off: #252f42;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* Thai Typography Adjustments */
:root[lang="th"] {
  --lh-body: 1.62;
  --fs-label: 13px;
  --fs-cap: 12.5px;
}

/* ============================================================================
   BASE & RESET
   ============================================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  background-color: var(--bg);
  background-image: none;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
a {
  color: inherit;
  text-decoration: none;
}
table {
  border-collapse: separate;
  border-spacing: 0;
}
.num, .tnum, .cnt, .kpi b, td.n, th.n, input[type="number"] {
  font-variant-numeric: tabular-nums;
}
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ============================================================================
   TOPBAR & NAVIGATION (.st-topbar / .top)
   ============================================================================ */
.st-topbar, .top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.st-brand, .brand, .logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
}
.st-brand b, .brand b, .logo b {
  font-weight: 400;
  color: var(--muted);
}
.st-brand-mark, .brand-mark {
  width: 22px;
  height: 22px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--surface);
  display: inline-grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
}
.st-back, .back-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  transition: border-color var(--ease), color var(--ease), background var(--ease);
  white-space: nowrap;
}
.st-back:hover, .back-pill:hover {
  color: var(--ink);
  border-color: var(--border-strong);
  background: var(--surface);
}
.sep {
  color: var(--border-strong);
  font-size: 14px;
  user-select: none;
}

/* Editable Document Title */
.title-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 200px;
  max-width: 340px;
  flex: 1;
}
.st-doc-title, .title {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: 4px 10px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  background: transparent;
  transition: border-color var(--ease), background var(--ease);
  text-overflow: ellipsis;
}
.st-doc-title:hover, .title:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.st-doc-title:focus, .title:focus {
  background: var(--surface);
  border-color: var(--primary);
  outline: none;
  box-shadow: var(--focus-ring);
}
.sp {
  flex: 1;
}

/* ============================================================================
   BUTTONS, SELECTS & SEGMENTED CONTROLS
   ============================================================================ */
.st-btn, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 5px 11px;
  min-height: 30px;
  cursor: pointer;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text);
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  white-space: nowrap;
}
.st-btn:hover, .btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--ink);
}
.st-btn:disabled, .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.st-btn-pri, .btn.pri {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}
.st-btn-pri:hover, .btn.pri:hover {
  background: var(--primary-h);
  border-color: var(--primary-h);
  color: #ffffff;
}
.st-btn-sm, .btn.sm {
  padding: 3px 8px;
  min-height: 26px;
  font-size: 12px;
  border-radius: var(--r-sm);
}
.st-btn svg, .btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.75;
  fill: none;
  flex-shrink: 0;
}

.sel {
  max-width: 190px;
  padding-right: 24px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.st-seg, .seg {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 2px;
  gap: 1px;
}
.st-seg button, .seg button {
  border: 0;
  border-radius: calc(var(--r-md) - 2px);
  background: transparent;
  padding: 3px 9px;
  min-height: 24px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  transition: background var(--ease), color var(--ease);
  white-space: nowrap;
}
.st-seg button:hover, .seg button:hover {
  color: var(--ink);
}
.st-seg button.on, .seg button.on {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ============================================================================
   WORKFLOW STEPPER / TABS (.st-tabs / .tabs)
   ============================================================================ */
.st-tabs, .tabs {
  position: sticky;
  top: 48px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.st-tab, .tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  padding: 11px 12px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  transition: color var(--ease), border-color var(--ease);
  white-space: nowrap;
}
.st-tab:hover, .tab:hover {
  color: var(--ink);
}
.st-tab.on, .tab.on {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--primary);
}
.st-tab .num, .tab .num {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.st-tab.on .num, .tab.on .num {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}
.st-tab .cnt, .tab .cnt {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 1px 6px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.st-tab.on .cnt, .tab.on .cnt {
  background: var(--soft);
  color: var(--primary);
}
.tab-arr {
  color: var(--faint);
  font-size: 12px;
  padding: 0 2px;
  user-select: none;
}
.tabs-sp {
  flex: 1;
}
.step-nav {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 0;
}

/* ============================================================================
   HERO & KPI LEDGER (.st-hero / .hero / .kpis)
   ============================================================================ */
.st-hero, .hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.hero .eyebrow, .st-kicker {
  font-size: var(--fs-kicker);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.hero h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--ink);
}
.hero p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 620px;
  font-size: 13px;
  line-height: 1.55;
}

.st-kpis, .kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(98px, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  overflow: hidden;
  flex-shrink: 0;
}
.st-kpi, .kpi {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: background var(--ease);
}
.st-kpi:hover, .kpi:hover {
  background: var(--surface-hover);
}
.st-kpi + .st-kpi, .kpi + .kpi {
  border-left: 1px solid var(--line);
}
.st-kpi b, .kpi b {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.2;
}
.st-kpi span, .kpi span {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

/* ============================================================================
   SEMANTIC BADGES & CHIPS (.st-badge / .badge / .chip)
   ============================================================================ */
.st-badge, .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  padding: 1px 6px;
  font-size: var(--fs-badge);
  font-weight: 600;
  border: 1px solid transparent;
  line-height: 1.35;
  white-space: nowrap;
}
.bS, .bSO, .st-badge-ok     { color: var(--S); background: var(--Sbg); border-color: var(--Sbd); }
.bW, .bST, .st-badge-warn   { color: var(--W); background: var(--Wbg); border-color: var(--Wbd); }
.bO, .bWO, .st-badge-info   { color: var(--O); background: var(--Obg); border-color: var(--Obd); }
.bT, .bWT, .st-badge-danger { color: var(--T); background: var(--Tbg); border-color: var(--Tbd); }
.bG, .st-badge-neutral      { color: var(--muted); background: var(--surface-2); border-color: var(--border); }

.st-chip, .chip {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  transition: border-color var(--ease), background var(--ease), color var(--ease);
}
.st-chip:hover, .chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--ink);
}

/* ============================================================================
   CARDS, PANELS & TABLES (Strictly 1px Hairline — Zero Colored Stripes)
   ============================================================================ */
.st-card, .card, .q, .cell, .th, .ai, .plot2, .handoff {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
}
.st-table, table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
th {
  font-size: var(--fs-kicker);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  background: var(--surface-2);
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover td {
  background: var(--surface-hover);
}
td.n, th.n {
  text-align: right;
}

/* Micro-visualizations: 1-5 Rating Scale & Bars */
.sc {
  display: inline-flex;
  gap: 3px;
  justify-content: center;
}
.sc i {
  width: 10px;
  height: 12px;
  border-radius: 2px;
  background: var(--sc-off);
  cursor: pointer;
  transition: background var(--ease);
}
.sc i.on {
  background: currentColor;
}
.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  gap: 2px;
}
.bar span {
  display: block;
  height: 100%;
  border-radius: 2px;
}

/* Toast Notification */
.st-toast, .toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: 12.5px;
  font-weight: 500;
  opacity: 0;
  transition: opacity var(--ease);
  pointer-events: none;
  box-shadow: var(--shadow-pop);
  z-index: 1200;
}
.st-toast.on, .toast.on {
  opacity: 1;
}

/* Print Reset (§9 Mandatory) */
@media print {
  body { background: #ffffff !important; color: #000000 !important; }
  .st-topbar, .top, .st-tabs, .tabs, .toast { display: none !important; }
  .st-card, .card, .q, .cell, .th, table, .plot2 {
    box-shadow: none !important;
    border-color: #cccccc !important;
    break-inside: avoid;
  }
}

/* Reduced Motion (§9 Mandatory) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
