:root {
  --primary: #1f4e79; --primary-2: #2c6aa3; --ok: #1e8a4c; --danger: #c0392b; --warn: #d68910;
  --bg: #f3f5f8; --card: #fff; --text: #1c2430; --muted: #6b7686; --line: #e1e5eb; --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--primary); color: #fff;
  padding: calc(12px + var(--safe-top)) 16px 12px; display: flex; align-items: center; justify-content: space-between; }
header.top h1 { margin: 0; font-size: 18px; font-weight: 600; }
header.top button { background: transparent; border: 0; color: #fff; font-size: 14px; padding: 6px 8px; opacity: .9; }

main { padding: 16px 16px calc(84px + var(--safe-bottom)); max-width: 760px; margin: 0 auto; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: var(--safe-bottom); z-index: 5; }
nav.tabs button { flex: 1; border: 0; background: none; padding: 9px 4px 10px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; }
nav.tabs button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; }
nav.tabs button.active { color: var(--primary); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 14px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; } .row > * { flex: 1; min-width: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 9px;
  padding: 12px 16px; background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; }
.btn.block { width: 100%; margin-top: 14px; }
.btn.secondary { background: #e7edf4; color: var(--primary); }
.btn.danger { background: var(--danger); } .btn.ok { background: var(--ok); }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; }

.clock { text-align: center; padding: 8px 0 4px; }
.clock .time { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock .sub { color: var(--muted); font-size: 14px; }
.bigbtn { width: 100%; padding: 20px; font-size: 20px; border-radius: 14px; margin-top: 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { font-size: 13px; color: var(--muted); }
.list .right { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 14px 0; font-size: 14px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: #e7edf4; color: var(--primary); font-weight: 600; }
.badge.low { background: #fdecea; color: var(--danger); } .badge.off { background: #eee; color: #888; }
.total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 10px; }

.segmented { display: flex; background: #e7edf4; border-radius: 10px; padding: 3px; margin-bottom: 14px; overflow-x: auto; }
.segmented button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 8px; font-size: 14px; color: var(--primary); white-space: nowrap; }
.segmented button.active { background: #fff; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.sig-wrap { border: 1px dashed #9aa6b5; border-radius: 9px; background: #fbfcfd; position: relative; touch-action: none; }
.sig-wrap canvas { width: 100%; height: 160px; display: block; }
.sig-wrap .hint { position: absolute; left: 12px; bottom: 8px; font-size: 12px; color: var(--muted); pointer-events: none; }

#scanner { width: 100%; border-radius: 9px; overflow: hidden; margin-top: 10px; }

.login { max-width: 400px; margin: 0 auto; padding: calc(40px + var(--safe-top)) 20px 20px; }
.login .logo { text-align: center; margin-bottom: 24px; }
.login .logo svg { width: 64px; height: 64px; stroke: var(--primary); fill: none; stroke-width: 1.6; }
.login h1 { text-align: center; margin: 8px 0 0; font-size: 24px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + var(--safe-bottom)); background: #222; color: #fff;
  padding: 11px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: 90%; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.error { background: var(--danger); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal-box { background: #fff; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom)); }
.modal-box h2 { margin: 0 0 6px; font-size: 18px; }
@media (min-width: 700px) { .modal { align-items: center; } .modal-box { border-radius: 16px; } }
