/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100dvh;
  /* Room for bottom nav + iPhone home indicator + a little breathing room */
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
}

header h1 { font-size: 1.2rem; color: #7c85ff; }

/* ─── Tab System ────────────────────────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-inner {
  padding: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* ─── Bottom Nav ────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #1a1d27;
  border-top: 1px solid #2d3148;
  display: flex;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #4a5568;
  cursor: pointer;
  min-height: unset;
  padding: 0;
  transition: color 0.15s;
}
.nav-btn:hover { color: #94a3b8; background: transparent; }
.nav-btn.active { color: #7c85ff; }

.nav-icon { font-size: 1.35rem; line-height: 1; }
.nav-label { font-size: 0.6rem; font-weight: 500; letter-spacing: 0.02em; }

/* ─── Hero Card ─────────────────────────────────────────────────────────────── */
.hero-card {
  background: linear-gradient(135deg, #1a1d27 0%, #1e2035 100%);
  border: 1px solid #2d3148;
  border-radius: 16px;
  padding: 1.75rem 1.5rem 1.5rem;
  margin-bottom: 1rem;
  text-align: center;
}

.hero-label {
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}

.hero-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: #7c85ff;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 1.25rem;
}

.hero-sub-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.hero-sub {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.hero-divider {
  width: 1px;
  height: 2rem;
  background: #2d3148;
  flex-shrink: 0;
}

.hero-sub-label {
  font-size: 0.65rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hero-sub-value {
  font-size: 1.1rem;
  font-weight: 700;
}
.hero-sub-value.green { color: #22c55e; }
.hero-sub-value.red { color: #ef4444; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h2 {
  font-size: 0.8rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card h3 { font-size: 0.85rem; color: #64748b; margin: 1rem 0 0.5rem; }

/* ─── Overview Sub-tabs ─────────────────────────────────────────────────────── */
.widget-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid #2d3148;
  padding-bottom: 0.75rem;
}

.widget-tab {
  background: transparent;
  color: #64748b;
  border: none;
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: unset;
}
.widget-tab:hover { background: #2d3148; color: #e2e8f0; }
.widget-tab.active { background: #7c85ff; color: white; }

.widget-panel { min-height: 7rem; }
.chart-empty { text-align: center; padding: 2rem 0; }

/* ─── Chat (full-screen tab) ─────────────────────────────────────────────────── */
.chat-screen {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 56px - 64px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-input-row {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #2d3148;
  background: #1a1d27;
  margin: 0;
}

.chat-input-row input { flex: 1; }
.chat-input-row button { flex-shrink: 0; min-width: 64px; }

.chat-msg {
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.55;
  max-width: 85%;
}
.chat-msg.user {
  background: #2d3148;
  align-self: flex-end;
  color: #e2e8f0;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  background: #1e2a1e;
  border: 1px solid #2d4a2d;
  color: #86efac;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-msg.assistant p { margin: 0 0 0.5em; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant ul, .chat-msg.assistant ol { margin: 0.25em 0 0.5em 1.25em; padding: 0; }
.chat-msg.assistant li { margin-bottom: 0.2em; }
.chat-msg.assistant strong { color: #bbf7d0; }
.chat-msg.assistant h1, .chat-msg.assistant h2, .chat-msg.assistant h3 { color: #bbf7d0; margin: 0.5em 0 0.25em; font-size: 1em; }
.chat-msg.error { background: #2d1a1a; border: 1px solid #4a2d2d; color: #fca5a5; max-width: 100%; }

/* ─── Profile ───────────────────────────────────────────────────────────────── */
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1.25rem;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #7c85ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: white;
  margin-bottom: 0.75rem;
}

.profile-email { color: #94a3b8; font-size: 0.875rem; }

.btn-danger-outline {
  width: 100%;
  background: transparent;
  border: 1px solid #2d3148;
  color: #94a3b8;
  padding: 0.65rem;
}
.btn-danger-outline:hover { border-color: #ef4444; color: #ef4444; background: transparent; }

.admin-link {
  display: block;
  text-align: center;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: #4a5568;
  text-decoration: none;
}
.admin-link:hover { color: #94a3b8; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
button {
  background: #7c85ff;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
  min-height: 44px;
}
button:hover { background: #6470ff; }
button.small { padding: 0.25rem 0.6rem; font-size: 0.75rem; min-height: 28px; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
form { display: flex; flex-direction: column; gap: 0.6rem; }

input, select, textarea {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: #e2e8f0;
  font-size: 0.875rem;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #7c85ff; }
textarea { resize: vertical; }

/* ─── Account / Bill Rows ───────────────────────────────────────────────────── */
.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid #2d3148;
  font-size: 0.875rem;
  gap: 0.5rem;
}
.account-row:last-child { border-bottom: none; }
.account-row .name { color: #e2e8f0; flex: 1; min-width: 0; }
.account-row .balance { color: #7c85ff; font-weight: 600; white-space: nowrap; }
.account-row .delete-btn { background: transparent; color: #ef4444; font-size: 0.75rem; padding: 0.2rem 0.4rem; min-height: unset; }
.account-row .delete-btn:hover { background: #2d1a1a; }

.bill-row { align-items: flex-start; }
.bill-amounts { display: flex; gap: 1.25rem; }
.bill-col { display: flex; flex-direction: column; align-items: flex-end; font-size: 0.8rem; }
.bill-col small { font-size: 0.68rem; margin-bottom: 0.1rem; color: #64748b; }
.editable-amount { color: #7c85ff; font-weight: 600; cursor: pointer; border-bottom: 1px dashed #7c85ff; }
.editable-amount:hover { color: #a5acff; }
.actual-amount { font-weight: 600; }
.actual-amount.over { color: #ef4444; }
.actual-amount.under { color: #22c55e; }
input.inline-edit { background: #1a1d27; border: 1px solid #7c85ff; border-radius: 4px; color: #e2e8f0; padding: 0.15rem 0.3rem; font-size: 0.875rem; width: auto; min-height: unset; }
.actual-empty { cursor: pointer; border-bottom: 1px dashed #64748b; color: #64748b; }
.actual-empty:hover { color: #94a3b8; }
.updated-label { display: block; font-size: 0.63rem; color: #64748b; margin-top: 0.1rem; }

/* ─── Regex Tester ──────────────────────────────────────────────────────────── */
.regex-row { display: flex; gap: 0.5rem; }
.regex-row input { flex: 1; }
.regex-row button { white-space: nowrap; padding: 0.4rem 0.75rem; font-size: 0.8rem; min-height: unset; }
.regex-results { margin-top: 0.4rem; font-size: 0.8rem; }
.regex-match { padding: 0.2rem 0; border-bottom: 1px solid #2d3148; display: flex; justify-content: space-between; }
.regex-error { color: #ef4444; }

/* ─── Transactions ─────────────────────────────────────────────────────────── */
.txn-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #2d3148;
  font-size: 0.82rem;
  align-items: center;
}
.txn-row:last-child { border-bottom: none; }
.txn-row .desc { color: #e2e8f0; }
.txn-row .cat { color: #64748b; font-size: 0.7rem; margin-top: 0.1rem; }
.txn-row .amt { font-weight: 600; text-align: right; }
.txn-row .amt.expense { color: #ef4444; }
.txn-row .amt.income { color: #22c55e; }

/* ─── Modals ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding: 0;
}

.modal-box {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem 0;
}

.modal-header h3 { font-size: 1rem; color: #e2e8f0; font-weight: 600; }

.modal-close {
  background: transparent;
  color: #64748b;
  border: none;
  font-size: 1rem;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  min-height: unset;
  line-height: 1;
  border-radius: 4px;
}
.modal-close:hover { color: #e2e8f0; background: #2d3148; }

.modal-body {
  padding: 1.25rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0;
}

.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.75rem; color: #94a3b8; font-weight: 500; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.details-toggle {
  background: transparent;
  color: #7c85ff;
  border: 1px dashed #2d3148;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  min-height: unset;
  transition: all 0.15s;
}
.details-toggle:hover { background: #1e2030; border-color: #7c85ff; }

.details-body {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  background: #0f1117;
  border-radius: 8px;
  border: 1px solid #2d3148;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

.btn-secondary {
  background: transparent;
  color: #64748b;
  border: 1px solid #2d3148;
}
.btn-secondary:hover { color: #e2e8f0; border-color: #64748b; background: transparent; }

.add-section-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed #2d3148;
  color: #7c85ff;
  padding: 0.6rem;
  border-radius: 8px;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  min-height: 44px;
  transition: all 0.15s;
}
.add-section-btn:hover { background: #1e2030; border-color: #7c85ff; }

/* ─── Nudge Banner ─────────────────────────────────────────────────────────── */
#nudge-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: #1a2a2a;
  border-bottom: 1px solid #2d4a3a;
  font-size: 0.82rem;
  color: #86efac;
  flex-wrap: wrap;
}
#nudge-banner a { color: #bbf7d0; }
.nudge-dismiss {
  background: transparent;
  color: #64748b;
  border: none;
  padding: 0.1rem 0.3rem;
  font-size: 0.8rem;
  min-height: unset;
  cursor: pointer;
  flex-shrink: 0;
}
.nudge-dismiss:hover { color: #e2e8f0; background: transparent; }

/* ─── Misc ─────────────────────────────────────────────────────────────────── */
.muted { color: #64748b; font-size: 0.85rem; }
hr { border: none; border-top: 1px solid #2d3148; margin: 1rem 0; }

.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100dvh;
  color: #64748b;
}

/* ─── Slurp FAB + Drawer ────────────────────────────────────────────────────── */
#slurp-fab {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  right: 1rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #7c85ff;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(124, 133, 255, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  min-height: unset;
  transition: transform 0.15s, background 0.15s;
}
#slurp-fab:hover { background: #6470ff; transform: scale(1.08); }
#slurp-fab.visible { display: flex; }

#slurp-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
}
#slurp-drawer-overlay.open { display: block; }

#slurp-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  height: 70dvh;
  background: #1a1d27;
  border-radius: 16px 16px 0 0;
  border-top: 1px solid #2d3148;
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
#slurp-drawer.open { transform: translateY(0); }

.drawer-handle {
  width: 36px;
  height: 4px;
  background: #2d3148;
  border-radius: 2px;
  margin: 0.75rem auto 0;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem 0.5rem;
  flex-shrink: 0;
  border-bottom: 1px solid #2d3148;
}

.drawer-header h3 { font-size: 0.9rem; color: #94a3b8; font-weight: 600; }

.drawer-close {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 1rem;
  padding: 0.25rem 0.4rem;
  min-height: unset;
  cursor: pointer;
  border-radius: 4px;
}
.drawer-close:hover { color: #e2e8f0; background: #2d3148; }

.drawer-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.drawer-input-row {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #2d3148;
  flex-shrink: 0;
}
.drawer-input-row input { flex: 1; }
.drawer-input-row button { flex-shrink: 0; min-width: 56px; }

/* ─── Desktop ───────────────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 1rem; }
  .modal-box { border-radius: 16px; }
  .modal-body { padding-bottom: 1.5rem; }
  .form-row { grid-template-columns: 1fr 1fr; }
}
