/* Kapeleion design system: tokens, the app shell (sidebar, top bar), and the shared components every page
   uses. Plain CSS, no build step. Colours live only in the tokens below; components read them through var(),
   so the dark theme is just a second set of tokens. Class names are documented next to each block. */

/* ------------------------------------------------------------------ tokens */

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* greys */
  --gray-25: #FCFCFD; --gray-50: #F7F8FA; --gray-100: #EEF0F3; --gray-150: #F3F4F6; --gray-200: #E5E7EB;
  --gray-300: #D1D5DB; --gray-400: #9CA3AF; --gray-500: #6B7280; --gray-700: #374151; --gray-800: #1F2937;
  --gray-900: #111827;

  /* surfaces */
  --canvas: var(--gray-100);         /* page behind the frame */
  --bg-main: var(--gray-50);         /* main area behind the cards */
  --surface: #FFFFFF;                /* cards, sidebar, inputs */
  --surface-2: #F9FAFB;              /* table header, subtle fills */
  --hover: var(--gray-150);
  --border: var(--gray-100);         /* cards, dividers */
  --border-strong: var(--gray-200);  /* inputs, outline buttons */
  --border-hover: var(--gray-300);

  /* text */
  --text: var(--gray-900);
  --text-2: var(--gray-700);
  --text-nav: var(--gray-800);
  --text-secondary: var(--gray-500);
  --text-muted: var(--gray-400);

  /* brand and states */
  --primary: #2563EB; --primary-600: #1D4ED8; --primary-50: #EAF1FE; --primary-100: #D6E4FD;
  --on-primary: #FFFFFF;
  --success: #16A34A; --success-50: #E8F7EE;
  --danger: #DC2626; --danger-50: #FDECEC;
  --warning: #EA580C; --warning-50: #FFF1E6;
  --ring: rgba(37, 99, 235, .2);
  --band: rgba(22, 163, 74, .07);     /* allowed temperature range on charts */
  --area-top: rgba(37, 99, 235, .18); /* chart gradient fill */

  /* radii */
  --r-xs: 8px; --r-sm: 10px; --r-md: 12px; --r-lg: 16px; --r-xl: 24px;

  /* shadows */
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-frame: 0 1px 3px rgba(16, 24, 40, .05), 0 16px 40px -12px rgba(16, 24, 40, .10);
  --shadow-pop: 0 4px 8px -2px rgba(16, 24, 40, .06), 0 16px 32px -6px rgba(16, 24, 40, .14);
  --shadow-dialog: 0 24px 48px -12px rgba(16, 24, 40, .25);
  --shadow-primary: 0 1px 2px rgba(37, 99, 235, .18), 0 4px 12px -2px rgba(37, 99, 235, .35);
  --shadow-seg: 0 1px 2px rgba(16, 24, 40, .08), 0 1px 1px rgba(16, 24, 40, .04);

  --sb-w: 248px;
  --topbar-h: 72px;
  color-scheme: light;
}

:root[data-sidebar='collapsed'] { --sb-w: 72px; }

/* Dark theme: same names, darker values (toggle in the top bar, saved in localStorage 'theme'). */
:root[data-theme='dark'] {
  --canvas: #07090D;
  --bg-main: #0D1117;
  --surface: #151A22;
  --surface-2: #1A2029;
  --hover: #1E2530;
  --border: #212833;
  --border-strong: #2C3541;
  --border-hover: #3B4552;
  --text: #F3F4F6;
  --text-2: #D1D5DB;
  --text-nav: #E5E7EB;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --gray-100: #212833; --gray-150: #1E2530; --gray-200: #2C3541; --gray-300: #3B4552;
  --primary: #3B82F6; --primary-600: #2563EB; --primary-50: rgba(59, 130, 246, .15); --primary-100: rgba(59, 130, 246, .25);
  --success: #22C55E; --success-50: rgba(34, 197, 94, .14);
  --danger: #F87171; --danger-50: rgba(248, 113, 113, .14);
  --warning: #FB923C; --warning-50: rgba(251, 146, 60, .14);
  --ring: rgba(59, 130, 246, .35);
  --band: rgba(34, 197, 94, .09);
  --area-top: rgba(59, 130, 246, .28);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-frame: 0 1px 3px rgba(0, 0, 0, .4), 0 16px 40px -12px rgba(0, 0, 0, .6);
  --shadow-pop: 0 16px 32px -6px rgba(0, 0, 0, .6);
  --shadow-dialog: 0 24px 48px -12px rgba(0, 0, 0, .7);
  --shadow-primary: 0 4px 12px -2px rgba(37, 99, 235, .45);
  --shadow-seg: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-feature-settings: 'cv11', 'ss01';
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
img, svg { display: block; }
svg.i { flex: none; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
[hidden] { display: none !important; }
.tabular, .num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .92em; letter-spacing: 0; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.caption { font-size: 12px; color: var(--text-secondary); line-height: 1.45; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nowrap { white-space: nowrap; }
.print-only { display: none; }

/* layout helpers: .row (flex, centred), .stack (column), .grid + .cols-2/3/4, .spacer */
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.spacer { flex: 1; }
.grid { display: grid; gap: 20px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

/* boot: before the shell is drawn */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--primary-100); border-top-color: var(--primary); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ app frame */

.app {
  display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr);
  height: calc(100vh - 48px); height: calc(100dvh - 48px); margin: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-frame);
  overflow: hidden; transition: grid-template-columns .2s ease;
}
.main { position: relative; min-width: 0; overflow-y: auto; background: var(--bg-main); scroll-behavior: smooth; }
.content { padding: 8px 32px 48px; max-width: 1480px; margin: 0 auto; }

/* ------------------------------------------------------------------ sidebar */

.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); overflow: hidden; }
.sb-head { display: flex; align-items: center; gap: 8px; height: var(--topbar-h); padding: 0 14px 0 20px; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; flex: 1; }
.brand:hover { color: var(--text); }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand-word { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.sb-collapse { width: 32px; height: 32px; border: 0; background: transparent; color: var(--text-secondary); border-radius: var(--r-xs); display: grid; place-items: center; cursor: pointer; flex: none; }
.sb-collapse:hover { background: var(--hover); color: var(--text); }
.sb-close { display: none; }
.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 12px 12px; }
.sb-foot { flex: none; padding: 8px 12px 16px; border-top: 1px solid var(--border); }
.nav-divider { height: 1px; background: var(--border); margin: 10px 8px; }
.nav-label-group { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--text-muted); padding: 8px 12px 4px; text-transform: uppercase; }

/* .nav-item: icon + label (+ .nav-badge, + chevron for a group); .active = current page */
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-nav); font-size: 14px; font-weight: 500;
  text-align: left; cursor: pointer; line-height: 1.3; margin: 2px 0;
}
.nav-item svg { width: 18px; height: 18px; color: var(--text-secondary); flex: none; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--primary-50); color: var(--primary); }
.nav-item.active svg { color: var(--primary); }
.nav-item.active::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-chev { width: 16px !important; height: 16px !important; transition: transform .15s; }
.nav-group.open > .nav-item .nav-chev { transform: rotate(180deg); }
.nav-group.has-active > .nav-item { color: var(--text); }
.nav-group.has-active > .nav-item > svg:first-child { color: var(--primary); }
.nav-sub { display: none; padding: 2px 0 4px; }
.nav-group.open > .nav-sub { display: block; }
.nav-sub .nav-item { padding-left: 42px; font-size: 13.5px; min-height: 38px; }
.nav-sub .nav-item .nav-text { white-space: normal; }
.nav-sub .nav-item.active::before { top: 6px; bottom: 6px; }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }
.nav-dot.danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-50); }
.nav-dot.warning { background: var(--warning); }
.nav-dot.muted { background: var(--gray-300); }
.nav-skeleton { height: 14px; margin: 12px 12px 12px 42px; border-radius: 6px; }

/* count badge: green by default, .danger red, .info blue, .neutral grey */
.nav-badge, .count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 7px;
  border-radius: 999px; background: var(--success-50); color: var(--success); font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums; flex: none; line-height: 1;
}
.nav-badge.danger, .count.danger { background: var(--danger-50); color: var(--danger); }
.nav-badge.info, .count.info { background: var(--primary-50); color: var(--primary); }
.nav-badge.warning, .count.warning { background: var(--warning-50); color: var(--warning); }
.nav-badge.neutral, .count.neutral { background: var(--gray-150); color: var(--text-secondary); }

.sb-status { display: flex; align-items: center; gap: 8px; padding: 10px 12px 0; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; }

/* collapsed rail (desktop/tablet only) */
@media (min-width: 900px) {
  :root[data-sidebar='collapsed'] .sb-head { padding: 0; justify-content: center; flex-direction: column; gap: 4px; height: auto; padding: 16px 0 8px; }
  :root[data-sidebar='collapsed'] .brand { flex: none; }
  :root[data-sidebar='collapsed'] .brand-word,
  :root[data-sidebar='collapsed'] .nav-text,
  :root[data-sidebar='collapsed'] .nav-chev,
  :root[data-sidebar='collapsed'] .nav-sub,
  :root[data-sidebar='collapsed'] .nav-label-group,
  :root[data-sidebar='collapsed'] .sb-status span:last-child { display: none !important; }
  :root[data-sidebar='collapsed'] .nav-item { justify-content: center; padding: 10px 0; }
  :root[data-sidebar='collapsed'] .nav-item .nav-badge {
    position: absolute; top: 4px; right: 4px; min-width: 8px; width: 8px; height: 8px; padding: 0; font-size: 0;
    background: currentColor;
  }
  :root[data-sidebar='collapsed'] .nav-item .nav-badge:not(.danger) { display: none; }
  :root[data-sidebar='collapsed'] .nav-item .nav-badge.danger { color: var(--danger); }
  :root[data-sidebar='collapsed'] .sb-status { justify-content: center; padding: 10px 0 0; }
  :root[data-sidebar='collapsed'] .nav-divider { margin: 10px 4px; }
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: var(--topbar-h); padding: 0 32px;
  background: var(--bg-main);
  background: color-mix(in srgb, var(--bg-main) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
}
.topbar.scrolled { box-shadow: 0 1px 0 var(--border); }
.tb-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.hamburger { display: none !important; }

/* .search: pill field with a magnifier and a ⌘K chip; .search-results is its dropdown */
.search { position: relative; width: min(420px, 100%); }
.search-field {
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 8px 0 14px; border: 1px solid var(--border-strong);
  border-radius: var(--r-md); background: var(--surface); color: var(--text-muted); transition: border-color .15s, box-shadow .15s;
}
.search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.search-field svg { width: 18px; height: 18px; }
.search-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 14px; height: 100%; }
.search-field input::placeholder { color: var(--text-muted); }
.kbd {
  display: inline-flex; align-items: center; height: 24px; padding: 0 7px; border: 1px solid var(--border-strong); border-radius: 6px;
  font-size: 11.5px; font-weight: 500; color: var(--text-secondary); background: var(--surface-2); white-space: nowrap;
}
.search-results { position: absolute; top: calc(100% + 8px); left: 0; right: 0; max-height: 420px; overflow-y: auto; padding: 6px; }
.sr-group { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--text-muted); padding: 10px 10px 4px; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-xs); color: var(--text); cursor: pointer; font-size: 14px; }
.sr-item svg { width: 16px; height: 16px; color: var(--text-secondary); }
.sr-item .sr-sub { margin-left: auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.sr-item:hover, .sr-item.active { background: var(--primary-50); color: var(--primary); }
.sr-item:hover svg, .sr-item.active svg { color: var(--primary); }
.sr-empty { padding: 18px 12px; color: var(--text-secondary); text-align: center; font-size: 13px; }

/* .icon-btn: round 40px button with a 1px border; .dot = red notification dot */
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; padding: 0;
  border: 1px solid var(--border-strong); border-radius: 50%; background: var(--surface); color: var(--text-2); cursor: pointer;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--hover); border-color: var(--border-hover); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.square { border-radius: var(--r-sm); }
.icon-btn.plain { border-color: transparent; background: transparent; }
.icon-btn.plain:hover { background: var(--hover); }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface); }
.avatar {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--primary-50); color: var(--primary); font-weight: 600; font-size: 14px; letter-spacing: .02em;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 48px; height: 48px; font-size: 16px; }
button.avatar { border: 0; padding: 0; cursor: pointer; box-shadow: 0 0 0 1px var(--border-strong); }
button.avatar:hover { box-shadow: 0 0 0 1px var(--border-strong), 0 0 0 4px var(--ring); }

/* .popover: floating white panel under a top-bar button (notifications, avatar menu) */
.popover {
  position: absolute; z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); animation: pop-in .14s ease-out;
}
.tb-pop { top: calc(100% + 10px); right: 0; width: 380px; max-width: calc(100vw - 24px); }
.anchor { position: relative; }
.pop-head { display: flex; align-items: center; gap: 8px; padding: 16px 16px 10px; font-weight: 600; font-size: 15px; }
.pop-list { max-height: 420px; overflow-y: auto; padding: 0 8px 8px; }
.pop-foot { border-top: 1px solid var(--border); padding: 10px 16px; font-size: 13px; }
.notif { display: flex; gap: 12px; padding: 10px 8px; border-radius: var(--r-sm); color: var(--text); align-items: flex-start; }
.notif:hover { background: var(--hover); color: var(--text); }
.notif-text { font-size: 13.5px; line-height: 1.4; }
.notif-time { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.menu { padding: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--text); font-size: 14px; text-align: left; cursor: pointer;
}
.menu-item svg { width: 18px; height: 18px; color: var(--text-secondary); }
.menu-item:hover { background: var(--hover); color: var(--text); }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-user { display: flex; align-items: center; gap: 12px; padding: 12px 10px 10px; }
.menu-user b { display: block; font-weight: 600; font-size: 14px; }
.menu-user .mu-line { display: block; font-size: 12.5px; color: var(--text-secondary); }

/* ------------------------------------------------------------------ page header */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin: 8px 0 24px; }
.page-head > div:first-child { min-width: 0; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--text-secondary); }
.crumbs a:hover { color: var(--primary); }
.crumbs svg { width: 14px; height: 14px; color: var(--text-muted); }
.page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; color: var(--text); }
.page-sub { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-top: 6px; color: var(--text-secondary); font-size: 14px; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; justify-content: flex-end; }
.section-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 28px 0 14px; letter-spacing: -0.01em; }

/* ------------------------------------------------------------------ buttons */

/* .btn + .btn-primary | .btn-outline | .btn-ghost | .btn-danger | .btn-soft; sizes .btn-sm .btn-lg .btn-xl; .btn-block */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--r-sm); font-size: 14px; font-weight: 500; line-height: 1; white-space: nowrap;
  cursor: pointer; user-select: none; text-decoration: none; transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-primary); }
.btn-primary:hover { background: var(--primary-600); color: var(--on-primary); }
.btn-outline { background: var(--surface); border-color: var(--border-strong); color: var(--text-nav); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.btn-outline:hover { background: var(--hover); border-color: var(--border-hover); color: var(--text); }
.btn-outline svg { color: var(--text-secondary); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-soft { background: var(--primary-50); color: var(--primary); }
.btn-soft:hover { background: var(--primary-100); color: var(--primary-600); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); color: #fff; }
.btn-danger-outline { background: var(--surface); border-color: var(--border-strong); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-50); border-color: var(--danger); color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--r-xs); gap: 6px; }
.btn-sm svg { width: 16px; height: 16px; }
.btn-lg { height: 48px; padding: 0 20px; font-size: 15px; border-radius: var(--r-md); }
.btn-xl { height: 56px; padding: 0 24px; font-size: 16px; font-weight: 600; border-radius: var(--r-md); }
.btn-xl svg { width: 20px; height: 20px; }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn.loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor;
  border-color: rgba(255, 255, 255, .5); border-top-color: #fff; animation: spin .7s linear infinite;
}
.btn-outline.loading::after, .btn-ghost.loading::after { border-color: var(--primary-100); border-top-color: var(--primary); }

/* .seg: segmented control (range tabs, Fridge/Freezer, ΕΛ|EN); buttons with aria-pressed */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--gray-150); border: 1px solid var(--border-strong); border-radius: var(--r-sm); }
.seg button {
  height: 32px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--text-secondary);
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.seg button svg { width: 16px; height: 16px; }
.seg button:hover:not(:disabled) { color: var(--text); }
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-seg); }
.seg button:disabled { cursor: default; opacity: .5; }
.seg.lang button { height: 32px; padding: 0 10px; font-size: 12.5px; font-weight: 600; letter-spacing: .02em; }
.seg.lg button { height: 40px; padding: 0 16px; font-size: 14px; }

/* .chip: toggle chip (outline grey → light blue with a check when aria-pressed=true) */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border: 1px solid var(--border-strong);
  border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: 14px; font-weight: 500; cursor: pointer;
  user-select: none; transition: background .12s, border-color .12s, color .12s; white-space: nowrap;
}
.chip svg { width: 16px; height: 16px; display: none; }
.chip:hover { border-color: var(--border-hover); }
.chip[aria-pressed='true'] { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.chip[aria-pressed='true'] svg { display: block; }
.chip:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------------ cards */

/* .card (+ .card-flush: no padding, for tables); .card-head with .card-title / .card-sub / .card-menu */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: 22px 24px; min-width: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > .card-head { padding: 20px 24px 16px; margin: 0; }
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.card-head > .grow, .card-head > div:first-child:not(.icon-tile), .card-head > .icon-tile + div { flex: 1; min-width: 0; }
.card-title { font-size: 16px; font-weight: 600; color: var(--text); line-height: 1.35; letter-spacing: -0.01em; }
.card-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.card-menu { margin: -6px -8px 0 0; }
a.card:not(.kpi) { display: block; }
a.card { color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.card:hover { color: inherit; border-color: var(--primary-100); box-shadow: var(--shadow-pop); }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* .icon-tile: rounded square with an icon (blue by default; .success .danger .warning .neutral) */
.icon-tile { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-sm); background: var(--primary-50); color: var(--primary); flex: none; }
.icon-tile svg { width: 20px; height: 20px; }
.icon-tile.sm { width: 32px; height: 32px; border-radius: var(--r-xs); }
.icon-tile.sm svg { width: 16px; height: 16px; }
.icon-tile.lg { width: 48px; height: 48px; border-radius: var(--r-md); }
.icon-tile.lg svg { width: 24px; height: 24px; }
.icon-tile.success { background: var(--success-50); color: var(--success); }
.icon-tile.danger { background: var(--danger-50); color: var(--danger); }
.icon-tile.warning { background: var(--warning-50); color: var(--warning); }
.icon-tile.neutral { background: var(--gray-150); color: var(--text-secondary); }

/* KPI / stat card: .kpi > .kpi-head (.kpi-title + .icon-tile) + .kpi-value + .kpi-foot (pill + caption) */
.kpi { display: flex; flex-direction: column; gap: 12px; padding: 20px 22px; }
.kpi-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-height: 40px; }
.kpi-title { font-size: 14px; font-weight: 500; color: var(--text-secondary); line-height: 1.35; padding-top: 2px; }
.kpi-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 16px; font-weight: 500; color: var(--text-muted); margin-left: 1px; letter-spacing: 0; }
.kpi-value small.spaced { margin-left: 5px; }
.kpi-value.text { font-size: 22px; }
.kpi-value.danger { color: var(--danger); }
.kpi-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 24px; }
.kpi-foot .caption { flex: 1 1 100%; min-width: 0; }

/* ------------------------------------------------------------------ pills */

/* .pill + .success | .danger | .warning | .info | .neutral; .dot adds a leading dot */
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 3px 10px; border-radius: 999px;
  background: var(--gray-150); color: var(--text-2); font-size: 12px; font-weight: 500; line-height: 1.3; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill svg { width: 13px; height: 13px; }
.pill.success { background: var(--success-50); color: var(--success); }
.pill.danger { background: var(--danger-50); color: var(--danger); }
.pill.warning { background: var(--warning-50); color: var(--warning); }
.pill.info { background: var(--primary-50); color: var(--primary); }
.pill.neutral { background: var(--gray-150); color: var(--text-secondary); }
.pill.outline { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border-strong); }
.pill.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.lg { min-height: 30px; padding: 5px 12px; font-size: 13px; }
.pill.wrap { white-space: normal; }

/* ------------------------------------------------------------------ tables */

/* .table-wrap (scrolls) > table.table; th uppercase 11px; td.num right-aligned tabular; tr.voided strikes the row */
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th {
  position: sticky; top: 0; z-index: 1; padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--text-secondary); text-align: left; white-space: nowrap;
}
.table td { padding: 10px 16px; height: 56px; border-bottom: 1px solid var(--border); color: var(--text-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-left: 24px; }
.table th:last-child, .table td:last-child { padding-right: 24px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.strong, .table .strong { color: var(--text); font-weight: 500; }
.table.compact td { height: 48px; padding-top: 6px; padding-bottom: 6px; }
.table tr.voided td { color: var(--text-muted); text-decoration: line-through; }
.table td.empty-row { text-align: center; color: var(--text-secondary); height: 120px; }

/* ------------------------------------------------------------------ forms */

/* .field > label.label + .input|.select|.textarea + .hint|.field-error */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.label .opt { color: var(--text-muted); font-weight: 400; }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-size: 14px; outline: 0; transition: border-color .15s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-hover); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-secondary); cursor: not-allowed; }
.input[aria-invalid='true'] { border-color: var(--danger); }
.input[aria-invalid='true']:focus { box-shadow: 0 0 0 3px var(--danger-50); }
.input.num { font-variant-numeric: tabular-nums; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.textarea { height: auto; min-height: 96px; padding: 10px 14px; resize: vertical; line-height: 1.5; }
.hint { font-size: 12px; color: var(--text-secondary); }
.field-error { font-size: 13px; color: var(--danger); display: flex; gap: 6px; align-items: flex-start; }
.field-error svg { width: 16px; height: 16px; margin-top: 1px; }
.form-error:empty, .field-error:empty { display: none; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 46px; }
.input-wrap .input-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--text-secondary); display: grid; place-items: center; cursor: pointer;
}
.input-wrap .input-btn:hover { background: var(--hover); color: var(--text); }
.input-wrap .input-btn svg { width: 18px; height: 18px; }
.form-grid { display: grid; gap: 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ alerts, progress, empty states */

/* .alert + .danger | .warning | .info | .success: icon + text banner */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md); font-size: 14px; background: var(--primary-50); color: var(--text); }
.alert > svg { width: 20px; height: 20px; flex: none; color: var(--primary); margin-top: 1px; }
.alert b { font-weight: 600; }
.alert .alert-body { flex: 1; min-width: 0; }
.alert .alert-sub { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.alert.danger { background: var(--danger-50); }
.alert.danger > svg { color: var(--danger); }
.alert.warning { background: var(--warning-50); }
.alert.warning > svg { color: var(--warning); }
.alert.success { background: var(--success-50); }
.alert.success > svg { color: var(--success); }

/* .progress > i (width = percent); .success | .warning colours the bar */
.progress { height: 8px; border-radius: 999px; background: var(--gray-150); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .4s ease; }
.progress.success > i { background: var(--success); }
.progress.warning > i { background: var(--warning); }
.progress.lg { height: 10px; }

.empty { text-align: center; padding: 40px 16px; color: var(--text-secondary); }
.empty .icon-tile { margin: 0 auto 14px; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); }
.empty-text { font-size: 14px; margin-top: 4px; max-width: 46ch; margin-left: auto; margin-right: auto; }

.skeleton { background: linear-gradient(90deg, var(--gray-150) 25%, var(--surface-2) 50%, var(--gray-150) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* bottom action bar (multi-select → sign); sticks to the bottom of the scrolling area */
.action-bar {
  position: sticky; bottom: 16px; z-index: 20; display: flex; align-items: center; gap: 12px; margin-top: 20px; padding: 12px 12px 12px 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
}

/* ------------------------------------------------------------------ toasts */

.toasts { position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 14px 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop); pointer-events: auto; animation: toast-in .22s ease-out;
}
.toast.out { animation: toast-out .18s ease-in forwards; }
.toast .icon-tile { width: 32px; height: 32px; border-radius: var(--r-xs); }
.toast .icon-tile svg { width: 18px; height: 18px; }
.toast-body { flex: 1; min-width: 0; padding-top: 1px; }
.toast-title { font-weight: 600; font-size: 14px; color: var(--text); }
.toast-msg { font-size: 13.5px; color: var(--text-2); margin-top: 1px; }
.toast-title + .toast-msg { color: var(--text-secondary); }
.toast-x { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; padding: 2px; border-radius: 6px; }
.toast-x:hover { color: var(--text); background: var(--hover); }
.toast-x svg { width: 16px; height: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ------------------------------------------------------------------ dialogs */

.overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px; overflow-y: auto;
  background: rgba(17, 24, 39, .45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: fade-in .15s ease-out;
}
.dialog {
  position: relative; width: min(480px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-dialog); animation: dialog-in .18s ease-out; outline: 0;
}
.dialog.sm { width: min(400px, 100%); }
.dialog.lg { width: min(640px, 100%); }
.dialog.xl { width: min(860px, 100%); }
.dialog-head { display: flex; align-items: center; gap: 14px; padding: 22px 24px 0; }
.dialog-head .grow { flex: 1; min-width: 0; }
.dialog-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); line-height: 1.35; }
.dialog-sub { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }
.dialog-x { margin: -4px -10px 0 0; align-self: flex-start; }
.dialog-body { padding: 18px 24px; overflow-y: auto; color: var(--text-2); }
.dialog-body > p + p { margin-top: 10px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 4px 24px 22px; flex-wrap: wrap; }
.dialog-error { margin: 0 24px 12px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ------------------------------------------------------------------ PIN pad */

.pin-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 4px 0 4px; }
.pin-dots { display: flex; gap: 14px; height: 18px; align-items: center; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--gray-300); transition: background .1s, border-color .1s, transform .1s; }
.pin-dot.opt { border-style: dashed; opacity: .6; }
.pin-dot.on { background: var(--primary); border-color: var(--primary); border-style: solid; opacity: 1; transform: scale(1.05); }
.pin-msg { min-height: 40px; text-align: center; font-size: 14px; color: var(--text-secondary); max-width: 300px; display: grid; place-items: center; }
.pin-msg.error { color: var(--danger); font-weight: 500; }
.pinpad { display: grid; grid-template-columns: repeat(3, 64px); gap: 14px 22px; justify-content: center; }
.pin-key {
  width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 24px; font-weight: 500; display: grid; place-items: center; cursor: pointer; user-select: none; font-variant-numeric: tabular-nums;
  transition: background .1s, border-color .1s, transform .06s; touch-action: manipulation;
}
.pin-key:hover:not(:disabled) { background: var(--hover); }
.pin-key:active:not(:disabled) { background: var(--primary-50); border-color: var(--primary); transform: scale(.96); }
.pin-key svg { width: 24px; height: 24px; }
.pin-key.plain { border-color: transparent; background: transparent; color: var(--text-secondary); }
.pin-key.go { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--shadow-primary); }
.pin-key.go:hover:not(:disabled) { background: var(--primary-600); }
.pin-key:disabled { opacity: .35; cursor: not-allowed; }
.shake { animation: shake .36s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

/* ------------------------------------------------------------------ signature pad / signature images */

.sigpad { position: relative; border: 1px dashed var(--border-hover); border-radius: var(--r-md); background: #fff; touch-action: none; overflow: hidden; }
.sigpad canvas { display: block; width: 100%; cursor: crosshair; touch-action: none; }
.sigpad-line { position: absolute; left: 24px; right: 24px; bottom: 34%; border-bottom: 1.5px solid #E5E7EB; pointer-events: none; }
.sigpad-x { position: absolute; left: 22px; bottom: calc(34% + 4px); color: #9CA3AF; font-size: 18px; pointer-events: none; }
.sigpad-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #9CA3AF; font-size: 14px; pointer-events: none; padding-bottom: 16%; }
.sigpad.has-ink .sigpad-hint { display: none; }
/* signatures are dark ink on transparent: always shown on white so they stay visible in the dark theme */
.sig-img { display: block; max-width: 100%; height: 40px; object-fit: contain; background: #fff; border-radius: 6px; }
.sig-chip { display: inline-flex; align-items: center; padding: 2px 6px; background: #fff; border: 1px solid var(--border); border-radius: var(--r-xs); }
.sig-chip img { height: 28px; max-width: 96px; object-fit: contain; }

/* ------------------------------------------------------------------ charts (uPlot) */

.chart { position: relative; min-height: 320px; }
.chart .uplot { font-family: var(--font); width: 100%; }
.chart .u-cursor-x { border-right: 1px dashed var(--gray-400) !important; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 140px; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--shadow-pop); font-size: 12px; color: var(--text-secondary);
  white-space: nowrap; transition: opacity .1s;
}
.chart-tip b { display: block; font-size: 15px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; margin-top: 2px; }
.chart-tip .tip-alarm { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--text-secondary); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.lg-line { width: 18px; height: 0; border-top: 2px solid var(--primary); border-radius: 2px; }
.lg-dash { width: 18px; height: 0; border-top: 2px dashed var(--gray-400); }
.lg-band { width: 14px; height: 10px; border-radius: 3px; background: var(--band); box-shadow: inset 0 0 0 1px rgba(22, 163, 74, .35); }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--danger-50); }
.lg-dot.ok { background: var(--success); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--success-50); }

/* small sparkline (home cards): an SVG plus the last-point dot */
.spark { position: relative; height: 84px; }
.spark svg { width: 100%; height: 100%; overflow: visible; }
.spark-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--primary-100); }
.spark-dot.danger { background: var(--danger); box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--danger-50); }

/* battery and radio mini meters */
.batt { position: relative; display: inline-block; width: 26px; height: 13px; border: 1.5px solid var(--text-secondary); border-radius: 4px; padding: 1.5px; flex: none; margin-right: 3px; }
.batt::after { content: ''; position: absolute; right: -4px; top: 3px; width: 2px; height: 4px; border-radius: 0 2px 2px 0; background: var(--text-secondary); }
.batt i { display: block; height: 100%; width: 0; border-radius: 1.5px; background: var(--success); }
.batt.low i { background: var(--warning); }
.batt.crit i { background: var(--danger); }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; flex: none; }
.bars i { width: 4px; border-radius: 1px; background: var(--gray-200); }
.bars i:nth-child(1) { height: 25%; } .bars i:nth-child(2) { height: 50%; }
.bars i:nth-child(3) { height: 75%; } .bars i:nth-child(4) { height: 100%; }
.bars i.on { background: var(--lvl, var(--text-secondary)); }
[data-level='1'] { --lvl: var(--danger); } [data-level='2'] { --lvl: var(--warning); }
[data-level='3'], [data-level='4'] { --lvl: var(--success); }
.meter { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }

/* ------------------------------------------------------------------ sign-in pages (login, setup) */

.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; background: var(--canvas); }
.auth-top { position: fixed; top: 20px; right: 20px; display: flex; gap: 10px; }
.auth-card { width: min(440px, 100%); padding: 36px 36px 32px; border-radius: var(--r-xl); box-shadow: var(--shadow-frame); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-brand .brand-mark { width: 40px; height: 40px; }
.auth-brand .brand-word { font-size: 22px; }
.auth-title { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.auth-sub { color: var(--text-secondary); margin-top: 6px; font-size: 14.5px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; margin-top: 26px; }
.auth-form .input { height: 48px; font-size: 15px; }
.auth-foot { margin-top: 22px; text-align: center; font-size: 12.5px; color: var(--text-muted); }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1199px) {
  body { background: var(--bg-main); }
  .app { margin: 0; height: 100vh; height: 100dvh; border: 0; border-radius: 0; box-shadow: none; }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* phones and portrait tablets: the sidebar becomes a drawer */
@media (max-width: 899px) {
  :root { --sb-w: 280px; --topbar-h: 64px; }
  .app { display: block; height: auto; min-height: 100vh; overflow: visible; background: var(--bg-main); }
  .main { overflow: visible; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 90; width: 280px; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: none; border-right: 0;
  }
  .nav-open .sidebar { transform: none; box-shadow: var(--shadow-dialog); }
  .sb-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(17, 24, 39, .4); animation: fade-in .15s; }
  .sb-collapse { display: none; }
  .sb-close { display: grid; }
  .hamburger { display: inline-grid !important; }
  .topbar { padding: 0 16px; gap: 10px; }
  .content { padding: 4px 16px 40px; }
  .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .input, .select { font-size: 16px; } /* iOS doesn't zoom into 16px fields */
}

@media (max-width: 639px) {
  .search { width: auto; flex: 1; }
  .search .kbd { display: none; }
  .tb-lang { display: none !important; }
  .topbar.searching .tb-actions, .topbar.searching .hamburger { display: none !important; }
  .search:not(.open) { flex: 0 0 auto; margin-left: auto; }
  .search:not(.open) .search-field { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 50%; cursor: pointer; }
  .search:not(.open) .search-field input { display: none; }
  .topbar:not(.searching) .search { order: 2; }
  .topbar:not(.searching) .tb-actions { order: 3; margin-left: 0; }
  .tb-actions { gap: 8px; }
  .page-head { margin: 4px 0 18px; }
  .page-title { font-size: 22px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .card { padding: 18px; border-radius: 14px; }
  .card-flush { padding: 0; }
  .card-flush > .card-head { padding: 16px 18px 12px; }
  .kpi { padding: 16px; gap: 10px; }
  .kpi-value { font-size: 24px; }
  .grid { gap: 14px; }
  .cols-2, .form-grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .table th:first-child, .table td:first-child { padding-left: 16px; }
  .table th:last-child, .table td:last-child { padding-right: 16px; }
  .table th, .table td { padding-left: 10px; padding-right: 10px; }
  .toasts { top: 12px; right: 16px; left: 16px; width: auto; }
  .tb-pop { position: fixed; top: 68px; left: 12px; right: 12px; width: auto; }
  .auth-card { padding: 28px 22px 24px; }
  .action-bar { bottom: 12px; padding: 10px 10px 10px 16px; }
  .dialog-head { padding: 20px 20px 0; }
  .dialog-body { padding: 16px 20px; }
  .dialog-foot { padding: 4px 20px 20px; }
  .dialog-foot .btn { flex: 1 1 auto; }
}

/* touch screens (the kitchen tablet): 48px targets */
@media (pointer: coarse) {
  .btn { height: 48px; padding: 0 18px; }
  .btn-sm { height: 40px; }
  .btn-xl { height: 60px; }
  .input, .select { height: 48px; }
  .chip { height: 48px; padding: 0 18px; font-size: 15px; }
  .nav-item { min-height: 48px; }
  .nav-sub .nav-item { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .seg button { height: 38px; padding: 0 14px; }
  .seg.lg button { height: 48px; }
  .pinpad { grid-template-columns: repeat(3, 72px); }
  .pin-key { width: 72px; height: 72px; font-size: 26px; }
  .menu-item { padding: 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------------ print (pages add their own @page) */

@media print {
  :root { color-scheme: light; }
  body { background: #fff !important; color: #000; }
  .sidebar, .topbar, .sb-backdrop, .toasts, .overlay, .no-print { display: none !important; }
  .app { display: block !important; height: auto !important; margin: 0 !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; overflow: visible !important; background: #fff !important; }
  .main { overflow: visible !important; background: #fff !important; }
  .content { padding: 0 !important; max-width: none !important; }
  .print-only { display: block !important; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (pointer: coarse) { .search .kbd { display: none; } }
.danger-text { color: var(--danger) !important; }
.chart-tip { left: 0; top: 0; }
.tip-alarm .pill { white-space: normal; }
.kpi-foot .pill { max-width: 100%; white-space: normal; }
