/* ═══════════════════════════════════════════════
   VPN Dashboard — Premium Dark Theme v2
   ═══════════════════════════════════════════════ */

:root {
    --bg-primary: #0a0e14;
    --bg-secondary: #111820;
    --bg-card: rgba(17, 24, 32, 0.75);
    --bg-card-hover: rgba(25, 34, 44, 0.85);
    --bg-elevated: rgba(30, 40, 52, 0.9);
    --border: rgba(56, 68, 82, 0.4);
    --border-hover: rgba(88, 166, 255, 0.25);
    --text-1: #ecf0f5;
    --text-2: #8b949e;
    --text-3: #484f58;
    --blue: #58a6ff;
    --purple: #bc8cff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #e3b341;
    --orange: #f0883e;
    --cyan: #56d4dd;
    --sweden-blue: #006aa7;
    --sweden-yellow: #fecc00;
    --glow-blue: rgba(88, 166, 255, 0.12);
    --glow-green: rgba(63, 185, 80, 0.12);
    --glow-red: rgba(248, 81, 73, 0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

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

html {
    background: var(--bg-primary);
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-1);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* Ambient background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 20% 10%, rgba(0, 106, 167, 0.07) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 90%, rgba(188, 140, 255, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse 40% 30% at 50% 50%, rgba(63, 185, 80, 0.03) 0%, transparent 40%);
    z-index: -1;
    animation: ambientShift 25s ease-in-out infinite alternate;
}

@keyframes ambientShift {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 480px;
    margin: 0 auto;
}

/* ─── Header ──────────────────────────────────── */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px 10px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(10, 14, 20, 0.88);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

header h1 {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.4px;
    background: linear-gradient(135deg, var(--text-1), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btn {
    color: var(--text-2);
    transition: all 0.2s var(--ease);
}

.header-btn:hover { color: var(--blue); }
.header-btn.spinning svg { animation: spin 0.6s linear infinite; }

/* Refresh ring */
.refresh-indicator {
    position: relative;
    width: 24px;
    height: 24px;
}

.refresh-ring {
    width: 24px;
    height: 24px;
    transform: rotate(-90deg);
    color: var(--blue);
}

#refresh-arc {
    transition: stroke-dashoffset 1s linear;
}

#refresh-timer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 700;
    color: var(--text-3);
    font-family: var(--mono);
}

/* ─── Badges ──────────────────────────────────── */

.badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-weight: 600;
    font-family: var(--mono);
}

.badge-user {
    background: linear-gradient(135deg, rgba(88,166,255,0.1), rgba(188,140,255,0.1));
    border-color: rgba(88,166,255,0.2);
    color: var(--blue);
}

.badge-sweden {
    background: rgba(0,106,167,0.12);
    border-color: rgba(0,106,167,0.25);
    color: var(--cyan);
}

/* ─── Main Content ────────────────────────────── */

main {
    flex: 1;
    padding: 10px 14px 100px;
    overflow-y: auto;
}

.tab-panel {
    display: none;
    animation: panelIn 0.3s var(--ease);
}

.tab-panel.active { display: block; }

@keyframes panelIn {
    from { opacity: 0; transform: translateY(6px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Cards ───────────────────────────────────── */

.cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: all 0.25s var(--ease);
}

.glass-card {
    background: rgba(17, 24, 32, 0.5);
    border-color: rgba(56, 68, 82, 0.3);
}

.card.full-width { margin-bottom: 10px; }

.card:active {
    transform: scale(0.985);
}

.status-card {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    padding: 12px 14px;
}

.status-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    opacity: 0;
    transition: opacity 0.4s var(--ease);
    pointer-events: none;
}

.status-card.ok::before {
    background: linear-gradient(135deg, var(--glow-green), transparent 70%);
    opacity: 1;
}

.status-card.fail::before {
    background: linear-gradient(135deg, var(--glow-red), transparent 70%);
    opacity: 1;
}

.card-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    flex-shrink: 0;
    transition: all 0.4s var(--ease);
    position: relative;
}

.card-dot.green {
    background: var(--green);
    box-shadow: 0 0 6px var(--green), 0 0 12px rgba(63,185,80,0.3);
}

.card-dot.red {
    background: var(--red);
    box-shadow: 0 0 6px var(--red);
    animation: pulse-red 2s ease-in-out infinite;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.card-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-left: auto;
    opacity: 0.7;
}

.card-body { flex: 1; min-width: 0; }

.card-label {
    font-size: 9px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    font-family: var(--mono);
}

.card-value {
    font-size: 14px;
    font-weight: 600;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-header h2 {
    font-size: 14px;
    font-weight: 700;
}

/* ─── Ping ────────────────────────────────────── */

.ping-list { display: flex; flex-direction: column; gap: 4px; }

.ping-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
    font-size: 13px;
    transition: background 0.2s;
}

.ping-row:hover { background: rgba(255, 255, 255, 0.04); }

.ping-row .label {
    color: var(--text-2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ping-row .value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: var(--mono);
    font-size: 12px;
}

.ping-row .value.ok { color: var(--green); }
.ping-row .value.warn { color: var(--yellow); }
.ping-row .value.fail { color: var(--red); }

.quality-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.quality-dot.good { background: var(--green); box-shadow: 0 0 4px var(--green); }
.quality-dot.fair { background: var(--yellow); box-shadow: 0 0 4px var(--yellow); }
.quality-dot.poor { background: var(--red); box-shadow: 0 0 4px var(--red); }

/* Skeleton */
.ping-row.skeleton, .skeleton-item {
    height: 38px;
    background: linear-gradient(90deg, rgba(255,255,255,0.02) 25%, rgba(255,255,255,0.05) 50%, rgba(255,255,255,0.02) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Info Grid ───────────────────────────────── */

.info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.info-cell {
    text-align: center;
    padding: 10px 4px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
}

.info-num {
    display: block;
    font-size: 18px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(135deg, var(--text-1), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.info-label {
    font-size: 9px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    margin-top: 2px;
    display: block;
}

/* ─── Action Bar ──────────────────────────────── */

.action-bar {
    display: flex;
    gap: 8px;
    margin-top: 2px;
}

.action-bar .btn { flex: 1; }

/* ─── Route Items ─────────────────────────────── */

.list-container {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.route-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
    gap: 10px;
    transition: all 0.2s var(--ease);
    position: relative;
    overflow: hidden;
}

.route-item:hover { background: rgba(255, 255, 255, 0.05); }

.route-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 15%;
    bottom: 15%;
    width: 3px;
    border-radius: 3px;
    transition: background 0.2s;
}

.route-item.ru::before { background: var(--red); }
.route-item.sw::before { background: var(--blue); }
.route-item.cf::before { background: var(--yellow); }

.route-domain {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--mono);
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-tag {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 700;
    text-transform: uppercase;
    font-family: var(--mono);
    letter-spacing: 0.5px;
}

.route-tag.ru { background: rgba(248,81,73,0.12); color: var(--red); border: 1px solid rgba(248,81,73,0.2); }
.route-tag.sw { background: rgba(88,166,255,0.12); color: var(--blue); border: 1px solid rgba(88,166,255,0.2); }
.route-tag.cf { background: rgba(227,179,65,0.12); color: var(--yellow); border: 1px solid rgba(227,179,65,0.2); }

.route-delete {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    font-size: 14px;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.route-delete:hover { color: var(--red); background: var(--glow-red); }

/* ─── User Items ──────────────────────────────── */

.user-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
    gap: 10px;
    transition: all 0.2s var(--ease);
}

.user-item:hover { background: rgba(255, 255, 255, 0.05); }

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    flex-shrink: 0;
    color: #fff;
}

.user-info { flex: 1; min-width: 0; }

.user-name {
    font-size: 13px;
    font-weight: 600;
}

.user-traffic {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.traffic-bar {
    flex: 1;
    height: 3px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.traffic-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--blue), var(--purple));
    transition: width 0.6s var(--ease);
}

.traffic-text {
    font-size: 10px;
    color: var(--text-3);
    font-family: var(--mono);
    white-space: nowrap;
}

.user-actions {
    display: flex;
    gap: 4px;
}

.user-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: all 0.2s;
    display: flex;
    color: var(--text-3);
}

.user-actions button:hover { background: rgba(255,255,255,0.06); color: var(--text-1); }

/* ─── Worker Items ────────────────────────────── */

.worker-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
    gap: 10px;
}

.worker-domain {
    flex: 1;
    font-size: 12px;
    font-family: var(--mono);
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.worker-ping {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: var(--mono);
}

/* ─── Forms ───────────────────────────────────── */

.add-form { padding: 14px; }

.form-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
}

.form-icon { font-size: 14px; }

.form-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.input {
    font-family: var(--mono);
    font-size: 13px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-1);
    outline: none;
    transition: all 0.2s var(--ease);
    flex: 1;
    min-width: 0;
}

.input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--glow-blue);
    background: rgba(255, 255, 255, 0.05);
}

.input::placeholder { color: var(--text-3); }

.select-wrap { flex: 0 0 auto; position: relative; }

.select-wrap::after {
    content: '▾';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    font-size: 10px;
    pointer-events: none;
}

.select {
    width: 90px;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: 24px;
    color-scheme: dark;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-1);
    font-family: var(--mono);
    font-size: 13px;
    padding: 10px 28px 10px 14px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s var(--ease);
}

.select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--glow-blue);
}

.select option {
    background: var(--bg-secondary);
    color: var(--text-1);
    padding: 8px;
}

/* ─── Buttons ─────────────────────────────────── */

.btn {
    font-family: var(--font);
    font-size: 12px;
    font-weight: 700;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    overflow: hidden;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
    background: linear-gradient(135deg, var(--blue), var(--purple));
    color: #fff;
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.2);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(88, 166, 255, 0.3);
    filter: brightness(1.1);
}

.btn-add {
    width: 42px;
    height: 42px;
    padding: 0;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.btn-danger-subtle {
    background: rgba(248, 81, 73, 0.08);
    color: var(--red);
    border: 1px solid rgba(248, 81, 73, 0.15);
    font-size: 11px;
}

.btn-danger-subtle:hover {
    background: rgba(248, 81, 73, 0.15);
    border-color: rgba(248, 81, 73, 0.3);
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    color: var(--text-2);
}

.btn-icon:hover { background: rgba(255,255,255,0.06); }

.btn-glow:hover {
    color: var(--blue);
    background: var(--glow-blue);
}

/* ─── Bottom Tab Bar ──────────────────────────── */

#tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    background: rgba(10, 14, 20, 0.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--border);
    padding: 6px 0;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    z-index: 10;
    max-width: 480px;
    margin: 0 auto;
}

.tab {
    flex: 1;
    max-width: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 0;
    background: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    position: relative;
}

.tab-svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-3);
    transition: all 0.25s var(--ease);
}

.tab-label {
    font-family: var(--font);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    transition: color 0.2s;
}

.tab.active .tab-svg { stroke: var(--blue); }
.tab.active .tab-label { color: var(--blue); }

.tab.active::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 30%;
    right: 30%;
    height: 2px;
    background: var(--blue);
    border-radius: 2px;
    box-shadow: 0 0 8px var(--blue);
}

/* ─── Bottom Sheet ────────────────────────────── */

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

.overlay.visible { opacity: 1; }
.overlay.hidden { display: none; }

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    z-index: 51;
    padding: 12px 20px 28px;
    transform: translateY(100%);
    transition: transform 0.35s var(--ease);
}

.bottom-sheet.visible { transform: translateY(0); }
.bottom-sheet.hidden { display: none; }

.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--text-3);
    border-radius: 4px;
    margin: 0 auto 16px;
}

.sheet-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
}

.sheet-text {
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 16px;
    line-height: 1.5;
}

.sheet-actions {
    display: flex;
    gap: 8px;
}

.sheet-actions .btn { flex: 1; padding: 12px; }

.btn-sheet-cancel {
    background: rgba(255,255,255,0.06);
    color: var(--text-2);
    border: 1px solid var(--border);
}

.btn-sheet-confirm {
    background: linear-gradient(135deg, var(--red), #d63031);
    color: #fff;
}

/* ─── Toast ───────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    backdrop-filter: blur(24px);
    z-index: 100;
    opacity: 0;
    transition: all 0.3s var(--ease);
    pointer-events: none;
    max-width: 85%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.hidden { display: none; }

/* ─── Empty State ─────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 28px;
    color: var(--text-3);
    font-size: 13px;
}

/* ─── Utilities ───────────────────────────────── */

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loading { pointer-events: none; opacity: 0.5; }
