:root {
  --bg: #F7F4F2; --card: #FFFFFF; --text: #1F1A1D; --muted: #7A6F75; --border: #E8E1E4;
  --accent: #8A2E5F; --accent-soft: #F4E6EE; --danger: #C0392B; --ok: #1E8E5A; --ok-soft: #E3F4EC;
  --warn: #B26A00; --warn-soft: #FCEFD9; --input: #FCFBFA; --shadow: 0 8px 24px rgba(60, 20, 40, .18);
  --tabbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141012; --card: #1F1A1D; --text: #F4EEF1; --muted: #A79AA1; --border: #332B30;
    --accent: #E07AAE; --accent-soft: #3A2030; --danger: #FF6B5E; --ok: #4CC38A; --ok-soft: #173326;
    --warn: #F0B35A; --warn-soft: #3A2A12; --input: #191416; --shadow: 0 8px 24px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; padding: 0; }
.hidden { display: none !important; }
#app { max-width: 640px; margin: 0 auto; }
h2, h3, h4 { margin: 0; }

/* Login */
.login-inner { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px; }
.brand { text-align: center; margin-bottom: 28px; }
.brand h1 { margin: 0; font-size: 34px; font-weight: 800; color: var(--accent); }
.brand p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.field, textarea.field, select.field {
  width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--input); color: var(--text); outline: none; -webkit-appearance: none; appearance: none;
}
.field:focus { border-color: var(--accent); }
textarea.field { min-height: 84px; resize: vertical; }
.btn { width: 100%; margin-top: 18px; padding: 14px; border-radius: 12px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn:active { opacity: .85; } .btn[disabled] { opacity: .6; }
.error { color: var(--danger); font-size: 14px; margin-top: 12px; }

/* Top / tabs */
.top { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 20px 10px; }
.top h2 { font-size: 26px; font-weight: 800; }
.who { color: var(--muted); font-size: 14px; }
.tab { padding-bottom: calc(var(--tabbar-h) + 100px + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabbar button { flex: 1; max-width: 160px; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.tabbar .ico { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); }
.tabbar button.active .ico { filter: none; opacity: 1; }
.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; padding: 15px 26px; border-radius: 30px; box-shadow: var(--shadow); z-index: 4;
}

/* Day nav */
.daynav { display: flex; align-items: center; margin: 0 16px; padding: 10px 0; background: var(--card); border: 1px solid var(--border); border-radius: 16px; }
.arrow { width: 56px; font-size: 34px; line-height: 1; color: var(--accent); padding: 4px 0; }
.daymid { flex: 1; text-align: center; }
.daylabel { font-size: 20px; font-weight: 700; }
.daydate { font-size: 14px; color: var(--muted); margin-top: 2px; }
.daypick { position: relative; display: inline-block; }
.daypick input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.today { font-size: 13px; color: var(--accent); font-weight: 600; margin-top: 4px; padding: 2px 6px; }

/* Lists */
.list { padding: 14px 16px 0; }
.searchbar { padding: 0 16px; }
.count { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin: 0 0 8px 4px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.item:active { background: var(--accent-soft); }
.time { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 8px 9px; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; align-self: flex-start; }
.grow { flex: 1; min-width: 0; }
.name { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.phone { color: var(--accent); text-decoration: none; font-size: 15px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; }
.pill { font-size: 12px; font-weight: 700; padding: 5px 9px; border-radius: 999px; white-space: nowrap; }
.pill.paid { background: var(--ok-soft); color: var(--ok); }
.pill.unpaid { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; margin-top: 48px; padding: 0 24px; }
.empty h3 { font-size: 18px; } .empty p { color: var(--muted); margin: 6px 0 0; }
.empty button { color: var(--accent); font-weight: 700; margin-top: 14px; }
.spinner { width: 26px; height: 26px; margin: 40px auto; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.section { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin: 22px 0 8px 4px; }

/* Finance */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.stat .k { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 24px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.yearbar { display: flex; align-items: center; justify-content: space-between; margin: 22px 4px 8px; }
.yearbar b { font-size: 18px; }
.yearbar button { color: var(--accent); font-size: 26px; padding: 0 12px; }
.months { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 4px 14px; }
.mrow { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; }
.mrow + .mrow { border-top: 1px solid var(--border); }
.mname { font-weight: 600; font-size: 15px; }
.bar { height: 10px; border-radius: 6px; background: var(--bg); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar i.u { background: var(--warn); opacity: .55; }
.mval { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }
.mval small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 8px 4px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--accent); }
.legend span.u::before { background: var(--warn); opacity: .55; }

/* Sheet */
.overlay { position: fixed; inset: 0; background: rgba(20, 10, 15, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.overlay.center { align-items: center; z-index: 30; }
.sheet { width: 100%; max-width: 640px; background: var(--bg); border-radius: 18px 18px 0 0; max-height: 94vh; max-height: 94dvh; overflow: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.sheethead { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.sheethead b { font-size: 17px; }
.sheethead .save { color: var(--accent); font-weight: 700; font-size: 17px; }
.sheethead .cancel { color: var(--muted); font-size: 17px; }
.sheetbody { padding: 16px; }
.group { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.group > input, .group > .row, .group > textarea, .group > .cell { border: 0; }
.group > * + * { border-top: 1px solid var(--border) !important; }
.group input, .group textarea { width: 100%; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 17px; padding: 13px 16px; outline: none; -webkit-appearance: none; appearance: none; min-height: 48px; }
.group textarea { min-height: 80px; resize: vertical; }
.row { display: flex; align-items: center; justify-content: space-between; padding-left: 16px; min-height: 48px; gap: 8px; }
.row > span { font-size: 17px; white-space: nowrap; }
.row input { width: auto; flex: 1; text-align: right; color: var(--accent); font-weight: 600; min-width: 0; }
.row input.num { max-width: 90px; }
.cell { padding: 12px 16px; }
.switch { position: relative; width: 51px; height: 31px; margin-right: 12px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 31px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); font-size: 15px; font-weight: 600; color: var(--text); }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin: 10px 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.suggest { max-height: 220px; overflow: auto; }
.suggest button { display: block; width: 100%; text-align: left; padding: 11px 16px; border-top: 1px solid var(--border); }
.suggest button small { color: var(--muted); margin-left: 6px; }
.picked { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.picked b { font-size: 17px; } .picked button { color: var(--accent); font-weight: 600; }
.summary { text-align: center; margin-top: 14px; font-weight: 600; }
.kv { display: flex; justify-content: space-between; padding: 12px 16px; gap: 12px; }
.kv span { color: var(--muted); } .kv b { text-align: right; overflow-wrap: anywhere; }
.actions { display: flex; gap: 10px; margin-top: 14px; } .actions .btn { margin-top: 0; }

/* Dialog / toast */
.dialog { background: var(--card); width: calc(100% - 48px); max-width: 320px; border-radius: 16px; overflow: hidden; text-align: center; }
.dialog h4 { margin: 20px 16px 6px; font-size: 17px; }
.dialog p { margin: 0 16px 18px; color: var(--muted); white-space: pre-line; font-size: 14px; }
.dialog .btns { display: flex; border-top: 1px solid var(--border); }
.dialog .btns button { flex: 1; padding: 14px; font-size: 17px; }
.dialog .btns button + button { border-left: 1px solid var(--border); }
.dialog .danger { color: var(--danger); font-weight: 700; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(14px + env(safe-area-inset-top)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 40; max-width: calc(100% - 32px); }
