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

:root {
  color-scheme: only light;
  --bg:          #F5F0E8;
  --surface:     #FFFDF7;
  --primary:     #7C6F5B;
  --safe:        #6B8F71;
  --exceeded:    #C17A5A;
  --text:        #2C2416;
  --text-muted:  #9E8E7A;
  --border:      #E8E0D0;
  --accent:      #B8A898;
  --shadow:      rgba(44,36,22,0.06);
}

html, body {
  font-family: 'DM Sans', sans-serif;
  background-color: var(--bg) !important;
  color: var(--text) !important;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Force light mode — override OS dark mode */
  forced-color-adjust: none;
  color-scheme: only light;
}

/* ── Login Screen ────────────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  background-color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  display: block;
}

.login-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.login-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-label {
  text-align: left;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  display: block;
  margin-bottom: -0.4rem;
}

.login-form input[type="password"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.login-form input[type="password"]:focus {
  border-color: var(--primary);
}

.login-error {
  font-size: 0.82rem;
  color: var(--exceeded);
  min-height: 1.2rem;
  text-align: left;
}

.login-form button {
  width: 100%;
  padding: 0.8rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.login-form button:hover { background: var(--text); }

/* ── App Shell ───────────────────────────────────────────────────────────── */
#app {
  min-height: 100vh;
  background-color: var(--bg);
  max-width: 1400px;
  margin: 0 auto;
}

.hidden { display: none !important; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.5rem 1.5rem 1rem;
}

.app-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

.app-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.refresh-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.refresh-btn:hover { background: var(--text); }

/* ── Filter Bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem 0.75rem;
}

.filter-label {
  font-family: 'Playfair Display', serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.filter-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.filter-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.filter-chip:hover {
  border-color: var(--primary);
  background: var(--bg);
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
}

.filter-chip.active .chip-label,
.filter-chip.active .chip-value {
  color: white;
}

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

.chip-value {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
}

/* ── Filter Panel (bottom sheet style) ───────────────────────────────────── */
.filter-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44,36,22,0.3);
  z-index: 200;
}

.filter-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 201;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem 2rem;
  max-height: 60vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.filter-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.filter-panel-header span {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.panel-close {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
}

.filter-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  transition: color 0.15s;
}

.filter-option:last-child { border-bottom: none; }
.filter-option:hover { color: var(--primary); }

.filter-option.selected {
  color: var(--primary);
  font-weight: 500;
}

.filter-option.selected::after {
  content: '✓';
  color: var(--primary);
  font-weight: 600;
}

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
  padding: 1.25rem 1.5rem 3rem;
}

/* ── KPI Strip ───────────────────────────────────────────────────────────── */
.kpi-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 4px var(--shadow);
}

.kpi-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.3rem;
}

.kpi-value {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}

.kpi-value-sm { font-size: 1.1rem; }

.kpi-delta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.kpi-delta.positive { color: var(--safe); }
.kpi-delta.negative { color: var(--exceeded); }

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* ── Section Header ──────────────────────────────────────────────────────── */
.section-header {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

/* ── Budget Section ──────────────────────────────────────────────────────── */
.budget-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (min-width: 768px) {
  .budget-grid {
    grid-template-columns: 1fr 2fr;
  }
}

.budget-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.budget-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  text-align: center;
}

.budget-stat .kpi-label { margin-bottom: 0.2rem; }

.budget-stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.status-badge {
  display: inline-block;
  border-radius: 20px;
  padding: 0.2rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.status-safe {
  background: rgba(107,143,113,0.15);
  color: var(--safe);
  border: 1px solid rgba(107,143,113,0.3);
}

.status-exceeded {
  background: rgba(193,122,90,0.15);
  color: var(--exceeded);
  border: 1px solid rgba(193,122,90,0.3);
}

/* ── Charts Row ──────────────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .charts-row {
    grid-template-columns: 3fr 2fr;
  }
}

.chart-card { overflow: hidden; }

/* ── Account Cards ───────────────────────────────────────────────────────── */
.account-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  text-align: center;
  box-shadow: 0 1px 4px var(--shadow);
}

/* ── YoY Summary ─────────────────────────────────────────────────────────── */
.yoy-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}

@media (max-width: 480px) {
  .yoy-summary { grid-template-columns: 1fr; }
}

.yoy-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 1px 4px var(--shadow);
}

/* ── Top 5 ───────────────────────────────────────────────────────────────── */
.top5-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.top5-rank {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  color: var(--text-muted);
  width: 22px;
  flex-shrink: 0;
}

.top5-body { flex: 1; min-width: 0; }

.top5-desc {
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top5-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.top5-amount {
  font-family: 'Playfair Display', serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Transaction Table ───────────────────────────────────────────────────── */
.txn-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.txn-summary {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.txn-table th {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.txn-table td {
  padding: 0.6rem 0.85rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.txn-table tbody tr:last-child td { border-bottom: none; }

.txn-table tbody tr:hover td { background: var(--bg); }

.text-right { text-align: right !important; }

.txn-desc {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 600px) {
  .txn-table th:nth-child(3),
  .txn-table td:nth-child(3) { display: none; }
}

.txn-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
  align-items: center;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-show-txn {
  width: 100%;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 0.5rem;
}

.btn-show-txn:hover {
  background: var(--bg);
  border-color: var(--primary);
}

.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

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

/* ── Loading Spinner ─────────────────────────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── No-budget info ──────────────────────────────────────────────────────── */
.info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* ── Desktop tweaks ──────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .app-header { padding: 2rem 2.5rem 1rem; }
  .filter-bar  { padding: 0.75rem 2.5rem; }
  .main-content { padding: 1.5rem 2.5rem 3rem; }
  .kpi-strip { grid-template-columns: repeat(4, 1fr); }
  .account-cards { grid-template-columns: repeat(4, 1fr); }
  .filter-chips { grid-template-columns: repeat(4, 1fr); }
  .filter-panel {
    position: fixed;
    bottom: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    border-radius: 16px;
    border: 1px solid var(--border);
    max-height: 70vh;
    animation: fadeIn 0.15s ease;
  }
  @keyframes fadeIn { from { opacity: 0; transform: translate(-50%, -48%); } }
}
