/* ==========================================================================
   VendorIQ — Design System
   Premium, sober finance/ops admin UI. Neutral surfaces, one accent color.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Accent */
  --accent-h: 221;
  --accent: #2f6fed;
  --accent-600: #2158c9;
  --accent-50: #eef4ff;
  --accent-100: #dde9ff;
  --accent-soft: rgba(47, 111, 237, 0.1);

  /* Semantic */
  --green: #17875a;
  --green-soft: rgba(23, 135, 90, 0.12);
  --red: #d1403f;
  --red-soft: rgba(209, 64, 63, 0.12);
  --amber: #b5760b;
  --amber-soft: rgba(181, 118, 11, 0.14);
  --purple: #6c4fd6;
  --purple-soft: rgba(108, 79, 214, 0.12);
  --cyan: #0e8fa3;
  --cyan-soft: rgba(14, 143, 163, 0.12);

  /* Surfaces - light */
  --bg: #f4f6f9;
  --bg-canvas: #eef1f6;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: #f7f8fb;
  --border: #e2e6ee;
  --border-soft: #edf0f5;
  --border-strong: #cbd2e0;

  --text-primary: #161b25;
  --text-secondary: #545c6c;
  --text-tertiary: #8992a3;
  --text-disabled: #b7bdc9;
  --text-on-accent: #ffffff;

  --shadow-xs: 0 1px 2px rgba(20, 24, 38, 0.04);
  --shadow-sm: 0 1px 3px rgba(20, 24, 38, 0.06), 0 1px 2px rgba(20,24,38,0.04);
  --shadow-md: 0 4px 12px rgba(20, 24, 38, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 24, 38, 0.14);
  --shadow-popover: 0 8px 24px rgba(20,24,38,0.12), 0 2px 6px rgba(20,24,38,0.06);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 9px;
  --radius-lg: 14px;
  --radius-full: 999px;

  --sidebar-w: 236px;
  --sidebar-w-collapsed: 68px;
  --header-h: 56px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", "Roboto Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

  --accent: #4f8cff;
  --accent-600: #6ea0ff;
  --accent-50: #16233d;
  --accent-100: #1b2c4a;
  --accent-soft: rgba(79, 140, 255, 0.16);

  --green: #35c185;
  --green-soft: rgba(53, 193, 133, 0.14);
  --red: #ef6560;
  --red-soft: rgba(239, 101, 96, 0.14);
  --amber: #e0a835;
  --amber-soft: rgba(224, 168, 53, 0.14);
  --purple: #9c88ea;
  --purple-soft: rgba(156, 136, 234, 0.16);
  --cyan: #4fc4d8;
  --cyan-soft: rgba(79, 196, 216, 0.14);

  --bg: #0d1017;
  --bg-canvas: #0a0c12;
  --surface: #141822;
  --surface-raised: #171c28;
  --surface-sunken: #10131b;
  --border: #262c3a;
  --border-soft: #1d222e;
  --border-strong: #363e4f;

  --text-primary: #edf0f5;
  --text-secondary: #a3abbd;
  --text-tertiary: #737d92;
  --text-disabled: #4c5464;
  --text-on-accent: #ffffff;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.24);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.32);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.5);
  --shadow-popover: 0 10px 28px rgba(0,0,0,0.5);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02","cv03","cv04","cv11";
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg { display: block; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

.tabular-num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* Focus visibility for accessibility */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.skip-link {
  position: absolute; left: 8px; top: -40px; z-index: 999;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 6px;
  transition: top 0.15s var(--ease);
}
.skip-link:focus { top: 8px; }

/* ---------- App shell ---------- */
.app-loading {
  height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--text-secondary);
}
.boot-mark { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }
.boot-text { font-size: 12.5px; }

.app-shell.is-ready { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
  transition: width 0.18s var(--ease);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 16px; height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap; overflow: hidden;
}
.brand-mark { flex-shrink: 0; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { font-size: 9.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; margin-top: -2px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px; }
.nav-group { margin-bottom: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 13px; font-weight: 500;
  cursor: pointer; margin-bottom: 1px; position: relative;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
  white-space: nowrap; overflow: hidden;
}
.nav-item svg { flex-shrink: 0; width: 16px; height: 16px; opacity: 0.85; }
.nav-item:hover { background: var(--surface-sunken); color: var(--text-primary); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }
.nav-item .nav-badge {
  margin-left: auto; font-size: 10.5px; font-weight: 700; padding: 1px 6px;
  border-radius: 999px; background: var(--red-soft); color: var(--red);
}
.sidebar-collapsed .nav-label, .sidebar-collapsed .brand-name, .sidebar-collapsed .brand-sub, .sidebar-collapsed .nav-badge { display: none; }
.sidebar-collapsed .nav-item { justify-content: center; }
.sidebar-collapsed .sidebar-brand { justify-content: center; }

.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.collapse-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 7px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-sunken); color: var(--text-secondary); cursor: pointer;
  font-size: 12px;
}
.collapse-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }

/* ---------- Header ---------- */
.topheader {
  height: var(--header-h); border-bottom: 1px solid var(--border);
  background: var(--surface); display: flex; align-items: center; gap: 12px;
  padding: 0 16px; position: sticky; top: 0; z-index: 30;
}
.header-menu-btn { display: none; }
.global-search {
  flex: 1; max-width: 420px; position: relative; display: flex; align-items: center;
}
.global-search input {
  width: 100%; height: 32px; padding: 0 30px 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-sunken); color: var(--text-primary);
  font-size: 12.5px;
}
.global-search input:focus { border-color: var(--accent); background: var(--surface); }
.global-search .kbd-hint {
  position: absolute; right: 8px; font-size: 10px; color: var(--text-tertiary);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; background: var(--surface);
}
.header-filters { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text-primary); border-color: var(--border-strong); }
.icon-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.role-badge {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: var(--surface-sunken); font-size: 11.5px; font-weight: 600;
  color: var(--text-secondary); cursor: pointer; white-space: nowrap;
}
.role-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* ---------- Main content ---------- */
.main-scroll { min-width: 0; display: flex; flex-direction: column; }
.page-content { padding: 18px 22px 60px; max-width: 1560px; width: 100%; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.page-subtitle { font-size: 12.5px; color: var(--text-secondary); margin-top: 3px; max-width: 640px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-tertiary); margin-bottom: 6px; }
.breadcrumb a:hover { color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-primary); font-size: 12.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: all 0.12s var(--ease);
}
.btn:hover { background: var(--surface-sunken); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-600); border-color: var(--accent-600); }
.btn-danger { color: var(--red); border-color: var(--red-soft); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { height: 27px; padding: 0 9px; font-size: 11.5px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-sunken); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon-only { width: 32px; padding: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--border); gap: 10px; }
.card-title { font-size: 13.5px; font-weight: 700; }
.card-desc { font-size: 11.5px; color: var(--text-tertiary); margin-top: 2px; }
.card-body { padding: 14px 16px; }
.card-body.no-pad { padding: 0; }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 14px; }
.grid-kpi { grid-template-columns: repeat(5, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4,1fr); }
.grid-span-2 { grid-column: span 2; }
.grid-span-3 { grid-column: span 3; }
.grid-2-1 { grid-template-columns: 2fr 1fr; }
.grid-1-2 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1240px) {
  .grid-kpi { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-3, .grid-4, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .grid-kpi, .grid-2, .grid-3, .grid-4, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
  .grid-span-2, .grid-span-3 { grid-column: span 1; }
}

/* ---------- KPI cards ---------- */
.kpi-card { padding: 14px 15px; display: flex; flex-direction: column; gap: 7px; position: relative; overflow: hidden; }
.kpi-label { font-size: 11px; color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-sub { font-size: 11.5px; color: var(--text-secondary); display: flex; align-items: center; gap: 5px; }
.kpi-delta { font-weight: 700; display: inline-flex; align-items: center; gap: 2px; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-icon { position: absolute; right: 12px; top: 12px; width: 28px; height: 28px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
.kpi-icon svg { width: 15px; height: 15px; }

/* ---------- Badges / chips / tags ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 700; line-height: 1.6; white-space: nowrap;
}
.badge-dot::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-cyan { background: var(--cyan-soft); color: var(--cyan); }
.badge-gray { background: var(--surface-sunken); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: var(--radius-sm);
  background: var(--surface-sunken); border: 1px solid var(--border); font-size: 11.5px; color: var(--text-secondary);
  cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip button { background: none; border: none; color: inherit; cursor: pointer; display: flex; padding: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); display: flex; justify-content: space-between; }
.form-label .req { color: var(--red); }
.form-hint { font-size: 10.5px; color: var(--text-tertiary); }
.form-error { font-size: 10.5px; color: var(--red); font-weight: 600; }
.input, select.input, textarea.input {
  height: 32px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-primary); width: 100%; font-size: 12.5px;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 64px; }
.input:focus, select.input:focus, textarea.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.invalid { border-color: var(--red); }
.input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-primary); }
.input-group { display: flex; align-items: center; }
.input-prefix { padding: 0 9px; height: 32px; display: flex; align-items: center; background: var(--surface-sunken); border: 1px solid var(--border); border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); font-size: 12px; color: var(--text-tertiary); }
.input-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.select-native { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.4' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 26px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border-radius: var(--radius-lg); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 640px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-sunken); text-align: left; font-weight: 700; color: var(--text-secondary);
  padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text-primary); }
.data-table th .sort-arrow { margin-left: 4px; opacity: 0.5; font-size: 9px; }
.data-table th.sorted .sort-arrow { opacity: 1; color: var(--accent); }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--border-soft); color: var(--text-primary); vertical-align: middle; }
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--surface-sunken); }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.muted { color: var(--text-tertiary); }
.row-avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; margin-right: 7px; vertical-align: middle; }
.link-strong { font-weight: 600; color: var(--text-primary); }
.link-strong:hover { color: var(--accent); }
.cell-flag { display: inline-flex; align-items: center; gap: 4px; color: var(--red); font-weight: 600; }

.table-toolbar { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-toolbar .search-mini { position: relative; }
.table-toolbar .search-mini input { height: 30px; padding: 0 8px; width: 200px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-sunken); font-size: 12px; }
.table-footer { display: flex; align-items: center; justify-content: space-between; padding: 9px 14px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-tertiary); }
.pagination { display: flex; align-items: center; gap: 4px; }
.page-btn { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text-secondary); }
.page-btn:hover { background: var(--surface-sunken); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab-btn { padding: 9px 14px; font-size: 12.5px; font-weight: 600; color: var(--text-tertiary); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-color: var(--accent); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,12,18,0.5); display: flex; align-items: flex-start; justify-content: center; z-index: 200; padding: 40px 16px; overflow-y: auto; animation: fadeIn 0.15s var(--ease); backdrop-filter: blur(1px); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; animation: slideUp 0.18s var(--ease); }
.modal-box.modal-lg { max-width: 880px; }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { padding: 18px; max-height: 68vh; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--border); }
.modal-close { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 50%; cursor: pointer; color: var(--text-tertiary); }
.modal-close:hover { background: var(--surface-sunken); color: var(--text-primary); }

/* ---------- Drawer (right panel, e.g. notes/activity) ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(10,12,18,0.4); z-index: 190; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: 380px; background: var(--surface); border-left: 1px solid var(--border); z-index: 195; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slideLeft 0.18s var(--ease); }
@keyframes slideLeft { from { transform: translateX(24px); opacity: 0.6; } to { transform: translateX(0); opacity: 1; } }

/* ---------- Toast ---------- */
.toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-raised); border: 1px solid var(--border); box-shadow: var(--shadow-popover); border-radius: var(--radius-md); padding: 10px 14px; font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 240px; animation: toastIn 0.18s var(--ease); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

/* ---------- Empty / error / skeleton states ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 50px 20px; text-align: center; color: var(--text-tertiary); gap: 8px; }
.empty-state svg { opacity: 0.5; margin-bottom: 4px; }
.empty-state-title { font-size: 13px; font-weight: 700; color: var(--text-secondary); }
.empty-state-sub { font-size: 12px; max-width: 320px; }

.skeleton { background: linear-gradient(90deg, var(--border-soft) 25%, var(--border) 37%, var(--border-soft) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skel-row { height: 14px; margin-bottom: 8px; }
.skel-kpi { height: 84px; border-radius: var(--radius-lg); }
.skel-chart { height: 260px; border-radius: var(--radius-lg); }

/* ---------- Misc UI ---------- */
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-tertiary); }
.text-sec { color: var(--text-secondary); }
.small { font-size: 11.5px; }
.strong { font-weight: 700; }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.warn-text { color: var(--amber); }

.progress-bar { height: 6px; border-radius: 999px; background: var(--border-soft); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s var(--ease); }
.progress-fill.green { background: var(--green); }
.progress-fill.amber { background: var(--amber); }
.progress-fill.red { background: var(--red); }

.avatar-stack { display: flex; }
.avatar-stack .row-avatar { margin-left: -6px; border: 2px solid var(--surface); }
.avatar-stack .row-avatar:first-child { margin-left: 0; }

.stat-inline { display: flex; align-items: baseline; gap: 6px; }
.stat-inline .v { font-size: 17px; font-weight: 700; }
.stat-inline .l { font-size: 11px; color: var(--text-tertiary); }

.info-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.info-item .k { font-size: 10.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; margin-bottom: 3px; }
.info-item .v { font-size: 13px; font-weight: 600; }

.formula-box { background: var(--surface-sunken); border: 1px dashed var(--border-strong); border-radius: var(--radius-md); padding: 10px 12px; font-size: 11.5px; color: var(--text-secondary); }
.formula-box .fx { font-family: var(--font-mono); color: var(--accent); font-weight: 600; }

.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); margin-bottom: 10px; }

.alert { display: flex; gap: 10px; padding: 11px 13px; border-radius: var(--radius-md); font-size: 12px; border: 1px solid; align-items: flex-start; }
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-amber { background: var(--amber-soft); border-color: rgba(181,118,11,0.3); color: var(--amber); }
.alert-red { background: var(--red-soft); border-color: rgba(209,64,63,0.3); color: var(--red); }
.alert-accent { background: var(--accent-soft); border-color: rgba(47,111,237,0.3); color: var(--accent); }
.alert-green { background: var(--green-soft); border-color: rgba(23,135,90,0.3); color: var(--green); }

.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); right: 0; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-popover); min-width: 190px; z-index: 100; padding: 6px; animation: slideUp 0.12s var(--ease); }
.dropdown-menu.left { right: auto; left: 0; }
.dropdown-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: var(--radius-sm); font-size: 12.5px; cursor: pointer; color: var(--text-primary); }
.dropdown-item:hover { background: var(--surface-sunken); }
.dropdown-item.danger { color: var(--red); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown-label { font-size: 10.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; padding: 5px 9px 3px; }

.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.trend-mini { display: flex; align-items: center; gap: 2px; height: 24px; }

.legend-row { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-secondary); }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ---------- Utility spacing ---------- */
.mt-0 { margin-top: 0 } .mt-4 { margin-top: 4px } .mt-8 { margin-top: 8px } .mt-12 { margin-top: 12px } .mt-16 { margin-top: 16px }
.mb-8 { margin-bottom: 8px } .mb-12 { margin-bottom: 12px } .mb-16 { margin-bottom: 16px }
.gap-6 { gap: 6px } .gap-8 { gap: 8px } .gap-12 { gap: 12px }
.flex-1 { flex: 1 }
.w-full { width: 100% }
.text-right { text-align: right }
.text-center { text-align: center }
.hide-mobile { }
.only-mobile { display: none; }

/* ---------- Icon size utilities ----------
   Inline SVG icons pass a size class (e.g. icon('name', 'w-14')) that must
   set both width and height, or the SVG falls back to the browser's
   unstyled intrinsic size (often huge) whenever it isn't already
   constrained by a parent selector like .nav-item svg / .btn svg. */
svg[class^="w-"], svg[class*=" w-"] { flex-shrink: 0; }
.w-11 { width: 11px; height: 11px; }
.w-12 { width: 12px; height: 12px; }
.w-13 { width: 13px; height: 13px; }
.w-14 { width: 14px; height: 14px; }
.w-15 { width: 15px; height: 15px; }
.w-16 { width: 16px; height: 16px; }
.w-28 { width: 28px; height: 28px; }

/* ---------- Chart container ---------- */
.chart-wrap { position: relative; width: 100%; }
.chart-legend-list { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft); }

/* ---------- Sparkline cost per user distribution bars ---------- */
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-list-row { display: grid; grid-template-columns: 140px 1fr 70px; align-items: center; gap: 10px; font-size: 12px; }
.bar-list-row .lbl { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--border-soft); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.bar-list-row .val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topheader, .page-actions, .no-print, .table-toolbar, .table-footer, .filter-bar { display: none !important; }
  .app-shell { display: block !important; }
  .page-content { max-width: 100%; padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .app-shell.is-ready { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 236px; transform: translateX(-100%); transition: transform 0.2s var(--ease); box-shadow: var(--shadow-lg); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-collapsed .sidebar { width: 236px; }
  .header-menu-btn { display: flex; }
  .header-filters .hide-mobile { display: none; }
  .grid-kpi { grid-template-columns: repeat(2,1fr); }
  .only-mobile { display: block; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 39; }
}
@media (max-width: 560px) {
  .grid-kpi { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 14px 12px 40px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Auth screens (login / change password / MFA) ---------- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg-canvas);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 28px 26px 26px;
}
.auth-brand {
  display: flex; align-items: center; gap: 9px; font-size: 16px; font-weight: 800;
  color: var(--text-primary); margin-bottom: 22px;
}
.auth-brand svg { flex-shrink: 0; }
.auth-title { font-size: 17px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.auth-subtitle { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 18px; line-height: 1.5; }
.auth-submit { width: 100%; justify-content: center; height: 36px; font-size: 13px; font-weight: 600; }
.auth-qr { display: flex; justify-content: center; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 14px; }
.auth-qr svg { max-width: 100%; height: auto; }
.auth-secret { text-align: center; margin-bottom: 18px; }
.auth-secret-code {
  display: inline-block; margin-top: 6px; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface-sunken); border: 1px solid var(--border); font-family: var(--font-mono);
  font-size: 12px; letter-spacing: 0.04em; word-break: break-all;
}
.auth-otp-input { text-align: center; font-size: 20px; letter-spacing: 0.35em; font-family: var(--font-mono); font-weight: 700; }

/* ---------- Import users (CSV) preview ---------- */
.import-preview-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.import-preview-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-tertiary); padding: 8px 10px; background: var(--surface-sunken);
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
}
.import-preview-table td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); color: var(--text-primary); }
.import-preview-table tr.import-row-error td:first-child { border-left: 2px solid var(--red, #e5484d); }
