/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg:          #f0f4f8;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e2e8f0;
  --text:        #1e293b;
  --text-2:      #64748b;
  --text-3:      #94a3b8;
  --primary:     #6366f1;
  --primary-h:   #4f46e5;
  --danger:      #ef4444;
  --warning:     #f59e0b;
  --success:     #10b981;
  --radius:      12px;
  --shadow:      0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:   0 10px 15px -3px rgba(0,0,0,.10), 0 4px 6px -2px rgba(0,0,0,.05);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  color: #fff;
  padding: .875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.header-actions { display: flex; gap: .5rem; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Summary grid ────────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.summary-label {
  font-size: .7rem;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .4rem;
}
.summary-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.summary-value.green  { color: var(--success); }
.summary-value.amber  { color: var(--warning); }
.summary-sub {
  font-size: .7rem;
  color: var(--text-3);
  margin-top: .35rem;
}

/* ── Chart section ───────────────────────────────────────────────────────── */
.chart-section {
  display: flex;
  gap: 2rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 1.5rem;
}
.chart-wrapper { position: relative; flex-shrink: 0; }
.chart-legend {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-label {
  font-size: .875rem;
  color: var(--text);
  flex: 1;
}
.legend-value {
  font-size: .78rem;
  color: var(--text-2);
  white-space: nowrap;
}

/* SVG pie slice hover */
.pie-slice {
  cursor: pointer;
  transition: filter .15s;
}
.pie-slice:hover { filter: brightness(1.12) drop-shadow(0 2px 6px rgba(0,0,0,.2)); }

/* Tooltip */
.tooltip {
  position: absolute;
  background: #1e293b;
  color: #fff;
  padding: .4rem .7rem;
  border-radius: 8px;
  font-size: .8rem;
  line-height: 1.4;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

/* ── Bills section ───────────────────────────────────────────────────────── */
.bills-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: .5rem;
}
.bills-title { font-weight: 600; color: var(--text); }
.filter-group {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.filter-btn {
  padding: .28rem .7rem;
  font-size: .75rem;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--text-2);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active { background: var(--primary); color: #fff; }

/* ── Bill rows ───────────────────────────────────────────────────────────── */
.bill-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.bill-row:last-child { border-bottom: none; }
.bill-row:hover { background: var(--surface-2); }
.bill-row.bill-expired { opacity: .55; }

.bill-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.bill-info { flex: 1; min-width: 0; }
.bill-name {
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.bill-meta {
  display: flex;
  gap: .75rem;
  margin-top: .2rem;
  flex-wrap: wrap;
}
.bill-category { font-size: .75rem; color: var(--text-2); }
.bill-enddate  { font-size: .75rem; color: var(--text-3); }
.bill-amount   { text-align: right; white-space: nowrap; }
.amount-main   { font-size: .95rem; font-weight: 600; color: var(--text); }
.freq          { font-size: .75rem; color: var(--text-2); font-weight: 400; }
.amount-sub    { font-size: .72rem; color: var(--text-2); margin-top: .1rem; }

.bill-actions {
  display: flex;
  gap: .25rem;
  opacity: 0;
  transition: opacity .15s;
}
.bill-row:hover .bill-actions { opacity: 1; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  font-size: .62rem;
  font-weight: 700;
  padding: .1rem .4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-warning   { background: #fef3c7; color: #92400e; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* ── Section headers inside bills list ───────────────────────────────────── */
.section-label {
  padding: .45rem 1.25rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}
.section-label.warning   { background: #fffbeb; color: #92400e; }
.section-label.secondary { background: var(--surface-2); color: var(--text-2); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  border: none;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-outline {
  background: transparent;
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
}
.btn-outline:hover { background: rgba(255,255,255,.1); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .3rem;
  cursor: pointer;
  color: var(--text-2);
  display: flex;
  align-items: center;
  transition: all .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.btn-danger:hover { background: #fee2e2; color: var(--danger); border-color: #fecaca; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal-header h2 { font-size: 1.05rem; font-weight: 600; }
.modal-body {
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
label {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-2);
}
.label-hint { font-weight: 400; color: var(--text-3); }
input, select, textarea {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
input[type="color"] {
  padding: .25rem .35rem;
  height: 2.4rem;
  cursor: pointer;
}
textarea { resize: vertical; }
.checkbox-group {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.checkbox-group input  { width: auto; padding: 0; }
.checkbox-group label  { margin: 0; font-size: .875rem; color: var(--text); }

/* ── States ──────────────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 3rem;
  color: var(--text-2);
  font-size: .9rem;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state, .no-data {
  padding: 3rem;
  text-align: center;
  color: var(--text-2);
  font-size: .9rem;
}
.error-state {
  padding: 3rem;
  text-align: center;
  color: var(--danger);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  font-size: .9rem;
}

/* ── Chart navigation header ─────────────────────────────────────────────── */
.chart-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
}
.chart-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .35rem .5rem;
  cursor: pointer;
  color: var(--text-2);
  display: flex;
  align-items: center;
  transition: all .15s;
  flex-shrink: 0;
}
.chart-nav-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }
.chart-view-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
}
#chart-view-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.chart-dots { display: flex; gap: .35rem; }
.chart-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background .2s, transform .2s;
}
.chart-dot.active { background: var(--primary); transform: scale(1.3); }

/* ── Bills controls row ──────────────────────────────────────────────────── */
.bills-controls {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.btn-sm {
  padding: .25rem .6rem;
  font-size: .75rem;
  border-radius: 6px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid .summary-card:last-child { grid-column: 1 / -1; }
  .chart-section { flex-direction: column; align-items: flex-start; }
  .form-row { grid-template-columns: 1fr; }
  .bill-actions { opacity: 1; }
  .container { padding: 1rem; }
  .auth-card { margin: 0 .5rem; }
}

/* ── Auth Screen ──────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%);
  padding: 1rem;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}
.auth-header {
  text-align: center;
  padding: 2rem 1.5rem 1rem;
  color: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}
.auth-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  flex: 1;
  padding: .75rem;
  border: none;
  background: none;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
  border-bottom: 2px solid transparent;
}
.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.auth-tab:hover:not(.active) {
  color: var(--text);
}
.auth-form {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.auth-error {
  font-size: .8rem;
  color: var(--danger);
  background: #fee2e2;
  padding: .5rem .75rem;
  border-radius: 6px;
}
.btn-full {
  width: 100%;
  justify-content: center;
  padding: .6rem;
}
