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

:root {
    --color-good: #22C55E;
    --color-caution: #F59E0B;
    --color-over: #EF4444;
    --color-neutral: #3B82F6;
    --color-budget-line: #6B7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-card: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --nav-bg: #1f2937;
    --nav-text: #f9fafb;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}

html { font-size: 16px; }
body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--color-neutral); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navigation === */
.top-nav {
    background: var(--nav-bg);
    color: var(--nav-text);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}
.nav-brand {
    color: var(--nav-text);
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.75rem 0;
    text-decoration: none;
}
.nav-toggle-checkbox { display: none; }
.nav-toggle-label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 0.75rem 0;
}
.nav-toggle-label span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--nav-text);
    transition: transform 0.3s;
}
.nav-links {
    list-style: none;
    display: none;
    width: 100%;
    flex-direction: column;
    padding-bottom: 0.5rem;
}
.nav-toggle-checkbox:checked ~ .nav-links { display: flex; }
.nav-links li a {
    display: block;
    color: var(--nav-text);
    padding: 0.5rem 0;
    text-decoration: none;
    opacity: 0.85;
    font-size: 0.95rem;
}
.nav-links li a:hover, .nav-links li a.active {
    opacity: 1;
    text-decoration: none;
}
.nav-links li a.active { border-bottom: 2px solid var(--color-neutral); }
.nav-logout { opacity: 0.6 !important; }

@media (min-width: 768px) {
    .nav-toggle-label { display: none; }
    .nav-links {
        display: flex;
        flex-direction: row;
        width: auto;
        padding-bottom: 0;
        gap: 0.25rem;
    }
    .nav-links li a {
        padding: 0.75rem 0.75rem;
    }
}

/* === Layout === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* === Page Header === */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* === Cards Grid === */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}
@media (min-width: 640px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .card-grid { grid-template-columns: repeat(3, 1fr); }
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.card-title {
    font-size: 0.95rem;
    font-weight: 600;
}

/* === Status Dot === */
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.good { background: var(--color-good); }
.status-dot.caution { background: var(--color-caution); }
.status-dot.on-budget { background: var(--color-neutral); }
.status-dot.over { background: var(--color-over); }

/* === Progress Bar === */
.progress-bar-container {
    width: 100%;
    height: 12px;
    background: #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}
.progress-bar {
    height: 100%;
    border-radius: 6px;
    transition: width 0.4s ease;
    min-width: 2px;
}
.progress-bar.good { background: var(--color-good); }
.progress-bar.caution { background: var(--color-caution); }
.progress-bar.on-budget { background: var(--color-neutral); }
.progress-bar.over { background: var(--color-over); }

.card-spent {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}
.card-remaining {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.card-remaining.over { color: var(--color-over); font-weight: 600; }

/* === Summary Metric Cards === */
.metric-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}
@media (min-width: 640px) {
    .metric-cards { grid-template-columns: repeat(3, 1fr); }
}
.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
}
.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}
.metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}
.metric-value.good { color: var(--color-good); }
.metric-value.over { color: var(--color-over); }

/* === Chart Containers === */
.chart-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}
.chart-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}
.chart-wrapper {
    position: relative;
    width: 100%;
}

/* === Custom Chart Legend === */
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
    font-size: 0.85rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.2s;
}
.legend-item.dimmed { opacity: 0.3; }
.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* === Forms === */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-neutral);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    text-decoration: none;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn-primary { background: var(--color-neutral); color: #fff; }
.btn-danger { background: var(--color-over); color: #fff; }
.btn-secondary { background: #e5e7eb; color: var(--text-primary); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-full { width: 100%; }

/* === Alerts === */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* === Tables === */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.5rem;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead th {
    text-align: left;
    padding: 0.65rem 0.75rem;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
thead th a { color: var(--text-secondary); }
tbody td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
tbody tr:hover { background: var(--bg-secondary); }
.amount-large { color: var(--color-over); font-weight: 600; }
.sort-arrow { font-size: 0.75rem; margin-left: 0.2rem; }

/* === Heatmap === */
.heatmap-cell {
    padding: 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    min-width: 80px;
    cursor: pointer;
}
.heatmap-cell:hover { outline: 2px solid var(--color-neutral); }
.heatmap-good { background: #dcfce7; }
.heatmap-caution { background: #fef3c7; }
.heatmap-on-budget { background: #dbeafe; }
.heatmap-over { background: #fecaca; }
.heatmap-empty { background: #f3f4f6; color: var(--text-muted); }

/* === Filters Row === */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}
.filters .form-group {
    margin-bottom: 0;
    min-width: 150px;
    flex: 1;
}
@media (min-width: 768px) {
    .filters .form-group { flex: 0 1 auto; min-width: 160px; }
}

/* === Person Pills === */
.person-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.person-pill {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    background: #e5e7eb;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}
.person-pill:hover { background: #d1d5db; text-decoration: none; }
.person-pill.active {
    background: var(--color-neutral);
    color: #fff;
}

/* === Pagination === */
.pagination {
    display: flex;
    gap: 0.35rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.pagination a, .pagination span {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--text-primary);
}
.pagination a:hover { background: var(--bg-secondary); }
.pagination .current {
    background: var(--color-neutral);
    color: #fff;
    border-color: var(--color-neutral);
}

/* === Login Page === */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    margin: 1rem;
    box-shadow: var(--shadow-md);
    text-align: center;
}
.login-card h1 {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* === Admin Sections === */
.admin-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.admin-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* === Radio Group === */
.radio-group {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 0.5rem;
}
.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    cursor: pointer;
}
.radio-group input[type="radio"] { width: auto; }

/* === Toggle Button === */
.toggle-group {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}
.toggle-btn {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-family: inherit;
    border: none;
    background: var(--bg-primary);
    cursor: pointer;
    color: var(--text-secondary);
}
.toggle-btn.active {
    background: var(--color-neutral);
    color: #fff;
}

/* === Color Swatch === */
.color-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,0.1);
}

/* === Footer === */
.site-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* === Utilities === */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.fw-bold { font-weight: 600; }
