:root {
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #f8f8fb;
  --ink: #17171c;
  --muted: #6b6b78;
  --border: #e3e3ea;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --accent-soft: #fbe7ea;
  --side: #121218;
  --side-ink: #c9c9d4;
  --ok: #2f9e44;
  --warn: #e8913a;
  --danger: #d6293e;
  --info: #4a7fd6;
  --chart-bar: #4fb3bf;
  --chart-bar-hover: #2f8f9b;
  --chart-line: #c8102e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 2px 8px rgba(20, 20, 30, .04);
  --side-w: 232px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w);
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; padding: 18px 12px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; padding: 4px 8px 22px; font-size: 1.05rem; }
.brand img { border-radius: 9px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--side-ink); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.install-btn { margin: 18px 6px 0; }
.side-foot { margin-top: auto; font-size: .75rem; padding: 0 8px; opacity: .6; }
.view { margin-left: var(--side-w); padding: 26px 32px 60px; max-width: 1280px; }

@media (max-width: 860px) {
  .sidebar {
    inset: auto 0 0 0; width: auto; height: calc(62px + env(safe-area-inset-bottom));
    flex-direction: row; padding: 0 0 env(safe-area-inset-bottom);
  }
  .brand, .side-foot, .install-btn { display: none; }
  .nav { flex-direction: row; flex: 1; gap: 0; }
  .nav a { flex: 1; flex-direction: column; gap: 3px; font-size: .68rem; padding: 9px 2px; border-radius: 0; justify-content: center; }
  .nav a.active { background: transparent; color: #fff; box-shadow: inset 0 3px 0 var(--accent); }
  .nav a.active svg { stroke: var(--accent); }
  .view { margin-left: 0; padding: 18px 14px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.35rem; }
}

/* ---------- page pieces ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.counter {
  display: inline-flex; align-items: baseline; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 12px 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.counter span { color: var(--muted); font-weight: 500; }
.counter b { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; }
.kpi span { color: var(--muted); font-size: .82rem; }
.kpi b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: .75rem; min-height: 1em; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.banner { background: #fff4e5; border: 1px solid #f5d0a0; color: #7a4a0b; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: .9rem; }
.empty { color: var(--muted); padding: 18px 4px; margin: 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 16px; border-radius: 9px;
  cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #a90d27; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: #fdecee; }
.btn-primary-ghost { color: var(--accent); border-color: #f0c3ca; }
.btn-primary-ghost:hover { background: var(--accent-soft); }
.btn-sm { padding: 5px 11px; font-size: .8rem; min-height: 32px; }
.icon-btn { border: 0; background: transparent; font-size: 1.3rem; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: var(--surface-2); }
.link { color: var(--accent); text-decoration: none; font-weight: 500; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  border: 1px solid #d3d3dc; border-radius: 9px; padding: 9px 11px; min-height: 42px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, .cal-cell:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
input[readonly] { background: var(--surface-2); font-weight: 600; }
input[type=color] { padding: 3px; width: 64px; height: 42px; cursor: pointer; }
input[type=checkbox] { width: auto; min-height: 0; }
.search { max-width: 300px; }
.form .field { margin-bottom: 14px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; color: #3a3a45; }
.field-error { color: var(--danger); font-size: .82rem; margin-top: 5px; }
.field-error:empty { display: none; }
.has-error input, .has-error select { border-color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.grid-colour { display: grid; grid-template-columns: 2fr 1fr; gap: 0 16px; max-width: 560px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .grid-2, .grid-colour { grid-template-columns: 1fr; } }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.form-actions.left { justify-content: flex-start; align-items: center; margin: 14px 0 8px; }
.form-actions.left label.small { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.form-actions.left select { width: auto; min-height: 36px; padding: 5px 8px; }
.form-actions.sticky {
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 6px; z-index: 5;
}
@media (max-width: 860px) { .form-actions.sticky { bottom: calc(62px + env(safe-area-inset-bottom)); } }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; cursor: pointer; }

/* segmented */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; font: inherit; font-size: .85rem; font-weight: 600; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-sm { margin-bottom: 12px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; min-height: 36px; padding: 5px 9px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 10px 18px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--ink); border-color: var(--accent); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.opts { text-align: right; white-space: nowrap; }
.opts .btn + .btn { margin-left: 4px; }
.nowrap { white-space: nowrap; }
td.low { color: var(--danger); font-weight: 700; }
.thumb-btn { border: 0; padding: 0; background: none; cursor: zoom-in; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0,0,0,.15); vertical-align: middle; margin-right: 10px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.pill-booked { background: #fde3e6; color: #a3172b; }
.pill-pending { background: #fdebd6; color: #9a5512; }
.pill-completed { background: #e0f2e4; color: #1f6e31; }

@media (max-width: 640px) {
  .table thead { display: none; }
  .table tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
  .table tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 2px 0; }
  .table td.num { text-align: left; }
  .table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-weight: 400; }
  .table td.opts { flex-basis: 100%; text-align: left; white-space: normal; padding-top: 6px; }
  .opts .btn { margin: 2px 4px 2px 0; }
  .opts .btn + .btn { margin-left: 0; }
}

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d3d3dc; background: var(--surface);
  border-radius: 99px; padding: 6px 13px; font: inherit; font-size: .85rem; cursor: pointer; font-weight: 500;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .sw { width: 13px; height: 13px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }
.chip.on .sw { border-color: rgba(255,255,255,.6); }

/* ---------- autocomplete ---------- */
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: 72px; z-index: 30; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 320px; overflow: auto;
}
.ac-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.ac-item:last-child { border-bottom: 0; }
.ac-item.active, .ac-item:hover { background: var(--accent-soft); }
.ac-empty { padding: 12px; color: var(--muted); }
.ac-selected { margin-top: 5px; }

/* ---------- image field / cropper ---------- */
.img-field { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.img-preview { width: 140px; height: 140px; border-radius: 10px; border: 1px dashed #c6c6d0; display: grid; place-items: center; overflow: hidden; background: var(--surface-2); }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-actions { display: flex; flex-direction: column; gap: 8px; }
.crop-tools { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.crop-stage { position: relative; margin: 0 auto; touch-action: none; user-select: none; background: #000; }
.crop-stage canvas { display: block; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); cursor: move; touch-action: none; }
.crop-box .h { position: absolute; width: 22px; height: 22px; background: #fff; border-radius: 50%; border: 3px solid var(--accent); }
.crop-box .nw { left: -11px; top: -11px; cursor: nwse-resize; }
.crop-box .ne { right: -11px; top: -11px; cursor: nesw-resize; }
.crop-box .sw { left: -11px; bottom: -11px; cursor: nesw-resize; }
.crop-box .se { right: -11px; bottom: -11px; cursor: nwse-resize; }
.crop-stage { overflow: hidden; }
.hint { text-align: center; color: var(--muted); font-size: .82rem; margin: 10px 0 0; }
.full-img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 8px; }

/* ---------- chart ---------- */
.chart-wrap { height: 300px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; touch-action: pan-y; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: .82rem; margin-top: 8px; align-items: center; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 6px; }
.lg-bar { width: 14px; height: 12px; background: var(--chart-bar); border-radius: 2px; }
.lg-line { width: 18px; height: 3px; background: var(--chart-line); border-radius: 2px; }
.legend .muted { margin-left: auto; }

/* ---------- calendar ---------- */
.cal { max-width: 560px; }
.cal-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.cal-nav strong { min-width: 150px; text-align: center; }
.cal-nav .btn { margin-left: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { text-align: center; font-size: .75rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-cell {
  aspect-ratio: 1 / .9; border: 0; border-radius: 6px; color: #fff; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 2px;
}
.cal-cell b { font-size: 1rem; }
.cal-cell small { font-size: .62rem; opacity: .9; }
.cal-cell.empty { background: transparent; cursor: default; }
.st-available { background: var(--ok); }
.st-booked { background: var(--danger); }
.st-pending { background: var(--warn); }
.cal-cell.past { opacity: .55; }
.cal-cell.today { box-shadow: inset 0 0 0 3px rgba(255,255,255,.9); }
.cal-cell.sel { outline: 3px solid var(--ink); outline-offset: 1px; }
.cal-cell:hover { filter: brightness(1.08); }
.cal-legend { display: flex; gap: 16px; margin-top: 12px; flex-wrap: wrap; font-size: .85rem; }
.cal-legend i { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 5px; color: #fff; font-style: normal; font-weight: 700; margin-right: 6px; }
.cal-layout { display: grid; grid-template-columns: minmax(280px, 520px) 1fr; gap: 24px; align-items: start; }
.day-detail .card-head { margin-bottom: 8px; }
@media (max-width: 1100px) {
  .cal-layout { grid-template-columns: 1fr; }
  .day-detail { border-top: 1px solid var(--border); padding-top: 14px; }
}

/* ---------- accessories ---------- */
.needle-preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 14px; margin-bottom: 14px; display: inline-block; }
.needle-preview b { font-family: ui-monospace, Consolas, monospace; font-size: 1.1rem; color: var(--accent); }
.picker { display: flex; align-items: center; gap: 10px; }

/* ---------- modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,10,15,.5); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 14px; width: min(440px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-wide { width: min(780px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; overflow: auto; }
.modal-body p { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 500; transition: opacity .3s, transform .3s; }
.toast-err { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@media (max-width: 860px) { .toasts { left: 16px; right: 16px; } }

/* ================= v2 additions ================= */
:root { --st-available: var(--ok); --st-booked: var(--danger); --st-pending: var(--warn); }
.st-available { background: var(--st-available); }
.st-booked { background: var(--st-booked); }
.st-pending { background: var(--st-pending); }
.cal-cell.split b, .cal-cell.split small { text-shadow: 0 1px 2px rgba(0,0,0,.35); }

.banner-danger { background: #fdecee; border-color: #f3b9c1; color: #7d1020; }
.due { color: var(--danger); font-weight: 600; }
.h-sub { font-size: 1rem; font-weight: 500; }
.counter .small { color: var(--muted); }

/* pager */
.pager { display: flex; align-items: center; gap: 6px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.pager > .muted { margin-right: auto; }

/* client history */
.client-card { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.client-card > div { display: flex; flex-direction: column; gap: 2px; }
@media (max-width: 700px) { .client-card { grid-template-columns: 1fr 1fr; } }

/* reports */
.grid-reports { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 18px; }
@media (max-width: 1100px) { .grid-reports { grid-template-columns: 1fr; } }
.toolbar label.small { display: inline-flex; align-items: center; gap: 6px; }
.toolbar input[type=date] { width: auto; min-height: 36px; padding: 5px 8px; }

/* needle chips with quantity */
.chip-q { display: inline-flex; align-items: center; gap: 4px; }
.chip-q input { width: 58px; min-height: 34px; padding: 4px 6px; text-align: center; }
.stock-tag { font-size: .7rem; opacity: .7; font-weight: 400; }
.stock-tag.low { color: var(--danger); opacity: 1; font-weight: 700; }
.chip.on .stock-tag.low { color: #ffb3bd; }
[data-stockmsg] { margin-top: 6px; }

/* lock screen */
.lock { position: fixed; inset: 0; z-index: 300; background: var(--side); display: grid; place-items: center; padding: 20px; }
.is-locked .modal-backdrop { z-index: 310; }
.lock-box { text-align: center; color: #fff; width: min(320px, 100%); }
.lock-box img { border-radius: 16px; }
.lock-box h2 { margin: 12px 0 2px; font-size: 1.3rem; }
.lock-box .muted { color: #a5a5b2; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 8px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #8a8a98; }
.pin-dots i.on { background: #fff; border-color: #fff; }
.pin-input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.pin-err { min-height: 22px; color: #ff8a98; font-size: .9rem; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 8px auto 14px; width: 260px; }
.keypad button { height: 64px; border-radius: 50%; border: 0; background: rgba(255,255,255,.09); color: #fff; font-size: 1.5rem; font-weight: 500; cursor: pointer; width: 64px; justify-self: center; }
.keypad button:active, .keypad button:hover { background: rgba(255,255,255,.2); }
.link-btn { background: none; border: 0; color: #a5a5b2; text-decoration: underline; cursor: pointer; font: inherit; font-size: .85rem; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }

/* receipt */
.receipt { max-width: 560px; margin: 0 auto; color: #111; font-size: .92rem; }
.r-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #111; padding-bottom: 10px; margin-bottom: 12px; }
.r-head h2 { margin: 0 0 4px; font-size: 1.3rem; }
.r-meta { text-align: right; font-size: .85rem; }
.r-meta b { font-size: 1rem; letter-spacing: .08em; }
.r-to { margin-bottom: 12px; }
.r-table { width: 100%; border-collapse: collapse; }
.r-table th { text-align: left; font-weight: 600; width: 38%; padding: 6px 8px 6px 0; vertical-align: top; color: #444; }
.r-table td { padding: 6px 0; }
.r-table tr { border-bottom: 1px solid #e4e4e4; }
.r-sum td { text-align: right; font-variant-numeric: tabular-nums; }
.r-total th, .r-total td { font-weight: 800; font-size: 1.05rem; border-top: 2px solid #111; color: #111; }
.r-thanks { text-align: center; margin-top: 18px; color: #555; }
#printArea { display: none; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; padding: 10mm; }
  body { background: #fff; }
}

/* mobile nav has six items */
@media (max-width: 860px) { .nav a { font-size: .62rem; } }
@media (max-width: 640px) { .no-img { display: none; } }
