/* ── Reset & base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 1rem;
    color: #212529;
    background: #f4f5f7;
}

a { color: #4f8ef7; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

@media (prefers-reduced-motion: no-preference) {
    .page-content { animation: pageIn 0.35s ease-out both; }
    @keyframes pageIn {
        from { opacity: 0; transform: translateY(16px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #1a1a2e;
    color: #e0e0e0;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
}

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: block;
    padding: 0.55rem 1rem;
    color: #c0c8d8;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background 0.15s;
}

.sidebar-nav li a:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-nav li.active a {
    background: rgba(255,255,255,0.1);
    border-left: 3px solid #4f8ef7;
    color: #fff;
}

.sidebar-footer {
    padding: 0.5rem 0;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* Logout button — styled as a sidebar link */
.sidebar-logout-form { margin: 0; padding: 0; }
.sidebar-logout-btn {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: #c0c8d8;
    cursor: pointer;
    font: inherit;
    font-size: 1rem;
    padding: 0.55rem 1rem;
    text-align: left;
    border-left: 3px solid transparent;
    transition: background 0.15s;
}
.sidebar-logout-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

/* ── Page content ───────────────────────────────────────────────────────────── */
.page-content {
    flex: 1;
    padding: 2rem;
    background: #f4f5f7;
    min-width: 0; /* prevent flex child overflow */
}

/* ── Alerts / flash messages ────────────────────────────────────────────────── */
.alert {
    padding: .75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}
.alert-success  { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.alert-error,
.alert-danger   { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }
.alert-warning  { background: #fff3cd; color: #856404; border-color: #ffeeba; }
.alert-info     { background: #d1ecf1; color: #0c5460; border-color: #bee5eb; }

/* ── Login page ─────────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f4f5f7;
}

.login-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.10);
    padding: 2rem 2.5rem;
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    margin: 0 0 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a2e;
    text-align: center;
}

.form-group {
    margin-bottom: 1.1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #444;
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    color: #212529;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #4f8ef7;
    box-shadow: 0 0 0 3px rgba(79,142,247,0.15);
}

.form-group select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23666' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 14px 10px;
    padding-right: 2.25rem;
    cursor: pointer;
}

.form-group textarea {
    width: 100%;
    min-height: 80px;
    resize: vertical;
}

.form-group--check label,
.form-check-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #444;
    cursor: pointer;
    margin-bottom: 0;
}

.form-group--check input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #4f8ef7;
}

.form-group--error input,
.form-group--error select,
.form-group--error textarea {
    border-color: #dc3545;
}

.form-error {
    color: #dc3545;
    font-size: 0.83rem;
    margin: 0.3rem 0 0;
}

.form-hint {
    color: #6c757d;
    font-size: 0.83rem;
    margin: 0.3rem 0 0;
}

/* ── Form card ───────────────────────────────────────────────────────────────── */
.form-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    padding: 2rem;
}

/* ── Month filter bar ────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    color: #444;
}

.filter-bar select {
    padding: 0.35rem 2rem 0.35rem 0.65rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #212529;
    background: #fff;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23666' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.55rem center;
    background-size: 12px 9px;
    cursor: pointer;
}

.filter-bar select:focus {
    outline: none;
    border-color: #4f8ef7;
    box-shadow: 0 0 0 3px rgba(79,142,247,0.15);
}

.filter-total {
    font-weight: 600;
    color: #212529;
}

/* ── Action icon buttons ─────────────────────────────────────────────────────── */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: none;
    background: none;
    color: #6c757d;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    padding: 0;
    font: inherit;
}

.action-btn:hover {
    color: #4f8ef7;
    background: rgba(79,142,247,0.08);
    text-decoration: none;
}

.action-btn--danger:hover {
    color: #dc3545;
    background: rgba(220,53,69,0.08);
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-primary {
    background: #4f8ef7;
    color: #fff;
}

.btn-primary:hover {
    background: #3a7ae0;
    color: #fff;
    text-decoration: none;
}

.login-card .btn-primary { width: 100%; margin-top: 0.5rem; }


/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 { margin: 0; font-size: 1.5rem; }

/* ── Buttons (additional variants) ─────────────────────────────────────────── */
.btn-secondary {
    background: #6c757d;
    color: #fff;
}

.btn-secondary:hover {
    background: #5a6268;
    color: #fff;
    text-decoration: none;
}

.btn-link {
    background: none;
    border: none;
    color: #4f8ef7;
    cursor: pointer;
    font: inherit;
    font-size: 1rem;
    padding: 0;
    text-decoration: none;
}

.btn-link:hover { text-decoration: underline; }

.btn-danger { color: #dc3545; }
.btn-danger:hover { color: #a71d2a; }
.text-danger { color: #dc3545; }

.btn-outline {
    background: transparent;
    border: 1px solid #6c757d;
    color: #6c757d;
}
.btn-outline:hover {
    background: #6c757d;
    color: #fff;
    text-decoration: none;
}

/* ── Data table ─────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.data-table th, .data-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}
.data-table th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 0.875rem;
    color: #495057;
}
.data-table tr:hover td { background: #f8f9fa; }
.data-table .actions { white-space: nowrap; text-align: right; }
.data-table .actions a, .data-table .actions button { margin-left: 0.5rem; }

/* Expired / dimmed rows */
.row-dimmed td { opacity: 0.45; }

/* ── Badge ──────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.2em 0.55em;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 3px;
    background: #e9ecef;
    color: #495057;
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: #6c757d;
}

/* ── Form layout ────────────────────────────────────────────────────────────── */
.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}


/* ── Utility charts ─────────────────────────────────────────────────────────── */
.chart-wrap { height: 250px; }

/* ── Planning grid ──────────────────────────────────────────────────────────── */
.subtitle { color: #6c757d; margin: -0.75rem 0 1.5rem; }

.planning-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.planning-column {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.planning-column h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #1a1a2e;
    text-transform: capitalize;
}

.planning-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.planning-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
}

.planning-name { flex: 1; }

.planning-amount {
    font-weight: 500;
    white-space: nowrap;
}

.planning-edit {
    color: #6c757d;
    text-decoration: none;
    font-size: 0.85rem;
}

.planning-edit:hover { color: #4f8ef7; }

.planning-total {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e5e7eb;
    text-align: right;
    font-size: 0.95rem;
}

.no-expenses { color: #6c757d; font-size: 0.9rem; margin: 0; }

@media (max-width: 900px) {
    .planning-grid { grid-template-columns: 1fr; }
}

/* ── Dashboard stat cards ───────────────────────────────────────────────────── */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.stat-label { font-size: .85rem; color: #6b7280; margin-bottom: .5rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }

.stat-income  .stat-value { color: #16a34a; }
.stat-expenses .stat-value { color: #dc2626; }
.stat-positive .stat-value { color: #16a34a; }
.stat-negative .stat-value { color: #dc2626; }

@media (max-width: 600px) {
    .stat-cards { grid-template-columns: 1fr; }
}

/* ── Dashboard sections ─────────────────────────────────────────────────────── */
.dashboard-section { margin-bottom: 2rem; }
.dashboard-section h2 { margin-bottom: 0.75rem; }

.planning-mini-grid {
    display: flex;
    gap: 1rem;
    margin: .75rem 0;
}

.planning-mini-col {
    flex: 1;
    background: #f9fafb;
    border-radius: 6px;
    padding: .75rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.planning-mini-total { font-weight: 600; }
.planning-mini-count { font-size: .85rem; color: #6b7280; }

.quick-add {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .data-table { font-size: .875rem; }
    .data-table .actions { white-space: nowrap; }
    .data-table .hide-mobile { display: none; }

    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .sidebar-header { flex: 0 0 auto; }
    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
        flex: 1;
        padding: 0;
    }
    .sidebar-nav li a { padding: 0.5rem 0.75rem; }
    .sidebar-footer { width: 100%; }
}
