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

:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-alt: #1a2744;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6c6c80;
  --accent: #00d4aa;
  --accent-soft: rgba(0, 212, 170, 0.15);
  --warning: #ffc107;
  --warning-soft: rgba(255, 193, 7, 0.15);
  --danger: #ff4757;
  --danger-soft: rgba(255, 71, 87, 0.15);
  --success: #2ed573;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ===== Splash ===== */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 1000;
  transition: opacity 0.4s, visibility 0.4s;
}

.splash.fade-out {
  opacity: 0;
  visibility: hidden;
}

.splash-content {
  text-align: center;
}

.splash-icon {
  font-size: 4rem;
  margin-bottom: 0.5rem;
}

.splash h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent);
}

.splash p {
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-card);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 1.5rem auto 0;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Config Screen ===== */
.config-container {
  max-width: 360px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  text-align: center;
}

.config-container h2 {
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.config-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}

#config-form label {
  display: block;
  text-align: left;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
  margin-top: 1rem;
}

#config-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-alt);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

#config-form input:focus {
  border-color: var(--accent);
}

.config-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.75rem;
}

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  margin-top: 1.5rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:active {
  opacity: 0.8;
}

/* ===== Screens ===== */
.screen { min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }

/* ===== Config Screen ===== */
.config-container {
  max-width: 420px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

.config-container h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.subtitle {
  color: var(--text-secondary);
  margin: 0.25rem 0 1.5rem;
  font-size: 0.9rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group small {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  padding: 0.6rem 1.2rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1.5px solid var(--bg-card-alt);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

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

.btn-danger {
  width: 100%;
  padding: 0.75rem;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1.5px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.error-msg {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-align: center;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 50;
}

.header-left h1 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
}

.month-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.3rem;
}

/* ===== Budget Card ===== */
.budget-card {
  margin: 0.75rem 1.25rem;
  padding: 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.budget-ring-container {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.budget-ring {
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--bg-primary);
  stroke-width: 8;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 1s ease, stroke 0.3s;
}

.ring-progress.warning { stroke: var(--warning); }
.ring-progress.danger { stroke: var(--danger); }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-percentage {
  font-size: 1.5rem;
  font-weight: 800;
}

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

.budget-details {
  flex: 1;
}

.budget-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.9rem;
}

.budget-row .label { color: var(--text-secondary); }
.budget-row .value { font-weight: 600; }
.budget-row .spent { color: var(--danger); }
.budget-row.highlight .value {
  color: var(--accent);
  font-size: 1.05rem;
}

/* ===== Advisor Card ===== */
.advisor-card {
  margin: 0.75rem 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.advisor-card.warning-state {
  background: var(--warning-soft);
  border-left-color: var(--warning);
}

.advisor-card.danger-state {
  background: var(--danger-soft);
  border-left-color: var(--danger);
}

.advisor-icon { font-size: 1.5rem; }

.advisor-content h3 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.advisor-content p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ===== Daily Card ===== */
.daily-card {
  margin: 0.75rem 1.25rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.daily-item {
  text-align: center;
}

.daily-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.daily-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Categories ===== */
.categories-section,
.transactions-section,
.trend-section {
  margin: 1.25rem;
}

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

.section-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.transactions-section h2,
.trend-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
}

.btn-pill {
  padding: 0.3rem 0.75rem;
  background: var(--bg-card);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-pill:active { background: var(--accent-soft); }
.btn-pill.active {
  background: var(--accent);
  color: var(--bg-primary);
}

/* Plan summary bar */
.plan-summary {
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.plan-summary span { font-weight: 600; color: var(--text-secondary); }

.plan-bar {
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  margin-top: 0.4rem;
  overflow: hidden;
}

.plan-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.plan-bar-fill.over { background: var(--warning); }

.categories-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.category-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.category-item:active { background: var(--bg-card-alt); }

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

.category-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.category-amount {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Dual bar: planned (bg) + actual (fill) */
.category-bar {
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.category-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* Budget vs actual sub-row */
.category-budget-row {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.category-budget-row .over { color: var(--danger); font-weight: 600; }
.category-budget-row .under { color: var(--accent); }

/* Edit mode input */
.category-budget-input {
  width: 90px;
  padding: 0.3rem 0.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.8rem;
  text-align: right;
}

.category-budget-input:focus { outline: none; }

/* Category mini chart (expandable) */
.category-chart-container {
  margin-top: 0.5rem;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.category-chart-container.open {
  max-height: 160px;
}

.category-chart-container canvas {
  width: 100%;
  height: 120px;
}

/* ===== Transactions ===== */
.transactions-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.transaction-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}

.transaction-info {
  display: flex;
  flex-direction: column;
}

.transaction-desc {
  font-size: 0.85rem;
  font-weight: 500;
}

.transaction-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.transaction-amount {
  font-weight: 700;
  font-size: 0.9rem;
}

.transaction-amount.expense { color: var(--danger); }
.transaction-amount.income { color: var(--success); }

/* ===== Trend Chart ===== */
.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: hidden;
}

#trend-chart {
  width: 100%;
  height: auto;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 1.5rem 1.25rem 3rem;
}

.sync-status {
  font-size: 0.8rem;
  color: var(--danger);
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.last-sync {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-content {
  width: 100%;
  max-width: 500px;
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem 1.25rem 2rem;
  max-height: 85vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  font-size: 1.2rem;
}

.modal hr {
  border: none;
  border-top: 1px solid var(--bg-card);
  margin: 1.25rem 0;
}

/* ===== Utilities ===== */
@media (min-width: 500px) {
  .budget-card { max-width: 480px; margin-left: auto; margin-right: auto; }
  .advisor-card,
  .daily-card { max-width: 480px; margin-left: auto; margin-right: auto; }
  .categories-section,
  .transactions-section,
  .trend-section { max-width: 480px; margin-left: auto; margin-right: auto; }
  .app-header { max-width: 480px; margin-left: auto; margin-right: auto; }
}

/* ===== Pull to refresh indicator ===== */
.pull-indicator {
  text-align: center;
  padding: 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: opacity 0.2s;
}

/* ===== Skeleton loading ===== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-alt) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
