/* Masroof — one stylesheet, no build step, no framework.
   Mobile-first. The app is a 560px column centred on wider screens so it reads
   as an app rather than a stretched web page. */

:root {
  color-scheme: light dark;

  --bg:        #F6F6F3;
  --surface:   #FFFFFF;
  --surface-2: #F0F0EC;
  --text:      #16181D;
  --muted:     #6B7280;
  --faint:     #9AA1AC;
  --border:    #E5E5DF;
  --accent:    #0E7C66;
  --accent-ink:#FFFFFF;
  --accent-sub:#E3F2EC;
  --danger:    #B42318;
  --danger-sub:#FDECEA;
  --shadow:    0 1px 2px rgba(16,18,20,.05), 0 8px 24px rgba(16,18,20,.06);
  --radius:    16px;
  --radius-sm: 10px;
  --tabh:      64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0F1113;
    --surface:   #17191D;
    --surface-2: #1F2226;
    --text:      #ECEEF1;
    --muted:     #99A1AD;
    --faint:     #6E7783;
    --border:    #262A30;
    --accent:    #2FBF9B;
    --accent-ink:#06231D;
    --accent-sub:#13322A;
    --danger:    #F97066;
    --danger-sub:#3A1A17;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* An explicit display value beats the browser default for [hidden], so anything
   toggled with .hidden needs this or it stays on screen. */
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ------------------------------------------------------------------ layout */

#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--tabh) + 32px + env(safe-area-inset-bottom)); }
.page { padding-top: 12px; animation: rise .18s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .page { animation: none; } }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 8px; }
.topbar h1 { font-size: 20px; }
.sub { color: var(--muted); font-size: 13px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card.flush { padding: 0; overflow: hidden; }
.card h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 10px; letter-spacing: .01em; }

/* ------------------------------------------------------------------ tab bar */

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
#tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--faint); padding: 6px 0; font-weight: 550;
}
#tabs a .ico { font-size: 17px; line-height: 1; }
#tabs a[aria-current="page"] { color: var(--accent); }
#tabs a.add { position: relative; }
#tabs a.add .plus {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 26px; font-weight: 400;
  line-height: 1; margin-top: -14px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ------------------------------------------------------------------ controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: 15px; cursor: pointer;
  min-height: 46px; transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost   { background: transparent; }
.btn.danger  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.btn.block   { width: 100%; }
.btn.sm      { padding: 7px 11px; min-height: 34px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; pointer-events: none; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; min-height: 48px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.input:focus-visible, .btn:focus-visible, #tabs a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
select.input { background-image: none; }
textarea.input { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 6px; }
.err { color: var(--danger); font-size: 13.5px; margin: 10px 0; }

/* ------------------------------------------------------------------ money */

.big-total { font-size: 40px; font-weight: 680; letter-spacing: -.025em; line-height: 1.05; }
.big-total .cur { font-size: 17px; color: var(--muted); font-weight: 600; margin-left: 6px; letter-spacing: 0; }
.delta { font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; }
.delta.up   { color: var(--danger); }
.delta.down { color: var(--accent); }

.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.monthnav button {
  background: none; border: 0; padding: 6px 10px; cursor: pointer; color: var(--muted);
  font-size: 18px; border-radius: 8px; line-height: 1;
}
.monthnav button:disabled { opacity: .25; }
.monthnav .label { font-weight: 620; font-size: 15px; }

/* ------------------------------------------------------------------ donut */

.donut-wrap { display: flex; align-items: center; gap: 14px; }
.donut { flex: 0 0 112px; width: 112px; height: 112px; }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.legend-row { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.legend-row .dot { width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto; }
.legend-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .vl { color: var(--muted); font-weight: 600; }

/* ------------------------------------------------------------------ bars */

/* Each bar sets its own height as a percentage of this fixed-height row. The
   track behind it keeps empty days visible as a baseline rather than a gap. */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 78px; margin-top: 4px; }
.bars .bar { flex: 1; border-radius: 3px 3px 0 0; background: var(--accent); min-height: 2px; }
.bars .bar.zero { background: var(--surface-2); height: 2px; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 6px; }

.trend { display: flex; align-items: flex-end; gap: 6px; height: 110px; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.trend .col .b { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .35; }
.trend .col.now .b { opacity: 1; }
.trend .col .m { font-size: 10px; color: var(--faint); }

/* ------------------------------------------------------------------ lists */

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.item .ic {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-size: 18px; flex: 0 0 auto; background: var(--surface-2);
}
.item .mid { flex: 1; min-width: 0; }
.item .t1 { font-weight: 580; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .t2 { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 640; white-space: nowrap; }

.daygroup { padding: 10px 16px 4px; font-size: 12px; color: var(--muted); font-weight: 600;
            display: flex; justify-content: space-between; background: var(--surface-2); }

.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty .em { font-size: 30px; margin-bottom: 10px; }

/* ------------------------------------------------------------------ chips */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 13px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 14px; font-weight: 550;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 9px; }
.catbtn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 14px;
  padding: 14px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 570; min-height: 78px; justify-content: center;
}
.catbtn .e { font-size: 22px; line-height: 1; }
.catbtn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-sub); }

/* ------------------------------------------------------------------ sheet */

#sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
#sheet .sheet-back { position: absolute; inset: 0; background: rgba(0,0,0,.42); animation: fade .15s ease both; }
#sheet .sheet-body {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .2s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(18px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { #sheet .sheet-body, #sheet .sheet-back { animation: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font-size: 17px; color: var(--text); }

/* ------------------------------------------------------------------ toast */

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px); z-index: 80;
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 560; opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease; max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------ landing */

.landing { max-width: 560px; margin: 0 auto; padding: 0 20px 60px; }
.hero { padding: 52px 0 30px; text-align: center; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand .mk { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
             display: grid; place-items: center; font-size: 15px; }
.hero h1 { font-size: 33px; line-height: 1.15; margin: 26px 0 12px; letter-spacing: -.025em; }
.hero p { color: var(--muted); font-size: 16px; margin: 0 auto 26px; max-width: 30rem; }
.steps { display: flex; flex-direction: column; gap: 10px; margin: 28px 0; text-align: left; }
.step { display: flex; gap: 13px; align-items: flex-start; background: var(--surface);
        border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 15px; }
.step .n { width: 25px; height: 25px; border-radius: 50%; background: var(--accent-sub); color: var(--accent);
           display: grid; place-items: center; font-size: 12.5px; font-weight: 700; flex: 0 0 auto; }
.step b { display: block; font-weight: 610; margin-bottom: 2px; }
.step span { color: var(--muted); font-size: 13.5px; }

/* ------------------------------------------------------------------ misc */

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 570; text-align: right; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; word-break: break-all; user-select: all; line-height: 1.45;
}
.pill { font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 999px;
        background: var(--surface-2); color: var(--muted); }
.pill.on { background: var(--accent-sub); color: var(--accent); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent);
           border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
