:root {
    --background: #0b1020;
    --sidebar: #11182b;
    --card: #151d32;
    --card-hover: #1a2440;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #263149;
    --radius: 14px;
    --sidebar-open: 250px;
    --sidebar-closed: 72px;
    --topbar-height: 64px;
}

/* ========================================
   RESET
======================================== */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text);
}

/* ========================================
   APP
======================================== */
.app { min-height: 100vh; }

/* ========================================
   SIDEBAR — DESKTOP
======================================== */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    width: var(--sidebar-closed);
    height: 100vh;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    overflow: hidden;
    transition: width 0.25s ease, padding 0.25s ease;
}
.sidebar.open {
    width: var(--sidebar-open);
    padding: 20px;
}

/* ========================================
   SIDEBAR CONTENT
======================================== */
.sidebar > a,
.logo,
.navigation,
.navigation a,
.sidebar-bottom,
.bot-status {
    width: 100%;
}

.sidebar > a {
    display: block;
    color: inherit;
    text-decoration: none;
}

.logo {
    height: 38px;
    display: flex;
    align-items: center;
    margin-bottom: 35px;
    font-size: 19px;
    font-weight: 700;
    white-space: nowrap;
}

/* ========================================
   NAVIGATION
======================================== */
.navigation {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.navigation a {
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 13px;
    gap: 12px;
    border-radius: 10px;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    transition: background 0.2s ease, color 0.2s ease;
}
.navigation a:hover { background: var(--card); color: var(--text); }
.navigation a.active {
    color: white;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
}

/* ========================================
   LUCIDE ICONS
======================================== */
.navigation a svg,
.navigation a i {
    width: 20px; height: 20px;
    min-width: 20px;
    flex-shrink: 0;
}

/* ========================================
   BOTTOM
======================================== */
.sidebar-bottom {
    margin-top: auto;
}
.bot-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    margin-bottom: 15px;
    background: var(--card);
    border-radius: 10px;
    overflow: hidden;
}
.status-dot {
    width: 8px; height: 8px;
    min-width: 8px;
    border-radius: 50%;
    background: #22c55e;
}
.bot-status > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.bot-status strong,
.bot-status small { white-space: nowrap; }

/* ========================================
   USER
======================================== */
.user {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}
.user > div:not(.avatar) {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.user strong,
.user small { white-space: nowrap; }

/* ========================================
   AVATAR
======================================== */
.avatar {
    width: 36px; height: 36px;
    min-width: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #9333ea);
    color: white;
    font-weight: 600;
}

/* ========================================
   TG AUTH BUTTON (неавторизованный)
======================================== */
.tg-auth-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    background: #229ED9;
    color: white;
    font-weight: 600;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    transition: background 0.2s ease, transform 0.2s ease;
}
.tg-auth-button:hover {
    background: #1e96d0;
}

/* Стиль «icon» – маленький кружок без текста */
.tg-auth-button[data-style="icon"] {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    overflow: hidden;
    background: #229ED9;
    position: relative;
    flex-shrink: 0;
    font-size: 0;
    line-height: 0;
}

/* Скрываем весь контент внутри кнопки (текст, лишние элементы) */
.tg-auth-button[data-style="icon"] * {
    display: none !important;
}

/* Показываем только iframe виджета Telegram */
.tg-auth-button[data-style="icon"] iframe {
    display: block !important;
    width: 36px !important;
    height: 36px !important;
    border: none;
    border-radius: 50%;
}

/* Если скрипт вставляет iframe не в кнопку, а рядом, скрываем его тоже,
   но тогда лучше вообще убрать кастомную кнопку и оставить только iframe.
   В нашем случае iframe будет внутри кнопки, поэтому всё хорошо. */

/* ========================================
   MAIN — DESKTOP
======================================== */
.main {
    width: calc(100% - var(--sidebar-closed));
    min-height: 100vh;
    margin-left: var(--sidebar-closed);
    transition: margin-left 0.25s ease, width 0.25s ease;
}
.sidebar.open ~ .main {
    width: calc(100% - var(--sidebar-open));
    margin-left: var(--sidebar-open);
}

/* ========================================
   TOPBAR
======================================== */
.topbar {
    position: relative;
    z-index: 1101;
    width: 100%;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    border-bottom: 1px solid var(--border);
}

/* ========================================
   BUTTONS
======================================== */
.menu-button,
.icon-button,
.sidebar-toggle {
    width: 40px; height: 40px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s ease;
}
.menu-button:hover,
.icon-button:hover,
.sidebar-toggle:hover { background: var(--card); }
.menu-button svg,
.icon-button svg,
.sidebar-toggle svg { width: 20px; height: 20px; }

/* Кнопка внутри sidebar */
.sidebar-toggle {
    display: none;
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1002;
    transition: right 0.25s ease, background 0.2s ease;
}
.sidebar:not(.open) .sidebar-toggle {
    right: 16px;
}

/* ========================================
   TOPBAR RIGHT
======================================== */
.topbar-right {
    display: flex;
    align-items: center;
    gap: 18px;
}

/* ========================================
   CONTENT
======================================== */
.content {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 35px;
}

/* ========================================
   PAGE HEADER
======================================== */
.page-header { margin-bottom: 30px; }
.page-header h1 { margin: 0 0 7px; font-size: 28px; }
.page-header p { margin: 0; color: var(--text-muted); }

/* ========================================
   STATS
======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    margin-bottom: 20px;
}
.stat-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 22px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.stat-card > div:last-child {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-card strong { font-size: 25px; }

/* ========================================
   ICONS
======================================== */
.stat-icon,
.action-icon {
    width: 44px; height: 44px;
    min-width: 44px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: #222b55;
}
.stat-icon svg,
.action-icon svg { width: 20px; height: 20px; }

/* ========================================
   DASHBOARD
======================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ========================================
   CARD
======================================== */
.card {
    padding: 22px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.card-header {
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 17px; }

/* ========================================
   ACTION
======================================== */
.action {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 5px;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
}
.action div:nth-child(2) {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.arrow { transition: transform 0.2s ease; }
.action:hover .arrow { transform: translateX(4px); }

/* ========================================
   EVENTS
======================================== */
.event {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
}
.event div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.event-icon {
    width: 36px; height: 36px;
    min-width: 36px;
    display: grid;
    place-items: center;
    background: #222b55;
    border-radius: 9px;
}

/* ========================================
   SETTINGS
======================================== */
.settings {
    max-width: 900px;
}
.settings-section {
    margin-bottom: 20px;
    padding: 25px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.section-title { margin-bottom: 25px; }
.section-title h2 { margin: 0 0 5px; font-size: 18px; }
.section-title p { margin: 0; color: var(--text-muted); }

/* ========================================
   FORM
======================================== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
.form-field { display: flex; flex-direction: column; gap: 8px; }
.form-field span { color: var(--text); font-size: 14px; }
.form-field input,
.form-field select {
    width: 100%;
    padding: 12px 13px;
    color: var(--text);
    background: #0d1427;
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-field input:focus,
.form-field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* ========================================
   TOGGLE
======================================== */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 17px 0;
    border-top: 1px solid var(--border);
}
.toggle-row div { display: flex; flex-direction: column; gap: 4px; }
.toggle-row input {
    width: 42px; height: 22px;
    flex-shrink: 0;
    accent-color: var(--primary);
}

/* ========================================
   BUTTON
======================================== */
.settings-actions { display: flex; justify-content: flex-end; }
.button-primary {
    padding: 12px 20px;
    border: 0;
    border-radius: 9px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.button-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.25);
}

/* ========================================
   TABLET + MOBILE
======================================== */
@media (max-width: 900px) {
    .sidebar {
        width: var(--sidebar-open);
        height: 100vh;
        padding: 20px;
        transform: translateX(-100%);
        box-shadow: none;
        transition: transform 0.25s ease;
        z-index: 1000;
    }
    .sidebar.open {
        width: var(--sidebar-open);
        padding: 20px;
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
        z-index: 1200;
    }
    .main,
    .sidebar.open ~ .main {
        width: 100%;
        margin-left: 0;
    }
    .content { padding: 25px; }
    .stats-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }

    .sidebar-toggle { display: none; }
    .sidebar.open .sidebar-toggle { display: grid; }
    .sidebar.open ~ .main .menu-button {
        opacity: 0;
        pointer-events: none;
    }
    .menu-button { display: grid; }
}

/* ========================================
   MOBILE
======================================== */
@media (max-width: 650px) {
    .topbar { padding: 0 20px; }
    .content { padding: 20px; }
    .form-grid { grid-template-columns: 1fr; }
    .settings-section { padding: 20px; }
    .page-header h1 { font-size: 24px; }
}

/* ========================================
   SMALL MOBILE
======================================== */
@media (max-width: 400px) {
    .topbar { padding: 0 15px; }
    .content { padding: 15px; }
    .settings-section { padding: 16px; }
}

/* ========================================
   COLLAPSED SIDEBAR — только десктоп
======================================== */
@media (min-width: 901px) {
    .sidebar:not(.open) .navigation a {
        font-size: 0;
        gap: 0;
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }
    .sidebar:not(.open) .logo span {
        opacity: 0;
        visibility: hidden;
    }
    .sidebar:not(.open) .bot-status {
        display: none;
    }
    .sidebar:not(.open) .user {
        justify-content: center;
        gap: 0;
    }
    .sidebar:not(.open) .user > div:not(.avatar):not(.tg-auth-button) {
        width: 0;
        opacity: 0;
        visibility: hidden;
        overflow: hidden;
    }
    /* Для кнопки Telegram в свёрнутом состоянии дополнительно центрируем */
    .sidebar:not(.open) .user .tg-auth-button {
        width: 36px;
        height: 36px;
        padding: 0;
        font-size: 0;
        line-height: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .sidebar:not(.open) .sidebar-toggle {
        right: 16px;
    }
    .sidebar-toggle {
        display: grid;
    }
    .menu-button {
        display: none;
    }
}

/* ========================================
   OVERLAY (для мобильных)
======================================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}
@media (max-width: 900px) {
    .sidebar-overlay.active {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }
}

/* =========================================================
   НАСТРОЙКИ – КОНТЕЙНЕР
   ========================================================= */
.settings {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1000px;
}
.config-root {
    width: 100%;
    background: var(--sidebar, #1e2230);
    border: 1px solid var(--border, #2e3440);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.config-tree { display: flex; flex-direction: column; }
.config-node {
    position: relative;
    border-bottom: 1px solid var(--border, #2e3440);
}
.config-node:last-child { border-bottom: none; }
.config-summary {
    list-style: none;
    display: flex;
    align-items: center;
    min-height: 54px;
    padding: 0 18px;
    cursor: pointer;
    user-select: none;
    transition: background 0.18s ease;
}
.config-summary::-webkit-details-marker,
.config-summary::marker { display: none; }
.config-summary:hover { background: rgba(255, 255, 255, 0.04); }
.config-summary-left { display: flex; align-items: center; gap: 10px; }
.chevron {
    width: 20px; height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted, #8a93a6);
    transition: transform 0.2s ease, color 0.2s ease;
}
.chevron svg { width: 17px; height: 17px; }
.config-node[open] > .config-summary .chevron {
    transform: rotate(90deg);
    color: var(--primary, #6346ff);
}
.config-key {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #e5e9f0);
}
.config-children {
    position: relative;
    margin-left: 28px;
    padding: 4px 18px 12px 20px;
}
.config-children::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 18px;
    width: 1px;
    background: var(--border, #2e3440);
}
.config-property {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    padding: 7px 0;
    position: relative;
    transition: background 0.15s ease;
}
.config-property:hover { background: rgba(255, 255, 255, 0.02); }
.config-property::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 50%;
    width: 12px;
    height: 1px;
    background: var(--border, #2e3440);
}
.property-name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    color: var(--text, #e5e9f0);
}
.property-value { display: flex; align-items: center; flex-shrink: 0; }
.config-input {
    width: 280px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border, #2e3440);
    border-radius: 8px;
    outline: none;
    background: var(--background, #0f1117);
    color: var(--text, #e5e9f0);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.config-input:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--primary, #6346ff);
}
.config-input:focus {
    border-color: var(--primary, #6346ff);
    box-shadow: 0 0 0 3px rgba(99, 70, 255, 0.15);
}
.switch {
    position: relative;
    width: 42px; height: 24px;
    display: block;
    flex-shrink: 0;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
    position: absolute;
    inset: 0;
    border-radius: 20px;
    cursor: pointer;
    background: #2a3040;
    transition: background 0.2s;
}
.switch-slider::before {
    content: "";
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; top: 3px;
    border-radius: 50%;
    background: white;
    transition: transform 0.2s;
}
.switch input:checked + .switch-slider { background: var(--primary, #6346ff); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.settings-actions { display: flex; justify-content: flex-end; }
.settings-actions .button-primary {
    min-height: 40px;
    padding: 0 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: var(--primary, #6346ff);
    box-shadow: 0 2px 6px rgba(99, 70, 255, 0.3);
    transition: transform 0.15s, filter 0.15s, box-shadow 0.15s;
}
.settings-actions .button-primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 10px rgba(99, 70, 255, 0.4);
}
.settings-actions .button-primary:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(99, 70, 255, 0.3);
}
@media (max-width: 700px) {
    .config-summary { padding: 0 14px; }
    .config-children { margin-left: 18px; padding-left: 16px; padding-right: 12px; }
    .config-property { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 0; }
    .property-value { width: 100%; }
    .config-input { width: 100%; }
}