:root {
  --bg: #f4f5f9;
  --bg-grad-1: #f4f5f9;
  --bg-grad-2: #eef0f7;
  --surface: #ffffff;
  --surface-2: #f3f3f7;
  --surface-3: #ebebf0;
  --text: #14151a;
  --text-2: #5f6275;
  --text-3: #a0a3b3;
  --border: #e7e8ee;
  --border-strong: #d8d9e1;
  --accent: #5856d6;
  --accent-2: #ecebff;
  --accent-grad-1: #6c5ce7;
  --accent-grad-2: #5856d6;
  --accent-grad-3: #af52de;
  --green: #10b981;
  --green-soft: #e7f7f0;
  --red: #ef4444;
  --red-soft: #fde8e8;
  --orange: #f59e0b;
  --teal: #14b8a6;
  --purple: #a855f7;
  --pink: #ec4899;
  --blue: #3b82f6;
  --indigo: #6366f1;
  --shadow-sm: 0 1px 2px rgba(20, 21, 26, .04);
  --shadow: 0 2px 6px rgba(20, 21, 26, .04), 0 8px 24px rgba(20, 21, 26, .06);
  --shadow-lg: 0 4px 12px rgba(20, 21, 26, .06), 0 24px 48px rgba(20, 21, 26, .12);
  --shadow-glow: 0 8px 24px rgba(88, 86, 214, .25);
  --radius: 18px;
  --radius-lg: 24px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 56px;
  --tab-h: 72px;
  --glass-bg: rgba(255, 255, 255, .72);
  --glass-border: rgba(255, 255, 255, .4);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0f;
    --bg-grad-1: #0a0a0f;
    --bg-grad-2: #11121a;
    --surface: #16171f;
    --surface-2: #1d1e28;
    --surface-3: #262732;
    --text: #f5f6fa;
    --text-2: #9da0b3;
    --text-3: #5a5c6e;
    --border: #25262f;
    --border-strong: #2f3140;
    --accent: #7c7afe;
    --accent-2: #1d1d44;
    --accent-grad-1: #7c7afe;
    --accent-grad-2: #5856d6;
    --accent-grad-3: #c084fc;
    --green: #34d399;
    --green-soft: #0f2a22;
    --red: #f87171;
    --red-soft: #2e1414;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 2px 8px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.5);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.4), 0 32px 60px rgba(0,0,0,.7);
    --shadow-glow: 0 8px 32px rgba(124, 122, 254, .35);
    --glass-bg: rgba(22, 23, 31, .72);
    --glass-border: rgba(255, 255, 255, .06);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  letter-spacing: -0.011em;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ====== Header ====== */
#app-header {
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  background: var(--glass-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 5;
}
#app-title {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header-btn {
  font-size: 22px;
  color: var(--accent);
  font-weight: 600;
  height: 100%;
  transition: opacity .15s;
}
.header-btn:active { opacity: .55; }
#header-back { text-align: left; padding-left: 16px; font-size: 30px; line-height: 1; }
#header-action { text-align: right; padding-right: 16px; font-size: 15px; font-weight: 600; }

/* ====== View ====== */
.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px calc(var(--tab-h) + var(--safe-bottom) + 28px);
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.view::-webkit-scrollbar { display: none; }

/* ====== Tab Bar ====== */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--glass-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 10;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  height: 100%;
  transition: color .15s, transform .15s;
  letter-spacing: 0;
}
.tab svg { opacity: .8; transition: opacity .15s; }
.tab:active { transform: scale(.94); }
.tab.active { color: var(--accent); }
.tab.active svg { opacity: 1; }
.fab-tab { position: relative; }
.fab-circle {
  width: 54px; height: 54px;
  background: linear-gradient(135deg, var(--accent-grad-1), var(--accent-grad-2));
  color: #fff;
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  margin-top: -20px;
  box-shadow: var(--shadow-glow), inset 0 1px 0 rgba(255,255,255,.2);
  transition: transform .15s;
}
.fab-tab:active .fab-circle { transform: scale(.92); }
.fab-tab span:not(.fab-circle) { display: none; }

/* ====== Cards & Sections ====== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 22px 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title:first-child { margin-top: 6px; }

/* ====== Summary card (Hero) ====== */
.summary {
  position: relative;
  background: linear-gradient(135deg, var(--accent-grad-1) 0%, var(--accent-grad-2) 55%, var(--accent-grad-3) 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px 22px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-glow), inset 0 1px 0 rgba(255,255,255,.15);
  overflow: hidden;
  isolation: isolate;
}
.summary::before {
  content: '';
  position: absolute;
  top: -50%; right: -20%;
  width: 240px; height: 240px;
  background: radial-gradient(circle at center, rgba(255,255,255,.18), transparent 70%);
  z-index: -1;
}
.summary::after {
  content: '';
  position: absolute;
  bottom: -60%; left: -10%;
  width: 200px; height: 200px;
  background: radial-gradient(circle at center, rgba(255,255,255,.1), transparent 60%);
  z-index: -1;
}
.summary .label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .8;
}
.summary .net {
  font-size: 38px;
  font-weight: 700;
  margin: 6px 0 14px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.summary .breakdown {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 13px;
  opacity: .95;
}
.summary .breakdown > span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(255,255,255,.12);
  padding: 10px 12px;
  border-radius: 12px;
  flex: 1;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.summary .breakdown b {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ====== Quick-add Tiles ====== */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.quick-tile {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  padding: 14px 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .15s;
  overflow: hidden;
}
.quick-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, var(--tile-tint, transparent) 0%, transparent 60%);
  opacity: .9;
  pointer-events: none;
}
.quick-tile:active { transform: scale(.93); box-shadow: var(--shadow-sm); }
.quick-tile .emoji {
  font-size: 28px;
  line-height: 1;
  z-index: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.08));
}
.quick-tile .label {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  z-index: 1;
  letter-spacing: -0.01em;
}
.quick-tile.add-tile {
  border: 2px dashed var(--border-strong);
  background: transparent;
  box-shadow: none;
  color: var(--text-2);
}
.quick-tile.add-tile::before { display: none; }
.quick-tile.add-tile .emoji {
  font-size: 24px;
  color: var(--text-3);
  filter: none;
}
.quick-tile.add-tile .label { color: var(--text-2); }

/* Tile color variants (cycled via JS data attribute or auto from hash) */
.quick-tile[data-tint="0"] { --tile-tint: rgba(245, 158, 11, .14); }
.quick-tile[data-tint="1"] { --tile-tint: rgba(20, 184, 166, .14); }
.quick-tile[data-tint="2"] { --tile-tint: rgba(168, 85, 247, .14); }
.quick-tile[data-tint="3"] { --tile-tint: rgba(239, 68, 68, .12); }
.quick-tile[data-tint="4"] { --tile-tint: rgba(16, 185, 129, .14); }
.quick-tile[data-tint="5"] { --tile-tint: rgba(59, 130, 246, .14); }
.quick-tile[data-tint="6"] { --tile-tint: rgba(236, 72, 153, .14); }
.quick-tile[data-tint="7"] { --tile-tint: rgba(99, 102, 241, .14); }

/* ====== List rows ====== */
.list {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
  min-height: 60px;
  transition: background .15s;
  width: 100%;
  text-align: left;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row .icon {
  width: 38px; height: 38px; min-width: 38px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -0.01em; }
.row .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.row .amount {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: -0.01em;
}
.row .amount.positive { color: var(--green); }
.row .amount.negative { color: var(--red); }
.row .chev { color: var(--text-3); font-size: 20px; font-weight: 300; }

/* ====== Empty state ====== */
.empty {
  text-align: center;
  color: var(--text-2);
  padding: 48px 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 8px;
}
.empty .emoji { font-size: 48px; margin-bottom: 12px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.08)); }
.empty .title { font-weight: 700; color: var(--text); margin-bottom: 4px; font-size: 16px; }
.empty .desc { font-size: 14px; max-width: 280px; margin: 0 auto; }

/* ====== Buttons ====== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 15px 20px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-grad-1), var(--accent-grad-2));
  color: #fff;
  width: 100%;
  box-shadow: var(--shadow-glow);
  transition: transform .12s, opacity .15s;
  letter-spacing: -0.01em;
}
.btn:active { transform: scale(.97); opacity: .9; }
.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.btn.danger {
  background: linear-gradient(135deg, #f87171, var(--red));
  color: #fff;
  box-shadow: 0 8px 24px rgba(239, 68, 68, .25);
}
.btn.ghost {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row > .btn { flex: 1; }

/* ====== Sheet (modal) ====== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(8, 9, 14, .5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 100;
  opacity: 0;
  transition: opacity .22s;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 92vh;
  background: linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  border-radius: 22px 22px 0 0;
  z-index: 101;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,.0,1);
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -16px 60px rgba(0,0,0,.18);
}
.sheet.show { transform: translateY(0); }
.sheet-handle {
  width: 38px; height: 5px;
  background: var(--text-3);
  border-radius: 3px;
  margin: 10px auto 6px;
  opacity: .35;
}
.sheet-header {
  display: grid;
  grid-template-columns: 70px 1fr 70px;
  align-items: center;
  padding: 6px 16px 12px;
}
.sheet-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
}
.sheet-header button {
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  transition: opacity .15s;
}
.sheet-header button:active { opacity: .5; }
.sheet-header button.primary { font-weight: 700; }
.sheet-header button.left { text-align: left; }
.sheet-header button.right { text-align: right; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
.sheet-body::-webkit-scrollbar { display: none; }

/* ====== Form ====== */
.form-group { margin-bottom: 16px; }
.form-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0 4px 8px;
}
.form-input,
.form-select {
  width: 100%;
  background: var(--surface);
  border: 0;
  border-radius: 14px;
  padding: 15px;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: box-shadow .15s;
}
.form-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%235f6275' d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
.form-input:focus, .form-select:focus { box-shadow: 0 0 0 3px var(--accent-2), var(--shadow-sm); }
.amount-input {
  font-size: 44px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 22px;
  letter-spacing: -0.03em;
  background: transparent;
  box-shadow: none;
}
.amount-input:focus { box-shadow: none; }
.currency-prefix {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-2);
  text-align: center;
  margin-top: 8px;
  margin-bottom: 0;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ====== Picker rows (in sheet) ====== */
.picker-list .row { cursor: pointer; }
.picker-list .row.selected { background: var(--accent-2); }
.picker-list .row.selected .title { color: var(--accent); font-weight: 700; }
.picker-list .row.selected::after { content: "✓"; color: var(--accent); font-weight: 800; font-size: 17px; }

/* ====== Reports ====== */
.report-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 14px;
}
.report-tab {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  transition: all .15s;
  letter-spacing: -0.01em;
}
.report-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}
.date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.date-range .form-input { padding: 12px 14px; font-size: 14px; font-weight: 600; }
.preset-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
}
.preset-pills::-webkit-scrollbar { display: none; }
.pill {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--surface);
  border-radius: 16px;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: all .15s;
  letter-spacing: -0.01em;
}
.pill.active {
  background: linear-gradient(135deg, var(--accent-grad-1), var(--accent-grad-2));
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.report-line {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.report-line .label { color: var(--text); font-weight: 500; }
.report-line.indent .label { padding-left: 18px; color: var(--text-2); font-size: 14px; font-weight: 500; }
.report-line.total {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 8px;
  font-weight: 700;
}
.report-line.grand {
  border-top: 2px solid var(--text);
  margin-top: 10px;
  padding-top: 14px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.report-line .v.positive { color: var(--green); }
.report-line .v.negative { color: var(--red); }

/* ====== Toast ====== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 22px);
  transform: translateX(-50%) translateY(10px);
  background: rgba(20, 21, 26, .94);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity .22s, transform .22s;
  box-shadow: var(--shadow-lg);
  letter-spacing: -0.01em;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ====== Misc ====== */
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.spacer { height: 14px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-2);
  letter-spacing: .02em;
}
.tag.income { background: var(--green-soft); color: var(--green); }
.tag.expense { background: var(--red-soft); color: var(--red); }
.tag.asset { background: var(--accent-2); color: var(--accent); }
.tag.liability { background: #fff4e0; color: var(--orange); }

/* keypad-friendly */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* selection */
::selection { background: var(--accent-2); color: var(--accent); }
