/* Family Expense Tracker — Dark Theme matching portfolio */
:root {
  --bg: #0a0a0a;
  --bg2: #111111;
  --bg3: #1a1a1a;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-muted: #888;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim: rgba(59, 130, 246, 0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.15);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim: rgba(59, 130, 246, 0.1);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.1);
  --success: #16a34a;
  --success-dim: rgba(22, 163, 74, 0.1);
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

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

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  transition: all var(--transition);
}

input, select, textarea {
  font-family: inherit;
  font-size: 0.9375rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.625rem 0.875rem;
  width: 100%;
  transition: border-color var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Layout ── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Nav ── */
.nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: auto;
}

.nav-brand span { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  background: none;
  color: var(--text-muted);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

.nav-link:hover, .nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

.avatar-placeholder {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
}

/* ── Main content ── */
.main { flex: 1; padding: 1.5rem 1.25rem; max-width: 900px; margin: 0 auto; width: 100%; }

/* ── Views ── */
.view { display: none; }
.view.active { display: block; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}

.login-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.9375rem;
}

.login-divider {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 1.5rem 0;
}

.google-btn-wrapper {
  display: flex;
  justify-content: center;
}

/* ── Cards ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

/* ── Stat cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.375rem;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.stat-change {
  font-size: 0.8125rem;
  margin-top: 0.25rem;
  font-weight: 500;
}

.stat-change.up { color: var(--danger); }
.stat-change.down { color: var(--success); }
.stat-change.neutral { color: var(--text-muted); }

/* ── Category bars ── */
.category-bars { display: flex; flex-direction: column; gap: 0.625rem; }

.cat-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
}

.cat-icon { text-align: center; font-size: 1rem; }

.cat-bar-wrap {
  background: var(--bg3);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
}

.cat-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.6s ease;
}

.cat-amount {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  min-width: 90px;
  text-align: right;
}

.cat-name {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── Person chips ── */
.person-chips { display: flex; flex-wrap: wrap; gap: 0.625rem; }

.person-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.375rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.person-chip .chip-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  object-fit: cover;
}

.person-chip .chip-name { font-weight: 500; }
.person-chip .chip-amount { color: var(--accent); font-weight: 600; }

/* ── Expense list ── */
.expense-list { display: flex; flex-direction: column; gap: 0.5rem; }

.expense-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.875rem;
  transition: background var(--transition);
}

.expense-item:hover { background: var(--bg3); }

.expense-icon {
  font-size: 1.375rem;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.expense-info { min-width: 0; }

.expense-desc {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

.expense-amount {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  white-space: nowrap;
}

.expense-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.expense-delete {
  background: none;
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
}

.expense-item:hover .expense-delete { opacity: 1; }
.expense-delete:hover { color: var(--danger); }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

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

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
}

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

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

.btn-icon {
  background: none;
  color: var(--text-muted);
  padding: 0.375rem;
  border-radius: var(--radius-sm);
}

.btn-icon:hover { background: var(--bg3); color: var(--text); }

.btn-full { width: 100%; justify-content: center; }

/* ── Member list ── */
.member-list { display: flex; flex-direction: column; gap: 0.5rem; }

.member-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
}

.member-item:last-child { border-bottom: none; }

.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 500; }
.member-email { font-size: 0.8125rem; color: var(--text-muted); }

.role-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.role-badge.owner {
  background: var(--accent-dim);
  color: var(--accent);
}

.role-badge.member {
  background: var(--bg3);
  color: var(--text-muted);
}

/* ── Month picker ── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.month-nav .month-label {
  font-size: 1.125rem;
  font-weight: 700;
  flex: 1;
}

/* ── Filters ── */
.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filters select {
  width: auto;
  min-width: 140px;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h3 { font-size: 1.125rem; margin-bottom: 0.5rem; color: var(--text); }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.875rem 1.25rem;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 240px;
  animation: toastIn 0.25s ease;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(1rem); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Theme toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0.375rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
}

.theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Section heading ── */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

/* ── No-family setup ── */
.setup-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  margin-top: 2rem;
}

.setup-card h2 { margin-bottom: 0.5rem; }
.setup-card p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ── Loading ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 2rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Inline input row ── */
.input-row {
  display: flex;
  gap: 0.5rem;
}

.input-row input { flex: 1; }

/* ── Daily sparkline ── */
.sparkline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 48px;
  margin-top: 0.75rem;
}

.spark-bar {
  flex: 1;
  background: var(--accent-dim);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: background var(--transition);
  cursor: default;
}

.spark-bar:hover { background: var(--accent); }

/* ── Pending invites ── */
.invite-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.invite-item:last-child { border-bottom: none; }
.invite-email { font-weight: 500; }
.invite-status { font-size: 0.8rem; color: var(--warning); }

/* ── Auth tabs ── */
.auth-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  background: none;
  color: var(--text-muted);
  border-radius: calc(var(--radius-sm) - 2px);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
}

.auth-tab.active {
  background: var(--bg2);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.auth-tab:hover:not(.active) { color: var(--text); }

.auth-panel { display: none; }
.auth-panel.active { display: block; }

/* ── Form error ── */
.form-error {
  color: var(--danger);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--danger-dim);
  border-radius: var(--radius-sm);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .nav-links { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.375rem; }
  .filters { flex-direction: column; }
  .filters select { width: 100%; }
  .main { padding: 1rem; padding-bottom: 80px; }

  .login-card { padding: 2rem 1.25rem; margin: 1rem; border-radius: var(--radius); }
  .login-page { align-items: flex-start; padding-top: 2rem; }

  input, select, textarea { min-height: 44px; }
  .btn { min-height: 44px; }
  .bottom-nav-item { min-height: 56px; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 100;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.7rem;
    gap: 0.125rem;
    background: none;
    border: none;
    cursor: pointer;
  }

  .bottom-nav-item.active { color: var(--accent); }
  .bottom-nav-item .bnav-icon { font-size: 1.25rem; }

  body { padding-bottom: 60px; }
}

@media (min-width: 641px) {
  .bottom-nav { display: none; }
}
