:root {
  --ink: #17181C; --ink-2: #24262C; --bg: #F4F3EF; --card: #FFFFFF; --line: #E4E2DC; --line-2: #EEECE6;
  --muted: #5E6168; --red: #C4212B; --red-d: #A51B24; --in: #136B43; --in-bg: #E3F2EA; --out: #B3261E; --out-bg: #FBE5E3;
  --warn: #6B3F00; --warn-bg: #FFF1DC; --amber: #FFC46B; --radius: 14px;
  --tabbar-h: 68px;
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink); background: var(--bg);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: inherit; }
h1 { font-size: 20px; margin: 0; font-weight: 800; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 800; }
h2.section { margin: 22px 0 10px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { display: grid; place-items: center; min-height: 40vh; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.in { color: var(--in); } .out { color: var(--out); }
.stack { display: grid; gap: 10px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* ---------- layout ---------- */
.layout { min-height: 100vh; }
.side { display: none; }
.main { min-width: 0; padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.page { padding: 14px 16px; display: grid; gap: 12px; max-width: 1100px; }
.page > * { min-width: 0; }

/* dark header */
.dhead { background: var(--ink); color: #fff; padding: calc(14px + env(safe-area-inset-top)) 16px 14px; border-radius: 0 0 22px 22px; }
.dhead-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.dhead-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dhead-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dhead-title span { color: #B8BBC2; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-head .dhead-title h1 { font-size: 22px; }
.head-logo { width: 40px; height: 40px; border-radius: 10px; background: #fff; object-fit: contain; padding: 2px; }
.icon-btn { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 12px; background: rgba(255,255,255,.1); color: #fff; border: 0; cursor: pointer; text-decoration: none; font: inherit; font-weight: 800; }
.icon-btn.light { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.lhead { display: flex; align-items: center; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 16px 4px; }

.stats3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 14px; }
.stat { background: var(--ink-2); border: 1px solid #34363D; border-radius: 12px; padding: 10px 12px; text-decoration: none; color: #fff; display: flex; flex-direction: column-reverse; gap: 2px; min-width: 0; }
.stats3.two .stat { flex-direction: column; }
.stat b { font-size: 18px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat span { color: #B8BBC2; font-size: 12px; font-weight: 600; }
.stat .amber { color: var(--amber); }
.in-l { color: #7DDCA6; } .out-l { color: #FF9C94; }

/* header tabs */
.htabs { display: flex; gap: 4px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.htab { text-decoration: none; color: #B8BBC2; font-weight: 700; font-size: 14px; padding: 9px 14px; border-radius: 10px; white-space: nowrap; min-height: 40px; display: inline-flex; align-items: center; }
.htab.on { background: #fff; color: var(--ink); }

/* bottom tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.tab-btn { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: #7A7D84; font-size: 11px; font-weight: 700; padding: 6px 0; min-height: 52px; justify-content: center; }
.tab-btn.on { color: var(--ink); }
.tab-btn.on svg { stroke-width: 2.4; }
.tab-btn .badge:not(:empty) { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--red); color: #fff; font-style: normal; font-size: 11px; font-weight: 800; border-radius: 9px; padding: 0 6px; min-width: 18px; text-align: center; }
.fab { justify-self: center; width: 58px; height: 58px; margin-top: -26px; border-radius: 50%; border: 4px solid var(--bg); background: var(--red); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 6px 16px rgba(196,33,43,.35); }
.fab:active, .fab-sq:active { transform: scale(.95); }

/* project footer / sticky action bars */
.actionbar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 15; display: flex; gap: 8px; padding: 10px 16px; background: linear-gradient(to top, var(--bg) 70%, rgba(244,243,239,0)); }
.actionbar .btn { flex: 1; }
.fab-sq { width: 52px; height: 52px; flex: none; border-radius: 14px; border: 0; background: var(--ink); color: #fff; display: grid; place-items: center; cursor: pointer; }
.main:has(.actionbar) { padding-bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
a.card { text-decoration: none; display: block; }
a.card:hover { border-color: #B9B6AD; }
.section-head { margin-top: 4px; } .section-head h2 { margin: 0; }
.pcard { display: grid; gap: 12px; }
.pcard .pname { font-size: 16px; display: block; }
.pcard .small { display: block; }
.money3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.money3 > div { display: flex; flex-direction: column; min-width: 0; }
.money3 > div.r { text-align: right; }
.money3 span { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.money3 b { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary .money3 b { font-size: 17px; }
.money3.sub { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.money3.sub b { font-size: 14px; }

.search { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.search input { border: 0; padding: 0; min-height: 44px; outline: none; }

.list-card { padding: 0; overflow: hidden; }
.txrow, .lrow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; border-bottom: 1px solid var(--line-2); min-height: 64px; }
.list-card > :last-child { border-bottom: 0; }
.txrow:hover, .lrow:hover { background: #FAF9F6; }
.txrow.cancelled { opacity: .55; } .txrow.cancelled b { text-decoration: line-through; }
.dbadge { flex: none; width: 52px; text-align: center; border-radius: 10px; background: var(--line-2); padding: 4px 0; display: flex; flex-direction: column; line-height: 1.15; }
.dbadge .dy { font-size: 10px; color: var(--muted); font-weight: 700; }
.dbadge b { font-size: 13px; font-weight: 800; }
.txmid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.txmid > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txtype { font-size: 12px; color: var(--muted); font-weight: 600; }
.txparty, .txmid > b { font-size: 15px; font-weight: 800; }
.txnote { font-size: 12px; color: var(--muted); }
.txright { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; }
.txright b { font-size: 15px; font-weight: 800; white-space: nowrap; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--line-2); display: grid; place-items: center; font-style: normal; font-weight: 800; font-size: 14px; color: var(--ink); }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; background: var(--ink); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; }
.big-who > div { display: flex; flex-direction: column; }
.big-who b { font-size: 18px; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip-link { flex: none; text-decoration: none; padding: 0 14px; min-height: 36px; display: inline-flex; align-items: center; border-radius: 18px; border: 1px solid #D6D3CB; background: #fff; font-weight: 700; font-size: 13px; }
.chip-link.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }

/* ---------- buttons ---------- */
.btn { font: inherit; font-weight: 800; font-size: 14px; border-radius: 12px; padding: 0 16px; min-height: 44px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-lg { min-height: 52px; font-size: 15px; }
.btn-sm { min-height: 36px; font-size: 13px; padding: 0 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-in { background: var(--in); color: #fff; }
.btn-out { background: var(--out); color: #fff; }
.btn-out-soft { background: var(--out-bg); color: var(--out); border-color: #F2C3BF; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: #D6D3CB; }
.cancel-btn { color: var(--out); }

/* ---------- pills / notes ---------- */
.pill { display: inline-block; font-size: 11px; font-weight: 800; border-radius: 8px; padding: 2px 8px; white-space: nowrap; background: var(--line-2); color: #3D4047; text-transform: capitalize; }
.pill-pending { background: var(--warn-bg); color: var(--warn); }
.pill-approved, .pill-auto_approved { background: var(--in-bg); color: var(--in); }
.pill-rejected { background: var(--out-bg); color: var(--out); }
.pill-cancelled { background: var(--line-2); color: var(--muted); }
.note { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--line-2); font-size: 13px; font-weight: 600; }
.note-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- forms ---------- */
.form { display: grid; gap: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 700; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea { font: inherit; font-size: 15px; color: var(--ink); background: #fff; border: 1px solid #D6D3CB; border-radius: 10px; padding: 0 12px; min-height: 44px; width: 100%; }
select { padding-right: 28px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid #4C8DF6; outline-offset: 2px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions.two { display: grid; grid-template-columns: 1fr 1fr; margin-top: 10px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.with-btn { display: flex; gap: 6px; align-items: center; }
.with-btn select { flex: 1; min-width: 0; }

.entry-form { gap: 12px; }
.type-field select { font-weight: 800; }
.amount-card { padding: 14px 16px; }
.amount-label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.amount-row { display: flex; align-items: center; gap: 6px; }
.amount-row span { font-size: 30px; font-weight: 800; color: var(--muted); }
.amount-row input { border: 0; font-size: 34px; font-weight: 800; padding: 0; min-height: 52px; outline: none; }
.field-card { padding: 0 14px; }
.frow { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; font-weight: 700; color: var(--muted); }
.field-card > :last-child, .field-card > div:last-child > :last-child { border-bottom: 0; }
.frow input, .frow select { border-color: transparent; background: #F7F6F2; }
.modes { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.modes legend { font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; }
.chip span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 20px; border: 1px solid #D6D3CB; background: #fff; font-weight: 700; cursor: pointer; }
.chip input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip input:focus-visible + span { outline: 3px solid #4C8DF6; outline-offset: 2px; }
.photo-btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border: 1.5px dashed #C9C6BE; border-radius: 14px; background: #fff; font-weight: 700; color: var(--muted); cursor: pointer; position: relative; }
.photo-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.savebar { position: sticky; bottom: calc(var(--tabbar-h) + 8px + env(safe-area-inset-bottom)); z-index: 5; padding-top: 4px; }

/* ---------- entry detail ---------- */
.detail .hero { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.detail .hero > div { display: flex; flex-direction: column; }
.detail .big { font-size: 32px; font-weight: 800; line-height: 1.15; }
.detail-list { padding-bottom: 6px; }
.drow { display: grid; grid-template-columns: 30px 110px 1fr; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.drow:last-of-type { border-bottom: 0; }
.dicon { font-style: normal; color: var(--muted); display: grid; place-items: center; }
.dlabel { color: var(--muted); font-size: 13px; font-weight: 700; }
.dval { font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.dval a { text-decoration: none; }
.detail-list .btn { margin-top: 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-2); }

/* ---------- bottom sheet & dialogs ---------- */
.overlay { position: fixed; inset: 0; background: rgba(23,24,28,.5); z-index: 50; display: grid; place-items: center; padding: 16px; }
.sheet-overlay { place-items: end center; padding: 0; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet h2 { margin: 0; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: #C9C6BE; margin: 0 auto 10px; }
.sheet h3.group { font-size: 11px; letter-spacing: .6px; color: var(--muted); margin: 16px 0 8px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 64px; padding: 8px; border-radius: 14px; background: #fff; border: 1px solid var(--line); text-decoration: none; font-weight: 800; font-size: 13px; line-height: 1.2; }
.tile:hover { border-color: #B9B6AD; }
.tile-in { background: var(--in-bg); color: var(--in); border-color: #BFE3CE; }
.tile-out { background: var(--out-bg); color: var(--out); border-color: #F2C3BF; }
.dialog { width: 100%; max-width: 440px; }

/* ---------- tables (ledger, team) ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; letter-spacing: .3px; color: var(--muted); font-weight: 800; padding: 10px 12px; background: #FAF9F6; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
td a { text-decoration: none; font-weight: 700; }
.num { text-align: right; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #FAF9F6; }
tr.total td { font-weight: 800; background: #FAF9F6; border-top: 2px solid var(--line); }
.switch { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; }
.switch input { width: 20px; min-height: 20px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--ink); }
.login-card { width: 100%; max-width: 400px; display: grid; gap: 14px; padding: 24px; border-radius: 20px; }
.login-logo { width: 72px; height: 72px; object-fit: contain; border-radius: 14px; }
.profile { padding: 18px; }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.toast-err { background: var(--out); }
.offline { position: fixed; top: 0; left: 0; right: 0; background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #F2D29E; padding: 10px 16px; font-weight: 700; font-size: 13px; text-align: center; z-index: 70; }

/* ---------- computer: sidebar instead of bottom bar ---------- */
@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 240px 1fr; }
  .side { display: flex; flex-direction: column; gap: 14px; background: var(--ink); color: #fff; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
  .brand { display: flex; gap: 10px; align-items: center; }
  .brand img { border-radius: 8px; background: #fff; object-fit: contain; padding: 2px; }
  .brand div { display: flex; flex-direction: column; } .brand span { font-size: 11px; color: #B8BBC2; }
  .side nav { display: grid; gap: 2px; }
  .nav-link { text-decoration: none; padding: 10px 12px; border-radius: 10px; color: #D5D7DC; font-weight: 700; display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
  .nav-link:hover { background: #24262C; }
  .nav-link.on { background: #fff; color: var(--ink); }
  .nav-count:not(:empty) { background: var(--amber); color: var(--ink); border-radius: 9px; padding: 1px 8px; font-size: 12px; font-weight: 800; }
  .me-mini { margin-top: auto; border-top: 1px solid #34363D; padding-top: 14px; display: flex; flex-direction: column; }
  .me-mini span { font-size: 12px; color: #B8BBC2; }
  .tabbar { display: none; }
  .main { padding-bottom: 32px; }
  .main:has(.actionbar) { padding-bottom: 110px; }
  .dhead { border-radius: 0 0 22px 22px; padding: 18px 24px; }
  .lhead, .page { padding-left: 24px; padding-right: 24px; }
  .actionbar { left: 240px; bottom: 0; max-width: 860px; }
  .savebar { bottom: 12px; }
  .toast { bottom: 24px; }
  .entry-form, .detail, .detail-list { max-width: 640px; }
  .page > .btn-block, .page > .stack { max-width: 640px; }
}

/* ---------- receipt ---------- */
.receipt { background: #fff; border: 1px solid var(--line); padding: 24px; max-width: 800px; font-size: 14px; border-radius: 6px; overflow-x: auto; }
.r-head { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.r-logo { width: 72px; height: auto; }
.r-co { font-size: 13px; }
.r-title h2 { margin: 0 0 6px; font-size: 20px; text-align: right; }
.r-meta th, .r-meta td { padding: 2px 0 2px 12px; border: 0; background: none; font-size: 13px; }
.r-meta th { color: var(--ink); }
.r-parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 18px 0; }
.r-parties div { display: flex; flex-direction: column; } .r-parties span { color: var(--muted); font-size: 12px; }
.r-table { border: 1px solid var(--line); margin: 14px 0; }
.r-table th { width: 40%; background: #fff; color: var(--ink); font-size: 13px; border-right: 1px solid var(--line); }
.r-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-top: 24px; flex-wrap: wrap; }
.r-sign { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-left: auto; }
.r-sign b { border-top: 1px solid var(--ink); padding-top: 6px; min-width: 180px; text-align: center; }
.r-stamp { display: flex; align-items: center; gap: 6px; }
.r-stamp img { height: 72px; width: auto; mix-blend-mode: multiply; }
.r-empty { width: 180px; height: 72px; }
@media (max-width: 560px) {
  .receipt { padding: 16px; font-size: 13px; }
  .r-head { grid-template-columns: auto 1fr; }
  .r-title { grid-column: 1 / -1; } .r-title h2 { text-align: left; }
  .r-logo { width: 56px; }
}
.print-only { display: none; }
.print-head { gap: 16px; align-items: flex-start; margin-bottom: 12px; font-size: 12px; }
.print-head .right { margin-left: auto; text-align: right; }

@media print {
  body { background: #fff; }
  .side, .tabbar, .dhead, .lhead, .actionbar, .print-hide, .toast, .offline, .fab { display: none !important; }
  .main, .page { padding: 0 !important; }
  .print-only { display: flex !important; }
  .card, .receipt { border: 0; padding: 0; }
  tr.clickable:hover td { background: none; }
  a { text-decoration: none; }
}
