/* Hung Ledger — mobile-first UI. Chart colours follow the validated reference palette (slot 1 blue = income, slot 2 orange = expense). */

/* Fonts are bundled locally (public/fonts, SIL OFL 1.1) so Lao and Thai always render correctly — even with no internet.
   Variable fonts: one file covers every weight 100–900. */
@font-face {
  font-family: "Noto Sans Lao";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/NotoSansLao-lao.woff2") format("woff2");
  unicode-range: U+0E81-0EDF, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Noto Sans Lao";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/NotoSansLao-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Noto Sans Lao";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/NotoSansLao-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Noto Sans Thai";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/NotoSansThai-thai.woff2") format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e9edf2;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.2);
  --text: #191919;
  --text-2: #5f6368;
  --text-3: #8a8f96;
  --primary: #1b64be;
  --primary-hover: #1757ac;
  --primary-ink: #ffffff;
  --primary-soft: #e8f1fd;
  --s1: #257de0;
  --s2: #f47230;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --good: #0aac23;
  --good-text: #006c10;
  --good-soft: #e7f6ea;
  --warn: #fbb315;
  --warn-soft: #fff6e0;
  --warn-text: #8a5a00;
  --crit: #dc3c3d;
  --crit-text: #c02a2b;
  --crit-soft: #fdecec;
  --meter-track: #cce3fd;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 10px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 10px 40px rgba(16, 24, 40, 0.18);
  --font: "Noto Sans Lao", "Noto Sans Thai", "Phetsarath OT", "Saysettha OT", "Lao UI", "Leelawadee UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sidebar: 248px;
  --bottombar: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0b0b0b; --surface: #191919; --surface-2: #222324; --surface-3: #2b2c2e;
    --border: rgba(255, 255, 255, 0.1); --border-strong: rgba(255, 255, 255, 0.2);
    --text: #efefef; --text-2: #a3a3a3; --text-3: #7c7c7c;
    --primary: #338ced; --primary-hover: #519ced; --primary-soft: #15263b;
    --s1: #338ced; --s2: #e76624; --grid: #303030; --axis: #474747;
    --good-text: #53c556; --good-soft: #11291a; --warn-soft: #2e2510; --warn-text: #f5c45a;
    --crit-text: #ff7b7b; --crit-soft: #331616; --meter-track: #1b3a63;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0b; --surface: #191919; --surface-2: #222324; --surface-3: #2b2c2e;
  --border: rgba(255, 255, 255, 0.1); --border-strong: rgba(255, 255, 255, 0.2);
  --text: #efefef; --text-2: #a3a3a3; --text-3: #7c7c7c;
  --primary: #338ced; --primary-hover: #519ced; --primary-soft: #15263b;
  --s1: #338ced; --s2: #e76624; --grid: #303030; --axis: #474747;
  --good-text: #53c556; --good-soft: #11291a; --warn-soft: #2e2510; --warn-text: #f5c45a;
  --crit-text: #ff7b7b; --crit-soft: #331616; --meter-track: #1b3a63;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; font-weight: 600; }
h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h3 { font-size: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
h4 { font-size: 14px; margin: 16px 0 8px; color: var(--text-2); }
p { margin: 0 0 8px; }
code { font-size: 12px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
small { font-size: 12.5px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.neg { color: var(--crit-text); }
.pos { color: var(--good-text); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.center { text-align: center; margin: 14px 0; }
.spacer { flex: 1; }
[hidden] { display: none !important; }
.ico { width: 20px; height: 20px; flex: none; }
.ico.small { width: 17px; height: 17px; }
.ico.tiny { width: 14px; height: 14px; vertical-align: -2px; }
.ico.big { width: 40px; height: 40px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost.on { background: var(--primary-soft); color: var(--primary); }
.btn-ghost.danger, .icon-btn.danger { color: var(--crit-text); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-lg { min-height: 50px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; background: transparent; color: var(--text-2);
  border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--text-2); font: inherit; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 8px 4px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ------------------------------------------------------------------ shell */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 40; transition: transform 0.22s ease;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 12px; }
.brand img { width: 40px; height: 40px; object-fit: contain; border-radius: 10px; }
.brand b { display: block; font-size: 15px; line-height: 1.25; }
.brand small { color: var(--text-2); font-size: 11.5px; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--primary); color: #fff; flex: none; }
.brand-mark.big { width: 60px; height: 60px; border-radius: 18px; margin: 0 auto 10px; }
.brand-mark.big .ico { width: 32px; height: 32px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--text); font-size: 14.5px; margin: 1px 0;
}
.sidebar nav a:hover { background: var(--surface-2); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-group { font-size: 11.5px; color: var(--text-3); padding: 14px 12px 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.nav-sep { height: 8px; }
.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.lang-switch { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.lang-switch button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font: inherit; font-size: 13px; color: var(--text-2); cursor: pointer; }
.lang-switch button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.main-col { margin-left: var(--sidebar); min-height: 100vh; }
#view { max-width: 1240px; margin: 0 auto; padding: 22px 26px 100px; outline: none; }
.topbar { display: none; }
.bottombar { display: none; }
.drawer-backdrop { display: none; }
.fab {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; box-shadow: 0 6px 20px rgba(27, 100, 190, 0.4);
}
.fab .ico { width: 28px; height: 28px; }
.fab-desk { position: fixed; right: 28px; bottom: 28px; z-index: 30; }

@media (max-width: 1000px) {
  .sidebar { transform: translateX(-105%); box-shadow: var(--shadow-lg); }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 35; }
  .main-col { margin-left: 0; }
  .topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 20; height: 54px; padding: 0 8px 0 4px;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
  }
  .topbar-title { flex: 1; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #view { padding: 16px 14px calc(var(--bottombar) + 40px); }
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    height: calc(var(--bottombar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .bottombar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-2); font-size: 11px; padding: 6px 0; }
  .bottombar a.active { color: var(--primary); font-weight: 600; }
  .bottombar .fab { margin: -26px auto 0; }
  .fab-desk { display: none; }
}

/* ------------------------------------------------------------------ page */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 13px; margin-bottom: 2px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar.sub { margin-top: -6px; }
.toolbar select, .toolbar input[type="search"] { min-height: 40px; }
.search { position: relative; display: flex; align-items: center; flex: 1 1 180px; max-width: 320px; }
.search .ico { position: absolute; left: 10px; color: var(--text-3); }
.search input { width: 100%; padding-left: 34px !important; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 4px; }
.card-head h3 { margin-bottom: 2px; }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2col > .card { margin-bottom: 0; }
.grid-2col + .grid-2col, .grid-2col + .card, .card + .grid-2col { margin-top: 16px; }
@media (max-width: 860px) { .grid-2col { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ forms */
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 11px; min-height: 42px; width: 100%;
}
textarea { min-height: 60px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.invalid, .chips.invalid { border-color: var(--crit) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--crit) 22%, transparent) !important; border-radius: var(--radius-sm); }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field .opt { font-style: normal; color: var(--text-3); font-weight: 400; }
.field.full { grid-column: 1 / -1; }
.hint { color: var(--good-text); min-height: 1em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
@media (max-width: 640px) { .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .grid2, .grid3 { grid-template-columns: 1fr; } .grid2 .qty-field, .grid2 .field:has(.stepper) { min-width: 0; } }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.form-error { color: var(--crit-text); font-size: 14px; }
.warn-text { color: var(--warn-text); font-size: 13px; display: inline-flex; gap: 4px; align-items: center; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.note-box { background: var(--primary-soft); color: var(--text); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13.5px; display: flex; gap: 8px; align-items: flex-start; }
.date-row { display: flex; gap: 6px; align-items: center; }
.date-row input { flex: 1; min-width: 0; }
.with-btn { display: flex; gap: 8px; align-items: center; }
.with-btn .money-field { flex: 1; }

/* chips: big tap targets */
.chip-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
  transition: all 0.12s;
}
.chip small { color: var(--text-3); font-size: 12px; }
.chip:hover { border-color: var(--primary); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.chip.on small { color: rgba(255, 255, 255, 0.8); }
.chip.add { border-style: dashed; color: var(--primary); }
.chip.mini { min-height: 32px; padding: 3px 11px; font-size: 13px; }
.chip-more { width: auto; min-height: 40px; border-radius: 999px; padding: 6px 12px; max-width: 220px; }
.chip-more.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.chips.seg { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 11px; flex-wrap: wrap; }
.chips.seg .chip { border: 0; min-height: 34px; border-radius: 9px; background: transparent; padding: 4px 13px; }
.chips.seg .chip.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.suggest:empty { display: none; }

/* stepper & money */
.stepper { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.stepper input { border: 0; border-radius: 0; text-align: center; font-size: 17px; font-weight: 600; min-width: 0; box-shadow: none !important; }
.step-btn { width: 46px; flex: none; border: 0; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.step-btn:active { background: var(--surface-3); }
.money-field { position: relative; display: flex; }
.money-field input { font-variant-numeric: tabular-nums; padding-right: 50px; }
.money-field.big input { font-size: 24px; font-weight: 700; min-height: 54px; }
.k-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%); border: 0; background: var(--surface-2); color: var(--text-2);
  border-radius: 7px; padding: 4px 7px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.amount-field .money-field.big input { font-size: 30px; min-height: 62px; }
.total-box {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}
.total-box > div:first-child { display: flex; flex-direction: column; }
.total-amt { font-size: 26px; font-weight: 700; line-height: 1.2; }
.manual-amt { flex-basis: 100%; }
details.more { border: 1px solid var(--border); border-radius: var(--radius); padding: 0 14px; background: var(--surface-2); }
details.more[open] { padding-bottom: 14px; }
details.more > summary { cursor: pointer; padding: 12px 0; font-weight: 600; font-size: 14px; list-style: none; display: flex; gap: 6px; align-items: center; }
details.more > summary::before { content: "▸"; color: var(--text-3); transition: transform 0.15s; }
details.more[open] > summary::before { transform: rotate(90deg); }
details.more > summary small { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.more > :not(summary) { margin-top: 12px; }

/* ------------------------------------------------------------------ modal */
.modal-wrap {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(10, 15, 25, 0); transition: background 0.16s;
}
.modal-wrap.in { background: rgba(10, 15, 25, 0.45); }
.modal-wrap.out { background: rgba(10, 15, 25, 0); }
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface);
  border-radius: 18px; box-shadow: var(--shadow-lg); transform: translateY(12px) scale(0.98); opacity: 0; transition: all 0.16s ease;
}
.modal.wide { max-width: 780px; }
.modal.small { max-width: 420px; }
.modal-wrap.in .modal { transform: none; opacity: 1; }
.modal-wrap.out .modal { transform: translateY(12px); opacity: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 16px 20px; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal.is-busy .modal-foot .btn-primary { opacity: 0.6; }
.foot-total { font-size: 16px; }
.confirm-text { font-size: 15.5px; white-space: pre-line; }
@media (max-width: 640px) {
  .modal-wrap { align-items: flex-end; padding: 0; }
  .modal, .modal.wide, .modal.small { max-width: none; border-radius: 20px 20px 0 0; max-height: 94vh; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .modal-foot .spacer, .modal-foot .foot-total { flex-basis: 100%; }
}
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.quick-btn .ico { width: 28px; height: 28px; color: var(--primary); }
.quick-btn.q-expense .ico { color: var(--s2); }
.quick-btn b { font-size: 15px; }
.quick-btn small { color: var(--text-2); }

/* ------------------------------------------------------------------ toast & tooltip */
#toasts { position: fixed; z-index: 200; left: 50%; top: 14px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw; }
.toast {
  background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toast-in 0.18s ease; transition: opacity 0.3s, transform 0.3s;
}
.toast-ok { background: #116b2a; }
.toast-err { background: #b42318; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
#tooltip {
  position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none; background: #1f2937; color: #fff; padding: 7px 10px;
  border-radius: 8px; font-size: 12.5px; white-space: pre-line; max-width: 280px; opacity: 0; transition: opacity 0.1s; line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
#tooltip.show { opacity: 1; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.rtable th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--text-2); padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.rtable td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.rtable tbody tr:last-child td { border-bottom: 0; }
.rtable tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border-strong); }
.rtable.compact td, .rtable.compact th { padding: 7px 10px; }
.rtable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rtable .main-cell small { display: block; color: var(--text-2); font-size: 12px; }
.rtable tr.clickable, .rtable tbody tr[data-id] { cursor: pointer; }
.rtable tbody tr[data-id]:hover { background: var(--surface-2); }
.rtable tr.sel { background: var(--primary-soft) !important; }
.rtable tr.is-void td { opacity: 0.5; }
.rtable .cb { width: 36px; }
.rtable .num small { display: block; font-weight: 400; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .icon-btn { width: 34px; height: 34px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; background: var(--surface-2); font-size: 12.5px; white-space: nowrap; }
.tag.t-exp { background: color-mix(in srgb, var(--s2) 16%, transparent); }
.tag.t-inc { background: color-mix(in srgb, var(--s1) 16%, transparent); }
@media (max-width: 760px) {
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tfoot { display: block; }
  .rtable tr { display: flex; flex-direction: column; position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 10px 14px; box-shadow: var(--shadow); }
  .rtable td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 3px 0; border: 0; text-align: right; }
  .rtable td::before { content: attr(data-label); color: var(--text-2); font-size: 13px; text-align: left; flex: none; }
  .rtable td:empty, .rtable td.row-actions:not(:has(*)) { display: none; }
  .rtable td.main-cell { order: -1; display: block; text-align: left; font-size: 16px; padding-right: 40px; }
  .rtable td.main-cell::before, .rtable td.row-actions::before, .rtable td.cb::before { display: none; }
  .rtable td.cb { position: absolute; top: 12px; right: 12px; width: auto; padding: 0; }
  .rtable td.row-actions { justify-content: flex-end; gap: 4px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
  .rtable .num { white-space: normal; }
  .rtable tfoot tr { background: var(--surface-2); }
  .rtable tfoot td::before { content: none; }
  .rtable.compact tr { padding: 8px 12px; }
}

/* ------------------------------------------------------------------ badges, status */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.b-unbilled { background: var(--surface-3); color: var(--text-2); }
.b-unpaid { background: var(--warn-soft); color: var(--warn-text); }
.b-partial { background: var(--primary-soft); color: var(--primary); }
.b-paid { background: var(--good-soft); color: var(--good-text); }
.b-void { background: var(--surface-3); color: var(--text-3); text-decoration: line-through; }
.b-overdue { background: var(--crit-soft); color: var(--crit-text); }
h1 .badge { font-size: 13px; }
.badge-link:hover .badge { filter: brightness(0.95); text-decoration: underline; }

/* ------------------------------------------------------------------ summary strips & cards */
.sum-strip { display: flex; flex-wrap: wrap; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.sum-strip > div { flex: 1 1 140px; background: var(--surface); padding: 10px 14px; display: flex; flex-direction: column; }
.sum-strip small { color: var(--text-2); }
.sum-strip b { font-size: 17px; }
.bulk {
  position: sticky; top: 8px; z-index: 15; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.bulk span { flex: 1; font-weight: 600; }
@media (max-width: 1000px) { .bulk { top: 62px; } }
.cat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cat-card {
  display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 11px 13px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; box-shadow: var(--shadow);
}
.cat-card span { font-size: 13px; color: var(--text-2); }
.cat-card b { font-size: 16px; font-variant-numeric: tabular-nums; }
.cat-card small { color: var(--text-2); font-size: 12px; }
.cat-card.on { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent); }

/* period */
.period { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 2px; flex-wrap: wrap; }
.period .icon-btn { width: 36px; height: 36px; }
.period-label { position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; font-weight: 600; font-size: 14.5px; cursor: pointer; white-space: nowrap; }
.period-label select { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.period-custom { display: inline-flex; align-items: center; gap: 4px; padding: 0 4px; }
.period-custom input { min-height: 34px; padding: 4px 6px; width: 140px; }

/* ------------------------------------------------------------------ dashboard */
.big-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.big-act {
  display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow); transition: transform 0.1s;
}
.big-act:active { transform: scale(0.98); }
.big-act .ico { width: 34px; height: 34px; padding: 6px; border-radius: 10px; flex: none; }
.big-act span { display: flex; flex-direction: column; min-width: 0; }
.big-act b { font-size: 15.5px; }
.big-act small { color: var(--text-2); font-size: 12.5px; }
.a-job .ico { background: color-mix(in srgb, var(--s1) 16%, transparent); color: var(--s1); }
.a-exp .ico { background: color-mix(in srgb, var(--s2) 16%, transparent); color: var(--s2); }
.a-bill .ico { background: var(--good-soft); color: var(--good-text); }
@media (max-width: 640px) {
  .big-actions { grid-template-columns: 1fr 1fr; gap: 8px; }
  .big-act { flex-direction: column; align-items: flex-start; padding: 12px; gap: 8px; }
  .big-act.a-bill { grid-column: 1 / -1; flex-direction: row; align-items: center; }
  .big-act small { display: none; }
}
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); flex-wrap: wrap; }
.alert > span { flex: 1 1 200px; font-size: 14px; }
.alert.a-info { background: var(--primary-soft); }
.alert.a-info > .ico { color: var(--primary); }
.alert.a-warn { background: var(--warn-soft); }
.alert.a-warn > .ico { color: var(--warn-text); }
.alert.a-crit { background: var(--crit-soft); }
.alert.a-crit > .ico { color: var(--crit-text); }
/* hero takes a 2×2 block on the left, four tiles fill the 2×2 block on the right */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); min-width: 0;
}
a.kpi:hover { border-color: var(--primary); }
.kpi small { color: var(--text-2); font-size: 13px; }
.kpi b { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.kpi.hero { grid-column: span 2; grid-row: span 2; justify-content: center; background: linear-gradient(135deg, var(--primary-soft), var(--surface)); }
@media (max-width: 1100px) and (min-width: 641px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi.hero { grid-row: auto; } }
.hero-num { font-size: 44px !important; line-height: 1.15; font-weight: 700 !important; letter-spacing: -0.01em; }
.hero-num span { font-size: 22px; color: var(--text-2); font-weight: 500; }
.kpi.hero.is-neg .hero-num { color: var(--crit-text); }
@media (max-width: 640px) { .kpi.hero { grid-column: 1 / -1; grid-row: auto; } .hero-num { font-size: 36px !important; } .kpis { grid-template-columns: 1fr 1fr; gap: 8px; } .kpi b { font-size: 16.5px; } }
.delta { font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.delta small { font-weight: 400; color: var(--text-2); }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--crit-text); }
.delta.flat { color: var(--text-2); }
.insights { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.insights li { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.insights .i-good .ico { color: var(--good-text); }
.insights .i-bad .ico { color: var(--crit-text); }
.insights .i-info .ico { color: var(--primary); }
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.recent li:last-child { border-bottom: 0; }
.r-ic { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; flex: none; }
.r-job, .r-income { background: color-mix(in srgb, var(--s1) 15%, transparent); color: var(--s1); }
.r-expense { background: color-mix(in srgb, var(--s2) 15%, transparent); color: var(--s2); }
.r-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.r-main b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-main small { color: var(--text-2); }
.r-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.link-more { display: inline-flex; gap: 6px; align-items: center; margin-top: 10px; font-size: 13.5px; }
.budget-list { display: flex; flex-direction: column; gap: 8px; }
.budget-row { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr auto; gap: 10px; align-items: center; font-size: 14px; }

/* ------------------------------------------------------------------ charts */
.chart { width: 100%; min-height: 230px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-2); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .bar.s1 { fill: var(--s1); }
.chart .bar.s2 { fill: var(--s2); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit.is-hover { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin: 6px 0 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.sw.s1 { background: var(--s1); }
.sw.s2 { background: var(--s2); }
.seg-mini { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.seg-mini button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; font: inherit; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.seg-mini button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(70px, 34%) 1fr; gap: 10px; align-items: center; padding: 2px 4px; border-radius: 8px; }
.hbar.is-hover { background: var(--surface-2); }
.hbar-label { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-label small { color: var(--text-3); margin-left: 4px; }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill { height: 14px; border-radius: 0 4px 4px 0; flex: none; max-width: calc(100% - 56px); }
.hbar-fill.s1 { background: var(--s1); }
.hbar-fill.s2 { background: var(--s2); }
.hbar-val { font-size: 12.5px; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter { display: flex; align-items: center; gap: 8px; min-width: 0; }
.meter-track { flex: 1; height: 8px; border-radius: 999px; background: var(--meter-track); overflow: hidden; min-width: 50px; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--s1); }
.m-warn .meter-fill { background: var(--warn); }
.m-crit .meter-fill { background: var(--crit); }
.meter-pct { font-size: 12px; font-weight: 600; display: inline-flex; gap: 3px; align-items: center; font-variant-numeric: tabular-nums; }
.m-warn .meter-pct { color: var(--warn-text); }
.m-crit .meter-pct { color: var(--crit-text); }

/* ------------------------------------------------------------------ invoices */
.inv-jobs { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface-2); }
.inv-jobs:empty { display: none; }
.inv-jobs-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 330px; overflow-y: auto; }
.pick {
  display: grid; grid-template-columns: auto auto 1fr auto; gap: 10px; align-items: center; padding: 9px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.pick:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.pick-date { font-size: 13px; color: var(--text-2); white-space: nowrap; }
.pick-main { min-width: 0; display: flex; flex-direction: column; }
.pick-main small { color: var(--text-2); font-size: 12px; }
.pick-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-row { display: grid; grid-template-columns: 2fr 70px 1fr auto; gap: 8px; margin-bottom: 8px; }
.line-row .money-field input { padding-right: 10px; }
.inv-layout { margin-bottom: 14px; }
.pay-list { list-style: none; margin: 0; padding: 0; }
.pay-list li { display: grid; grid-template-columns: 100px 90px 1fr auto auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.pay-list li:last-child { border: 0; }
.doc-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.doc-wrap { background: var(--surface-3); border-radius: var(--radius); padding: 18px; overflow-x: auto; margin-bottom: 16px; }

/* printable A4 document — always light, independent of the app theme */
.doc {
  position: relative; color-scheme: light; background: #fff; color: #1a1a1a; width: 100%; max-width: 210mm; min-height: 270mm; margin: 0 auto;
  padding: 14mm 13mm; box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12); font-size: 13px; line-height: 1.5; --doc-accent: #1b64be;
}
.doc-head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 14px; border-bottom: 2px solid var(--doc-accent); }
.doc-biz { display: flex; gap: 12px; align-items: flex-start; }
.doc-logo { width: 72px; height: 72px; object-fit: contain; }
.doc-biz h2 { font-size: 19px; margin-bottom: 2px; }
.doc-biz p { margin: 0; color: #444; font-size: 12.5px; }
.doc-title { text-align: right; }
.doc-title h1 { font-size: 24px; display: block; color: var(--doc-accent); }
.doc-en { font-size: 12px; letter-spacing: 0.25em; color: #777; margin-bottom: 6px; }
.doc-meta { margin-left: auto; border-collapse: collapse; font-size: 13px; }
.doc-meta th { text-align: left; font-weight: 500; color: #666; padding: 1px 12px 1px 0; }
.doc-meta td { text-align: right; font-weight: 600; }
.doc-parties { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; }
.doc-parties small { display: block; color: #777; font-size: 11.5px; }
.doc-parties b { font-size: 15px; }
.doc-period { text-align: right; }
.doc-items { width: 100%; border-collapse: collapse; margin-top: 4px; }
.doc-items th { background: #eef3fb; color: #333; font-weight: 600; font-size: 12px; padding: 7px 6px; text-align: left; border-bottom: 1px solid #c9d6ea; }
.doc-items td { padding: 7px 6px; border-bottom: 1px solid #e5e5e5; vertical-align: top; font-size: 12.5px; }
.doc-items .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-items .c-no { width: 38px; text-align: center; white-space: nowrap; }
.doc-items .c-date { width: 82px; white-space: nowrap; }
.doc-sub { color: #666; font-size: 11.5px; }
.doc-bottom { display: flex; justify-content: space-between; gap: 20px; margin-top: 12px; align-items: flex-start; }
.doc-left { flex: 1; min-width: 0; }
.doc-words { font-weight: 600; background: #f4f6f9; padding: 7px 10px; border-radius: 6px; margin-bottom: 10px; }
.doc-bank small, .doc-note small { display: block; color: #777; font-size: 11.5px; }
.doc-bank pre { margin: 0; font: inherit; white-space: pre-wrap; }
.doc-note { margin-top: 8px; }
.doc-totals { border-collapse: collapse; min-width: 250px; font-variant-numeric: tabular-nums; }
.doc-totals th { text-align: left; font-weight: 500; color: #555; padding: 4px 14px 4px 0; }
.doc-totals td { text-align: right; padding: 4px 0; white-space: nowrap; }
.doc-totals .grand th, .doc-totals .grand td { font-size: 15px; font-weight: 700; color: #111; border-top: 2px solid #222; padding-top: 7px; }
.doc-totals .due td { color: #c02a2b; font-weight: 700; }
.doc-pay { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 12.5px; }
.doc-pay th { text-align: left; background: #f4f6f9; padding: 6px; font-weight: 600; }
.doc-pay td { padding: 6px; border-bottom: 1px solid #eee; }
.doc-pay .num { text-align: right; }
.doc-received { text-align: center; margin-top: 10px; font-weight: 600; }
.doc-sign { display: flex; justify-content: space-around; gap: 40px; margin-top: 50px; text-align: center; }
.doc-sign > div { flex: 0 1 220px; display: flex; flex-direction: column; gap: 3px; }
.sig-line { border-bottom: 1px dotted #555; height: 40px; }
.doc-sign small { color: #777; font-size: 11px; }
.doc-foot { margin-top: 24px; text-align: center; color: #555; font-size: 12px; border-top: 1px solid #eee; padding-top: 8px; }
.doc-stamp {
  position: absolute; top: 46%; left: 50%; transform: translate(-50%, -50%) rotate(-16deg); font-size: 64px; font-weight: 800;
  padding: 4px 26px; border: 6px solid; border-radius: 14px; opacity: 0.14; pointer-events: none; white-space: nowrap;
}
.doc-stamp.paid { color: #0a8a1f; }
.doc-stamp.void { color: #c02a2b; }
.placeholder { color: #bbb; font-weight: 400; font-size: 14px; }
/* On small screens the bill keeps its real A4 layout and is scaled down to fit (zoom set in invoice-view.js),
   so the owner sees exactly what will be printed / sent. */
@media (max-width: 860px) {
  .doc-wrap { padding: 6px; }
  .doc { width: 210mm; max-width: none; min-height: 0; }
}

/* ------------------------------------------------------------------ collection countdown */
.cd { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.cd-over { background: var(--crit-soft); color: var(--crit-text); }
.cd-today { background: var(--crit); color: #fff; }
.cd-soon { background: var(--warn-soft); color: var(--warn-text); }
.cd-later { background: var(--surface-3); color: var(--text-2); }
.col-list { display: flex; flex-direction: column; gap: 10px; }
.col-group { margin: 18px 0 20px; }
[data-unbilled] .alert { margin-bottom: 6px; }
.col-group h3 .count { background: var(--surface-3); border-radius: 999px; padding: 0 9px; font-size: 13px; }
.col-card {
  display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: center; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-left: 5px solid var(--axis); border-radius: var(--radius); box-shadow: var(--shadow);
}
.col-card.c-over { border-left-color: var(--crit); }
.col-card.c-today { border-left-color: var(--crit); background: color-mix(in srgb, var(--crit) 6%, var(--surface)); }
.col-card.c-soon { border-left-color: var(--warn); }
.col-count { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 66px; border-radius: 12px; background: var(--surface-2); }
.col-count b { font-size: 30px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.col-count small { font-size: 12px; color: var(--text-2); }
.c-over .col-count { background: var(--crit-soft); color: var(--crit-text); }
.c-today .col-count { background: var(--crit); color: #fff; }
.c-today .col-count small { color: #fff; }
.c-soon .col-count { background: var(--warn-soft); color: var(--warn-text); }
.col-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; align-items: flex-start; }
.col-main > b { font-size: 15.5px; }
.col-main small { color: var(--text-2); }
.col-amt { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.col-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 700px) {
  .col-card { grid-template-columns: 64px 1fr; }
  .col-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
.col-dash { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--crit); color: #fff;
  font-size: 11.5px; font-style: normal; font-weight: 700; display: inline-grid; place-items: center; line-height: 1;
}
.bottombar a.has-badge { position: relative; }
.bottombar .nav-badge { position: absolute; top: 2px; left: 50%; margin-left: 4px; }
.tb-split { color: var(--text-2); font-weight: 600; }

/* multi-select chips (checkbox inside) */
.check-chip input { display: none; }
.check-chip:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.check-chip:has(input:checked) small { color: rgba(255, 255, 255, 0.8); }

/* price rate card */
.rate-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px; margin-bottom: 16px; }
.rate-cards .card { margin: 0; }
@media (max-width: 560px) { .rate-cards { grid-template-columns: 1fr; } }
.rtable tr.rate-old td { opacity: 0.55; }
.rtable tr.rate-current td { background: color-mix(in srgb, var(--good) 8%, transparent); }

/* ------------------------------------------------------------------ timesheet editor */
.ts-editor { display: flex; flex-direction: column; gap: 10px; }
.ts-rows { display: flex; flex-direction: column; gap: 8px; }
.ts-row {
  display: grid; grid-template-columns: 140px repeat(3, minmax(150px, 1fr)) 64px 72px; gap: 6px 10px; align-items: end;
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.ts-row.bad { border-color: var(--crit); background: var(--crit-soft); }
.ts-row input { min-height: 36px; padding: 4px 6px; font-size: 14px; }
.ts-seg { display: grid; grid-template-columns: 1fr auto 1fr; gap: 3px; align-items: center; }
.ts-seg small, .ts-tot small, .ts-ot small { grid-column: 1 / -1; color: var(--text-2); font-size: 12px; }
.ts-tot { display: flex; flex-direction: column; }
.ts-tot b { font-size: 17px; font-variant-numeric: tabular-nums; }
.ts-ot { display: flex; flex-direction: column; }
.ts-sup { grid-column: 1 / 3; }
.ts-note { grid-column: 3 / 5; }
.ts-act { grid-column: 5 / -1; display: flex; gap: 4px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.ts-foot { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
@media (max-width: 760px) {
  .ts-row { grid-template-columns: 1fr 1fr; }
  .ts-date { grid-column: 1 / -1; }
  .ts-seg { grid-column: 1 / -1; }
  .ts-sup, .ts-note, .ts-act { grid-column: 1 / -1; }
  .ts-act { justify-content: flex-start; }
}
.wt-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.wt-row input { width: auto; min-height: 36px; }

/* ------------------------------------------------------------------ photo evidence & map */
.ev-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.ev-bar select { width: auto; min-height: 36px; }
.ev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.ev-thumb {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2);
  padding: 0; cursor: pointer; display: grid; place-items: center;
}
.ev-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ev-thumb small { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 11px; padding: 2px 6px; text-align: left; }
.ev-thumb.pending { opacity: 0.6; outline: 2px dashed var(--primary); }
.ev-pdf { font-weight: 800; color: var(--crit-text); }
.lightbox img { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 10px; background: #000; }
.ev-meta { list-style: none; padding: 0; margin: 10px 0; }
.ev-meta li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.geo-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.geo-bar input { flex: 1 1 220px; min-height: 36px; }
.map-box { width: 100%; height: 240px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.map-box.tall { height: 420px; }
.map-box iframe { width: 100%; height: 100%; border: 0; }
.map-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.map-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 560px; overflow: auto; }
.map-list button { width: 100%; text-align: left; display: flex; flex-direction: column; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.map-list button.on { border-color: var(--primary); background: var(--primary-soft); }
.map-list small { color: var(--text-2); }
@media (max-width: 860px) { .map-layout { grid-template-columns: 1fr; } .map-box.tall { height: 320px; } }
.rtable .main-cell .work { color: var(--primary); font-weight: 500; }
.row-icons { display: inline-flex; gap: 8px; margin-top: 2px; }
.row-icons i, .row-icons a { font-style: normal; font-size: 12px; color: var(--text-2); display: inline-flex; gap: 3px; align-items: center; }

/* printable timesheet & evidence pages */
.docs { display: flex; flex-direction: column; gap: 18px; }
.ts-doc { font-size: 12px; }
.ts-head { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid var(--doc-accent); padding-bottom: 10px; }
.ts-biz { flex: 1; }
.ts-biz h2 { font-size: 17px; margin: 0; }
.ts-biz p { margin: 0; color: #555; }
.ts-title { text-align: right; }
.ts-title h1 { display: block; font-size: 20px; color: var(--doc-accent); }
.ts-info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 16px; padding: 10px 0; }
.ts-info small { display: block; color: #777; font-size: 11px; }
.ts-info .wide { grid-column: 1 / -1; }
.ts-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.ts-table th, .ts-table td { border: 1px solid #bbb; padding: 4px 5px; text-align: center; }
.ts-table th { background: #f6d36b; color: #222; font-weight: 600; }
.ts-table td:nth-last-child(-n+2) { text-align: left; }
.ts-table tfoot td { background: #f4f6f9; font-weight: 600; }
.doc-sign.three > div { flex: 0 1 180px; }
.ev-doc h3 { margin: 0 0 10px; font-size: 15px; }
.ev-doc figure { margin: 0 0 14px; text-align: center; }
.ev-doc img { max-width: 100%; max-height: 118mm; object-fit: contain; border: 1px solid #ddd; }
.ev-doc figcaption { font-size: 11.5px; color: #444; margin-top: 4px; }

/* ------------------------------------------------------------------ history */
.history { list-style: none; margin: 0; padding: 0; }
.history > li { position: relative; padding: 8px 0 10px 18px; border-left: 2px solid var(--border); margin-left: 6px; }
.history > li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); border: 2px solid var(--surface); }
.history > li.h-create::before, .history > li.h-pay::before { background: var(--good); }
.history > li.h-update::before { background: var(--s1); }
.history > li.h-delete::before, .history > li.h-void::before, .history > li.h-unpay::before { background: var(--crit); }
.h-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.h-act { font-weight: 600; }
.h-head time { color: var(--text-2); font-size: 12.5px; white-space: nowrap; }
.h-sum { font-size: 13.5px; }
.h-changes { list-style: none; padding: 4px 0 0; margin: 0; font-size: 13px; }
.h-changes s { color: var(--text-3); }
.h-changes span { color: var(--text); font-weight: 500; }
.h-dev { font-size: 12px; color: var(--text-3); }
.history-block { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
.history-block summary { cursor: pointer; color: var(--text-2); font-size: 13.5px; display: inline-flex; gap: 6px; align-items: center; }
.history-block .hb-body { margin-top: 10px; }

/* ------------------------------------------------------------------ settings */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.settings > .card { margin-bottom: 0; }
.settings > form[data-settings] { grid-row: span 3; }
@media (max-width: 980px) { .settings { grid-template-columns: 1fr; } .settings > form[data-settings] { grid-row: auto; } }
.logo-row { display: flex; gap: 14px; align-items: center; }
.logo-box { width: 72px; height: 72px; border-radius: 14px; border: 1px dashed var(--border-strong); display: grid; place-items: center; overflow: hidden; color: var(--text-3); background: var(--surface-2); }
.logo-box img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.logo-row > div:last-child { display: flex; gap: 6px; flex-wrap: wrap; }
.cur-grid { display: flex; flex-direction: column; gap: 8px; }
.cur-item { display: grid; grid-template-columns: 160px 1fr; gap: 10px; align-items: center; }
.rate-in { display: flex; align-items: center; gap: 6px; }
.rate-in small { color: var(--text-2); white-space: nowrap; }
.rate-in .money-field input { padding-right: 10px; min-height: 38px; }
.backup-list { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.backup-list li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); }
.stat-list { list-style: none; padding: 0; margin: 0 0 8px; }
.stat-list li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.map-grid .field > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[data-import] .table-wrap { margin: 8px 0 12px; max-height: 340px; overflow: auto; }
@media (max-width: 520px) { .cur-item { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ auth, empty, loading */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 30% 20%, var(--primary-soft), var(--bg) 60%); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 22px; padding: 26px 24px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.auth-card .field { text-align: left; }
.auth-card h1 { justify-content: center; font-size: 21px; }
.auth-top { display: flex; justify-content: flex-end; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 10px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty .ico.big { color: var(--text-3); }
.empty.error { color: var(--crit-text); border-color: var(--crit); }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--text-2); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--text-2); }

/* ------------------------------------------------------------------ print */
@media print {
  @page { size: A4; margin: 9mm; }
  body { background: #fff !important; color: #000; font-size: 12px; }
  .sidebar, .topbar, .bottombar, .fab, .fab-desk, .no-print, .head-actions, .drawer-backdrop, #toasts, #tooltip,
  .period button, .period select, .seg-mini, .history-block, .search { display: none !important; }
  .main-col { margin: 0 !important; }
  #view { padding: 0 !important; max-width: none; }
  .doc-wrap { padding: 0; background: none; margin: 0; overflow: visible; }
  .doc { box-shadow: none; max-width: none; width: auto; min-height: 0; padding: 0; zoom: 1 !important; }
  .docs { display: block; }
  .docs > .doc + .doc { break-before: page; page-break-before: always; }
  .ev-doc figure { break-inside: avoid; }
  .card, .kpi, .table-wrap { box-shadow: none !important; break-inside: avoid; }
  .kpi.hero { background: none; }
  a { color: inherit; }
}
