@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,400;0,14..32,500;0,14..32,600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

a, button, input, select, textarea {
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

:root {
  --zinc-50:  #fafafa;
  --zinc-100: #f4f4f5;
  --zinc-200: #e4e4e7;
  --zinc-300: #d4d4d8;
  --zinc-400: #a1a1aa;
  --zinc-500: #71717a;
  --zinc-600: #52525b;
  --zinc-700: #3f3f46;
  --zinc-800: #27272a;
  --zinc-900: #18181b;

  --red-50:   #fef2f2;
  --red-200:  #fecaca;
  --red-600:  #dc2626;
  --red-800:  #991b1b;

  --green-50:  #f0fdf4;
  --green-200: #bbf7d0;
  --green-600: #16a34a;
  --green-800: #166534;

  --amber-50:  #fffbeb;
  --amber-200: #fde68a;
  --amber-600: #d97706;
  --amber-800: #92400e;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
}

html, body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--zinc-900);
  background: var(--zinc-100);
  height: 100%;
  width: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────────────── */

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  height: var(--app-height, 100dvh);
  background: #fff;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  background: #fff;
  border-bottom: 1px solid var(--zinc-100);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--zinc-900);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--zinc-500);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  padding: 0;
}

.back-btn svg {
  width: 16px; height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.page-content {
  padding: 18px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Avatar ─────────────────────────────────────── */

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  background: var(--zinc-900);
  color: #fff;
}

/* ── Cards ──────────────────────────────────────── */

.card {
  background: #fff;
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.card + .card { margin-top: 8px; }

/* ── Summary grid (home totals) ──────────────────── */

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.sum-card {
  border-radius: var(--radius-lg);
  padding: 14px;
  border: 1px solid transparent;
}

.sum-card.owe   { background: var(--red-50);   border-color: var(--red-200); }
.sum-card.owed  { background: var(--green-50); border-color: var(--green-200); }

.sum-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.sum-card.owe  .sum-label { color: var(--red-800); }
.sum-card.owed .sum-label { color: var(--green-800); }

.sum-amount {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.sum-card.owe  .sum-amount { color: var(--red-600); }
.sum-card.owed .sum-amount { color: var(--green-600); }

/* ── Ledger list items ───────────────────────────── */

.section-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--zinc-400);
  margin-bottom: 10px;
}

.ledger-list { display: flex; flex-direction: column; }

.ledger-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--zinc-100);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.ledger-item:last-child { border-bottom: none; }
.ledger-item:active { opacity: 0.7; }

.li-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}

.li-info { flex: 1; min-width: 0; }

.li-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--zinc-900);
  display: flex;
  align-items: center;
  gap: 6px;
}

.li-meta {
  font-size: 11px;
  color: var(--zinc-400);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.li-right { text-align: right; flex-shrink: 0; }

.li-amount {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.li-amount.pos   { color: var(--green-600); }
.li-amount.neg   { color: var(--red-600); }
.li-amount.zero  { color: var(--zinc-400); font-weight: 400; }

/* ── Badges ─────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.6;
}

.badge-amber  { background: var(--amber-50);  color: var(--amber-800);  border: 1px solid var(--amber-200); }
.badge-red    { background: var(--red-50);    color: var(--red-800);    border: 1px solid var(--red-200); }
.badge-green  { background: var(--green-50);  color: var(--green-800);  border: 1px solid var(--green-200); }
.badge-zinc   { background: var(--zinc-100);  color: var(--zinc-500);   border: 1px solid var(--zinc-200); }

/* ── Buttons ─────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.1s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { opacity: 0.75; }

.btn-primary {
  background: var(--zinc-900);
  color: #fff;
  border-color: var(--zinc-900);
}

.btn-secondary {
  background: #fff;
  color: var(--zinc-700);
  border-color: var(--zinc-200);
}

.btn-danger {
  background: var(--red-50);
  color: var(--red-600);
  border-color: var(--red-200);
}

.btn-full { width: 100%; }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* ── FAB ─────────────────────────────────────────── */

.fab-wrap { padding: 12px 18px 16px; }

.fab {
  width: 100%;
  background: var(--zinc-900);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  letter-spacing: -0.01em;
}

.fab:active { opacity: 0.8; }

/* ── Bottom nav ──────────────────────────────────── */

.bottom-nav {
  display: flex;
  border-top: 1px solid var(--zinc-100);
  background: #fff;
  padding: 4px 0 env(safe-area-inset-bottom, 8px);
  position: sticky;
  bottom: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 4px;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  text-decoration: none;
  position: relative;
}

.nav-icon {
  width: 20px; height: 20px;
  stroke: var(--zinc-400);
  fill: none;
  stroke-width: 1.5;
}

.nav-label {
  font-size: 10px;
  color: var(--zinc-400);
  font-weight: 500;
}

.nav-item.active .nav-icon { stroke: var(--zinc-900); }
.nav-item.active .nav-label { color: var(--zinc-900); }

.nav-dot {
  position: absolute;
  top: 6px; right: calc(50% - 14px);
  width: 6px; height: 6px;
  background: var(--amber-600);
  border-radius: 50%;
}

/* ── Forms ───────────────────────────────────────── */

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--zinc-500);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--zinc-100);
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius);
  color: var(--zinc-900);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--zinc-400);
  background: #fff;
}

.field input::placeholder { color: var(--zinc-400); }

/* ── Toggle (who paid) ───────────────────────────── */

.toggle {
  display: flex;
  background: var(--zinc-100);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}

.toggle-opt {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  color: var(--zinc-500);
  transition: all 0.15s;
}

.toggle-opt.active {
  background: #fff;
  color: var(--zinc-900);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ── Hint box ────────────────────────────────────── */

.hint {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.5;
}

.hint-amber { background: var(--amber-50);  color: var(--amber-800);  border: 1px solid var(--amber-200); }
.hint-green { background: var(--green-50);  color: var(--green-800);  border: 1px solid var(--green-200); }
.hint-zinc  { background: var(--zinc-100);  color: var(--zinc-600);   border: 1px solid var(--zinc-200); }

/* ── Balance card (ledger page) ──────────────────── */

.balance-card {
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 18px;
  border: 1px solid var(--zinc-200);
  background: var(--zinc-50);
}

.balance-card--pos {
  background: var(--green-50);
  border-color: var(--green-200);
}

.balance-card--neg {
  background: var(--red-50);
  border-color: var(--red-200);
}

.balance-card--zero {
  background: var(--zinc-50);
  border-color: var(--zinc-200);
}

.balance-card__label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--zinc-500);
  margin-bottom: 6px;
}

.balance-card--pos .balance-card__label { color: var(--green-800); }
.balance-card--neg .balance-card__label { color: var(--red-800); }

.balance-card__amount {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--zinc-900);
  line-height: 1;
}

.balance-card--pos .balance-card__amount { color: var(--green-600); }
.balance-card--neg .balance-card__amount { color: var(--red-600); }
.balance-card--zero .balance-card__amount { color: var(--zinc-400); }

.balance-card__sub {
  font-size: 11px;
  color: var(--zinc-500);
  margin-top: 8px;
}

.balance-card--pos .balance-card__sub { color: var(--green-800); opacity: 0.7; }
.balance-card--neg .balance-card__sub { color: var(--red-800); opacity: 0.7; }


/* ── Ledger card (horizontal card on home) ───────── */

.ledger-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.ledger-card:active { opacity: 0.7; }
.ledger-card:hover { border-color: var(--zinc-300); }

.lc-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.lc-right {
  text-align: right;
  flex-shrink: 0;
  margin-left: 12px;
}

/* ── Tabs ────────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--zinc-100);
  margin-bottom: 14px;
}

.tab-btn {
  flex: 1;
  padding: 9px 8px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--zinc-400);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.tab-btn.active {
  color: var(--zinc-900);
  border-bottom-color: var(--zinc-900);
}

/* ── Expense entries ─────────────────────────────── */

.entry-list { display: flex; flex-direction: column; }

.entry {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--zinc-100);
}

.entry:last-child { border-bottom: none; }

.entry-note {
  font-size: 13px;
  font-weight: 500;
  color: var(--zinc-900);
}

.entry-meta {
  font-size: 11px;
  color: var(--zinc-400);
  margin-top: 2px;
}

.entry-amount {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  margin-left: 12px;
}

.entry-amount.pos  { color: var(--green-600); }
.entry-amount.neg  { color: var(--red-600); }

/* ── Pending card ────────────────────────────────── */

.pending-card {
  background: #fff;
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.pending-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.pending-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--zinc-900);
}

.pending-meta {
  font-size: 11px;
  color: var(--zinc-400);
  margin-top: 2px;
}

.pending-actions { display: flex; gap: 8px; }
.pending-actions .btn { flex: 1; }

/* ── Auth page ───────────────────────────────────── */

.auth-page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.auth-logo {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--zinc-900);
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 13px;
  color: var(--zinc-400);
  margin-bottom: 32px;
}

.auth-footer {
  text-align: center;
  font-size: 12px;
  color: var(--zinc-400);
  margin-top: 18px;
}

.auth-footer a {
  color: var(--zinc-900);
  font-weight: 500;
  text-decoration: none;
}

/* ── Error / toast ───────────────────────────────── */

.error-msg {
  background: var(--red-50);
  border: 1px solid var(--red-200);
  color: var(--red-800);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  margin-bottom: 14px;
  display: none;
}

.error-msg.show { display: block; }

/* ── Offline chip ────────────────────────────────── */

.chip-offline {
  font-size: 10px;
  font-weight: 500;
  color: var(--zinc-400);
  background: var(--zinc-100);
  border-radius: 99px;
  padding: 1px 7px;
}

/* ── Empty state ─────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--zinc-400);
}

.empty-state p { font-size: 13px; margin-top: 6px; }

/* ── Utilities ───────────────────────────────────── */

.text-muted { color: var(--zinc-400); }
.text-sm    { font-size: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.ml-auto { margin-left: auto; }

/* ── Entry edit button ───────────────────────────── */

.entry-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  color: var(--zinc-400);
  text-decoration: none;
  flex-shrink: 0;
}

.entry-edit-btn:hover {
  background: var(--zinc-100);
  color: var(--zinc-600);
}

.entry-edit-btn svg {
  stroke: currentColor;
}