:root {
  color-scheme: light;
  --brand: #0b7f74; --brand-dark: #086259; --brand-soft: #dff4f1; --on-brand: #fff;
  --bg: #f0f8f7; --card: #fff; --surface: #fff; --text: #14262a; --muted: #5b6f74; --line: #dbe9e7; --field-line: #bdd3d0;
  --green: #167a4a; --green-soft: #e0f5e9; --amber: #9a5b00; --amber-soft: #fff1d6; --amber-text: #5e3b00; --red: #b3261e; --red-soft: #fde7e5; --red-line: #f0c2be; --grey-soft: #e9f1f0;
  --focus: #7fd6cc; --hover: #f1f8f7; --shadow: 0 1px 2px rgba(10,60,55,.06); --backdrop: rgba(10,30,30,.5); --toast: #14262a;
  --radius: 16px; --pill: 999px; --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #2dd4bf; --brand-dark: #5eead4; --brand-soft: #123a3b; --on-brand: #04201c;
  --bg: #0a1220; --card: #121c2f; --surface: #121c2f; --text: #e6eef8; --muted: #91a2b8; --line: #22304a; --field-line: #33445f;
  --green: #4ade80; --green-soft: #12301f; --amber: #fbbf24; --amber-soft: #3a2b0c; --amber-text: #fde7a8; --red: #ff8a80; --red-soft: #3b1816; --red-line: #6b2a26; --grey-soft: #1a2640;
  --focus: #2dd4bf; --hover: #18243b; --shadow: 0 1px 2px rgba(0,0,0,.4); --backdrop: rgba(0,0,0,.65); --toast: #2dd4bf;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
body.modal-open { overflow: hidden; }
h1 { font-size: 1.55rem; margin: 0; } h2 { font-size: 1.2rem; margin: 0; } h3 { font-size: 1.02rem; margin: 0 0 8px; } h4 { margin: 14px 0 6px; font-size: .95rem; }
a { color: var(--brand); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .grow { flex: 1; min-width: 0; } .right { text-align: right; white-space: nowrap; } .between { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

#app { display: block; min-height: 100vh; }
#side { display: none; }
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
#tabs a, #side nav a { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; font-size: .72rem; color: var(--muted); text-decoration: none; min-height: 56px; }
#tabs a.active, #side nav a.active { color: var(--brand); font-weight: 600; }
.badge { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--red); color: var(--bg); border-radius: 999px; font-size: .68rem; min-width: 18px; padding: 1px 5px; text-align: center; }
main#view { padding: 16px 14px calc(88px + var(--safe-b)); max-width: 860px; margin: 0 auto; }
@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 240px 1fr; }
  #side { display: block; position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; }
  #side .brand { display: flex; flex-direction: column; gap: 8px; padding: 4px 8px 18px; font-size: .95rem; }
  #side .brand img { max-width: 100%; height: auto; max-height: 64px; object-fit: contain; object-position: left; }
  #side nav a { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: .95rem; padding: 10px 12px; border-radius: 10px; min-height: 44px; }
  #side nav a.active { background: var(--brand-soft); border-radius: var(--pill); }
  #side .badge { position: static; margin-left: auto; }
  #tabs { display: none; }
  main#view { padding: 28px 28px 60px; width: 100%; }
}

.page-head { margin-bottom: 12px; } .page-head p { margin: 2px 0 0; }
.back { display: inline-block; margin-bottom: 6px; text-decoration: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); }
details.card > summary { cursor: pointer; list-style: none; } details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h3 { margin: 0; display: flex; justify-content: space-between; } details.card > summary h3::after { content: '▾'; color: var(--muted); } details[open].card > summary h3::after { content: '▴'; }
details.card[open] > summary { margin-bottom: 10px; }
.card.list { padding: 4px 14px; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.note { background: var(--amber-soft); color: var(--amber-text); border-radius: 12px; padding: 8px 12px; margin: 8px 0; font-size: .9rem; }

.btn, button.btn, a.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: var(--pill); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--hover); } .btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); } .btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--red); border-color: var(--red-line); } .btn.small { min-height: 36px; padding: 0 12px; font-size: .88rem; } .btn.icon { min-width: 44px; padding: 0; } .btn.wide { width: 100%; margin-top: 8px; }
.icon-btn { border: 0; background: none; font-size: 1.2rem; min-width: 44px; min-height: 44px; cursor: pointer; color: var(--muted); }
.btnrow { display: flex; gap: 8px; margin: 8px 0 12px; align-items: center; } .btnrow.wrap { flex-wrap: wrap; }
.datebar { display: flex; gap: 8px; margin-bottom: 12px; } .datebar input { flex: 1; }

input, select, textarea { font: inherit; width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--field-line); border-radius: 12px; background: var(--surface); color: var(--text); }
textarea { resize: vertical; } input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; flex: none; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.field { display: block; margin-bottom: 10px; } .field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } @media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-size: .95rem; }
.seg { display: flex; background: var(--grey-soft); border-radius: var(--pill); padding: 3px; margin-bottom: 12px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; min-height: 38px; border-radius: var(--pill); font: inherit; color: var(--muted); cursor: pointer; } .seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.row { display: flex; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); } .row:last-child { border-bottom: 0; }
.row.col { flex-direction: column; align-items: stretch; gap: 6px; } .row.link { color: inherit; text-decoration: none; }
.count { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 1px 9px; font-size: .8rem; margin-left: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: .78rem; font-weight: 600; background: var(--grey-soft); color: var(--muted); }
.chip.done { background: var(--green-soft); color: var(--green); } .chip.due { background: var(--amber-soft); color: var(--amber); } .chip.bad { background: var(--red-soft); color: var(--red); } .chip.info { background: var(--brand-soft); color: var(--brand); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; } .stats b { display: block; font-size: 1.12rem; } .stats span { font-size: .75rem; color: var(--muted); }
.stop-top { display: flex; gap: 10px; align-items: flex-start; } .num { background: var(--brand); color: var(--on-brand); border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; font-weight: 700; font-size: .9rem; flex: none; }
.title { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.leg { text-align: center; color: var(--muted); font-size: .8rem; margin: -4px 0 6px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; margin: 0; } .kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 105px 1fr; } }

.svc-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; } .svc-nums { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 6px; } .svc-nums label { display: flex; align-items: center; gap: 4px; } .svc-nums input[type=number] { width: 84px; }
.svc-edit { display: grid; grid-template-columns: 1fr 82px 92px 44px; gap: 6px; align-items: center; margin-bottom: 8px; } .svc-edit label { display: flex; align-items: center; gap: 3px; font-size: .8rem; } .svc-edit input[type=number] { min-width: 0; }
@media (max-width: 480px) { .svc-edit { grid-template-columns: 1fr 1fr 44px; } .svc-edit input[name="svcName[]"] { grid-column: 1 / -1; } }
.line-head, .line-row { display: grid; grid-template-columns: 1fr 78px 64px 44px; gap: 6px; align-items: center; margin-bottom: 6px; } .line-head { font-size: .75rem; color: var(--muted); margin-bottom: 2px; }
.line-row input { min-width: 0; padding: 8px; }

.modal-backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; border-radius: 18px 18px 0 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 18px; border-bottom: 1px solid var(--line); } .modal-body { overflow-y: auto; padding: 14px 18px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) { .modal-backdrop { align-items: center; } .modal { border-radius: 18px; max-height: 88vh; } }
#toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--toast); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: 90vw; text-align: center; } #toast.show { opacity: 1; transform: translateX(-50%); }

/* invoice document */
.invoice-doc { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-top: 10px; }
.inv-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; } .inv-logo { max-width: 210px; max-height: 80px; object-fit: contain; } .inv-meta { text-align: right; } .inv-meta h2 { color: var(--brand); letter-spacing: .08em; font-size: 1.5rem; margin-bottom: 4px; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 18px 0; font-size: .92rem; } .inv-parties h4 { margin: 0 0 4px; color: var(--muted); text-transform: uppercase; font-size: .72rem; letter-spacing: .08em; }
.inv-table { width: 100%; border-collapse: collapse; } .inv-table th, .inv-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; } .inv-table .r, .inv-table th.r { text-align: right; } .inv-table tr.total td { font-weight: 700; font-size: 1.05rem; border-bottom: 0; }
.inv-pay { margin-top: 16px; padding: 12px; background: var(--brand-soft); border-radius: 10px; } .inv-pay pre { margin: 6px 0 0; font: inherit; white-space: pre-wrap; } .inv-pay p { margin: 0; } .inv-foot { margin: 16px 0 0; color: var(--muted); font-size: .85rem; }
.stamp { position: absolute; right: 26px; top: 46%; transform: rotate(-12deg); border: 4px solid var(--green); color: var(--green); font-weight: 800; font-size: 2rem; padding: 2px 16px; border-radius: 8px; opacity: .55; } .stamp.void { border-color: var(--red); color: var(--red); }

@media print {
  :root, :root[data-theme="dark"] { --bg:#fff; --card:#fff; --surface:#fff; --text:#14262a; --muted:#5b6f74; --line:#ccc; --brand:#0b7f74; --brand-soft:#fff; }
  #themebtn { display: none !important; }
  body { background: #fff; color: #14262a; } #side, #tabs, .no-print, .page-head, #toast, .back { display: none !important; }
  main#view { padding: 0; max-width: none; } #app { display: block; } .invoice-doc { border: 0; padding: 0; margin: 0; }
  .inv-pay { background: none; border: 1px solid #ccc; }
}

/* v0.2 additions */
.selbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.row.sel { cursor: pointer; } .row.sel input { margin-right: 2px; }
.modebar .seg { margin-bottom: 8px; } .modebar p { margin: 6px 0; }
.scroll-x { overflow-x: auto; } .prev-table { border-collapse: collapse; width: 100%; font-size: .82rem; } .prev-table th, .prev-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
body.modal-open #toast { bottom: auto; top: 16px; }

/* v0.3 themes */
body { transition: background .2s, color .2s; }
#tabs a.active::before { content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--brand); }
#themebtn { position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px; z-index: 30; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 1.15rem; cursor: pointer; box-shadow: var(--shadow); display: grid; place-items: center; }
#themebtn:hover { background: var(--hover); }
.page-head h1 { padding-right: 52px; }
@media (min-width: 900px) { .page-head h1 { padding-right: 56px; } }
.seg.theme-seg button { min-height: 40px; }
:root[data-theme="dark"] .inv-logo { background: #fff; border-radius: 8px; padding: 4px; }
:root[data-theme="dark"] .stamp { opacity: .8; }
.logo-d { display: none; } :root[data-theme="dark"] .logo-d { display: block; } :root[data-theme="dark"] .logo-l:not(.inv-logo) { display: none; }
:root[data-theme="dark"] .inv-logo.logo-l { background: #fff; border-radius: 8px; padding: 4px; }
#side .brand img.side-logo { width: 100%; max-width: 190px; height: auto; max-height: none; }
