/* ==========================================================================
   3rd Space POS: tokens, base, app shell, shared components
   Brand: black + white. Accent: Signal Orange (#FF4F00), tenant-configurable.
   ========================================================================== */

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Inter Tight', 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --bg: #f3f3f1;
  --surface: #ffffff;
  --surface-2: #f7f7f5;
  --surface-3: #ececea;
  --ink: #0b0b0b;
  --ink-2: #4a4a46;
  --ink-3: #85847e;
  --line: #e5e4df;
  --line-2: #d2d1cb;
  --hover: rgba(11, 11, 11, 0.04);

  --chrome: #0b0b0b;
  --chrome-2: #161616;
  --chrome-ink: #ffffff;
  --chrome-ink-2: rgba(255, 255, 255, 0.62);
  --chrome-line: rgba(255, 255, 255, 0.10);

  --accent: #FF4F00;
  --accent-ink: #0b0b0b;
  --accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
  --accent-text: color-mix(in srgb, var(--accent) 72%, #000);

  --good: #0a7a30;   --good-bg: #e5f4e9;
  --warn: #8a5a00;   --warn-bg: #fff2d1;   --warn-mark: #f2a900;
  --crit: #c22b2b;   --crit-bg: #fde7e7;
  --info: #1f58b5;   --info-bg: #e7eefb;

  --chart-bar: #0b0b0b;
  --chart-muted: #d6d5cf;
  --grid: #ebeae5;

  --r-lg: 18px;
  --r: 14px;
  --r-sm: 10px;
  --r-xs: 7px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow-2: 0 10px 30px -12px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.06);
  --shadow-3: 0 30px 80px -20px rgba(0, 0, 0, 0.45);

  --sidebar-w: 252px;
  --topbar-h: 64px;
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sim-top: 0px;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #090909;
  --surface: #141414;
  --surface-2: #1b1b1b;
  --surface-3: #252525;
  --ink: #f3f3f1;
  --ink-2: #b9b8b2;
  --ink-3: #7f7e79;
  --line: #262626;
  --line-2: #363636;
  --hover: rgba(255, 255, 255, 0.05);
  --chrome: #000000;
  --chrome-2: #121212;
  --accent-text: color-mix(in srgb, var(--accent) 80%, #fff);
  --good: #3fcf6c;   --good-bg: rgba(63, 207, 108, 0.12);
  --warn: #f5b93a;   --warn-bg: rgba(245, 185, 58, 0.13);
  --crit: #ff6b6b;   --crit-bg: rgba(255, 107, 107, 0.13);
  --info: #79a8ff;   --info-bg: rgba(121, 168, 255, 0.13);
  --chart-bar: #f3f3f1;
  --chart-muted: #3a3a3a;
  --grid: #222;
  --shadow-2: 0 10px 30px -12px rgba(0, 0, 0, 0.8), 0 2px 6px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

html.embed-iphone { --sim-top: 50px; --safe-bottom: 26px; }
html.embed-ipad { --sim-top: 24px; --safe-bottom: 18px; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; line-height: 1.2; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
code { font-family: var(--font-mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 18px; height: 18px; flex: none; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 0.94em; }
.num-pos { color: var(--good); }
.num-neg { color: var(--crit); }
.grow { flex: 1; }
.sub { display: block; font-size: 12px; font-weight: 400; }
[hidden] { display: none !important; }

/* ---------- Brand mark ---------- */
.logo-mark { display: block; height: auto; }
.logo-img { object-fit: contain; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  padding-top: var(--sim-top);
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }

/* Sidebar */
.sidebar {
  background: var(--chrome);
  color: var(--chrome-ink);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}
.sb-brand { display: flex; align-items: center; gap: 14px; padding: 22px 20px 18px; }
.sb-logo { width: 46px; color: #fff; }
.sb-brand-text b { display: block; font-family: var(--font-display); font-size: 17px; letter-spacing: 0.01em; }
.sb-brand-text span { font-size: 12px; color: var(--chrome-ink-2); }
.sb-nav { padding: 6px 12px; flex: 1; }
.sb-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--chrome-ink-2); padding: 16px 10px 6px; font-weight: 600; }
.sb-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--chrome-ink-2); font-weight: 500;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.sb-link:hover { background: var(--chrome-line); color: #fff; }
.sb-link.active { background: #fff; color: #0b0b0b; font-weight: 600; }
.sb-link.active::after { content: ''; position: absolute; right: 10px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sb-foot { padding: 12px; border-top: 1px solid var(--chrome-line); }
.sb-user {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px; border-radius: var(--r-sm); text-align: left; color: #fff;
}
.sb-user:hover { background: var(--chrome-line); }
.sb-user > span:not(.avatar) { flex: 1; min-width: 0; }
.sb-user b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user em { font-style: normal; font-size: 11.5px; color: var(--chrome-ink-2); }
.sb-user .ico { color: var(--chrome-ink-2); }
.sb-powered { font-size: 10.5px; color: var(--chrome-ink-2); padding: 8px 10px 2px; line-height: 1.5; }
.sb-powered b { color: #fff; font-weight: 600; }
.sb-powered code { font-size: 10px; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.tb-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tb-logo { display: none; }
.tb-title h1 { font-size: 20px; font-weight: 700; }
.tb-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.tb-right { display: flex; align-items: center; gap: 8px; }
.demo-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  padding: 5px 10px; border-radius: 999px; border: 1px dashed var(--line-2);
}
.demo-tag .ico { width: 14px; height: 14px; }
.shift-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  padding: 6px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
}
.shift-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.shift-pill.on i { background: #19b24b; box-shadow: 0 0 0 3px rgba(25, 178, 75, 0.18); }
.shift-pill.off i { background: var(--crit); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-grid; place-items: center; position: relative;
  color: var(--ink-2);
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.dot-count {
  position: absolute; top: 3px; right: 2px;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--surface);
}
.tb-user { border-radius: 50%; }

/* View */
.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 28px 40px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.view-inner { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.view-inner > * { min-width: 0; }

/* Mobile tab bar + bubbles: hidden on desktop */
.tabbar, .bubble-layer { display: none; }

/* ==========================================================================
   Components
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 13.5px; white-space: nowrap;
  border: 1px solid transparent;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, opacity 0.15s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; }
.btn .ico { width: 17px; height: 17px; }
.btn.primary { background: var(--ink); color: var(--surface); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 85%, var(--surface)); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.accent:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn.ghost:hover:not(:disabled) { border-color: var(--ink); }
.btn.danger { background: var(--crit); color: #fff; }
.btn.danger-ghost { background: var(--surface); border-color: var(--line-2); color: var(--crit); }
.btn.danger-ghost:hover { border-color: var(--crit); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn.lg { height: 46px; padding: 0 20px; font-size: 14.5px; }
.btn.xl { height: 56px; font-size: 16px; border-radius: var(--r); }
.btn.full { width: 100%; }
.btn .count, .tab-btn .count, .qcol-head .count {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  font-weight: 600; font-size: 13px; color: var(--ink);
  border-bottom: 1px solid transparent;
}
.link-btn:hover { border-bottom-color: currentColor; }
.link-btn .ico { width: 15px; height: 15px; }
.link-btn.danger { color: var(--crit); }
.link-btn:disabled { opacity: 0.35; border-color: transparent; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-3); border-radius: var(--r-sm);
  max-width: 100%;
}
.seg.full { display: flex; width: 100%; }
.seg.full .seg-btn { flex: 1; }
.seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.seg-btn .ico { width: 16px; height: 16px; }
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.chips { display: flex; gap: 8px; }
.chips.wrap { flex-wrap: wrap; }
.scroll-x { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-2);
  font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip .ico { width: 16px; height: 16px; }
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  min-width: 0; flex: 1 1 220px; max-width: 420px;
  color: var(--ink-3);
}
.search:focus-within { border-color: var(--ink); }
.search input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; height: 100%; color: var(--ink); }
.input, .select {
  height: 40px; padding: 0 12px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--line-2); outline: 0;
  min-width: 0;
}
.input { width: 100%; }
.select.full { width: 100%; }
.input:focus, .select:focus { border-color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money-input { display: flex; align-items: center; height: 52px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); padding: 0 14px; gap: 6px; }
.money-input:focus-within { border-color: var(--ink); }
.money-input em { font-style: normal; color: var(--ink-3); font-size: 20px; }
.money-input input { border: 0; outline: 0; background: none; font-size: 24px; font-weight: 700; font-family: var(--font-display); width: 100%; min-width: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2);
}
.badge .ico { width: 13px; height: 13px; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warning { background: var(--warn-bg); color: var(--warn); }
.badge.critical { background: var(--crit-bg); color: var(--crit); }
.badge.info { background: var(--info-bg); color: var(--info); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center;
  background: var(--ink); color: var(--surface);
  font-family: var(--font-display); font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
}
.sb-user .avatar, .lock-screen .avatar { background: #fff; color: #0b0b0b; }
.avatar.xs { width: 22px; height: 22px; font-size: 9px; }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }
.avatar.md { width: 40px; height: 40px; }
.avatar.lg { width: 52px; height: 52px; font-size: 17px; }
.avatar.ghost, .avatar.sys { background: var(--surface-3); color: var(--ink-2); }
.avatar.sys .ico { width: 15px; height: 15px; }
.avatar .ico { width: 18px; height: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head h3 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-head h3 .ico { width: 18px; height: 18px; }
.card-head p { font-size: 12.5px; margin-top: 2px; }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.sec-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-family: var(--font); font-weight: 600; margin: 20px 0 10px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; text-align: left; min-width: 0;
}
.kpi.as-btn { transition: border-color 0.15s; }
.kpi.as-btn:hover { border-color: var(--ink); }
.kpi-top { display: flex; justify-content: space-between; align-items: center; color: var(--ink-3); }
.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.kpi-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value.sm { font-size: 22px; }
.kpis.small .kpi-value { font-size: 24px; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; flex-wrap: wrap; }
.kpi .badge { align-self: flex-start; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-size: 12px; padding: 2px 7px 2px 4px; border-radius: 999px; }
.delta .ico { width: 13px; height: 13px; }
.delta.up { color: var(--good); background: var(--good-bg); }
.delta.down { color: var(--crit); background: var(--crit-bg); }
.delta.flat { color: var(--ink-3); background: var(--surface-3); padding: 2px 8px; }

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
  text-align: left; width: 100%;
}
.list-row:last-child { border-bottom: 0; }
.list.compact .list-row { padding: 9px 2px; }
.btn-row { border-radius: var(--r-sm); padding: 10px 10px; }
.btn-row:hover { background: var(--hover); }
.btn-row.selected { background: var(--accent-soft); }
.lr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lr-main b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lr-main .muted { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lr-side { display: flex; align-items: center; gap: 10px; flex: none; }
.radio-row { display: flex; align-items: center; gap: 10px; padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.radio-row input { accent-color: var(--ink); width: 18px; height: 18px; }

.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; min-width: 60px; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.meter.low i { background: var(--warn-mark); }
.meter.out i { background: var(--crit); }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 36px 16px; text-align: center; color: var(--ink-3);
}
.empty .ico { width: 30px; height: 30px; margin-bottom: 4px; color: var(--ink-3); }
.empty strong { color: var(--ink); font-size: 15px; }
.empty span { font-size: 13px; max-width: 320px; }
.empty .btn { margin-top: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab-btn {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 10px 14px 12px; font-weight: 600; font-size: 13.5px; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn .ico { width: 17px; height: 17px; }
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--accent); }

.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.summary-strip { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); padding: 2px 2px; }
.summary-strip b { color: var(--ink); font-family: var(--font-display); font-size: 15px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.card .table-wrap { border: 0; border-radius: 0; margin: 0 -20px -20px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--ink-3); padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-action] { cursor: pointer; }
.table tbody tr[data-action]:hover td { background: var(--hover); }
.table tfoot td { padding: 12px 14px; border-top: 1px solid var(--line-2); font-weight: 600; }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table td .ico { width: 15px; height: 15px; vertical-align: -3px; }
.ellipsis { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strike { text-decoration: line-through; color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.who { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.who .sub { display: block; }

/* Tooltip */
.tip {
  position: fixed; left: 0; top: 0; z-index: 400;
  background: var(--ink); color: var(--surface);
  font-size: 12px; line-height: 1.45; padding: 7px 10px; border-radius: 8px;
  pointer-events: none; opacity: 0; transition: opacity 0.12s;
  max-width: 240px; box-shadow: var(--shadow-2);
}
.tip.show { opacity: 1; }

/* Toast */
#toast-root {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 350; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--ink); color: var(--surface);
  padding: 12px 16px; border-radius: 12px; font-weight: 500; font-size: 13.5px;
  box-shadow: var(--shadow-2);
  opacity: 0; transform: translateY(12px) scale(0.98); transition: opacity 0.2s, transform 0.25s;
}
.toast.show { opacity: 1; transform: none; }
.toast .ico { color: var(--accent); }

/* Spinner */
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { width: 40px; height: 24px; border-radius: 12px; background: var(--line-2); position: relative; transition: background 0.2s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform 0.2s; }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch span { font-size: 12.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.switch-row { cursor: pointer; }

/* ==========================================================================
   Modal / bottom sheet
   ========================================================================== */
.modal-wrap {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sim-top) + 24px) 24px 24px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.22s; backdrop-filter: blur(2px); }
.modal {
  position: relative; width: 100%; max-width: 520px; max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-3);
  opacity: 0; transform: translateY(10px) scale(0.98); transition: opacity 0.22s, transform 0.25s cubic-bezier(.2,.8,.2,1);
}
.modal-sm .modal { max-width: 420px; }
.modal-md .modal { max-width: 560px; }
.modal-lg .modal { max-width: 960px; }
.modal-wrap.open .modal-backdrop { opacity: 1; }
.modal-wrap.open .modal { opacity: 1; transform: none; }
.sheet-grip { display: none; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 4px 24px; }
.modal-head h3 { font-size: 19px; font-weight: 700; }
.modal-head p { font-size: 13px; margin-top: 4px; }
.modal-head .icon-btn { margin: -6px -6px 0 0; flex: none; }
.modal-body { padding: 16px 24px 20px; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot { display: flex; gap: 10px; padding: 14px 20px calc(16px + var(--safe-bottom) * 0); border-top: 1px solid var(--line); align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .grow { flex: 1; }

/* PIN pad */
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 8px 0 22px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; opacity: 0.4; transition: all 0.12s; }
.pin-dots i.on { background: currentColor; opacity: 1; }
.pin-dots.shake { animation: shake 0.38s; }
@keyframes shake { 0%,100% { transform: none; } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.pin-key {
  height: 64px; border-radius: 50%; font-size: 24px; font-weight: 600; font-family: var(--font-display);
  background: var(--surface-3); transition: background 0.1s, transform 0.08s;
}
.pin-key:active { transform: scale(0.94); background: var(--line-2); }
.pin-key.fn { font-size: 16px; background: transparent; color: var(--ink-2); }
.pin-hint { text-align: center; margin-top: 16px; font-size: 12px; color: var(--ink-3); }
.approver-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.approver-row .chip { padding-left: 6px; }

/* Lock screen */
.lock-screen {
  position: fixed; inset: 0; z-index: 260;
  background: var(--chrome); color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sim-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
  opacity: 0; transition: opacity 0.25s; overflow-y: auto;
}
.lock-screen.open { opacity: 1; }
.lock-inner { width: 100%; max-width: 640px; display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; margin: auto; }
.lock-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lock-logo { width: 72px; color: #fff; }
.lock-brand span { font-size: 12px; color: var(--chrome-ink-2); letter-spacing: 0.04em; }
.lock-clock b { display: block; font-family: var(--font-display); font-size: 52px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.lock-clock span { color: var(--chrome-ink-2); font-size: 13px; }
.lock-step h3 { font-size: 17px; margin-bottom: 16px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.lock-staff { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; width: 100%; }
.lock-person { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border-radius: var(--r); background: var(--chrome-2); border: 1px solid var(--chrome-line); color: #fff; transition: border-color 0.15s, transform 0.1s; }
.lock-person:hover { border-color: var(--accent); }
.lock-person:active { transform: scale(0.97); }
.lock-person b { font-size: 14px; }
.lock-person span { font-size: 11px; color: var(--chrome-ink-2); }
.lock-pin .pin-key { background: rgba(255,255,255,.1); color: #fff; }
.lock-pin .pin-key.fn { background: transparent; color: var(--chrome-ink-2); }
.lock-pin .pin-hint { color: var(--chrome-ink-2); }
.lock-back { color: var(--chrome-ink-2); margin-bottom: 12px; }
.lock-step { width: 100%; }

/* Print: only the receipt */
#print-root { display: none; }
@media print {
  body { overflow: visible; background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root .receipt { border: 0; box-shadow: none; margin: 0 auto; }
}

/* ==========================================================================
   Tablet & phone: top header + bottom tab bar with centre logo button
   ========================================================================== */
@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }

  .topbar {
    height: calc(56px + var(--safe-top));
    padding: var(--safe-top) 12px 0 14px;
    background: var(--chrome); color: var(--chrome-ink); border-bottom: 0;
  }
  .tb-logo { display: block; color: #fff; }
  .tb-logo-mark { width: 32px; }
  .tb-title h1 { font-size: 18px; color: #fff; }
  .tb-sub { color: var(--chrome-ink-2); font-size: 11px; }
  .tb-right { gap: 4px; }
  .device-seg, .demo-tag { display: none; }
  .icon-btn { color: var(--chrome-ink-2); }
  .icon-btn:hover { background: var(--chrome-line); color: #fff; }
  .dot-count { border-color: var(--chrome); }
  .tb-user .avatar { background: #fff; color: #0b0b0b; width: 32px; height: 32px; font-size: 12px; }
  .shift-pill { background: var(--chrome-2); border-color: var(--chrome-line); color: #fff; padding: 5px 10px; font-size: 11px; }

  .view { padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px); }

  /* --- Tab bar --- */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
    transition: background 0.25s, border-color 0.25s;
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 10.5px; font-weight: 600; color: var(--ink-3); position: relative;
    transition: color 0.15s, opacity 0.2s;
  }
  .tab .ico { width: 23px; height: 23px; }
  .tab.active { color: var(--ink); }
  .tab.active::before { content: ''; position: absolute; top: 0; width: 24px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

  .tab-center { display: flex; justify-content: center; position: relative; }
  .fab {
    position: relative; margin-top: -26px;
    width: 66px; height: 66px; border-radius: 50%;
    background: var(--chrome); color: #fff;
    border: 4px solid var(--surface);
    box-shadow: 0 8px 20px -6px rgba(0,0,0,.45);
    display: grid; place-items: center;
    transition: background 0.25s, transform 0.25s cubic-bezier(.34,1.56,.64,1), border-color 0.25s;
  }
  :root[data-theme='dark'] .fab { border-color: var(--surface); box-shadow: 0 0 0 1px var(--line-2), 0 8px 20px -6px rgba(0,0,0,.8); }
  .fab:active { transform: scale(0.94); }
  .fab.in-more::after { content: ''; position: absolute; top: 4px; right: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--chrome); }
  .fab-face { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity 0.2s, transform 0.35s cubic-bezier(.34,1.56,.64,1); }
  .fab-mark { width: 30px; color: #fff; }
  .fab-logo .logo-img { width: 34px; height: 34px; }
  .fab-x { opacity: 0; transform: rotate(-90deg) scale(0.5); }
  .fab-x .ico { width: 28px; height: 28px; stroke-width: 2.4; }

  body.fab-open:not(.fab-popping) .fab { background: var(--accent); color: var(--accent-ink); transform: rotate(90deg); }
  body.fab-open:not(.fab-popping) .fab::after { display: none; }
  body.fab-open:not(.fab-popping) .fab-logo { opacity: 0; transform: rotate(90deg) scale(0.4); }
  body.fab-open:not(.fab-popping) .fab-x { opacity: 1; transform: rotate(-90deg); }
  body.fab-open .tabbar { background: transparent; border-color: transparent; }
  body.fab-open .tab { opacity: 0.18; pointer-events: none; }
  body.fab-open:not(.fab-popping) .fab { border-color: transparent; }

  /* --- Bubbles --- */
  .bubble-layer { display: block; }
  .bubble-backdrop {
    position: fixed; inset: 0; z-index: 45;
    background: rgba(8, 8, 8, 0.72);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
  }
  .bubbles {
    position: fixed; z-index: 55; left: 50%; width: 0; height: 0;
    bottom: calc(var(--safe-bottom) + var(--tabbar-h) - 7px);
    pointer-events: none;
  }
  .bubble {
    position: absolute; left: 0; top: 0;
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    width: 84px; margin-left: -42px; margin-top: -28px;
    transform: translate(0, 0) scale(0.3);
    opacity: 0;
    transition: transform 0.28s cubic-bezier(.4,0,.2,1), opacity 0.18s;
    pointer-events: none;
  }
  .bubble-dot {
    position: relative;
    width: 56px; height: 56px; border-radius: 50%;
    display: grid; place-items: center;
    background: #fff; color: #0b0b0b;
    box-shadow: 0 10px 24px -8px rgba(0,0,0,.6);
  }
  .bubble-dot .ico { width: 24px; height: 24px; }
  .bubble.active .bubble-dot { background: var(--accent); color: var(--accent-ink); }
  .bubble-dot::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid #fff; opacity: 0; pointer-events: none; }
  .bubble-label { color: #fff; font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.15; text-shadow: 0 1px 6px rgba(0,0,0,.6); }

  body.fab-open .bubble-backdrop { opacity: 1; pointer-events: auto; }
  body.fab-open .bubble {
    opacity: 1; pointer-events: auto;
    transform: translate(var(--x), var(--y)) scale(1);
    transition: transform 0.5s cubic-bezier(.34,1.56,.64,1) calc(var(--i) * 40ms), opacity 0.2s calc(var(--i) * 40ms);
  }
  body.fab-open .bubble:active .bubble-dot { transform: scale(0.92); }

  /* "Pop" when closing with the X: each bubble bursts in place */
  body.fab-popping .bubble { animation: bubble-pop 0.38s ease-out forwards; animation-delay: calc(var(--i) * 25ms); pointer-events: none; }
  body.fab-popping .bubble-dot::after { animation: bubble-ring 0.38s ease-out forwards; animation-delay: calc(var(--i) * 25ms); }
  body.fab-popping .bubble-backdrop { opacity: 0; transition-delay: 0.12s; pointer-events: none; }
  @keyframes bubble-pop {
    0% { transform: translate(var(--x), var(--y)) scale(1); opacity: 1; }
    35% { transform: translate(var(--x), var(--y)) scale(1.2); opacity: 1; }
    100% { transform: translate(var(--x), var(--y)) scale(0.2); opacity: 0; }
  }
  @keyframes bubble-ring {
    0% { opacity: 0.9; transform: scale(1); }
    100% { opacity: 0; transform: scale(2.1); }
  }

  #toast-root { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px); }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

/* Simulated status bar + home indicator inside the device preview */
.sim-status, .home-indicator { display: none; }
html.embed .sim-status {
  display: flex; align-items: center; justify-content: space-between;
  position: fixed; top: 0; left: 0; right: 0; height: var(--sim-top); z-index: 280;
  background: var(--chrome); color: #fff;
  font-family: -apple-system, 'SF Pro Text', var(--font); font-weight: 600;
  pointer-events: none;
}
html.embed-iphone .sim-status { padding: 6px 30px 0 46px; font-size: 16px; }
html.embed-ipad .sim-status { padding: 0 22px; font-size: 12.5px; }
.ss-time em { font-style: normal; font-weight: 500; margin-left: 4px; }
.ss-icons { display: flex; align-items: center; gap: 6px; }
.ss-batt { width: 26px; height: 13px; border: 1.5px solid rgba(255,255,255,.55); border-radius: 4px; padding: 1.5px; position: relative; }
.ss-batt::after { content: ''; position: absolute; right: -4px; top: 3.5px; width: 2px; height: 4px; border-radius: 0 1px 1px 0; background: rgba(255,255,255,.55); }
.ss-batt i { display: block; height: 100%; width: 78%; border-radius: 1.5px; background: #fff; }
html.embed .home-indicator {
  display: block; position: fixed; z-index: 290; left: 50%; bottom: 7px; transform: translateX(-50%);
  width: 136px; height: 5px; border-radius: 3px; background: var(--ink); opacity: 0.85; pointer-events: none;
}
html.embed-ipad .home-indicator { width: 300px; bottom: 6px; }
html.embed .lock-screen .home-indicator { background: #fff; }

/* Phones */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .tb-sub { display: none; }
  .shift-pill { display: none; }
  .view-inner { gap: 16px; }
  .card { padding: 16px; border-radius: var(--r); }
  .card .table-wrap { margin: 0 -16px -16px; }
  .kpi { padding: 14px; border-radius: var(--r); }
  .kpi-value { font-size: 22px; }
  .kpis.small .kpi-value { font-size: 20px; }
  .kpi-top .ico { display: none; }
  .search { max-width: none; flex-basis: 100%; }
  .filters .select { flex: 1 1 140px; }
  .filters > .seg { overflow-x: auto; scrollbar-width: none; }
  .filters > .seg::-webkit-scrollbar { display: none; }
  .field-row { grid-template-columns: 1fr; gap: 0; }

  /* Modal becomes a bottom sheet */
  .modal-wrap { align-items: flex-end; padding: calc(var(--sim-top) + 28px) 0 0; }
  .modal, .modal-sm .modal, .modal-md .modal, .modal-lg .modal {
    max-width: none; border-radius: 22px 22px 0 0;
    transform: translateY(100%); opacity: 1;
    transition: transform 0.32s cubic-bezier(.2,.8,.2,1);
  }
  .modal-wrap.open .modal { transform: none; }
  .sheet-grip { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 8px auto 0; flex: none; }
  .modal-head { padding: 12px 16px 2px 20px; }
  .modal-body { padding: 14px 20px 18px; }
  .modal-foot { padding: 12px 16px calc(12px + var(--safe-bottom)); }
  .modal-foot .btn { flex: 1; }
  .modal-foot .stepper { flex: none; }

  /* Tables become stacked cards */
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .card .table-wrap { margin: 0; }
  .table thead { display: none; }
  .table, .table tbody, .table tfoot { display: block; }
  .table tr { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 14px; margin-bottom: 10px; }
  .card .table tr { border-radius: var(--r-sm); }
  .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); text-align: right; }
  .table td:last-child { border-bottom: 0; }
  .table td::before { content: attr(data-l); font-size: 11.5px; font-weight: 600; color: var(--ink-3); text-align: left; flex: none; }
  .table td:not([data-l]) { justify-content: flex-end; }
  .table td:not([data-l])::before { display: none; }
  .table td:first-child { font-size: 14px; }
  .table .r { text-align: right; }
  .ellipsis { max-width: 60%; }
  .table tfoot tr { background: var(--surface-2); }
  .table tfoot td { border: 0; }
  .table tfoot td:empty { display: none; }

  .pin-pad { grid-template-columns: repeat(3, 68px); gap: 10px; }
  .pin-key { height: 60px; }
  .lock-clock b { font-size: 44px; }
  .lock-staff { grid-template-columns: repeat(3, 1fr); }
}
