:root {
    --bg: #08090c;
    --bg-soft: #0e1016;
    --panel: rgba(18, 20, 28, 0.72);
    --panel-border: rgba(255, 255, 255, 0.07);
    --text: #e6e8ee;
    --text-dim: #8b90a0;
    --accent: #5eead4;
    --accent-2: #818cf8;
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
    --mono: "JetBrains Mono", ui-monospace, monospace;
    --sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Анимированный фон ---------- */
.bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(120% 120% at 50% 0%, #0d1018 0%, #08090c 55%, #050608 100%);
}
.bg-grid {
    position: absolute;
    inset: -2px;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(circle at 50% 40%, black 0%, transparent 80%);
    animation: gridDrift 40s linear infinite;
}
@keyframes gridDrift {
    from { background-position: 0 0, 0 0; }
    to { background-position: 44px 44px, 44px 44px; }
}
.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.5;
    mix-blend-mode: screen;
}
.blob-1 { width: 46vw; height: 46vw; background: #14b8a6; top: -12vw; left: -8vw; animation: float1 22s ease-in-out infinite; }
.blob-2 { width: 40vw; height: 40vw; background: #6366f1; bottom: -14vw; right: -8vw; animation: float2 26s ease-in-out infinite; }
.blob-3 { width: 30vw; height: 30vw; background: #0ea5e9; top: 30%; left: 40%; opacity: 0.3; animation: float3 30s ease-in-out infinite; }
@keyframes float1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(6vw, 8vw) scale(1.12); } }
@keyframes float2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-7vw, -5vw) scale(1.1); } }
@keyframes float3 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-5vw, 4vw) scale(0.9); } }
.bg-noise {
    position: absolute;
    inset: 0;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Экран входа ---------- */
.login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 360px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
    box-shadow: none;
}
#login-form {
    display: flex;
    justify-content: center;
    width: 100%;
}
#login-key {
    width: 100%;
    max-width: 320px;
    text-align: center;
    letter-spacing: 0.12em;
    caret-color: var(--accent);
}
#login-key.login-locked {
    color: var(--text-dim);
    caret-color: transparent;
    cursor: default;
}
#turnstile-wrap {
    display: none;
    justify-content: center;
    width: 100%;
    margin-top: 14px;
    min-height: 65px;
}
#turnstile-wrap.active {
    display: flex;
}
.login-error:empty {
    display: none;
}
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 0; text-align: center; }
input, select {
    width: 100%;
    padding: 13px 15px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--panel-border);
    border-radius: 11px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 14px;
    outline: none;
    color-scheme: dark;
    transition: border-color 0.15s, box-shadow 0.15s;
}
select option,
select optgroup {
    background: #12141c;
    color: var(--text);
}
select option:checked,
select option:hover {
    background: #1a1f2e;
    color: var(--accent);
}
input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.12);
}
button {
    cursor: pointer;
    font-family: var(--sans);
    font-weight: 600;
    border: none;
    border-radius: 11px;
    transition: transform 0.1s, opacity 0.15s, background 0.15s;
}
button:active { transform: scale(0.97); }
#login-form button {
    padding: 13px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #06110f;
    font-size: 15px;
}

/* ---------- App ---------- */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(10, 11, 15, 0.55);
    backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-weight: 700; font-size: 16px; }
.brand-accent { color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
    padding: 9px 18px;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    border-radius: 9px;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab.active { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.logout {
    margin-left: 24px;
    padding: 9px 16px;
    background: rgba(248, 113, 113, 0.12);
    color: var(--danger);
    font-size: 14px;
}
.logout:hover { background: rgba(248, 113, 113, 0.2); }

.content { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
.content:has(#tab-console.active) { overflow: hidden; }
.tab-panel { display: none; max-width: 1100px; margin: 0 auto; height: 100%; }
.tab-panel.active { display: block; }

/* ---------- Метрики ---------- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.metric-card {
    padding: 18px 20px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    backdrop-filter: blur(12px);
}
.metric-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--text-dim); }
.metric-head span:last-child { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--text); }
.bar { height: 6px; background: rgba(255, 255, 255, 0.07); border-radius: 4px; margin: 12px 0 8px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 4px; transition: width 0.5s ease; }
.metric-sub { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.metric-net { display: flex; gap: 14px; margin: 10px 0 6px; font-size: 14px; color: var(--text); }

/* ---------- Сайты ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-size: 18px; font-weight: 600; }
.btn-add { padding: 9px 16px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #06110f; font-size: 14px; }
.btn-ghost { padding: 9px 16px; background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 14px; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }

.sites-list { display: flex; flex-direction: column; gap: 12px; }
.site-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    backdrop-filter: blur(12px);
    transition: border-color 0.15s, opacity 0.15s;
}
.site-card.dragging { opacity: 0.45; }
.site-card.drag-over { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(94, 234, 212, 0.25); }
.site-leading {
    display: flex;
    align-items: center;
    gap: 10px;
}
.site-drag {
    cursor: grab;
    width: 24px;
    height: 24px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-dim);
    background: transparent;
    border: none;
    border-radius: 6px;
    font-weight: 400;
    user-select: none;
    touch-action: none;
}
.site-drag-icon {
    display: block;
    fill: currentColor;
    opacity: 0.5;
}
.site-drag:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.site-drag:hover .site-drag-icon { opacity: 0.85; }
.site-drag:active { cursor: grabbing; }
.site-state { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.state-active { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.state-warn { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.state-inactive { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.state-failed { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.site-info { flex: 1; min-width: 0; }
.site-name { font-weight: 600; font-size: 15px; }
.site-meta { font-family: var(--mono); font-size: 12px; color: var(--text-dim); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-meta a { color: var(--accent); text-decoration: none; }
.site-actions { display: flex; gap: 8px; flex-shrink: 0; }
.act {
    padding: 7px 13px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    border-radius: 8px;
}
.act:hover { background: rgba(255, 255, 255, 0.12); }
.act-start { color: var(--ok); }
.act-stop { color: var(--danger); }
.act-del { color: var(--text-dim); }
.empty { color: var(--text-dim); text-align: center; padding: 40px; font-family: var(--mono); font-size: 14px; }

/* ---------- Логи ---------- */
.logs-toolbar, .term-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.term-title { font-family: var(--mono); font-size: 14px; color: var(--text); }

/* Консоль: единое окно (терминал или логи сайта) */
#tab-console {
    display: none;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
#tab-console.active { display: flex; }
.console-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-shrink: 0;
}
.console-head select {
    width: auto;
    min-width: 0;
    max-width: 260px;
    flex: 1 1 160px;
    padding: 5px 28px 5px 10px;
    font-size: 12px;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.55);
}
.console-head .btn-ghost {
    width: auto;
    min-width: 0;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 7px;
    white-space: nowrap;
}
#console-reconnect {
    width: 30px;
    min-width: 30px;
    padding: 5px 0;
    font-size: 15px;
    line-height: 1;
    text-align: center;
}
.console-single { flex: 1 1 auto; min-height: 0; }
.logs-toolbar select { width: auto; min-width: 200px; }
.logs-status {
    width: 18px;
    min-width: 18px;
    height: 18px;
    justify-content: center;
    display: inline-flex;
    align-items: center;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    border: 0;
}
.logs-status::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: background 0.2s;
}
.logs-status.on {
    background: transparent;
}
.logs-status.on::before {
    background: var(--ok);
    box-shadow: 0 0 8px var(--ok);
    animation: statusPulse 1.6s ease-in-out infinite;
}
@keyframes statusPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.logs-output {
    height: calc(100vh - 210px);
    overflow: auto;
    padding: 16px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.5;
    color: #cdd3df;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Терминал ---------- */
.terminal-box {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 12px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
}
.terminal-mount {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}
.terminal-mount .xterm {
    height: 100%;
}
.terminal-mount .xterm-viewport {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* ---------- Nginx editor ---------- */
#tab-nginx { display: none; flex-direction: column; }
#tab-nginx.active { display: flex; }
.nginx-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.nginx-head h2 { font-size: 18px; font-weight: 600; }
.nginx-path {
    margin-top: 4px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-dim);
}
.nginx-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
#nginx-editor {
    flex: 1 1 auto;
    width: 100%;
    height: calc(100vh - 260px);
    min-height: 360px;
    resize: none;
    padding: 16px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    color: #d7dce8;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.55;
    tab-size: 4;
    outline: none;
}
#nginx-editor:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.12);
}
.nginx-output {
    flex-shrink: 0;
    margin-top: 10px;
    padding: 7px 12px;
    max-height: 120px;
    overflow: auto;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.nginx-output:empty { display: none; }
.nginx-output.ok { color: var(--ok); border-color: rgba(74, 222, 128, 0.3); background: rgba(74, 222, 128, 0.06); }
.nginx-output.err { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.06); }

/* ---------- Модалка ---------- */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
}
.modal-card {
    width: 100%;
    max-width: 400px;
    padding: 28px;
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
}
.modal-card h3 { margin-bottom: 20px; font-size: 17px; }
#add-form { display: flex; flex-direction: column; gap: 14px; }
#add-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* Скроллбары */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: 12px; }
    .tabs { margin-left: 0; order: 3; width: 100%; }
    .logout { margin-left: auto; }
}
