/* Money Manager — design tokens from spec §3. Every text/background pair uses a token. */
:root {
  --bg: #F2F5FA;
  --surface: #FFFFFF;
  --text: #14253A;
  --text-2: #52657D;
  --border: #CBD7E6;
  --soft: #E9F0F8;
  --accent: #174EB8;
  --selected-bg: #DBE9FF;
  --danger: #AE2645;
  --up: #B42318;      /* expense higher */
  --up-bg: #FDE7E4;
  --down: #116A3B;    /* expense lower */
  --down-bg: #DDF5E7;
  --primary: #174EB8; /* primary button bg (white text) */
  --primary-text: #FFFFFF;
  --hero-1: #1E3A8A;
  --hero-2: #6D28D9;
  --hero-inc-1: #065F46;
  --hero-inc-2: #0E7490;
  --focus: #174EB8;
  --shadow: 0 1px 2px rgba(20, 37, 58, .08), 0 2px 8px rgba(20, 37, 58, .06);
  --radius: 12px;
  --radius-sm: 10px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0E1726;
  --surface: #1D2B3D;
  --text: #F7F9FF;
  --text-2: #C1CEE0;
  --border: #4C607A;
  --soft: #2A3C53;
  --accent: #B1CEFF;
  --selected-bg: #314F78;
  --danger: #FFB1BF;
  --up: #FFB4A8;
  --up-bg: #4A1E1A;
  --down: #8EE4B0;
  --down-bg: #143D2A;
  --primary: #2F66D0;
  --primary-text: #FFFFFF;
  --hero-1: #1E3A8A;
  --hero-2: #5B21B6;
  --hero-inc-1: #065F46;
  --hero-inc-2: #155E75;
  --focus: #B1CEFF;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.topbar .sub { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); }
.icon-btn {
  min-width: 44px; min-height: 44px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 18px; padding: 0 8px;
}
.icon-btn.ghost { border-color: transparent; background: transparent; }
main { flex: 1; padding: 10px 12px calc(84px + env(safe-area-inset-bottom)); }

/* Bottom nav */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .inner { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; max-width: 480px; }
.bottomnav button {
  border: 0; background: transparent; color: var(--text-2);
  min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 600;
}
.bottomnav button .ni { font-size: 20px; line-height: 1; }
.bottomnav button[aria-current="page"] { color: var(--accent); background: var(--selected-bg); }

/* Cards & sections */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); margin-bottom: 10px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 2px 6px; font-size: 13px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--text-2); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* Hero */
.hero {
  border-radius: 14px; padding: 14px; margin-bottom: 10px;
  background: linear-gradient(135deg, var(--hero-1), var(--hero-2));
  color: #FFFFFF; /* fixed white on dark gradient (spec F12) */
}
.hero.income { background: linear-gradient(135deg, var(--hero-inc-1), var(--hero-inc-2)); }
.hero .label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #FFFFFF; opacity: .92; }
.hero .big { font-size: 32px; font-weight: 800; line-height: 1.15; margin: 4px 0 8px; overflow-wrap: anywhere; color: #FFFFFF; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 14px; color: #FFFFFF; }
.delta { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-weight: 700; font-size: 13px; background: #FFFFFF; }
.delta.bad { color: #B42318; }
.delta.good { color: #116A3B; }
.delta.same { color: #14253A; }

/* Segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: var(--radius); background: var(--soft); border: 1px solid var(--border); margin-bottom: 10px; }
.seg button { min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--text-2); font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* Tile grid */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px;
  min-height: 88px; padding: 8px 4px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  text-align: center; box-shadow: var(--shadow);
}
.tile:active { transform: scale(.97); }
.tile .ti { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 24px; background: var(--soft); }
.tile .tn { font-size: 13px; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; hyphens: auto; }
.tile .tc { font-size: 11px; color: var(--text-2); }
.tile.add { border-style: dashed; background: transparent; box-shadow: none; color: var(--accent); }
.tile.add .ti { background: var(--selected-bg); color: var(--accent); }
.tile[aria-pressed="true"] { background: var(--selected-bg); border-color: var(--accent); color: var(--text); }
/* colourful tile icons */
.c0 .ti { background: #FDE7E4; } .c1 .ti { background: #E0EDFF; } .c2 .ti { background: #DDF5E7; } .c3 .ti { background: #FFF1D6; }
.c4 .ti { background: #EFE4FF; } .c5 .ti { background: #D7F4F6; } .c6 .ti { background: #FFE2F0; } .c7 .ti { background: #EAF2D3; }
:root[data-theme="dark"] .c0 .ti { background: #4A2A2A; } :root[data-theme="dark"] .c1 .ti { background: #243B5E; } :root[data-theme="dark"] .c2 .ti { background: #1F4232; } :root[data-theme="dark"] .c3 .ti { background: #4A3A1C; }
:root[data-theme="dark"] .c4 .ti { background: #3A2C57; } :root[data-theme="dark"] .c5 .ti { background: #1E4448; } :root[data-theme="dark"] .c6 .ti { background: #4C2539; } :root[data-theme="dark"] .c7 .ti { background: #36421F; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.tx { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tx:last-child { border-bottom: 0; }
.tx .ic { width: 40px; height: 40px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--soft); font-size: 20px; }
.tx .body { flex: 1; min-width: 0; }
.tx .t1 { font-weight: 650; overflow-wrap: anywhere; }
.tx .t2 { font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.tx .amt { font-weight: 750; white-space: nowrap; }
.tx .acts { display: flex; gap: 4px; }
.tx .acts .icon-btn { font-size: 16px; min-width: 40px; min-height: 40px; }
.tx .acts .del { color: var(--danger); }
.tx.highlight { background: var(--selected-bg); border-radius: 8px; padding-left: 6px; padding-right: 6px; transition: background 1s; }
.badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--soft); color: var(--text-2); border: 1px solid var(--border); vertical-align: middle; }

.sumrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.sumrow:last-child { border-bottom: 0; }
.sumrow.total { font-weight: 800; }
.amount { font-weight: 700; white-space: nowrap; }

.empty { text-align: center; padding: 18px 8px; color: var(--text-2); }
.empty .big { font-size: 32px; }

/* Entry */
.amount-box { display: flex; align-items: baseline; gap: 6px; padding: 10px 12px; background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius); margin-bottom: 8px; min-height: 64px; }
.amount-box .cur { font-size: 20px; font-weight: 700; color: var(--text-2); }
.amount-box .val { font-size: 32px; font-weight: 800; flex: 1; text-align: right; overflow-wrap: anywhere; min-width: 0; }
.amount-box .val.placeholder { color: var(--text-2); }
.expr { font-size: 14px; color: var(--text-2); text-align: right; min-height: 20px; overflow-wrap: anywhere; }
.err { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 18px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.keypad.calc { grid-template-columns: repeat(4, 1fr); }
.key { min-height: 52px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 22px; font-weight: 650; }
.key:active { background: var(--selected-bg); }
.key.op { background: var(--soft); color: var(--accent); }
.key.fn { background: var(--soft); color: var(--text); font-size: 17px; }
.keypad.calc .key.eq { grid-row: span 2; }
.keypad.calc .key.zero { grid-column: span 2; }
.key.eq { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; flex: 1; min-width: 0; }
.field label { font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.input { width: 100%; min-height: 44px; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.input::placeholder { color: var(--text-2); opacity: 1; }
.btn { min-height: 48px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 750; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--soft); color: var(--text-2); border-color: var(--border); cursor: not-allowed; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { min-height: 40px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.chip[aria-pressed="true"] { background: var(--selected-bg); color: var(--accent); border-color: var(--accent); }
.curtag { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--soft); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }

/* Reports */
.bar-row { display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: center; margin: 6px 0; }
.bar-track { height: 14px; background: var(--soft); border-radius: 7px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; background: var(--accent); border-radius: 7px; }
.share-track { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.share-fill { height: 100%; background: var(--accent); }
.typegroup > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 4px 0; min-height: 44px; }
.typegroup > summary::-webkit-details-marker { display: none; }
.typegroup > summary .chev { transition: transform .15s; color: var(--text-2); }
.typegroup[open] > summary .chev { transform: rotate(90deg); }
.catrow { display: flex; gap: 8px; align-items: center; padding: 6px 0 6px 10px; border-top: 1px dashed var(--border); }
.catrow .body { flex: 1; min-width: 0; }

/* Settings */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch { position: relative; width: 52px; height: 30px; border-radius: 15px; border: 1px solid var(--border); background: var(--soft); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text-2); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--primary); border-color: var(--primary); }
.switch[aria-checked="true"]::after { left: 25px; background: #FFFFFF; }
.cur-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cur-tile { min-height: 56px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px; }
.cur-tile .f { font-size: 18px; }
.cur-tile .cd { font-weight: 750; font-size: 13px; }
.cur-tile .sy { font-size: 12px; color: var(--text-2); }
.cur-tile[aria-pressed="true"] { background: var(--selected-bg); border-color: var(--accent); }
.cur-tile[aria-pressed="true"] .cd { color: var(--accent); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; max-height: 300px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); }
.icon-grid button { min-height: 46px; border-radius: 10px; border: 1px solid transparent; background: var(--surface); font-size: 22px; }
.icon-grid button[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--selected-bg); }
.mgmt-type { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.mgmt-type:last-child { border-bottom: 0; }
.mgmt-type .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(5, 10, 20, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 16px; width: 100%; max-width: 360px; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal p { margin: 0 0 14px; color: var(--text-2); }
.modal .row { justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700; z-index: 30; max-width: calc(100% - 32px); text-align: center; box-shadow: var(--shadow); }

@media (min-width: 560px) {
  .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
