:root {
    --bg: #0f172a;
    --card: #1e293b;
    --card-border: rgba(255, 255, 255, 0.08);
    --text: #f8fafc;
    --muted: #94a3b8;
    --primary: #6366f1;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text);
    padding: calc(14px + env(safe-area-inset-top, 0px)) 16px calc(32px + env(safe-area-inset-bottom, 0px)) 16px;
    min-height: 100vh;
}

/* ================= Тосты ================= */
.toast-container {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text);
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

/* ================= Шапка ================= */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.app-title {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.15;
}
.app-subtitle {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    margin-top: 3px;
}
.btn-add {
    padding: 10px 16px;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s;
}
.btn-add:active { transform: scale(0.95); }

/* ================= 3 Вкладки ================= */
.top-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: rgba(0, 0, 0, 0.28);
    padding: 4px;
    border-radius: 14px;
    margin-bottom: 14px;
    border: 1px solid var(--card-border);
}
.top-tab {
    padding: 9px 6px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.top-tab.active {
    background: var(--card);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.tab-count {
    font-size: 11px;
    opacity: 0.7;
    margin-left: 2px;
}

/* ================= Фильтры ================= */
.filter-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-pill {
    padding: 6px 12px;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.filter-pill.active {
    background: rgba(99, 102, 241, 0.2);
    color: #e0e7ff;
    border-color: rgba(99, 102, 241, 0.5);
}

/* ================= Список устройств (Чистый, без кнопки QR) ================= */
.devices-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.device-row {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 13px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}
.device-row:active {
    transform: scale(0.99);
}
.device-row.online {
    border-color: rgba(16, 185, 129, 0.28);
}
.dev-left {
    min-width: 0;
    flex: 1;
}
.dev-name-line {
    display: flex;
    align-items: center;
    gap: 7px;
}
.dev-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dev-meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 3px;
}

.dev-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Переключатель страны в 1 клик */
.route-switch {
    display: inline-flex;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 2px;
}
.route-seg {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}
.route-seg.active-by {
    background: rgba(148, 163, 184, 0.22);
    color: #fff;
}
.route-seg.active-usa {
    background: rgba(59, 130, 246, 0.35);
    color: #93c5fd;
}

.direct-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 9px;
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(56, 189, 248, 0.32);
    color: #7dd3fc;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.dot.on {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}
.dot.off {
    background: #475569;
}

/* ================= Топ устройств на вкладке Графики ================= */
.top-dev-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
}
.top-dev-item:last-child { border-bottom: none; padding-bottom: 0; }
.top-dev-head {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 5px;
}
.top-dev-name { font-weight: 600; color: var(--text); }
.top-dev-val { color: #a5b4fc; font-weight: 600; }
.top-dev-bar-bg {
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}
.top-dev-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #38bdf8);
    border-radius: 3px;
}

/* ================= Вкладка Серверы ================= */
.server-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
}
.srv-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 14px;
}
.srv-title {
    font-size: 15px;
    font-weight: 700;
}
.srv-ip {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}
.status-pill {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 8px;
}
.status-pill.ok {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}
.status-pill.usa {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
}

.metrics-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.metric-item {
    background: rgba(0, 0, 0, 0.22);
    border-radius: 12px;
    padding: 10px;
}
.m-label {
    font-size: 11px;
    color: var(--muted);
}
.m-val {
    font-size: 16px;
    font-weight: 700;
    margin: 3px 0 6px 0;
}
.mini-bar {
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}
.mini-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: var(--success);
    transition: width 0.4s ease;
}
.mini-fill.yellow { background: var(--warning); }
.mini-fill.red { background: var(--danger); }

.simple-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.btn-secondary {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}
.btn-secondary.danger-outline {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.25);
}

/* ================= Нижние шторки (Bottom Sheets) ================= */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 22, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.22s ease;
}
.sheet-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.bottom-sheet {
    background: #162033;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 24px 24px 0 0;
    padding: 12px 18px calc(22px + env(safe-area-inset-bottom, 0px)) 18px;
    width: 100%;
    max-width: 460px;
    max-height: 92vh;
    overflow-y: auto;
    transform: translateY(0);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.sheet-overlay.hidden .bottom-sheet {
    transform: translateY(100%);
}
.sheet-handle {
    width: 38px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 0 auto 12px auto;
}
.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.sheet-title {
    font-size: 18px;
    font-weight: 700;
}
.sheet-subtitle {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}
.sheet-close-x {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
}
.rename-inline-btn {
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 8px;
    cursor: pointer;
}

.sheet-route-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 10px;
}
.sheet-route-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

/* Внутренние вкладки в шторке: QR / График */
.sheet-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: rgba(0, 0, 0, 0.28);
    padding: 3px;
    border-radius: 11px;
    margin-bottom: 12px;
    border: 1px solid var(--card-border);
}
.sheet-tab {
    padding: 8px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.sheet-tab.active {
    background: var(--card);
    color: var(--text);
}

.device-chart-box {
    height: 195px;
    width: 100%;
    margin: 8px 0;
}

.qr-card-wrap {
    display: flex;
    justify-content: center;
    margin: 8px 0;
}
.qr-card-wrap img {
    max-width: 195px;
    width: 100%;
    border-radius: 16px;
    padding: 12px;
    background: #fff;
}

.amnezia-hint {
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    line-height: 1.45;
    margin: 8px 0 14px 0;
}

.sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sheet-btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.sheet-btn {
    padding: 13px;
    border-radius: 12px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.sheet-btn.primary-tg {
    background: #0284c7;
    color: #fff;
}
.sheet-btn.secondary {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
    border: 1px solid var(--card-border);
}

.sheet-footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--card-border);
}
.text-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
}
.text-btn.danger {
    color: #f87171;
}

/* Форма создания */
.field-label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 600;
}
.input {
    width: 100%;
    padding: 13px 14px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(0, 0, 0, 0.28);
    color: var(--text);
    font-size: 15px;
    margin-bottom: 14px;
    outline: none;
}
.input:focus { border-color: var(--primary); }

.country-choice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}
.country-choice-grid.three-cols {
    grid-template-columns: repeat(3, 1fr);
}
.country-card {
    background: rgba(0, 0, 0, 0.25);
    border: 2px solid var(--card-border);
    border-radius: 14px;
    padding: 10px 6px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-align: center;
}
.country-card.active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.16);
}
.c-flag { font-size: 20px; }
.c-name { font-size: 12px; font-weight: 700; }
.c-sub { font-size: 10px; color: var(--muted); }

.small-note {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 14px;
    line-height: 1.35;
}
.btn-primary {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.section { display: none; }
.section.active { display: block; }
.refresh-time { text-align: center; font-size: 11px; color: var(--muted); margin-top: 10px; opacity: 0.6; }

.skeleton-row {
    height: 64px;
    border-radius: 16px;
    background: rgba(30, 41, 59, 0.6);
}

/* ================= Новые стили v7: Выгрузка конфигураций ================= */
.sheet-btn.copy-main {
    background: rgba(99, 102, 241, 0.22);
    color: #e0e7ff;
    border: 1px solid rgba(99, 102, 241, 0.45);
}

.conf-box-wrap {
    background: rgba(0, 0, 0, 0.32);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 10px 12px;
    margin: 10px 0;
    text-align: left;
}
.conf-box-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 6px;
}
.conf-box-head code {
    color: #93c5fd;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}
.conf-mini-copy {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
    color: var(--text);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
}
.conf-code-box {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: #cbd5e1;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 130px;
    overflow-y: auto;
    cursor: pointer;
    user-select: all;
}

.bulk-export-card {
    background: rgba(30, 41, 59, 0.65);
    border: 1px dashed rgba(148, 163, 184, 0.25);
    border-radius: 16px;
    padding: 14px;
    margin-top: 14px;
}
.bulk-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}
.bulk-sub {
    font-size: 12px;
    color: var(--muted);
    margin: 4px 0 10px 0;
    line-height: 1.4;
}
.bulk-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.btn-bulk {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.btn-bulk.primary {
    background: rgba(2, 132, 199, 0.25);
    border-color: rgba(56, 189, 248, 0.4);
    color: #bae6fd;
}

.country-choice-grid.three-cols.four-cols {
    grid-template-columns: repeat(2, 1fr);
}
