/* ==========================================================================
   Expense Beacon — design system (mobile-first, light theme)
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --surface-2: #f1f3f5;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --accent: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }

img { max-width: 100%; height: auto; }

/* ---------------------------------------------------------------- layout */
.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 { margin: 0; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row-end { justify-content: flex-end; }
.spacer { flex: 1 1 auto; }

.muted { color: var(--muted); }
.small { font-size: .8rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.hide { display: none !important; }

.pos { color: var(--accent); }
.neg { color: var(--danger); }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; }

/* summary / balance cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.summary-card .label {
  font-size: .78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 6px;
}
.summary-card .value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.summary-card.is-accent { border-color: rgba(16, 185, 129, .35); }
.summary-card.is-accent .value { color: var(--accent); }
.summary-card.is-danger .value { color: var(--danger); }
.summary-card.is-primary .value { color: var(--primary); }
.summary-card.is-warn .value { color: var(--warn); }

/* ----------------------------------------------------------------- forms */
.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.field .hint { font-size: .78rem; color: var(--muted); margin-top: 4px; }

.input, select.input, textarea.input {
  width: 100%;
  font-size: 16px; /* prevents iOS zoom */
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 88px; resize: vertical; line-height: 1.4; }
select.input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.input::placeholder { color: #9ca3af; }
.input:disabled, select.input:disabled { background: var(--surface-2); color: var(--muted); }

.input-error { border-color: var(--danger) !important; }
.error-text { color: var(--danger); font-size: .78rem; margin-top: 4px; }

.field-inline { display: flex; gap: 12px; flex-wrap: wrap; }
.field-inline .field { flex: 1 1 140px; margin-bottom: 0; }

.checkline { display: flex; align-items: center; gap: 8px; }
.checkline input[type="checkbox"] { width: 18px; height: 18px; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; }

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

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #059669; border-color: #059669; }

.btn-sm { min-height: 36px; padding: 0 12px; font-size: .85rem; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-icon { padding: 0 10px; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-business { background: rgba(37, 99, 235, .1); color: var(--primary-600); border-color: rgba(37, 99, 235, .2); }
.badge-personal { background: rgba(16, 185, 129, .1); color: #047857; border-color: rgba(16, 185, 129, .2); }
.badge-success { background: rgba(16, 185, 129, .12); color: #047857; border-color: rgba(16, 185, 129, .25); }
.badge-danger { background: rgba(239, 68, 68, .1); color: #b91c1c; border-color: rgba(239, 68, 68, .2); }
.badge-warn { background: rgba(245, 158, 11, .12); color: #b45309; border-color: rgba(245, 158, 11, .25); }
.badge-default { background: rgba(37, 99, 235, .1); color: var(--primary-600); border-color: rgba(37, 99, 235, .2); }

/* ----------------------------------------------------------------- table */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table th, .table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-2);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }

/* ----------------------------------------------------- mobile card lists */
.mcards { display: none; }
.mcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.mcard + .mcard { margin-top: 10px; }
.mcard-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.mcard-title { font-weight: 700; font-size: 1rem; }
.mcard-amt { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mcard-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.mcard-sub { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.mcard-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.mcard-actions .btn { flex: 1 1 0; }

/* ------------------------------------------------------------ empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty .empty-icon { font-size: 2.2rem; margin-bottom: 8px; }
.empty h3 { color: var(--text); }

/* ----------------------------------------------------------------- flash */
.flash {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: .9rem;
  border: 1px solid transparent;
}
.flash-success { background: rgba(16, 185, 129, .1); border-color: rgba(16, 185, 129, .3); color: #065f46; }
.flash-error { background: rgba(239, 68, 68, .08); border-color: rgba(239, 68, 68, .3); color: #991b1b; }
.flash-icon { font-weight: 700; }
.flash-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: .6;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 2px;
}
.flash-close:hover { opacity: 1; }

/* ------------------------------------------------------------------- nav */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .04);
}
.nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
}
.nav-brand:hover { text-decoration: none; }
.nav-brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .15);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.nav-links a {
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
  padding: 8px 12px;
  border-radius: 9px;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-links a.is-active { color: var(--primary-600); background: rgba(37, 99, 235, .1); }
.nav-links a.nav-add { color: #fff; background: var(--primary); }
.nav-links a.nav-add:hover { background: var(--primary-600); color: #fff; }

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
.nav-user .email { font-size: .82rem; font-weight: 600; color: var(--text); max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.nav-user .cur { font-size: .72rem; color: var(--muted); }
.nav-logout button {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
}
.nav-logout button:hover { color: var(--danger); background: var(--surface-2); }

.nav-burger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}
.nav-burger span,
.nav-burger span::before,
.nav-burger span::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  position: relative;
}
.nav-burger span::before { position: absolute; top: -6px; }
.nav-burger span::after { position: absolute; top: 6px; }

/* mobile drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .4);
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(80vw, 300px);
  background: var(--surface);
  z-index: 70;
  box-shadow: -8px 0 30px rgba(16, 24, 40, .15);
  transform: translateX(100%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.drawer-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}
.drawer-user {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.drawer-user .email { font-weight: 600; font-size: .9rem; word-break: break-all; }
.drawer-user .cur { font-size: .8rem; color: var(--muted); }
.drawer-links { display: flex; flex-direction: column; gap: 2px; }
.drawer-links a {
  display: flex;
  align-items: center;
  color: var(--text);
  font-weight: 600;
  padding: 12px 12px;
  border-radius: 10px;
  min-height: 44px;
}
.drawer-links a:hover { background: var(--surface-2); text-decoration: none; }
.drawer-links a.is-active { color: var(--primary-600); background: rgba(37, 99, 235, .1); }
.drawer-links a.nav-add { color: #fff; background: var(--primary); margin-bottom: 6px; }
.drawer-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

body.drawer-open { overflow: hidden; }
body.drawer-open .drawer-backdrop { opacity: 1; visibility: visible; }
body.drawer-open .drawer { transform: translateX(0); }

/* ----------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  z-index: 80;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.modal-backdrop.is-open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
  width: 100%;
  max-width: 520px;
  margin: auto;
  padding: 20px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h3 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* --------------------------------------------------------------- charts */
.chart-box { position: relative; width: 100%; height: 300px; }
.chart-box.sm { height: 240px; }

/* ----------------------------------------------------------- auth shell */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(37, 99, 235, .08), transparent),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.2rem;
  margin-bottom: 4px;
}
.auth-brand .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 5px rgba(37, 99, 235, .15);
}
.auth-sub { color: var(--muted); margin-bottom: 20px; font-size: .9rem; }
.auth-foot { margin-top: 18px; text-align: center; font-size: .88rem; color: var(--muted); }

/* ---------------------------------------------------------- definition list */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .9rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* code / secret */
.code-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
}

/* =====================================================================
   Responsive — phones
   ===================================================================== */
@media (max-width: 900px) {
  .summary-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .container { padding: 14px; }

  .nav-links, .nav-user { display: none; }
  .nav-burger { display: inline-flex; }
  .nav-inner { gap: 10px; }

  .summary-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .summary-card { padding: 12px; }
  .summary-card .value { font-size: 1.2rem; }

  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  /* swap data tables for mobile card lists */
  .table-wrap.has-mcards { display: none; }
  .mcards { display: block; }

  .page-head h1 { font-size: 1.3rem; }

  .modal { padding: 16px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }

  .field-inline { flex-direction: column; gap: 0; }
  .field-inline .field { margin-bottom: 14px; }

  .chart-box { height: 260px; }
}

@media (min-width: 641px) {
  /* on desktop hide the mobile card lists, show tables */
  .mcards { display: none; }
}
