/* ── Tokens ────────────────────────────────────────────────────── */
:root {
  --sidebar-bg: #111827;
  --sidebar-w: 240px;
  --brand: #6366f1;
  --brand-h: #4f46e5;
  --brand-light: #eef2ff;
  --brand-muted: rgba(99,102,241,.15);
  --brand-text: #a5b4fc;
  --positive: #059669;
  --positive-bg: #ecfdf5;
  --positive-border: #6ee7b7;
  --negative: #e11d48;
  --negative-bg: #fff1f2;
  --negative-border: #fda4af;
  --warn: #d97706;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --border: #e4e4e7;
  --border-2: #f0f0f1;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;
  --r: 12px;
  --r-sm: 8px;
  --r-xs: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.06),0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08),0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.14),0 8px 16px rgba(0,0,0,.06);
  --mobile-nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --content-max: 960px;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; display: flex; }
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; border: none; }
input, select { font-family: inherit; }
a { text-decoration: none; }

/* ── Auth ──────────────────────────────────────────────────────── */
.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1e1b4b 0%, #111827 50%, #0f172a 100%);
  padding: 24px;
  overflow-y: auto;
}

.auth-inner {
  background: white;
  border-radius: 20px;
  padding: 36px 32px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.auth-brand-mark { margin-bottom: 10px; }

.auth-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-sub { color: var(--text-3); font-size: 14px; margin-bottom: 28px; }

.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 3px;
  margin-bottom: 22px;
  gap: 3px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: var(--r-xs);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  transition: all 0.15s;
}
.auth-tab.active { background: white; color: var(--text); box-shadow: var(--shadow); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }

/* ── Layout ────────────────────────────────────────────────────── */
#main-app { flex: 1; display: flex; overflow: hidden; min-width: 0; }

/* ── Sidebar (desktop only) ────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,.05);
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 14px;
  font-size: 15px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--r-xs);
  color: rgba(255,255,255,.5);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.12s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.85); }
.nav-item.active { background: var(--brand-muted); color: var(--brand-text); }

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,.2);
}

.sidebar-add-btn {
  width: 20px; height: 20px;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  color: rgba(255,255,255,.4);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.1s; flex-shrink: 0;
}
.sidebar-add-btn:hover { background: rgba(255,255,255,.16); color: white; }

.sidebar-group-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--r-xs);
  color: rgba(255,255,255,.5);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
}
.sidebar-group-item:hover { background: rgba(255,255,255,.05); color: rgba(255,255,255,.8); }
.sidebar-group-item.active { background: rgba(255,255,255,.09); color: white; }

.sidebar-group-dot { width: 7px; height: 7px; border-radius: 2px; flex-shrink: 0; }
.sidebar-group-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-group-balance { font-size: 11px; font-weight: 600; flex-shrink: 0; }
.sidebar-group-balance.pos { color: #34d399; }
.sidebar-group-balance.neg { color: #fb7185; }

.sidebar-group-skeleton {
  height: 30px; background: rgba(255,255,255,.04); border-radius: var(--r-xs);
  margin: 2px 0; animation: pulse 1.5s ease-in-out infinite;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-user { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.sidebar-user-meta { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-meta span:first-child { font-size: 12.5px; font-weight: 600; color: rgba(255,255,255,.85); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-meta span:last-child { font-size: 11px; color: rgba(255,255,255,.3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Avatars ───────────────────────────────────────────────────── */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white; flex-shrink: 0;
}
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.avatar.xs { width: 20px; height: 20px; font-size: 8px; }
.avatar.lg { width: 42px; height: 42px; font-size: 16px; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: none; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-h); }
.btn-primary:active { transform: scale(.97); }
.btn-secondary { background: var(--bg); color: var(--text-2); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--negative-bg); color: var(--negative); }
.btn-danger:hover { background: #fecdd3; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 13px 20px; font-size: 15px; font-weight: 600; }
.btn-full { width: 100%; }

.btn-icon-dark {
  width: 30px; height: 30px; background: transparent; border-radius: var(--r-xs);
  color: rgba(255,255,255,.3); display: flex; align-items: center; justify-content: center; transition: all 0.1s;
}
.btn-icon-dark:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.7); }

.back-btn {
  width: 34px; height: 34px; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: all 0.1s; flex-shrink: 0;
}
.back-btn:hover { border-color: var(--brand); color: var(--brand); }

/* ── Forms ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.opt { font-size: 11px; font-weight: 400; color: var(--text-3); }

/* 16px minimum on mobile to prevent iOS zoom */
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
input::placeholder { color: var(--text-3); }
select { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.amount-input-wrap {
  display: flex; align-items: stretch; border: 1.5px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.amount-input-wrap:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.amount-prefix { padding: 0 12px; background: var(--bg); color: var(--text-3); font-size: 15px; font-weight: 500; border-right: 1.5px solid var(--border); white-space: nowrap; display: flex; align-items: center; }
.amount-input-wrap input { border: none; border-radius: 0; box-shadow: none; flex: 1; }
.amount-input-wrap input:focus { box-shadow: none; border: none; }

.form-error { padding: 11px 14px; background: var(--negative-bg); color: var(--negative); border-radius: var(--r-sm); font-size: 13.5px; border: 1px solid var(--negative-border); }
.flex-1 { flex: 1; }
.field-hint { font-size: 12px; color: var(--text-3); }

/* ── Main content ──────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; min-width: 0; }
.view { flex: 1; }

/* ── Dashboard ─────────────────────────────────────────────────── */
.dash-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 28px 28px 0; gap: 12px;
}
#dash-greeting { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.dash-sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }

.dash-balances { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 20px 28px 0; }

.dash-balance-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 18px 16px; display: flex; align-items: flex-start; gap: 12px; box-shadow: var(--shadow);
}
.dash-balance-icon { width: 36px; height: 36px; border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.positive-card .dash-balance-icon { background: var(--positive-bg); color: var(--positive); }
.negative-card .dash-balance-icon { background: var(--negative-bg); color: var(--negative); }
.dash-balance-label { font-size: 11.5px; font-weight: 500; color: var(--text-3); margin-bottom: 4px; }
.dash-balance-num { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.positive-card .dash-balance-num { color: var(--positive); }
.negative-card .dash-balance-num { color: var(--negative); }

.section-label { padding: 24px 28px 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }

/* ── Groups list ───────────────────────────────────────────────── */
.groups-list { padding: 0 28px 120px; display: flex; flex-direction: column; gap: 8px; }

.group-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px 18px; cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.group-card:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99,102,241,.07), var(--shadow-md); }
.group-card:active { transform: scale(.99); }

.group-card-icon { font-size: 22px; width: 44px; height: 44px; background: var(--bg); border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.group-card-body { flex: 1; min-width: 0; }
.group-card-name { font-size: 14.5px; font-weight: 600; color: var(--text); margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-card-meta { font-size: 12px; color: var(--text-3); }
.group-card-right { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.group-card-balance { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; }
.group-card-balance.pos { color: var(--positive); }
.group-card-balance.neg { color: var(--negative); }
.group-card-balance.zero { font-size: 12px; font-weight: 500; color: var(--text-3); }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h4 { font-size: 15px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

/* ── Group detail ──────────────────────────────────────────────── */
.group-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-2);
  position: sticky; top: 0; z-index: 20;
}
.group-header-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.group-header-info h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.currency-badge { font-size: 10.5px; font-weight: 700; color: var(--brand); background: var(--brand-light); padding: 2px 8px; border-radius: 20px; flex-shrink: 0; }

/* ── Balance banner ────────────────────────────────────────────── */
.balance-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; border-bottom: 1px solid transparent;
}
.balance-banner.owing { background: var(--negative-bg); border-color: var(--negative-border); }
.balance-banner.owed { background: var(--positive-bg); border-color: var(--positive-border); }
.balance-banner.settled { background: var(--bg); border-color: var(--border); }
.bb-text { font-size: 13.5px; font-weight: 500; }
.balance-banner.owing .bb-text { color: var(--negative); }
.balance-banner.owed .bb-text { color: var(--positive); }
.balance-banner.settled .bb-text { color: var(--text-3); }
.bb-text strong { font-weight: 700; }
.bb-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Group tabs ────────────────────────────────────────────────── */
.gtabs-bar {
  display: flex; background: var(--surface);
  border-bottom: 1px solid var(--border-2);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.gtabs-bar::-webkit-scrollbar { display: none; }

.gtab {
  padding: 12px 18px; border: none; background: transparent;
  font-size: 13.5px; font-weight: 500; color: var(--text-3); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all 0.15s; white-space: nowrap; flex-shrink: 0;
}
.gtab:hover { color: var(--text); }
.gtab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.gtab-panels { padding: 20px; }
.gtab-panel { min-height: 200px; }

/* ── Expense timeline ──────────────────────────────────────────── */
.exp-day-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-3); padding: 0 0 8px; margin-top: 20px; }
.exp-day-label:first-child { margin-top: 0; }

.expense-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--r);
  margin-bottom: 6px; transition: all 0.15s; position: relative;
}
.expense-row:hover { border-color: var(--border); box-shadow: var(--shadow-md); }
.expense-row:hover .exp-del { opacity: 1; }

.exp-emoji { width: 40px; height: 40px; background: var(--bg); border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.exp-body { flex: 1; min-width: 0; }
.exp-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-meta { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.exp-splits { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.exp-split-chip { display: flex; align-items: center; gap: 3px; background: var(--bg); border-radius: 20px; padding: 1px 7px 1px 3px; font-size: 11px; color: var(--text-2); }
.exp-right { flex-shrink: 0; text-align: right; }
.exp-total { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.exp-share { font-size: 12px; font-weight: 600; margin-top: 2px; }
.exp-share.pos { color: var(--positive); }
.exp-share.neg { color: var(--negative); }
.exp-share.neutral { color: var(--text-3); }
.exp-del { opacity: 0; background: transparent; color: var(--text-3); padding: 5px; border-radius: 5px; transition: all 0.1s; flex-shrink: 0; }
.exp-del:hover { color: var(--negative); background: var(--negative-bg); }

/* ── Balances tab ──────────────────────────────────────────────── */
.bal-section { margin-bottom: 24px; }
.bal-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 10px; }
.bal-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r); margin-bottom: 6px; }
.bal-row-left { display: flex; align-items: center; gap: 10px; }
.bal-row-name { font-size: 13.5px; font-weight: 500; color: var(--text); }
.bal-row-amount { font-size: 13.5px; font-weight: 700; }
.bal-row-amount.pos { color: var(--positive); }
.bal-row-amount.neg { color: var(--negative); }
.bal-row-amount.zero { font-size: 12px; font-weight: 500; color: var(--text-3); }

.txn-card { background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r); padding: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }
.txn-flow { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.txn-person { display: flex; align-items: center; gap: 6px; min-width: 0; }
.txn-person span { font-size: 13px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-arrow { flex: 1; height: 1px; background: var(--border); position: relative; display: flex; align-items: center; justify-content: center; min-width: 24px; }
.txn-arrow::after { content: '→'; position: absolute; font-size: 14px; color: var(--text-3); background: var(--surface); padding: 0 4px; }
.txn-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.txn-amount { font-size: 15px; font-weight: 700; color: var(--warn); letter-spacing: -0.02em; }

/* ── People tab ────────────────────────────────────────────────── */
.people-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.people-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r); }
.people-info { flex: 1; min-width: 0; }
.people-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.people-email { font-size: 12px; color: var(--text-3); }
.people-badge { font-size: 10.5px; font-weight: 600; background: var(--brand-light); color: var(--brand); padding: 2px 8px; border-radius: 20px; }
.people-creator-badge { font-size: 10.5px; font-weight: 600; background: var(--bg); color: var(--text-3); padding: 2px 8px; border-radius: 20px; }
.add-member-form { margin-top: 8px; }
.add-member-form .field-row { display: flex; gap: 8px; align-items: flex-end; }
.add-member-form .field { flex: 1; }

/* ── Activity ──────────────────────────────────────────────────── */
.activity-item { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border-2); }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.activity-dot.exp { background: var(--brand-light); }
.activity-dot.settle { background: var(--positive-bg); }
.activity-body { flex: 1; }
.activity-desc { font-size: 13.5px; color: var(--text-2); line-height: 1.5; }
.activity-desc strong { color: var(--text); font-weight: 600; }
.activity-time { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

/* ── Skeleton ──────────────────────────────────────────────────── */
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.skeleton { background: linear-gradient(90deg, var(--border-2) 25%, var(--border) 50%, var(--border-2) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--r-xs); }
.skeleton-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r); margin-bottom: 6px; }

/* ── Split UI ──────────────────────────────────────────────────── */
.split-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.split-toggle { display: flex; background: var(--bg); border-radius: var(--r-xs); padding: 2px; gap: 2px; }
.stbtn { padding: 5px 14px; border: none; background: transparent; border-radius: 4px; font-size: 13px; font-weight: 500; color: var(--text-3); transition: all 0.1s; }
.stbtn.active { background: white; color: var(--brand); box-shadow: var(--shadow); }
.splits-container { border-top: 1px solid var(--border-2); }
.split-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border-2); }
.split-row:last-of-type { border-bottom: none; }
.split-row-name { display: flex; align-items: center; gap: 8px; flex: 1; font-size: 14px; color: var(--text); font-weight: 500; }
.split-row-you { font-size: 11px; color: var(--text-3); }
.split-eq-amount { font-size: 14px; font-weight: 600; color: var(--text-2); min-width: 80px; text-align: right; }
.split-amt-input { width: 100px; padding: 8px 10px; font-size: 14px; text-align: right; }
.split-total-row { display: flex; justify-content: space-between; padding: 10px 0 0; font-size: 13px; color: var(--text-3); border-top: 1.5px dashed var(--border); margin-top: 6px; }
.split-total-row span:last-child { font-weight: 700; }
.ok { color: var(--positive); }
.err { color: var(--negative); }

/* ── Modals ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.48);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; backdrop-filter: blur(2px);
  animation: fadein 0.2s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 24px calc(24px + var(--safe-bottom));
  width: 100%; max-width: 540px;
  max-height: 92vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  animation: slideup 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: var(--shadow-lg);
}
@keyframes slideup { from { transform: translateY(60px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 6px auto 0; flex-shrink: 0; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding-top: 4px; }
.modal-header h3 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.modal-close { width: 30px; height: 30px; background: var(--bg); border-radius: 50%; font-size: 18px; color: var(--text-3); display: flex; align-items: center; justify-content: center; transition: all 0.1s; }
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.expense-amount-row { display: flex; gap: 12px; }

.settle-context { background: var(--bg); border-radius: var(--r-sm); padding: 12px 14px; font-size: 14px; color: var(--text-2); line-height: 1.5; }
.settle-context strong { color: var(--text); }

/* ── FAB ───────────────────────────────────────────────────────── */
.fab {
  position: fixed; right: 20px;
  bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 16px);
  width: 54px; height: 54px;
  background: var(--brand); color: white; border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,.5);
  transition: all 0.2s; z-index: 40;
}
.fab:hover { background: var(--brand-h); transform: scale(1.07); }
.fab:active { transform: scale(.95); }

/* ── Mobile bottom nav ─────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--mobile-nav-h) + var(--safe-bottom));
  background: white;
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 50;
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}

.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; background: transparent; border: none; cursor: pointer;
  color: var(--text-3); font-size: 10.5px; font-weight: 500;
  transition: color 0.15s; padding: 6px 4px; -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item.active { color: var(--brand); }
.mobile-nav-item.active svg { stroke: var(--brand); }

.mnav-plus {
  width: 46px; height: 30px; background: var(--brand); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,.4);
}

.mnav-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: white;
}

/* ── Sheets (mobile groups / account) ─────────────────────────── */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 60; display: flex; align-items: flex-end;
  animation: fadein 0.2s ease;
}

.sheet {
  background: white; border-radius: 20px 20px 0 0;
  width: 100%; max-height: 80vh; overflow-y: auto;
  padding: 0 0 calc(16px + var(--safe-bottom));
  animation: slideup 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 12px auto 8px; }

.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px 12px; border-bottom: 1px solid var(--border-2);
}
.sheet-header h3 { font-size: 16px; font-weight: 700; }

.sheet-groups-list { padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }

.sheet-group-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px; border-radius: var(--r-sm); cursor: pointer;
  transition: background 0.1s; -webkit-tap-highlight-color: transparent;
}
.sheet-group-item:active { background: var(--bg); }

.sheet-group-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.sheet-group-name { flex: 1; font-size: 15px; font-weight: 500; color: var(--text); }
.sheet-group-balance { font-size: 14px; font-weight: 700; }
.sheet-group-balance.pos { color: var(--positive); }
.sheet-group-balance.neg { color: var(--negative); }
.sheet-group-balance.zero { font-size: 12px; font-weight: 500; color: var(--text-3); }

.sheet-account {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px 14px; border-bottom: 1px solid var(--border-2);
}
.sheet-account-avatar { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; color: white; flex-shrink: 0; }
.sheet-account-info { flex: 1; }
.sheet-account-info div:first-child { font-size: 16px; font-weight: 600; color: var(--text); }
.sheet-account-info div:last-child { font-size: 13px; color: var(--text-3); }

.sheet-logout-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 16px 20px; background: transparent; border: none;
  font-size: 15px; font-weight: 500; color: var(--negative); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sheet-logout-btn:active { background: var(--negative-bg); }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 10px 20px; border-radius: 30px;
  font-size: 14px; font-weight: 500; z-index: 200; box-shadow: var(--shadow-lg);
  animation: toastin 0.2s ease; white-space: nowrap;
}
@keyframes toastin { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.page-load-state { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--text-3); font-size: 13px; }

/* ── Desktop (>= 1024px) ───────────────────────────────────────── */
@media (min-width: 1024px) {
  .mobile-nav { display: none !important; }
  .sheet-overlay { display: none !important; }
  .fab { bottom: 28px; right: 28px; }
  .toast { bottom: 28px; }
  .groups-list { padding-bottom: 32px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .groups-list .empty-state { grid-column: 1 / -1; }
  .gtab-panels { padding: 24px; }
  .modal { border-radius: 20px; max-width: 500px; padding: 24px; margin: auto; }
  .modal-overlay { align-items: center; }
  .modal-handle { display: none; }
}

/* ── Large desktop (>= 1280px) ────────────────────────────────── */
@media (min-width: 1280px) {
  .dash-top,
  .dash-balances,
  .section-label,
  .groups-list,
  .gtab-panels {
    max-width: var(--content-max);
    margin-left: auto;
    margin-right: auto;
  }
}

/* ── XL desktop (>= 1440px) ───────────────────────────────────── */
@media (min-width: 1440px) {
  :root { --sidebar-w: 260px; }

  .groups-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .dash-top     { padding-top: 36px; }
  .dash-balances { padding-top: 28px; gap: 16px; }
}

/* ── Tablet + Mobile (< 1024px) ────────────────────────────────── */
@media (max-width: 1023px) {
  .sidebar { display: none; }
  .mobile-nav { display: flex; align-items: stretch; }
  .main-content { padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom)); }
  .fab { bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 16px); right: 16px; }

  /* Bigger touch targets everywhere */
  .group-card { padding: 14px 16px; }
  .gtab { padding: 13px 16px; font-size: 14px; }
  .expense-row { padding: 14px; }
  .exp-del { opacity: 1; } /* always visible on mobile */
}

/* ── Tablet (768px - 1023px) ───────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  .dash-top { padding: 28px 32px 0; }
  .dash-balances { padding: 20px 32px 0; gap: 16px; }
  .dash-balance-num { font-size: 26px; }
  .section-label { padding: 24px 32px 10px; }
  .groups-list { padding: 0 32px 120px; }
  .groups-list { display: grid; grid-template-columns: 1fr 1fr; }
  .groups-list .empty-state { grid-column: 1 / -1; }
  .group-header { padding: 18px 24px 14px; }
  .gtabs-bar { padding: 0 4px; }
  .gtab-panels { padding: 24px; }
  .expense-amount-row { gap: 16px; }

  .modal { border-radius: 20px; max-width: 500px; padding: 24px; margin: auto; }
  .modal-overlay { align-items: center; }
  .modal-handle { display: none; }
}

/* ── Mobile only (< 768px) ─────────────────────────────────────── */
@media (max-width: 767px) {
  .auth-inner { padding: 32px 24px 36px; margin: 0; border-radius: 20px; }
  .auth-screen { padding: 16px; align-items: center; }
  .auth-title { font-size: 26px; }

  .dash-top { padding: 20px 16px 0; }
  #dash-greeting { font-size: 20px; }
  .dash-balances { grid-template-columns: 1fr 1fr; padding: 16px; gap: 10px; }
  .dash-balance-card { padding: 14px; gap: 10px; }
  .dash-balance-num { font-size: 20px; }
  .dash-balance-icon { width: 30px; height: 30px; }
  .section-label { padding: 18px 16px 8px; }
  .groups-list { padding: 0 16px 120px; }
  .group-card-name { font-size: 15px; }
  .group-card-balance { font-size: 15px; }

  .group-header { padding: 12px 14px 10px; gap: 10px; }
  .group-header-info h2 { font-size: 16px; }
  .balance-banner { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .bb-text { font-size: 13px; flex: 1; min-width: 0; }
  .bb-actions { width: 100%; display: flex; justify-content: flex-end; }
  .gtabs-bar { padding: 0; }
  .gtab { padding: 12px 14px; font-size: 13px; }
  .gtab-panels { padding: 14px; }

  .expense-row { padding: 11px 12px; gap: 10px; }
  .exp-emoji { width: 36px; height: 36px; font-size: 16px; }
  .exp-name { font-size: 14px; }
  .exp-total { font-size: 14px; }

  .txn-card { flex-wrap: wrap; gap: 10px; }
  .txn-right { width: 100%; justify-content: flex-end; }

  .expense-amount-row { flex-direction: column; gap: 12px; }

  .modal { max-height: 96vh; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .btn { width: 100%; padding: 14px; }

  .fab { width: 52px; height: 52px; right: 16px; }

  .add-member-form .field-row { flex-direction: column; }
  .add-member-form .field-row .btn { width: 100%; }

  .split-label-row { flex-wrap: wrap; gap: 8px; }
  .split-label-row label { flex: 1 0 100%; }
}
