:root {
    --vk: #0077ff;
    --vk-2: #00a2ff;
    --bg: #0a0d13;
    --bg-2: #0e121b;
    --surface: rgba(255, 255, 255, 0.045);
    --surface-2: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.09);
    --text: #e8edf5;
    --muted: rgba(232, 237, 245, 0.5);
    --green: #3fd07f;
    --red: #ff5c6c;
    --yellow: #ffc24b;
    --cyan: #2bd4ff;
    --purple: #9b7bff;
    --sidebar-w: 256px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background:
        radial-gradient(1200px 600px at 100% -10%, rgba(0, 119, 255, 0.12), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(155, 123, 255, 0.10), transparent 55%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 6px;
    backdrop-filter: blur(14px);
    z-index: 50;
}
.brand {
    display: flex; align-items: center; gap: 11px;
    padding: 6px 10px 18px;
}
.brand-logo {
    width: 42px; height: 42px; border-radius: 12px;
    background: linear-gradient(135deg, var(--vk), var(--vk-2));
    display: grid; place-items: center;
    font-weight: 800; font-size: 1.25rem; color: #fff;
    box-shadow: 0 6px 20px rgba(0, 119, 255, 0.4);
}
.brand-name { font-weight: 700; font-size: 1.05rem; line-height: 1.1; }
.brand-sub { font-size: 0.7rem; color: var(--muted); }

.nav-section-title {
    font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--muted); padding: 14px 12px 6px;
}
.nav-link-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 13px; border-radius: 11px;
    color: var(--muted); font-size: 0.92rem; font-weight: 500;
    cursor: pointer; transition: all 0.18s ease;
    border: 1px solid transparent;
}
.nav-link-item i { font-size: 1.15rem; width: 20px; text-align: center; }
.nav-link-item:hover { background: var(--surface); color: var(--text); }
.nav-link-item.active {
    background: linear-gradient(135deg, rgba(0,119,255,0.22), rgba(0,119,255,0.08));
    color: #fff; border-color: rgba(0,119,255,0.4);
    box-shadow: 0 4px 16px rgba(0,119,255,0.18);
}
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.sidebar-backdrop {
    display: none; position: fixed; inset: 0; z-index: 40;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(2px);
}

/* ── Main ── */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    padding: 14px 22px;
    background: rgba(10, 13, 19, 0.72);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; font-weight: 700; margin: 0; flex: 1 1 auto; }
.hamburger {
    display: none; border: none; background: var(--surface);
    color: var(--text); width: 40px; height: 40px; border-radius: 11px;
    font-size: 1.2rem; cursor: pointer;
}
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content { padding: 22px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ── Cards ── */
.card-vk {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px;
}
.section { display: none; animation: fadeIn 0.25s ease; }
.section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.section-head h2 { font-size: 1.25rem; margin: 0; font-weight: 700; }
.section-head .ico {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    background: rgba(0,119,255,0.15); color: var(--vk-2); font-size: 1.1rem;
}

/* stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px 14px; text-align: center;
}
.stat-card .num { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat-card .lbl { font-size: 0.72rem; color: var(--muted); margin-top: 6px; }

/* status badge */
.status-badge {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 15px; border-radius: 999px; font-weight: 600; font-size: 0.82rem;
    border: 1px solid var(--border);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; }
.status-idle { background: #6c757d; }
.status-running { background: var(--green); animation: pulse 1.5s infinite; }
.status-paused { background: var(--yellow); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* forms */
.form-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.form-control, .form-select {
    background: rgba(0,0,0,0.25); border: 1px solid var(--border);
    color: var(--text); border-radius: 11px; font-size: 0.9rem;
}
.form-control:focus, .form-select:focus {
    background: rgba(0,0,0,0.35); border-color: var(--vk);
    box-shadow: 0 0 0 3px rgba(0,119,255,0.18); color: var(--text);
}
.form-text { color: var(--muted); font-size: 0.74rem; }
textarea.form-control { resize: vertical; }

/* buttons */
.btn-vk {
    background: linear-gradient(135deg, var(--vk), var(--vk-2));
    border: none; color: #fff; font-weight: 600; border-radius: 11px;
    padding: 9px 16px; font-size: 0.88rem; transition: transform 0.12s, box-shadow 0.2s;
    box-shadow: 0 6px 18px rgba(0,119,255,0.3);
}
.btn-vk:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(0,119,255,0.42); color: #fff; }
.btn-vk:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-ghost {
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    border-radius: 11px; padding: 9px 16px; font-size: 0.88rem; transition: background 0.18s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger-soft { background: rgba(255,92,108,0.12); border: 1px solid rgba(255,92,108,0.35); color: var(--red); border-radius: 11px; }
.btn-danger-soft:hover { background: rgba(255,92,108,0.2); color: var(--red); }

/* tables */
.table-vk { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table-vk th {
    text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.table-vk td { padding: 11px 12px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.table-vk tbody tr:hover { background: var(--surface); }
.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--border); }

/* log */
.log-box {
    background: #070a0f; color: #c8d3e0; border: 1px solid var(--border);
    border-radius: 12px; padding: 16px; height: 62vh; overflow: auto;
    font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 0.78rem; line-height: 1.55;
    white-space: pre-wrap; word-break: break-all;
}
.log-line-error { color: #ff6b78; }
.log-line-info { color: #6fb6ff; }
.log-line-warn { color: #e7b54a; }
.log-line-success { color: #4fd98a; }

/* bottom nav */
.bottomnav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: rgba(10,13,19,0.92); backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(6, 1fr);
}
.bottomnav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--muted); font-size: 0.62rem; padding: 6px 2px; border-radius: 10px;
}
.bottomnav a i { font-size: 1.25rem; }
.bottomnav a.active { color: var(--vk-2); background: rgba(0,119,255,0.12); }

/* misc */
.pill { padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.pill-ok { background: rgba(63,208,127,0.16); color: var(--green); }
.pill-fail { background: rgba(255,92,108,0.16); color: var(--red); }
.pill-info { background: rgba(43,212,255,0.16); color: var(--cyan); }
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 0.85rem; }
.kv span:first-child { color: var(--muted); }
.switch-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ── Responsive ── */
@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
    .sidebar {
        position: fixed; left: 0; top: 0; transform: translateX(-100%);
        transition: transform 0.25s ease; box-shadow: 0 0 40px rgba(0,0,0,0.6);
    }
    .sidebar.open { transform: none; }
    .sidebar-backdrop.show { display: block; }
    .hamburger { display: inline-flex; align-items: center; justify-content: center; }
    .bottomnav { display: grid; }
    .content { padding: 16px 14px 92px; }
    .topbar { padding: 12px 14px; }
    .topbar h1 { font-size: 1.02rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
    .stat-card { padding: 12px 8px; }
    .stat-card .num { font-size: 1.25rem; }
    .card-vk { padding: 14px; }
    .section-head h2 { font-size: 1.1rem; }
    .table-vk { font-size: 0.74rem; }
    .hide-mobile { display: none !important; }
    .log-box { height: 50vh; font-size: 0.7rem; }
}
@media (max-width: 420px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Bottom nav: выдвижная панель ── */
.bottomnav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: rgba(10,13,19,0.94); backdrop-filter: blur(18px);
    border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(5, 1fr);
}
.bottomnav a, .bottomnav .bottom-more {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); font-size: 0.6rem; padding: 8px 2px; border-radius: 12px;
    background: none; border: none; cursor: pointer; min-height: 52px;
}
.bottomnav a i, .bottomnav .bottom-more i { font-size: 1.25rem; }
.bottomnav a.active { color: var(--vk-2); background: rgba(0,119,255,0.12); }
.bottomnav .bottom-more.active i { transform: rotate(180deg); transition: transform 0.2s; }

.sheet-backdrop {
    display: none; position: fixed; inset: 0; z-index: 70;
    background: rgba(0,0,0,0.55); backdrop-filter: blur(2px);
}
.sheet-backdrop.show { display: block; }

.bottom-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    background: linear-gradient(180deg, rgba(20,25,36,0.98), rgba(10,13,19,0.99));
    border-top-left-radius: 22px; border-top-right-radius: 22px;
    border-top: 1px solid var(--border);
    padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
    transform: translateY(110%); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 -16px 50px rgba(0,0,0,0.5);
    max-height: 72vh; overflow-y: auto;
}
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle { width: 42px; height: 4px; border-radius: 4px; background: rgba(255,255,255,0.18); margin: 0 auto 10px; }
.sheet-title { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; padding-left: 4px; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sheet-grid a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 16px 6px; color: var(--text); font-size: 0.78rem; cursor: pointer; min-height: 78px;
    transition: background 0.15s, border-color 0.15s;
}
.sheet-grid a i { font-size: 1.5rem; color: var(--vk-2); }
.sheet-grid a:active { background: var(--surface-2); }

/* ── Глобальная мобильная оптимизация ── */
@media (max-width: 860px) {
    .bottomnav { display: grid; }
    .content { padding: 14px 12px 96px; }
    .topbar { padding: 10px 12px; }
    .topbar h1 { font-size: 1rem; }
    .hamburger { width: 42px; height: 42px; }

    /* Крупные тач-зоны */
    .btn-vk, .btn-ghost, .btn-danger-soft, .form-control, .form-select,
    .input-group .btn, .input-group .form-control {
        min-height: 46px; font-size: 0.95rem;
    }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
    .stat-card { padding: 13px 8px; }
    .stat-card .num { font-size: 1.3rem; }
    .stat-card .lbl { font-size: 0.66rem; }

    .card-vk { padding: 14px 12px; border-radius: 14px; }
    .section-head h2 { font-size: 1.05rem; }
    .section-head .ico { width: 34px; height: 34px; font-size: 1rem; }

    /* Кнопки действий на всю ширину */
    .d-flex.gap-2.flex-wrap .btn-vk,
    .overview-actions .btn-vk,
    form[style*="display:inline"] .btn-vk,
    form[style*="display:inline"] .btn-ghost,
    form[style*="display:inline"] .btn-danger-soft { width: 100%; }
    .section > .card-vk > .d-flex.gap-2 { flex-direction: column; }
    .section > .card-vk > .d-flex.gap-2 > form { width: 100%; }

    /* Формы в одну колонку */
    .row.g-3 .col-lg-8, .row.g-3 .col-lg-4 { width: 100%; flex: 0 0 100%; }
    .row.g-2 > .col-md-6, .row.g-2 > .col-md-4, .row.g-2 > .col-6, .row.g-2 > .col-4 { flex: 0 0 100%; max-width: 100%; }

    .table-vk { font-size: 0.76rem; }
    .table-wrap { border-radius: 12px; }
    .hide-mobile { display: none !important; }
    .log-box { height: 46vh; font-size: 0.7rem; }

    .kv { padding: 11px 0; font-size: 0.85rem; }
    .nav-link-item { padding: 13px 13px; font-size: 0.95rem; }

    /* Кнопки действий на всю ширину */
    .vk-actions { flex-direction: column; width: 100%; }
    .vk-actions > form { width: 100%; }
    .vk-actions .btn-vk, .vk-actions .btn-ghost, .vk-actions .btn-danger-soft { width: 100%; }
    .switch-row { flex-direction: column; align-items: stretch !important; }
    .switch-row .btn-vk { width: 100%; }
}

@media (max-width: 420px) {
    .sheet-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .sheet-grid a { min-height: 70px; padding: 12px 4px; font-size: 0.72rem; }
    .bottomnav a span, .bottomnav .bottom-more span { font-size: 0.55rem; }
    .stat-grid { gap: 7px; }
}

/* Лёгкий режим для слабых устройств */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
