/* ============================================================
   SpendLog – Stylesheet
   Aesthetic: Clean financial ledger · dark navy + warm amber
   Font pairing: DM Serif Display + DM Sans
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&display=swap');

/* ── Variables ───────────────────────────────────────────── */
:root {
    --navy:       #0f1b2d;
    --navy-mid:   #162236;
    --navy-light: #1e3050;
    --amber:      #f0a500;
    --amber-dim:  #c48400;
    --cream:      #f5f0e8;
    --cream-dim:  #e8e0d0;
    --white:      #ffffff;
    --red:        #e05252;
    --green:      #3db87a;
    --muted:      #8a9bb0;
    --border:     rgba(255,255,255,0.08);
    --radius:     10px;
    --shadow:     0 4px 24px rgba(0,0,0,0.35);
    --font-head:  'DM Serif Display', Georgia, serif;
    --font-body:  'DM Sans', system-ui, sans-serif;
    --transition: 0.18s ease;
}

/* ── Light theme overrides ───────────────────────────────── */
body.light {
    --navy:       #f0f4f8;
    --navy-mid:   #ffffff;
    --navy-light: #e2eaf2;
    --amber:      #b87a00;
    --amber-dim:  #a36e00;
    --cream:      #1a2535;
    --cream-dim:  #2d3e52;
    --muted:      #5a7090;
    --border:     rgba(0,0,0,0.12);
    --shadow:     0 4px 24px rgba(0,0,0,0.10);
    --green:      #1f8f52;
    --red:        #c03030;
    background:   #f0f4f8;
    color:        #1a2535;
}

/* Force all major containers to inherit variable colours */
body.light .topbar,
body.light .card,
body.light .stat-card,
body.light .budget-bar-wrap,
body.light .table-wrap,
body.light thead th,
body.light .suggest-form-wrap,
body.light .suggestion-item,
body.light .login-box,
body.light .modal-box {
    background: var(--navy-light);
    border-color: var(--border);
    color: var(--cream);
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body.light .topbar { background: var(--navy-mid); }

body.light table tbody tr { background: var(--navy-mid); }
body.light table tbody tr:hover { background: var(--navy-light); }
body.light .daily-subtotal { background: rgba(180,130,0,0.08); }

body.light tbody td,
body.light .suggestion-name,
body.light .stat-card .value,
body.light .section-header h2,
body.light .card h2,
body.light .date-label { color: var(--cream); }

body.light .stat-card .sub,
body.light .suggestion-meta,
body.light .suggestion-note,
body.light thead th,
body.light .budget-bar-label { color: var(--muted); }

body.light .budget-bar-track { background: #c8d6e5; }

body.light .form-group input,
body.light .form-group textarea,
body.light .form-group select {
    background: #ffffff;
    border-color: rgba(0,0,0,0.15);
    color: var(--cream);
}

body.light .topbar-brand,
body.light .stat-card .value,
body.light .td-total,
body.light .date-label { color: var(--amber); }

body.light .user-badge { border-color: var(--border); color: var(--muted); }
body.light .footer { border-color: var(--border); color: var(--muted); }

body.light .btn-ghost {
    color: var(--muted);
    border-color: var(--border);
}
body.light .btn-ghost:hover { color: var(--cream); }

/* Smooth transition on ALL elements when theme switches */
body, body * {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

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

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

body {
    font-family: var(--font-body);
    background: var(--navy);
    color: var(--cream);
    min-height: 100vh;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
}

a { color: var(--amber); text-decoration: none; }
a:hover { color: #ffd166; }

/* ── Layout ──────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
    background: var(--navy-mid);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

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

.topbar-brand svg { width: 22px; height: 22px; }

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-nav .user-badge {
    font-size: 0.8rem;
    color: var(--muted);
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
}

.topbar-nav .user-badge span { color: var(--amber); font-weight: 600; }

/* ── Main content ────────────────────────────────────────── */
.main {
    flex: 1;
    padding: 2rem 1.5rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

/* ── Stat cards ──────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--navy-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
    background: var(--amber);
    border-radius: var(--radius) 0 0 var(--radius);
}

.stat-card .label {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.stat-card .value {
    font-family: var(--font-head);
    font-size: 1.9rem;
    color: var(--amber);
    line-height: 1;
}

.stat-card .sub {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.3rem;
}

/* ── Section heading ─────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-family: var(--font-head);
    font-size: 1.3rem;
    color: var(--cream);
    font-weight: 400;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.5rem 1.1rem;
    border-radius: 7px;
    border: none;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    text-decoration: none;
    line-height: 1;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--amber);
    color: var(--navy);
}
.btn-primary:hover { background: #ffc62e; color: var(--navy); box-shadow: 0 0 0 3px rgba(240,165,0,0.25); }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--cream); border-color: var(--muted); }

.btn-danger {
    background: transparent;
    color: var(--red);
    border: 1px solid rgba(224,82,82,0.3);
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-edit {
    background: transparent;
    color: var(--amber);
    border: 1px solid rgba(240,165,0,0.3);
}
.btn-edit:hover { background: rgba(240,165,0,0.15); }

.btn-sm { font-size: 0.78rem; padding: 0.35rem 0.8rem; }

/* ── Flash messages ──────────────────────────────────────── */
.flash {
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.flash-success { background: rgba(61,184,122,0.15); border: 1px solid rgba(61,184,122,0.35); color: var(--green); }
.flash-error   { background: rgba(224,82,82,0.15);  border: 1px solid rgba(224,82,82,0.35);  color: var(--red); }

/* ── Date group ──────────────────────────────────────────── */
.date-group { margin-bottom: 2rem; }

.date-label {
    font-family: var(--font-head);
    font-size: 1.05rem;
    color: var(--amber);
    font-style: italic;
    margin-bottom: 0.6rem;
    padding-left: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.date-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
    margin-left: 0.5rem;
}

/* ── Table ───────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 560px;
}

thead th {
    background: var(--navy-light);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.7rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.03); }

tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    color: var(--cream);
}

.td-num {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.td-total {
    font-weight: 600;
    color: var(--amber);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.td-actions {
    text-align: right;
    white-space: nowrap;
}

.daily-subtotal {
    background: rgba(240,165,0,0.06);
}

.daily-subtotal td {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--amber);
    padding: 0.5rem 1rem;
    border-top: 1px solid rgba(240,165,0,0.15);
}

/* ── Forms ───────────────────────────────────────────────── */
.card {
    background: var(--navy-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
}

.card h2 {
    font-family: var(--font-head);
    font-size: 1.3rem;
    margin-bottom: 1.4rem;
    color: var(--cream);
    font-weight: 400;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.form-group input,
.form-group textarea,
.form-group select {
    background: var(--navy);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--cream);
    font-family: var(--font-body);
    font-size: 0.92rem;
    padding: 0.6rem 0.85rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    width: 100%;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(240,165,0,0.18);
}

.form-group textarea { resize: vertical; min-height: 72px; }

.form-footer {
    margin-top: 1.25rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: flex-end;
}

/* ── Login page ──────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--navy);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(240,165,0,0.07) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(30,48,80,0.8) 0%, transparent 60%);
    padding: 2rem 1rem;
}

.login-box {
    background: var(--navy-mid);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem 2.25rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.login-logo {
    font-family: var(--font-head);
    font-size: 2rem;
    color: var(--amber);
    text-align: center;
    margin-bottom: 0.25rem;
}

.login-sub {
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 2rem;
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}

.empty-state svg { opacity: 0.3; margin-bottom: 1rem; }
.empty-state p { font-size: 0.9rem; }

/* ── Theme toggle button ─────────────────────────────────── */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    color: var(--amber);
    border-color: var(--amber);
    background: rgba(240,165,0,0.08);
}

.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
body.light .theme-toggle .icon-sun  { display: block !important; }
body.light .theme-toggle .icon-moon { display: none  !important; }

/* ── Budget progress bar ─────────────────────────────────── */
.budget-bar-wrap {
    background: var(--navy-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 2rem;
}

.budget-bar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
}

.budget-bar-label {
    font-size: 0.82rem;
    color: var(--muted);
}

.budget-bar-pct {
    font-family: var(--font-head);
    font-size: 1rem;
    font-weight: 400;
}

.budget-bar-track {
    height: 8px;
    background: var(--navy);
    border-radius: 99px;
    overflow: hidden;
}

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

/* ── Footer ──────────────────────────────────────────────── */
.footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.78rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

/* ── Confirmation modal ──────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--navy-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 380px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
}

.modal-box h3 {
    font-family: var(--font-head);
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: var(--cream);
}

.modal-box p { font-size: 0.88rem; color: var(--muted); margin-bottom: 1.5rem; }

.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* ── Suggestions ─────────────────────────────────────────── */
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--amber);
    color: var(--navy);
    font-family: var(--font-body);
    font-size: 0.7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.suggest-form-wrap {
    background: var(--navy-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
}

.suggest-form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

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

.suggestion-item {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    background: var(--navy-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    transition: background var(--transition);
}

.suggestion-item.is-bought {
    opacity: 0.5;
}

.suggestion-item.is-bought .suggestion-name {
    text-decoration: line-through;
}

.suggestion-icon {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(240,165,0,0.12);
    color: var(--amber);
}

.is-bought .suggestion-icon {
    background: rgba(61,184,122,0.12);
    color: var(--green);
}

.suggestion-body {
    flex: 1;
    min-width: 0;
}

.suggestion-name {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--cream);
}

.suggestion-note {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

.suggestion-meta {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.2rem;
}

.suggestion-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .main { padding: 1.25rem 1rem; }

    .topbar { padding: 0 1rem; }

    .topbar-brand { font-size: 1.15rem; }

    .stats-row { grid-template-columns: 1fr 1fr; }

    .form-grid { grid-template-columns: 1fr; }

    .btn-text-hide { display: none; }

    .card { padding: 1.25rem; }

    .section-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }

    .suggest-form-row { flex-direction: column; }
}

@media (max-width: 380px) {
    .stats-row { grid-template-columns: 1fr; }
}
