/* Studio MK — own theme (not ALICSS, by request). "Blueprint" palette (chosen 2026-10-24): architectural blue on blue-grey. */
:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-2: #f5f8fb;
  --ink: #13263d;
  --ink-2: #2a3d55;
  --muted: #566a80;
  --line: #dbe4ee;
  --line-2: #c7d4e2;
  --accent: #1d5fa6;
  --accent-hover: #174d88;
  --accent-ink: #ffffff;
  --accent-soft: #e1ecf8;
  --ok: #2c7a4b;
  --ok-soft: #e2f1e7;
  --warn: #8a5d00;
  --warn-soft: #fbf0d4;
  --neg: #c0392b;
  --neg-soft: #fbe5e2;
  --focus: rgba(29, 95, 166, .35);
  --shadow: 0 1px 2px rgba(19, 38, 61, .05), 0 6px 20px rgba(19, 38, 61, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --top-h: 60px;
  --nav-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1626;
  --surface: #112036;
  --surface-2: #15273f;
  --ink: #e4edf7;
  --ink-2: #c8d6e6;
  --muted: #8fa6bf;
  --line: #1f3352;
  --line-2: #2a4166;
  --accent: #7cb6ee;
  --accent-hover: #94c4f2;
  --accent-ink: #081626;
  --accent-soft: #173357;
  --ok: #6cc591;
  --ok-soft: #1d3326;
  --warn: #e3b85a;
  --warn-soft: #362c14;
  --neg: #f0786b;
  --neg-soft: #3a1d1a;
  --focus: rgba(124, 182, 238, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--neg); }
.nowrap { white-space: nowrap; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 8px 15px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--neg); }
.btn.danger:hover { background: var(--neg-soft); border-color: var(--neg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.icon-btn { min-width: 40px; padding: 8px; }

/* Two-option toggles: one fixed-width button that cycles (spacer holds the longest label). */
.cycle { position: relative; display: inline-grid; }
.cycle > .cycle-spacer { visibility: hidden; grid-area: 1 / 1; padding: 0 15px 0 34px; font-weight: 500; height: 0; overflow: hidden; }
.cycle > button { grid-area: 1 / 1; }
.cycle button[data-on="1"] { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.cycle button[data-on="0"] { color: var(--muted); }
.cycle button::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- forms ---------- */
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); align-content: start; }
.field > div, .field .input { font-weight: 400; }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 16px; /* no iOS zoom */
}
textarea.input { min-height: 70px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.input[readonly] { background: var(--surface-2); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.form-grid > * { grid-column: span 12; min-width: 0; }
@media (min-width: 760px) {
  .span-3 { grid-column: span 3 !important; }
  .span-4 { grid-column: span 4 !important; }
  .span-6 { grid-column: span 6 !important; }
  .span-8 { grid-column: span 8 !important; }
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface-2); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; cursor: pointer; color: var(--ink-2);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.form-error { color: var(--neg); font-size: 14px; min-height: 0; }

/* ---------- combobox ---------- */
.combo { position: relative; }
.combo-input { padding-right: 36px; }
.combo-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1;
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; display: none;
}
.combo.has-value .combo-clear { display: block; }
.combo-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 280px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.combo-list li { padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.combo-list li.active, .combo-list li:hover { background: var(--accent-soft); }
.combo-list li.combo-add { color: var(--accent); font-weight: 600; }
.combo-list li.combo-none { color: var(--muted); }
.combo-list li.combo-empty { color: var(--muted); cursor: default; background: none; }
.combo-list mark { background: none; color: var(--accent); font-weight: 700; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 22px; }
.auth-card form { display: grid; gap: 14px; }

/* ---------- shell ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; letter-spacing: 0; }
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; gap: 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.top .spacer { flex: 1; }
.top-nav { display: flex; gap: 2px; flex: 1 1 auto; min-width: 0; overflow: hidden; align-items: center; }
.top > .brand, .top > .btn { flex: 0 0 auto; }
.top > .brand div { white-space: nowrap; }
.top-nav a[hidden], .top-nav .top-more[hidden] { display: none; }
.top-nav .top-more { flex: 0 0 auto; border: 0; background: none; cursor: pointer; padding: 8px 12px; border-radius: 8px; color: var(--muted); font: inherit; font-weight: 500; font-size: 14px; white-space: nowrap; }
.top-nav .top-more:hover { color: var(--ink); background: var(--surface-2); }
.top-nav .top-more.active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.menu button.active { background: var(--surface-2); font-weight: 600; }
.menu button svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--muted); }
.top-nav a {
  flex: 0 0 auto; white-space: nowrap;
  padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: 14px;
}
.top-nav a:hover { color: var(--ink); background: var(--surface-2); }
.top-nav a.active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.acct-btn { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px;
}
.menu {
  position: fixed; z-index: 60; min-width: 220px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow);
}
.menu .menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button { display: flex; width: 100%; gap: 9px; align-items: center; padding: 9px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--surface-2); }

main.view {
  max-width: 1240px; margin: 0 auto;
  padding: calc(var(--top-h) + env(safe-area-inset-top) + 20px) 16px 40px;
}
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { flex: 1; }

.bottom-nav { display: none; }

@media (max-width: 759px) {
  .top-nav, .hide-sm { display: none !important; }
  .bottom-nav {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
  .bottom-nav a {
    display: grid; justify-items: center; align-content: center; gap: 3px;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500;
  }
  .bottom-nav a svg { width: 23px; height: 23px; }
  .bottom-nav a.active { color: var(--accent); }
  main.view { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); }
  h1 { font-size: 20px; }
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .card + .grid-2, .grid-2 + .card, .kpis + .card { margin-top: 16px; }
.card-body { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { flex: 1; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid-2 > * { min-width: 0; }   /* a wide table scrolls inside its card instead of widening the page (iPhone zoomed out) */
@media (min-width: 1000px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.grid-2 .card + .card { margin-top: 0; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters .field { min-width: 150px; flex: 1 1 150px; }
.filters .field.client { flex: 2 1 220px; }
.filters select.input { min-width: 150px; }
@media (max-width: 759px) { .filters .field { flex-basis: calc(50% - 5px); min-width: 0; } .filters .field.client { flex-basis: 100%; } }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th {
  font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-2); white-space: nowrap; user-select: none;
}
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--ink); }
table.data th[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
table.data th[data-dir="desc"]::after { content: " ▼"; font-size: 9px; }
table.data th.num, table.data td.num { text-align: right; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td, tr.totals-row td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line-2); border-bottom: 0; }
table.data td.desc { min-width: 180px; max-width: 360px; white-space: pre-wrap; color: var(--ink-2); }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.mute { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.bulkbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- receipt photo ---------- */
.photo-pick { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.photo-pick .btn.camera { min-height: 48px; font-weight: 600; }
.photo-preview { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.photo-preview img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.photo-preview .pdf-badge { width: 76px; height: 76px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.thumb-link { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; border: 0; background: none; color: var(--accent); font-weight: 500; padding: 0; }

/* ---------- modal + viewer ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(15, 14, 13, .5);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: 18px; border: 1px solid var(--line); box-shadow: var(--shadow);
}
.modal .modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal .modal-head h2 { flex: 1; }
.modal .modal-body { padding: 18px; }
.modal .modal-foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--line); }
@media (max-width: 759px) {
  .overlay { place-items: end center; padding: 0; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
}
.viewer { position: fixed; inset: 0; z-index: 90; background: rgba(10, 10, 9, .86); display: flex; flex-direction: column; }
.viewer-bar { display: flex; gap: 8px; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; color: #fff; }
.viewer-bar .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .2); color: #fff; }
.viewer-body { flex: 1; overflow: auto; display: grid; place-items: center; padding: 0 12px 12px; -webkit-overflow-scrolling: touch; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; background: #fff; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.viewer-body canvas { display: block; max-width: 100%; height: auto; margin: 0 auto 10px; background: #fff; }
.viewer-body.pages { display: block; }

/* ---------- toasts ---------- */
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
@media (max-width: 759px) { #toasts { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); } }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-weight: 500; animation: toast-in .2s ease-out; }
.toast.error { background: var(--neg); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.secret { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: 8px; padding: 10px 12px; font-size: 15px; word-break: break-all; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- reload button (top bar) ---------- */
.reload-btn { position: relative; color: var(--muted); }
.reload-btn:hover { color: var(--ink); }
.reload-btn.spinning svg { animation: smk-spin .8s linear infinite; }
@keyframes smk-spin { to { transform: rotate(360deg); } }
.reload-btn.has-update { color: var(--accent); }
.reload-btn.has-update::after {
  content: ""; position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- feedback & tickets ---------- */
.tk-btn { position: relative; color: var(--muted); }
.tk-btn:hover { color: var(--ink); }
.tk-count {
  position: absolute; top: 3px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}
.click-row { cursor: pointer; }
.pill.neg-pill { background: var(--neg-soft); color: var(--neg); }
.attach { border: 1px dashed transparent; border-radius: var(--radius-sm); }
.attach.drop, [data-attach].drop .attach { border-color: var(--accent); background: var(--accent-soft); }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 6px 10px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink); cursor: pointer; font-size: 13px;
}
.file-chip:hover { border-color: var(--accent); }
.file-chip .fc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.file-chip .fc-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 13px; }
.thread { padding: 6px 18px 14px; }
.msg { padding: 14px 0; border-bottom: 1px solid var(--line); }
.msg:last-child { border-bottom: 0; }
.msg-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 6px; }
.msg-head .avatar { width: 28px; height: 28px; font-size: 12px; }
.msg-reply .msg-head .avatar { background: var(--ok-soft); color: var(--ok); }
.msg-body { white-space: pre-wrap; word-break: break-word; color: var(--ink-2); }
.msg-status { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.viewer-text { margin: 0; padding: 16px; background: #fff; color: #13263d; border-radius: 6px; font: 13px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.viewer-nopreview { color: #fff; text-align: center; max-width: 420px; margin: auto; padding: 30px 16px; }
.combo-code { display: inline-block; min-width: 44px; margin-right: 8px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

/* ---------- client contacts ---------- */
.contact-list { display: grid; gap: 8px; }
.contact-row { display: grid; grid-template-columns: 1.2fr 1.2fr 1fr 1.4fr auto; gap: 8px; align-items: center; }
@media (max-width: 759px) {
  .contact-row { grid-template-columns: 1fr 1fr; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
  .contact-row [data-rm-contact] { grid-column: 1 / -1; justify-self: end; }
}
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 18px; }

/* ---------- client logos ---------- */
.client-logo { display: inline-grid; place-items: center; flex: none; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.client-logo-blank { background: var(--accent-soft); color: var(--accent); font-weight: 700; border-color: transparent; }
.client-cell { display: flex; align-items: center; gap: 10px; }
.client-head { display: flex; align-items: center; gap: 14px; }
.logo-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* KPI tiles: the generic `.card + .card { margin-top }` must not apply inside the grid, or every tile after
   the first is pushed down and the row looks uneven. Equal height, label/value/sub aligned. */
.kpis > .card + .card { margin-top: 0; }
.kpis { align-items: stretch; grid-auto-rows: 1fr; }
.kpi { display: flex; flex-direction: column; min-height: 112px; }
.kpi .sub { margin-top: auto; padding-top: 4px; }

/* ---------- KPI cards open a side drawer ---------- */
.kpi-btn { text-align: left; font: inherit; color: inherit; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.kpi-btn:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.kpi-btn:active { transform: scale(.99); }
.kpi .label { display: flex; align-items: center; gap: 6px; }
.kpi-more { margin-left: auto; font-size: 18px; line-height: 1; color: var(--muted); }
.kpi-btn:hover .kpi-more { color: var(--accent); }
.drawer-wrap { position: fixed; inset: 0; z-index: 85; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 14, 13, .45); opacity: 0; transition: opacity .2s; }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .22s ease-out;
}
.drawer-wrap.open .drawer { transform: none; }
.drawer-wrap.open .drawer-backdrop { opacity: 1; }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: calc(16px + env(safe-area-inset-top)) 18px 14px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow: auto; padding: 4px 18px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.drawer-h { margin: 18px 0 8px; }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

/* ---------- drawer attachments (Noème-style tiles) ---------- */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.att-tile { display: flex; flex-direction: column; text-align: left; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); cursor: pointer; overflow: hidden; font: inherit; }
.att-tile:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.att-thumb { display: grid; place-items: center; height: 110px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-icon { font-size: 40px; }
.att-cap { display: grid; gap: 1px; padding: 8px 10px; font-size: 13px; }
.att-cap strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer { z-index: 95; }   /* above the drawer */

/* ---------- dashboard chart (one series: one hue, validated light + dark) ---------- */
:root { --chart-bar: #1d5fa6; }
:root[data-theme="dark"] { --chart-bar: #7cb6ee; }
.kpis + .chart-card { margin-top: 16px; }
.chart-card { position: relative; }
.chart-pick { display: flex; align-items: center; gap: 8px; }
.chart-pick select { min-width: 220px; min-height: 36px; padding: 6px 10px; font-size: 14px; }
.hbars { display: grid; gap: 2px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 200px) 1fr auto; align-items: center; gap: 12px; padding: 5px 4px; border: 0; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; border-radius: 8px; }
.hbar:hover, .hbar:focus-visible { background: var(--surface-2); }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--ink-2); }
.hbar-track { height: 14px; display: flex; align-items: center; }
.hbar-fill { display: block; height: 14px; background: var(--chart-bar); border-radius: 0 4px 4px 0; }
.hbar-val { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; min-width: 70px; text-align: right; }
.vbars { display: flex; align-items: flex-end; gap: 8px; height: 230px; padding-top: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.vbar { flex: 1 0 42px; max-width: 90px; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0 2px; border: 0; background: none; color: var(--ink); font: inherit; cursor: pointer; border-radius: 8px 8px 0 0; }
.vbar:hover, .vbar:focus-visible { background: var(--surface-2); }
.vbar-track { flex: 1; width: 60%; display: flex; align-items: flex-end; }
.vbar-fill { display: block; width: 100%; background: var(--chart-bar); border-radius: 4px 4px 0 0; }
.vbar-val { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.vbar-label { font-size: 12px; color: var(--muted); padding-bottom: 4px; white-space: nowrap; }
.chart-total { margin-top: 10px; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; padding: 8px 10px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 13px; line-height: 1.4; box-shadow: var(--shadow); max-width: 240px; }
.chart-tip .muted { color: inherit; opacity: .7; }
@media (max-width: 759px) {
  .hbar { grid-template-columns: minmax(70px, 110px) 1fr auto; gap: 8px; }
  .chart-pick select { min-width: 0; width: 100%; }
  .chart-pick { flex: 1 1 100%; }
}

/* ---------- Bookkeeping tab ---------- */
.books-balance { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.books-balance .card + .card { margin-top: 0; }
.books-sec { margin-top: 16px; }
.books-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; }
.books-sec > summary::-webkit-details-marker { display: none; }
.books-sec > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.books-sec[open] > summary::before { transform: rotate(90deg); }
.books-sec[open] > summary { border-bottom: 1px solid var(--line); }
.books-sec > summary h2 { flex: 1; }
.books-tools { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.books-tools .field { min-width: 180px; }
.books-left { font-weight: 600; }

/* ---------- phone lists (company + contacts) ---------- */
.phone-list { display: grid; gap: 6px; }
.phone-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 8px; align-items: center; }
.contact-row { display: grid !important; grid-template-columns: 1fr !important; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.contact-main { display: grid; grid-template-columns: 1.1fr 1.2fr 1.4fr auto; gap: 8px; align-items: center; }
.contact-row [data-add-phone] { justify-self: start; }
@media (max-width: 759px) {
  .contact-main { grid-template-columns: 1fr 1fr; }
  .contact-main [data-k="email"] { grid-column: 1 / -1; }
  .contact-main [data-rm-contact] { grid-column: 1 / -1; justify-self: end; }
  .phone-row { grid-template-columns: 96px 1fr auto; }
}

/* ---------- view as / act as (only the admin doing it sees this bar) ---------- */
.acting-bar {
  position: fixed; left: 0; right: 0; z-index: 29; top: calc(var(--top-h) + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 12px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--line); font-size: 14px;
}
.acting-bar .btn { min-height: 30px; }
body.is-acting main.view { padding-top: calc(var(--top-h) + env(safe-area-inset-top) + 64px); }
.audit-by { display: block; font-size: 12px; color: var(--warn); }

/* ---------- projects ---------- */
.proj-choose { display: grid; gap: 6px; }
.used { display: inline-flex; align-items: center; gap: 8px; min-width: 120px; }
.used-track { flex: 1; height: 8px; min-width: 60px; border-radius: 4px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.used-fill { display: block; height: 100%; border-radius: 4px; }
.used-fill.ok { background: var(--ok); } .used-fill.near { background: var(--warn); } .used-fill.over { background: var(--neg); }
.used-num { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }
.used-num.near { color: var(--warn); } .used-num.over { color: var(--neg); font-weight: 700; }
.fee-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--surface-2); }
.phase-edit td { padding: 6px; } .phase-edit .input { min-height: 36px; padding: 6px 8px; font-size: 14px; }
.phase-edit .num-in { width: 78px; text-align: right; }
.fee-result { margin-top: 12px; }
.fee-lines { display: grid; gap: 4px; max-width: 420px; margin-left: auto; }
.fee-lines > div { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.fee-lines .fee-total { border-top: 1px solid var(--line-2); padding-top: 6px; font-size: 17px; }
.more-list { display: grid; gap: 6px; }
.more-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; color: var(--ink); text-decoration: none; border: 1px solid var(--line); }
.more-item svg { width: 22px; height: 22px; color: var(--muted); }
.bottom-nav a[data-more].active { color: var(--accent); }

/* ---------- help ---------- */
.help-btn { color: var(--muted); } .help-btn:hover { color: var(--ink); }
.help-link { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 500; text-decoration: none; color: var(--accent); white-space: nowrap; }
.help-link svg { width: 16px; height: 16px; }
.card-head .help-link { margin-left: auto; }
.help-wrap { display: grid; gap: 16px; grid-template-columns: 260px 1fr; align-items: start; }
.help-toc { padding: 12px; display: grid; gap: 2px; position: sticky; top: calc(var(--top-h) + 16px); }
.help-toc-g { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin: 8px 6px 4px; }
.help-toc a { padding: 6px 8px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.help-toc a:hover { background: var(--surface-2); color: var(--ink); }
.help-group { margin: 6px 0 10px; }
.help-group ~ .help-group { margin-top: 22px; }
.help-sec + .help-sec { margin-top: 10px; }
.help-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.help-sec > summary::-webkit-details-marker { display: none; }
.help-sec > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.help-sec[open] > summary::before { transform: rotate(90deg); }
.help-sec > summary h3 { margin: 0; }
.help-text { padding: 0 18px 16px 38px; color: var(--ink-2); line-height: 1.6; }
.help-text h4 { margin: 14px 0 4px; color: var(--ink); }
.help-text ul, .help-text ol { padding-left: 20px; margin: 6px 0; }
.help-text li + li { margin-top: 4px; }
.help-table { margin: 8px 0; max-width: 680px; }
@media (max-width: 899px) { .help-wrap { grid-template-columns: 1fr; } .help-toc { display: none; } .help-text { padding-left: 18px; } }

/* ---------- task rates ---------- */
.rate-grid td { padding: 6px; }
.rate-grid .num-in { width: 96px; text-align: right; min-height: 36px; padding: 6px 8px; font-size: 14px; }

/* ---------- tabs inside a modal (client edit: Details / Rates) ---------- */
.modal-tabs { display: flex; gap: 4px; margin: -4px 0 16px; border-bottom: 1px solid var(--line); }
.modal-tabs button { border: 0; background: none; padding: 9px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.modal-tabs button:hover { color: var(--ink); }
.modal-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.rate-list .num-in { width: 110px; text-align: right; min-height: 36px; padding: 6px 8px; font-size: 14px; }
.rate-list tr.rate-first td { border-top: 2px solid var(--line-2); }
.rate-list tbody tr:first-child td { border-top: 0; }
.rate-custom { border-color: var(--accent) !important; background: var(--accent-soft) !important; font-weight: 600; }

/* fixed-price task: the running charge (quantity × price each) */
.fixed-total { min-height: 44px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* phase budget: % of the fee or a fixed $ amount — one cycle button + the input */
.unit-in { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.unit-btn { display: inline-grid; min-width: 34px; padding-inline: 8px; font-weight: 700; }
.unit-btn > span { grid-area: 1 / 1; }
.unit-btn .unit-spacer { visibility: hidden; }

/* dashboard projects: expandable breakdown under a project row */
.detail-row > td { background: var(--surface-2); padding: 10px 12px 14px; }
.dash-detail .data { background: var(--surface); }
.part-head td { background: var(--surface-2); }
.caret { display: inline-block; width: 1em; color: var(--muted); }

/* ---------------- HR ---------------- */
.pill.bad { background: rgba(185, 28, 28, .12); color: #b91c1c; }
.kpis + .grid-2 { margin-top: 16px; }
.hr-fields { display: grid; gap: 12px; }
.hr-field > div { margin-top: 2px; overflow-wrap: anywhere; }
.hr-pay-now .value { font-size: 24px; font-weight: 700; }
.hr-em { margin-top: 8px; }
.hr-em .form-grid { width: 100%; }
.hr-cal th.cal-d { min-width: 22px; padding: 4px 2px; font-size: 11px; line-height: 1.2; text-align: center; }
.hr-cal td.cal-c { padding: 0; min-width: 22px; height: 28px; border-left: 1px solid var(--line); }
.cal-off { background: var(--surface-2); }
.cal-vacation { background: #1d5fa6 !important; }
.cal-sick { background: #c9932b !important; }
.cal-personal { background: #2f9e8f !important; }
.cal-bereavement { background: #6b7280 !important; }
.cal-unpaid { background: #a8a29e !important; }
.cal-other { background: #6f8f5a !important; }
.cal-req { opacity: .45; background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.5) 0 3px, transparent 3px 6px) !important; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); }
:root[data-theme="dark"] .pill.bad { color: #f87171; }

/* sub-tabs never wrap: they scroll sideways on a phone */
.modal-tabs { overflow-x: auto; scrollbar-width: none; }
.modal-tabs button { white-space: nowrap; flex: 0 0 auto; }

/* Notifications: Push + Email switch per alert */
.notif-table td { vertical-align: middle; }
.notif-table .cycle .btn { min-height: 32px; padding: 4px 10px; }

/* ---------------- Dashboard → Projects: one card per project ---------------- */
.dash-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.dash-tools .input { width: auto; min-height: 38px; }
.dash-tools [data-q] { flex: 1 1 220px; }
.dash-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.dash-summary > div { background: var(--surface); padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.dash-summary span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dash-summary strong { font-size: 20px; font-weight: 700; }
.warn-text { color: var(--warn, #b45309); }
.pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; }
.pcard { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; gap: 12px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.03); transition: border-color .15s, box-shadow .15s, transform .15s; }
.pcard:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.pcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pcard-head { display: flex; gap: 12px; align-items: flex-start; }
.pcard-title { min-width: 0; flex: 1; }
.pcard-code { font-size: 12px; font-weight: 700; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pcard-name { font-size: 16px; font-weight: 700; line-height: 1.3; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pcard-money { display: flex; align-items: flex-end; gap: 10px; }
.pcard-money > div:not(.pcard-of) { display: flex; flex-direction: column; }
.pcard-money span, .pcard-stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pcard-money strong { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.pcard-money > div:last-child strong { font-size: 16px; color: var(--muted); font-weight: 600; }
.pcard-of { color: var(--muted); font-size: 13px; padding-bottom: 4px; }
.pcard-bar .used { width: 100%; }
.pcard-bar .used-track { height: 10px; border-radius: 5px; }
.pcard-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.pcard-stats > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pcard-stats strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.drawer-status .kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
