/* ── Ledger Expense Tracker — Styles ── */
/* Palette: Copper & Slate — dark fintech aesthetic */

/* ── Google Fonts already loaded in HTML ── */

/* ── CSS Variables ── */
:root {
  /* Dark theme (default) */
  --bg-base:        #1a1f2e;
  --bg-surface:     #222840;
  --bg-elevated:    #2a3050;
  --bg-input:       #1e2438;
  --border:         rgba(255,255,255,0.08);
  --border-focus:   #c9956b;

  --text-primary:   #f0ece6;
  --text-secondary: #9aa0b8;
  --text-muted:     #5c6480;

  --accent:         #c9956b;
  --accent-light:   #e6b896;
  --accent-glow:    rgba(201,149,107,0.18);
  --accent-2:       #7b8cde;

  --danger:         #e05c6a;
  --danger-bg:      rgba(224,92,106,0.12);
  --success:        #5cb88a;
  --success-bg:     rgba(92,184,138,0.12);

  --shadow-sm:      0 2px 8px rgba(0,0,0,0.3);
  --shadow-md:      0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg:      0 8px 40px rgba(0,0,0,0.5);
  --shadow-accent:  0 4px 24px rgba(201,149,107,0.2);

  --radius-sm:      6px;
  --radius-md:      12px;
  --radius-lg:      18px;

  --font-display:   'DM Serif Display', Georgia, serif;
  --font-body:      'DM Sans', sans-serif;

  --transition:     0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-base:        #f5f0eb;
  --bg-surface:     #ffffff;
  --bg-elevated:    #faf7f4;
  --bg-input:       #f9f5f1;
  --border:         rgba(0,0,0,0.1);
  --border-focus:   #b87333;

  --text-primary:   #2f3640;
  --text-secondary: #5a6070;
  --text-muted:     #9aa0b0;

  --accent:         #b87333;
  --accent-light:   #d4a574;
  --accent-glow:    rgba(184,115,51,0.12);
  --accent-2:       #4a5ab8;

  --danger:         #c0392b;
  --danger-bg:      rgba(192,57,43,0.08);
  --success:        #27ae60;
  --success-bg:     rgba(39,174,96,0.08);

  --shadow-sm:      0 2px 8px rgba(0,0,0,0.08);
  --shadow-md:      0 4px 20px rgba(0,0,0,0.1);
  --shadow-lg:      0 8px 40px rgba(0,0,0,0.12);
  --shadow-accent:  0 4px 24px rgba(184,115,51,0.15);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-base);
  min-height: 100vh;
  transition: background-color var(--transition-slow), color var(--transition-slow);
  /* Subtle grain texture */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
}

/* ── Layout ── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}

.main { padding: 32px 0 64px; }

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-slow);
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { flex-shrink: 0; border-radius: 8px; }

.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Theme Toggle ── */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: rotate(20deg);
}

/* ── Summary Cards ── */
.summary-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
  animation: fadeUp 0.5s ease both;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.stat-card:hover::before { opacity: 1; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card--accent {
  background: linear-gradient(135deg, var(--bg-surface), var(--accent-glow));
  border-color: rgba(201,149,107,0.25);
}
.stat-card--accent::before { opacity: 0.6; }

.stat-card__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-card__value {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}
.stat-card__value--sm { font-size: 18px; }
.stat-card__sub {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Main Grid ── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  align-items: start;
}

/* ── Cards ── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-slow), border-color var(--transition-slow);
  animation: fadeUp 0.5s ease both;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 20px;
}

.card__title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card__badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid rgba(201,149,107,0.2);
  padding: 3px 10px;
  border-radius: 20px;
}

/* ── Form ── */
.expense-form { padding: 0 24px 24px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.required { color: var(--accent); }
.optional { color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.input-prefix {
  position: relative;
  display: flex;
  align-items: center;
}
.prefix-symbol {
  position: absolute;
  left: 12px;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  pointer-events: none;
  z-index: 1;
}
.input-prefix input { padding-left: 28px; }

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  transition: all var(--transition);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-elevated);
}
input::placeholder { color: var(--text-muted); }
input.error, select.error { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa0b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.5);
  cursor: pointer;
}

.form-error {
  font-size: 11px;
  color: var(--danger);
  min-height: 16px;
  display: block;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-accent);
}
.btn--primary:hover {
  background: var(--accent-light);
  box-shadow: 0 6px 28px rgba(201,149,107,0.35);
  transform: translateY(-1px);
}

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

.btn--danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
  padding: 5px 10px;
  font-size: 12px;
}
.btn--danger:hover { background: var(--danger); color: #fff; }

.btn--edit {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid transparent;
  padding: 5px 10px;
  font-size: 12px;
}
.btn--edit:hover { background: var(--accent); color: #fff; }

.btn--sm { padding: 7px 14px; font-size: 12px; }

/* ── Table Controls ── */
.table-controls { display: flex; gap: 8px; align-items: center; }

.filter-select {
  width: auto;
  padding: 6px 32px 6px 10px;
  font-size: 12px;
  background: var(--bg-elevated);
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
  padding: 0 24px;
}

.expense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.expense-table thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.expense-table thead th.sortable { cursor: pointer; }
.expense-table thead th.sortable:hover { color: var(--accent); }
.expense-table thead th.sort-asc .sort-icon,
.expense-table thead th.sort-desc .sort-icon { color: var(--accent); }
.expense-table thead th.sort-asc .sort-icon::after { content: ' ↑'; }
.expense-table thead th.sort-desc .sort-icon::after { content: ' ↓'; }
.sort-icon { font-size: 10px; color: var(--text-muted); }

.expense-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.expense-table tbody tr:last-child { border-bottom: none; }
.expense-table tbody tr:hover { background: var(--bg-elevated); }

.expense-table tbody td {
  padding: 12px 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.amount-cell {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--accent);
  text-align: right;
  white-space: nowrap;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.desc-cell {
  color: var(--text-secondary);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date-cell { color: var(--text-secondary); white-space: nowrap; font-size: 12px; }

.actions-cell { display: flex; gap: 6px; justify-content: center; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state__icon { font-size: 40px; margin-bottom: 12px; }
.empty-state__title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state__sub { font-size: 13px; }

/* ── Table Footer ── */
.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
}
.table-footer span:last-child {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--accent);
}

/* ── Chart Card ── */
.chart-card { position: sticky; top: 80px; }

.chart-wrap {
  padding: 0 24px;
  position: relative;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrap canvas {
  max-height: 260px;
  transition: opacity var(--transition-slow);
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}
.chart-empty__icon { font-size: 36px; }
.chart-empty.hidden { display: none; }

/* ── Chart Legend ── */
.chart-legend {
  padding: 16px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  animation: fadeUp 0.3s ease both;
}

.legend-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.legend-label { color: var(--text-secondary); }

.legend-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-amount {
  font-weight: 600;
  color: var(--text-primary);
}

.legend-pct {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  max-width: 320px;
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast--success { background: var(--success); color: #fff; }
.toast--error   { background: var(--danger);  color: #fff; }
.toast--info    { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }

/* ── Category Colors ── */
.cat--food        { background: rgba(255,183,77,0.15);  color: #ffb74d; }
.cat--transport   { background: rgba(100,181,246,0.15); color: #64b5f6; }
.cat--housing     { background: rgba(129,199,132,0.15); color: #81c784; }
.cat--entertainment { background: rgba(186,104,200,0.15); color: #ba68c8; }
.cat--healthcare  { background: rgba(240,98,146,0.15);  color: #f06292; }
.cat--shopping    { background: rgba(255,138,101,0.15); color: #ff8a65; }
.cat--utilities   { background: rgba(255,241,118,0.15); color: #c8a800; }
.cat--travel      { background: rgba(77,208,225,0.15);  color: #4dd0e1; }
.cat--education   { background: rgba(161,136,127,0.15); color: #a1887f; }
.cat--other       { background: rgba(144,164,174,0.15); color: #90a4ae; }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes rowIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.row-new { animation: rowIn 0.25s ease both; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .main-grid { grid-template-columns: 1fr; }
  .chart-card { position: static; }
}

@media (max-width: 768px) {
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .container { padding: 0 16px; }
  .main { padding: 20px 0 48px; }
  .brand-name { font-size: 18px; }
}

@media (max-width: 480px) {
  .summary-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-card__value { font-size: 22px; }
  .header__inner { height: 52px; }
  .btn--sm span { display: none; }
}

/* ── Left col spacing ── */
.left-col { display: flex; flex-direction: column; gap: 20px; }