/* ═══════════════ Mizan — design tokens ═══════════════ */
:root {
  --bg:        #0b0f17;
  --bg-2:      #111827;
  --surface:   #151c2b;
  --surface-2: #1b2436;
  --line:      #263047;
  --text:      #e8edf7;
  --text-dim:  #93a1bd;
  --text-mute: #64748b;
  --accent:    #5b8cff;
  --accent-2:  #7c6cff;
  --good:      #34d399;
  --warn:      #fbbf24;
  --bad:       #f87171;
  --radius:    14px;
  --radius-sm: 10px;
  --shadow:    0 6px 24px rgba(0,0,0,.35);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="light"] {
  --bg:        #f4f6fb;
  --bg-2:      #eaeefa;
  --surface:   #ffffff;
  --surface-2: #f2f5fc;
  --line:      #dfe5f2;
  --text:      #101828;
  --text-dim:  #52627d;
  --text-mute: #8494ad;
  --accent:    #2f6bff;
  --accent-2:  #6b52ff;
  --good:      #059669;
  --warn:      #b45309;
  --bad:       #dc2626;
  --shadow:    0 6px 22px rgba(20,35,80,.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
h1,h2,h3,h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ═══════════════ buttons / fields ═══════════════ */
.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: .55rem .95rem;
  cursor: pointer;
  font-weight: 550;
  transition: .15s transform, .15s background, .15s border-color, .15s opacity;
  white-space: nowrap;
}
.btn:hover  { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost   { background: transparent; }
.btn.danger  { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); border-color: var(--bad); }
.btn.small   { padding: .35rem .7rem; font-size: .85rem; }
.btn.block   { width: 100%; }
.btn.grow    { flex: 1; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text-dim);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 1.05rem; line-height: 1;
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.field { display: block; margin: 0 0 .85rem; }
.field > span { display: block; font-size: .82rem; color: var(--text-dim); margin-bottom: .3rem; font-weight: 550; }
input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
  outline: none;
  transition: .15s border-color, .15s box-shadow;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ═══════════════ onboarding ═══════════════ */
.onboarding {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: radial-gradient(1000px 600px at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%), var(--bg);
  overflow: auto; box-sizing: border-box;
}
.onb-card {
  width: 100%;
  max-width: 520px;
  flex: none;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
  margin: auto;
}
.onb-logo { font-size: 2.4rem; }
.onb-steps { display: flex; gap: .4rem; justify-content: center; margin-bottom: 1.1rem; }
.onb-steps .dot { width: 26px; height: 4px; border-radius: 3px; background: var(--line); transition: .2s; }
.onb-steps .dot.on { background: var(--accent); }
.onb-step h1 { font-size: 1.45rem; }
.onb-step > p { margin-top: 0; }
.onb-total {
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem .85rem; margin: .9rem 0;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: .9rem; color: var(--text-dim);
}
.onb-total strong { font-family: var(--mono); font-size: 1rem; color: var(--text); white-space: nowrap; }
.onb-total > span { white-space: nowrap; }
.onb-diff { text-align: right; font-size: .8rem; margin: -.55rem 0 .8rem; }
.onb-plan { max-height: min(46vh, 420px); overflow: auto; margin: .2rem -.3rem .2rem 0; padding-right: .3rem; }
.onb-plan .prow {
  display: grid; grid-template-columns: 1.6rem 1fr 7.5rem; gap: .55rem; align-items: center;
  padding: .38rem 0;
}
.onb-plan .prow input { text-align: right; font-family: var(--mono); padding: .4rem .55rem; }
.onb-plan .pname { font-size: .92rem; }
.onb-plan .ppct { font-size: .74rem; color: var(--text-mute); }
.extra-row { display: grid; grid-template-columns: 1fr 8rem 34px; gap: .5rem; margin-bottom: .5rem; }
.extra-row input { padding: .5rem .65rem; }

.lock-card { text-align: center; }
.lock-input {
  text-align: center; font-size: 1.6rem; letter-spacing: .4em; font-family: var(--mono);
  padding: .7rem; margin: .3rem 0 .8rem;
}
.lock-error { color: var(--bad); font-size: .85rem; margin: -.4rem 0 .8rem; }

/* ═══════════════ app shell ═══════════════ */
.app { max-width: 1080px; margin: 0 auto; padding: 0 1rem 3rem; }
.topbar {
  display: flex; align-items: center; gap: .8rem;
  padding: .9rem 0 .7rem;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--bg) 78%, transparent);
}
.brand { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.brand-mark { font-size: 1.5rem; }
.brand-name { font-weight: 700; letter-spacing: -.02em; }
.brand-sub { font-size: .74rem; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.month-nav { margin-left: auto; display: flex; align-items: center; gap: .3rem; }
.month-label {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: .35rem .8rem; cursor: pointer; font-weight: 600; font-size: .9rem;
  min-width: 120px;
}
.month-label:hover { border-color: var(--accent); }

/* quick add */
.quickbar { position: sticky; top: 58px; z-index: 19; background: var(--bg); padding-bottom: .55rem; }
.quick-wrap { display: flex; gap: .5rem; }
.quick-wrap input {
  background: var(--surface); border-radius: 12px; padding: .75rem .95rem; font-size: .98rem;
}
.quick-wrap .btn { padding: .75rem 1.3rem; }
.quick-preview {
  margin-top: .45rem; padding: .5rem .75rem; font-size: .86rem;
  background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.quick-preview .chip { background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: .1rem .55rem; font-size: .8rem; }
.quick-preview .amt { font-family: var(--mono); font-weight: 700; color: var(--accent); }

/* tabs */
.tabs { display: flex; gap: .25rem; overflow-x: auto; padding-bottom: .8rem; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: .4rem .85rem; border-radius: 999px; cursor: pointer; font-weight: 550; font-size: .9rem; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-2); border-color: var(--line); color: var(--text); }

/* ═══════════════ cards / layout ═══════════════ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin-bottom: .85rem;
}
.card > h3 { font-size: .95rem; display: flex; align-items: center; gap: .5rem; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.card-head h3 { margin: 0; font-size: .95rem; }
.grid { display: grid; gap: .85rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: .85rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem .95rem;
}
.stat .label { font-size: .74rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .value { font-family: var(--mono); font-size: 1.32rem; font-weight: 700; margin-top: .15rem; letter-spacing: -.02em; }
.stat .sub { font-size: .76rem; color: var(--text-dim); margin-top: .1rem; }
.stat.hero { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--surface)); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.v-good { color: var(--good); } .v-warn { color: var(--warn); } .v-bad { color: var(--bad); }

/* progress */
.bar { height: 7px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; transition: width .35s ease; }
.bar.lg { height: 10px; }

/* category rows */
.cat-list { display: grid; gap: .1rem; }
.cat-row { padding: .6rem .1rem; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: none; }
.cat-top { display: flex; align-items: center; gap: .55rem; margin-bottom: .38rem; font-size: .9rem; }
.cat-ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: .95rem; flex: none; }
.cat-name { font-weight: 550; }
.cat-nums { margin-left: auto; font-family: var(--mono); font-size: .84rem; color: var(--text-dim); white-space: nowrap; }
.cat-nums b { color: var(--text); font-weight: 650; }

/* expense list */
.day-group { margin-bottom: .3rem; }
.day-head {
  display: flex; align-items: baseline; gap: .5rem; padding: .7rem .1rem .35rem;
  font-size: .8rem; color: var(--text-mute); font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 104px; background: var(--surface); z-index: 2;
}
.day-head .dtotal { margin-left: auto; font-family: var(--mono); color: var(--text-dim); text-transform: none; letter-spacing: 0; }
.exp {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .35rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .12s;
}
.exp:hover { background: var(--surface-2); }
.exp .note { min-width: 0; }
.exp .note .t { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp .note .s { font-size: .74rem; color: var(--text-mute); }
.exp .amt { margin-left: auto; font-family: var(--mono); font-weight: 650; white-space: nowrap; }
.exp .del { opacity: 0; border: none; background: transparent; color: var(--text-mute); cursor: pointer; padding: .1rem .3rem; font-size: 1rem; }
.exp:hover .del { opacity: 1; }
.exp .del:hover { color: var(--bad); }

.empty { text-align: center; padding: 2.2rem 1rem; color: var(--text-mute); }
.empty .big { font-size: 2rem; display: block; margin-bottom: .4rem; }

/* plan editor */
.plan-row {
  display: grid; grid-template-columns: 1.9rem 1fr 8.5rem 4.6rem 30px; gap: .55rem; align-items: center;
  padding: .45rem 0; border-bottom: 1px solid var(--line);
}
.plan-row:last-of-type { border-bottom: none; }
.plan-row input[type=text].pamt { text-align: right; font-family: var(--mono); padding: .42rem .6rem; }
.plan-row .pctcell { font-family: var(--mono); font-size: .8rem; color: var(--text-mute); text-align: right; }
.plan-row .pdel { border: none; background: transparent; color: var(--text-mute); cursor: pointer; font-size: 1rem; }
.plan-row .pdel:hover { color: var(--bad); }
.plan-row .pname-in { padding: .42rem .6rem; }

/* bills */
.bill { display: flex; align-items: center; gap: .6rem; padding: .5rem .1rem; border-bottom: 1px solid var(--line); }
.bill:last-child { border-bottom: none; }
.bill .amt { font-family: var(--mono); font-weight: 600; margin-left: auto; }
.tag { font-size: .68rem; padding: .1rem .45rem; border-radius: 99px; border: 1px solid var(--line); color: var(--text-mute); }
.tag.paid { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, transparent); }
.tag.due  { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

/* charts */
.chart-wrap { width: 100%; overflow-x: auto; }
svg.chart { display: block; width: 100%; height: auto; }
.legend { display: grid; gap: .3rem; margin-top: .6rem; }
.legend .li { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .v { margin-left: auto; font-family: var(--mono); color: var(--text-dim); font-size: .82rem; }

/* table */
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mute); padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
table.tbl td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.num { font-family: var(--mono); text-align: right; }

/* modal */
.modal-host { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,6,18,.6); backdrop-filter: blur(3px); }
.modal {
  position: relative; width: min(440px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1.2rem; box-shadow: var(--shadow);
}
.modal h3 { font-size: 1.1rem; margin-bottom: .9rem; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip-btn {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text-dim);
  border-radius: 999px; padding: .32rem .7rem; cursor: pointer; font-size: .84rem;
}
.chip-btn:hover { color: var(--text); }
.chip-btn.on { background: color-mix(in srgb, var(--accent) 20%, transparent); border-color: var(--accent); color: var(--text); }

/* toast */
.toast-host { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 80; display: grid; gap: .4rem; width: min(420px, 92vw); }
.toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: .6rem .8rem; box-shadow: var(--shadow); font-size: .88rem;
  display: flex; align-items: center; gap: .55rem;
  animation: pop .22s ease;
}
.toast.good { border-left-color: var(--good); }
.toast.bad  { border-left-color: var(--bad); }
.toast .undo { margin-left: auto; background: none; border: none; color: var(--accent); cursor: pointer; font-weight: 600; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

.foot { text-align: center; color: var(--text-mute); font-size: .76rem; padding: 1.5rem 0 .5rem; }

@media (max-width: 620px) {
  .app { padding: 0 .7rem 3rem; }
  .topbar { flex-wrap: wrap; }
  .month-nav { order: 3; width: 100%; justify-content: space-between; }
  .month-label { flex: 1; }
  .quickbar { top: 96px; }
  .day-head { top: 148px; }
  .plan-row { grid-template-columns: 1.6rem 1fr 6.6rem 26px; }
  .plan-row .pctcell { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .card-head { flex-wrap: wrap; }
  .card-head h3 { flex: 1 1 100%; }
  .stat { padding: .7rem .75rem; }
  .stat .value { font-size: 1.02rem; white-space: nowrap; }
  .stat .label { font-size: .68rem; }
  .stat .sub { font-size: .7rem; }
  .quick-wrap input { min-width: 0; }
  .onb-card { padding: 1.2rem; }
}
@supports (padding: max(0px)) {
  .app { padding-left: max(.7rem, env(safe-area-inset-left)); padding-right: max(.7rem, env(safe-area-inset-right)); }
  .foot { padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }
}
