*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w: 220px;
    --accent: #4f46e5;
    --accent-light: #eef2ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ── */
html, body { overflow-x: hidden; width: 100%; }
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    background: #1e1b4b;
    color: #c7d2fe;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 100;
}

.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Sidebar ── */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-icon { font-size: 22px; }
.logo-text { font-size: 16px; font-weight: 700; color: #fff; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px;
    flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: #e0e7ff; }
.user-role { font-size: 11px; color: #818cf8; text-transform: uppercase; letter-spacing: .5px; }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }

.nav-section-label {
    padding: 12px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: #6366f1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: #a5b4fc;
    text-decoration: none;
    font-size: 13.5px;
    border-radius: 0;
    transition: background .15s, color .15s;
    cursor: pointer;
    border: none; background: none; width: 100%; text-align: left;
}
.nav-item svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(79,70,229,.35); color: #fff; border-right: 3px solid var(--accent); }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.08); padding: 8px 0; }
.logout-btn { color: #f87171 !important; }
.logout-btn:hover { background: rgba(239,68,68,.1) !important; }

/* ── Mobile menu controls (hidden on desktop) ── */
.sidebar-toggle, .sidebar-close { display: none; }
.sidebar-overlay { display: none; }

/* ── Page ── */
.page-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 28px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }

.page-body { padding: 24px 28px; flex: 1; }

/* ── Card ── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text); }

/* ── Search form ── */
.search-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.form-control {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    min-width: 180px;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }

.btn {
    padding: 8px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s, transform .1s;
    display: inline-flex; align-items: center; gap: 6px;
    text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--accent-light); }
tbody td { padding: 10px 14px; color: var(--text); vertical-align: top; white-space: nowrap; }

/* ── Group rows (collapsible) ── */
.group-row { cursor: pointer; background: var(--bg); }
.group-row:hover { background: var(--accent-light); }
.group-row .group-arrow { display: inline-block; transition: transform .15s; margin-right: 6px; }
.group-row.open .group-arrow { transform: rotate(90deg); }
.group-child { display: none; }
.group-child.open { display: table-row; }

/* ── Copy button ── */
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s, border-color .15s;
}
.copy-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.copy-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { background: #dcfce7; color: #16a34a; border-color: #86efac; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-warning { background: #fef9c3; color: #b45309; }
.badge-danger  { background: #fee2e2; color: #dc2626; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }
.badge-muted   { background: #f1f5f9; color: var(--text-muted); }

/* ── Alert ── */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13.5px; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; stroke: var(--border); margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── Login page ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1e1b4b; }
.login-box { background: #fff; border-radius: 12px; padding: 36px 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-box h1 { font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }
.login-box .form-group { margin-bottom: 16px; }
.login-box .form-control { width: 100%; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 8px; padding: 10px; }

/* ── Pagination ── */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 5px 10px; border-radius: 6px; font-size: 13px; text-decoration: none;
    border: 1px solid var(--border); color: var(--text);
}
.pagination a:hover { background: var(--accent-light); border-color: var(--accent); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Profile form ── */
.profile-form { max-width: 480px; }
.profile-form .form-group { margin-bottom: 16px; }
.profile-form .form-control { width: 100%; }

/* ── Responsive ── */
@media (max-width: 900px) {
    body.no-scroll { overflow: hidden; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        width: 260px;
        max-width: 82vw;
        box-shadow: 0 0 30px rgba(0,0,0,.25);
    }
    .sidebar.sidebar-open { transform: translateX(0); }

    .sidebar-logo { justify-content: space-between; }
    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30px; height: 30px;
        border: none;
        background: rgba(255,255,255,.08);
        border-radius: 6px;
        color: #c7d2fe;
        cursor: pointer;
        flex-shrink: 0;
    }
    .sidebar-close svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,.5);
        z-index: 99;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    .sidebar-overlay.sidebar-overlay-visible { opacity: 1; pointer-events: auto; }

    .main-content { margin-left: 0; }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px; height: 36px;
        border: 1px solid var(--border);
        background: var(--surface);
        border-radius: var(--radius);
        cursor: pointer;
        flex-shrink: 0;
    }
    .sidebar-toggle svg { width: 18px; height: 18px; stroke: var(--text); fill: none; stroke-width: 2; stroke-linecap: round; }

    .page-header { padding: 12px 16px; }
    .page-title { font-size: 17px; }
    .page-body { padding: 14px; }

    .card { padding: 14px 16px; margin-bottom: 14px; }
    .card-title { font-size: 14px; }

    /* формы: раскладываем в столбец и растягиваем на всю ширину */
    .search-form { flex-direction: column; align-items: stretch; gap: 10px; }
    .search-form .form-group { width: 100%; }
    .form-control { min-width: 0; width: 100%; }
    .search-form .btn { width: 100%; justify-content: center; }

    /* карточки-статистики (инлайн flex в crm.php и др.) переносятся по 2 в ряд */
    div[style*="display:flex"][style*="flex-wrap:wrap"] > .card[style*="text-align:center"] {
        min-width: 45% !important;
    }

    table { font-size: 12.5px; }
    thead th { padding: 8px 10px; font-size: 10px; }
    tbody td { padding: 8px 10px; }

    .btn { padding: 7px 14px; font-size: 13px; }
    .btn-sm { padding: 4px 10px; font-size: 11.5px; }

    .login-box { padding: 28px 22px; }
}

@media (max-width: 480px) {
    div[style*="display:flex"][style*="flex-wrap:wrap"] > .card[style*="text-align:center"] {
        min-width: 100% !important;
    }
}
