:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-main: #f9fafb;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --sidebar: #111827;
    --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', -apple-system, sans-serif; }

body { background-color: var(--bg-main); color: var(--text-main); display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: 260px; background: var(--sidebar); color: white; padding: 24px 16px; display: flex; flex-direction: column; position: fixed; height: 100vh; z-index: 100; }
.sidebar-logo { font-size: 1.25rem; font-weight: 800; margin-bottom: 32px; display: flex; align-items: center; gap: 12px; padding: 0 12px; }
.nav-menu { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: #9ca3af; text-decoration: none; border-radius: 8px; font-weight: 500; transition: 0.2s; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.1); color: white; }
.logout-btn { margin-top: auto; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 16px; color: #f87171 !important; cursor: pointer; border: none; background: none; width: 100%; text-align: left; }

/* Main Content */
.main-content { margin-left: 260px; flex: 1; padding: 40px; max-width: 1400px; width: 100%; }
.page-header { margin-bottom: 32px; }
.page-header h1 { font-size: 1.8rem; font-weight: 700; color: var(--text-main); }

/* Layout Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 32px; }

/* Cards */
.card { background: var(--bg-card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.stat-label { color: var(--text-muted); font-size: 0.875rem; font-weight: 500; margin-bottom: 8px; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 20px; border-radius: 8px; font-weight: 600; text-decoration: none; transition: 0.2s; border: none; cursor: pointer; font-size: 0.95rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Tables */
.table-container { background: white; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { background: #f9fafb; padding: 12px 16px; font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #f9fafb; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 6px; color: var(--text-main); }
.form-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; transition: 0.2s; }
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Funnel */
.funnel-item { display: grid; grid-template-columns: 160px 1fr 100px 80px; align-items: center; gap: 16px; margin-bottom: 12px; }
.bar-bg { height: 8px; background: #f3f4f6; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.badge-conv { font-size: 0.75rem; font-weight: 700; color: var(--primary); background: var(--primary-soft); padding: 2px 8px; border-radius: 4px; }

/* Utilities */
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }

/* ========== Mobile adaptive (desktop-first, breakpoint 768px) ========== */
@media (max-width: 768px) {
    body { flex-direction: column; }

    /* Sidebar: скрыт по умолчанию, выезжает по overlay при .sidebar-open */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.25s ease, box-shadow 0.25s ease;
        z-index: 1000;
        overflow-y: auto;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 8px 0 24px rgba(0,0,0,0.25);
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.25s ease;
    }
    body.sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
    }
    body.sidebar-open { overflow: hidden; }
    .sidebar-overlay:focus,
    .sidebar-overlay[aria-hidden="false"] {
        cursor: pointer;
    }

    /* Кнопка открытия меню — видна только на мобильных */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: max(12px, env(safe-area-inset-top));
        left: max(12px, env(safe-area-inset-left));
        width: 44px;
        height: 44px;
        border-radius: 10px;
        background: var(--sidebar);
        color: white;
        border: none;
        cursor: pointer;
        z-index: 998;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        transition: background 0.2s;
    }
    .mobile-menu-toggle:hover { background: #1f2937; }
    .mobile-menu-toggle svg { width: 24px; height: 24px; }

    /* Main content: полная ширина, отступ сверху под кнопку меню */
    .main-content {
        margin-left: 0;
        padding: 60px 16px 24px;
        padding-top: calc(56px + env(safe-area-inset-top, 0px));
        width: 100%;
        max-width: 100%;
    }

    .page-header h1 { font-size: 1.4rem; }
    .stats-grid { gap: 12px; margin-bottom: 20px; }
    .card { padding: 16px; }
    .stat-value { font-size: 1.25rem; }

    /* Таблицы: горизонтальный скролл без поломки layout */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
    .table-container .data-table { min-width: 480px; }
    .data-table th, .data-table td { padding: 10px 12px; font-size: 0.85rem; }
    .data-table th { font-size: 0.7rem; }

    /* Формы: вертикальный стек, полная ширина */
    .form-group { margin-bottom: 12px; }
    form[style*="flex"] { flex-direction: column; align-items: stretch !important; }
    form .form-group { min-width: 100% !important; flex: none !important; }
    form .btn { width: 100%; margin-top: 4px; }

    /* Funnel (для страниц с воронкой в style.css) */
    .funnel-item {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px 0;
        border-bottom: 1px solid var(--border);
    }
    .funnel-item .bar-bg { order: 2; }
    .funnel-item .bar-fill { min-width: 4px; }
}

/* Кнопка меню скрыта на десктопе */
@media (min-width: 769px) {
    .mobile-menu-toggle,
    .sidebar-overlay { display: none !important; }
}