/* Layout: one column. Login → employees see the entry form and their own records; managers get tabs — journal, analytics, reference lists and access */
:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --sunken: #eaeee9;
  --ink: #18201c;
  --muted: #5f6b65;
  --line: #d9dfd9;
  --accent: #23477a;
  --accent-ink: #ffffff;
  --in: #1d7348;
  --in-soft: #e1f1e7;
  --out: #ad3b28;
  --out-soft: #f8e5e0;
  --plan: #8a6a12;
  --plan-soft: #f6efd9;
  --focus: #23477a55;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111513; --surface: #191e1b; --sunken: #141816; --ink: #e5eae6; --muted: #98a39d;
    --line: #2a312d; --accent: #8db0e8; --accent-ink: #0e1a2c; --in: #62c591; --in-soft: #183325;
    --out: #f18a73; --out-soft: #3a1f19; --plan: #e3c063; --plan-soft: #33290f; --focus: #8db0e866;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111513; --surface: #191e1b; --sunken: #141816; --ink: #e5eae6; --muted: #98a39d;
  --line: #2a312d; --accent: #8db0e8; --accent-ink: #0e1a2c; --in: #62c591; --in-soft: #183325;
  --out: #f18a73; --out-soft: #3a1f19; --plan: #e3c063; --plan-soft: #33290f; --focus: #8db0e866;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 15px; line-height: 1.45; }
.wrap {
  max-width: 1080px; margin: 0 auto;
  padding-block: max(28px, env(safe-area-inset-top, 0px)) max(64px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 20px;
}
.view { display: grid; gap: 20px; min-width: 0; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.role { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: var(--sunken); color: var(--muted); }

/* Tabs + period */
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.tabs { display: inline-flex; gap: 2px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 14px 10px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { font-family: var(--font-num); font-size: 12px; margin-left: 4px; padding: 1px 6px; border-radius: 999px; background: var(--plan-soft); color: var(--plan); }
.period { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; font-size: 16px; }
.icon-btn:hover { border-color: var(--muted); }
.period-label { min-width: 132px; text-align: center; font-weight: 600; }
.chip-btn { height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; white-space: nowrap; }
.chip-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.sum { padding: 14px 18px; display: grid; gap: 2px; min-width: 0; }
.sum + .sum { border-left: 1px solid var(--line); }
.sum-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.sum-value { font-size: 22px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-note { font-size: 12.5px; color: var(--muted); min-height: 1.2em; }
.sum.in .sum-value { color: var(--in); }
.sum.out .sum-value { color: var(--out); }

/* Entry form */
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 14px; }
.entry.editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.entry-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.entry-title { margin: 0; font-size: 16px; font-weight: 600; }
.entry-meta { font-size: 13px; color: var(--muted); }
.row1 { display: grid; grid-template-columns: auto minmax(0, 1fr) 170px; gap: 12px; align-items: end; }
.row2 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.row2.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row3 { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: end; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label, .field .lbl { font-size: 12.5px; color: var(--muted); }
.field input, .field select { width: 100%; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.field select { padding-right: 28px; }
.field input:hover, .field select:hover { border-color: var(--muted); }
.field input:focus, .field select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--focus); }
.amount-input { font-family: var(--font-num); font-size: 22px !important; height: 48px !important; font-weight: 600; }
.entry[data-kind="in"] .amount-input { color: var(--in); }
.entry[data-kind="out"] .amount-input { color: var(--out); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--bg); height: 48px; }
.seg button { border: 0; background: transparent; padding: 0 14px; border-radius: 7px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"][data-kind="in"] { background: var(--in-soft); color: var(--in); }
.seg button[aria-pressed="true"][data-kind="out"] { background: var(--out-soft); color: var(--out); }
.seg.small { height: 40px; }
.seg.small button { padding: 0 12px; font-weight: 500; font-size: 14px; }
.seg.small button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.seg.small button[aria-pressed="true"][data-plan="1"] { background: var(--plan-soft); color: var(--plan); box-shadow: none; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { height: 40px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--out); }
.btn.danger.armed { background: var(--out); border-color: var(--out); color: var(--surface); }
.btn:disabled { opacity: .55; cursor: default; }
.form-error { color: var(--out); font-size: 13.5px; }
.notice { padding: 14px 16px; border-radius: 10px; background: var(--sunken); color: var(--muted); font-size: 14px; }

/* Journal */
.journal { display: grid; gap: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search, .tools select { height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.search { width: 240px; max-width: 100%; }
.search:focus, .tools select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--focus); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.day { display: flex; justify-content: space-between; gap: 12px; padding: 9px 18px; background: var(--sunken); font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
.day:first-child { border-top: 0; }
.day strong { color: var(--ink); font-weight: 600; }
.op { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; align-items: stretch; border-top: 1px solid var(--line); }
.day + .op { border-top: 0; }
.op .bar-mark { border-radius: 0 3px 3px 0; margin-block: 8px; }
.op.in .bar-mark { background: var(--in); }
.op.out .bar-mark { background: var(--out); }
.op-open { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1.2fr) auto; gap: 4px 16px; align-items: center; padding: 11px 16px 11px 14px; border: 0; background: transparent; text-align: left; width: 100%; min-width: 0; }
.op-open:disabled { cursor: default; }
.op:hover { background: var(--bg); }
.op.selected { background: var(--bg); box-shadow: inset 0 0 0 2px var(--accent); }
.op-main { min-width: 0; }
.op-cat { font-weight: 600; overflow-wrap: anywhere; }
.op-desc { display: block; font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.tag { font-size: 12.5px; padding: 2px 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tag.plan { background: var(--plan-soft); color: var(--plan); font-weight: 600; }
.tag.example { border: 1px dashed var(--muted); background: transparent; }
.tag.person { background: transparent; border: 1px solid var(--line); }
.tag.ok { background: var(--in-soft); color: var(--in); }
.op-sum { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 16px; text-align: right; white-space: nowrap; }
.op.in .op-sum { color: var(--in); }
.op.out .op-sum { color: var(--out); }
.op.planned .op-sum { opacity: .7; text-decoration: underline dotted; text-underline-offset: 4px; }
.check { align-self: center; margin-right: 12px; width: 34px; height: 34px; border-radius: 8px; border: 1px dashed var(--muted); background: transparent; color: var(--muted); font-size: 15px; display: grid; place-items: center; }
.check[aria-pressed="true"] { border: 1px solid var(--in); background: var(--in-soft); color: var(--in); }
.check:hover { border-style: solid; }

.empty { padding: 36px 24px; text-align: center; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty strong { color: var(--ink); font-size: 16px; }
.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }

/* Analytics */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 14px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.sw-in { background: var(--in); }
.sw-out { background: repeating-linear-gradient(135deg, var(--out) 0 3px, color-mix(in srgb, var(--out) 70%, var(--surface)) 3px 5px); }

.chart-scroll { overflow-x: auto; }
.chart { position: relative; min-width: 560px; height: 250px; padding-top: 10px; display: grid; grid-template-columns: 56px minmax(0, 1fr); }
.yaxis { position: relative; font-size: 11.5px; color: var(--muted); }
.yaxis span { position: absolute; right: 8px; transform: translateY(50%); font-family: var(--font-num); }
.plot { position: relative; border-bottom: 1px solid var(--muted); display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); height: 210px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); pointer-events: none; }
.mcol { position: relative; border: 0; background: transparent; padding: 0 4px; display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; border-radius: 6px 6px 0 0; }
.mcol:hover, .mcol:focus-visible { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.mcol.current { background: color-mix(in srgb, var(--accent) 11%, transparent); }
.mbar { width: min(18px, 40%); border-radius: 4px 4px 0 0; min-height: 0; }
.mbar.in { background: var(--in); }
.mbar.out { background: repeating-linear-gradient(135deg, var(--out) 0 3px, color-mix(in srgb, var(--out) 70%, var(--surface)) 3px 5px); }
.mlabel { position: absolute; bottom: -22px; left: 0; right: 0; text-align: center; font-size: 11.5px; color: var(--muted); }
.mcol.current .mlabel { color: var(--ink); font-weight: 600; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -100%); }
.tip b { font-weight: 600; }

.struct { display: grid; gap: 8px; }
.srow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; }
.sname { font-size: 14px; overflow-wrap: anywhere; }
.sval { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 13.5px; text-align: right; white-space: nowrap; }
.sval small { color: var(--muted); margin-left: 6px; }
.strack { grid-column: 1 / -1; height: 8px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.sfill { height: 100%; border-radius: 0 4px 4px 0; }
.sfill.in { background: var(--in); }
.sfill.out { background: var(--out); }

.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 500; }
td.n, th.n { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.pos { color: var(--in); } .neg { color: var(--out); }
.late { color: var(--out); font-weight: 600; }

/* Reference lists */
.dict { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 10px; border-radius: 999px; background: var(--sunken); font-size: 14px; }
.chip button { border: 0; background: none; width: 22px; height: 22px; border-radius: 50%; color: var(--muted); }
.chip button:hover { background: var(--line); color: var(--ink); }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.add-row .btn { height: 36px; padding: 0 12px; }
.save-bar { display: flex; gap: 12px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.save-bar span { color: var(--muted); font-size: 13.5px; }
.people { display: grid; gap: 6px; }
.person { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.person:last-child { border-bottom: 0; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0; max-width: 70ch; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }

@media (max-width: 820px) {
  .row2, .row2.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .op-open { grid-template-columns: minmax(0, 1fr) auto; }
  .op-open .tags { grid-column: 1 / -1; grid-row: 2; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .wrap { padding-block: 18px 48px; gap: 16px; }
  h1 { font-size: 22px; }
  .row1 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .row1 .seg { grid-column: 1 / -1; }
  .row1 .seg button { flex: 1; }
  .row2, .row2.three { grid-template-columns: minmax(0, 1fr); }
  .row3 { grid-template-columns: minmax(0, 1fr); }
  .row3 .actions .btn { flex: 1; }
  .summary { grid-template-columns: minmax(0, 1fr); }
  .sum + .sum { border-left: 0; border-top: 1px solid var(--line); }
  .sum { grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; padding: 10px 14px; }
  .sum-note { grid-column: 1 / -1; }
  .sum-value { font-size: 18px; }
  .search, .tools select { width: 100%; }
  .tools { width: 100%; }
  .entry, .panel { padding: 14px; }
  .day { padding: 8px 14px; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* Standalone app additions: login, account, people */
.chip-btn.tall { height: 40px; }
.chart-scroll + .tbl-wrap { margin-top: 8px; }
.login { display: grid; justify-items: center; padding-block: 24px; }
.login form { width: min(380px, 100%); }
.login h2 { font-size: 20px; }
.login .btn { height: 44px; }
.account { gap: 12px; }
.pw-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.add-user { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: end; padding-top: 4px; }
.secret { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: center; padding: 14px 16px; border-radius: 10px; background: var(--in-soft); }
.secret .num { font-size: 16px; margin-top: 4px; user-select: all; }
.secret .hint { margin-top: 4px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions .btn { height: 32px; padding: 0 10px; font-size: 13.5px; }
td select { height: 32px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); padding: 0 6px; }
.muted-row td { color: var(--muted); }
@media (max-width: 820px) {
  .pw-form, .add-user { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .pw-form, .add-user { grid-template-columns: minmax(0, 1fr); }
}
