/* KR Brain admin shell — Tabler-default design tokens + utilities.
   Loaded via base.html: <link rel="stylesheet" href="/static/css/admin.css?v=…">.
   Cache-busting handled by Flask static_v(). Fonts (@font-face) stay inline in
   base.html since they need Jinja static_v() interpolation. */

/* Tabler default design system — light + dark variants.
   Aligned with @tabler/core CSS variables (--tblr-*). */
:root {
  --bg:           #f6f8fb;     /* body / app background */
  --bg-card:      #ffffff;
  --bg-subtle:    #fafbfc;     /* table head, subtle areas */
  --border:       #e6e7e9;
  --border-strong:#cbd5e0;
  --text:         #1d273b;     /* primary */
  --text-muted:   #67768d;
  --text-dim:     #9ba9bd;
  --accent:       #206bc4;     /* Tabler primary blue */
  --accent-bg:    #e8f0fb;
  --pos:          #2fb344;     /* Tabler green */
  --pos-bg:       #e7f6ea;
  --neg:          #d63939;     /* Tabler red */
  --neg-bg:       #fbeaea;
  --neutral:      #f76707;     /* Tabler orange (warning) */
  --info:         #4299e1;     /* Tabler cyan (info) */
  /* Admin shell */
  --sidebar-bg:      #ffffff;
  --sidebar-border:  #e6e7e9;
  --sidebar-text:    #4d5874;
  --sidebar-active:  var(--accent);
  --sidebar-active-bg: var(--accent-bg);
  --topbar-bg:       #ffffff;
  --topbar-border:   #e6e7e9;
  --statusbar-bg:    #ffffff;
  --shadow-card:     0 1px 2px 0 rgba(20, 30, 50, 0.04);
  --shadow-pop:      0 2px 6px 0 rgba(20, 30, 50, 0.10);
  --radius-sm: 3px;
  --radius:    4px;     /* Tabler default */
  --radius-md: 6px;
  --radius-lg: 8px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg:           #1a2234;     /* Tabler dark body */
  --bg-card:      #1e2940;
  --bg-subtle:    #182032;
  --border:       #2c3a52;
  --border-strong:#3d4b67;
  --text:         #e1e1e1;
  --text-muted:   #a4abc4;
  --text-dim:     #6c7a96;
  --accent:       #4299e1;     /* lighter blue for dark mode */
  --accent-bg:    #1e3a5f;
  --pos:          #2dce89;
  --pos-bg:       #1f3d2a;
  --neg:          #f5365c;
  --neg-bg:       #3d1f29;
  --neutral:      #fb8c00;
  --info:         #5fa8d3;
  --sidebar-bg:      #1e2940;     /* lifted vs body for visible separation */
  --sidebar-border:  #2c3a52;
  --sidebar-text:    #c8d2e0;
  --sidebar-active-bg: var(--accent-bg);
  --topbar-bg:       #1e2940;
  --topbar-border:   #2c3a52;
  --statusbar-bg:    #1a2234;
  --shadow-card:     0 1px 2px 0 rgba(0, 0, 0, 0.20);
  --shadow-pop:      0 4px 12px 0 rgba(0, 0, 0, 0.30);
  color-scheme: dark;
}
:root[data-theme="dark"] pre,
:root[data-theme="dark"] code {
  background: #182032;
  color: #e1e1e1;
}
:root[data-theme="dark"] .modal-card,
:root[data-theme="dark"] details > summary { background: var(--bg-card); }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Spoqa Han Sans Neo", "Apple SD Gothic Neo", "AppleGothic",
               "Helvetica Neue", Helvetica, Arial, sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4715;
  font-size: 14px;
}

/* ─────────────────── ADMIN SHELL (Tabler-inspired) ─────────────────── */
/* Two-column grid: sidebar (sticky 100vh) + main-col (flex column).
   The right column owns its own topbar/main/statusbar stacking, which
   means each part can size independently without grid row conflicts. */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
:root[data-sidebar="collapsed"] .app-shell { grid-template-columns: 64px 1fr; }

.main-col {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;     /* allow children with overflow to shrink properly */
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  /* 14px top + 28px brand-mark + 14px bottom = 56px, exactly matching the
     topbar's min-height so the brand and topbar bottom borders line up. */
  padding: 14px 18px; height: 56px;
  border-bottom: 1px solid var(--sidebar-border);
  /* Breathing room between the brand divider and the first nav item — keeps
     the rhythm consistent with the spacing under each .nav-section heading. */
  margin-bottom: 8px;
  text-decoration: none; color: var(--text);
  font-weight: 700; font-size: 16px; letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark {
  flex: 0 0 28px; width: 28px; height: 28px;
  border-radius: var(--radius); background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.brand-text { line-height: 1; overflow: hidden; text-overflow: ellipsis; }
:root[data-sidebar="collapsed"] .brand-text { display: none; }
:root[data-sidebar="collapsed"] .brand { padding: 14px 0; justify-content: center; }

.nav-section {
  padding: 14px 12px 4px 16px;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
:root[data-sidebar="collapsed"] .nav-section {
  /* Hide section labels entirely when collapsed — Tabler convention. */
  display: none;
}
:root[data-sidebar="collapsed"] .navlist {
  /* Tighter top spacing between sections when labels are hidden. */
  border-top: 1px solid var(--sidebar-border);
  padding-top: 6px;
  margin-top: 6px;
}
:root[data-sidebar="collapsed"] .navlist:first-of-type {
  border-top: none; padding-top: 0; margin-top: 0;
}

.navlist { list-style: none; margin: 0; padding: 0 8px; }
.navlink {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px;
  margin: 1px 0;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.navlink:hover {
  background: var(--bg-subtle);
  color: var(--text);
  text-decoration: none;
}
.navlink.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
}
.navlink.active .ico { color: var(--sidebar-active); }
.navlink .ico {
  flex: 0 0 18px; width: 18px; height: 18px;
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.navlink .ico svg { width: 18px; height: 18px; }
:root[data-sidebar="collapsed"] .navlink .label { display: none; }
:root[data-sidebar="collapsed"] .navlink {
  justify-content: center; padding: 9px 0;
  position: relative;        /* anchor for custom tooltip */
}
:root[data-sidebar="collapsed"] .navlist { padding: 0 8px; }

/* Custom hover tooltip on collapsed sidebar — replaces native title="..."
   bubble. Reads label from the `title` attribute via attr(). */
:root[data-sidebar="collapsed"] .navlink:hover::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--text);
  color: var(--bg-card);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: var(--radius);
  white-space: nowrap;
  box-shadow: var(--shadow-pop);
  z-index: 95;
  pointer-events: none;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}
:root[data-sidebar="collapsed"] .sidebar-foot { display: none; }

/* Topbar — sticky, auto-height with min-height fallback so content can wrap
   (e.g. many meta pills on narrow screens) without being clipped. */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex; align-items: center; gap: 14px;
  padding: 8px 24px;
  min-height: 56px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-toggle {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-muted);
  padding: 6px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.topbar-toggle:hover { background: var(--bg-subtle); color: var(--text); }

.topbar-title {
  font-size: 14px; font-weight: 500; color: var(--text-muted);
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.topbar-title .page-name {
  font-size: 18px; font-weight: 700; color: var(--text);
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin-right: 10px;
}
.topbar-title .meta-pill {
  color: var(--text-muted); font-weight: 400; font-size: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 2px 8px; border-radius: var(--radius);
}
.topbar-title .meta-pill code { background: transparent; padding: 0; font-size: 12px; }
.topbar-title .mode-tag {
  text-transform: uppercase; letter-spacing: 0.06em;
  font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: var(--radius-sm);
}
.mode-tag.mode-paper { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }
.mode-tag.mode-live  { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent); }

.topbar-spacer { flex: 1; }

.topbar-actions {
  display: flex; align-items: center; gap: 6px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 5px 8px;
  cursor: pointer;
  font-size: 13px; line-height: 1;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  font-family: inherit;
}
.icon-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text);
}
.icon-btn svg { width: 16px; height: 16px; }

/* Profile widget */
.profile { position: relative; }
.profile-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 3px 10px 3px 3px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s;
}
.profile-trigger:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.profile-name { font-size: 13px; font-weight: 500; }
.profile-chev { color: var(--text-muted); font-size: 11px; }

.profile-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  display: none;
  z-index: 100;
}
.profile-menu.show { display: block; }
.profile-menu .pm-header {
  padding: 12px 12px 10px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.pm-header .avatar { width: 36px; height: 36px; font-size: 14px; }
.pm-header .pm-user-info {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.pm-user-name { font-weight: 600; font-size: 14px; color: var(--text); }
.pm-user-role { font-size: 12px; color: var(--text-muted); }

.pm-section-label {
  padding: 6px 12px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}
.pm-mode-row {
  display: flex; gap: 4px;
  padding: 0 8px 6px;
}
.pm-mode-btn {
  flex: 1;
  padding: 6px 10px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.12s;
  /* `<button>` reset — used for the theme switcher (anchor for the
     mode switcher, button for the theme switcher; same visual shape). */
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
}
.pm-mode-btn:hover {
  background: var(--bg-subtle);
  text-decoration: none;
  border-color: var(--border-strong);
}
.pm-mode-btn.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.pm-stat-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px; padding: 0 8px 8px;
}
.pm-stat {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.pm-stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pm-stat-value { font-size: 13px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.pm-stat-value.dot::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); margin-right: 6px; vertical-align: 1px;
}
.pm-stat-value.dot.ok::before { background: var(--pos); }
.pm-stat-value.dot.degraded::before { background: var(--neutral); }
.pm-stat-value.dot.err::before { background: var(--neg); }

.pm-divider { height: 1px; background: var(--border); margin: 4px 0; }
.pm-link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  border-radius: var(--radius);
  margin: 1px 0;
  transition: background 0.12s;
}
.pm-link:hover { background: var(--bg-subtle); text-decoration: none; }
.pm-link.danger { color: var(--neg); }
.pm-link.danger:hover { background: var(--neg-bg); }
.pm-link svg { width: 16px; height: 16px; color: var(--text-muted); }
.pm-link.danger svg { color: var(--neg); }

/* Main content — flex grows to fill the column so statusbar pins to bottom. */
.main {
  flex: 1;
  padding: 24px 32px 28px 32px;
  min-width: 0;
}
.container { max-width: none; width: 100%; margin: 0; padding: 0; }

/* Status bar (footer) */
.statusbar {
  background: var(--statusbar-bg);
  border-top: 1px solid var(--border);
  padding: 8px 24px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
}
.statusbar a { color: var(--accent); }
.statusbar .sep { color: var(--text-dim); }

/* Mobile drawer */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,18,14,0.45);
  z-index: 80;
}
.sidebar-backdrop.show { display: block; }

@media (max-width: 900px) {
  /* On mobile the grid collapses to a single column; sidebar floats over
     the main column as a drawer (fixed-positioned, off-screen by default). */
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 90;
  }
  :root[data-sidebar="open"] .sidebar { transform: translateX(0); }
  :root[data-sidebar="collapsed"] .app-shell { grid-template-columns: 1fr; }
  .main { padding: 18px 18px 20px 18px; }
  .topbar { padding: 8px 14px; }
  .topbar-title .meta-pill.hide-sm { display: none; }
  .topbar-title { font-size: 13px; gap: 6px; }
  .profile-name { display: none; }
  /* Hide the desktop collapse-toggle on mobile — hamburger handles drawer. */
  .topbar-toggle.desktop-only { display: none; }
}
@media (min-width: 901px) {
  .topbar-toggle.mobile-only { display: none; }
}

/* ─────────────────── Reusable utilities ─────────────────── */
h1, h2, h3 {
  font-family: inherit;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
h1 { margin: 0 0 4px 0; font-size: 24px; font-weight: 700; }
h2 {
  margin: 24px 0 12px 0;
  font-size: 18px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  scroll-margin-top: 16px;
}
h2:first-child { margin-top: 4px; }
h3 { font-size: 15px; font-weight: 600; }

.meta {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 16px;
}
.meta code { font-size: 11.5px; color: var(--text-muted); }
.meta strong { color: var(--text-muted); font-weight: 500; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }

.stat { font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.stat-pos { color: var(--pos); }
.stat-neg { color: var(--neg); }
.stat-neutral { color: var(--neutral); }
.pnl-pos  { color: var(--pos); font-variant-numeric: tabular-nums; }
.pnl-neg  { color: var(--neg); font-variant-numeric: tabular-nums; }
.pnl-zero { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Sticky table headers — offset by topbar height (56px) so header rows
   don't disappear behind the sticky topbar when the page scrolls.
   Inside a .scroll-x wrapper the local scroll context resets the offset. */
table thead th {
  position: sticky; top: 56px; z-index: 1;
  background: var(--bg-card);
  box-shadow: inset 0 -1px 0 var(--border);
}
.scroll-x table thead th { top: 0; }
table.sortable thead th { cursor: pointer; user-select: none; transition: background 0.1s; }
table.sortable thead th:hover { background: var(--bg-subtle); }
table.sortable thead th[aria-sort]::after {
  margin-left: 4px; color: var(--text-muted); font-size: 11px;
}
table.sortable thead th[aria-sort="ascending"]::after  { content: " ▲"; }
table.sortable thead th[aria-sort="descending"]::after { content: " ▼"; }
table.sortable thead th[data-no-sort]::after { content: ""; }
table.sortable thead th[data-no-sort] { cursor: default; }
table.sortable thead th[data-no-sort]:hover { background: var(--bg-card); }

.label {
  color: var(--text-muted);
  font-size: 13px; margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: 500;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  margin: 2px 3px 2px 0;
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
  line-height: 1.5;
}
.tag-bull { background: var(--pos-bg); color: var(--pos); border-color: transparent; }
.tag-bear { background: var(--neg-bg); color: var(--neg); border-color: transparent; }
.tag-warn { background: #fff5e6; color: var(--neutral); border-color: transparent; }

table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--bg-card); }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  color: var(--text-muted);
  font-weight: 500;
  background: var(--bg-subtle);
  position: sticky; top: 56px;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.scroll-x th { top: 0; }
th[title] {
  cursor: help;
  text-decoration: underline dotted var(--text-dim);
  text-underline-offset: 3px;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--bg-subtle); }

.scroll-x {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}
.scroll-x table { min-width: 1400px; }
.scroll-x th, .scroll-x td { padding: 8px 11px; font-size: 13px; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.dim { color: var(--text-dim); }

.pick-row { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
            padding: 14px; margin-bottom: 10px; }
.pick-name { font-size: 15px; font-weight: 600; color: var(--text); }
.pick-meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.pick-line { margin-top: 6px; font-family: ui-monospace, monospace; font-size: 12px; }

a { color: var(--accent); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* Section jump pill bar */
.section-jump {
  display: flex; flex-wrap: wrap; gap: 6px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.section-jump .jump-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  margin-right: 4px;
}
.section-jump a {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text);
  border: 1px solid transparent;
  transition: all 0.15s;
  font-weight: 500;
}
.section-jump a:hover {
  background: var(--accent-bg);
  color: var(--accent);
  text-decoration: none;
  border-color: var(--accent);
}

/* Pill nav (used by account.html sub-nav) */
.nav { margin-bottom: 20px; display: flex; gap: 6px; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  transition: all 0.15s ease;
}
.nav a:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.btn {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: #1a5aa3; border-color: #1a5aa3; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge-tier1 { background: #ebe8dd; color: var(--text-muted); }
.badge-tier2 { background: #e2dac4; color: #6b5410; }
.badge-tier3 { background: var(--pos-bg); color: var(--pos); }
.badge-tier4 { background: var(--accent-bg); color: var(--accent); }

.small { font-size: 12px; color: var(--text-muted); }

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: dash-spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes dash-spin { to { transform: rotate(360deg); } }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  margin: 0 2px;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.btn-icon.danger:hover { background: var(--neg-bg); border-color: var(--neg); color: var(--neg); }

.clickable-name {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  border-bottom: 1px dashed transparent;
  transition: background 0.15s, border-color 0.15s;
}
.clickable-name:hover {
  background: var(--accent-bg);
  border-bottom-color: var(--accent);
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(26,26,26,0.4);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-backdrop.show { display: flex; }
.modal-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 24px 28px; width: 100%; max-width: 460px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
}
.modal-title {
  font-family: inherit;
  font-size: 18px; font-weight: 600; margin: 0 0 18px 0;
  letter-spacing: -0.005em;
}
/* Form field — global. modal-card uses same style. */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500;
}
.field input,
.field select,
.field textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit;
  background: var(--bg-card); color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
  line-height: 1.4;
}
.field select {
  /* Native arrow + reasonable padding for the chevron */
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%2367768d' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 10px;
  padding-right: 28px;
  cursor: pointer;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none; border-color: var(--accent);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.field input::placeholder { color: var(--text-dim); }
/* Modal context — keep slight bg-subtle hint inside modals (existing UX) */
.modal-card .field input,
.modal-card .field select,
.modal-card .field textarea { background: var(--bg); }
.modal-card .field input:focus,
.modal-card .field select:focus,
.modal-card .field textarea:focus { background: var(--bg-card); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal-err {
  background: var(--neg-bg); color: var(--neg);
  padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px;
  display: none;
}
.modal-err.show { display: block; }

/* AI 리뷰 modal */
.modal-card.large { max-width: 820px; max-height: 85vh; overflow-y: auto; }
.ai-meta {
  color: var(--text-muted); font-size: 12px; margin-bottom: 14px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.ai-content { font-size: 14px; line-height: 1.7; color: var(--text); }
.ai-content h1, .ai-content h2, .ai-content h3, .ai-content h4 {
  margin: 18px 0 10px 0; padding-bottom: 4px; border-bottom: none;
}
.ai-content h1 { font-size: 20px; }
.ai-content h2 { font-size: 17px; }
.ai-content h3 { font-size: 15px; color: var(--accent); }
.ai-content p  { margin: 8px 0; }
.ai-content ul, .ai-content ol { padding-left: 22px; margin: 8px 0; }
.ai-content li { margin: 4px 0; }
.ai-content strong { color: var(--text); font-weight: 600; }
.ai-content code {
  background: var(--bg-subtle); padding: 1px 6px; border-radius: 3px;
  font-size: 12px; font-family: ui-monospace, monospace;
}
.ai-content pre {
  background: var(--bg-subtle); padding: 12px; border-radius: 6px;
  overflow-x: auto; font-size: 12px; margin: 10px 0;
}
.ai-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text-muted); margin: 10px 0;
}

.ai-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.ai-cached-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: 12px;
  padding: 0;
}
.ai-cached-card[open] { box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.ai-cached-card summary {
  cursor: pointer;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-radius: var(--radius);
}
.ai-cached-card summary::-webkit-details-marker { display: none; }
.ai-cached-card summary::before {
  content: '▶';
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.ai-cached-card[open] summary::before { transform: rotate(90deg); }
.ai-cached-card summary:hover { background: var(--bg-subtle); }
.ai-cached-card .cached-meta {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 12px;
  margin-left: auto;
}
.ai-cached-body { padding: 0 18px 16px 18px; }
.ai-cached-body .ai-content { font-size: 14px; line-height: 1.7; }
.ai-cached-body .ai-content h1, .ai-cached-body .ai-content h2,
.ai-cached-body .ai-content h3, .ai-cached-body .ai-content h4 {
  margin: 16px 0 8px 0; padding-bottom: 4px; border-bottom: none;
  scroll-margin-top: 0;
}
.ai-cached-body .ai-content h1 { font-size: 19px; }
.ai-cached-body .ai-content h2 { font-size: 17px; }
.ai-cached-body .ai-content h3 { font-size: 15px; color: var(--accent); }
.ai-cached-body .ai-content ul, .ai-cached-body .ai-content ol {
  padding-left: 22px; margin: 8px 0;
}
.ai-cached-body .ai-content li { margin: 4px 0; }
.ai-cached-body .ai-content strong { color: var(--text); font-weight: 600; }
.ai-cached-body .ai-content code {
  background: var(--bg-subtle); padding: 1px 6px; border-radius: 3px;
  font-size: 12px; font-family: ui-monospace, monospace;
}
.ai-cached-body .ai-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text-muted); margin: 10px 0;
}
.ai-cached-card .cached-actions {
  margin-top: 12px; display: flex; gap: 8px; justify-content: flex-end;
}
.btn-ai {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-ai:hover:not(:disabled) {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-ai:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ai .ai-emoji { font-size: 16px; }
.ai-status {
  display: inline-block; margin-left: 8px;
  color: var(--text-muted); font-size: 12px; align-self: center;
}

pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 12px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

/* Toast */
.toast {
  position: fixed; top: 20px; right: 20px;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--pos);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow-pop);
  z-index: 2000;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--neg); }
.toast.info  { border-left-color: var(--accent); }

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-subtle);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text);
  margin-right: 4px;
}

/* Skip-to-content link — hidden until keyboard-focused. */
.skip-link {
  position: absolute; top: -40px; left: 8px;
  background: var(--accent); color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius);
  z-index: 9999;
  font-size: 13px; font-weight: 500;
  transition: top 0.15s;
}
.skip-link:focus {
  top: 8px;
  text-decoration: none;
  outline: 2px solid var(--accent-bg);
  outline-offset: 2px;
}
