/* Bill Command Center — Styles */

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg: #0a0a0f;
  --surface: #141420;
  --surface-2: #1e1e2e;
  --surface-3: #2a2a3a;
  --border: #2a2a3a;
  --text: #f0f0f5;
  --text-dim: #8888a0;
  --text-muted: #555570;
  --green: #22c55e;
  --green-dim: #166534;
  --amber: #f59e0b;
  --amber-dim: #92400e;
  --red: #ef4444;
  --red-dim: #991b1b;
  --blue: #3b82f6;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); text-decoration: none; }

/* ── App Layout ────────────────────────────────────────── */
.app { min-height: 100dvh; padding-bottom: calc(var(--nav-height) + var(--safe-bottom)); }
.main-content { padding: 16px 16px 24px; max-width: 600px; margin: 0 auto; }
.loading { text-align: center; padding: 60px 0; color: var(--text-dim); font-size: 1.1rem; }

/* ── PIN Screen ────────────────────────────────────────── */
.pin-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.pin-container { text-align: center; width: 100%; max-width: 320px; padding: 20px; }
.pin-logo { font-size: 48px; margin-bottom: 8px; }
.pin-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 32px; letter-spacing: -0.02em; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin-bottom: 16px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--text-dim);
  transition: all 0.15s ease;
}
.pin-dot.filled { background: var(--green); border-color: var(--green); transform: scale(1.1); }
.pin-error { color: var(--red); font-size: 0.9rem; height: 24px; }
.pin-hint { color: var(--text-dim); font-size: 0.9rem; height: 24px; }
.pin-pad {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; max-width: 280px; margin: 24px auto 0;
}
.pin-key {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--surface-2); font-size: 1.5rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.pin-key:active { background: var(--surface-3); transform: scale(0.93); }
.pin-key.empty { background: transparent; pointer-events: none; }

/* ── Bottom Nav ────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
  z-index: 900;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 12px; border-radius: 12px;
  transition: color 0.15s;
  color: var(--text-dim);
  min-width: 56px;
}
.nav-item.active { color: var(--green); }
.nav-icon { font-size: 1.4rem; }
.nav-label { font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Page Title ────────────────────────────────────────── */
.page-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 16px; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.75rem; }
.card-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-header-row .card-title { margin-bottom: 0; }

/* ── Coverage Meter ────────────────────────────────────── */
.coverage-card { text-align: center; }
.coverage-meter { margin-bottom: 16px; }
.meter-svg { width: 200px; max-width: 100%; }
.meter-fill { transition: stroke-dasharray 0.8s ease; }
.meter-pct { font-size: 36px; font-weight: 800; fill: var(--text); }
.meter-label { font-size: 13px; fill: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.coverage-amounts { display: flex; align-items: center; justify-content: center; gap: 12px; }
.coverage-item { text-align: center; }
.coverage-value { font-size: 1.3rem; font-weight: 700; display: block; }
.coverage-sublabel { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; font-weight: 600; letter-spacing: 0.04em; }
.coverage-divider { color: var(--text-muted); font-size: 1.5rem; font-weight: 300; }

/* ── Stats Grid ────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stats-3 { grid-template-columns: 1fr 1fr 1fr; }
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px;
  border: 1px solid var(--border);
  text-align: center;
}
.stat-value { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; font-weight: 600; margin-top: 4px; letter-spacing: 0.04em; }

/* ── Net Card ──────────────────────────────────────────── */
.net-card { display: flex; align-items: center; justify-content: space-between; }
.net-label { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.net-value { font-size: 1.5rem; font-weight: 800; }

/* ── Priority Stack ────────────────────────────────────── */
.priority-stack { display: flex; flex-direction: column; gap: 2px; }
.priority-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px; border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.priority-item.covered { background: rgba(34,197,94,0.06); }
.priority-item.partial { background: rgba(245,158,11,0.06); }
.priority-item.uncovered { background: rgba(239,68,68,0.06); }
.priority-item.paid { opacity: 0.5; }
.priority-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.priority-info { min-width: 0; }
.priority-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.priority-meta { font-size: 0.75rem; color: var(--text-dim); }
.priority-right { text-align: right; flex-shrink: 0; }
.priority-amount { font-weight: 700; font-size: 1rem; }
.priority-cumulative { font-size: 0.7rem; font-weight: 600; }
.check-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--text-dim); display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: var(--text-dim); flex-shrink: 0;
  transition: all 0.15s;
}
.check-btn:active { border-color: var(--green); color: var(--green); background: rgba(34,197,94,0.1); }
.check-done { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--green); font-size: 1.1rem; flex-shrink: 0; }
.paid-text { text-decoration: line-through; opacity: 0.6; }
.paid-divider {
  text-align: center; font-size: 0.7rem; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 12px 0 4px; border-top: 1px solid var(--border); margin-top: 8px;
}
.coverage-line {
  text-align: center; padding: 6px 0;
  font-size: 0.7rem; font-weight: 700; color: var(--amber);
  letter-spacing: 0.04em;
}

/* ── Activity ──────────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-name { font-weight: 600; font-size: 0.9rem; }
.activity-date { font-size: 0.75rem; color: var(--text-dim); }
.activity-amount { font-weight: 700; }

/* ── Bills Page ────────────────────────────────────────── */
.filters-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-input, .filter-select {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: 0.9rem; color: var(--text); flex: 1; min-width: 0;
}
.filter-select { flex: 0 0 auto; min-width: 130px; }
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus, .filter-select:focus { border-color: var(--green); }

.bills-list, .income-list { display: flex; flex-direction: column; gap: 8px; }
.bill-card, .income-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.bill-card.bill-paid { opacity: 0.55; }
.bill-left, .income-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.bill-icon { font-size: 1.5rem; flex-shrink: 0; }
.bill-info, .income-info { min-width: 0; }
.bill-name, .income-desc { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bill-meta, .income-meta { font-size: 0.75rem; color: var(--text-dim); }
.bill-right, .income-right { text-align: right; flex-shrink: 0; }
.bill-amount, .income-amount { font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.bill-actions, .income-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Buttons ───────────────────────────────────────────── */
.btn-primary {
  background: var(--green); color: #000; font-weight: 700;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 0.9rem; transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-dim {
  background: var(--surface-2); color: var(--text-dim);
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.85rem; transition: background 0.15s;
}
.btn-dim:active { background: var(--surface-3); }
.btn-sm { padding: 6px 10px; font-size: 0.75rem; border-radius: 8px; }
.btn-green { background: var(--green-dim); color: var(--green); font-weight: 700; }
.btn-red { background: var(--red-dim); color: var(--red); font-weight: 700; }

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-amber { background: var(--amber-dim); color: var(--amber); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-dim { background: var(--surface-3); color: var(--text-dim); }

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 950; padding: 16px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 500px;
  max-height: 85dvh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); } to { transform: translateY(0); } }
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 0;
}
.modal-header h2 { font-size: 1.2rem; font-weight: 700; }
.modal-close { font-size: 1.5rem; color: var(--text-dim); padding: 4px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ── Form Fields ───────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.field span { font-size: 0.75rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field select, .field textarea {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  font-size: 0.95rem; color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); }
.field textarea { resize: vertical; }
.field-row { display: flex; gap: 12px; }
.field-toggle { flex-direction: row; align-items: center; gap: 12px; }
.field-toggle input[type="checkbox"] {
  width: 44px; height: 24px; border-radius: 12px;
  appearance: none; -webkit-appearance: none;
  background: var(--surface-3); transition: background 0.2s;
  cursor: pointer; flex-shrink: 0; position: relative;
}
.field-toggle input[type="checkbox"]::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-dim); transition: transform 0.2s, background 0.2s;
}
.field-toggle input[type="checkbox"]:checked { background: var(--green-dim); }
.field-toggle input[type="checkbox"]:checked::after { transform: translateX(20px); background: var(--green); }

/* ── Chips ─────────────────────────────────────────────── */
.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 20px;
  background: var(--surface-2); border: 2px solid var(--border);
  color: var(--text-dim); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.chip:hover { border-color: var(--surface-3); background: var(--surface-3); }
.chip-active {
  border-color: var(--chip-color, var(--green));
  background: color-mix(in srgb, var(--chip-color, var(--green)) 15%, var(--surface));
  color: var(--text);
}
.chip-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Required & Disabled ──────────────────────────────── */
.required { color: var(--red); }
.btn-disabled { opacity: 0.35 !important; cursor: not-allowed !important; }

/* ── Calendar ──────────────────────────────────────────── */
.cal-grid { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 16px; overflow: hidden; }
.cal-header { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-dow {
  text-align: center; padding: 10px 0;
  font-size: 0.7rem; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.cal-body { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-cell {
  aspect-ratio: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; transition: background 0.1s;
  border-radius: 8px; margin: 2px;
}
.cal-cell:active { background: var(--surface-2); }
.cal-cell.empty { cursor: default; }
.cal-cell.today .cal-day { background: var(--green); color: #000; border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.cal-cell.selected { background: var(--surface-2); }
.cal-day { font-size: 0.85rem; font-weight: 600; }
.cal-dots { display: flex; gap: 3px; }
.dot { width: 5px; height: 5px; border-radius: 50%; }
.dot-red { background: var(--red); }
.dot-green { background: var(--green); }

/* Week summary */
.weekly-summary { display: flex; flex-direction: column; gap: 8px; }
.week-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.week-row:last-child { border-bottom: none; }
.week-label { font-size: 0.8rem; font-weight: 600; color: var(--text-dim); }
.week-bars { display: flex; gap: 16px; }
.week-out { color: var(--red); font-weight: 700; font-size: 0.85rem; }
.week-in { color: var(--green); font-weight: 700; font-size: 0.85rem; }

/* Day detail */
.day-detail { }
.detail-subtitle { font-size: 0.75rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin: 8px 0 6px; }
.detail-item { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.9rem; }

/* ── Settings ──────────────────────────────────────────── */
.pin-form { display: flex; gap: 10px; align-items: center; }
.pin-input-field {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  font-size: 1.1rem; letter-spacing: 8px; text-align: center; flex: 1;
}
.pin-input-field:focus { border-color: var(--green); }
.pin-msg { margin-top: 8px; font-size: 0.85rem; color: var(--green); }
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.cat-item:last-child { border-bottom: none; }
.cat-icon { font-size: 1.3rem; }
.cat-name { flex: 1; font-weight: 600; }
.cat-actions { display: flex; gap: 6px; }

/* ── Bar Chart ─────────────────────────────────────────── */
.bar-chart { display: flex; gap: 8px; align-items: flex-end; height: 160px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.bar-value { font-size: 0.6rem; color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.bar-track { flex: 1; width: 100%; background: var(--surface-2); border-radius: 6px; position: relative; overflow: hidden; display: flex; align-items: flex-end; }
.bar-fill { width: 100%; background: var(--green); border-radius: 6px; transition: height 0.5s ease; min-height: 2px; }
.bar-label { font-size: 0.7rem; color: var(--text-dim); font-weight: 600; }

/* ── Empty State ───────────────────────────────────────── */
.empty-state { text-align: center; padding: 32px 0; color: var(--text-dim); font-size: 0.9rem; }

/* ── Color Utilities ───────────────────────────────────── */
.green { color: var(--green); }
.amber { color: var(--amber); }
.red { color: var(--red); }
.dim { color: var(--text-dim); }

/* ── Responsive Desktop ────────────────────────────────── */
@media (min-width: 768px) {
  .main-content { padding: 24px; max-width: 700px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .stats-3 { grid-template-columns: repeat(3, 1fr); }
  .bottom-nav { left: 50%; transform: translateX(-50%); max-width: 500px; border-radius: var(--radius) var(--radius) 0 0; }
  .page-title { font-size: 2rem; }
}
