/* hme_fin – shared styles. Mobile first; .ui-web adds the desktop layout. */
:root {
  --bg: #f5f4ef; --surface: #ffffff; --surface-2: #faf9f5; --ink: #1f1e1b; --muted: #6d6b64;
  --line: #e3e1d9; --brand: #285e4b; --brand-ink: #ffffff; --focus: #3d7cc9;
  --nec: #2f7d4f; --nec-bg: #e5f2ea; --semi: #a86a10; --semi-bg: #fbefd9;
  --avoid: #b33a3a; --avoid-bg: #f8e3e1; --none: #8a8880; --none-bg: #eeede8;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412; --surface: #1d1d1a; --surface-2: #232320; --ink: #ecebe5; --muted: #a29f96;
    --line: #34332e; --brand: #4fa383; --brand-ink: #0d1a14; --focus: #7fb0ec;
    --nec: #62c08a; --nec-bg: #1c3125; --semi: #e0a64a; --semi-bg: #3a2c14;
    --avoid: #ec8577; --avoid-bg: #3d1f1c; --none: #9a978e; --none-bg: #2a2a26;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 24px 0 10px; color: var(--muted); font-weight: 600; }
.num, .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* cards & tiles */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile.hero { grid-column: 1 / -1; background: var(--brand); color: var(--brand-ink); border: 0; }
.tile.hero .label { color: inherit; opacity: .85; }
.tile.hero .value { font-size: 30px; }

/* necessity colours */
.nec-necessary { --c: var(--nec); --cb: var(--nec-bg); }
.nec-semi { --c: var(--semi); --cb: var(--semi-bg); }
.nec-avoidable { --c: var(--avoid); --cb: var(--avoid-bg); }
.nec-none { --c: var(--none); --cb: var(--none-bg); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; color: var(--c); background: var(--cb); }

/* stacked bar */
.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--none-bg); margin: 10px 0 12px; }
.stack span { background: var(--c); }
.stack span + span { border-left: 2px solid var(--surface); }
.legend { display: grid; gap: 6px; }
.legend a { display: flex; justify-content: space-between; align-items: center; color: inherit; padding: 4px 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 8px; }

/* category bars */
.bars { display: grid; gap: 10px; }
.bar-row .top { display: flex; justify-content: space-between; font-size: 14px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .title { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.item .amt { font-weight: 700; text-align: right; }
.item .actions { grid-column: 1 / -1; display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.cat-chip { display: inline-flex; align-items: center; gap: 5px; }
.cat-chip::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--cat, #888); }
.overdue .due { color: var(--avoid); font-weight: 600; }

/* quick necessity buttons */
.quick { display: inline-flex; gap: 4px; margin: 0; }
.quick button { font: inherit; font-size: 13px; min-width: 40px; min-height: 34px; padding: 4px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--c); cursor: pointer; }
.quick button[aria-pressed="true"] { background: var(--c); color: var(--surface); border-color: var(--c); font-weight: 700; }

/* forms */
.form { display: grid; gap: 14px; }
.field label, .field > .lbl { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field .err { color: var(--avoid); font-size: 13px; margin-top: 4px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; }
input[type=color] { width: 56px; height: 40px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); }
textarea { min-height: 0; }
.amount-input input { font-size: 26px; font-weight: 700; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; }

/* necessity picker: three tick buttons */
.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.picker .opt-none { grid-column: 1 / -1; }
.picker label { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 64px; padding: 8px 4px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface);
  cursor: pointer; font-size: 14px; font-weight: 600; color: var(--c); text-align: center; margin: 0; }
.picker .opt-none label { min-height: 40px; flex-direction: row; font-weight: 500; color: var(--muted); }
.picker input { position: absolute; opacity: 0; pointer-events: none; }
.picker .tick { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 15px;
  border: 2px solid var(--c); color: var(--c); }
.picker .opt-none .tick { width: 20px; height: 20px; font-size: 12px; }
.picker input:checked + label, .picker label:has(input:checked) { background: var(--cb); border-color: var(--c); }
.picker input:checked + label .tick, .picker label:has(input:checked) .tick { background: var(--c); color: var(--surface); }
.picker input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--avoid); border-color: var(--avoid); background: transparent; }
.btn.sm { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* filters */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters .q { grid-column: 1 / -1; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips a { flex: none; font-size: 14px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); }
.chips a.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* messages */
.msgs { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.msgs li { padding: 10px 14px; border-radius: 10px; background: var(--nec-bg); color: var(--nec); font-weight: 500; }
.msgs li.error { background: var(--avoid-bg); color: var(--avoid); }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.month-nav .m { font-weight: 700; font-size: 18px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.hint { background: var(--semi-bg); color: var(--semi); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.hint a { color: inherit; text-decoration: underline; font-weight: 600; }

/* ---------- mobile shell ---------- */
.ui-mobile .topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.ui-mobile .topbar .brand { font-weight: 800; color: var(--ink); }
.ui-mobile main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.ui-mobile .tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.ui-mobile .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px;
  font-size: 11px; color: var(--muted); }
.ui-mobile .tabbar a .ico { font-size: 20px; line-height: 1; }
.ui-mobile .tabbar a.on { color: var(--brand); font-weight: 700; }
.ui-mobile .tabbar a.add .ico { width: 48px; height: 48px; margin-top: -22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-size: 28px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.ui-mobile .sticky-save { position: sticky; bottom: calc(70px + env(safe-area-inset-bottom)); padding-top: 8px; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- web shell ---------- */
.ui-web .shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.ui-web .side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.ui-web .side .brand { font-weight: 800; font-size: 18px; color: var(--ink); display: block; padding: 0 10px 18px; }
.ui-web .side nav a { display: block; padding: 9px 10px; border-radius: 8px; color: var(--ink); margin-bottom: 2px; }
.ui-web .side nav a.on { background: var(--surface-2); color: var(--brand); font-weight: 700; }
.ui-web .side .add { margin: 8px 0 18px; }
.ui-web .side .foot { position: absolute; bottom: 16px; left: 24px; right: 14px; font-size: 13px; }
.ui-web main { padding: 28px 32px; max-width: 1100px; width: 100%; }
.ui-web .tiles { grid-template-columns: repeat(4, 1fr); }
.ui-web .tile.hero { grid-column: auto; }
.ui-web .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.ui-web .filters { grid-template-columns: 2fr 1fr 1fr 1fr auto; align-items: end; }
.ui-web .filters .q { grid-column: auto; }
.ui-web .form-card { max-width: 620px; }
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
table.grid td.amt, table.grid th.amt { text-align: right; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.overdue td { background: var(--avoid-bg); }
@media (max-width: 860px) {
  .ui-web .shell { grid-template-columns: 1fr; }
  .ui-web .side { position: static; height: auto; }
  .ui-web .side .foot { position: static; margin-top: 10px; }
  .ui-web .tiles, .ui-web .cols { grid-template-columns: 1fr 1fr; }
  .ui-web main { padding: 20px 16px; }
  .ui-web .filters { grid-template-columns: 1fr 1fr; }
  .table-wrap { overflow-x: auto; }
}
