/* ============================================================
   Multi-Agent Brainstorm — Design System
   Light-refined default · dark via [data-theme="dark"]
   Custom brand palette (rose/raspberry) · not Tailwind defaults
   ============================================================ */

/* ---- Design tokens ---- */
:root {
  /* Match the ChatGPT Work UI stack while retaining native Thai rendering. */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* spacing scale — intentional rhythm, not uniform */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 20px;
  --s5: 32px; --s6: 64px; --s7: 112px;

  /* type scale — modular, real jumps */
  --t-display: 42px;
  --t-h2: 22px;
  --t-h3: 16px;
  --t-body: 15px;
  --t-small: 13px;
  --t-micro: 11px;

  /* radii — distinct per element type (not cloned) */
  --r-input: 8px;
  --r-btn: 8px;
  --r-card: 14px;
  --r-panel: 18px;
  --r-pill: 999px;

  /* brand — bright sky blue, custom (not #2563eb) */
  --brand: #1677a8;
  --brand-strong: #0d526f;
  --brand-tint: #e8f3f5;
  --brand-ring: rgba(22, 119, 168, 0.20);

  /* neutrals — warm ink & paper */
  --ink: #102a36;
  --ink-2: #465e68;
  --ink-3: #71838a;
  --paper: #f1f5f4;
  --surface: #fbfdfc;
  --surface-2: #eaf0ef;
  --line: #d3dedb;
  --line-strong: #b9c9c5;

  /* semantic — distinct from brand */
  --amber: #9a671e;
  --amber-bg: #fbf5e8;
  --amber-line: #e6d5af;
  --red: #c0362c;
  --red-bg: #fdf1f0;
  --red-line: #f0c6c2;
  --green: #157f52;
  --green-bg: #eef8f2;
  --green-line: #b8e2c9;

  --shadow-sm: 0 1px 2px rgba(16, 42, 54, 0.045);
  --shadow-md: 0 18px 52px -34px rgba(16, 42, 54, 0.34);
  --shadow-brand: 0 14px 34px -22px rgba(13, 82, 111, 0.65);

  --bar-h: 72px;
  --maxw: 1360px;
}

[data-theme="dark"] {
  --brand: #63c4e8;
  --brand-strong: #91ddf5;
  --brand-tint: #123443;
  --brand-ring: rgba(99, 196, 232, 0.28);

  --ink: #edf6f7;
  --ink-2: #b1c3c7;
  --ink-3: #7e9499;
  --paper: #08151d;
  --surface: #0d2029;
  --surface-2: #132b35;
  --line: #213b44;
  --line-strong: #31515b;

  --amber: #e6b45c;
  --amber-bg: #2a2113;
  --amber-line: #453619;
  --red: #ef7d74;
  --red-bg: #2c1917;
  --red-line: #4a2723;
  --green: #57c98d;
  --green-bg: #14231b;
  --green-line: #204a33;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 22px -8px rgba(0, 0, 0, 0.6);
  --shadow-brand: 0 6px 22px -8px rgba(79, 176, 255, 0.45);
}

* { box-sizing: border-box; }

html { color-scheme: light; }
[data-theme="dark"] html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--t-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.25s ease, color 0.25s ease;
}

/* icons render inline; sized to text weight */
.ico { display: inline-block; vertical-align: -0.18em; flex: none; }
.ico svg { display: block; }

/* ============================================================
   App bar — full-bleed, hairline underline
   ============================================================ */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 0 var(--s5);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 680;
  font-size: 15.5px;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.brand-mark .glyph {
  width: 38px; height: 38px;
  display: block;
  overflow: hidden;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.brand-mark .glyph img { display: block; width: 100%; height: 100%; object-fit: cover; }
.app-bar .spacer { flex: 1; }
.app-bar .bar-actions { display: flex; align-items: center; gap: var(--s3); }

/* segmented lang switch */
.lang-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.lang-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 12px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.lang-btn:hover { color: var(--ink); }
.lang-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .lang-btn.active { background: var(--line-strong); }

.icon-btn {
  appearance: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ============================================================
   Page shell
   ============================================================ */
.page { max-width: var(--maxw); margin: 0 auto; padding: var(--s6) var(--s5) var(--s7); }

.lede { max-width: none; margin: 0 0 var(--s6); }
.lede h1 {
  font-size: min(var(--t-display), 32px);
  line-height: 1.08;
  letter-spacing: -0.03em;
  font-weight: 720;
  margin: 0 0 var(--s3);
  color: var(--ink);
}
.lede h1 em {
  font-style: normal;
  color: var(--brand);
}
.lede p {
  margin: 0;
  max-width: 62ch;
  font-size: 16px;
  color: var(--ink);
  line-height: 1.65;
}

/* Keep the Thai hero statement compact and on one line at every viewport. */
html[lang="th"] .lede h1 {
  display: inline-block;
  width: max-content;
  max-width: 100%;
  white-space: nowrap;
  font-size: clamp(16px, 2.7vw, 32px);
  letter-spacing: -0.035em;
}

/* ============================================================
   Composer — asymmetric hero (62 / 38)
   ============================================================ */
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(280px, 1fr);
  gap: var(--s5);
  align-items: stretch;
  margin-bottom: var(--s6);
}
.composer-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.prompt-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 208px;
  display: flex;
}

textarea#prompt-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 208px;
  height: 100%;
  resize: none;
  overflow-y: auto;
  scrollbar-gutter: stable;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  color: var(--ink);
  padding: var(--s4) 54px var(--s4) var(--s4);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.65;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.prompt-size-btn {
  position: absolute;
  z-index: 3;
  right: 12px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.prompt-size-btn:hover,
.prompt-size-btn:focus-visible { color: var(--brand-strong); border-color: var(--brand); outline: none; }
.prompt-size-top { top: 12px; }
.prompt-size-bottom { bottom: 12px; }
body.prompt-expanded { overflow: hidden; }
.prompt-shell.is-expanded {
  position: fixed;
  inset: 12px;
  z-index: 200;
  min-height: 0;
  display: flex;
  padding: 0;
  border-radius: var(--r-panel);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .32);
}
.prompt-shell.is-expanded::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: color-mix(in srgb, var(--ink) 34%, transparent);
}
.prompt-shell.is-expanded textarea#prompt-input {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 54px 62px 54px 28px;
  border-color: var(--brand);
  font-size: 17px;
  line-height: 1.75;
  box-shadow: 0 0 0 4px var(--brand-ring);
}
.prompt-shell.is-expanded .prompt-size-btn { right: 16px; }
.prompt-shell.is-expanded .prompt-size-top { top: 16px; }
.prompt-shell.is-expanded .prompt-size-bottom { bottom: 16px; }
textarea#prompt-input::placeholder { color: var(--ink-3); }
textarea#prompt-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring);
}
.prompt-templates { display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin-top:10px; }
.template-label { color:var(--ink-3); font-size:var(--t-small); margin-right:2px; }
.template-chip { border:1px solid var(--line-strong); background:var(--surface); color:var(--ink-2); border-radius:var(--r-pill); padding:6px 10px; font-size:var(--t-small); cursor:pointer; transition:background .15s,border-color .15s,color .15s; }
.template-chip:hover,.template-chip:focus-visible { background:var(--brand-tint); border-color:var(--brand); color:var(--brand-strong); outline:none; }
.campaign-cta { border:0; background:none; color:var(--brand-strong); font:inherit; font-weight:700; text-decoration:underline; cursor:pointer; padding:0; }
#tracking-consent { position:fixed; z-index:50; left:16px; right:16px; bottom:16px; display:flex; align-items:center; gap:10px; padding:12px 14px; border:1px solid var(--line-strong); border-radius:var(--r-card); background:var(--surface); box-shadow:var(--shadow-md); color:var(--ink-2); }
#tracking-consent[hidden] { display:none; }
.tracking-consent-copy { flex:1; font-size:var(--t-small); }

#attach-bar { margin-top: var(--s3); display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); }
#attach-list { display: flex; flex-wrap: wrap; gap: var(--s2); width: 100%; }

/* right composer column: account access sits directly above the credit panel */
.composer-side {
  position: sticky;
  top: calc(var(--bar-h) + var(--s4));
  z-index: 15;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

/* run panel — the dominant column */
.run-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: var(--s4);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.run-panel .mode-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  align-self: flex-start;
  font-size: var(--t-micro);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-tint);
  border: 1px solid color-mix(in srgb, var(--brand) 26%, transparent);
  padding: 4px 10px;
  border-radius: var(--r-pill);
}
.run-panel .mode-chip .balance-mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 2px;
  padding: 2px 7px;
  border: 1px solid color-mix(in srgb, var(--brand) 34%, transparent);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}
.run-panel .mode-chip .balance-mini strong {
  color: var(--brand);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.run-panel .mode-chip select {
  max-width: 150px;
  border: 1px solid color-mix(in srgb, var(--brand) 34%, transparent);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink);
  padding: 2px 20px 2px 7px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}
.run-panel .meta-line {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: var(--t-small); color: var(--ink-2);
}
.run-panel .meta-line strong { color: var(--ink); font-weight: 640; font-variant-numeric: tabular-nums; }
.run-panel .meta-line.spend-chip {
  align-self: flex-start;
  justify-content: flex-start;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  color: var(--brand);
  background: var(--brand-tint);
  border: 1px solid color-mix(in srgb, var(--brand) 26%, transparent);
  border-radius: var(--r-pill);
  font-size: var(--t-micro);
  font-weight: 650;
}
.run-panel .meta-line.spend-chip .cost-badge {
  gap: 3px;
  padding: 0;
  color: var(--brand);
  background: transparent;
  border: 0;
  font-size: inherit;
  font-weight: 750;
}

/* primary action — visually dominant */
button.primary {
  appearance: none;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border: none;
  border-radius: var(--r-btn);
  background: linear-gradient(150deg, var(--brand) 15%, var(--brand-strong));
  color: #fff;
  font: inherit;
  font-size: var(--t-h3);
  font-weight: 640;
  letter-spacing: -0.005em;
  padding: 14px 22px;
  cursor: pointer;
  box-shadow: var(--shadow-brand);
  transition: transform 0.12s ease, box-shadow 0.15s, filter 0.15s;
}
button.primary:hover { filter: brightness(1.05); box-shadow: 0 8px 26px -8px rgba(190,42,94,0.6); }
button.primary:active { transform: translateY(1px); }
button.primary:disabled {
  background: var(--surface-2);
  color: var(--ink-3);
  box-shadow: none;
  cursor: not-allowed;
}

button.secondary, button.ghost {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  border-radius: var(--r-btn);
  font: inherit;
  font-size: var(--t-small);
  font-weight: 550;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button.secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}
button.secondary:hover { background: var(--surface-2); border-color: var(--line-strong); }
button.secondary:disabled { color: var(--ink-3); cursor: not-allowed; opacity: 0.6; }
button.ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-2);
}
button.ghost:hover { color: var(--ink); background: var(--surface-2); }

/* export dropdown — lives in the Synthesis card foot (bottom-left) */
.export-wrap { position: relative; }
.export-wrap > #export-btn { justify-content: center; }
.menu {
  position: absolute;
  bottom: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
#export-btn .chev { color: var(--ink-3); margin-left: 2px; transition: transform 0.15s; }
#export-btn.open .chev { transform: rotate(180deg); }
.menu[hidden] { display: none; }
.menu button {
  appearance: none;
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: transparent; border: none;
  color: var(--ink); font: inherit; font-size: var(--t-small); font-weight: 600;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu button .ico { color: var(--ink-3); }

.cost-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  font-size: var(--t-small);
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid var(--amber-line);
  border-radius: var(--r-pill);
  padding: 3px 12px;
  font-variant-numeric: tabular-nums;
}

/* subtle inline warning */
.note { color: var(--ink-2); font-size: var(--t-small); line-height: 1.6; margin: 0; }
.note.small { font-size: var(--t-micro); color: var(--ink-3); }
.note.warn {
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid var(--amber-line);
  border-radius: var(--r-input);
  padding: 10px 12px;
  display: flex; align-items: flex-start; gap: var(--s2);
  margin-top: var(--s3);
}

/* ============================================================
   Model board — 6 provider cards (2 rows x 3), credit mode
   ============================================================ */
.auth-section { margin: 0 0 var(--s5); }
.auth-section[hidden] { display: none; }
.auth-card {
  background:
    radial-gradient(100% 160% at 100% 0%, var(--brand-tint) 0%, transparent 52%),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--line));
  border-radius: var(--r-panel);
  padding: var(--s5);
  box-shadow: var(--shadow-sm);
}
.auth-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); }
.auth-head .eyebrow { margin: 0 0 4px; color: var(--brand); font-size: var(--t-micro); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.auth-head h2 { margin: 0; max-width: 54ch; font-size: var(--t-h3); font-weight: 620; line-height: 1.45; color: var(--ink); }
.auth-purpose, .auth-channel { display: inline-flex; padding: 4px; gap: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-btn); }
.auth-purpose button, .auth-channel button {
  appearance: none; border: 0; border-radius: 7px; background: transparent; color: var(--ink-2);
  padding: 7px 14px; font: inherit; font-size: var(--t-small); font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.auth-purpose button.active, .auth-channel button.active { background: var(--surface); color: var(--brand-strong); box-shadow: var(--shadow-sm); }
.auth-purpose button:disabled, .auth-channel button:disabled { cursor: wait; opacity: .68; }
.auth-channel { margin-top: var(--s4); }
.auth-request, .auth-verify { margin-top: var(--s3); }
.auth-action-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); align-items: stretch; }
.auth-action-row input { min-height: 43px; }
.auth-action-row button { white-space: nowrap; min-width: 190px; }
.auth-sent { margin: 0 0 var(--s2); color: var(--green); font-size: var(--t-small); font-weight: 600; }
.auth-status { min-height: 22px; margin-top: var(--s2); color: var(--green); font-size: var(--t-small); }
.auth-status.error { color: var(--red); }
.auth-verify #auth-otp { font-size: 22px; font-weight: 700; letter-spacing: .28em; font-variant-numeric: tabular-nums; }
.auth-card.signed-in { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); }
.auth-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--green); background: var(--green-bg); border: 1px solid var(--green-line); }
.auth-copy, .auth-balance { display: flex; flex-direction: column; }
.auth-copy strong, .auth-balance strong { color: var(--ink); }
.auth-copy span, .auth-balance span { color: var(--ink-2); font-size: var(--t-small); }
.auth-balance { text-align: right; }
.usage-history-link {
  display: inline-flex; align-items: center; justify-content: center; min-height: 36px;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: var(--r-btn);
  color: var(--brand-strong); background: var(--surface); text-decoration: none;
  font-size: var(--t-small); font-weight: 650; white-space: nowrap;
}
.usage-history-link:hover { border-color: var(--brand); background: var(--brand-tint); }
.composer-side .auth-section { margin: 0; }
.composer-side .auth-card { padding: var(--s4); }
.composer-side .auth-head { flex-direction: column; gap: var(--s3); }
.composer-side .auth-head h2 { font-size: var(--t-body); line-height: 1.5; }
.composer-side .auth-purpose,
.composer-side .auth-channel { display: flex; width: 100%; }
.composer-side .auth-purpose button,
.composer-side .auth-channel button { flex: 1; padding-inline: 8px; }
.composer-side .auth-channel { margin-top: var(--s3); }
.composer-side .auth-action-row { grid-template-columns: 1fr; }
.composer-side .auth-action-row button { min-width: 0; width: 100%; }
.composer-side .auth-card.signed-in { grid-template-columns: auto minmax(0, 1fr); }
.composer-side .auth-card.signed-in .auth-balance { display: none; }
.composer-side .auth-card.signed-in > button,
.composer-side .auth-card.signed-in > .usage-history-link { grid-column: 1 / -1; width: 100%; justify-content: center; }
.model-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s3);
}
#board-wrap { margin-bottom: var(--s6); }
.provider-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.provider-card.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
/* เมื่อเมนูเปิด ยกการ์ดขึ้นบนสุดเพื่อให้เมนูทับการ์ดอื่นได้ */
.provider-card.menu-open { z-index: 50; }
.pc-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); padding: var(--s3) var(--s4) 0; }
.pc-title { flex: 1 1 auto; font-size: var(--t-h3); font-weight: 640; color: var(--ink); }
.pc-spend {
  display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap;
  padding: 3px 7px; border: 1px solid color-mix(in srgb, var(--brand) 28%, transparent); border-radius: var(--r-pill);
  background: var(--brand-tint); color: var(--ink-2); font-size: 9px; line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.pc-spend strong { color: var(--brand-strong); font-size: 10px; font-weight: 750; }
.pc-desc { padding: var(--s2) var(--s4) var(--s3); color: var(--ink-2); font-size: var(--t-small); min-height: 40px; }
.pc-select { position: relative; border-top: 1px solid var(--line); }
.pc-trigger {
  appearance: none; width: 100%;
  display: flex; align-items: center; gap: var(--s2);
  border: none; background: var(--surface-2);
  border-bottom-left-radius: var(--r-card);
  border-bottom-right-radius: var(--r-card);
  padding: 10px var(--s4);
  font: inherit; font-size: var(--t-small); font-weight: 550;
  color: var(--ink); cursor: pointer; text-align: left;
}
.pc-trigger:hover { background: var(--line); }
.pc-trigger .pc-trigger-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-trigger .chev { color: var(--ink-3); transition: transform 0.15s; }
.pc-trigger.open .chev { transform: rotate(180deg); }

/* popover menu — opens UPWARD (bottom:100%), like a native app model-picker */
.pc-menu {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(100% + 6px);
  z-index: 35;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-md);
  padding: 6px;
  max-height: 320px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 1px;
}
.pc-menu[hidden] { display: none; }
.pc-item {
  appearance: none; width: 100%;
  display: flex; align-items: center; gap: var(--s2);
  background: transparent; border: none; border-radius: 8px;
  padding: 9px 10px; cursor: pointer; text-align: left;
}
.pc-item:hover { background: var(--surface-2); }
.pc-item.sel { background: var(--brand-tint); }
.pc-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pc-item-name { font-size: var(--t-small); font-weight: 600; color: var(--ink); }
.pc-item-sub { font-size: var(--t-micro); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.pc-item-check { color: var(--brand); flex: none; }
.pc-menu-custom { padding: 10px; }
.pc-custom-rows { display: flex; flex-direction: column; gap: var(--s2); }
.pc-custom {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  padding: 8px 10px;
  font-size: var(--t-small);
  color: var(--ink);
}
.pc-custom:focus { background: var(--surface); }

.tier-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--r-pill);
}
.tier-badge.free { color: var(--green); background: var(--green-bg); border: 1px solid var(--green-line); text-transform: none; letter-spacing: 0; }
.tier-badge.front { color: var(--brand); background: var(--brand-tint); border: 1px solid color-mix(in srgb, var(--brand) 28%, transparent); }

/* toggle switch */
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: var(--r-pill); transition: background 0.15s; pointer-events: none; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.15s; box-shadow: var(--shadow-sm); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(16px); }

/* toast */
.toast-wrap { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: var(--s2); width: min(92vw, 420px); }
.toast {
  display: flex; align-items: center; gap: var(--s2);
  background: var(--ink); color: var(--paper);
  padding: 11px 12px 11px 14px; border-radius: var(--r-card);
  box-shadow: var(--shadow-md); font-size: var(--t-small);
  animation: toastIn 0.2s ease;
}
.toast .toast-msg { flex: 1; }
.toast .ico { flex: none; }
.toast.warn { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-line); }
.toast .toast-act {
  flex: none; color: inherit; font-weight: 700; text-decoration: none;
  padding: 4px 10px; border-radius: var(--r-pill);
  background: color-mix(in srgb, currentColor 16%, transparent);
}
.toast .toast-x { flex: none; display: grid; place-items: center; width: 22px; height: 22px; background: none; border: none; color: inherit; opacity: 0.7; cursor: pointer; border-radius: 6px; }
.toast .toast-x:hover { opacity: 1; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   Phases — varied rhythm, not repeated cards
   ============================================================ */
.phase-title {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: var(--s6) 0 var(--s4);
  font-size: var(--t-small);
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.phase-title::before {
  content: "";
  width: 22px; height: 3px; border-radius: 2px;
  background: var(--brand);
}
.phase-title::after {
  content: "";
  flex: 1; height: 3px; border-radius: 2px;
  background: var(--brand);
}

.grid4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
  gap: var(--s3);
}
.phase-empty {
  grid-column: 1 / -1;
  min-height: 104px;
  display: grid;
  place-items: center;
  padding: var(--s4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-card);
  background: var(--surface-2);
  color: var(--ink-3);
  text-align: center;
  font-size: var(--t-small);
}
#final-card > .phase-empty { margin-top: var(--s3); }
.model-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--s3) var(--s4) var(--s4);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s;
}
.model-card:hover { border-color: var(--line-strong); }
.model-card h3 {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s2);
  margin: 0 0 var(--s3);
  font-size: var(--t-h3);
  font-weight: 620;
  color: var(--ink);
}
.model-card h3 .cost { color: var(--amber); font-size: var(--t-micro); font-weight: 550; font-variant-numeric: tabular-nums; }
.model-card pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.62;
  color: var(--ink-2);
  margin: 0;
}
.model-card.loading pre { color: var(--ink-3); }
.model-card.loading pre::after {
  content: "";
  display: inline-block;
  width: 30px;
  animation: dots 1.3s steps(4, end) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "·"; } 50% { content: "· ·"; } 75% { content: "· · ·"; } }
.model-card.error { border-color: var(--red-line); background: var(--red-bg); }
.model-card.error pre { color: var(--red); }

/* provider draft cards (credit mode, 6-card grid) */
.provider-draft { position: relative; }
.provider-draft h3 { padding-right: 70px; }
.provider-draft.off { border-style: dashed; background: var(--surface-2); }
.provider-draft.off pre { color: var(--ink-3); }
.result-grid { align-items: stretch; }
.workflow-controls { display:flex; align-items:flex-end; gap:12px; margin-top:12px; flex-wrap:wrap; }
.workflow-controls label { display:grid; gap:5px; color:var(--ink-2); font-size:12px; font-weight:700; }
.workflow-controls select { min-width:260px; padding:8px 30px 8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--surface); color:var(--ink); }
.workflow-note { color:var(--ink-3); font-size:11px; padding-bottom:8px; }
.workflow-note.is-warning {
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid var(--red-line);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.5;
}
.app-workflow-wrap { display:flex; align-items:flex-end; gap:12px; flex-wrap:wrap; }
.app-workflow-wrap label { display:grid; gap:5px; color:var(--ink-2); font-size:12px; font-weight:700; }
.app-workflow-wrap select { min-width:220px; padding:8px 30px 8px 10px; border:1px solid var(--line); border-radius:9px; background:var(--surface); color:var(--ink); }
.supplement-invalidation-banner {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--amber-line, #d4a017);
  background: var(--amber-bg, rgba(212, 160, 23, 0.08));
  border-radius: 11px;
  display: grid;
  gap: 10px;
}
.supplement-invalidation-banner[hidden] { display: none; }
.round-supplement {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  display: grid;
  gap: 10px;
}
.round-supplement[hidden] { display: none; }
.round-supplement.is-expanded {
  position: fixed;
  inset: 12px;
  z-index: 40;
  margin: 0;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}
.round-supplement.is-locked .round-supplement-input { opacity: .85; background: var(--surface); }
.round-supplement-head { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.round-supplement-head h3 { margin:0; font-size:13px; font-weight:800; color:var(--ink-2); }
.round-supplement-counter { font-size:11px; color:var(--ink-3); font-variant-numeric: tabular-nums; }
.round-supplement-counter.is-over { color: var(--red); font-weight: 700; }
.round-supplement-input {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}
.round-supplement.is-expanded .round-supplement-input { min-height: 40vh; }
.round-supplement-actions { display:flex; flex-wrap:wrap; gap:8px; }
.round-supplement-lock.active { border-color: var(--brand); color: var(--brand); }
.round-supplement-attach-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.round-supplement-attach-hint,
.round-supplement-attach-summary { color: var(--ink-3); }
.round-supplement-attach-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.round-supplement-attach-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 12px;
}
.round-supplement-attach-chip .name { font-weight: 700; color: var(--ink-2); }
.round-supplement-attach-chip .meta { color: var(--ink-3); font-size: 11px; }
.round-supplement-attach-chip.state-validating { border-color: var(--amber); }
.round-supplement-attach-chip.state-ready { border-color: var(--green); }
.round-supplement-attach-chip.state-needs_reattach { border-color: var(--amber); }
.round-supplement-attach-chip.state-uploading { border-color: var(--brand); }
.round-supplement-attach-chip.state-extracting { border-color: var(--brand); }
.round-supplement-attach-chip.state-local_saving { border-color: var(--brand); }
.round-supplement-attach-chip.state-acknowledging { border-color: var(--brand); }
.round-supplement-attach-chip.state-extracted { border-color: var(--green); }
.round-supplement-attach-chip.state-outcome_unknown { border-color: var(--amber); background: var(--amber-bg, rgba(245, 158, 11, 0.08)); }
.round-supplement-attach-chip.state-error { border-color: var(--red); background: var(--red-bg, rgba(220, 38, 38, 0.06)); }
.round-supplement-upload-beta { color: var(--ink-3); margin: 0 0 8px; }
.round-supplement-attach-actions { display: inline-flex; gap: 6px; flex-shrink: 0; }
.round-supplement-attach-actions button { font-size: 11px; padding: 2px 8px; }
.playbook-panel-host { margin-top: 10px; }
.playbook-panel-host[hidden] { display: none; }
.playbook-output-preview-host { margin-top: 0; }
.playbook-output-preview-host[hidden] { display: none; }
.playbook-panel {
  border: 1px solid var(--line, #d9e2df);
  border-radius: 12px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--panel, #f8faf9) 92%, transparent);
}
.playbook-panel-head { margin-bottom: 8px; }
.playbook-panel-title { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.playbook-panel-field {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-2);
}
.playbook-panel-field select,
.playbook-select {
  width: 100%;
  border: 1px solid var(--line, #d9e2df);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel, #fff);
  color: var(--ink);
}
.playbook-panel-meta,
.playbook-panel-empty,
.playbook-panel-notice {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--ink-3);
}
.playbook-panel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}
.playbook-panel-meta strong { color: var(--ink-2); }
.playbook-panel-preview { margin-top: 4px; }
.playbook-panel-preview-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
}
.playbook-round-preview {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.playbook-round-preview th,
.playbook-round-preview td {
  border-top: 1px solid var(--line, #d9e2df);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.playbook-round-preview th { color: var(--ink-3); font-weight: 700; }
.playbook-panel-error { color: var(--red); font-size: 12px; margin: 0 0 8px; }
.playbook-panel-notice { color: var(--amber, #b45309); }
.poa-contract-preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line, #d9e2df);
}
.poa-preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line, #d9e2df);
}
.poa-preview-title,
.poa-contract-title { margin: 0 0 4px; font-size: 12px; font-weight: 700; color: var(--ink-3); }
.poa-preview-hint,
.poa-contract-hint { margin: 0 0 6px; font-size: 11px; color: var(--ink-3); }
.poa-chip-list,
.poa-contract-list { margin: 0; padding-left: 18px; font-size: 12px; color: var(--ink-2); }
.poa-chip { margin-bottom: 2px; }
.poa-sections { margin-top: 6px; font-size: 11px; color: var(--ink-3); }
.poa-section-list { margin: 4px 0 0; padding-left: 18px; }
.poa-empty p,
.poa-contract-empty p { margin: 0; font-size: 12px; color: var(--ink-3); }
.poa-render { margin: 0; font-size: 11px; white-space: pre-wrap; color: var(--ink-2); }
.poa-render { white-space: pre-wrap; font-size: 11px; margin: 0; }
.structured-prompt-builder-host { margin-top: 10px; }
.structured-prompt-builder-host[hidden] { display: none; }
.spb-panel {
  border: 1px solid var(--line, #d9e2df);
  border-radius: 12px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--panel, #f8faf9) 92%, transparent);
}
.spb-head { margin-bottom: 8px; }
.spb-title { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.spb-form {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.spb-field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-2);
}
.spb-field input,
.spb-field textarea,
.spb-field select {
  width: 100%;
  border: 1px solid var(--line, #d9e2df);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel, #fff);
  color: var(--ink);
  font: inherit;
}
.spb-preview { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.spb-preview-title { margin: 0 0 8px; font-size: 12px; font-weight: 700; color: var(--ink-3); }
.spb-prompt-pair {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.spb-prompt-block h5,
.spb-diff h5,
.spb-proposal-block h5 { margin: 0 0 4px; font-size: 12px; color: var(--ink-3); }
.spb-prompt-text {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface, #fff);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}
.spb-diff-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-bottom: 10px;
}
.spb-diff-grid h6 { margin: 0 0 4px; font-size: 11px; color: var(--ink-3); }
.spb-diff-list { margin: 0; padding-left: 16px; font-size: 11px; color: var(--ink-2); }
.spb-diff-empty { margin: 0; font-size: 11px; color: var(--ink-3); }
.spb-proposal,
.spb-proposal-reason,
.spb-proposal-error,
.spb-error { font-size: 12px; margin: 0 0 6px; color: var(--ink-2); }
.spb-meta { color: var(--ink-3); font-weight: 400; }
.spb-estimates {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px dashed var(--line);
  font-size: 12px;
}
.spb-est-title { margin: 0 0 6px; font-weight: 700; color: var(--ink-3); }
.spb-est-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
}
.spb-est-disclaimer { margin: 6px 0 0; font-size: 11px; color: var(--ink-3); }
.spb-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.spb-disabled { opacity: 0.85; }
@media (max-width: 640px) {
  .spb-prompt-pair,
  .spb-diff-grid { grid-template-columns: 1fr; }
}

.research-profile-host { margin-top: 10px; }
.research-profile-host[hidden] { display: none; }
.research-profile-panel {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  padding: 12px;
}
.research-profile-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.research-profile-title { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.research-profile-summary { margin: 4px 0 0; }
.research-profile-identity-note { margin: 8px 0 0; color: var(--ink-3); }
.research-profile-body { margin-top: 10px; }
.research-profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}
.research-profile-grid-compact { margin-bottom: 8px; }
.research-profile-field {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
}
.research-profile-field input,
.research-profile-field select,
.research-profile-field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
.research-profile-field textarea { min-height: 52px; resize: vertical; }
.research-profile-field input[data-identity-field="true"] {
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
}
.research-profile-details { margin-top: 8px; }
.research-profile-details summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 8px;
}
.research-profile-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.research-profile-validation {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 12px;
}
.research-profile-error { color: var(--red); }
.research-profile-warning { color: var(--amber, #b45309); }
.research-document-host { margin-top: 10px; }
.research-document-host[hidden] { display: none; }
.research-document-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface-2, rgba(255, 255, 255, 0.02));
}
.research-document-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.research-document-title { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.research-document-summary { margin: 4px 0 0; }
.research-document-status.is-ready { color: var(--green, #15803d); font-weight: 700; }
.research-document-status.is-blocked { color: var(--red); font-weight: 700; }
.research-document-body { margin-top: 10px; }
.research-document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.research-document-action[disabled],
.research-document-action-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.research-document-validation {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 12px;
}
.research-document-error { color: var(--red); }
.research-document-warning { color: var(--amber, #b45309); }
.research-document-feedback { margin-top: 8px; min-height: 1.2em; }
.research-knowledge-workspace-host { margin-top: 10px; }
.research-knowledge-workspace-host[hidden] { display: none; }
.rkw-ui-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface-2, rgba(255, 255, 255, 0.02));
}
.rkw-ui-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.rkw-ui-title { margin: 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.rkw-ui-summary { margin: 4px 0 0; }
.rkw-ui-body { margin-top: 10px; }
.rkw-ui-section-title {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-2);
}
.rkw-ui-badge {
  display: inline-block;
  margin-right: 6px;
  margin-bottom: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface);
}
.rkw-ui-badge-muted { color: var(--ink-3); }
.rkw-ui-counts,
.rkw-ui-policy,
.rkw-ui-limit-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
}
.rkw-ui-counts li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.rkw-ui-coverage,
.rkw-ui-retention,
.rkw-ui-limitations { margin-top: 8px; }
.rkw-ui-r6-notice { color: var(--amber, #b45309); }
.rkw-ui-vertical-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.rkw-ui-vertical-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface);
}
.rkw-ui-vertical-card header {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin-bottom: 6px;
}
.rkw-ui-vertical-card h4 {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-2);
  flex: 1 1 100%;
}
.rkw-ui-vertical-card pre,
.rkw-ui-summary-block pre {
  margin: 0;
  padding: 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  font-size: 10px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}
.rkw-ui-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.rkw-ui-feedback { margin-top: 8px; min-height: 1.2em; }
@media (max-width: 900px) {
  .rkw-ui-vertical-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .research-profile-grid { grid-template-columns: 1fr; }
  .research-document-actions { flex-direction: column; align-items: stretch; }
}
.token-estimate {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}
.token-estimate[hidden] { display: none; }
.token-estimate-item {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
}
.token-estimate-item span { color: var(--ink-3); font-size: 10px; font-weight: 700; }
.token-estimate-item strong { color: var(--ink); font-size: 13px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.token-estimate-status {
  grid-column: 1 / -1;
  color: var(--ink-3);
  font-size: 10px;
  line-height: 1.45;
}
.token-estimate.is-warning { border-color: var(--amber-line); background: var(--amber-bg); }
.token-estimate.is-warning .token-estimate-status { color: var(--amber); font-weight: 700; }
.token-estimate.is-danger { border-color: var(--red-line); background: var(--red-bg); }
.token-estimate.is-danger .token-estimate-status { color: var(--red); font-weight: 750; }
.provider-card.budget-limited { border-color: var(--amber-line); }
.pc-item:disabled {
  opacity: .48;
  cursor: not-allowed;
  background: var(--surface-2);
}
.pc-item-lock { color: var(--amber); font-size: 10px; font-weight: 700; white-space: nowrap; }
.bd-on:disabled + span { opacity: .45; cursor: not-allowed; }

.funds-warning-dialog {
  width: min(92vw, 520px);
  padding: 0;
  border: 1px solid var(--amber-line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .34);
}
.funds-warning-dialog::backdrop { background: rgba(9, 16, 28, .58); backdrop-filter: blur(3px); }
.funds-warning-dialog form { display: grid; gap: 12px; padding: 24px; }
.funds-warning-dialog h2 { margin: 0; font-size: 20px; line-height: 1.35; }
.funds-warning-dialog p { margin: 0; line-height: 1.65; color: var(--ink-2); }
.funds-warning-icon {
  width: 44px; height: 44px; display: grid; place-items: center;
  color: var(--amber); background: var(--amber-bg); border: 1px solid var(--amber-line); border-radius: 50%;
}
.funds-warning-summary {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 14px;
  padding: 12px; border-radius: 10px; background: var(--surface-2); font-size: 13px;
}
.funds-warning-summary strong { font-variant-numeric: tabular-nums; }
.funds-warning-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 4px; }
.funds-warning-actions .primary { width: 100%; }
.workflow-phase-warning {
  margin: 10px 0 12px;
  padding: 11px 13px;
  border: 2px solid var(--red-line);
  border-radius: 10px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
  font-weight: 760;
  line-height: 1.55;
}
.workflow-skipped .result-card { opacity: .72; }
.workflow-unverified-final .final-answer-card { border-color: var(--red-line); }
.pc-role-wrap { width:calc(100% - 24px); margin:8px 12px 0; }
.pc-role { width:100%; margin:0; padding:7px 9px; border:1px solid var(--line); border-radius:8px; background:var(--surface); color:var(--ink); font-size:11px; }
.pc-role:focus { border-color:var(--brand); outline:2px solid color-mix(in srgb, var(--brand) 16%, transparent); }
.single-final-result { grid-template-columns: 1fr; }
.final-answer-card { grid-column: 1 / -1; }
.final-answer-card .result-editor-shell,
.final-answer-card .result-editor { min-height: 220px; }
.result-card { min-width: 0; display: flex; flex-direction: column; }
.result-editor-shell {
  position: relative;
  min-height: 148px;
  flex: 1;
  display: flex;
}
.result-editor {
  width: 100%;
  min-height: 148px;
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface-2);
  color: var(--ink);
  padding: 11px 52px 11px 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.62;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overflow-wrap: anywhere;
}
.result-size-btn {
  position: absolute;
  z-index: 4;
  right: 10px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.result-size-btn:hover,
.result-size-btn:focus-visible { color: var(--brand-strong); border-color: var(--brand); outline: none; }
.result-size-top { top: 10px; }
.result-size-bottom { bottom: 10px; }
body.result-editor-expanded { overflow: hidden; }
.result-editor-shell.is-expanded {
  position: fixed;
  inset: 12px;
  z-index: 210;
  min-height: 0;
  display: flex;
  background: var(--surface);
  border-radius: var(--r-panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .32);
}
.result-editor-shell.is-expanded::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: color-mix(in srgb, var(--ink) 34%, transparent);
}
.result-editor-shell.is-expanded .result-editor {
  width: 100%;
  height: 100%;
  min-height: 0 !important;
  padding: 54px 62px 54px 28px;
  border-color: var(--brand);
  background: var(--surface);
  font-size: 17px;
  line-height: 1.75;
  box-shadow: 0 0 0 4px var(--brand-ring);
}
.result-editor-shell.is-expanded .result-size-btn { right: 16px; }
.result-editor-shell.is-expanded .result-size-top { top: 16px; }
.result-editor-shell.is-expanded .result-size-bottom { bottom: 16px; }
.result-editor:hover { border-color: var(--line-strong); }
.result-editor:focus { background: var(--surface); border-color: var(--brand); outline: 2px solid color-mix(in srgb, var(--brand) 18%, transparent); }
.result-editor::placeholder { color: var(--ink-3); }
.result-card.loading .result-editor { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.result-card.error .result-editor { border-color: var(--red-line); }
.result-card.off .result-editor { background: var(--surface); }
.pd-copy {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: none; cursor: pointer;
  color: var(--ink-3); border-radius: 6px; padding: 4px;
  font: inherit; font-size: var(--t-micro); font-weight: 600;
}
.pd-copy:hover { color: var(--brand); background: var(--surface-2); }
.pd-copy-top { position: absolute; top: 10px; right: 50px; z-index: 2; }
.pd-copy[hidden] { display: none; }
.pd-foot { margin-top: var(--s3); display: flex; align-items: center; gap: var(--s2); min-height: 30px; }
.pd-foot .export-wrap { margin-right: auto; }
.pd-copy-foot { padding: 4px 8px; }

/* Round 2 research progress + source-count strip (answer-phase cards only) */
.research-progress {
  margin: 0 0 var(--s3);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.research-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px;
}
.research-step {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.4;
}
.research-step-num {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.research-step-label { font-weight: 600; color: var(--ink-2); }
.research-step-count {
  flex-basis: 100%;
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.research-step.active {
  border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
  background: color-mix(in srgb, var(--brand) 8%, var(--surface));
}
.research-step.active .research-step-num {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.research-step.active .research-step-label { color: var(--brand-strong); }
.research-step.done { color: var(--ink-2); border-color: color-mix(in srgb, var(--green) 50%, var(--line)); }
.research-step.done .research-step-num {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.research-step.done .research-step-label { color: var(--ink); }
.research-step.failed {
  border-color: var(--red-line);
  background: var(--red-bg);
}
.research-step.failed .research-step-num {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.research-step.failed .research-step-label { color: var(--red); }
.research-step[aria-disabled="true"] { opacity: .55; }
.research-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
}
.research-badge[data-kind="search-layer"] {
  border-color: color-mix(in srgb, var(--amber) 55%, var(--line));
  color: var(--amber);
  background: var(--amber-bg);
}
.research-badge[data-kind="native"] {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  color: var(--brand-strong);
  background: color-mix(in srgb, var(--brand) 8%, var(--surface));
}
.research-error {
  margin: 6px 0 0;
  color: var(--red);
  font-size: 11px;
  font-weight: 600;
}
[data-theme="dark"] .research-step.active .research-step-label { color: var(--brand); }

/* synthesis — elevated, distinct treatment */
.final-card {
  position: relative;
  background: var(--green-bg);
  border: 1px solid var(--green-line);
  border-radius: var(--r-panel);
  padding: var(--s5);
  padding-left: calc(var(--s5) + 4px);
  margin-top: var(--s3);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.final-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: var(--green);
}
.final-card h3 {
  margin: 0 0 var(--s3);
  font-size: var(--t-h2);
  font-weight: 660;
  letter-spacing: -0.015em;
  color: var(--green);
  display: flex; align-items: center; gap: var(--s2);
}
.final-card pre {
  white-space: pre-wrap; word-wrap: break-word;
  font-family: inherit; font-size: 13.5px; line-height: 1.68;
  color: var(--ink); margin: 0;
}
.final-card.error { background: var(--red-bg); border-color: var(--red-line); }
.final-card.error::before { background: var(--red); }
.final-card.error h3 { color: var(--red); }
.final-card h3 { padding-right: 36px; }
.final-card .pd-copy-top { position: absolute; top: 14px; right: 14px; z-index: 2; }
.final-card .pd-foot { margin-top: var(--s4); display: flex; align-items: center; gap: var(--s3); }

/* ============================================================
   Attachments
   ============================================================ */
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 5px 6px 5px 12px;
  font-size: var(--t-small);
  color: var(--ink);
  max-width: 100%;
}
.attach-chip .who { color: var(--brand); font-size: var(--t-micro); }
.attach-chip .state-uploading { color: var(--amber); font-size: var(--t-micro); }
.attach-chip .state-ready { color: var(--green); font-size: var(--t-micro); }
.attach-chip .state-error { color: var(--red); font-size: var(--t-micro); }
.attach-chip button {
  display: grid; place-items: center;
  width: 20px; height: 20px;
  background: none; border: none; color: var(--ink-3);
  cursor: pointer; border-radius: var(--r-pill);
}
.attach-chip button:hover { color: var(--red); background: var(--red-bg); }

/* ============================================================
   Settings — two-column 30/70 (asymmetric)
   ============================================================ */
.settings-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: var(--s6); align-items: start; }
.settings-rail { position: sticky; top: calc(var(--bar-h) + var(--s4)); display: flex; flex-direction: column; gap: var(--s1); }
.settings-rail .rail-head {
  font-size: var(--t-micro); font-weight: 680; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 var(--s2) var(--s3);
}
.rail-link {
  display: flex; align-items: center; gap: var(--s2);
  padding: 8px var(--s3); border-radius: var(--r-input);
  color: var(--ink-2); font-size: var(--t-small); font-weight: 550;
  text-decoration: none; cursor: pointer; border: 1px solid transparent;
}
.rail-link:hover { background: var(--surface-2); color: var(--ink); }
.rail-link.active { background: var(--brand-tint); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 20%, transparent); }

.settings-body { min-width: 0; display: flex; flex-direction: column; gap: var(--s4); }
.settings-actions {
  display: flex; align-items: center; gap: var(--s3);
  padding-bottom: var(--s4); margin-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
}
.settings-actions .grow { flex: 1; }
#save-status { color: var(--green); font-size: var(--t-small); }

/* segmented mode switch (Credit vs BYOK) */
.seg {
  display: inline-flex; padding: 4px; gap: 3px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-btn);
}
.seg button {
  appearance: none; border: none; background: transparent;
  color: var(--ink-2); font: inherit; font-size: var(--t-small); font-weight: 600;
  padding: 7px 16px; border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; gap: var(--s2);
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg button.active { background: var(--line-strong); color: var(--brand); }

/* card — the reusable surface, but NOT the whole-page container */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--s4);
  box-shadow: var(--shadow-sm);
}
.card > h2 {
  display: flex; align-items: center; gap: var(--s2);
  margin: 0 0 var(--s2);
  font-size: var(--t-h3); font-weight: 640; color: var(--ink);
  letter-spacing: -0.01em;
}
.card > h2 .grow { flex: 1; }

/* credit hero card — Section 1, given more emphasis than BYOK cards */
.credit-hero {
  background:
    radial-gradient(120% 140% at 100% 0%, var(--brand-tint) 0%, transparent 55%),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--line));
  border-radius: var(--r-panel);
  padding: var(--s5);
}
.credit-hero .eyebrow {
  font-size: var(--t-micro); font-weight: 680; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--brand); margin: 0 0 var(--s2);
}
.credit-hero h2 { font-size: var(--t-h2); font-weight: 680; letter-spacing: -0.02em; margin: 0 0 var(--s2); }

.balance-row { display: flex; flex-wrap: wrap; gap: var(--s3); margin: var(--s4) 0; }
.stat {
  flex: 1; min-width: 150px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); padding: var(--s3) var(--s4);
}
.stat .k { font-size: var(--t-micro); font-weight: 640; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .v small { font-size: 13px; font-weight: 550; color: var(--ink-2); }

.pack-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: var(--s2); margin-top: var(--s3); }
.pack {
  appearance: none; cursor: pointer; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-input); padding: var(--s3);
  transition: border-color 0.15s, transform 0.1s;
}
.pack:hover { border-color: var(--brand); transform: translateY(-1px); }
.pack .price { font-size: var(--t-h3); font-weight: 700; color: var(--ink); }
.pack .cr { font-size: var(--t-micro); color: var(--ink-2); }

/* forms */
label { display: block; font-size: var(--t-micro); font-weight: 600; letter-spacing: 0.02em; color: var(--ink-2); margin: var(--s3) 0 var(--s1); }
input[type="text"], input[type="password"], input[type="number"], input[type="email"], input[type="tel"], select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-input);
  color: var(--ink);
  padding: 9px 11px;
  font-family: inherit;
  font-size: var(--t-body);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.row { display: flex; gap: var(--s3); }
.row > div { flex: 1; }

/* key field with inline eye toggle */
.key-field { position: relative; flex: 1; }
.key-field input { padding-right: 42px; font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.02em; }
.eye-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; display: grid; place-items: center;
  background: transparent; border: none; color: var(--ink-3);
  cursor: pointer; border-radius: 7px;
}
.eye-btn:hover { color: var(--ink); background: var(--surface-2); }

a.ext-link, .inline-link {
  color: var(--brand); font-size: var(--t-micro); font-weight: 600;
  text-decoration: none; display: inline-flex; align-items: center; gap: 3px;
}
a.ext-link:hover, .inline-link:hover { text-decoration: underline; }

.field-note { font-size: var(--t-micro); color: var(--ink-3); margin: var(--s1) 0 0; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  max-width: var(--maxw); margin: var(--s7) auto 0;
  padding: var(--s5) var(--s5) var(--s6);
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s6);
  color: var(--ink-3);
}
.site-footer a { color: var(--ink-2); text-decoration: none; font-size: var(--t-small); }
.site-footer a:hover { color: var(--brand); }

.pricing-disclaimer { max-width: var(--maxw); margin: var(--s6) auto 0; padding: 0 var(--s5); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 860px) {
  .composer { grid-template-columns: 1fr; }
  /* On stacked layouts, surface account access before the prompt composer. */
  .composer-side { display: contents; }
  .composer-side .auth-section { order: 1; }
  .composer-main { order: 2; }
  .composer-side .run-panel { order: 3; }
  .model-board { grid-template-columns: 1fr 1fr; }
  .composer-side { position: static; }
  .settings-shell { grid-template-columns: 1fr; }
  .settings-rail { position: static; flex-direction: row; flex-wrap: wrap; }
  .page { padding: var(--s5) var(--s4) var(--s6); }
  .app-bar { padding: 0 var(--s4); gap: var(--s3); }
  :root { --t-display: 27px; }
  .auth-head { flex-direction: column; }
  .auth-purpose { width: 100%; }
  .auth-purpose button { flex: 1; }
  .auth-card.signed-in { grid-template-columns: auto 1fr auto; }
  .auth-card.signed-in .auth-balance { display: none; }
}
@media (max-width: 560px) {
  html[lang="th"] .lede h1 {
    display: block;
    width: auto;
    white-space: normal;
    font-size: clamp(20px, 5.5vw, 24px);
    line-height: 1.15;
  }
  .brand-mark .label-full { display: none; }
  .model-board { grid-template-columns: 1fr; }
  .auth-card { padding: var(--s4); }
  .auth-action-row { grid-template-columns: 1fr; }
  .auth-action-row button { min-width: 0; width: 100%; }
  .auth-channel { display: flex; width: 100%; }
  .auth-channel button { flex: 1; }
  .auth-card.signed-in { grid-template-columns: auto 1fr; }
  .auth-card.signed-in > button { grid-column: 1 / -1; width: 100%; }
  .prompt-shell.is-expanded { inset: 6px; }
  .prompt-shell.is-expanded textarea#prompt-input { padding: 48px 54px 48px 18px; font-size: 16px; }
  .result-editor-shell.is-expanded { inset: 6px; }
  .result-editor-shell.is-expanded .result-editor { padding: 48px 54px 48px 18px; font-size: 16px; }
  .token-estimate { grid-template-columns: 1fr 1fr; }
  .funds-warning-actions { grid-template-columns: 1fr; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* LINE support: rendered only when a validated OA Add Friend URL is configured. */
.mab-line-support {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(var(--mab-support-bottom, 20px), env(safe-area-inset-bottom));
  z-index: 80;
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 2px solid #9cf0b9;
  border-color: color-mix(in srgb, #06c755 72%, white);
  border-radius: 50%;
  background: #06c755;
  color: #fff;
  box-shadow: 0 10px 28px rgba(0, 70, 35, .25);
  text-decoration: none;
  transition: transform .16s ease, box-shadow .16s ease, bottom .2s ease;
}
.mab-line-support:hover { transform: translateY(-2px); box-shadow: 0 13px 32px rgba(0, 70, 35, .32); }
.mab-line-support:focus-visible { outline: 3px solid var(--focus, #1a90f5); outline-offset: 4px; }
.mab-line-support svg { width: 36px; height: 36px; }
.mab-line-support-label {
  position: absolute;
  right: 64px;
  width: max-content;
  max-width: min(260px, calc(100vw - 110px));
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-size: var(--t-small);
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translateX(4px);
  transition: opacity .15s ease, transform .15s ease;
}
.mab-line-support:hover .mab-line-support-label,
.mab-line-support:focus-visible .mab-line-support-label { opacity: 1; transform: translateX(0); }
body.prompt-expanded .mab-line-support,
body.result-editor-expanded .mab-line-support { display: none; }
@media (max-width: 640px) {
  .mab-line-support { width: 52px; height: 52px; right: max(14px, env(safe-area-inset-right)); }
  .mab-line-support svg { width: 33px; height: 33px; }
  .mab-line-support-label { display: none; }
}

/* ============================================================
   Premium editorial refinement — Precision Intelligence
   A restrained, information-led visual language for the live app.
   ============================================================ */
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  background:
    radial-gradient(90% 48% at 4% -8%, rgba(22, 119, 168, .09), transparent 60%),
    linear-gradient(180deg, var(--paper) 0%, color-mix(in srgb, var(--paper) 88%, var(--surface)) 100%);
}
[data-theme="dark"] body {
  background:
    radial-gradient(85% 44% at 8% -8%, rgba(99, 196, 232, .11), transparent 62%),
    linear-gradient(180deg, var(--paper), #071219);
}

a { color: var(--brand-strong); text-underline-offset: 3px; }
a:hover { color: var(--brand); }

:where(button, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
}

.app-bar {
  padding-inline: clamp(20px, 3.2vw, 52px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom-color: color-mix(in srgb, var(--line) 82%, transparent);
  box-shadow: 0 8px 30px -28px rgba(16, 42, 54, .55);
}
.brand-mark { gap: 11px; font-size: 16px; font-weight: 720; letter-spacing: -.025em; }
.brand-mark .glyph {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border-color: color-mix(in srgb, var(--brand) 24%, var(--line));
  box-shadow: 0 8px 22px -16px rgba(13, 82, 111, .7);
}
.icon-btn,
button.secondary { background: color-mix(in srgb, var(--surface) 92%, transparent); }

.page { padding: clamp(56px, 6.5vw, 96px) clamp(20px, 3.8vw, 52px) var(--s7); }

.lede {
  position: relative;
  margin-bottom: clamp(52px, 6vw, 82px);
  padding-bottom: clamp(34px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
}
.lede::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: clamp(96px, 13vw, 176px);
  height: 2px;
  background: linear-gradient(90deg, var(--brand-strong), var(--brand));
}
.lede-eyebrow {
  margin: 0 0 16px !important;
  color: var(--brand-strong) !important;
  font-size: 11px !important;
  font-weight: 760;
  line-height: 1.4 !important;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.lede-eyebrow,
.lede h1,
.lede > p.note,
.orchestration-rail,
.composer {
  animation: editorialReveal 280ms cubic-bezier(.16, 1, .3, 1) both;
}
.lede h1 { animation-delay: 35ms; }
.lede > p.note { animation-delay: 70ms; }
.orchestration-rail { animation-delay: 105ms; }
.composer { animation-delay: 140ms; }
@keyframes editorialReveal {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.lede h1 {
  max-width: none;
  margin-bottom: 18px;
  font-size: clamp(32px, 3.1vw, 44px);
  font-weight: 730;
  line-height: 1.11;
  letter-spacing: -.045em;
}
.lede h1 em {
  color: var(--brand-strong);
  background: none;
  -webkit-text-fill-color: currentColor;
}
.lede > p.note:not(.lede-eyebrow) {
  max-width: 84ch;
  color: var(--ink-2);
  font-size: clamp(16px, 1.45vw, 20px);
  line-height: 1.72;
  letter-spacing: -.012em;
}
html[lang="th"] .lede h1 {
  font-size: clamp(27px, 2.85vw, 40px);
  letter-spacing: -.045em;
}

.orchestration-rail {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin-top: clamp(34px, 4vw, 52px);
}
.orchestration-rail > div {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 11px;
  min-width: 0;
  padding: 17px 18px 0 0;
  border-top: 1px solid var(--line-strong);
}
.orchestration-rail > div:not(:last-child)::after {
  content: "";
  position: absolute;
  top: -3px;
  right: 12px;
  width: 5px;
  height: 5px;
  border-top: 1px solid var(--line-strong);
  border-right: 1px solid var(--line-strong);
  transform: rotate(45deg);
}
.orchestration-rail span {
  color: var(--brand);
  font-size: 10px;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  letter-spacing: .08em;
}
.orchestration-rail strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 640;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer {
  grid-template-columns: minmax(0, 1.72fr) minmax(320px, .88fr);
  gap: clamp(20px, 2.4vw, 34px);
  margin-bottom: clamp(72px, 8vw, 108px);
}
.prompt-shell { min-height: 286px; }
textarea#prompt-input {
  min-height: 286px;
  padding: 24px 58px 24px 24px;
  border-color: var(--line-strong);
  border-radius: var(--r-panel);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  font-size: 16px;
  line-height: 1.72;
  box-shadow: 0 22px 54px -44px rgba(16, 42, 54, .55);
}
textarea#prompt-input:hover { border-color: color-mix(in srgb, var(--brand) 38%, var(--line-strong)); }
.prompt-size-btn,
.result-size-btn { border-radius: 7px; box-shadow: none; }

.prompt-templates { gap: 2px 16px; margin-top: 14px; }
.template-label { flex-basis: 100%; margin-bottom: 2px; color: var(--ink-3); letter-spacing: .035em; }
.template-chip {
  padding: 5px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink-2);
}
.template-chip:hover,
.template-chip:focus-visible {
  border-bottom-color: var(--brand);
  background: transparent;
  color: var(--brand-strong);
}
.workflow-controls { margin-top: 18px; }
.workflow-controls label { font-size: 11px; letter-spacing: .035em; }
.workflow-controls select { min-height: 42px; border-color: var(--line-strong); background: var(--surface); }
.token-estimate {
  margin-top: 16px;
  padding: 8px 0;
  border-width: 1px 0;
  border-radius: 0;
  background: transparent;
}
.token-estimate-item { border: 0; border-right: 1px solid var(--line); border-radius: 0; background: transparent; }
.token-estimate-item:nth-child(4) { border-right: 0; }

.composer-side { gap: 14px; }
.auth-card,
.run-panel {
  border-color: var(--line-strong);
  border-radius: var(--r-panel);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 24px 54px -44px rgba(16, 42, 54, .62);
}
.auth-card { background: var(--surface); }
.auth-head .eyebrow { letter-spacing: .12em; }
.auth-purpose,
.auth-channel,
.lang-switch { border-radius: 7px; }
.auth-purpose button,
.auth-channel button,
.lang-btn { border-radius: 5px; }
.run-panel { position: relative; overflow: hidden; padding: 22px; }
.run-panel::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
}
.run-panel .mode-chip,
.run-panel .meta-line.spend-chip,
.pc-spend,
.cost-badge { border-radius: 6px; }

button.primary {
  min-height: 48px;
  border: 1px solid color-mix(in srgb, var(--brand-strong) 88%, black);
  border-radius: 8px;
  background: var(--brand-strong);
  font-weight: 680;
  box-shadow: var(--shadow-brand);
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}
button.primary:hover {
  background: color-mix(in srgb, var(--brand-strong) 88%, black);
  filter: none;
  box-shadow: 0 18px 36px -24px rgba(13, 82, 111, .82);
  transform: translateY(-1px);
}
[data-theme="dark"] button.primary {
  border-color: #4ca7c6;
  background: #2b7d99;
  color: #ffffff;
}
[data-theme="dark"] button.primary:hover { background: #246f89; }

#tracking-consent { max-width: 760px; left: 50%; right: auto; transform: translateX(-50%); }
#tracking-consent button.primary { width: auto; min-height: 38px; padding: 8px 18px; flex: none; }
#tracking-consent button.secondary { flex: none; }

#board-wrap { margin-bottom: clamp(78px, 8vw, 112px); }
.phase-title {
  gap: 14px;
  margin: clamp(68px, 7vw, 96px) 0 24px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 710;
  letter-spacing: .015em;
  text-transform: none;
}
.phase-title::before {
  content: attr(data-step);
  width: auto;
  height: auto;
  border-radius: 0;
  background: transparent;
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .09em;
  font-variant-numeric: tabular-nums;
}
.phase-title::after {
  height: 1px;
  border-radius: 0;
  background: linear-gradient(90deg, var(--line-strong), color-mix(in srgb, var(--line) 20%, transparent));
}
.board-title { margin-top: 0; }

.model-board { gap: 14px; }
.provider-card,
.model-card {
  border-color: var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 97%, transparent);
  box-shadow: none;
}
.provider-card { overflow: visible; }
.provider-card::before {
  content: "";
  position: absolute;
  inset: -1px auto -1px -1px;
  width: 3px;
  border-radius: 12px 0 0 12px;
  background: transparent;
  transition: background .16s ease;
}
.provider-card.on {
  border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
  box-shadow: 0 16px 44px -40px rgba(13, 82, 111, .78);
}
.provider-card.on::before { background: var(--brand); }
.pc-head { padding-top: 16px; }
.pc-title { font-weight: 680; letter-spacing: -.015em; }
.pc-trigger { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.pc-trigger:hover { background: var(--surface-2); }
.phase-empty {
  min-height: 132px;
  border-color: var(--line-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 54%, transparent);
  color: var(--ink-3);
}
.result-editor {
  border-color: var(--line);
  background: color-mix(in srgb, var(--surface-2) 66%, var(--surface));
  line-height: 1.7;
}
.final-answer-card,
.final-card {
  border-color: color-mix(in srgb, var(--brand) 38%, var(--line));
  background: color-mix(in srgb, var(--brand-tint) 48%, var(--surface));
}
.final-card::before { background: var(--brand-strong); }
.final-card h3 { color: var(--brand-strong); }

.site-footer {
  margin-top: 120px;
  padding-top: 38px;
  border-top-color: var(--line-strong);
  gap: 12px clamp(24px, 4vw, 58px);
}
.site-footer a { font-size: 12px; }
.pricing-disclaimer { margin-top: 72px; }

/* Secondary public pages inherit the same restrained editorial language. */
body > main.card.legal,
body > main.card.pricing,
.wrap > .card.legal {
  border-color: var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 28px 72px -58px rgba(16, 42, 54, .62);
}
body > main.card.legal > h1,
body > main.card.pricing > h1,
.wrap > .card.legal > h1 { letter-spacing: -.035em; }

.legal-page,
.pricing-page,
.usage-page-shell { background-attachment: fixed; }
.legal-page > main.card.legal,
.pricing-page > main.card.pricing {
  width: calc(100% - 40px);
  margin: clamp(36px, 6vw, 76px) auto;
  padding: clamp(28px, 4.5vw, 64px);
}
.legal-page > main.card.legal { max-width: 900px; }
.legal-page > main.card.legal > h1,
.pricing-page > main.card.pricing > h1 {
  margin: 28px 0 10px;
  color: var(--ink);
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.12;
}
.legal-page > main.card.legal h2 {
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--brand-strong);
  font-size: 18px;
}
.legal-page > main.card.legal h3 { color: var(--ink); font-size: 15px; }
.legal-page > .wrap {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(28px, 4vw, 56px) 0;
}
.legal-page > .wrap > .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.legal-page > .wrap > .topbar h1 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.legal-page > .wrap > .card.legal { padding: clamp(28px, 4.5vw, 60px); }
.pricing-page > main.card.pricing { max-width: 1180px; }
.pricing-page .pricing-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; margin-top: 36px; }
.pricing-page .price-card {
  position: relative;
  min-height: 100%;
  border-color: var(--line-strong);
  border-radius: 12px;
  padding: 28px;
  overflow: hidden;
}
.pricing-page .price-card:nth-child(1) { grid-column: span 5; }
.pricing-page .price-card:nth-child(2) { grid-column: span 7; }
.pricing-page .price-card:nth-child(3) {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(190px, .7fr) minmax(0, 1.8fr);
  gap: 4px 36px;
  align-items: start;
}
.pricing-page .price-card:nth-child(3) h2,
.pricing-page .price-card:nth-child(3) .price { grid-column: 1; }
.pricing-page .price-card:nth-child(3) ul,
.pricing-page .price-card:nth-child(3) .note { grid-column: 2; }
.pricing-page .price-card:nth-child(3) ul { grid-row: 1 / span 2; margin-top: 0; }
.pricing-page .price-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--brand);
}
.pricing-page .price { color: var(--brand-strong); font-size: 32px; letter-spacing: -.035em; }
.pricing-page .price-card a.primary,
.pricing-page .price-card a.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin-top: 12px;
  padding: 9px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 680;
}
.pricing-page .price-card a.primary { background: var(--brand-strong); color: #fff; }
.pricing-page .price-card a.secondary { border: 1px solid var(--line-strong); color: var(--ink); }
.pricing-page .note-box { border: 1px solid var(--amber-line); }

@media (max-width: 1020px) {
  .composer { grid-template-columns: minmax(0, 1.5fr) minmax(300px, .9fr); }
  .model-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html[lang="th"] .lede h1 { font-size: clamp(24px, 3vw, 32px); }
}

@media (max-width: 860px) {
  .page { padding-top: 48px; }
  .composer { grid-template-columns: 1fr; }
  .orchestration-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 0; }
  .composer-side { position: static; }
  .prompt-shell,
  textarea#prompt-input { min-height: 260px; }
  .phase-title { margin-top: 72px; }
  .pricing-page .price-card:nth-child(n) { grid-column: 1 / -1; }
  .pricing-page .price-card:nth-child(3) { display: block; }
}

@media (max-width: 560px) {
  :root { --bar-h: 64px; }
  .app-bar { padding-inline: 14px; }
  .bar-actions .lang-btn,
  .bar-actions .icon-btn,
  .bar-actions #settings-btn { min-height: 44px; }
  .bar-actions .icon-btn { width: 44px; }
  .bar-actions #settings-btn { padding-inline: 12px; }
  .brand-mark .glyph { width: 38px; height: 38px; }
  .page { padding: 38px 18px 76px; }
  .lede { margin-bottom: 38px; padding-bottom: 34px; }
  .lede-eyebrow { margin-bottom: 12px !important; font-size: 9.5px !important; letter-spacing: .12em; }
  html[lang="th"] .lede h1,
  .lede h1 { font-size: clamp(25px, 7.1vw, 31px); line-height: 1.16; }
  .lede > p.note:not(.lede-eyebrow) { font-size: 15px; line-height: 1.68; }
  .orchestration-rail { margin-top: 30px; }
  .orchestration-rail > div { padding-top: 12px; grid-template-columns: auto 1fr; }
  .orchestration-rail strong { font-size: 11px; }
  .composer { margin-bottom: 76px; }
  .prompt-shell,
  textarea#prompt-input { min-height: 280px; }
  textarea#prompt-input { padding: 20px 52px 20px 18px; font-size: 15px; }
  .prompt-size-btn,
  .result-size-btn { width: 44px; height: 44px; right: 8px; }
  .template-chip { min-height: 44px; display: inline-flex; align-items: center; }
  button.secondary,
  button.ghost,
  .usage-history-link { min-height: 44px; }
  .token-estimate { grid-template-columns: 1fr 1fr; }
  .token-estimate-item:nth-child(2) { border-right: 0; }
  .model-board { grid-template-columns: 1fr; }
  .phase-title { gap: 10px; margin-top: 64px; font-size: 12.5px; }
  .site-footer { margin-top: 80px; padding-inline: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
