/* =========================================================
   Personal Finance Manager -- global stylesheet
   ========================================================= */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-accent: #14b8a6;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --color-success: #16a34a;
    --color-bg: #f4f6fb;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --radius: 12px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
    --sidebar-width: 250px;
    --font: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-heading: var(--font);
    --bg-gradient: linear-gradient(160deg, #eef2ff 0%, #f4f6fb 45%, #ecfdf5 100%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; font-family: var(--font-heading); }
p { margin: 0 0 1em; }

/* ---------- Animated SVG background ---------- */
.bg-animated {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background: var(--bg-gradient);
}
.bg-animated svg { position: absolute; width: 100%; height: 100%; }
.bg-blob {
    opacity: 0.55;
    filter: blur(2px);
    transform-origin: center;
    animation: float-blob 18s ease-in-out infinite;
}
.bg-blob.b2 { animation-duration: 24s; animation-delay: -4s; }
.bg-blob.b3 { animation-duration: 30s; animation-delay: -10s; }
.bg-blob.b4 { animation-duration: 22s; animation-delay: -7s; }
@keyframes float-blob {
    0%   { transform: translate(0, 0) scale(1); }
    33%  { transform: translate(3%, -4%) scale(1.06); }
    66%  { transform: translate(-3%, 3%) scale(0.96); }
    100% { transform: translate(0, 0) scale(1); }
}
.bg-grid-line { stroke: #cbd5e1; stroke-width: 1; opacity: 0.35; }
@media (prefers-reduced-motion: reduce) {
    .bg-blob { animation: none; }
}

/* ---------- Layout containers ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.surface {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}
.card { padding: 20px; }

/* ---------- Public site nav ---------- */
.site-header {
    position: sticky; top: 0; z-index: 20;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--color-border);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--color-text); }
.brand img { height: 36px; width: 36px; object-fit: cover; border-radius: 50%; }
.site-nav ul { list-style: none; display: flex; gap: 22px; margin: 0; padding: 0; }
.site-nav a { color: var(--color-text); font-weight: 500; }
.site-nav a:hover { color: var(--color-primary); text-decoration: none; }
.nav-toggle {
    display: none; background: none; border: none; font-size: 1.5rem; line-height: 1;
    cursor: pointer; color: var(--color-text); padding: 6px 4px;
}

.hero { padding: 90px 0 70px; text-align: center; }
.hero h1 { font-size: 2.6rem; background: linear-gradient(90deg, var(--color-primary), var(--color-accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { font-size: 1.15rem; color: var(--color-text-muted); max-width: 640px; margin: 0 auto 28px; }

.site-footer { padding: 28px 0; text-align: center; color: var(--color-text-muted); border-top: 1px solid var(--color-border); background: var(--color-surface); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: 8px; border: 1px solid transparent;
    font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all .15s ease;
    background: var(--color-primary); color: #fff;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn.btn-outline { background: transparent; border-color: var(--color-primary); color: var(--color-primary); }
.btn.btn-outline:hover { background: var(--color-primary); color: #fff; }
.btn.btn-danger { background: var(--color-danger); }
.btn.btn-danger:hover { background: #b91c1c; }
.btn.btn-success { background: var(--color-success); }
.btn.btn-ghost { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
input, select, textarea {
    width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--color-border);
    font-family: inherit; font-size: 16px; background: #fff; color: var(--color-text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1 1 200px; }
.help-text { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 4px; }
.field-error { color: var(--color-danger); font-size: 0.8rem; margin-top: 4px; }
fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
legend { font-weight: 700; padding: 0 8px; }

/* ---------- Theme picker (Site Settings > Appearance) ---------- */
.theme-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.theme-option {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 2px solid var(--color-border);
    border-radius: 10px; cursor: pointer; font-weight: 500; font-size: 0.88rem; margin-bottom: 0;
}
.theme-option:hover { border-color: var(--color-primary); }
.theme-option.selected { border-color: var(--color-primary); background: rgba(37, 99, 235, 0.06); }
.theme-option input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
/* The swatch carries its own data-theme, so themes.css's variable overrides apply just to it --
   giving an accurate live color preview for every option with no JS or duplicated palette data. */
.theme-swatch { display: inline-flex; flex-shrink: 0; border-radius: 6px; overflow: hidden; box-shadow: var(--shadow-sm); }
.theme-swatch-primary, .theme-swatch-accent { width: 12px; height: 24px; }
.theme-swatch-primary { background: var(--color-primary); }
.theme-swatch-accent { background: var(--color-accent); }

/* ---------- Alerts / toasts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; border: 1px solid transparent; }
.alert-success { background: #dcfce7; color: #14532d; border-color: #bbf7d0; }
.alert-danger { background: #fee2e2; color: #7f1d1d; border-color: #fecaca; }
.alert-warning { background: #fef3c7; color: #78350f; border-color: #fde68a; }
.alert-info { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }

#toast-container { position: fixed; top: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast { min-width: 260px; padding: 12px 16px; border-radius: 8px; color: #fff; box-shadow: var(--shadow-md); animation: toast-in .25s ease; }
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.info { background: var(--color-primary); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- App shell (admin + user) ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-width); flex-shrink: 0; background: #0f172a; color: #e2e8f0;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { color: #fff; padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar .back-to-main {
    display: flex; align-items: center; gap: 6px;
    color: #93c5fd; font-size: 0.82rem; font-weight: 600;
    padding: 10px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .back-to-main:hover { color: #fff; text-decoration: none; background: rgba(37,99,235,0.2); }
.sidebar nav ul { list-style: none; margin: 0; padding: 12px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: #cbd5e1; padding: 10px 14px; border-radius: 8px; margin-bottom: 4px; font-weight: 500; }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(37,99,235,0.25); color: #fff; text-decoration: none; }
.sidebar .user-box { margin-top: auto; padding: 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.85rem; }

.main-content { flex: 1; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 24px; background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    position: sticky; top: 0; z-index: 10;
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content-area { padding: 24px; }

.sidebar-toggle {
    display: none; flex-shrink: 0; background: none; border: none; font-size: 1.4rem; line-height: 1;
    cursor: pointer; color: var(--color-text); padding: 4px 6px;
}
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 40; }
.sidebar-backdrop.open { display: block; }

/* ---------- Quick add (dashboard) ---------- */
.quick-add-card { border-top: 3px solid var(--color-primary); margin-bottom: 24px; }
.quick-add-submit button { height: 42px; }

/* ---------- Dashboard grid ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card { padding: 18px 20px; }
.stat-card .stat-label { color: var(--color-text-muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; margin-top: 6px; }
.stat-card.up .stat-value { color: var(--color-success); }
.stat-card.down .stat-value { color: var(--color-danger); }

.chart-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 24px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { padding: 20px; }
.chart-card h3 { font-size: 1rem; margin-bottom: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 0.82rem; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--color-border); }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-muted); background: #f8fafc; }
tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-green { background: #dcfce7; color: #14532d; }
.badge-red { background: #fee2e2; color: #7f1d1d; }
.badge-amber { background: #fef3c7; color: #78350f; }
.badge-gray { background: #e2e8f0; color: #334155; }
.row-actions { display: flex; gap: 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.toolbar .filters { display: flex; flex-wrap: wrap; gap: 10px; }
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--color-border); font-size: 0.85rem; }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--color-border); }
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--color-text-muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 18px; }
.tab-btn { padding: 10px 16px; background: none; border: none; cursor: pointer; font-weight: 600; color: var(--color-text-muted); border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--color-primary); border-color: var(--color-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.w-full { width: 100%; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 50; width: 260px; max-width: 82vw; height: 100vh;
        transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: var(--shadow-md);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; align-items: center; }

    .topbar { padding: 14px 16px; }
    .content-area { padding: 16px; }

    .nav-toggle { display: block; }
    .site-header .container { height: 60px; }
    .site-nav {
        position: absolute; top: 60px; left: 0; right: 0; background: var(--color-surface);
        border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow-md);
        max-height: 0; overflow: hidden; transition: max-height 0.25s ease;
    }
    .site-nav.open { max-height: 70vh; overflow-y: auto; }
    .site-nav ul { display: flex; flex-direction: column; gap: 0; padding: 8px 20px 16px; }
    .site-nav ul li { border-bottom: 1px solid var(--color-border); }
    .site-nav ul li:last-child { border-bottom: none; }
    .site-nav ul li a { display: block; padding: 13px 0; }

    .hero { padding: 50px 0 40px; }
    .hero h1 { font-size: 1.9rem; }
    .hero p { font-size: 1rem; }

    .container { padding: 0 16px; }
    .card { padding: 16px; }
    .stat-grid { grid-template-columns: 1fr; gap: 12px; }
    .chart-grid { gap: 12px; }

    .modal-backdrop { padding: 0; align-items: flex-end; }
    .modal { max-width: 100%; width: 100%; max-height: 92vh; border-radius: var(--radius) var(--radius) 0 0; }
    .modal-header, .modal-footer { padding: 14px 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { flex-wrap: wrap; }
    .modal-footer .btn { flex: 1 1 auto; }

    .form-row { gap: 12px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .filters { width: 100%; }
    .toolbar .filters select, .toolbar .filters input { flex: 1 1 140px; }
    .row-actions { flex-wrap: wrap; }

    table { font-size: 0.82rem; }
    th, td { padding: 8px; }
}
