/* Studio MK — own theme (not ALICSS, by request). Warm paper neutrals + terracotta accent. */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d1c1a;
  --ink-2: #3a3834;
  --muted: #6f6b64;
  --line: #e4e1da;
  --line-2: #d6d2c9;
  --accent: #b4532a;
  --accent-hover: #9c4521;
  --accent-ink: #ffffff;
  --accent-soft: #f7e8e0;
  --ok: #2c7a4b;
  --ok-soft: #e2f1e7;
  --warn: #8a5d00;
  --warn-soft: #fbf0d4;
  --neg: #c0392b;
  --neg-soft: #fbe5e2;
  --focus: rgba(180, 83, 42, .35);
  --shadow: 0 1px 2px rgba(29, 28, 26, .05), 0 6px 20px rgba(29, 28, 26, .05);
  --radius: 14px;
  --radius-sm: 9px;
  --top-h: 60px;
  --nav-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #151413;
  --surface: #1e1d1b;
  --surface-2: #232220;
  --ink: #edebe6;
  --ink-2: #d4d1ca;
  --muted: #a19c93;
  --line: #34322e;
  --line-2: #45423d;
  --accent: #e07a4f;
  --accent-hover: #ea8c64;
  --accent-ink: #1a1009;
  --accent-soft: #3a2419;
  --ok: #6cc591;
  --ok-soft: #1d3326;
  --warn: #e3b85a;
  --warn-soft: #362c14;
  --neg: #f0786b;
  --neg-soft: #3a1d1a;
  --focus: rgba(224, 122, 79, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  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; }
.top-nav a {
  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; }
@media (min-width: 1000px) { .grid-2 { grid-template-columns: 1fr 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);
}
