/* ═══════════════════════════════════════════════════════════════════════════
   components.css — reusable UI: buttons, badges, inputs, menus, dialogs,
   table/log, detail panel, stats, forms, lists, init overlay.
   Layout & responsive rules live in layout.css.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Buttons: shared base ────────────────────────────────────────────────── */
.header-btn, .action-btn, .menu-item, .filter, .tab-btn, .lang-btn, .model-btn {
  font-family: var(--font-display);
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}

/* Header / appbar buttons */
.header-btn {
  background: transparent;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold);
  font-size: var(--fs-xs);
  padding: 6px 12px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.header-btn:hover { background: rgba(212,168,75,0.1); box-shadow: inset 0 0 8px rgba(212,168,75,0.12); }
.header-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.danger-btn { border-color: rgba(180,60,60,0.45); color: var(--danger); }
.danger-btn:hover { background: rgba(180,60,60,0.12); border-color: rgba(220,80,80,0.7); box-shadow: inset 0 0 8px rgba(180,60,60,0.15); }

/* Mic states */
#mic-btn.mic-off { border-color: rgba(138,125,96,0.5); color: var(--muted); }
#mic-btn.mic-on  { border-color: var(--success-dim); color: var(--success); box-shadow: 0 0 8px rgba(74,159,112,0.25); }

#sync-btn .sync-icon { display: inline-block; }
#sync-btn.syncing .sync-icon { animation: spin 0.8s linear infinite; }

/* Action buttons (inside dialogs/forms) */
.action-btn {
  background: rgba(212,168,75,0.1);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold);
  font-size: var(--fs-xs);
  padding: 8px 16px;
  white-space: nowrap;
  flex-shrink: 0;
}
.action-btn:hover { background: rgba(212,168,75,0.2); }
.action-btn.small { padding: 6px 12px; font-size: 10px; }
.action-btn.danger { border-color: var(--danger-dim); color: var(--danger); background: rgba(139,32,32,0.1); }
.action-btn.danger:hover { background: rgba(139,32,32,0.25); }

/* ── Overflow "More" menu ────────────────────────────────────────────────── */
.more-wrap { position: relative; }
.more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: var(--panel);
  background-image: var(--grain);
  background-size: 300px 300px;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: var(--z-menu);
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: fadeIn var(--dur-fast) var(--ease);
}
.menu-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--gold);
  font-size: var(--fs-xs);
  text-align: left;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
.menu-item:hover { background: rgba(212,168,75,0.12); }
.menu-item .mi-icon { width: 1.1em; text-align: center; opacity: 0.85; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: rgba(139,32,32,0.2); }
.menu-sep { height: 1px; background: var(--hairline); margin: 4px 6px; border: none; }

/* ── Notification chip ───────────────────────────────────────────────────── */
#notif-chip {
  background: rgba(212,168,75,0.08);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-pill);
  color: var(--gold);
  cursor: pointer;
  font-size: 12px;
  padding: 5px 12px;
  white-space: nowrap;
  transition: background var(--dur) var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
#notif-chip:hover { background: rgba(212,168,75,0.18); }

/* ── Search field + dropdown ─────────────────────────────────────────────── */
.search-wrap { position: relative; }

#search, #log-filter, .setting-select,
.save-form input[type="text"], .save-form textarea, .save-form select {
  background: var(--bg3);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  padding: 8px 11px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
#search { width: 200px; }
#log-filter { width: 220px; max-width: 100%; }
#search:focus, #log-filter:focus,
.save-form input[type="text"]:focus, .save-form textarea:focus, .save-form select:focus,
.setting-select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-glow);
}
#search::placeholder, #log-filter::placeholder { color: var(--muted); opacity: 0.7; font-style: normal; }

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  list-style: none;
  min-width: 240px;
  max-height: 280px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-md);
}
.dropdown li {
  padding: 11px 14px;
  cursor: pointer;
  font-size: var(--fs-sm);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.dropdown li:last-child { border-bottom: none; }
.dropdown li:hover, .dropdown li.active { background: var(--bg3); color: var(--gold); }

/* ── Filter chips ────────────────────────────────────────────────────────── */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }

.filter {
  background: transparent;
  border: 2px solid rgba(138,125,96,0.4);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: var(--fs-xs);
  padding: 5px 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
.filter::before { margin-right: 4px; opacity: 0.9; }
.filter[data-cat="spell"]     { --cat: var(--spell);     --cat-tint: var(--spell-tint); }
.filter[data-cat="condition"] { --cat: var(--condition); --cat-tint: var(--condition-tint); }
.filter[data-cat="status"]    { --cat: var(--status);    --cat-tint: var(--status-tint); }
.filter[data-cat="action"]    { --cat: var(--action);    --cat-tint: var(--action-tint); }
.filter[data-cat="rule"]      { --cat: var(--rule);      --cat-tint: var(--rule-tint); }
.filter[data-cat="sense"]     { --cat: var(--sense);     --cat-tint: var(--sense-tint); }
.filter[data-cat="skill"]     { --cat: var(--skill);     --cat-tint: var(--skill-tint); }
.filter[data-cat="feat"]      { --cat: var(--feat);      --cat-tint: var(--feat-tint); }
.filter[data-cat="item"]      { --cat: var(--item);      --cat-tint: var(--item-tint); }
.filter[data-cat="custom"]    { --cat: var(--custom);    --cat-tint: var(--custom-tint); }
.filter[data-cat="spell"]::before     { content: '✦'; }
.filter[data-cat="condition"]::before { content: '⚠'; }
.filter[data-cat="status"]::before    { content: '◈'; }
.filter[data-cat="action"]::before    { content: '⚡'; }
.filter[data-cat="rule"]::before      { content: '§'; }
.filter[data-cat="sense"]::before     { content: '👁'; }
.filter[data-cat="skill"]::before     { content: '✜'; }
.filter[data-cat="feat"]::before      { content: '★'; }
.filter[data-cat="item"]::before      { content: '⚔'; }
.filter[data-cat="custom"]::before    { content: '❖'; }
/* Edition + source source filter chips */
.filter[data-ed="2024"] { --cat: var(--ed-2024-bg); --cat-tint: var(--ed-2024-tint); }
.filter[data-ed="2014"] { --cat: var(--ed-2014-bg); --cat-tint: var(--ed-2014-tint); }
.filter[data-src] { --cat: var(--gold-dim); --cat-tint: var(--text); font-family: var(--font-mono); letter-spacing: 0; }
.filter:hover { color: var(--cat-tint, var(--gold)); border-color: var(--cat, var(--gold-dim)); }
.filter.active { border-color: var(--cat, var(--gold-dim)); background: var(--cat, rgba(212,168,75,0.12)); color: var(--cat-tint, var(--gold)); }

/* Reset chip — neutral, sits ahead of the category chips */
.filter-reset {
  border-color: var(--gold-dim);
  color: var(--gold);
  border-style: solid;
}
.filter-reset:hover { background: rgba(212,168,75,0.1); color: var(--gold); border-color: var(--gold); }

/* Source filter row (visually separated from category filters) */
.filter-source-row {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--hairline);
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: var(--fs-xs);
  font-family: var(--font-display);
  letter-spacing: 0.5px;
  padding: 2px 10px;
  text-transform: uppercase;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge > span { display: inline-block; }
.badge::before { margin-right: 4px; opacity: 0.85; }

.badge-spell      { background: var(--spell);      color: var(--spell-tint); }
.badge-condition  { background: var(--condition);  color: var(--condition-tint); }
.badge-status     { background: var(--status);     color: var(--status-tint); }
.badge-disease    { background: var(--disease);    color: var(--disease-tint); }
.badge-action     { background: var(--action);     color: var(--action-tint); }
.badge-rule       { background: var(--rule);       color: var(--rule-tint); }
.badge-sense      { background: var(--sense);      color: var(--sense-tint); }
.badge-skill      { background: var(--skill);      color: var(--skill-tint); }
.badge-feat       { background: var(--feat);       color: var(--feat-tint); }
.badge-optfeature { background: var(--optfeature); color: var(--optfeature-tint); }
.badge-item       { background: var(--item);       color: var(--item-tint); }
.badge-custom     { background: var(--custom);     color: var(--custom-tint); }
.badge-ability    { background: var(--ability);    color: var(--ability-tint); }
.badge-damage     { background: var(--damage);     color: var(--damage-tint); }
.badge-ed-2024    { background: var(--ed-2024-bg);  color: var(--ed-2024-tint); }
.badge-ed-2014    { background: var(--ed-2014-bg);  color: var(--ed-2014-tint); }

/* Non-color category cue: glyph echoes the filter iconography */
.badge-spell::before     { content: '✦'; }
.badge-condition::before { content: '⚠'; }
.badge-status::before    { content: '◈'; }
.badge-disease::before   { content: '☣'; }
.badge-action::before    { content: '⚡'; }
.badge-rule::before      { content: '§'; }
.badge-sense::before     { content: '👁'; }
.badge-skill::before     { content: '✜'; }
.badge-feat::before      { content: '★'; }
.badge-optfeature::before{ content: '✧'; }
.badge-item::before      { content: '⚔'; }
.badge-custom::before    { content: '❖'; }
.badge-ability::before   { content: '◆'; }
.badge-damage::before    { content: '✸'; }
/* Edition badges carry no category glyph */
.badge-ed-2024::before, .badge-ed-2014::before { content: none; }

/* ── Section labels ──────────────────────────────────────────────────────── */
.section-label {
  font-family: var(--font-display);
  color: var(--gold-dim);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: var(--ls-title);
  text-transform: uppercase;
  margin-bottom: 10px;
  margin-top: var(--space-5);
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-label::before { content: ''; display: inline-block; width: 24px; height: 1px; background: var(--gold-dim); }
.section-label::after  { content: ''; flex: 1; height: 1px; background: linear-gradient(to right, var(--gold-dim), transparent); }

/* Collapsible section header (Pinned) */
.section-toggle { cursor: pointer; user-select: none; }
.section-toggle:hover { color: var(--gold); }
.section-toggle .fold-caret { transition: transform var(--dur-fast) var(--ease); display: inline-block; }
.section-toggle.collapsed .fold-caret { transform: rotate(-90deg); }
.section-toggle:focus-visible { outline: 1px solid var(--gold-dim); outline-offset: 3px; }

/* ── Tables / log ────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }

thead th {
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid var(--gold-dim);
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: var(--ls-label);
  padding: 8px 12px;
  text-align: left;
  text-transform: uppercase;
}
.col-time    { width: 70px; }
.col-cat     { width: 150px; white-space: nowrap; }
.col-actions { width: 76px; text-align: right; }

tr.log-row {
  border-bottom: 1px solid rgba(255,255,255,0.04);
  border-left: 3px solid transparent;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  animation: slideIn var(--dur) var(--ease);
}
tr.log-row:nth-child(even) { background: var(--zebra); }
tr.log-row:hover { background: rgba(0,0,0,0.25); border-left-color: var(--row-accent, var(--gold-dim)); }
tr.log-row.cat-hidden, tr.log-row.filter-hidden { display: none; }

/* Per-category accent (used on hover here; always-on in mobile card view) */
tr.log-row[data-category="spell"]     { --row-accent: var(--spell); }
tr.log-row[data-category="condition"] { --row-accent: var(--condition); }
tr.log-row[data-category="status"]    { --row-accent: var(--status); }
tr.log-row[data-category="action"]    { --row-accent: var(--action); }
tr.log-row[data-category="rule"]      { --row-accent: var(--rule); }
tr.log-row[data-category="sense"]     { --row-accent: var(--sense); }
tr.log-row[data-category="skill"]     { --row-accent: var(--skill); }
tr.log-row[data-category="feat"]      { --row-accent: var(--feat); }
tr.log-row[data-category="item"]      { --row-accent: var(--item); }
tr.log-row[data-category="custom"]    { --row-accent: var(--custom); }

tr.log-row td { padding: 11px 12px; vertical-align: middle; }
.col-time { color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.col-name { cursor: pointer; transition: color var(--dur-fast) var(--ease), text-shadow var(--dur-fast) var(--ease); }
.col-name:hover { color: var(--gold); text-shadow: 0 0 12px rgba(212,168,75,0.5); }

/* Pin / dismiss row actions */
.btn-pin, .btn-dismiss {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 6px 7px;
  border-radius: var(--radius);
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.btn-pin:hover    { color: var(--gold);   transform: scale(1.15); }
.btn-dismiss:hover { color: var(--danger); transform: scale(1.15); }

/* Reveal actions on hover only when a real pointer is present (touch keeps them visible) */
@media (hover: hover) and (pointer: fine) {
  .col-actions { opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
  tr.log-row:hover .col-actions { opacity: 1; }
}

/* ── Pinned section ──────────────────────────────────────────────────────── */
#pinned-section {
  margin-bottom: 4px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(212,168,75,0.02) 8px, rgba(212,168,75,0.02) 9px);
  border-radius: var(--radius);
}
#pinned-section .section-label::before { content: '📌'; width: auto; background: none; font-size: 12px; }
#pinned tr.log-row { background: rgba(212,168,75,0.04); border-left: 3px solid var(--gold-dim); }
#pinned tr.log-row:hover { background: rgba(212,168,75,0.09); border-left-color: var(--gold); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-msg { color: var(--muted); font-family: var(--font-fancy); font-size: var(--fs-base); padding: 36px 10px; text-align: center; }
.empty-msg::before { display: block; content: '⁕'; font-size: 20px; letter-spacing: 8px; color: var(--gold-dim); margin-bottom: 12px; opacity: 0.6; }

/* ── Detail accordion ────────────────────────────────────────────────────── */
tr.detail-row td { padding: 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.detail-panel {
  background-color: rgba(22, 17, 8, 0.98);
  background-image: var(--grain);
  background-size: 300px 300px;
  border-left: 3px solid var(--gold);
  border-top: 1px solid var(--hairline-strong);
  border-bottom: 1px solid var(--hairline-strong);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.35);
  padding: 16px 22px 16px 26px;
  font-size: var(--fs-md);
  line-height: 1.8;
  margin-left: 8px;
  animation: slideIn var(--dur) var(--ease);
}
.detail-panel p { margin-bottom: 6px; }
.detail-panel strong { color: var(--gold); font-variant: small-caps; letter-spacing: 0.5px; }
.detail-panel .desc { margin-top: 14px; color: var(--text); padding-top: 12px; border-top: 1px solid var(--hairline); }
.detail-panel .desc::before { display: block; content: '─── ✦ ───'; text-align: center; color: var(--gold-dim); font-size: 12px; letter-spacing: 4px; margin-bottom: 10px; }
.detail-panel .desc ul { margin: 6px 0 10px 18px; padding: 0; list-style: disc; }
.detail-panel .desc li { margin-bottom: 5px; line-height: 1.55; }
.detail-panel .desc h4, .detail-panel .desc h5, .detail-panel .desc h6 { color: var(--gold); font-size: 0.8rem; letter-spacing: 1px; font-variant: small-caps; margin: 10px 0 4px; }
.detail-panel .error { color: var(--danger); font-style: normal; }
.detail-panel .detail-empty { color: var(--muted); }
.detail-panel pre { font-size: 12px; color: var(--muted); white-space: pre-wrap; }

/* Rule tables (rendered from 5e.tools data) — scroll horizontally if wide */
.detail-panel .rule-table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
  font-size: var(--fs-sm);
  display: block;
  overflow-x: auto;
}
.detail-panel .rule-table th,
.detail-panel .rule-table td { border: 1px solid var(--gold-dim); padding: 4px 8px; text-align: left; }
.detail-panel .rule-table th { background: rgba(212,168,75,0.12); color: var(--gold); white-space: nowrap; }

/* ── Transcript strip ────────────────────────────────────────────────────── */
#transcript-strip {
  background: rgba(10, 8, 4, 0.85);
  border-bottom: 1px solid var(--hairline);
  color: var(--muted);
  font-family: var(--font-fancy);
  font-size: var(--fs-sm);
  padding: 6px 24px;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity var(--dur-slow) var(--ease);
}
#transcript-strip.fading { opacity: 0; }

/* ── Sync toast (relocated bottom-center snackbar) ───────────────────────── */
#sync-progress {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 10px 18px;
  min-width: 220px;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: var(--z-toast);
  box-shadow: var(--shadow-md);
  animation: fadeIn var(--dur) var(--ease);
}
#progress-text { font-family: var(--font-display); font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0.5px; }

/* ── Undo toast (snackbar with action) ───────────────────────────────────── */
#undo-toast {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 9px 12px 9px 18px;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: var(--z-toast);
  box-shadow: var(--shadow-md);
  animation: fadeIn var(--dur) var(--ease);
}
#undo-toast-text { font-family: var(--font-display); font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0.5px; white-space: nowrap; }
#undo-toast-btn {
  background: rgba(212,168,75,0.12);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--gold);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 5px 12px;
  transition: background var(--dur-fast) var(--ease);
}
#undo-toast-btn:hover { background: rgba(212,168,75,0.22); }

/* ── Dialogs (native <dialog>: #modal-overlay, #stats-overlay) ───────────── */
#modal-overlay, #stats-overlay {
  border: none;
  padding: 0;
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
#modal-overlay[open], #stats-overlay[open] {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
#modal-overlay::backdrop, #stats-overlay::backdrop {
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#modal, #stats-panel {
  background-color: var(--parchment);
  background-image: var(--grain);
  background-size: 300px 300px;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(212,168,75,0.08);
  width: 560px;
  max-width: 100%;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#stats-panel { width: 480px; }

.modal-header {
  border-bottom: 1px solid var(--hairline-strong);
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 6px;
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
}
.modal-title { font-family: var(--font-display); color: var(--gold); font-size: var(--fs-sm); letter-spacing: 1px; }
.modal-tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--fs-xs);
  padding: 6px 12px;
  white-space: nowrap;
}
.tab-btn.active { color: var(--gold); border-color: var(--gold-dim); background: rgba(212,168,75,0.08); }
.tab-btn:hover  { color: var(--gold); }

.modal-close {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 18px; padding: 4px 8px; line-height: 1;
  border-radius: var(--radius);
  transition: color var(--dur-fast) var(--ease);
  margin-left: auto;
}
.modal-close:hover { color: var(--danger); }

.modal-body { overflow-y: auto; padding: 18px; flex: 1; -webkit-overflow-scrolling: touch; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.save-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.save-form input[type="text"], .save-form textarea, .save-form select { flex: 1; min-width: 0; }
.save-form textarea { resize: vertical; min-height: 56px; }
.custom-form { flex-direction: column; }
.custom-form input, .custom-form select, .custom-form textarea { flex: none; }

.session-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
}

/* ── Item lists (sessions, custom terms) ─────────────────────────────────── */
.item-list { display: flex; flex-direction: column; gap: 2px; }
.list-empty { color: var(--muted); font-style: normal; font-size: var(--fs-sm); padding: 8px 0; text-align: center; }
.item-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  gap: 10px;
}
.item-row:last-child { border-bottom: none; }
.item-info { flex: 1; min-width: 0; }
.item-name { color: var(--text); font-size: var(--fs-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: var(--fs-xs); margin-top: 2px; }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Settings ────────────────────────────────────────────────────────────── */
.setting-row { margin-bottom: 22px; }
.setting-label { display: block; color: var(--muted); font-size: 12px; font-family: var(--font-display); letter-spacing: 0.5px; margin-bottom: 9px; }
.setting-label strong { color: var(--gold); }
.setting-hint { font-size: var(--fs-xs); color: var(--muted); font-style: normal; margin-left: 6px; font-family: var(--font-body); }
.setting-slider { width: 100%; accent-color: var(--gold); cursor: pointer; height: var(--touch); }
.setting-select { width: 100%; }
.setting-number {
  width: 72px; accent-color: var(--gold);
  background: var(--field-bg, rgba(0,0,0,0.2)); color: var(--gold);
  border: 1px solid var(--gold-dim); border-radius: var(--radius);
  padding: 6px 8px; font-family: var(--font-mono);
}
.setting-number:disabled { opacity: 0.4; cursor: not-allowed; }
.setting-label input[type="checkbox"] { accent-color: var(--gold); vertical-align: -1px; margin-right: 4px; }
.setting-text {
  accent-color: var(--gold);
  background: var(--field-bg, rgba(0,0,0,0.2)); color: var(--gold);
  border: 1px solid var(--gold-dim); border-radius: var(--radius);
  padding: 6px 10px; width: 220px; font-family: var(--font-mono);
}

/* AI plausibility check reachability indicator */
.ai-verify-status { font-size: var(--fs-xs); font-family: var(--font-mono); margin-left: 10px; color: var(--muted); }
.ai-verify-status.ok   { color: var(--gold); }
.ai-verify-status.down { color: var(--danger); }

/* Scan-category checklist */
.scan-cats { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.scan-cat {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--muted); font-size: var(--fs-sm); text-transform: capitalize; cursor: pointer;
}
.scan-cat input { accent-color: var(--gold); cursor: pointer; }

/* Match-confidence badge on log rows */
.score-badge {
  margin-left: 8px; padding: 1px 6px; border-radius: 8px;
  font-family: var(--font-mono); font-size: 10px; color: var(--muted);
  background: rgba(138,125,96,0.14); vertical-align: 1px;
}

/* AI-flagged ("implausible") match badge + row treatment */
.flagged-badge {
  margin-left: 8px; padding: 1px 6px; border-radius: 8px;
  font-family: var(--font-mono); font-size: 10px; color: var(--danger);
  background: rgba(232,125,125,0.12); vertical-align: 1px;
}
tr.log-row.flagged-row { border-left: 3px solid var(--danger-dim); opacity: 0.85; }
tr.log-row.flagged-row:hover { border-left-color: var(--danger); }

/* Segmented controls (language / model / on-rejection) */
.lang-group, .model-group, .reject-group {
  display: flex;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  overflow: hidden;
}
.lang-btn, .model-btn, .reject-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-right: 1px solid var(--gold-dim);
  color: var(--muted);
  font-size: var(--fs-xs);
  padding: 10px 0;
}
.lang-btn:last-child, .model-btn:last-child, .reject-btn:last-child { border-right: none; }
.lang-btn:hover, .model-btn:hover, .reject-btn:hover { background: rgba(212,168,75,0.08); color: var(--gold); }
.lang-btn.active, .model-btn.active, .reject-btn.active { background: rgba(212,168,75,0.15); color: var(--gold); }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stat-total { color: var(--text); font-size: var(--fs-md); margin-bottom: 16px; }
.stat-total strong { color: var(--gold); }
.stat-bars { margin-bottom: 20px; }
.stat-bar-row { margin-bottom: 10px; }
.stat-bar-label {
  font-family: var(--font-display); font-size: var(--fs-xs); color: var(--muted);
  letter-spacing: 0.5px; margin-bottom: 4px; text-transform: uppercase;
  display: flex; justify-content: space-between;
}
.stat-count { color: var(--gold); }
.stat-bar-track { background: rgba(255,255,255,0.06); border-radius: 2px; height: 16px; overflow: hidden; }
.stat-bar-fill  { height: 100%; border-radius: 2px; transition: width 0.4s var(--ease); min-width: 4px; }
.stat-heading {
  font-family: var(--font-display); color: var(--gold-dim); font-size: 10px;
  letter-spacing: var(--ls-label); text-transform: uppercase; margin-bottom: 10px;
  border-top: 1px solid var(--gold-glow); padding-top: 14px;
}
.stat-top-list { display: flex; flex-direction: column; gap: 6px; }
.stat-top-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }
.stat-top-name { color: var(--text); font-size: var(--fs-md); }
.stat-top-count { color: var(--gold); font-family: var(--font-display); font-size: 12px; }

/* ── Source badge (on log rows + search results) ─────────────────────────── */
.source-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
  background: rgba(138,125,96,0.12);
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap;
}
.source-badge.ed-2024 { background: rgba(42,122,74,0.2); color: var(--ed-2024-tint); }
.source-badge.ed-2014 { background: rgba(90,80,96,0.2); color: var(--ed-2014-tint); }

/* Flex wrapper when a source badge accompanies the category badge in a cell */
.col-cat-inner { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }

/* source-hidden rows are invisible (source/edition filter toggled off) */
tr.log-row.source-hidden { display: none; }

/* ── Search category header (browse / filtered mode) ────────────────────── */
.dropdown li.search-cat-header {
  padding: 7px 14px;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
  pointer-events: none;
}
.dropdown li.search-cat-header:hover { background: none; color: inherit; }
.search-cat-count { color: var(--muted); font-family: var(--font-mono); font-size: 10px; }

/* Pop-out trigger button inside the dropdown header */
.browse-popout-btn {
  background: none;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 7px;
  line-height: 1.5;
  margin-left: auto;
  pointer-events: all;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.browse-popout-btn:hover { color: var(--gold); border-color: var(--gold); }

/* ── Browse pop-out dialog ───────────────────────────────────────────────── */
#browse-overlay, #levelup-overlay {
  border: none;
  padding: 0;
  margin: 0;
  max-width: 100%;
  max-height: 100%;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
#browse-overlay[open], #levelup-overlay[open] {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
#browse-overlay::backdrop, #levelup-overlay::backdrop {
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.browse-panel {
  background-color: var(--parchment);
  background-image: var(--grain);
  background-size: 300px 300px;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(212,168,75,0.08);
  width: 900px;
  max-width: calc(100vw - 32px);
  height: 80vh;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.browse-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline-strong);
  background: rgba(0,0,0,0.2);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.browse-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.browse-count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  flex-shrink: 0;
}
.browse-select,
.browse-search-input {
  background: var(--bg3);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  padding: 6px 10px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.browse-select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a7d60'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
  flex-shrink: 0;
}
.browse-select option { background: var(--panel); }
.browse-search-input {
  width: 0;
  flex: 1;
  min-width: 80px;
}
.browse-select:focus,
.browse-search-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-glow);
}
.browse-search-input::placeholder { color: var(--muted); opacity: 0.7; font-style: normal; }
.browse-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.browse-list {
  width: 260px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--hairline);
  padding: 6px 0;
  list-style: none;
  margin: 0;
  -webkit-overflow-scrolling: touch;
}
.browse-item {
  display: flex;
  flex-direction: column;
  padding: 8px 14px;
  cursor: pointer;
  gap: 4px;
  border-left: 3px solid transparent;
  transition: background var(--dur-fast) var(--ease);
}
.browse-item:hover { background: rgba(255,255,255,0.04); }
.browse-item.selected { background: rgba(212,168,75,0.08); border-left-color: var(--gold-dim); }
.browse-item-name { font-size: var(--fs-sm); color: var(--text); line-height: 1.3; }
.browse-item.selected .browse-item-name { color: var(--gold); }
.browse-item-meta { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.browse-empty-item { padding: 16px 14px; color: var(--muted); font-style: normal; font-size: var(--fs-sm); }
.browse-detail {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.browse-detail-inner { padding: 20px 24px; }
.browse-detail-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: var(--gold);
  letter-spacing: var(--ls-title);
  margin-bottom: 12px;
}
.browse-detail-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}
.browse-empty-detail {
  color: var(--muted);
  font-style: normal;
  text-align: center;
  margin-top: 60px;
  font-size: var(--fs-sm);
}
/* Strip the table-row box styling when detail-panel sits inside the browse pane */
.browse-detail-inner .detail-panel {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin-left: 0;
  animation: none;
}
.dropdown li.search-empty-item {
  padding: 11px 14px;
  color: var(--muted);
  font-style: normal;
  font-size: var(--fs-sm);
  cursor: default;
  pointer-events: none;
}
.dropdown li.search-empty-item:hover { background: none; }

/* ── Init overlay ────────────────────────────────────────────────────────── */
#init-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--bg);
  background-image: var(--grain);
  background-size: 300px 300px;
  z-index: var(--z-init);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 1;
  transition: opacity 0.85s var(--ease);
}
#init-overlay.fade-out { opacity: 0; pointer-events: none; }
.init-box {
  text-align: center;
  max-width: 440px;
  width: 100%;
  padding: 44px 40px;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-lg);
  background-color: var(--parchment);
  background-image: var(--grain);
  background-size: 300px 300px;
  box-shadow: 0 0 60px rgba(0,0,0,0.8), inset 0 0 50px rgba(0,0,0,0.2);
}
.init-glyph { font-size: 2.2rem; color: var(--gold); display: block; margin-bottom: 14px; animation: initPulse 2.5s ease-in-out infinite; }
.init-title { font-family: var(--font-display); color: var(--gold); font-size: var(--fs-lg); letter-spacing: var(--ls-title); margin-bottom: 22px; }
.init-messages {
  font-family: var(--font-fancy); color: var(--muted); font-size: var(--fs-sm);
  min-height: 56px; max-height: 120px; overflow-y: auto; margin-bottom: 8px; line-height: 1.9; text-align: left;
}
.init-messages p { margin: 0; padding: 1px 0; }
.init-current { font-family: var(--font-fancy); color: rgba(138,125,96,0.6); font-size: 12px; margin-bottom: 16px; min-height: 18px; }
.init-bar-track { background: rgba(255,255,255,0.05); border: 1px solid var(--gold-dim); border-radius: 3px; height: 4px; overflow: hidden; }
.init-bar-fill { height: 100%; background: linear-gradient(to right, var(--gold-dim), var(--gold)); border-radius: 3px; width: 0%; transition: width 0.5s var(--ease); }

/* ── Level-up helper ──────────────────────────────────────────────────────── */
.levelup-header { justify-content: flex-start; }
.levelup-header .modal-title { margin-right: auto; }
.levelup-toggles { display: flex; gap: 0; border: 1px solid var(--gold-dim); border-radius: var(--radius); overflow: hidden; }
.lvl-toggle {
  background: transparent; border: none; border-right: 1px solid var(--gold-dim);
  color: var(--muted); font-family: var(--font-body); font-size: 11px;
  padding: 6px 10px; cursor: pointer; transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lvl-toggle:last-child { border-right: none; }
.lvl-toggle:hover { background: rgba(212,168,75,0.08); color: var(--gold); }
.lvl-toggle.active { background: rgba(212,168,75,0.15); color: var(--gold); }

.levelup-roster {
  width: 260px; flex-shrink: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--hairline);
}
.levelup-roster .browse-list { width: 100%; border-right: none; flex: 1; }
#roster-add-btn { margin: 8px; flex-shrink: 0; }
.lvl-cls { color: var(--muted); font-size: 11px; }

.levelup-detail-head { border-bottom: 1px solid var(--hairline); padding-bottom: 14px; margin-bottom: 14px; }
.levelup-sub { color: var(--text); font-size: var(--fs-sm); margin: 2px 0; }
.levelup-leveling { color: var(--gold); font-size: var(--fs-md); margin: 6px 0 12px; }
.levelup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.action-btn.lvlup { background: rgba(212,168,75,0.16); color: var(--gold); }

.levelup-section {
  font-family: var(--font-display); color: var(--gold); font-size: var(--fs-sm);
  letter-spacing: 1px; margin: 18px 0 8px; padding-bottom: 4px;
  border-bottom: 1px solid var(--hairline);
}
.levelup-none { color: var(--muted); font-style: normal; font-size: var(--fs-sm); }

.levelup-feature { padding: 10px 0; border-bottom: 1px solid var(--hairline); transition: opacity var(--dur) var(--ease); }
.levelup-feature.done { opacity: 0.5; }
.levelup-feat-head { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.levelup-feature.done .lvl-feat-name { text-decoration: line-through; }
.lvl-feat-name { font-family: var(--font-display); color: var(--gold); font-size: var(--fs-sm); letter-spacing: 0.5px; }
.lvl-check { accent-color: var(--gold); width: 16px; height: 16px; flex-shrink: 0; }
.lvl-sc-tag { font-size: 10px; color: var(--muted); border: 1px solid var(--gold-dim); border-radius: 3px; padding: 1px 6px; margin-left: auto; }
.levelup-feature .desc { margin-top: 6px; font-size: var(--fs-sm); }

.levelup-stats td { font-size: var(--fs-sm); }
.levelup-stats .lvl-from { color: var(--muted); text-align: right; }
.levelup-stats .lvl-to { color: var(--gold); font-weight: 600; }

.levelup-spells { display: flex; flex-wrap: wrap; gap: 6px; }
.lvl-spell {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--bg3); border: 1px solid var(--gold-dim); border-radius: var(--radius);
  color: var(--text); font-family: var(--font-body); font-size: 12px; padding: 4px 8px;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lvl-spell:hover { border-color: var(--gold); color: var(--gold); }
.lvl-spell-lvl {
  font-family: var(--font-mono); font-size: 10px; color: var(--gold);
  background: rgba(212,168,75,0.14); border-radius: 3px; padding: 0 5px;
}

.levelup-form { display: flex; flex-direction: column; gap: 12px; max-width: 380px; }
.lvl-field { display: flex; flex-direction: column; gap: 4px; }
.lvl-field > span { font-size: 11px; color: var(--muted); letter-spacing: 0.5px; text-transform: uppercase; }
.levelup-form .levelup-actions { margin-top: 6px; }

.levelup-basics { display: flex; flex-direction: column; gap: 2px; }
.lvl-basic { display: flex; gap: 12px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--hairline); }
.lvl-basic-label { flex-shrink: 0; width: 150px; color: var(--gold); font-size: var(--fs-sm); font-family: var(--font-display); letter-spacing: 0.5px; }
.lvl-basic-val { color: var(--text); font-size: var(--fs-sm); display: flex; flex-direction: column; gap: 2px; }
.lvl-basic-note { font-size: 11px; }

.lvl-opt-tag {
  font-size: 10px; color: var(--gold); letter-spacing: 0.5px;
  border: 1px solid var(--gold-dim); border-radius: 3px; padding: 1px 6px;
  background: rgba(212,168,75,0.08); white-space: nowrap;
}
.lvl-spell.optional { border-style: dashed; }
.lvl-spell-src {
  font-family: var(--font-mono); font-size: 9px; color: var(--muted);
  border: 1px solid var(--gold-dim); border-radius: 3px; padding: 0 4px;
}
