:root {
  --red: #C8240E; --red-d: #9E1C0B; --red-soft: #FDE8E4; --red-ink: #A31D0B;
  --green: #0B2E1A; --green-2: #163F27; --green-ok: #1D6B3A; --green-soft: #E3F0E7;
  --cream: #FBF4E9; --cream-2: #F2EADC; --line: #E6DCCB; --line-2: #F0E8DA;
  --ink: #0B2E1A; --muted: #4A5D50; --amber: #8A4A05; --amber-soft: #FDF0D9;
  --white: #FFFFFF;
  --r-lg: 18px; --r-md: 14px; --r-sm: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--cream); color: var(--ink); font-family: 'DM Sans', system-ui, sans-serif; font-size: 16px; -webkit-text-size-adjust: 100%; }
body { padding-top: var(--safe-t); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #1A55B8; outline-offset: 2px; }
.h { font-family: Fredoka, 'DM Sans', sans-serif; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { min-height: 80vh; display: grid; place-items: center; }

/* layout */
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; margin: 0 auto; }
.page { padding-bottom: calc(110px + var(--safe-b)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.wraprow { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.wraprow > .main { flex: 999 1 520px; min-width: 0; }
.wraprow > .side { flex: 1 1 320px; min-width: 0; }
.section-title { font-family: Fredoka, sans-serif; font-weight: 600; font-size: 17px; margin: 10px 4px 0; display: flex; align-items: center; gap: 8px; }

/* header */
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px; }
.topbar img { width: 40px; height: 40px; object-fit: contain; border-radius: 50%; }
.topbar .t { flex: 1; min-width: 0; }
.topbar .t b { display: block; font-family: Fredoka, sans-serif; font-weight: 700; font-size: 21px; line-height: 1.15; }
.topbar .t span { font-size: 13px; color: var(--muted); }
.topbar.dark { background: var(--green); color: var(--cream); }
.topbar.dark .t span { color: #C9D8CE; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--white); display: inline-flex; align-items: center; justify-content: center; color: var(--ink); flex-shrink: 0; }
.topbar.dark .icon-btn { background: var(--green-2); border-color: var(--green-2); color: var(--cream); }

/* buttons */
.btn { min-height: 48px; border-radius: var(--r-md); border: none; padding: 0 18px; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--white); color: var(--ink); border: 1px solid var(--line); }
.btn.primary { background: var(--red); color: var(--white); border-color: var(--red); }
.btn.primary:active { background: var(--red-d); }
.btn.dark { background: var(--green); color: var(--cream); border-color: var(--green); }
.btn.ghost { background: transparent; }
.btn.dashed { background: transparent; border: 2px dashed #D9CBB3; }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-family: Fredoka, sans-serif; font-weight: 600; font-size: 19px; border-radius: 16px; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.linkbtn { background: none; border: none; padding: 6px 0; color: var(--red); font-weight: 600; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.tile { min-height: 96px; border-radius: 16px; border: none; background: var(--green); color: var(--cream); display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; padding: 14px; text-align: left; font-weight: 700; font-size: 16px; }
.tile.red { background: var(--red); color: var(--white); }

/* cards & lists */
.card { background: var(--white); border-radius: var(--r-lg); padding: 16px; }
.card.pad0 { padding: 4px 16px; }
.card.alert { outline: 2px solid var(--red); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row b { display: block; font-size: 15px; }
.list-row .sub { font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; background: var(--cream-2); color: var(--muted); white-space: nowrap; }
.pill.red { background: var(--red-soft); color: var(--red-ink); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green-ok); }
.empty { text-align: center; padding: 24px 12px; color: var(--muted); font-size: 14px; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--white); padding: 10px 12px; font-size: 16px; }
textarea.input { min-height: 80px; resize: vertical; }
.input.big { font-size: 20px; font-weight: 700; }
.input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(11,46,26,.12); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--white); border-radius: 14px; padding: 4px; border: 1px solid var(--line); }
.seg button { min-height: 44px; border-radius: 10px; border: none; background: transparent; font-weight: 600; font-size: 15px; }
.seg button[aria-pressed="true"] { background: var(--green); color: var(--cream); font-weight: 700; }
.hint { font-size: 13px; color: var(--muted); }
.err { font-size: 13px; color: var(--red-ink); font-weight: 600; }
.ok { font-size: 13px; color: var(--green-ok); font-weight: 700; display: flex; align-items: center; gap: 6px; }

/* suggest */
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--white); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(11,46,26,.12); max-height: 280px; overflow: auto; }
.suggest-list button { width: 100%; text-align: left; border: none; background: none; padding: 12px 14px; min-height: 48px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.suggest-list button:last-child { border-bottom: none; }
.suggest-list button:hover, .suggest-list button:focus-visible { background: var(--cream); }
.suggest-list .add { color: var(--red); font-weight: 700; }

/* photo */
.photo-box { display: flex; gap: 12px; align-items: center; }
.photo-thumb { width: 72px; height: 88px; border-radius: 10px; background: var(--cream-2); display: flex; align-items: center; justify-content: center; color: #8C7B60; overflow: hidden; flex-shrink: 0; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* totals */
.totalbox { background: var(--green); color: var(--cream); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.totalbox .input { background: var(--cream); color: var(--ink); border: none; text-align: right; max-width: 170px; }
.totalbox .ok { color: #9FE0B5; }
.totalbox .warn { color: #FFD8A8; font-size: 13px; font-weight: 700; }
.totalbox select.input { max-width: none; text-align: left; }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 40px 20px calc(24px + var(--safe-b)); gap: 20px; max-width: 420px; margin: 0 auto; }
.login img { width: 84px; height: 84px; }
.who { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; }
.who button { flex: 1 1 120px; min-height: 64px; border-radius: 16px; border: 2px solid var(--line); background: var(--white); font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.who button span { font-size: 12px; font-weight: 400; color: var(--muted); }
.who button[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: var(--cream); }
.who button[aria-pressed="true"] span { color: #C9D8CE; }
.dots { display: flex; gap: 16px; min-height: 18px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #CDBFA6; display: block; }
.dots i.on { background: var(--red); border-color: var(--red); }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; }
.keypad button { min-height: 62px; border-radius: 18px; border: none; background: var(--white); font-family: Fredoka, sans-serif; font-size: 26px; font-weight: 500; }
.keypad button:active { background: var(--cream-2); }
.keypad .blank { visibility: hidden; }
.keypad .del { background: transparent; }

/* owner */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpi { background: var(--white); border-radius: var(--r-lg); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-family: Fredoka, sans-serif; font-weight: 600; font-size: 30px; line-height: 1.1; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi.dark { background: var(--green); color: var(--cream); }
.kpi.dark .l, .kpi.dark .muted { color: #C9D8CE; }
.kpi.red { background: var(--red); color: var(--white); }
.kpi.red .l, .kpi.red .muted { color: #FFE3DD; }
.notice { width: 100%; min-height: 56px; border-radius: 14px; border: 1px solid var(--line); background: var(--white); display: flex; align-items: center; gap: 12px; padding: 0 16px; text-align: left; font-weight: 600; }
.notice .badge { min-width: 28px; height: 28px; border-radius: 999px; background: var(--red); color: var(--white); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.catbtn { width: 100%; border: none; background: transparent; text-align: left; padding: 10px 12px; margin: 0 -12px; width: calc(100% + 24px); border-radius: 12px; display: flex; flex-direction: column; gap: 6px; }
.catbtn[aria-pressed="true"] { background: var(--cream); outline: 2px solid var(--green); }
.bar { height: 10px; border-radius: 999px; background: var(--cream-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--red); }
.tablebox { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 11px 8px; border-bottom: 1px solid var(--line-2); }
table.t .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.hot td { background: var(--red-soft); }
.up { color: var(--red-ink); font-weight: 700; }
.down { color: var(--green-ok); font-weight: 700; }

/* bottom nav */
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--white); border-top: 1px solid var(--line); display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding-bottom: var(--safe-b); z-index: 30; }
.bottomnav button { min-height: 60px; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); position: relative; }
.bottomnav button[aria-current="page"] { color: var(--red); }
.bottomnav .dot { position: absolute; top: 8px; right: calc(50% - 18px); min-width: 16px; height: 16px; border-radius: 99px; background: var(--red); color: #fff; font-size: 10px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.footbar { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(to top, var(--cream) 70%, rgba(251,244,233,0)); z-index: 25; }
.footbar .btn { max-width: 560px; margin: 0 auto; display: flex; width: 100%; }

/* sheet (modal) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(11,46,26,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--cream); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 22px; } }
.sheet h2 { margin: 0; font-family: Fredoka, sans-serif; font-weight: 600; font-size: 21px; }
.photo-view { width: 100%; border-radius: 12px; background: var(--cream-2); }

/* toast & banner */
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--green); color: var(--cream); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--red-ink); }
.banner { margin: 0 16px; border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600; background: var(--amber-soft); color: var(--amber); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.spin { width: 20px; height: 20px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }
.ver { text-align: center; font-size: 11px; color: #8C7B60; padding: 16px 0; }
