/* =============================================================
   SekJote.com — UI tokens + components (Batch 1: trust+friction)
   ============================================================= */

:root {
  /* ---- Design system (design-system/latex-doc-online/MASTER.md) ----
     "Document grey + scan blue": Swiss-minimal, slate navy structure,
     one confident blue for action. Old --brand-*/--ink-* names kept as
     aliases so the component layer updates without rewrites. */

  /* Canonical semantic tokens */
  --color-primary:       #1E293B;  /* slate-800 — headings, dark surfaces */
  --color-primary-hover: #0F172A;
  --color-accent:        #2563EB;  /* blue-600 — the single action color */
  --color-accent-hover:  #1D4ED8;
  --color-accent-weak:   #EFF4FE;  /* selected rows / chips wash */
  --color-foreground:    #0F172A;
  --color-muted:         #64748B;  /* >=4.5:1 on white */
  --color-border:        #E2E8F0;
  --color-surface:       #FFFFFF;
  --color-surface-tint:  #F1F5F9;
  --color-background:    #F8FAFC;

  /* Brand aliases (action = blue, deep ink = navy) */
  --brand-50:  #EFF4FE;
  --brand-100: #DBE7FB;
  --brand-500: #2563EB;
  --brand-700: #1D4ED8;
  --brand-900: #1E293B;

  /* Semantic */
  --success: #15803D;
  --success-bg: #E7F4EC;
  --warning: #B45309;
  --warning-bg: #FBF0DC;
  --danger:  #DC2626;
  --danger-bg: #FDECEA;
  --paid:    #A85518;   /* answer-key add-on = the paid action */
  --paid-hover: #8B4814;

  /* Neutrals (slate ramp) */
  --ink-900: #0F172A;
  --ink-700: #334155;
  --ink-500: #64748B;
  --ink-300: #94A3B8;
  --line:    #E2E8F0;
  --bg:      #F8FAFC;
  --surface: #FFFFFF;
  --surface-tint: #F1F5F9;
  --surface-selected: #EFF4FE;

  /* Fonts */
  --font-ui: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Menlo", "Consolas", monospace;

  /* Type (16px base) */
  --t-xs:  12px;
  --t-sm:  14px;
  --t-md:  16px;
  --t-lg:  20px;
  --t-xl:  25px;
  --t-2xl: 32px;

  /* Spacing (4px base) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px;  --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px;

  /* Radius — soft, not bubbly */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;

  /* Elevation — slate-tinted, shadow only for real elevation */
  --shadow-1: 0 1px 2px rgba(15,23,42,.06);
  --shadow-2: 0 4px 12px rgba(15,23,42,.10);
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }

/* The HTML `hidden` attribute is how we toggle auth panel / sidebar /
   workspace / the signup-only name field. Author rules like
   `label{display:grid}` and `.workspace{display:grid}` otherwise win over the
   UA `[hidden]{display:none}` (author origin beats UA), leaving "hidden"
   elements visible — e.g. the display-name field showing on the login tab and
   the workspace leaking under the login form. Force it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-900);
  font-family: var(--font-ui);
  font-size: var(--t-md);
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;   /* Thai needs more leading than Latin */
}

button, input { font: inherit; }

/* ---------- buttons ---------- */
button {
  min-height: 40px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--brand-500);
  color: #fff;
  padding: 0 var(--s-4);
  cursor: pointer;
  transition: background 120ms, box-shadow 120ms, transform 60ms;
}
button:hover { background: var(--brand-700); }
button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}

button.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-700);
}
button.ghost:hover { background: var(--surface-tint); }

button.text-only {
  background: transparent;
  color: var(--ink-500);
  min-height: 32px;
  padding: 0 var(--s-2);
}
button.text-only:hover {
  background: var(--surface-tint);
  color: var(--ink-700);
}

.btn-primary-large {
  width: 100%;
  min-height: 52px;
  font-size: var(--t-md);
  font-weight: 600;
  padding: var(--s-2) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
}
.btn-primary-large .btn-meta {
  font-weight: 400;
  font-size: var(--t-xs);
  opacity: .85;
}

/* ---------- inputs ---------- */
input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  color: var(--ink-900);
  transition: border-color 120ms, box-shadow 120ms;
}
input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}
input::placeholder { color: var(--ink-300); }
input[type="checkbox"] { accent-color: var(--brand-500); }

label {
  display: grid;
  gap: var(--s-1);
  color: var(--ink-500);
  font-size: var(--t-sm);
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar h1 { margin: 0; font-size: var(--t-xl); color: var(--brand-900); }
.brand-h1 { display: flex; align-items: center; gap: 10px; font-family: "Kanit", "IBM Plex Sans Thai", sans-serif; font-weight: 700; font-size: 28px; }
.brand-h1 .brand-logo { width: 36px; height: 36px; flex-shrink: 0; }
.brand-h1 small { font-family: "IBM Plex Sans Thai", sans-serif; font-size: 13px; font-weight: 500; color: var(--ink-500); }
.topbar p  { margin: 3px 0 0; color: var(--ink-500); font-size: var(--t-sm); }

.account {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-3);
  color: var(--ink-500);
  white-space: nowrap;
  font-size: var(--t-sm);
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--s-4);
  padding: var(--s-4);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.auth-panel {
  grid-column: 1 / -1;
  width: min(440px, calc(100vw - 32px));
  margin: 48px auto;
  padding: var(--s-5);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
  margin-bottom: var(--s-4);
}
.tab { background: var(--surface-tint); color: var(--ink-700); }
.tab.active { background: var(--brand-500); color: #fff; }

.form, .build-panel {
  display: grid;
  gap: var(--s-3);
}

.otp-actions { display: flex; justify-content: space-between; align-items: center; }
#otpCode {
  letter-spacing: 10px; text-align: center;
  font-size: 24px; font-family: var(--font-mono);
}

.sidebar {
  align-self: start;
  padding: var(--s-3);
  max-height: calc(100vh - 116px);
  overflow: auto;
}

.section-title {
  margin-bottom: var(--s-3);
  color: var(--ink-900);
  font-size: var(--t-sm);
  font-weight: 700;
  letter-spacing: .02em;
}

.topic-list { display: grid; gap: var(--s-2); }

.topic-button {
  width: 100%;
  min-height: auto;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-900);
  text-align: left;
}
.topic-button:hover { background: var(--surface-tint); }
.topic-button.active {
  border-color: var(--brand-500);
  background: var(--surface-selected);
}
.topic-meta {
  display: block;
  margin-top: 2px;
  color: var(--ink-500);
  font-size: var(--t-xs);
}

/* ---------- workspace + toolbar ---------- */
.workspace { display: grid; gap: var(--s-4); }
.toolbar {
  display: flex;
  align-items: end;
  gap: var(--s-4);
  padding: var(--s-3);
}
.search { flex: 1; }
.checkbox {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 40px;
  color: var(--ink-900);
}
.checkbox input { width: auto; min-height: auto; }

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: stretch;
  gap: var(--s-4);
  height: calc(100vh - 152px);
  min-height: 560px;
}

.question-panel, .build-panel {
  padding: var(--s-3);
  min-height: 0;
}
.question-panel {
  overflow: auto;
  align-self: start;            /* don't force-stretch, so the panel can be resized */
  height: calc(100vh - 152px);  /* default fills the column height */
  min-height: 420px;            /* roomier floor on shorter windows */
  max-height: 92vh;
  resize: vertical;             /* drag the bottom edge to make the list longer */
}
.build-panel {
  align-content: start;
  grid-auto-rows: max-content;
  height: 100%;
  overflow: auto;
  width: 100%;
}

/* ---------- question card ---------- */
.question-list { display: grid; gap: var(--s-3); }
.question {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3);
  background: var(--surface);
  transition: border-color 120ms, background 120ms;
}
.question.selected {
  border-color: var(--brand-500);
  background: var(--surface-selected);
}

.question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.question-head strong { font-size: var(--t-sm); color: var(--ink-700); letter-spacing: .02em; }
.question-position {
  display: inline-block;
  margin-left: var(--s-2);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-100);
  color: var(--brand-900);
  font-size: var(--t-xs);
  font-weight: 600;
}

.question-select {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 36px;
  padding: 0 var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-700);
  cursor: pointer;
  background: var(--surface);
}
.question-select:hover { background: var(--surface-tint); }
.question-select input { width: 18px; min-height: 18px; }
.question.selected .question-select {
  border-color: var(--brand-500);
  background: var(--brand-50);
  color: var(--brand-900);
}

.question-preview {
  margin-top: var(--s-3);
  color: var(--ink-700);
  font-size: var(--t-md);
  line-height: 1.7;
}
.question-preview ol { margin: var(--s-2) 0 0 var(--s-6); padding: 0; }
.question-preview li { margin: var(--s-1) 0; }
.question-preview .katex { font-size: 1.04em; }

pre {
  margin: var(--s-2) 0 0;
  white-space: pre-wrap;
  color: var(--ink-700);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}

/* ---------- cart (with preview + drag) ---------- */
.cart {
  display: grid;
  gap: var(--s-2);
  min-height: 56px;
}

.cart-empty {
  padding: var(--s-4);
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--ink-500);
  font-size: var(--t-sm);
  text-align: center;
  background: var(--surface-tint);
}

.cart-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: var(--s-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s-2);
  background: var(--surface);
  cursor: grab;
  transition: background 120ms, border-color 120ms, opacity 120ms;
}
.cart-item:hover { background: var(--surface-tint); }
.cart-item.dragging { opacity: .4; cursor: grabbing; }
.cart-item.drag-over { border-color: var(--brand-500); background: var(--brand-50); }

.cart-handle {
  color: var(--ink-300);
  font-size: 14px;
  line-height: 1;
  letter-spacing: -2px;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-body { min-width: 0; }   /* allow text-overflow inside grid */

.cart-line {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--t-sm);
}
.cart-num {
  font-weight: 600;
  color: var(--brand-900);
  min-width: 18px;
}
.cart-code {
  flex: 1;
  color: var(--ink-700);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-remove {
  min-height: 26px;
  padding: 0 var(--s-2);
  font-size: var(--t-xs);
  background: transparent;
  color: var(--ink-500);
  border: 1px solid transparent;
}
.cart-remove:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-bg);
}

.cart-preview {
  margin-top: 4px;
  color: var(--ink-500);
  font-size: var(--t-xs);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- status pill (replaces plain message) ---------- */
.status-pill {
  display: none;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
  font-weight: 500;
  min-height: 36px;
}
.status-pill.visible { display: inline-flex; }
.status-pill .status-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.status-pill.state-rendering,
.status-pill.state-queued {
  background: var(--brand-50);
  color: var(--brand-900);
}
.status-pill.state-rendering .status-icon::before {
  content: "";
  width: 14px; height: 14px;
  border: 2px solid var(--brand-100);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.status-pill.state-queued .status-icon::before { content: "⏳"; }

.status-pill.state-ready {
  background: var(--success-bg);
  color: var(--success);
}
.status-pill.state-ready .status-icon::before { content: "✓"; font-weight: 700; }

.status-pill.state-failed {
  background: var(--danger-bg);
  color: var(--danger);
}
.status-pill.state-failed .status-icon::before { content: "⚠"; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- messages (generic, for form errors etc.) ---------- */
.message {
  min-height: 22px;
  color: var(--ink-500);
  font-size: var(--t-sm);
}
.message.error { color: var(--danger); }

/* ---------- downloads + build actions ---------- */
.downloads { display: grid; gap: var(--s-2); }
.downloads button {
  background: var(--paid);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 44px;
}
.downloads button:hover { background: #8b4814; }
.downloads button.is-student {
  background: var(--brand-500);
}
.downloads button.is-student:hover { background: var(--brand-700); }

/* Primary action sits at top; reset is a separate text button below a hairline */
.build-actions {
  display: grid;
  gap: var(--s-3);
  margin-top: var(--s-2);
}
.build-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: var(--s-2) 0 0;
}
#clearPaper {
  justify-self: start;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .topbar, .toolbar, .account {
    align-items: stretch;
    flex-direction: column;
  }
  .layout, .columns {
    grid-template-columns: 1fr;
  }
  .columns { height: auto; min-height: 0; }
  .sidebar { max-height: none; }
  .question-panel { overflow: visible; resize: none; height: auto; min-height: 0; max-height: none; }
  .build-panel { height: auto; }
}

/* =============================================================
   Design-system additions (MASTER.md): difficulty chip, meta row,
   skeleton loading, reduced-motion guard.
   ============================================================= */

/* Meta row under a question code: difficulty + est. time.
   Color is never the only signal — each chip carries an icon glyph + text. */
.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: 2px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--t-xs);
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface-tint);
  color: var(--ink-700);
  white-space: nowrap;
}
.chip .chip-glyph { font-size: 11px; line-height: 1; }
.chip-diff-1 { background:#ecfdf3; border-color:#bbf7d0; color:#15803d; } /* ง่ายมาก */
.chip-diff-2 { background:#ecfdf3; border-color:#bbf7d0; color:#15803d; } /* ง่าย */
.chip-diff-3 { background:#fef9ec; border-color:#fde68a; color:#b45309; } /* กลาง */
.chip-diff-4 { background:#fdeee6; border-color:#fed7aa; color:#9a3412; } /* ยาก */
.chip-diff-5 { background:#fdecec; border-color:#fecaca; color:#b91c1c; } /* ท้าทาย */
.chip-time { color: var(--ink-500); }

/* Skeleton rows for the question list while loading (>300ms). */
.skeleton-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3);
  background: var(--surface);
}
.skeleton-line {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-tint) 25%, #e9eef4 37%, var(--surface-tint) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
.skeleton-line + .skeleton-line { margin-top: var(--s-2); }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-90 { width: 90%; }
.skeleton-line.w-70 { width: 70%; }

@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* Respect reduced motion: kill spinners/shimmer/transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ---------- checkout modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--s-6);
  background: rgba(15,23,42,.45);
  overflow: auto;
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  margin: auto;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: 0 16px 40px rgba(15,23,42,.25);
  padding: var(--s-6);
  display: grid; gap: var(--s-3);
}
.modal-close {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px; min-height: 32px; padding: 0;
  background: var(--surface-tint); color: var(--ink-700);
}
.modal-close:hover { background: var(--line); }
.modal-title { margin: 0 var(--s-6) 0 0; font-size: var(--t-lg); color: var(--brand-900); }
.co-plan {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 1px solid var(--line); padding-bottom: var(--s-2);
}
.co-plan strong { font-size: var(--t-xl); color: var(--brand-900); }
.co-qr { display: grid; place-items: center; padding: var(--s-2); }
.co-qr canvas { border-radius: var(--r-sm); }
.co-info { margin: 0; display: grid; gap: 4px; }
.co-info div { display: flex; justify-content: space-between; gap: var(--s-3); font-size: var(--t-sm); }
.co-info dt { color: var(--ink-500); margin: 0; }
.co-info dd { margin: 0; font-weight: 600; color: var(--ink-900); font-family: var(--font-mono); }
.co-count { color: var(--brand-700) !important; }
.co-hint { margin: 0; font-size: var(--t-xs); color: var(--ink-500); }
.co-upload { gap: var(--s-2); }
.co-upload input { padding: 6px; }

/* current-plan chip in the topbar */
.plan-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--brand-50); color: var(--brand-900);
  font-size: var(--t-xs); font-weight: 600; white-space: nowrap;
}
.plan-chip.is-free { background: var(--surface-tint); color: var(--ink-700); }

/* wide modal for the plan picker */
.modal-card-wide { width: min(900px, 100%); }
.plan-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); margin-top: var(--s-2); }
.plan-card {
  border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4);
  display: grid; gap: var(--s-2); align-content: start;
}
.plan-card.is-current { border-color: var(--success); background: var(--success-bg); }
.plan-card h3 { margin: 0; font-size: var(--t-md); color: var(--brand-900); }
.plan-card .price { font-size: var(--t-xl); font-weight: 700; color: var(--ink-900); }
.plan-card .price small { font-size: var(--t-sm); font-weight: 400; color: var(--ink-500); }
.plan-card ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.plan-card li { font-size: var(--t-sm); color: var(--ink-700); }
.plan-card .pick { width: 100%; margin-top: var(--s-2); }
.plan-card .current-tag { font-size: var(--t-xs); color: var(--success); font-weight: 600; text-align: center; }
@media (max-width: 720px) { .plan-list { grid-template-columns: 1fr; } }

/* upgrade paywall banner (shown on 402 in the build panel) */
.upgrade-note {
  border: 1px solid var(--line);
  background: var(--brand-50);
  border-radius: var(--r-md);
  padding: var(--s-3);
  display: grid; gap: var(--s-2);
  font-size: var(--t-sm); color: var(--brand-900);
}
.upgrade-note button { min-height: 40px; }

/* ---------- recent papers (history) modal ---------- */
.history-list { display: grid; gap: var(--s-2); margin-top: var(--s-2); }
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.hist-info { display: grid; gap: 4px; min-width: 0; }
.hist-title { font-weight: 600; color: var(--ink-900); }
.hist-keytag {
  font-size: var(--t-xs); font-weight: 600; color: var(--paid);
  background: var(--warning-bg); border-radius: 999px; padding: 1px 8px;
}
.hist-meta {
  display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap;
  font-size: var(--t-sm); color: var(--ink-500);
}
.hist-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.hist-actions button { min-height: 34px; padding: 6px 12px; font-size: var(--t-sm); }

/* compact status badge — reuses .status-pill colours with a smaller footprint */
.status-pill.hist-status { min-height: 0; padding: 2px 8px; font-size: var(--t-xs); font-weight: 600; }
.status-pill.state-idle { background: var(--surface-tint); color: var(--ink-500); }

/* ---------- account modal ---------- */
.account-body { display: grid; gap: var(--s-5); margin-top: var(--s-2); }
.account-section { display: grid; gap: var(--s-2); }
.account-section h3 {
  margin: 0; font-size: var(--t-md); color: var(--brand-900);
  border-bottom: 1px solid var(--line); padding-bottom: var(--s-2);
}
.account-dl { margin: 0; display: grid; gap: var(--s-2); }
.account-dl div { display: flex; justify-content: space-between; gap: var(--s-3); font-size: var(--t-sm); }
.account-dl dt { color: var(--ink-500); margin: 0; }
.account-dl dd { margin: 0; font-weight: 600; color: var(--ink-900); }
.account-name { font-size: var(--t-sm); color: var(--ink-700); }
.account-name-row { display: flex; gap: var(--s-2); align-items: stretch; }
.account-name-row input { flex: 1; min-width: 0; }
.account-name-row button { min-height: 0; padding: 8px 16px; white-space: nowrap; }
.account-name-msg { min-height: 18px; font-size: var(--t-xs); }

.billing-table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.billing-table th, .billing-table td {
  text-align: left; padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line); vertical-align: middle;
}
.billing-table th { color: var(--ink-500); font-weight: 600; font-size: var(--t-xs); }
.billing-table .bill-ref { font-family: var(--font-mono); color: var(--ink-500); font-size: var(--t-xs); }
@media (max-width: 720px) {
  .billing-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- tag filter (sidebar) + tag chips on cards ---------- */
.tag-filter-title { margin-top: var(--s-4); }
.tag-filter { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.tag-chip {
  min-height: auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--t-xs);
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-700);
}
.tag-chip:hover { background: var(--surface-tint); }
.tag-chip.active {
  border-color: var(--brand-500);
  background: var(--brand-500);
  color: #fff;
}
.tag-chip .tag-count { font-size: 10px; font-weight: 600; opacity: .65; }
.tag-chip.active .tag-count { opacity: .9; }
.tag-clear { padding: 3px 6px; }

/* read-only tag chips on each question card (extend the .chip base) */
.tag-chip-static { cursor: default; }
.tag-chip-static.is-selected {
  border-color: var(--brand-500);
  background: var(--brand-50);
  color: var(--brand-900);
}
.chip-figure { background: var(--brand-50); color: var(--brand-900); border-color: var(--brand-100); }

/* ----- tag search (search-then-select) ----- */
.tag-search {
  width: 100%;
  margin-bottom: var(--s-2);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-900);
  font: inherit;
}
.tag-selected { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.tag-selected:not(:empty) { margin-bottom: var(--s-2); }
.tag-results { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.tag-x { font-weight: 700; margin-left: 2px; }

/* ----- premium (สอวน.) lock ----- */
.topic-button.is-locked { opacity: .9; }
.topic-button.is-locked .topic-meta { color: #b45309; }
.chip-lock { background: #fdf6e3; border-color: #fde68a; color: #92400e; font-weight: 600; }
.question.is-locked { opacity: .62; }
.question.is-locked .question-select,
.question.is-locked input[type="checkbox"] { cursor: not-allowed; }
