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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --card: #0f3460;
  --accent: #e94560;
  --accent2: #00b4d8;
  --green: #06d6a0;
  --yellow: #ffd166;
  --text: #edf2f4;
  --text-dim: #8d99ae;
  --radius: 12px;
}

html { font-size: 16px; }
body {
  font-family: 'M PLUS Rounded 1c', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* === Header === */
.header {
  background: var(--surface);
  padding: 16px 20px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* === Tab Navigation === */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  display: flex;
  border-top: 1px solid rgba(255,255,255,0.05);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-bar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 4px;
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: color 0.2s;
}
.tab-bar button.active { color: var(--accent); }
.tab-bar button svg { width: 24px; height: 24px; }

/* === Pages === */
.page { display: none; padding: 16px; }
.page.active { display: block; }

/* === Cards === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Dashboard === */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.summary-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.summary-item .label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.summary-item .value {
  font-size: 1.3rem;
  font-weight: 700;
}
.summary-item .value.income { color: var(--green); }
.summary-item .value.expense { color: var(--accent); }
.summary-item .value.balance { color: var(--accent2); }
.summary-item .value.debt { color: var(--yellow); }

/* === Debt Items === */
.debt-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.debt-item .debt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.debt-item .debt-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.debt-item .debt-due {
  font-size: 0.75rem;
  color: var(--yellow);
  background: rgba(255,209,102,0.15);
  padding: 2px 8px;
  border-radius: 20px;
}
.debt-item .debt-due.overdue {
  color: var(--accent);
  background: rgba(233,69,96,0.15);
}
.debt-progress {
  background: rgba(255,255,255,0.08);
  border-radius: 6px;
  height: 8px;
  margin: 8px 0;
  overflow: hidden;
}
.debt-progress-bar {
  height: 100%;
  border-radius: 6px;
  background: var(--green);
  transition: width 0.5s ease;
}
.debt-details {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* === Transaction List === */
.tx-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.tx-item:last-child { border-bottom: none; }
.tx-info { flex: 1; }
.tx-info .tx-note { font-size: 0.9rem; font-weight: 500; }
.tx-info .tx-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}
.tx-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; margin-left: 12px; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--accent); }
.tx-actions { margin-left: 8px; }
.tx-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

/* === Forms === */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--card); color: var(--text); }
.btn-income { background: var(--green); color: #1a1a2e; }
.btn-expense { background: var(--accent); color: #fff; }
.btn-small {
  padding: 8px 16px;
  font-size: 0.8rem;
  width: auto;
}

.btn-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.btn-group .btn { flex: 1; }

.toggle-group {
  display: flex;
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}
.toggle-group button {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.toggle-group button.active {
  background: var(--accent2);
  color: #fff;
  font-weight: 600;
}

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
}

/* === Chart === */
.chart-container {
  position: relative;
  height: 200px;
  margin: 12px 0;
}

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

/* === Month Selector === */
.month-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}
.month-selector button {
  background: var(--card);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.month-selector .month-label {
  font-size: 1rem;
  font-weight: 600;
  min-width: 120px;
  text-align: center;
}

/* === Background Image === */
body.has-bg-image {
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}
body.has-bg-image::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(0,0,0, var(--bg-overlay, 0.6));
  z-index: 0;
  pointer-events: none;
}
body.has-bg-image .header,
body.has-bg-image .page,
body.has-bg-image .tab-bar,
body.has-bg-image .modal-overlay { position: relative; z-index: 1; }
body.has-bg-image .header { background: rgba(22,33,62,0.7); backdrop-filter: blur(8px); }
body.has-bg-image .tab-bar { background: rgba(22,33,62,0.85); backdrop-filter: blur(8px); }
body.has-bg-image .card,
body.has-bg-image .summary-item,
body.has-bg-image .debt-item { background: rgba(22,33,62,0.7); backdrop-filter: blur(4px); }

/* === Theme Grid === */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.theme-swatch {
  aspect-ratio: 1;
  border-radius: 10px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.theme-swatch:active { transform: scale(0.93); }
.theme-swatch.active { border-color: #fff; }

/* === Login Screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-screen.hidden { display: none; }
.login-container {
  width: 100%;
  max-width: 360px;
}
.login-logo {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  color: var(--text);
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 32px;
}

/* === Utilities === */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
