/* ===== Базовые стили ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    background: #f0f2f5;
    color: #333;
    line-height: 1.5;
}
a { color: #3498db; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Шапка ===== */
.site-header {
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    display: none;
}
.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
}
.header-logo {
    font-weight: 700;
    color: #2c3e50;
    font-size: 16px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #2c3e50;
    padding: 4px 8px;
    height: 50px;
    width: 40px;
    background: #287ccc;
}
.avatar-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #3498db;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    flex-shrink: 0;
}

/* ===== Авторизация ===== */
.auth-wrapper {
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; padding: 20px;
}
.auth-card {
    background: #fff; border-radius: 12px; padding: 40px;
    box-shadow: 0 2px 20px rgba(0,0,0,0.1); width: 100%; max-width: 400px;
}
.auth-card h1 { margin-bottom: 24px; text-align: center; color: #2c3e50; }
.auth-link { text-align: center; margin-top: 16px; }

/* ===== Формы ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
.form-group input {
    width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 6px;
    font-size: 15px; transition: border-color 0.2s;
}
.form-group input:focus { border-color: #3498db; outline: none; }

.form-row {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
}
.form-row input, .form-row select, .form-row button { margin: 0; }
.form-row input, .form-row select {
    padding: 8px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
}
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select {
    padding: 8px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px;
}
.filter-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-form label { display: flex; align-items: center; gap: 6px; }
.filter-form input { padding: 6px 10px; border: 1px solid #ddd; border-radius: 6px; }

/* ===== Кнопки ===== */
.btn {
    padding: 10px 20px; background: #3498db; color: #fff; border: none;
    border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 600;
    transition: background 0.2s;
}
.btn:hover { background: #2980b9; }
.btn-sm {
    padding: 4px 10px; border: none; border-radius: 4px;
    cursor: pointer; font-size: 13px; background: #3498db; color: #fff;
}
.btn-sm:hover { background: #2980b9; }
.btn-danger { background: #e74c3c; }
.btn-danger:hover { background: #c0392b; }

/* ===== Алерты ===== */
.alert {
    padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px;
}
.alert.error { background: #fdf2f2; color: #e74c3c; border: 1px solid #e74c3c; }

/* ===== Лейаут ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; background: #2c3e50; color: #fff; padding: 20px; flex-shrink: 0;
}
.sidebar h2 { margin-bottom: 20px; font-size: 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 8px; }
.sidebar nav a {
    color: #ecf0f1; padding: 10px 14px; border-radius: 6px; transition: background 0.2s;
}
.sidebar nav a:hover, .sidebar nav a.active {
    background: #34495e; text-decoration: none;
}
.content { flex: 1; padding: 30px; overflow-x: auto; }
.content h1 { margin-bottom: 24px; color: #2c3e50; }
.content h3 { margin-bottom: 16px; color: #34495e; }

/* ===== Карточки статистики ===== */
.stats-row {
    display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin-bottom: 24px;
}
.stat-card {
    background: #fff; border-radius: 10px; padding: 18px 20px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08); text-align: center;
    border: 2px solid transparent;
}
.stat-card .label {
    display: block; font-size: 13px; color: #7f8c8d; margin-bottom: 6px;
}
.stat-card .value {
    display: block; font-size: 22px; font-weight: 700; color: #2c3e50;
}
.stat-card.income { border-color: #2ecc71; }
.stat-card.income .value { color: #2ecc71; }
.stat-card.expense { border-color: #e74c3c; }
.stat-card.expense .value { color: #e74c3c; }
.stat-card.balance .value { font-size: 26px; }

/* ===== Карточки ===== */
.card {
    background: #fff; border-radius: 10px; padding: 24px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.08); margin-bottom: 24px;
}

/* ===== Таблицы ===== */
.table {
    width: 100%; border-collapse: collapse; font-size: 14px;
}
.table th {
    text-align: left; padding: 10px 12px; background: #f8f9fa;
    border-bottom: 2px solid #dee2e6; color: #495057; font-weight: 600;
}
.table td {
    padding: 10px 12px; border-bottom: 1px solid #eee;
}
.table tr:hover { background: #f8f9fa; }
.row-over { background: #fdf2f2 !important; }
.row-warn { background: #fff8e1 !important; }

/* ===== Бейджи ===== */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 4px;
    font-size: 12px; font-weight: 600; color: #fff;
}
.badge-green { background: #2ecc71; }
.badge-red { background: #e74c3c; }
.badge-yellow { background: #f39c12; }

/* ===== Прогресс-бар ===== */
.progress-bar {
    width: 100%; height: 24px; background: #ecf0f1; border-radius: 12px;
    overflow: hidden; margin-bottom: 8px;
}
.progress-bar.small { height: 8px; border-radius: 4px; }
.progress-fill {
    height: 100%; border-radius: 12px; transition: width 0.4s;
}
.progress-fill.ok { background: #2ecc71; }
.progress-fill.warn { background: #f39c12; }
.progress-fill.over { background: #e74c3c; }
.progress-text { font-size: 14px; color: #555; }

/* ===== Обёртка для таблиц (горизонтальная прокрутка) ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============================================ */
/* ===== АДАПТАЦИЯ ДЛЯ МОБИЛЬНЫХ (<= 768px) ===== */
/* ============================================ */
@media (max-width: 768px) {

    /* Шапка: показываем, сайдбар скрываем по умолчанию */
    .site-header {
        display: block;
    }
    .menu-toggle {
        display: block;
    }
    .header-logo {
        font-size: 15px;
    }
    .avatar-link {
        width: 34px;
        height: 34px;
        font-size: 13px;
    }

    /* Сайдбар: выезжающее меню */
    .layout { flex-direction: column; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 200;
        overflow-y: auto;
        padding-top: 60px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar h2 { display: block; font-size: 20px; }
    .sidebar nav a {
        padding: 14px 16px;
        font-size: 15px;
    }

    /* Затемнение фона при открытом меню */
    .sidebar.open::after {
        content: '';
        position: fixed;
        top: 0; left: 260px; right: 0; bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: -1;
    }

    /* Контент на всю ширину */
    .content {
        padding: 14px;
        width: 100%;
    }
    .content h1 {
        font-size: 22px;
        margin-bottom: 16px;
    }
    .content h3 {
        font-size: 17px;
        margin-bottom: 12px;
    }

    /* Карточки статистики — вертикально */
    .stats-row {
        flex-direction: column;
        gap: 10px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .stat-card {
        padding: 14px 16px;
    }
    .stat-card .value {
        font-size: 20px;
    }
    .stat-card.balance .value { font-size: 22px; }

    /* Карточки */
    .card {
        padding: 16px;
        margin-bottom: 16px;
    }

    /* Формы — вертикально */
    .form-row {
        flex-direction: column;
        align-items: stretch;
    }
    .form-row > * {
        width: 100%;
    }
    .form-row input,
    .form-row select {
        font-size: 16px; /* чтобы iOS не зумила */
        padding: 12px 14px;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }
    .inline-form input,
    .inline-form select {
        width: 100%;
        font-size: 16px;
    }

    .filter-form {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-form label {
        margin-bottom: 8px;
    }
    .filter-form input {
        width: 100%;
        font-size: 16px;
    }

    /* Кнопки на всю ширину */
    .btn {
        width: 100%;
        padding: 14px;
        font-size: 16px;
    }
    .btn-sm {
        width: 100%;
        text-align: center;
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Авторизация */
    .auth-card {
        padding: 24px 18px;
    }
    .auth-card h1 {
        font-size: 20px;
    }

    /* Таблицы — карточки */
    .table-wrap {
        overflow-x: auto;
    }
    .table {
        font-size: 15px;
    }
    .table th, .table td {
        padding: 12px 10px;
    }

    /* Прогресс-бары компактнее */
    .progress-bar {
        height: 20px;
    }
    .progress-text {
        font-size: 13px;
    }
}

/* ============================================ */
/* ===== ОЧЕНЬ УЗКИЕ ЭКРАНЫ (<= 400px) ===== */
/* ============================================ */
@media (max-width: 400px) {
    .stat-card .value {
        font-size: 18px;
    }
    .stat-card.balance .value { font-size: 20px; }
    .content h1 { font-size: 20px; }
    .auth-card {
        padding: 20px 14px;
        border-radius: 8px;
    }
    .card {
        padding: 12px;
    }
}


/* ===== Затемнение при открытом мобильном меню ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
}
@media (max-width: 768px) {
    .sidebar.open ~ .sidebar-overlay,
    .sidebar-overlay {
        display: none;
    }
    .sidebar.open + .sidebar-overlay,
    body:has(.sidebar.open) .sidebar-overlay {
        display: block;
    }
}
