/* SIMRS — Hospital Information System */
:root {
  /* Accent (tweakable) */
  --accent-h: 200;
  --accent: oklch(0.55 0.11 var(--accent-h));
  --accent-soft: oklch(0.95 0.03 var(--accent-h));
  --accent-hover: oklch(0.48 0.12 var(--accent-h));
  --accent-fg: oklch(0.99 0.005 var(--accent-h));

  /* Neutrals — slight cool tint */
  --bg: oklch(0.985 0.003 240);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.975 0.004 240);
  --surface-3: oklch(0.955 0.005 240);
  --border: oklch(0.91 0.005 240);
  --border-strong: oklch(0.85 0.008 240);
  --text: oklch(0.22 0.01 240);
  --text-2: oklch(0.45 0.01 240);
  --text-3: oklch(0.62 0.008 240);

  /* Semantic */
  --ok: oklch(0.62 0.14 155);
  --ok-soft: oklch(0.95 0.04 155);
  --warn: oklch(0.74 0.15 75);
  --warn-soft: oklch(0.96 0.05 75);
  --danger: oklch(0.6 0.2 20);
  --danger-soft: oklch(0.95 0.04 20);
  --info: oklch(0.58 0.14 260);
  --info-soft: oklch(0.95 0.04 260);
  --violet: oklch(0.55 0.14 300);
  --violet-soft: oklch(0.95 0.04 300);

  /* Shape */
  --r-sm: 4px;
  --r: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  --shadow-xs: 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.05);

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

[data-theme="dark"] {
  --bg: oklch(0.16 0.01 240);
  --surface: oklch(0.205 0.012 240);
  --surface-2: oklch(0.235 0.012 240);
  --surface-3: oklch(0.27 0.012 240);
  --border: oklch(0.31 0.012 240);
  --border-strong: oklch(0.42 0.015 240);
  --text: oklch(0.96 0.005 240);
  --text-2: oklch(0.72 0.01 240);
  --text-3: oklch(0.55 0.01 240);

  --accent: oklch(0.7 0.12 var(--accent-h));
  --accent-soft: oklch(0.3 0.05 var(--accent-h));
  --accent-hover: oklch(0.76 0.13 var(--accent-h));
  --accent-fg: oklch(0.14 0.01 240);

  --ok-soft: oklch(0.28 0.05 155);
  --warn-soft: oklch(0.3 0.05 75);
  --danger-soft: oklch(0.3 0.05 20);
  --info-soft: oklch(0.3 0.05 260);
  --violet-soft: oklch(0.3 0.05 300);

  --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(0, 0, 0, 0.25);
  --shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
.mono { font-family: var(--font-mono); font-feature-settings: 'zero'; }

/* ========== App Shell ========== */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  background: var(--bg);
}
.app.collapsed { grid-template-columns: 60px 1fr; }

/* ========== Desktop layouts ========== */
/* Classic = menubar + toolbar + tabs + statusbar (Windows/legacy SIMRS feel) */
.app.layout-classic {
  grid-template-columns: 1fr;
  grid-template-rows: 24px 30px 40px 30px 1fr 22px;
  grid-template-areas:
    "menubar"
    "toolbar"
    "tabs"
    "subnav"
    "main"
    "statusbar";
}
.app.layout-classic .sidebar,
.app.layout-classic .topbar { display: none; }
.app.layout-classic .main { grid-area: main; padding: 16px 20px 20px; }

/* Ribbon = tabbed ribbon */
.app.layout-ribbon {
  grid-template-columns: 1fr;
  grid-template-rows: 36px 34px 100px 28px 1fr 22px;
  grid-template-areas:
    "titlebar"
    "ribbon-tabs"
    "ribbon"
    "tabs"
    "main"
    "statusbar";
}
.app.layout-ribbon .sidebar,
.app.layout-ribbon .topbar { display: none; }
.app.layout-ribbon .main { grid-area: main; padding: 16px 20px 20px; }

/* Rail = narrow icon rail + horizontal section tabs */
.app.layout-rail {
  grid-template-columns: 52px 1fr;
  grid-template-rows: 38px 40px 1fr 22px;
  grid-template-areas:
    "rail titlebar"
    "rail subnav"
    "rail main"
    "rail statusbar";
}
.app.layout-rail .sidebar,
.app.layout-rail .topbar { display: none; }
.app.layout-rail .main { grid-area: main; padding: 16px 20px 20px; }

/* Hybrid = module bar (top) + tab strip + page list (left) */
.app.layout-hybrid {
  grid-template-columns: 220px 1fr;
  grid-template-rows: 40px 32px 1fr 22px;
  grid-template-areas:
    "modulebar modulebar"
    "pagelist tabs"
    "pagelist main"
    "statusbar statusbar";
}
.app.layout-hybrid .sidebar,
.app.layout-hybrid .topbar { display: none; }
.app.layout-hybrid .main { grid-area: main; padding: 16px 20px 20px; }
.app.layout-hybrid .doc-tabs { grid-area: tabs; }

.modulebar {
  grid-area: modulebar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 2px;
}
.modulebar .brand {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px 0 4px;
  margin-right: 6px;
  border-right: 1px solid var(--border);
  height: 100%;
}
.modulebar .brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.modulebar .brand-text b { font-size: 12.5px; font-weight: 600; }
.modulebar .brand-text span { font-size: 10px; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }
.modulebar-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  border-radius: 5px;
  position: relative;
}
.modulebar-btn:hover { background: var(--surface-2); color: var(--text); }
.modulebar-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.modulebar-btn svg { width: 14px; height: 14px; }
.modulebar-btn .badge-mini {
  background: var(--danger);
  color: white;
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  font-family: var(--font-mono);
  margin-left: 2px;
}
.modulebar-btn.active .badge-mini { background: var(--accent); color: var(--accent-fg); }
.modulebar .right {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px;
}
.modulebar .right .meta {
  display: flex; flex-direction: column; line-height: 1.15; padding: 0 8px;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
.modulebar .right .meta b { font-size: 11.5px; font-weight: 600; }
.modulebar .right .meta span { font-size: 10px; color: var(--text-3); }
.modulebar .right .user {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 4px; border-radius: 4px;
}
.modulebar .right .user:hover { background: var(--surface-2); }
.modulebar .right .user .avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 10px; font-weight: 600;
}
.modulebar .right .user .info { display: flex; flex-direction: column; line-height: 1.15; }
.modulebar .right .user .info b { font-size: 11.5px; }
.modulebar .right .user .info span { font-size: 10px; color: var(--text-3); }

/* Page list (left vertical) */
.pagelist {
  grid-area: pagelist;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.pagelist-h {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.pagelist-h .ic {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.pagelist-h .ic svg { width: 15px; height: 15px; }
.pagelist-h .title { display: flex; flex-direction: column; line-height: 1.15; flex: 1; min-width: 0; }
.pagelist-h .title b { font-size: 12.5px; font-weight: 600; }
.pagelist-h .title span { font-size: 10px; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }
.pagelist-body { flex: 1; overflow-y: auto; padding: 8px 6px; }
.pagelist-group {
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
  padding: 10px 10px 4px;
}
.pagelist-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 7px 10px;
  background: transparent; border: none; text-align: left;
  border-radius: var(--r);
  font-size: 12.5px; font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: 1px;
}
.pagelist-item:hover { background: var(--surface-3); color: var(--text); }
.pagelist-item.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
}
.pagelist-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.pagelist-item .lbl { flex: 1; }
.pagelist-item .badge-mini {
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2);
  font-family: var(--font-mono);
}
.pagelist-item.active .badge-mini { background: var(--accent); color: var(--accent-fg); }

/* ========== Menubar (classic) ========== */
.menubar {
  grid-area: menubar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 4px;
  gap: 0;
  font-size: 12px;
  user-select: none;
}
.menubar .brand {
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px 0 6px;
  height: 100%;
  border-right: 1px solid var(--border);
  margin-right: 4px;
}
.menubar .brand-logo {
  width: 16px; height: 16px; border-radius: 3px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700;
}
.menubar .brand-text { font-size: 11.5px; font-weight: 600; }
.menubar-item {
  padding: 3px 9px;
  border-radius: 3px;
  color: var(--text);
  cursor: default;
}
.menubar-item:hover { background: var(--accent-soft); color: var(--accent); }
.menubar-item u { text-decoration: underline; }
.menubar .right {
  margin-left: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px;
  font-size: 11px; color: var(--text-3);
}
.menubar .win-ctrls { display: flex; gap: 0; height: 100%; margin-left: 4px; }
.menubar .win-ctrl {
  width: 44px; display: grid; place-items: center;
  color: var(--text-2); cursor: default;
}
.menubar .win-ctrl:hover { background: var(--surface-2); }
.menubar .win-ctrl.close:hover { background: var(--danger); color: white; }

/* Toolbar (classic) */
.toolbar-classic {
  grid-area: toolbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
}
.tbtn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-size: 11.5px; font-weight: 500;
  border-radius: 3px;
}
.tbtn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.tbtn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tbtn svg { width: 13px; height: 13px; }
.tbtn-icon { width: 24px; padding: 0; justify-content: center; }
.tbar-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.tbar-spacer { flex: 1; }
.tbar-search {
  height: 22px; border: 1px solid var(--border-strong); border-radius: 3px;
  background: var(--surface-2); padding: 0 8px; font-size: 11px;
  color: var(--text); outline: none; width: 200px;
}
.tbar-search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* Doc tabs (MDI style, all layouts) */
.doc-tabs {
  grid-area: tabs;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 0 6px;
  gap: 1px;
  overflow-x: auto;
}
.doc-tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px;
  padding: 0 10px 0 12px;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  margin-top: 2px;
  cursor: default;
  max-width: 220px;
  white-space: nowrap;
}
.doc-tab:hover { background: var(--surface-2); color: var(--text); }
.doc-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  margin-top: 0;
  height: 30px;
  border-top: 2px solid var(--accent);
  padding-top: 0;
  position: relative;
}
.doc-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--surface);
}
.doc-tab svg { width: 12px; height: 12px; flex-shrink: 0; }
.doc-tab .close-x {
  width: 14px; height: 14px; border-radius: 2px;
  display: grid; place-items: center; opacity: 0.5;
  color: var(--text-3); margin-left: 2px;
}
.doc-tab .close-x:hover { background: var(--surface-3); opacity: 1; color: var(--text); }
.doc-tab-add {
  width: 24px; height: 24px; margin-top: 3px;
  display: grid; place-items: center;
  color: var(--text-3); border-radius: 3px;
}
.doc-tab-add:hover { background: var(--surface-3); color: var(--text); }

/* Subnav — module's internal tabs below chrome */
.subnav {
  grid-area: subnav;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 2px;
}
.subnav-tab {
  height: 24px;
  padding: 0 10px;
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  color: var(--text-2);
  border-radius: 3px;
  background: transparent; border: 1px solid transparent;
}
.subnav-tab:hover { background: var(--surface-2); }
.subnav-tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.subnav-tab svg { width: 12px; height: 12px; }
.subnav .right { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); }

/* Statusbar */
.statusbar {
  grid-area: statusbar;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
  font-size: 10.5px;
  color: var(--text-3);
  user-select: none;
}
.statusbar .sep { width: 1px; height: 12px; background: var(--border); }
.statusbar b { color: var(--text-2); font-weight: 600; }
.statusbar .right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.statusbar .ok-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

/* ========== Ribbon ========== */
.ribbon-titlebar {
  grid-area: titlebar;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 8px;
}
.ribbon-titlebar .brand {
  display: flex; align-items: center; gap: 8px;
  padding-right: 10px;
}
.ribbon-titlebar .qat {
  display: flex; align-items: center; gap: 2px;
  padding: 0 6px;
  border-left: 1px solid var(--border);
  margin-left: 6px;
}
.ribbon-titlebar .qat-btn {
  width: 22px; height: 22px; display: grid; place-items: center;
  border-radius: 3px; color: var(--text-2);
}
.ribbon-titlebar .qat-btn:hover { background: var(--surface-3); color: var(--text); }
.ribbon-titlebar .qat-btn svg { width: 12px; height: 12px; }
.ribbon-titlebar .doc-title {
  margin: 0 auto;
  font-size: 12px; font-weight: 500; color: var(--text-2);
}
.ribbon-tabs-bar {
  grid-area: ribbon-tabs;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 8px;
  gap: 0;
  align-items: flex-end;
}
.ribbon-tab {
  padding: 0 16px;
  height: 100%;
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 500;
  color: var(--text-2);
  border: none; background: none;
  position: relative;
  letter-spacing: 0.01em;
}
.ribbon-tab:hover { color: var(--text); }
.ribbon-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-top: 2px solid var(--accent);
}
.ribbon-tab.file {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.ribbon-tab.file:hover { background: var(--accent-hover); color: var(--accent-fg); }
.ribbon {
  grid-area: ribbon;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 4px 8px;
  gap: 0;
  overflow-x: auto;
}
.ribbon-group {
  display: flex;
  flex-direction: column;
  padding: 0 10px;
  border-right: 1px solid var(--border);
  gap: 2px;
  min-width: max-content;
}
.ribbon-group:last-child { border-right: none; }
.ribbon-group-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
}
.ribbon-group-label {
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
  padding-top: 2px;
  letter-spacing: 0.04em;
}
.rbtn {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 48px; padding: 4px 6px 2px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 10.5px; font-weight: 500;
  border-radius: 3px;
  gap: 3px;
  line-height: 1.2;
}
.rbtn:hover { background: var(--surface-2); border-color: var(--border); }
.rbtn.large svg { width: 22px; height: 22px; }
.rbtn .rbtn-label { max-width: 72px; text-align: center; white-space: normal; }
.rbtn-small {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 6px;
  background: transparent; border: 1px solid transparent;
  color: var(--text); font-size: 11px;
  border-radius: 3px;
}
.rbtn-small:hover { background: var(--surface-2); border-color: var(--border); }
.rbtn-small svg { width: 12px; height: 12px; }
.rbtn-col { display: flex; flex-direction: column; gap: 2px; }

/* ========== Rail ========== */
.rail {
  grid-area: rail;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
}
.rail-logo {
  width: 32px; height: 32px;
  border-radius: 7px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  margin-bottom: 10px;
}
.rail-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 6px;
  color: var(--text-2);
  background: transparent; border: none;
  position: relative;
}
.rail-btn:hover { background: var(--surface-3); color: var(--text); }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); }
.rail-btn.active::before {
  content: ''; position: absolute; left: -8px; top: 8px; bottom: 8px;
  width: 3px; background: var(--accent); border-radius: 2px;
}
.rail-btn svg { width: 18px; height: 18px; }
.rail-spacer { flex: 1; }

.rail-titlebar {
  grid-area: titlebar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
}
.rail-titlebar .title {
  font-size: 13px; font-weight: 600;
}
.rail-titlebar .sub {
  font-size: 11px; color: var(--text-3);
}
.rail-titlebar .spacer { flex: 1; }
.rail-titlebar .search {
  height: 26px; border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface-2); padding: 0 10px; font-size: 11.5px;
  color: var(--text); outline: none; width: 240px;
}

/* Sidebar */
.sidebar {
  grid-row: 1 / 3;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sb-brand {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sb-logo {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sb-brand-text { display: flex; flex-direction: column; line-height: 1.1; overflow: hidden; }
.sb-brand-text b { font-size: 13px; font-weight: 600; }
.sb-brand-text span { font-size: 10.5px; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }
.collapsed .sb-brand-text { display: none; }

.sb-nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.sb-group { margin-bottom: 14px; }
.sb-group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px 4px;
}
.collapsed .sb-group-label { display: none; }
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
}
.sb-item:hover { background: var(--surface-2); color: var(--text); }
.sb-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
[data-theme="dark"] .sb-item.active { color: var(--accent); }
.sb-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.sb-item-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.collapsed .sb-item-label, .collapsed .sb-item-badge { display: none; }
.collapsed .sb-item { justify-content: center; padding: 8px; }
.sb-item-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
}
.sb-item.active .sb-item-badge { background: var(--accent); color: var(--accent-fg); }

.sb-foot { border-top: 1px solid var(--border); padding: 10px; }

/* Topbar */
.topbar {
  grid-column: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: relative;
  z-index: 10;
}
.tb-title { display: flex; flex-direction: column; line-height: 1.15; }
.tb-crumbs { font-size: 11px; color: var(--text-3); letter-spacing: 0.02em; }
.tb-heading { font-size: 14px; font-weight: 600; color: var(--text); }
.tb-spacer { flex: 1; }
.tb-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 10px;
  width: 320px;
  color: var(--text-3);
}
.tb-search input {
  background: none; border: none; outline: none;
  font-size: 13px; color: var(--text);
  flex: 1; min-width: 0;
}
.tb-search kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text-3);
}
.tb-divider { width: 1px; height: 22px; background: var(--border); }
.tb-meta { display: flex; flex-direction: column; line-height: 1.15; font-size: 11.5px; }
.tb-meta b { color: var(--text); font-weight: 600; }
.tb-meta span { color: var(--text-3); font-size: 10.5px; }
.tb-icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: none;
  color: var(--text-2);
  position: relative;
}
.tb-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.tb-icon-btn svg { width: 16px; height: 16px; }
.tb-icon-btn .dot {
  position: absolute; top: 7px; right: 7px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--surface);
}
.tb-user {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 4px 4px;
  border-radius: var(--r);
  cursor: pointer;
}
.tb-user:hover { background: var(--surface-2); }
.tb-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
}
.tb-user-info { display: flex; flex-direction: column; line-height: 1.15; }
.tb-user-info b { font-size: 12.5px; font-weight: 600; }
.tb-user-info span { font-size: 10.5px; color: var(--text-3); }

/* Main area */
.main {
  grid-column: 2;
  overflow-y: auto;
  padding: 20px 24px 40px;
}
.page-header {
  display: flex; align-items: flex-end; gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; margin: 0; }
.page-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.1s;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 14px; height: 14px; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 26px; padding: 0 9px; font-size: 11.5px; }

/* ========== Cards ========== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
}
.card-h {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.card-h h3 { margin: 0; font-size: 13px; font-weight: 600; }
.card-h .sub { font-size: 11.5px; color: var(--text-3); }
.card-h .spacer { flex: 1; }
.card-b { padding: 16px; }
.card-b.tight { padding: 0; }

/* ========== Badges & Chips ========== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
[data-theme="dark"] .badge.ok { color: oklch(0.8 0.15 155); }
[data-theme="dark"] .badge.warn { color: oklch(0.85 0.15 75); }
[data-theme="dark"] .badge.danger { color: oklch(0.78 0.18 20); }
[data-theme="dark"] .badge.info { color: oklch(0.78 0.14 260); }
[data-theme="dark"] .badge.violet { color: oklch(0.78 0.14 300); }

.tag {
  display: inline-flex; align-items: center;
  font-size: 10.5px; font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--surface-3);
  color: var(--text-2);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; }
table.t {
  width: 100%; border-collapse: collapse;
  font-size: 12.5px;
}
table.t thead th {
  text-align: left;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  white-space: nowrap;
}
table.t tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
table.t tbody tr:hover td { background: var(--surface-2); }
table.t tbody tr:last-child td { border-bottom: none; }
.t .num { text-align: right; font-family: var(--font-mono); }
.t .center { text-align: center; }

/* ========== Forms ========== */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; font-weight: 500; color: var(--text-2); }
.field label .req { color: var(--danger); }
.input, .select, .textarea {
  height: 34px;
  padding: 0 10px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.1s, box-shadow 0.1s;
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 60px; }
.input-group {
  display: flex; align-items: center; gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}
.input-group:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group .addon {
  padding: 0 10px; height: 34px;
  display: flex; align-items: center;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 11.5px;
  border-right: 1px solid var(--border);
}
.input-group input { border: none; flex: 1; background: none; outline: none; height: 34px; padding: 0 10px; color: var(--text); font-size: 12.5px; width: 100%; }
.field-hint { font-size: 11px; color: var(--text-3); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; }

/* ========== Stat cards ========== */
.stat {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.stat-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.stat-val { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11.5px; color: var(--text-2); display: flex; align-items: center; gap: 4px; }
.stat-sub.up { color: var(--ok); }
.stat-sub.down { color: var(--danger); }
.stat-spark { position: absolute; right: 10px; bottom: 10px; opacity: 0.4; }

/* ========== Tabs ========== */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  border: none; background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab .count {
  background: var(--surface-3); color: var(--text-2);
  font-size: 10.5px; padding: 1px 6px; border-radius: 999px;
  font-weight: 600;
}
.tab.active .count { background: var(--accent-soft); color: var(--accent); }

/* ========== Tweaks Panel ========== */
.tweaks-panel {
  position: fixed; bottom: 16px; right: 16px;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 100;
  display: none;
}
.tweaks-panel.open { display: block; }
.tweaks-h { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.tweaks-h b { font-size: 12px; font-weight: 600; }
.tweaks-h .spacer { flex: 1; }
.tweaks-section { margin-bottom: 10px; }
.tweaks-section label {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-3); display: block; margin-bottom: 6px;
}
.seg {
  display: flex; background: var(--surface-2); border-radius: var(--r); padding: 2px; gap: 2px;
  border: 1px solid var(--border);
}
.seg button {
  flex: 1; height: 26px; font-size: 11.5px; font-weight: 500;
  background: none; border: none; border-radius: 4px; color: var(--text-2);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.hue-row { display: flex; gap: 6px; }
.hue-sw {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.hue-sw:hover { transform: scale(1.1); }
.hue-sw.on { border-color: var(--text); }

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* Utilities */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.gap-16 { gap: 16px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.muted { color: var(--text-3); }
.subtle { color: var(--text-2); }
