/* style.css */

/* ============================================================
   CSS VARIABLES — LIGHT & DARK THEMES
   ============================================================ */
:root {
  --font-display: 'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;

  /* Spacing */
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 16px;
  --gap-lg: 24px;
  --gap-xl: 36px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;

  /* Category colors */
  --cat-food: #f97316;
  --cat-rent: #8b5cf6;
  --cat-travel: #06b6d4;
  --cat-bills: #eab308;
  --cat-other: #6b7280;
}

/* DARK THEME (default) */
[data-theme="dark"] {
  --bg-base:       #0c0e14;
  --bg-surface:    #141720;
  --bg-elevated:   #1c2030;
  --bg-hover:      #232840;
  --border-subtle: #2a2f45;
  --border-default:#353d5c;

  --text-primary:  #eef0f8;
  --text-secondary:#8890b0;
  --text-muted:    #50577a;

  --accent-green:  #22c55e;
  --accent-green-bg: rgba(34,197,94,0.12);
  --accent-red:    #f43f5e;
  --accent-red-bg: rgba(244,63,94,0.12);
  --accent-blue:   #6366f1;
  --accent-blue-bg:rgba(99,102,241,0.15);

  --shadow-card:   0 2px 20px rgba(0,0,0,0.5);
  --shadow-glow:   0 0 30px rgba(99,102,241,0.15);
}

/* LIGHT THEME */
[data-theme="light"] {
  --bg-base:       #f4f5fb;
  --bg-surface:    #ffffff;
  --bg-elevated:   #f0f1fa;
  --bg-hover:      #e8eaf7;
  --border-subtle: #dde0f0;
  --border-default:#c4c9e3;

  --text-primary:  #111827;
  --text-secondary:#4b5280;
  --text-muted:    #9095b5;

  --accent-green:  #16a34a;
  --accent-green-bg: rgba(22,163,74,0.1);
  --accent-red:    #dc2626;
  --accent-red-bg: rgba(220,38,38,0.1);
  --accent-blue:   #4f46e5;
  --accent-blue-bg:rgba(79,70,229,0.12);

  --shadow-card:   0 2px 16px rgba(0,0,0,0.08);
  --shadow-glow:   0 0 20px rgba(79,70,229,0.1);
}

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

html {
  scroll-behavior: smooth;
  font-size: 15px;
}

body {
  font-family: var(--font-display);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

/* ============================================================
   ALERTS / TOASTS
   ============================================================ */
#alerts-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  max-width: 340px;
}

.alert-toast {
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-card);
  animation: toastIn 0.3s ease forwards;
  border-left: 4px solid;
}

.alert-toast.alert-warn {
  background: rgba(234,179,8,0.15);
  border-color: #eab308;
  color: #eab308;
}

.alert-toast.alert-danger {
  background: var(--accent-red-bg);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.alert-toast.alert-info {
  background: var(--accent-blue-bg);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--gap-lg);
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: var(--gap-sm);
}

.brand-mark {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-blue);
  line-height: 1;
}

.brand-name {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: none;
}

@media (min-width: 600px) { .brand-sub { display: inline; } }

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--gap-lg);
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--gap-lg);
  align-items: start;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: var(--gap-md);
  }
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg);
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s;
}

.card:hover {
  border-color: var(--border-default);
}

.card-title {
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: var(--gap-md);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

/* ============================================================
   FORM CARD
   ============================================================ */
.form-body { display: flex; flex-direction: column; gap: var(--gap-md); }

.input-group { display: flex; flex-direction: column; gap: var(--gap-xs); }

.input-label {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

.optional {
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.input-field {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}

.input-field:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-bg);
}

.input-field option {
  background: var(--bg-elevated);
}

.input-sm { padding: 7px 10px; font-size: 0.82rem; }

/* Type toggle */
.type-toggle {
  display: flex;
  gap: 6px;
}

.type-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.type-btn:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
}

.type-btn.active[data-type="expense"] {
  background: var(--accent-red-bg);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.type-btn.active[data-type="income"] {
  background: var(--accent-green-bg);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}
.btn-primary:hover { background: #4f46e5; transform: translateY(-1px); box-shadow: 0 4px 15px var(--accent-blue-bg); }
.btn-primary:active { transform: translateY(0); }

.btn-accent {
  background: var(--accent-green);
  color: #fff;
}
.btn-accent:hover { opacity: 0.9; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-danger {
  background: transparent;
  color: var(--accent-red);
  border: 1px solid transparent;
  padding: 4px 10px;
  font-size: 0.78rem;
}
.btn-danger:hover { background: var(--accent-red-bg); border-color: var(--accent-red); }

.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-xs { padding: 3px 7px; font-size: 0.75rem; }
.btn-icon { padding: 7px 10px; font-size: 1rem; }

/* ============================================================
   BUDGET CARD
   ============================================================ */
.budget-body { display: flex; flex-direction: column; gap: var(--gap-md); }

.input-row {
  display: flex;
  gap: var(--gap-sm);
}

.input-row .input-field { flex: 1; }

.budget-display {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.budget-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.budget-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.budget-val {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.budget-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 4px;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent-green);
  transition: width 0.5s ease, background 0.3s;
}

/* ============================================================
   INSIGHTS
   ============================================================ */
.insights-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.insight-item {
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-blue);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
  animation: fadeSlideIn 0.4s ease forwards;
}

.insight-item.warn { border-color: #eab308; }
.insight-item.good { border-color: var(--accent-green); }

/* ============================================================
   CONTENT COLUMN
   ============================================================ */
.content-col {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}

/* ============================================================
   SUMMARY CARDS
   ============================================================ */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-md);
}

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

.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--gap-md) var(--gap-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.summary-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); }

.balance-card { border-top: 2px solid var(--accent-blue); }
.income-card  { border-top: 2px solid var(--accent-green); }
.expense-card { border-top: 2px solid var(--accent-red); }

.summary-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.summary-amount {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-family: var(--font-display);
}

/* ============================================================
   COLOR HELPERS
   ============================================================ */
.income-color  { color: var(--accent-green) !important; }
.expense-color { color: var(--accent-red) !important; }

/* ============================================================
   CHARTS
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-lg);
}

.chart-block-wide { grid-column: 1 / -1; }

@media (max-width: 700px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-block-wide { grid-column: 1; }
}

.chart-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: var(--gap-md);
}

/* Category chart */
.category-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cat-bar-row {
  display: grid;
  grid-template-columns: 80px 1fr 60px;
  align-items: center;
  gap: var(--gap-sm);
}

.cat-bar-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-bar-track {
  height: 10px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
}

.cat-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.5s ease;
}

.cat-bar-amount {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-align: right;
}

/* Compare chart */
.compare-chart {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--gap-md);
}

.compare-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.compare-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.compare-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.compare-amount {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
}

.compare-bar-track {
  height: 14px;
  background: var(--bg-elevated);
  border-radius: 99px;
  overflow: hidden;
}

.compare-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.5s ease;
}

/* Trend chart */
.trend-chart {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.trend-months-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  height: 80px;
}

.trend-month-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.trend-bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 60px;
}

.trend-bar {
  flex: 1;
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  min-height: 2px;
}

.trend-bar-income  { background: var(--accent-green); opacity: 0.8; }
.trend-bar-expense { background: var(--accent-red); opacity: 0.8; }

.trend-month-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.trend-legend {
  display: flex;
  gap: var(--gap-md);
  justify-content: flex-end;
}

.trend-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* ============================================================
   COMPARISON TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.comparison-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  border-bottom: 1px solid var(--border-subtle);
}

.comparison-table td {
  padding: 10px 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.comparison-table tr:last-child td { border-bottom: none; }
.comparison-table tr:hover td { background: var(--bg-elevated); }

.diff-positive { color: var(--accent-red); }
.diff-negative { color: var(--accent-green); }

/* ============================================================
   FILTERS BAR
   ============================================================ */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-md);
  align-items: flex-end;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--gap-md) var(--gap-lg);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  min-width: 120px;
}

.search-group { flex: 1; min-width: 200px; }

.search-wrap {
  display: flex;
  gap: var(--gap-sm);
  align-items: center;
}
.search-wrap .input-field { flex: 1; }

/* ============================================================
   TRANSACTIONS LIST
   ============================================================ */
.tx-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--gap-md);
}

.tx-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tx-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.tx-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: var(--gap-md);
  padding: 12px 14px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all 0.2s;
  animation: fadeSlideIn 0.3s ease forwards;
}

.tx-item:hover {
  border-color: var(--border-default);
  background: var(--bg-hover);
}

.tx-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tx-dot-income  { background: var(--accent-green); }
.tx-dot-expense { background: var(--accent-red); }

.tx-info { min-width: 0; }

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

.tx-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.tx-cat-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.tx-date {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.tx-amount {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ============================================================
   NO DATA
   ============================================================ */
.no-data-msg {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: var(--gap-lg) 0;
}

/* ============================================================
   HIDDEN HELPER
   ============================================================ */
.hidden { display: none !important; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.95); }
}

.tx-item.removing {
  animation: fadeOut 0.25s ease forwards;
  pointer-events: none;
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  text-align: center;
  padding: var(--gap-xl) var(--gap-md);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--gap-xl);
}

/* ============================================================
   SCROLLBAR STYLING
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
