/*
 * Daily Expense Tracker — Styles
 * MIT License
 * Copyright (c) 2026
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 */

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

:root {
  /* Palette — Light */
  --bg:           #f5f2ec;
  --bg-panel:     #fdfaf5;
  --bg-card:      #ffffff;
  --bg-input:     #f5f2ec;
  --border:       #e4ddd2;
  --border-focus: #b8986a;

  --text-primary:   #1a1612;
  --text-secondary: #7a6e62;
  --text-muted:     #b0a898;

  --accent:        #b8986a;
  --accent-dark:   #9a7d52;
  --accent-soft:   #f0e8d8;

  --danger:        #c0392b;
  --danger-soft:   #fdf0ef;
  --success:       #27ae60;

  /* Category colours */
  --cat-food:          #e8895a;
  --cat-transport:     #5a9ee8;
  --cat-shopping:      #e85a9e;
  --cat-health:        #5ae89e;
  --cat-entertainment: #9e5ae8;
  --cat-utilities:     #e8c75a;
  --cat-travel:        #5ae8e8;
  --cat-education:     #e8e85a;
  --cat-other:         #b0a898;

  --radius:    10px;
  --radius-lg: 16px;
  --shadow:    0 2px 12px rgba(26,22,18,0.06);
  --shadow-md: 0 4px 24px rgba(26,22,18,0.10);
  --transition: 0.18s ease;

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

[data-theme="dark"] {
  --bg:           #141210;
  --bg-panel:     #1c1916;
  --bg-card:      #231f1b;
  --bg-input:     #2a2520;
  --border:       #332e28;
  --border-focus: #b8986a;

  --text-primary:   #f0ebe3;
  --text-secondary: #9a9088;
  --text-muted:     #5a5450;

  --accent:        #c8a87a;
  --accent-dark:   #e0c090;
  --accent-soft:   #2a2218;

  --danger:        #e05040;
  --danger-soft:   #2a1815;
  --success:       #4ac878;

  --shadow:    0 2px 12px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.35);
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

/* ── Typography ────────────────────────────────────────── */
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; }

.section-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  margin-bottom: 0.75rem;
}

/* ── Header ────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.brand-icon { font-size: 1.2rem; }

.header-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-date {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 300;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ── App Layout ────────────────────────────────────────── */
.app-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 860px) {
  .app-layout { grid-template-columns: 1fr; }
  .panel-right { order: -1; }
}

/* ── Panels ────────────────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Summary Cards ─────────────────────────────────────── */
.summary-section { display: flex; flex-direction: column; gap: 0.75rem; }

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  transition: box-shadow var(--transition);
}

.summary-total {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  border-color: transparent;
}

.summary-total .summary-label { color: rgba(255,255,255,0.75); }
.summary-total .summary-amount { color: #fff; }
.summary-total .summary-sub { color: rgba(255,255,255,0.65); }

.summary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.summary-small { padding: 0.8rem 1rem; }

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

.summary-amount {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--text-primary);
  line-height: 1.1;
}
.summary-amount--sm { font-size: 1.25rem; }

.summary-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* ── Category Breakdown ────────────────────────────────── */
.breakdown-section {}

.category-list { display: flex; flex-direction: column; gap: 0.5rem; }

.cat-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  animation: fadeSlide 0.22s ease;
}

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

.cat-bar-wrap {
  height: 5px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.cat-bar {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(.4,0,.2,1);
}

.cat-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.cat-name {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.cat-amount {
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.empty-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Form Section ──────────────────────────────────────── */
.form-section {}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.field label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.optional {
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(184,152,106,0.15);
}

input::placeholder { color: var(--text-muted); }

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='%237a6e62' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2rem;
  cursor: pointer;
}

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

.form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  flex: 1;
}
.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(184,152,106,0.3);
}
.btn-primary:active { transform: none; box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { filter: brightness(1.1); }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
  font-size: 0.8rem;
  padding: 0.4rem 0.7rem;
}
.btn-danger-ghost:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

/* ── Toolbar ───────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.toolbar-left { display: flex; align-items: center; gap: 0.6rem; }
.toolbar-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.badge {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  border: 1px solid rgba(184,152,106,0.2);
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 0.6rem;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  padding-left: 2rem !important;
  width: 190px;
  font-size: 0.82rem !important;
}

.filter-select {
  font-size: 0.82rem !important;
  padding: 0.45rem 1.8rem 0.45rem 0.7rem !important;
  width: auto;
}

/* ── Expense List ──────────────────────────────────────── */
.expense-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 200px;
}

.expense-group {}

.expense-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  padding: 0.8rem 0 0.35rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

.expense-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  animation: fadeSlide 0.2s ease;
  transition: background var(--transition);
  border-radius: 6px;
}
.expense-item:hover { background: var(--bg-input); }
.expense-item:last-child { border-bottom: none; }

.expense-cat-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  flex-shrink: 0;
  background: var(--accent-soft);
}

.expense-meta { min-width: 0; }

.expense-desc {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.expense-cat-tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 500;
}

.expense-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.expense-amount {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text-primary);
}

.expense-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity var(--transition);
}
.expense-item:hover .expense-actions { opacity: 1; }

.btn-row-action {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  font-size: 0.75rem;
}
.btn-row-action:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-row-action.delete:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

/* ── List Footer ───────────────────────────────────────── */
.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
}
.footer-note { font-size: 0.72rem; color: var(--text-muted); }

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  gap: 0.5rem;
  animation: fadeIn 0.3s ease;
}
.empty-icon { font-size: 2rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.empty-title { font-family: var(--font-display); font-size: 1.1rem; color: var(--text-secondary); }
.empty-desc { font-size: 0.82rem; color: var(--text-muted); text-align: center; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,22,18,0.45);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 340px;
  box-shadow: var(--shadow-md);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}
.modal-overlay.active .modal { transform: scale(1); }

.modal-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
}
.modal-body { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text-primary);
  color: var(--bg);
  padding: 0.6rem 1.2rem;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

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

/* ── Category colour helpers ───────────────────────────── */
[data-cat="food"]          { --cc: var(--cat-food); }
[data-cat="transport"]     { --cc: var(--cat-transport); }
[data-cat="shopping"]      { --cc: var(--cat-shopping); }
[data-cat="health"]        { --cc: var(--cat-health); }
[data-cat="entertainment"] { --cc: var(--cat-entertainment); }
[data-cat="utilities"]     { --cc: var(--cat-utilities); }
[data-cat="travel"]        { --cc: var(--cat-travel); }
[data-cat="education"]     { --cc: var(--cat-education); }
[data-cat="other"]         { --cc: var(--cat-other); }

.cat-dot, .cat-bar   { background: var(--cc, var(--cat-other)); }
.expense-cat-icon    { background: color-mix(in srgb, var(--cc, var(--cat-other)) 15%, transparent); }
.expense-cat-tag     { background: color-mix(in srgb, var(--cc, var(--cat-other)) 18%, transparent);
                       color: color-mix(in srgb, var(--cc, var(--cat-other)) 80%, #000); }
