/* ==========================================================================
   ParandusApp UI system
   Tokens, reset, shell, primitives. See docs/design-system.md.
   Load order: fontawesome → ui.css → page <style> (page-local only). Behaviour: static/js/ui.js
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --surface-3: #e8e8e4;
  --border: #e4e4e0;
  --border-strong: #cfcfc9;
  --ink: #1b1917;
  --ink-2: #5f5b56;
  --ink-3: #8b8781;
  --ink-inverse: #ffffff;

  --accent: #7a4b1e;
  --accent-hover: #653d17;
  --accent-ink: #ffffff;
  --accent-soft: #f3ebe1;
  --accent-rgb: 122, 75, 30;

  --ok: #1e7a4c;
  --ok-soft: #e6f2ec;
  --warn: #a16207;
  --warn-soft: #f8efd9;
  --info: #2457a6;
  --info-soft: #e5ecf7;
  --danger: #b42318;
  --danger-soft: #f8e5e3;

  --font: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --fs-2xs: 10px;   /* avatar initials, carets — micro labels only */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 26px;

  --lh: 1.45;
  --lh-tight: 1.25;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --r-sm: 4px;
  --r: 6px;
  --r-lg: 10px;

  --shadow-pop: 0 4px 16px rgba(27, 25, 23, 0.10), 0 0 0 1px rgba(27, 25, 23, 0.04);
  --shadow-modal: 0 16px 48px rgba(27, 25, 23, 0.18), 0 0 0 1px rgba(27, 25, 23, 0.05);

  --h-ctl: 32px;
  --h-ctl-sm: 28px;
  --h-ctl-lg: 36px;
  --row-h: 40px;

  /* motion: one small language for the whole app (see section 19) */
  --m-instant: 80ms;    /* press feedback */
  --m-fast: 120ms;      /* hover colour, micro state */
  --m-normal: 180ms;    /* state changes, list swaps, chips */
  --m-panel: 220ms;     /* menus, popovers, dialogs entering */
  --m-sheet: 280ms;     /* drawers and bottom sheets entering */
  --m-exit: 140ms;      /* anything leaving is quicker than entering */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-enter: cubic-bezier(0, 0, 0.2, 1);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);
  --t-fast: var(--m-fast);
  --t: var(--m-normal);
  --ease: var(--ease-standard);

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 56px;
  --header-h: 52px;
  --toolbar-h: 44px;
  --page-gutter: 24px;

  /* Legacy aliases still referenced by page templates during migration. */
  --primary-color: var(--accent);
  --primary-rgb: var(--accent-rgb);
  --primary-hover: var(--accent-hover);
  --primary-dark: var(--accent-hover);
  --secondary-color: var(--info);
  --success-color: var(--ok);
  --warning-color: var(--warn);
  --danger-color: var(--danger);
  --info-color: var(--info);
  --success-rgb: 30, 122, 76;
  --warning-rgb: 161, 98, 7;
  --danger-rgb: 180, 35, 24;
  --info-rgb: 36, 87, 166;
  --text-primary: var(--ink);
  --text-secondary: var(--ink-2);
  --text-muted: var(--ink-3);
  --text-light: var(--ink-2);
  --body-bg: var(--bg);
  --bg-card: var(--surface);
  --bg-card-hover: var(--surface-2);
  --bg-sidebar: var(--surface);
  --bg-navbar: var(--surface);
  --bg-input: var(--surface);
  --bg-secondary: var(--surface);
  --bg-tertiary: var(--surface-2);
  --border-color: var(--border);
  --border-light: var(--border-strong);
  --border-radius: var(--r);
  --border-radius-sm: var(--r-sm);
  --border-radius-lg: var(--r-lg);
  --box-shadow: none;
  --box-shadow-lg: var(--shadow-pop);
  --font-family: var(--font);
  --font-mono: var(--mono);
  --dark-color: var(--ink);
  --light-color: var(--bg);
  --accent-glow: transparent;
}

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

  --bg: #141311;
  --surface: #1b1a18;
  --surface-2: #232120;
  --surface-3: #2b2927;
  --border: #2e2c29;
  --border-strong: #3d3a36;
  --ink: #eceae6;
  --ink-2: #a8a49d;
  --ink-3: #77736d;
  --ink-inverse: #1b1917;

  --accent: #d5a46e;
  --accent-hover: #e2b884;
  --accent-ink: #1b1917;
  --accent-soft: #33291e;
  --accent-rgb: 213, 164, 110;

  --ok: #4fb57e;
  --ok-soft: #1c2f25;
  --warn: #d9a441;
  --warn-soft: #33291a;
  --info: #6e9be0;
  --info-soft: #1e2736;
  --danger: #e0655c;
  --danger-soft: #36201f;

  --shadow-pop: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06);

  --success-rgb: 79, 181, 126;
  --warning-rgb: 217, 164, 65;
  --danger-rgb: 224, 101, 92;
  --info-rgb: 110, 155, 224;
}

/* --------------------------------------------------------------------------
   2. Reset and base typography
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
/* puutel ei vilgu nuppudel ja ridadel brauseri sinist/halli esiletõstet */
* { -webkit-tap-highlight-color: transparent; }
@media (hover: none) { a:focus, button:focus, [role="button"]:focus, .seg-item:focus, .filter-chip:focus { outline: none; } }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01" 0, "cv11" 1;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 500;
  line-height: var(--lh-tight);
  color: var(--ink);
  letter-spacing: 0;
}
h1 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4, h5, h6 { font-size: var(--fs-base); }

p { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

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

small, .small { font-size: var(--fs-sm); }
strong, b { font-weight: 500; }
code, kbd, pre, .mono { font-family: var(--mono); font-size: 0.95em; }
kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: var(--fs-xs);
  line-height: 18px;
}

hr, .divider { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }

img, svg, video, canvas { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button, input, select, textarea { margin: 0; }
img, svg { vertical-align: middle; }
label { display: inline-block; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend { padding: 0; }
table { caption-side: bottom; }
[hidden] { display: none !important; }

/* layout/spacing utilities (Bootstrap-compatible names, used sparingly in templates) */
.d-none { display: none !important; } .d-block { display: block !important; } .d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; } .d-flex { display: flex !important; } .d-inline-flex { display: inline-flex !important; }
.align-items-center { align-items: center !important; } .align-items-start { align-items: flex-start !important; } .align-items-end { align-items: flex-end !important; }
.justify-content-between { justify-content: space-between !important; } .justify-content-center { justify-content: center !important; } .justify-content-end { justify-content: flex-end !important; }
.flex-wrap { flex-wrap: wrap !important; } .flex-column { flex-direction: column !important; } .flex-grow-1 { flex-grow: 1 !important; } .flex-shrink-0 { flex-shrink: 0 !important; }
.gap-1 { gap: 4px !important; } .gap-2 { gap: 8px !important; } .gap-3 { gap: 16px !important; }
.w-100 { width: 100% !important; } .h-100 { height: 100% !important; } .min-w-0 { min-width: 0 !important; }
.text-center { text-align: center !important; } .text-end { text-align: right !important; } .text-start { text-align: left !important; } .text-nowrap { white-space: nowrap !important; }
.fw-normal { font-weight: 400 !important; } .fw-medium, .fw-semibold, .fw-bold { font-weight: 500 !important; }
.m-0 { margin: 0 !important; } .mt-1 { margin-top: 4px !important; } .mt-2 { margin-top: 8px !important; } .mt-3 { margin-top: 16px !important; } .mt-4 { margin-top: 24px !important; }
.mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: 4px !important; } .mb-2 { margin-bottom: 8px !important; } .mb-3 { margin-bottom: 16px !important; } .mb-4 { margin-bottom: 24px !important; }
.ms-1 { margin-left: 4px !important; } .ms-2 { margin-left: 8px !important; } .ms-3 { margin-left: 16px !important; } .ms-auto { margin-left: auto !important; }
.me-1 { margin-right: 4px !important; } .me-2 { margin-right: 8px !important; } .me-3 { margin-right: 16px !important; }
.p-0 { padding: 0 !important; } .p-1 { padding: 4px !important; } .p-2 { padding: 8px !important; } .p-3 { padding: 16px !important; } .p-4 { padding: 24px !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-soft); color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--ink-3); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Text utilities */
.text-ink { color: var(--ink) !important; }
.text-2 { color: var(--ink-2) !important; }
.text-3, .text-muted { color: var(--ink-3) !important; }
.text-ok { color: var(--ok) !important; }
.text-warn { color: var(--warn) !important; }
.text-info { color: var(--info) !important; }
.text-danger { color: var(--danger) !important; }
.text-accent { color: var(--accent) !important; }
.fs-xs { font-size: var(--fs-xs) !important; }
.fs-sm { font-size: var(--fs-sm) !important; }
.fs-md { font-size: var(--fs-md) !important; }
.fs-lg { font-size: var(--fs-lg) !important; }
.fw-500 { font-weight: 500 !important; }
.fw-600 { font-weight: 600 !important; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.tnum { font-variant-numeric: tabular-nums; }
.id { font-family: var(--mono); font-size: var(--fs-sm); color: var(--ink-2); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nowrap { white-space: nowrap; }

/* --------------------------------------------------------------------------
   3. Text utilities
   -------------------------------------------------------------------------- */
.text-primary { color: var(--accent) !important; }
.text-success { color: var(--ok) !important; }
.text-warning { color: var(--warn) !important; }
.text-secondary { color: var(--ink-2) !important; }
.bg-light { background: var(--surface-2) !important; }
.bg-white { background: var(--surface) !important; }
.border { border-color: var(--border) !important; }

/* --------------------------------------------------------------------------
   4. Application shell
   -------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  overflow: hidden;
  transition: width var(--t) var(--ease), transform var(--t) var(--ease);
}
[data-sidebar-collapsed="true"] .sidebar,
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
  height: 32px;
}
.sidebar-brand:hover { text-decoration: none; color: var(--ink); }
.sidebar-brand-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-brand-logo img { width: 28px; height: 28px; border-radius: 50%; display: block; }
.sidebar-brand-text { min-width: 0; overflow: hidden; white-space: nowrap; }
.sidebar-brand-name { font-size: var(--fs-md); font-weight: 600; letter-spacing: -0.01em; }

.sidebar-menu {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--sp-2) 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-section-label {
  flex-shrink: 0;   /* menüü on flex-veerg: overflow:hidden lubaks pealkirja kokku pressida, kui menüü ei mahu ekraanile */
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-item { padding: 1px var(--sp-2); }
.sidebar-link, .sidebar-submenu-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r);
  color: var(--ink-2);
  font-size: var(--fs-base);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-link:hover, .sidebar-submenu-toggle:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar-link.active, .sidebar-submenu-toggle.active { background: var(--surface-2); color: var(--ink); font-weight: 500; }
.sidebar-icon {
  width: 20px;
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--ink-3);
  position: relative;
  flex-shrink: 0;
}
.sidebar-link:hover .sidebar-icon, .sidebar-link.active .sidebar-icon { color: var(--ink); }
.sidebar-text { overflow: hidden; text-overflow: ellipsis; opacity: 1; transition: opacity var(--t-fast); }
.sidebar-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: var(--fs-xs);
  color: var(--ink-2);
  background: var(--surface-3);
  border-radius: var(--r-sm);
  padding: 0 5px;
  line-height: 18px;
}

/* collapsed */
[data-sidebar-collapsed="true"] .sidebar .sidebar-text,
[data-sidebar-collapsed="true"] .sidebar .sidebar-brand-text,
[data-sidebar-collapsed="true"] .sidebar .sidebar-section-label,
[data-sidebar-collapsed="true"] .sidebar .sidebar-badge,
[data-sidebar-collapsed="true"] .sidebar .user-info,
[data-sidebar-collapsed="true"] .sidebar .earnings-overview,
[data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-arrow,
.sidebar.collapsed .sidebar-text,
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .sidebar-section-label,
.sidebar.collapsed .sidebar-badge,
.sidebar.collapsed .user-info,
.sidebar.collapsed .earnings-overview,
.sidebar.collapsed .sidebar-submenu-arrow { display: none; }
[data-sidebar-collapsed="true"] .sidebar .sidebar-link,
[data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-toggle,
.sidebar.collapsed .sidebar-link,
.sidebar.collapsed .sidebar-submenu-toggle { justify-content: center; padding: 0; }
[data-sidebar-collapsed="true"] .sidebar .sidebar-item,
.sidebar.collapsed .sidebar-item { padding: 1px var(--sp-2); }
[data-sidebar-collapsed="true"] .sidebar .sidebar-header,
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 0; }

/* submenu */
.sidebar-submenu-group { padding: 1px var(--sp-2); }
.sidebar-submenu-arrow { margin-left: auto; font-size: var(--fs-2xs); color: var(--ink-3); transition: transform var(--t-fast); }
.sidebar-submenu-toggle.open .sidebar-submenu-arrow { transform: rotate(90deg); }
.sidebar-submenu-items { display: grid; grid-template-rows: 0fr; position: relative; margin: 1px 0 3px; transition: grid-template-rows var(--m-panel) var(--ease-standard); }
.sidebar-submenu-items > .sidebar-submenu-inner { min-height: 0; overflow: hidden; }
.sidebar-submenu-items.open { grid-template-rows: 1fr; }
/* õhuke juhtjoon vanema ikooni all, et alammenüü loeks ühe rühmana */
.sidebar-submenu-items::before { content: ""; position: absolute; left: 25px; top: 2px; bottom: 2px; width: 1px; background: var(--border-strong); transition: opacity var(--m-fast); }
.sidebar-submenu-items .sidebar-item { padding-left: 0; padding-right: 0; }
.sidebar .sidebar-submenu-items .sidebar-link { padding-left: 36px; height: 30px; font-size: var(--fs-base); justify-content: flex-start; }
.sidebar-submenu-items .sidebar-link .sidebar-icon { display: none; }
@media (min-width: 992px) {
  /* Ahendamisel voldib rühm kokku sama kiirusega kui riba kitseneb; pärast
     üleminekut läheb sisu ka tab-järjekorrast välja. */
  [data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-items,
  .sidebar.collapsed .sidebar-submenu-items { grid-template-rows: 0fr; }
  [data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-items::before,
  .sidebar.collapsed .sidebar-submenu-items::before { opacity: 0; }
  [data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-items > .sidebar-submenu-inner,
  .sidebar.collapsed .sidebar-submenu-items > .sidebar-submenu-inner { visibility: hidden; transition: visibility 0s linear var(--m-panel); }
}
.sidebar-submenu-items.open > .sidebar-submenu-inner .sidebar-item { animation: ui-fade-in var(--m-normal) var(--ease-enter); }

/* utility + user block */
.sidebar-utility { margin-top: auto; padding-top: var(--sp-2); border-top: 1px solid var(--border); }
.sidebar-notification-badge {
  position: absolute;
  top: -3px;
  right: -4px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--danger);
  color: #fff;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  line-height: 14px;
  text-align: center;
  display: none;
  box-shadow: 0 0 0 2px var(--surface);
}
.sidebar-notification-badge.visible { display: block; }
[data-sidebar-collapsed="true"] .sidebar-notification-badge {
  min-width: 7px; width: 7px; height: 7px; padding: 0; font-size: 0; top: 0; right: 1px; border-radius: 50%;
}

.user-profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: var(--sp-1) var(--sp-2) var(--sp-2);
  padding: 6px 10px;
  border-radius: var(--r);
  cursor: pointer;
  min-height: 44px;
  transition: background var(--t-fast);
}
.user-profile-card:hover { background: var(--surface-2); }
.user-profile-header { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-info { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.user-name { font-size: var(--fs-base); font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role-badge { font-size: var(--fs-xs); color: var(--ink-3); display: inline-flex; gap: 4px; align-items: center; }
.user-role-badge i { display: none; }
[data-sidebar-collapsed="true"] .user-profile-card,
.sidebar.collapsed .user-profile-card { justify-content: center; padding: 6px 0; }

.earnings-overview { padding: 0 var(--sp-2) var(--sp-2); }
.earnings-stats { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.earnings-item {
  border: 0;
  font: inherit;
  padding: 6px 8px;
  cursor: pointer;
  min-width: 0;
  text-align: left;
  background: var(--surface);
  transition: background var(--t-fast);
}
.earnings-item + .earnings-item { border-left: 1px solid var(--border); }
.earnings-item:hover { background: var(--surface-2); }
.earnings-label { display: block; font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.2; }
.earnings-amount {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  filter: blur(5px);
  user-select: none;
  transition: filter var(--t-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.earnings-item.revealed .earnings-amount { filter: none; }
.earnings-item.pending .earnings-amount { color: var(--warn); }
.earnings-item.confirmed .earnings-amount { color: var(--ok); }

/* sidebar collapse handle */
.sidebar-toggle-btn {
  position: fixed;
  top: 50%;
  left: calc(var(--sidebar-w) - 1px);
  transform: translateY(-50%);
  width: 16px;
  height: 36px;
  border-radius: 0 var(--r) var(--r) 0;
  border: 1px solid var(--border);
  border-left: 0;
  background: var(--surface);
  color: var(--ink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 1060;
  opacity: 0.7;
  transition: left var(--t) var(--ease), opacity var(--t-fast), color var(--t-fast);
}
.sidebar-toggle-btn i { font-size: 9px; }
.sidebar:hover ~ .sidebar-toggle-btn, .sidebar-toggle-btn:hover, .sidebar-toggle-btn:focus-visible { opacity: 1; }
.sidebar-toggle-btn:hover { color: var(--ink); background: var(--surface-2); }
[data-sidebar-collapsed="true"] .sidebar-toggle-btn { left: calc(var(--sidebar-w-collapsed) - 1px); }
[data-sidebar-collapsed="true"] .sidebar-toggle-btn i { transform: rotate(180deg); }

/* main column */
.main-content {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  max-width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  position: relative;
  transition: margin-left var(--t) var(--ease), width var(--t) var(--ease), max-width var(--t) var(--ease);
}
[data-sidebar-collapsed="true"] .main-content,
body.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-w-collapsed);
  width: calc(100% - var(--sidebar-w-collapsed));
  max-width: calc(100% - var(--sidebar-w-collapsed));
}
body:not(.authenticated) .main-content { margin-left: 0; width: 100%; max-width: 100%; }
.main-content > .container-fluid { padding: 0; margin: 0; max-width: none; }

html:not(.transitions-ready) .sidebar,
html:not(.transitions-ready) .main-content,
html:not(.transitions-ready) .sidebar-toggle-btn { transition: none !important; }

/* mobile header + drawer */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 1040;
  height: 48px;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.mobile-header-logo { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: var(--fs-md); }
.mobile-header-logo:hover { text-decoration: none; color: var(--ink); }
.mobile-header-logo img { width: 24px; height: 24px; border-radius: 50%; }
.mobile-header-right { display: flex; align-items: center; gap: var(--sp-2); }
.mobile-menu-btn {
  width: 36px; height: 36px; border-radius: var(--r); border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(27, 25, 23, 0.4); z-index: 1049; opacity: 0;
  transition: opacity var(--t);
}
body.sidebar-open .sidebar-backdrop { display: block; opacity: 1; }
.sidebar-page-overlay { display: none; }

@media (max-width: 991.98px) {
  .sidebar, [data-sidebar-collapsed="true"] .sidebar, .sidebar.collapsed {
    width: min(300px, 84vw);
    transform: translateX(-100%);
    z-index: 1060;
    transition: transform var(--t) var(--ease);
  }
  .sidebar.show { transform: translateX(0); }
  /* on mobile the drawer is always the expanded layout */
  .sidebar.collapsed .sidebar-text, .sidebar.collapsed .sidebar-brand-text, .sidebar.collapsed .user-info,
  .sidebar.collapsed .earnings-overview, .sidebar.collapsed .sidebar-section-label, .sidebar.collapsed .sidebar-badge,
  .sidebar.collapsed .sidebar-submenu-arrow,
  [data-sidebar-collapsed="true"] .sidebar .sidebar-text, [data-sidebar-collapsed="true"] .sidebar .sidebar-brand-text,
  [data-sidebar-collapsed="true"] .sidebar .user-info, [data-sidebar-collapsed="true"] .sidebar .earnings-overview,
  [data-sidebar-collapsed="true"] .sidebar .sidebar-section-label, [data-sidebar-collapsed="true"] .sidebar .sidebar-badge,
  [data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-arrow { display: initial; }
  .sidebar.collapsed .sidebar-text, [data-sidebar-collapsed="true"] .sidebar .sidebar-text { display: inline; }
  /* pealkirjad on sahtlis alati plokid ja saavad rohkem õhku, et rühmad eristuksid */
  .sidebar-section-label, .sidebar.collapsed .sidebar-section-label, [data-sidebar-collapsed="true"] .sidebar .sidebar-section-label { display: block; padding: var(--sp-5) var(--sp-4) var(--sp-2); font-size: var(--fs-sm); }
  .sidebar-menu > .sidebar-section-label:first-child { padding-top: var(--sp-3); }
  .sidebar.collapsed .user-info, [data-sidebar-collapsed="true"] .sidebar .user-info { display: flex; }
  .sidebar.collapsed .earnings-overview, [data-sidebar-collapsed="true"] .sidebar .earnings-overview { display: block; }
  .sidebar.collapsed .sidebar-link, [data-sidebar-collapsed="true"] .sidebar .sidebar-link { justify-content: flex-start; padding: 0 10px; }
  .sidebar.collapsed .sidebar-header, [data-sidebar-collapsed="true"] .sidebar .sidebar-header { justify-content: flex-start; padding: 0 var(--sp-3); }
  .sidebar.collapsed .user-profile-card, [data-sidebar-collapsed="true"] .sidebar .user-profile-card { justify-content: flex-start; padding: 6px 10px; }
  .sidebar.collapsed .sidebar-submenu-items, [data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-items { display: grid !important; }
  .sidebar.collapsed .sidebar-submenu-items .sidebar-link, [data-sidebar-collapsed="true"] .sidebar .sidebar-submenu-items .sidebar-link { padding-left: 36px; }
  .sidebar-toggle-btn { display: none; }
  .main-content, [data-sidebar-collapsed="true"] .main-content, body.sidebar-collapsed .main-content {
    margin-left: 0; width: 100%; max-width: 100%;
  }
  .mobile-header { display: flex; }
  body.sidebar-open { overflow: hidden; }
}

/* --------------------------------------------------------------------------
   5. Page structure
   -------------------------------------------------------------------------- */
.page { padding: 0 var(--page-gutter) var(--sp-10); }
.page--narrow > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.page--wide > * { max-width: 1200px; margin-left: auto; margin-right: auto; }
/* header and toolbar stay full-bleed; their content lines up with the centred body */
.page--narrow .page-header, .page--wide .page-header, .page--narrow .page-toolbar, .page--wide .page-toolbar { max-width: none; }
.page--narrow .page-header { padding-left: max(var(--page-gutter), calc((100% - 760px) / 2)); padding-right: max(var(--page-gutter), calc((100% - 760px) / 2)); }
.page--wide .page-header { padding-left: max(var(--page-gutter), calc((100% - 1200px) / 2)); padding-right: max(var(--page-gutter), calc((100% - 1200px) / 2)); }
.page--narrow .page-toolbar { padding-left: max(0px, calc((100% - 760px) / 2)); padding-right: max(0px, calc((100% - 760px) / 2)); }
.page--wide .page-toolbar { padding-left: max(0px, calc((100% - 1200px) / 2)); padding-right: max(0px, calc((100% - 1200px) / 2)); }
.page-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin: 0 calc(-1 * var(--page-gutter)) 0;
  padding: var(--sp-2) var(--page-gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.page-header + .page-toolbar { margin-top: 0; }
.page-header-main { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; flex: 1; }
.page-title { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-title-group { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.page-title-meta { font-size: var(--fs-sm); color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; margin-left: auto; }
.page-back {
  width: 28px; height: 28px; border-radius: var(--r); display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); flex-shrink: 0; border: 1px solid transparent;
}
.page-back:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }

.page-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  min-height: var(--toolbar-h);
  padding: var(--sp-2) 0;
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.page-toolbar-end { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.page-toolbar:has(+ .stat-row) { border-bottom: 0; margin-bottom: var(--sp-1); padding-bottom: 0; }
.page-body { padding-top: var(--sp-4); }
.page-header + .page-body { padding-top: var(--sp-5); }
.page-section { margin-bottom: var(--sp-6); }
.section-title {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.section-title .count { margin-left: 2px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.section-head h2 { font-size: var(--fs-md); font-weight: 500; }

@media (max-width: 991.98px) {
  :root { --page-gutter: 16px; }
  .page-header { top: 48px; min-height: 48px; }
  .page-title { font-size: 17px; }
  .page-header { flex-wrap: wrap; }
}

/* --------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--border-strong);
  --btn-bg-h: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--h-ctl);
  padding: 0 12px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-base);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  transition: background var(--m-fast), border-color var(--m-fast), color var(--m-fast), transform var(--m-instant), opacity var(--m-fast);
  box-shadow: none;
}
.btn:hover { background: var(--btn-bg-h); color: var(--btn-fg); border-color: var(--btn-bd); text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled, .btn.disabled { opacity: 0.5; pointer-events: none; }
.btn i, .btn svg { font-size: 13px; width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center; }
.btn svg { width: 14px; height: 14px; }

.btn--primary, .btn-primary {
  --btn-bg: var(--ink); --btn-fg: var(--ink-inverse); --btn-bd: var(--ink); --btn-bg-h: #34302c;
}
[data-theme="dark"] .btn--primary, [data-theme="dark"] .btn-primary { --btn-bg-h: #ffffff; }
.btn--secondary, .btn-secondary, .btn-outline-primary, .btn-outline-secondary, .btn-light, .btn-outline-dark,
.btn-outline-success, .btn-outline-info, .btn-outline-warning, .btn-outline-danger {
  --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-bd: var(--border-strong); --btn-bg-h: var(--surface-2);
}
.btn-outline-danger { --btn-fg: var(--danger); }
.btn--ghost, .btn-link {
  --btn-bg: transparent; --btn-fg: var(--ink-2); --btn-bd: transparent; --btn-bg-h: var(--surface-2);
}
.btn--ghost:hover, .btn-link:hover { color: var(--ink); text-decoration: none; }
.btn--danger, .btn-danger:not(.btn--solid) {
  --btn-bg: var(--surface); --btn-fg: var(--danger); --btn-bd: var(--border-strong); --btn-bg-h: var(--danger-soft);
}
/* a bare destructive icon rests neutral and only turns red under the pointer/focus */
.btn--ghost.text-danger, .btn--ghost.btn--icon.text-danger { color: var(--ink-3) !important; }
.btn--ghost.text-danger:hover, .btn--ghost.text-danger:focus-visible { color: var(--danger) !important; background: var(--danger-soft); }
.btn--danger.btn--solid, .btn-danger.btn--solid {
  --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); --btn-bg-h: #96190f;
}
.btn--accent, .btn-success, .btn-info, .btn-warning, .btn-dark {
  --btn-bg: var(--ink); --btn-fg: var(--ink-inverse); --btn-bd: var(--ink); --btn-bg-h: #34302c;
}
[data-theme="dark"] .btn--accent, [data-theme="dark"] .btn-success, [data-theme="dark"] .btn-info,
[data-theme="dark"] .btn-warning, [data-theme="dark"] .btn-dark { --btn-bg-h: #ffffff; }

.btn--sm, .btn-sm { height: var(--h-ctl-sm); padding: 0 10px; font-size: var(--fs-sm); }
.btn--lg, .btn-lg { height: var(--h-ctl-lg); padding: 0 16px; font-size: var(--fs-md); }
.btn--icon { width: var(--h-ctl); padding: 0; flex-shrink: 0; }   /* never squeezed below its tap target by a flex row */
.btn--icon.btn--sm { width: var(--h-ctl-sm); }
.btn--icon.btn--lg { width: var(--h-ctl-lg); }
.btn--block, .w-100.btn { width: 100%; }
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin 0.7s linear infinite;
}
.btn--primary.is-loading::after, .btn-primary.is-loading::after { border-color: var(--ink-inverse); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; margin-left: -1px; }
.btn-group > .btn:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.btn-group > .btn:last-child { border-radius: 0 var(--r) var(--r) 0; }
.btn-group > .btn.active { background: var(--surface-2); color: var(--ink); z-index: 1; }
.btn-close { width: 28px; height: 28px; padding: 0; border: 0; border-radius: var(--r); background: transparent; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; font-size: 0; cursor: pointer; }
.btn-close::before { content: "\00d7"; font-size: 17px; line-height: 1; }
.btn-close:hover { background: var(--surface-2); color: var(--ink); }


/* --------------------------------------------------------------------------
   7. Forms
   -------------------------------------------------------------------------- */
.input, .select, .textarea,
.form-control, .form-select {
  display: block;
  width: 100%;
  height: var(--h-ctl);
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-base);
  line-height: calc(var(--h-ctl) - 2px);
  box-shadow: none;
  transition: border-color var(--m-fast), background var(--m-fast), box-shadow var(--m-fast);
  -webkit-appearance: none;
  appearance: none;
}
.textarea, textarea.form-control { height: auto; min-height: 80px; padding: 8px 10px; line-height: var(--lh); resize: vertical; }
.select, .form-select {
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%238b8781' stroke-width='1.5'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.form-select-sm, .select--sm, .input--sm, .form-control-sm { height: var(--h-ctl-sm); line-height: calc(var(--h-ctl-sm) - 2px); font-size: var(--fs-sm); padding: 0 8px; }
.form-select-sm, .select--sm { padding-right: 26px; }
.form-control-lg, .input--lg { height: var(--h-ctl-lg); line-height: calc(var(--h-ctl-lg) - 2px); font-size: var(--fs-md); }
.input::placeholder, .form-control::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .select:hover, .textarea:hover, .form-control:hover, .form-select:hover { border-color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus, .form-control:focus, .form-select:focus {
  border-color: var(--accent); outline: none; box-shadow: 0 0 0 1px var(--accent); background: var(--surface); color: var(--ink);
}
.input:disabled, .select:disabled, .textarea:disabled, .form-control:disabled, .form-select:disabled,
.form-control[readonly] { background: var(--surface-2); color: var(--ink-2); cursor: not-allowed; border-color: var(--border); }
.is-invalid, .form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger) !important; background-image: none; }
.is-invalid:focus { box-shadow: 0 0 0 1px var(--danger) !important; }
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"] { font-family: var(--font); }
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="file"].form-control { padding: 0; line-height: calc(var(--h-ctl) - 2px); }
input[type="file"].form-control::file-selector-button {
  height: calc(var(--h-ctl) - 2px); padding: 0 10px; margin-right: 10px; border: 0; border-right: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--ink); font-weight: 500;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }
.field-label, .form-label, label.form-check-label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.field-label .req::after, .form-label .req::after, .req::after {
  content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); margin-left: 4px; vertical-align: middle;
}
.field-hint, .form-text { font-size: var(--fs-sm); color: var(--ink-3); margin: 0; }
.field-error, .invalid-feedback { display: none; font-size: var(--fs-sm); color: var(--danger); margin: 0; }
.is-invalid ~ .invalid-feedback, .field.is-invalid .field-error, .is-invalid ~ .field-error { display: block; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
.form-grid > .field { margin-bottom: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (min-width: 768px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid--3 { grid-template-columns: repeat(3, 1fr); } }
.form-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2);
  padding-top: var(--sp-4); margin-top: var(--sp-4); border-top: 1px solid var(--border);
}
.form-actions .btn--ghost, .form-actions .btn-link { margin-right: auto; }
.mb-3 .form-label, .mb-4 .form-label, .mb-2 .form-label { margin-bottom: 6px; }

.input-group { display: flex; align-items: stretch; width: 100%; }
.input-group > .form-control, .input-group > .form-select, .input-group > .input, .input-group > .select { flex: 1; min-width: 0; }
.input-group > :not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.input-group > :not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group-text {
  display: inline-flex; align-items: center; padding: 0 10px; height: var(--h-ctl);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-sm); border-radius: var(--r); white-space: nowrap;
}
.input-group-sm > .input-group-text { height: var(--h-ctl-sm); }
.input-group .btn { height: var(--h-ctl); }

/* checkbox / radio / switch */
.checkbox, .radio, input[type="checkbox"].form-check-input, input[type="radio"].form-check-input,
input[type="checkbox"]:not(.switch):not([role="switch"]), input[type="radio"] {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin: 0; flex-shrink: 0;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
  display: inline-grid; place-content: center; cursor: pointer; vertical-align: middle;
  transition: border-color var(--t-fast), background var(--t-fast);
}
input[type="radio"], .radio { border-radius: 50%; }
input[type="checkbox"]:not(.switch):not([role="switch"])::before, .checkbox::before {
  content: ""; width: 10px; height: 10px; transform: scale(0); transition: transform var(--m-fast) var(--ease-enter);
  background: var(--ink-inverse);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
input[type="radio"]::before, .radio::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-inverse); transform: scale(0); transition: transform var(--m-fast) var(--ease-enter); }
input[type="checkbox"]:not(.switch):not([role="switch"]):checked, input[type="radio"]:checked, .checkbox:checked, .radio:checked { background: var(--ink); border-color: var(--ink); }
input[type="checkbox"]:checked::before, input[type="radio"]:checked::before, .checkbox:checked::before, .radio:checked::before { transform: scale(1); }
input[type="checkbox"]:indeterminate { background: var(--ink); border-color: var(--ink); }
input[type="checkbox"]:indeterminate::before { transform: scale(1); clip-path: inset(40% 15% 40% 15%); }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--ink-3); }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { opacity: 0.5; cursor: not-allowed; }
.form-check { display: flex; align-items: center; gap: 8px; min-height: 0; padding: 0; margin: 0; }
.form-check-input { float: none; margin: 0; }
.form-check-label { cursor: pointer; font-size: var(--fs-base); color: var(--ink); font-weight: 400; }
.form-check-inline { display: inline-flex; margin-right: var(--sp-4); }
.form-switch { padding: 0; }
.form-switch .form-check-input, input[type="checkbox"].switch, input[type="checkbox"][role="switch"] {
  -webkit-appearance: none; appearance: none; width: 30px; height: 18px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface-3); position: relative; cursor: pointer; margin: 0; flex-shrink: 0; background-image: none; transition: background var(--t-fast), border-color var(--t-fast);
}
.form-switch .form-check-input::before, input[type="checkbox"].switch::before, input[type="checkbox"][role="switch"]::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); clip-path: none; transform: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2); transition: transform var(--m-normal) var(--ease-standard), background var(--m-fast);
}
.form-switch .form-check-input:checked, input[type="checkbox"].switch:checked, input[type="checkbox"][role="switch"]:checked { background: var(--ink); border-color: var(--ink); background-image: none; }
.form-switch .form-check-input:checked::before, input[type="checkbox"].switch:checked::before, input[type="checkbox"][role="switch"]:checked::before { transform: translateX(12px); background: var(--ink-inverse); }

/* search */
.search { position: relative; display: flex; align-items: center; min-width: 200px; }
.search > i, .search > svg, .search-icon { position: absolute; left: 10px; color: var(--ink-3); font-size: 13px; pointer-events: none; width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center; }
.search > .input, .search > .form-control, .search-input { padding-left: 30px; padding-right: 28px; }
.search-clear {
  position: absolute; right: 4px; width: 24px; height: 24px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-3);
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px;
}
.search-clear:hover { background: var(--surface-2); color: var(--ink); }
.search-clear:empty, .search-clear[hidden] { display: none; }
.search > .search-clear { opacity: 0; transform: scale(0.85); pointer-events: none; transition: opacity var(--m-fast), transform var(--m-fast) var(--ease-enter), background var(--m-fast), color var(--m-fast); }
.search.has-value > .search-clear, .search > .search-clear.is-visible { opacity: 1; transform: none; pointer-events: auto; }

/* --------------------------------------------------------------------------
   8. Tables
   -------------------------------------------------------------------------- */
.table-wrap, .table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap > .table { margin: 0; }
/* grid/flex children may not grow past their track because of a wide table inside */
.panel, .card, .table-wrap, .table-container { min-width: 0; }
.table-responsive { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ink);
  font-size: var(--fs-base);
  margin-bottom: 0;
}
.table > :not(caption) > * > * { padding: 0 12px; background: transparent; box-shadow: none; border-bottom: 1px solid var(--border); }
.table thead th, .table > thead > tr > th {
  height: 36px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  border-top: 0;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
.table tbody td, .table > tbody > tr > td { height: var(--row-h); vertical-align: middle; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast); }
.table-hover tbody tr:hover, .table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-selected, .table tbody tr.selected { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.table tbody tr.is-muted td { color: var(--ink-3); }
.table--compact tbody td, .table-sm tbody td { height: 34px; padding: 0 10px; }
.table--compact thead th, .table-sm thead th { height: 32px; padding: 0 10px; }
.table--sticky thead th { position: sticky; top: 0; z-index: 2; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.table td.num, .table td.id, .table td.tnum, .value-text, .stat-value, .list-item-aside { white-space: nowrap; }
.table td.id, .table th.id { font-family: var(--mono); font-size: var(--fs-sm); color: var(--ink-2); }
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; width: 1%; }
.table td.actions .btn { vertical-align: middle; }
.table td.actions .btn + .btn { margin-left: 2px; }
.table .th-sort { cursor: pointer; user-select: none; }
.table .th-sort:hover { color: var(--ink); }
.table .th-sort i { font-size: var(--fs-2xs); margin-left: 4px; opacity: 0.6; }
.table-striped > tbody > tr:nth-of-type(odd) > * { background: transparent; }
.table-bordered > :not(caption) > * > * { border-width: 0 0 1px; }
.table tfoot td, .table tfoot th { font-weight: 500; background: var(--surface-2); border-top: 1px solid var(--border-strong); height: 36px; }
.table .thumb { width: 36px; height: 36px; border-radius: var(--r-sm); object-fit: cover; background: var(--surface-2); display: block; }
.table-footer, .table-wrap .pager {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 8px 12px; border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--ink-2); background: var(--surface);
}
.table-wrap .empty { border: 0; }

/* --------------------------------------------------------------------------
   9. Status, counts, tags, avatars
   -------------------------------------------------------------------------- */
.status {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-base); color: var(--ink); white-space: nowrap; line-height: 1;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex-shrink: 0; }
.status--ok::before, .status--success::before, .status-repaired::before, .status-verified::before { background: var(--ok); }
.status--warn::before, .status--warning::before, .status-pending::before { background: var(--warn); }
.status--info::before, .status-in_progress::before, .status-in-progress::before { background: var(--info); }
.status--danger::before, .status--error::before, .status-not_repairable::before, .status-urgent::before { background: var(--danger); }
.status--muted::before { background: var(--ink-3); }
.status--sm { font-size: var(--fs-sm); }
.status--sm::before { width: 6px; height: 6px; }
.status.is-text-colored.status--ok { color: var(--ok); }
.status.is-text-colored.status--warn { color: var(--warn); }
.status.is-text-colored.status--info { color: var(--info); }
.status.is-text-colored.status--danger { color: var(--danger); }

.count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--r-sm); background: var(--surface-3); color: var(--ink-2);
  font-family: var(--mono); font-size: var(--fs-xs); font-weight: 500; line-height: 1;
}
.count--accent { background: var(--ink); color: var(--ink-inverse); }
.count--danger { background: var(--danger); color: #fff; }

.tag, .badge {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
  color: var(--ink-2); font-size: var(--fs-xs); font-weight: 500; line-height: 1; white-space: nowrap; vertical-align: middle;
}
.tag--ok, .badge.bg-success, .badge.text-bg-success { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-soft) !important; }
.tag--warn, .badge.bg-warning, .badge.text-bg-warning { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-soft) !important; }
.tag--info, .badge.bg-info, .badge.bg-primary, .badge.text-bg-primary, .badge.text-bg-info { color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, transparent); background: var(--info-soft) !important; }
.tag--danger, .badge.bg-danger, .badge.text-bg-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft) !important; }
.tag--accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }
.badge.bg-secondary, .badge.bg-light, .badge.bg-dark, .badge.text-bg-secondary, .badge.text-bg-light { background: var(--surface-2) !important; color: var(--ink-2) !important; }
.badge.rounded-pill { border-radius: var(--r-sm) !important; }

.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); color: var(--ink-2);
  font-size: var(--fs-sm); font-weight: 500; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 22px; height: 22px; font-size: var(--fs-2xs); }
.avatar--lg { width: 40px; height: 40px; font-size: var(--fs-md); }

/* --------------------------------------------------------------------------
   10. Panels, lists, stats
   -------------------------------------------------------------------------- */
.panel, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: none;
  overflow: visible;
}
.card:hover { box-shadow: none; border-color: var(--border); }
.panel-header, .card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: 44px; padding: 8px var(--sp-4); border-bottom: 1px solid var(--border); background: transparent;
}
.panel-title, .card-header h5, .card-header h4, .card-header h3, .card-header h6, .card-title { font-size: var(--fs-md); font-weight: 500; margin: 0; color: var(--ink); }
.panel-title small, .panel-sub { font-size: var(--fs-sm); color: var(--ink-2); font-weight: 400; margin-left: 6px; }
.panel-actions { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }
.panel-body, .card-body { padding: var(--sp-4); }
.panel-body--flush, .card-body--flush { padding: 0; }
.panel-footer, .card-footer { padding: 8px var(--sp-4); border-top: 1px solid var(--border); background: transparent; display: flex; align-items: center; gap: var(--sp-2); }
.card-subtitle { color: var(--ink-2); font-size: var(--fs-sm); }
.panel .panel, .card .card { border: 0; border-radius: 0; }
.panel > .table-wrap, .card > .table-wrap { border: 0; border-radius: 0; }
.panel-header + .table-wrap { border-top: 0; }

.list { display: flex; flex-direction: column; }
.list--boxed { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
.list-item {
  display: flex; align-items: center; gap: var(--sp-3); min-height: var(--row-h); padding: 8px 12px;
  border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; transition: background var(--t-fast);
}
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, .list-item.is-clickable:hover { background: var(--surface-2); text-decoration: none; color: inherit; }
.list-item.is-selected { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.list-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-item-title { font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-meta { font-size: var(--fs-sm); color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.list-item-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.list-item-aside { flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--sp-4); align-items: baseline; font-size: var(--fs-base); }
.kv dt { color: var(--ink-2); font-weight: 400; font-size: var(--fs-sm); margin: 0; }
.kv dd { margin: 0; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.kv--stack { grid-template-columns: 1fr; gap: 2px; }
.kv--stack dt { margin-top: var(--sp-3); }
.kv--stack dt:first-child { margin-top: 0; }

.stat-row {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  margin: 0 0 var(--sp-4) calc(-1 * var(--sp-4));
  border-bottom: 1px solid var(--border);
}
.stat {
  border: 0;
  font: inherit;
  flex: 0 0 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  padding: 6px var(--sp-4) 10px; text-align: left; background: transparent; color: inherit; text-decoration: none;
}
.stat-label { font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: var(--fs-xl); font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; color: var(--ink); }
.stat-value small, .stat-unit { font-size: var(--fs-sm); font-weight: 400; color: var(--ink-2); margin-left: 1px; }
.stat-delta { font-size: var(--fs-sm); color: var(--ink-3); }
.stat-delta.up { color: var(--ok); } .stat-delta.down { color: var(--danger); }
a.stat, button.stat, .stat.is-clickable { cursor: pointer; border-radius: var(--r) var(--r) 0 0; }
a.stat:hover, button.stat:hover, .stat.is-clickable:hover { background: var(--surface-2); text-decoration: none; }
.stat { transition: background var(--m-instant), box-shadow var(--m-fast) var(--ease-standard); }
.stat.is-active { box-shadow: inset 0 -2px 0 var(--accent); }
.stat--sm .stat-value { font-size: var(--fs-lg); }
/* inside a card the stats share the card evenly instead of hugging their content */
.stat-row--split {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  margin: 0; border-bottom: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden;
}
.stat-row--split { position: relative; align-items: stretch; }
.stat-row--split > .stat { padding: 10px var(--sp-4) 11px; border-right: 1px solid var(--border); border-radius: 0; }
.stat-row--split > .stat:last-child { border-right: 0; }
/* the active mark is one bar that slides between cells (ui.js positions it) */
.stat-indicator { position: absolute; left: 0; bottom: 0; width: 0; height: 2px; background: var(--accent); pointer-events: none; opacity: 0; z-index: 1; }
.stat-row--split.has-indicator > .stat-indicator { opacity: 1; }
.stat-row--split.has-indicator.is-ready > .stat-indicator { transition: transform var(--m-normal) var(--ease-standard), width var(--m-normal) var(--ease-standard); }
.stat-row--split.has-indicator > .stat.is-active, .stat-row--split.has-indicator > .stat.active-filter { box-shadow: none; }
/* focus must still win on the active cell, whose underline is cleared above */
.stat-row--split.has-indicator > button.stat:focus-visible,
.stat-row--split.has-indicator > a.stat:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
/* end cells curve with the container so hover fill and focus ring follow it too */
.stat-row--split.has-indicator > .stat:first-of-type { border-radius: 5px 0 0 5px; }
.stat-row--split.has-indicator > .stat:last-child { border-radius: 0 5px 5px 0; }
.stat-row--split > button.stat:active, .stat-row--split > a.stat:active { background: var(--surface-3); }
.stat-row--split > button.stat:focus-visible, .stat-row--split > a.stat:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
/* 992–1399px: the sidebar still takes 232px, so tables get the tighter gutter
   and text cells truncate earlier. */
@media (min-width: 992px) and (max-width: 1399.98px) {
  .table > :not(caption) > * > * { padding-left: 10px; padding-right: 10px; }
  .page { --page-gutter: 20px; }
}
/* 768–1399px a wide table may scroll sideways. Row actions stay pinned to the
   right edge so they are never the thing that scrolls out of reach. Phones are
   left alone: there a pinned column would cost a third of the viewport. */
@media (min-width: 768px) and (max-width: 1399.98px) {
  .table th.actions, .table td.actions { position: sticky; right: 0; background: var(--surface); }
  .table thead th.actions { background: var(--surface-2); }
  .table tbody tr:hover td.actions { background: var(--surface-2); }
  .table tbody tr.is-selected td.actions { background: var(--accent-soft); }
  [data-theme="dark"] .table tbody tr:hover td.actions { background: var(--surface-2); }
}
@media (max-width: 767.98px) {
  .stat-row { gap: 0; }
  .stat-row > .stat { flex: 1 0 auto; min-width: 40%; }
  .stat-row--split { grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: 1fr 1fr; }
  .stat-row--split > .stat:nth-child(2n) { border-right: 0; }
  .stat-row--split > .stat:nth-child(n+3) { border-top: 1px solid var(--border); }
}

/* --------------------------------------------------------------------------
   11. Tabs, segmented, filters
   -------------------------------------------------------------------------- */
.tabs, .nav-tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab, .nav-tabs .nav-link {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 4px; margin: 0 8px -1px 0;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  color: var(--ink-2); font-size: var(--fs-base); font-weight: 500; white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.tab:hover, .nav-tabs .nav-link:hover { color: var(--ink); border-color: var(--border-strong); background: none; isolation: auto; }
.tab.active, .tab.is-active, .nav-tabs .nav-link.active { color: var(--ink); border-bottom-color: var(--accent); background: none; }
.tab .count { margin-left: 2px; }
.tab-content > .tab-pane { padding-top: var(--sp-4); }

.seg { display: inline-flex; position: relative; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); padding: 2px; gap: 2px; }
/* one indicator slides between items instead of each item repainting */
.seg-indicator { position: absolute; top: 0; left: 0; width: 0; height: 0; border-radius: var(--r-sm); background: var(--ink); pointer-events: none; z-index: 0; opacity: 0; }
.seg.has-indicator > .seg-indicator { opacity: 1; }
.seg.has-indicator.is-ready > .seg-indicator { transition: transform var(--m-normal) var(--ease-standard), width var(--m-normal) var(--ease-standard), height var(--m-normal) var(--ease-standard); }
.seg.has-indicator > .seg-item { position: relative; z-index: 1; }
.seg.has-indicator > .seg-item.active, .seg.has-indicator > .seg-item.is-active { background: transparent; }
.seg-item {
  height: calc(var(--h-ctl) - 6px); padding: 0 10px; border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--ink-2); font-size: var(--fs-sm); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap;
  transition: background var(--m-fast), color var(--m-fast), transform var(--m-instant); text-decoration: none;
}
.seg-item:hover { color: var(--ink); text-decoration: none; }
.seg-item:active { transform: translateY(0.5px); }
.seg-item.active, .seg-item.is-active { background: var(--ink); color: var(--ink-inverse); }
.seg-item .count { background: rgba(255,255,255,0.18); color: inherit; }
.seg-item:not(.active) .count { background: var(--surface-3); color: var(--ink-2); }

.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; height: var(--h-ctl-sm); padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: var(--r); background: var(--surface); color: var(--ink-2); font-size: var(--fs-sm); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--m-fast), color var(--m-fast), border-color var(--m-fast), transform var(--m-instant);
}
.filter-chip:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.filter-chip:active { transform: translateY(0.5px); }
.filter-chip.active, .filter-chip.is-active { background: var(--ink); color: var(--ink-inverse); border-color: var(--ink); }
.filter-chip .count { background: var(--surface-3); color: var(--ink-2); }
.filter-chip.active .count { background: rgba(255,255,255,0.18); color: inherit; }
.filter-chip i { font-size: 11px; }
.filter-chip--dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--ink-3)); }
.filter-chip.active.filter-chip--dot::before { box-shadow: 0 0 0 1px rgba(255,255,255,0.5); }

/* Toolbar filters: inline on desktop, bottom sheet behind a "Filtrid" button on mobile (ui.js) */
.page-toolbar > .search { flex: 1 1 220px; max-width: 360px; }
.seg--scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.seg--scroll::-webkit-scrollbar { display: none; }
.seg--scroll .seg-item { flex-shrink: 0; }
.toolbar-filters { display: contents; }
.toolbar-filters-toggle { display: none; }
.toolbar-filters-toggle[aria-expanded="true"] { background: var(--surface-2); border-color: var(--ink-3); color: var(--ink); }
.toolbar-filters-head, .toolbar-filters-foot { display: none; }
.toolbar-filters-backdrop { position: fixed; inset: 0; z-index: 1090; background: rgba(27, 25, 23, 0.45); }
@media (max-width: 991.98px) {
  .page-toolbar > .search { max-width: none; flex-basis: 100%; }
  .toolbar-filters-toggle { display: inline-flex; }
  .toolbar-filters { display: none; }
  .toolbar-filters.is-open, .toolbar-filters.is-closing {
    display: flex; flex-direction: column; align-items: stretch; gap: 10px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1091; max-height: 85vh; overflow-y: auto;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--surface);
    border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-modal);
  }
  .toolbar-filters.is-open { animation: ui-sheet-in var(--m-sheet) var(--ease-enter); }
  .toolbar-filters.is-closing { animation: ui-sheet-out var(--m-exit) var(--ease-exit) forwards; pointer-events: none; }
  .toolbar-filters-backdrop { animation: ui-fade-in var(--m-panel) var(--ease-enter); }
  .toolbar-filters-backdrop.is-closing { animation: ui-fade-out var(--m-exit) var(--ease-exit) forwards; }
  .toolbar-filters.is-open .select, .toolbar-filters.is-open .input { width: 100%; max-width: none; height: var(--h-ctl); }
  .toolbar-filters.is-open .seg { width: 100%; }
  .toolbar-filters.is-open .toolbar-filters-head { display: flex; align-items: center; justify-content: space-between; font-weight: 500; font-size: var(--fs-md); padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  .toolbar-filters.is-open .toolbar-filters-foot { display: block; padding-top: 4px; }
}

/* --------------------------------------------------------------------------
   12. Dropdowns, tooltips, popovers
   -------------------------------------------------------------------------- */
.dropdown, .dropup { position: relative; }
.dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0; z-index: 1000; margin: 4px 0 0; list-style: none; text-align: left;
  min-width: 180px; padding: 4px; border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); font-size: var(--fs-base);
}
.dropdown-menu.show { display: block; animation: ui-menu-in var(--m-panel) var(--ease-enter); transform-origin: top left; }
.dropdown-menu-end.show { transform-origin: top right; }
.dropup .dropdown-menu.show { transform-origin: bottom left; }
.dropdown-menu.is-leaving { display: block; animation: ui-menu-out var(--m-exit) var(--ease-exit) forwards; pointer-events: none; }
.dropdown-menu-end { right: 0; left: auto; }
.dropup .dropdown-menu { top: auto; bottom: 100%; margin: 0 0 4px; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 10px; border: 0; border-radius: var(--r);
  background: transparent; color: var(--ink); font-size: var(--fs-base); text-align: left; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.dropdown-item.active { background: var(--surface-3); color: var(--ink); }
.dropdown-item.disabled, .dropdown-item:disabled { color: var(--ink-3); pointer-events: none; }
.dropdown-item.text-danger:hover { background: var(--danger-soft); }
.dropdown-item i { width: 14px; font-size: 12px; color: var(--ink-3); text-align: center; }
.dropdown-header { padding: 6px 10px 4px; font-size: var(--fs-xs); color: var(--ink-3); font-weight: 500; }
.dropdown-divider { height: 0; margin: 4px 0; border: 0; border-top: 1px solid var(--border); }
.dropdown-toggle::after { content: ""; display: inline-block; margin-left: 6px; vertical-align: 2px; border-top: 4px solid; border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: 0.6; transition: transform var(--m-normal) var(--ease-standard); }
.dropdown-toggle[aria-expanded="true"]::after { transform: rotate(180deg); }
.dropdown-toggle.btn--icon::after { display: none; }

/* --------------------------------------------------------------------------
   13. Dialogs
   -------------------------------------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 1055; display: none; overflow-x: hidden; overflow-y: auto; outline: 0; opacity: 1; }
.modal.fade { opacity: 0; transition: opacity var(--m-exit) var(--ease-exit); }
.modal.fade.show { opacity: 1; transition-duration: var(--m-panel); transition-timing-function: var(--ease-enter); }
.modal-backdrop { position: fixed; inset: 0; z-index: 1050; background: #1b1917; opacity: 0; transition: opacity var(--m-exit) var(--ease-exit); }
.modal-backdrop.show { opacity: 0.45; transition-duration: var(--m-panel); transition-timing-function: var(--ease-enter); }
body.modal-open { overflow: hidden; }
.modal-dialog { position: relative; width: auto; margin: var(--sp-4); pointer-events: none; --modal-w: 560px; }
.modal-sm { --modal-w: 400px; } .modal-lg { --modal-w: 800px; } .modal-xl { --modal-w: 1100px; }
@media (min-width: 576px) { .modal-dialog { max-width: var(--modal-w); margin: 28px auto; } }
.modal-dialog-centered { display: flex; align-items: center; min-height: calc(100% - 32px); }
@media (min-width: 576px) { .modal-dialog-centered { min-height: calc(100% - 56px); } }
.modal-dialog-scrollable { height: calc(100% - 32px); }
.modal-dialog-scrollable .modal-content { max-height: 100%; overflow: hidden; }
.modal-dialog-scrollable .modal-body { overflow-y: auto; overscroll-behavior: contain; }
.modal.fade .modal-dialog { transition: transform var(--m-exit) var(--ease-exit); transform: translateY(6px) scale(0.98); }
.modal.show .modal-dialog { transform: none; transition-duration: var(--m-panel); transition-timing-function: var(--ease-enter); }
.modal-content { position: relative; display: flex; flex-direction: column; width: 100%; pointer-events: auto; background: var(--surface); border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-modal); color: var(--ink); outline: 0; }
.modal-header { display: flex; align-items: center; gap: var(--sp-3); padding: 12px var(--sp-4); border-bottom: 1px solid var(--border); min-height: 48px; }
.modal-title { font-size: var(--fs-md); font-weight: 500; color: var(--ink); margin: 0; line-height: 1.3; }
.modal-header .btn-close { margin-left: auto; }
.modal-body { position: relative; flex: 1 1 auto; padding: var(--sp-4); }
.modal-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2); padding: 10px var(--sp-4); border-top: 1px solid var(--border); }
.modal-footer > * { margin: 0; }
.modal-footer .btn--ghost, .modal-footer .btn-link { margin-right: auto; }

/* Generic custom overlay (non-Bootstrap dialogs used by some pages) */
.overlay { position: fixed; inset: 0; z-index: 1100; background: rgba(27, 25, 23, 0.45); display: flex; align-items: center; justify-content: center; padding: var(--sp-4); opacity: 0; visibility: hidden; transition: opacity var(--m-exit) var(--ease-exit), visibility 0s linear var(--m-exit); }
.overlay.show, .overlay.is-open { opacity: 1; visibility: visible; transition: opacity var(--m-panel) var(--ease-enter), visibility 0s; }
.dialog { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-modal); transform: translateY(6px) scale(0.98); transition: transform var(--m-exit) var(--ease-exit); }
.overlay.show .dialog, .overlay.is-open .dialog { transform: none; transition: transform var(--m-panel) var(--ease-enter); }
.dialog--sm { max-width: 400px; } .dialog--lg { max-width: 800px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: 48px; padding: 12px var(--sp-4); border-bottom: 1px solid var(--border); }
.dialog-title { font-size: var(--fs-md); font-weight: 500; margin: 0; }
.dialog-body { padding: var(--sp-4); }
.dialog-footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); padding: 10px var(--sp-4); border-top: 1px solid var(--border); }
.dialog-footer .btn--ghost { margin-right: auto; }

/* --------------------------------------------------------------------------
   14. Toasts, banners, alerts
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed; top: var(--sp-4); right: var(--sp-4); z-index: 10000; display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; width: min(360px, calc(100vw - 32px));
}
.toast-card {
  pointer-events: auto; position: relative; display: flex; align-items: flex-start; gap: 10px; padding: 10px 10px 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-modal); overflow: hidden;
  animation: toast-in var(--m-panel) var(--ease-enter);
}
.toast-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--ink-3); }
.toast-card.toast-out { animation: toast-out var(--m-exit) var(--ease-exit) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }
.toast-icon-container { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px; }
.toast-icon-container svg { width: 14px; height: 14px; }
.toast-message-container { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.toast-title { margin: 0; font-size: var(--fs-base); font-weight: 500; color: var(--ink); line-height: 1.3; }
.toast-subtitle { margin: 0; font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.4; overflow-wrap: anywhere; }
.toast-close { width: 22px; height: 22px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-3); display: inline-flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; }
.toast-close:hover { background: var(--surface-2); color: var(--ink); }
.toast-close svg { width: 11px; height: 11px; }
.toast-success::before { background: var(--ok); } .toast-success .toast-icon-container { color: var(--ok); }
.toast-error::before, .toast-danger::before { background: var(--danger); } .toast-error .toast-icon-container, .toast-danger .toast-icon-container { color: var(--danger); }
.toast-warning::before { background: var(--warn); } .toast-warning .toast-icon-container { color: var(--warn); }
.toast-info::before { background: var(--info); } .toast-info .toast-icon-container { color: var(--info); }
.toast-wave { display: none; }
@media (max-width: 575.98px) { .toast-container { top: auto; bottom: var(--sp-4); left: var(--sp-4); right: var(--sp-4); width: auto; } }

.banner, .alert {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px 10px 14px; position: relative;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); color: var(--ink); font-size: var(--fs-base); margin-bottom: var(--sp-4);
}
.banner::before, .alert::before { content: ""; position: absolute; left: 0; top: -1px; bottom: -1px; width: 3px; border-radius: var(--r) 0 0 var(--r); background: var(--ink-3); }
.banner i, .alert > i { font-size: 13px; margin-top: 3px; color: var(--ink-2); flex-shrink: 0; }
.banner-body { flex: 1; min-width: 0; }
.banner-title { font-weight: 500; margin: 0 0 2px; }
.banner-actions { display: flex; gap: var(--sp-2); margin-left: auto; align-items: center; flex-shrink: 0; }
.banner--ok, .alert-success { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.banner--ok::before, .alert-success::before { background: var(--ok); } .banner--ok i, .alert-success > i { color: var(--ok); }
.banner--warn, .alert-warning { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.banner--warn::before, .alert-warning::before { background: var(--warn); } .banner--warn i, .alert-warning > i { color: var(--warn); }
.banner--info, .alert-info, .alert-primary { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.banner--info::before, .alert-info::before, .alert-primary::before { background: var(--info); } .banner--info i, .alert-info > i, .alert-primary > i { color: var(--info); }
.banner--danger, .alert-danger, .alert-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.banner--danger::before, .alert-danger::before, .alert-error::before { background: var(--danger); } .banner--danger i, .alert-danger > i, .alert-error > i { color: var(--danger); }
.banner--quiet { background: transparent; border-color: var(--border); color: var(--ink-2); }
.banner--quiet::before { background: var(--border-strong); }
.banner--quiet i { color: var(--ink-3); }
.banner--quiet .banner-title { color: var(--ink); }
.alert .btn-close { position: static; margin-left: auto; padding: 4px; width: 22px; height: 22px; }
.alert-dismissible { padding-right: 12px; }

/* --------------------------------------------------------------------------
   15. Empty, loading, skeleton, progress
   -------------------------------------------------------------------------- */
.empty, .empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  padding: var(--sp-8) var(--sp-4); color: var(--ink-2); font-size: var(--fs-base);
}
.empty i, .empty svg, .empty-state i, .empty-state svg { font-size: 20px; color: var(--ink-3); margin-bottom: 4px; }
.empty-title { color: var(--ink); font-weight: 500; }
.empty .btn { margin-top: var(--sp-2); }

.skeleton { background: var(--surface-2); border-radius: var(--r-sm); position: relative; overflow: hidden; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent); animation: shimmer 1.4s infinite; }
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent); }
@keyframes shimmer { to { transform: translateX(100%); } }
.skeleton-text { height: 12px; margin: 6px 0; }
.skeleton-text.short { width: 40%; } .skeleton-text.medium { width: 60%; } .skeleton-text.long { width: 85%; }
.skeleton-row { display: flex; align-items: center; gap: var(--sp-3); height: var(--row-h); padding: 0 12px; border-bottom: 1px solid var(--border); }
.skeleton-circle { width: 28px; height: 28px; border-radius: 50%; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-right-color: var(--ink); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }
.spinner--sm { width: 12px; height: 12px; border-width: 1.5px; }
.spinner-border { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -3px; }
.spinner-border-sm { width: 12px; height: 12px; border-width: 1.5px; }

.progress { height: 6px; border-radius: var(--r-sm); background: var(--surface-3); overflow: hidden; }
.progress-bar { background: var(--accent); border-radius: var(--r-sm); transition: width var(--t); }
.progress--ok .progress-bar { background: var(--ok); }
.progress--warn .progress-bar { background: var(--warn); }
.progress--danger .progress-bar { background: var(--danger); }

/* --------------------------------------------------------------------------
   16. Detail layouts, misc
   -------------------------------------------------------------------------- */
.detail { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--sp-5); align-items: start; }
.detail-main, .detail-aside { min-width: 0; display: flex; flex-direction: column; gap: var(--sp-5); }
@media (max-width: 1099.98px) { .detail { grid-template-columns: 1fr; } }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
@media (max-width: 991.98px) { .grid--3, .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 575.98px) { .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; } }

.row-actions { display: inline-flex; gap: 2px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.spacer { flex: 1; }
.meta { font-size: var(--fs-sm); color: var(--ink-2); }
.meta-sep::before { content: "·"; margin: 0 6px; color: var(--ink-3); }
.hide-desktop { display: none !important; }
@media (max-width: 991.98px) { .hide-mobile { display: none !important; } .hide-desktop { display: initial !important; } }

.thumb { width: 40px; height: 40px; border-radius: var(--r-sm); object-fit: cover; background: var(--surface-2); flex-shrink: 0; display: block; }
.thumb--lg { width: 64px; height: 64px; }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); background: var(--surface-2); border-radius: var(--r-sm); }

.pager { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); }
.page-link { height: var(--h-ctl-sm); display: inline-flex; align-items: center; }

.skip-link { position: absolute; top: -40px; left: 0; background: var(--ink); color: var(--ink-inverse); padding: 8px 16px; z-index: 10000; font-weight: 500; border-radius: 0 0 var(--r) 0; }
.skip-link:focus { top: 0; }

/* Legacy compatibility (old class names used by page templates being migrated) */
.content-wrapper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-4); margin-bottom: var(--sp-4); }
.header-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--h-ctl); height: var(--h-ctl); border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); color: var(--ink-2); padding: 0; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.fs-sm { font-size: var(--fs-sm); }

/* --------------------------------------------------------------------------
   17. Theme switch and view transitions
   -------------------------------------------------------------------------- */
@view-transition { navigation: none; }
::view-transition-group(*) { animation-duration: var(--m-normal); animation-timing-function: var(--ease-standard); }
::view-transition-old(*) { animation: ui-vt-out var(--m-fast) var(--ease-exit) both; }
::view-transition-new(*) { animation: ui-vt-in var(--m-normal) var(--ease-enter) both; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.vt-active *, html.vt-active *::before, html.vt-active *::after { transition: none !important; }
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline-flex; }
.sidebar-page-overlay[hidden] { display: none; }
.profile-modal-overlay.closing { opacity: 0; visibility: hidden; }

/* --------------------------------------------------------------------------
   18. Puuteseadmed: juhtelemendid vähemalt 36–40px kõrged, et sõrmega tabada
   -------------------------------------------------------------------------- */
@media (pointer: coarse) {
  :root { --h-ctl: 40px; --h-ctl-sm: 36px; --h-ctl-lg: 46px; --row-h: 44px; }
  .seg { padding: 3px; }
  .seg-item { height: 36px; padding: 0 12px; font-size: var(--fs-base); }
  .tab { min-height: 40px; }
  .page-back { width: 36px; height: 36px; }
  .btn-close { width: 36px; height: 36px; }
  .search-clear { width: 32px; height: 32px; right: 4px; }
  .sidebar-link, .sidebar-submenu-toggle { height: 40px; }
  .sidebar .sidebar-submenu-items .sidebar-link { height: 36px; }
  .dropdown-item { height: 40px; }
  .form-check { min-height: 36px; }
  input[type="checkbox"]:not(.switch):not([role="switch"]), input[type="radio"], .checkbox, .radio { width: 20px; height: 20px; }
  .toast-close, .alert .btn-close { width: 32px; height: 32px; }
  .list-item { min-height: 48px; }
  .icon-btn { width: 40px; height: 40px; }
}

/* --------------------------------------------------------------------------
   19. Motion
   Durations: --m-instant 80 (press) · --m-fast 120 (hover/micro) · --m-normal 180 (state, list swap)
              --m-panel 220 (menu/dialog enter) · --m-sheet 280 (drawer enter) · --m-exit 140 (anything leaving)
   Easing:    --ease-standard (move) · --ease-enter (decelerate in) · --ease-exit (accelerate out)
   Only transform and opacity animate; lists swap through a scoped View Transition (UI.swap).
   -------------------------------------------------------------------------- */
@keyframes ui-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ui-fade-out { to { opacity: 0; } }
@keyframes ui-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes ui-menu-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes ui-menu-out { to { opacity: 0; transform: translateY(-2px) scale(0.99); } }
@keyframes ui-sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes ui-sheet-out { to { transform: translateY(100%); } }
@keyframes ui-count { from { opacity: 0.3; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
@keyframes ui-swap-in { from { opacity: 0.5; } to { opacity: 1; } }
@keyframes ui-vt-out { to { opacity: 0; } }
@keyframes ui-vt-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* things that appear in place */
.empty, .empty-state { animation: ui-rise var(--m-normal) var(--ease-enter); }
/* vahetatud nimekiri/paneel: uus sisu sulandub kohale, vana ei jäädvustata */
.ui-swapped { animation: ui-swap-in var(--m-normal) var(--ease-enter); }
.is-updating { animation: ui-count var(--m-normal) var(--ease-enter); }
.ui-enter { animation: ui-rise var(--m-normal) var(--ease-enter); }
.pop, .popover-panel { animation: ui-menu-in var(--m-panel) var(--ease-enter); }

/* pressables: state colours ease, press is a half-pixel settle, never a bounce */
.tab, .page-back, .sidebar-link, .sidebar-submenu-toggle, .dropdown-item, .list-item, .stat, .btn-close, .icon-btn { transition-property: background, color, border-color, box-shadow, transform; transition-duration: var(--m-fast); }
.page-back:active, .btn-close:active, .icon-btn:active, .tab:active { transform: translateY(0.5px); }
.tab { transition: color var(--m-fast), border-color var(--m-fast), transform var(--m-instant); }
.status, .tag { transition: color var(--m-normal), background var(--m-normal), border-color var(--m-normal); }
.status::before { transition: background var(--m-normal); }
.table tbody tr { transition: background var(--m-fast), opacity var(--m-normal); }
.sidebar-submenu-arrow { transition: transform var(--m-normal) var(--ease-standard); }

/* touch: no hover colour sticks to the finger; press gives the feedback instead */
@media (hover: none) {
  .btn:hover { background: var(--btn-bg); color: var(--btn-fg); border-color: var(--btn-bd); }
  .btn--ghost:hover, .btn-link:hover { color: var(--ink-2); }
  .btn:active:not(:disabled) { background: var(--btn-bg-h); }
  .seg-item:hover:not(.active):not(.is-active) { color: var(--ink-2); }
  .filter-chip:hover:not(.active):not(.is-active) { background: var(--surface); color: var(--ink-2); }
  .filter-chip:active:not(.active) { background: var(--surface-2); }
  .tab:hover:not(.active):not(.is-active) { color: var(--ink-2); border-color: transparent; }
  .table tbody tr:hover { background: transparent; }
  .table tbody tr:active { background: var(--surface-2); }
  a.list-item:hover, .list-item.is-clickable:hover { background: transparent; }
  a.list-item:active, .list-item.is-clickable:active { background: var(--surface-2); }
  .sidebar-link:hover:not(.active), .sidebar-submenu-toggle:hover:not(.active) { background: transparent; color: var(--ink-2); }
  .sidebar-link:active, .sidebar-submenu-toggle:active { background: var(--surface-2); }
  .dropdown-item:hover { background: transparent; }
  .dropdown-item:active { background: var(--surface-2); }
  a.stat:hover, button.stat:hover, .stat.is-clickable:hover { background: transparent; }
  button.stat:active, a.stat:active { background: var(--surface-2); }
  .page-back:hover, .btn-close:hover, .icon-btn:hover, .search-clear:hover, .toast-close:hover { background: transparent; color: var(--ink-2); }
  .page-back:active, .btn-close:active, .icon-btn:active, .search-clear:active { background: var(--surface-2); }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
}

/* reduced motion: state changes still happen, they just do not travel */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .ui-swapped { animation: none !important; }
  .skeleton::after { animation: none; }
}

/* --------------------------------------------------------------------------
   20. Upload queue (shell widget, markup in base.html, behaviour uploads.js)
   -------------------------------------------------------------------------- */
.upload-queue {
  position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: 70;
  display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(360px, calc(100vw - var(--sp-8)));
}
.upload-queue[hidden] { display: none; }
.upload-summary {
  padding: 6px 10px; border-radius: var(--r); background: var(--ink);
  color: var(--ink-inverse); font-size: var(--fs-xs); text-align: center;
  box-shadow: var(--shadow-pop);
}
.upload-item {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 8px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-pop); font-size: var(--fs-sm);
}
.upload-item-icon { width: 18px; text-align: center; color: var(--ink-3); flex-shrink: 0; }
.upload-item[data-state="uploading"] .upload-item-icon,
.upload-item[data-state="finishing"] .upload-item-icon { color: var(--accent); }
.upload-item[data-state="done"] .upload-item-icon { color: var(--ok); }
.upload-item[data-state="error"] .upload-item-icon { color: var(--danger); }
.upload-item[data-state="duplicate"] .upload-item-icon { color: var(--warn); }
.upload-item-body { min-width: 0; flex: 1; }
.upload-item-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-item-msg { color: var(--ink-2); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.upload-item-actions { display: inline-flex; gap: 2px; flex-shrink: 0; }
.upload-bar {
  height: 4px; margin: 4px 0 3px; border-radius: 2px;
  background: var(--surface-3); overflow: hidden;
}
.upload-bar-fill {
  height: 100%; width: 0; background: var(--accent);
  transition: width var(--m-fast) linear;
}
.upload-item[data-state="done"] .upload-bar-fill { background: var(--ok); }
.upload-item[data-state="error"] .upload-bar-fill { background: var(--danger); }
.upload-item[data-state="duplicate"] .upload-bar-fill { background: var(--warn); }
/* States that ask a question carry labelled buttons, which leave the
   message too little room to sit beside them — give it the full width and
   put the choice on its own line. Same on a phone, whatever the state. */
.upload-item[data-state="duplicate"], .upload-item[data-state="error"] { flex-wrap: wrap; }
.upload-item[data-state="duplicate"] .upload-item-actions,
.upload-item[data-state="error"] .upload-item-actions { width: 100%; justify-content: flex-end; }
@media (max-width: 575.98px) {
  .upload-item { flex-wrap: wrap; }
  .upload-item-actions { width: 100%; justify-content: flex-end; }
}
