/* Layout: single column app, emerald gradient hero, glass cards, bottom action dock */
:root {
  --bg: #eef3f0;
  --bg-2: #e3ece7;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --fg: #0f1a15;
  --muted: #5d6e65;
  --line: rgba(15, 40, 28, 0.09);
  --accent: #138a5e;
  --accent-2: #0b5d40;
  --accent-fg: #ffffff;
  --gold: #e6b450;
  --pos: #12855a;
  --neg: #d0492f;
  --shadow: 0 1px 2px rgba(10, 30, 20, .06), 0 8px 24px -8px rgba(10, 30, 20, .14);
  --hero-1: #0d3b2b;
  --hero-2: #138a5e;
  --hero-3: #2fc48b;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Sora", "Manrope", system-ui, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.4, .5, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070d0a;
    --bg-2: #0c1712;
    --surface: rgba(22, 34, 28, 0.72);
    --surface-solid: #131f19;
    --fg: #e8f1ec;
    --muted: #8ea398;
    --line: rgba(200, 255, 225, 0.08);
    --accent: #2fc48b;
    --accent-2: #1f9a6b;
    --accent-fg: #04130c;
    --pos: #4fd69c;
    --neg: #ff7f66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -12px rgba(0, 0, 0, .7);
    --hero-1: #062419;
    --hero-2: #0f6b49;
    --hero-3: #23b07c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 100% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(900px 500px at -20% 10%, color-mix(in srgb, var(--gold) 10%, transparent), transparent 60%),
    linear-gradient(var(--bg), var(--bg-2));
  background-attachment: fixed;
  color: var(--fg);
  font: 500 15px/1.45 var(--font);
  min-height: 100vh;
  padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
}
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; font-family: var(--display); letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 6px 0 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--neg); margin: 10px 0 0; font-size: 14px; animation: shake .4s var(--ease); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

h2 {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 28px 2px 12px;
}
.label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }

/* ---------- Inputs ---------- */
label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--muted); margin: 14px 2px 6px; }
input, select {
  width: 100%; font: 600 16px var(--font); color: var(--fg); background: var(--surface-solid);
  border: 1.5px solid var(--line); border-radius: 14px; padding: 13px 14px; min-width: 0;
  transition: border-color .2s, box-shadow .2s;
  appearance: none; -webkit-appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[readonly] { background: color-mix(in srgb, var(--accent) 7%, var(--surface-solid)); }
#tx-amount { font: 700 28px var(--display); padding: 14px 16px; letter-spacing: -0.02em; }

.btn {
  font: 700 15px var(--font); border: 0; border-radius: 16px; padding: 13px 18px; cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .2s, filter .2s;
}
.btn:active { transform: scale(.96); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-fg);
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}
.btn.wide { width: 100%; margin-top: 20px; padding: 16px; font-size: 16px; }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--accent); font: 700 14px var(--font); cursor: pointer; padding: 6px 8px; border-radius: 8px; transition: background .2s; }
.link:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.link.danger { color: var(--neg); }
.link.danger:hover { background: color-mix(in srgb, var(--neg) 10%, transparent); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line); border-radius: 24px; padding: 28px; box-shadow: var(--shadow);
  animation: rise .6s var(--spring) both;
}
.login-card h1 { margin: 0 0 4px; font: 700 28px var(--display); letter-spacing: -0.03em; }
.login-card h1::before {
  content: "Br"; display: inline-grid; place-items: center; width: 40px; height: 40px; margin-right: 10px; vertical-align: -8px;
  border-radius: 12px; font-size: 17px; color: #fff; background: linear-gradient(135deg, var(--hero-2), var(--hero-3));
}
.login-card .btn { width: 100%; margin-top: 22px; padding: 15px; }

/* ---------- Header ---------- */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.top-inner, .tabs, main { max-width: 640px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top-inner { display: flex; justify-content: space-between; align-items: center; padding-block: 12px 6px; }
.top-inner strong { font: 700 18px var(--display); letter-spacing: -0.02em; }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); position: relative; padding-bottom: 8px; }
.tabs::after {
  content: ""; position: absolute; bottom: 8px; height: calc(100% - 8px); left: 0;
  width: calc((100% - 2 * max(16px, env(safe-area-inset-left, 0px))) / 5);
  margin-left: max(16px, env(safe-area-inset-left, 0px));
  background: var(--surface-solid); border-radius: 12px; box-shadow: var(--shadow); z-index: 0;
  transform: translateX(calc(var(--tab, 0) * 100%)); transition: transform .45s var(--spring);
}
.tab { position: relative; z-index: 1; background: none; border: 0; color: var(--muted); font: 700 13px var(--font); padding: 9px 0; cursor: pointer; transition: color .3s; white-space: nowrap; }
.tab.active { color: var(--fg); }
main { padding-block: 18px; }

/* ---------- Views ---------- */
.view { animation: viewIn .45s var(--ease) both; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; isolation: isolate;
  color: #fff; border-radius: 26px; padding: 22px 22px 20px;
  background: linear-gradient(140deg, var(--hero-1) 0%, var(--hero-2) 60%, var(--hero-3) 120%);
  box-shadow: 0 20px 40px -18px color-mix(in srgb, var(--hero-2) 80%, transparent);
  animation: rise .7s var(--spring) both;
}
.hero::before {
  content: ""; position: absolute; z-index: -1; width: 260px; height: 260px; right: -80px; top: -110px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .28), transparent 65%);
  animation: float 9s ease-in-out infinite;
}
.hero::after {
  content: ""; position: absolute; z-index: -1; width: 220px; height: 220px; left: -70px; bottom: -130px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--gold) 55%, transparent), transparent 65%);
  opacity: .55; animation: float 11s ease-in-out infinite reverse;
}
.hero .label { color: rgba(255, 255, 255, .75); }
.big { font-size: clamp(30px, 9vw, 40px); font-weight: 700; margin: 4px 0 18px; letter-spacing: -0.03em; line-height: 1.1; overflow-wrap: anywhere; }
.month-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.month-row > div {
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 16px; padding: 10px 12px; min-width: 0;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.month-row .num { font-size: 15px; font-weight: 700; color: #fff; overflow-wrap: anywhere; }
.month-row .num::before { display: inline-block; margin-right: 4px; font-size: 13px; opacity: .85; }
#month-in::before { content: "↑"; }
#month-out::before { content: "↓"; }

/* ---------- Glass cards ---------- */
.acct-card, .tx-list, .acct-item, .bars, .summary {
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}

.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.acct-card {
  border-radius: 18px; padding: 14px; min-width: 0; position: relative; overflow: hidden;
  animation: pop .5s var(--spring) both; animation-delay: calc(var(--i, 0) * 60ms + 120ms);
  transition: transform .2s var(--ease);
}
.acct-card:active { transform: scale(.97); }
.acct-card::before {
  content: ""; display: block; width: 28px; height: 28px; border-radius: 9px; margin-bottom: 10px;
  background: linear-gradient(135deg, hsl(var(--h, 155) 60% 45%), hsl(calc(var(--h, 155) + 40) 70% 60%));
}
.acct-card .name { color: var(--muted); font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-card .num { font-weight: 700; font-size: 17px; margin-top: 2px; overflow-wrap: anywhere; }

.bars { display: grid; gap: 14px; border-radius: 18px; padding: 16px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; font-weight: 600; animation: slideIn .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms); }
.bar-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .num { font-size: 13px; color: var(--muted); }
.bar-row .track { grid-column: 1 / -1; height: 10px; background: color-mix(in srgb, var(--fg) 7%, transparent); border-radius: 6px; overflow: hidden; }
.bar-row .fill {
  height: 100%; width: 0; border-radius: 6px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--neg) 70%, var(--gold)), var(--neg));
  transition: width 1s var(--ease); transition-delay: calc(var(--i, 0) * 70ms + 150ms);
}
.bars.person .fill { background: linear-gradient(90deg, var(--hero-3), var(--accent-2)); }
.empty { color: var(--muted); font-size: 14px; padding: 4px 2px; margin: 0; }
.bars .empty { padding: 0; }

/* ---------- Transactions ---------- */
.tx-list { list-style: none; margin: 0; padding: 4px; border-radius: 20px; }
.tx-list:empty { display: none; }
.tx {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 0 12px; align-items: center;
  padding: 12px; border-radius: 16px; position: relative;
  animation: slideIn .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms);
  transition: background .2s;
}
.tx + .tx::before { content: ""; position: absolute; top: 0; left: 64px; right: 12px; border-top: 1px solid var(--line); }
.tx:hover { background: color-mix(in srgb, var(--fg) 4%, transparent); }
.tx.removing { animation: slideOut .35s var(--ease) forwards; }
.tx .ico {
  grid-row: span 2; width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  font: 700 18px var(--display);
}
.tx.in .ico { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.tx.out .ico { background: color-mix(in srgb, var(--neg) 13%, transparent); color: var(--neg); }
.tx .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .meta { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; grid-column: 2; }
.tx .amt { font-weight: 700; text-align: right; font-size: 15px; white-space: nowrap; }
.tx .del { grid-column: 3; justify-self: end; font-size: 12px; padding: 2px 6px; opacity: .7; }
.tx .del:hover { opacity: 1; }

.filters { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; animation: rise .5s var(--ease) both; }
@media (max-width: 460px) { .filters { grid-template-columns: 1fr 1fr; } .filters input { grid-column: 1 / -1; } }
.summary { display: flex; gap: 8px 18px; flex-wrap: wrap; margin: 14px 0; font-size: 14px; font-weight: 700; padding: 14px 16px; border-radius: 16px; }

/* ---------- Accounts ---------- */
.inline-form { display: flex; gap: 8px; animation: rise .5s var(--ease) both; }
.inline-form .btn { white-space: nowrap; }
.acct-list { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 10px; }
.acct-item {
  display: flex; align-items: center; gap: 6px; border-radius: 18px; padding: 12px 10px 12px 14px;
  animation: slideIn .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms);
}
.acct-item::before {
  content: ""; flex: none; width: 34px; height: 34px; border-radius: 11px; margin-right: 6px;
  background: linear-gradient(135deg, hsl(var(--h, 155) 60% 45%), hsl(calc(var(--h, 155) + 40) 70% 60%));
}
.acct-item .grow { flex: 1; min-width: 0; }
.acct-item .grow div:first-child { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-item.empty { background: none; border: 0; box-shadow: none; }
.acct-item.empty::before { display: none; }

/* ---------- Periods ---------- */
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.period-chip {
  width: auto; max-width: 60%; font: 700 13px var(--font); color: #fff; padding: 7px 30px 7px 12px; border-radius: 999px;
  background-color: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22);
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
  text-overflow: ellipsis;
}
.period-chip option { color: var(--fg); background: var(--surface-solid); }
.panel { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 20px; padding: 16px; animation: rise .5s var(--ease) both; }
.panel h3 { margin: 0; font: 700 17px var(--display); }
.period-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.period-item {
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 18px; padding: 14px 16px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  animation: slideIn .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms);
}
.period-item .pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.period-item .range, .period-item .figs { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.period-item .figs { display: flex; gap: 6px 14px; flex-wrap: wrap; font-weight: 700; }
.period-item .btns { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; }
.pill { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 4px 9px; border-radius: 999px; }
.pill.open { color: var(--pos); background: color-mix(in srgb, var(--pos) 14%, transparent); }
.pill.closed { color: var(--muted); background: color-mix(in srgb, var(--fg) 9%, transparent); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: color-mix(in srgb, var(--fg) 7%, transparent); color: var(--fg); }
.btn.ghost.armed { background: var(--neg); color: #fff; }
.tx .lock { grid-column: 3; justify-self: end; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.audit .tx { grid-template-columns: 40px minmax(0, 1fr); }
.audit .tx .title { white-space: normal; }
.tx.edit .ico { background: color-mix(in srgb, var(--gold) 20%, transparent); color: #a8761c; }

/* ---------- Bottom dock ---------- */
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  max-width: 640px; margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  animation: dockIn .6s var(--spring) .2s both;
}
.actions::before {
  content: ""; position: absolute; inset: -20px 0 0; z-index: -1; pointer-events: none;
  background: linear-gradient(transparent, var(--bg-2) 45%);
}
.actions .btn { padding: 16px; font-size: 16px; border-radius: 18px; color: #fff; }
.btn.out { background: linear-gradient(135deg, #ef6a4f, #c23b22); box-shadow: 0 10px 24px -10px rgba(208, 73, 47, .7); }
.btn.in { background: linear-gradient(135deg, var(--hero-3), var(--hero-2)); box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--hero-2) 80%, transparent); }

/* ---------- Sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(3, 10, 7, 0); backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0);
  transition: background .35s, backdrop-filter .35s, -webkit-backdrop-filter .35s;
}
.sheet-backdrop.open { background: rgba(3, 10, 7, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 28px 28px 0 0; border: 1px solid var(--line); border-bottom: 0;
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, .35);
  padding: 10px max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  transform: translateY(105%); transition: transform .5s var(--spring);
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h3 { margin: 0; font: 700 22px var(--display); letter-spacing: -0.02em; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > div { min-width: 0; }
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; position: relative;
  background: color-mix(in srgb, var(--fg) 7%, transparent); border-radius: 14px; padding: 4px; margin-top: 16px;
}
.segmented::before {
  content: ""; position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px);
  background: var(--surface-solid); border-radius: 11px; box-shadow: var(--shadow);
  transform: translateX(calc(var(--seg, 0) * 100%)); transition: transform .4s var(--spring);
}
.seg { position: relative; z-index: 1; font: 700 14px var(--font); border: 0; background: none; color: var(--muted); padding: 10px; cursor: pointer; transition: color .3s; }
.seg.active { color: var(--fg); }
#fx-fields:not([hidden]), #fx-hint:not([hidden]) { animation: rise .35s var(--ease) both; }
#fx-hint { font-weight: 700; color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  background: var(--fg); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
  animation: toastIn .45s var(--spring) both;
}

/* ---------- Keyframes ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(8px); } }
@keyframes viewIn { from { opacity: 0; transform: translateX(var(--dir, 12px)); } }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes slideOut { to { opacity: 0; transform: translateX(40px); height: 0; padding-block: 0; } }
@keyframes dockIn { from { opacity: 0; transform: translateY(40px); } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 16px) scale(.95); } to { transform: translate(-50%, 0); } }
@keyframes float { 50% { transform: translate(-20px, 18px) scale(1.08); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
