/* ============================================================
   WireGuard Manager — visual identity
   A "signal in the dark" theme: deep slate-blue background,
   a fiber-optic teal accent for live/active state, amber for
   caution, and a woven-cable motif for structural dividers.
   ============================================================ */

:root {
    --bg-deep: #0A0E14;
    --bg-panel: #10151F;
    --bg-raised: #171F2C;
    --border: #232C3B;
    --border-soft: #1A2230;

    --text-primary: #E7ECF4;
    --text-muted: #8A96AC;
    --text-faint: #5B6579;

    --accent: #45E0C4;
    --accent-dim: #1F5E52;
    --accent-glow: rgba(69, 224, 196, 0.18);

    --warn: #F0B429;
    --warn-dim: #4A3A12;

    --danger: #F0576B;
    --danger-dim: #4A1E26;

    --radius: 10px;
    --radius-sm: 6px;

    --font-display: 'Space Grotesk', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

body {
    background-image:
        radial-gradient(ellipse 900px 500px at 15% -10%, rgba(69, 224, 196, 0.06), transparent),
        radial-gradient(ellipse 700px 400px at 90% 10%, rgba(240, 180, 41, 0.04), transparent);
    background-attachment: fixed;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 0.5em; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--font-mono); }

a { color: var(--accent); }

button { font-family: var(--font-body); cursor: pointer; }

/* ---------- Brand mark: a small braided/tunnel glyph ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 30px; height: 30px; flex-shrink: 0;
    border-radius: 8px;
    background:
        linear-gradient(135deg, var(--accent) 0%, #1a8f7a 100%);
    position: relative;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 4px 14px var(--accent-glow);
}
.brand-mark::before {
    content: "";
    position: absolute;
    inset: 8px;
    border: 2px solid rgba(10,14,20,0.85);
    border-radius: 50%;
    border-right-color: transparent;
    transform: rotate(45deg);
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }

/* ---------- Woven-cable divider: encodes "many strands, one tunnel" ---------- */
.wire-divider {
    height: 3px;
    margin: 0 32px;
    background-image: repeating-linear-gradient(
        90deg,
        var(--accent) 0px, var(--accent) 10px,
        transparent 10px, transparent 16px
    );
    opacity: 0.35;
}

/* ================= Auth pages (login / setup) ================= */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
}
.setup-card { max-width: 560px; }
.auth-card .brand { margin-bottom: 8px; }
.auth-card h1 { font-size: 1.3rem; }
.auth-card > p { margin: 12px 0 20px; }

fieldset {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    margin: 0 0 16px;
    padding: 14px 16px 16px;
}
legend {
    font-family: var(--font-display);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0 6px;
}

label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}
label:last-child { margin-bottom: 0; }

input[type="text"], input[type="password"] {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}
input:focus, button:focus-visible, dialog :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.btn-primary {
    background: var(--accent);
    color: #0A0E14;
    border: none;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-faint); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger-dim);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}
.btn-danger:hover { background: var(--danger-dim); }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
}
.alert ul { margin: 0; padding-left: 18px; }
.alert-error { background: var(--danger-dim); color: #FFC9D2; border: 1px solid #5a2530; }
.alert-success { background: var(--accent-dim); color: #B7F5E9; border: 1px solid #2a6f61; }
.alert-warning { background: var(--warn-dim); color: #FBE3A7; border: 1px solid #6b551c; }

/* ================= App shell ================= */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 32px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

.iface-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}
.dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-faint);
    box-shadow: 0 0 0 0 transparent;
}
.dot.up { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 2s ease-in-out infinite; }
.dot.down { background: var(--danger); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.user-chip {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 6px 10px;
    border-left: 1px solid var(--border);
}

.app-main {
    max-width: 980px;
    margin: 0 auto;
    padding: 28px 32px 64px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.count-badge {
    display: inline-block;
    background: var(--bg-raised);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: middle;
}

.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.field-value { font-size: 0.9rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

/* ---------- Peer list ---------- */
.peer-list { display: flex; flex-direction: column; gap: 10px; }

.peer-card {
    display: grid;
    grid-template-columns: auto 1.4fr 1fr 1fr auto;
    align-items: center;
    gap: 16px;
    background: var(--bg-raised);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}
.peer-card.disabled { opacity: 0.5; }

.peer-status { display: flex; align-items: center; justify-content: center; }

.peer-name-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.peer-name { font-weight: 600; font-size: 0.92rem; }
.peer-name-input {
    background: transparent; border: none; border-bottom: 1px dashed var(--border);
    color: var(--text-primary); font: inherit; font-weight: 600; font-size: 0.92rem;
    padding: 0; width: 100%;
}
.peer-ip { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-muted); }

.peer-meta { display: flex; flex-direction: column; gap: 2px; font-size: 0.78rem; color: var(--text-muted); }
.peer-meta .mono { color: var(--text-primary); }

.peer-transfer { display: flex; flex-direction: column; gap: 2px; font-size: 0.78rem; color: var(--text-muted); font-family: var(--font-mono); }

.peer-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.9rem;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--text-faint); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger-dim); background: var(--danger-dim); }

.toggle-switch {
    position: relative;
    width: 36px; height: 20px;
    background: var(--border);
    border-radius: 10px;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}
.toggle-switch::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: transform 0.15s ease, background 0.15s ease;
}
.toggle-switch.on { background: var(--accent-dim); }
.toggle-switch.on::after { transform: translateX(16px); background: var(--accent); }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}
.empty-state p:first-child { font-size: 1rem; font-weight: 600; }
.empty-state .btn-primary { margin-top: 12px; }

/* ---------- Modals ---------- */
dialog.modal {
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 420px;
}
dialog.modal-wide { max-width: 560px; }
dialog.modal::backdrop { background: rgba(5, 8, 12, 0.7); backdrop-filter: blur(2px); }
dialog.modal h3 { margin-bottom: 8px; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.cred-grid { display: grid; grid-template-columns: 160px 1fr; gap: 16px; align-items: start; margin: 16px 0; }
.qr-wrap { display: flex; align-items: center; justify-content: center; background: #fff; border-radius: var(--radius-sm); padding: 10px; }
.config-preview {
    background: var(--bg-raised);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 0.72rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 220px;
    overflow-y: auto;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 0.85rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
}
.toast.error { border-color: var(--danger-dim); color: #FFC9D2; }

@media (max-width: 720px) {
    .topbar { padding: 14px 16px; }
    .app-main { padding: 20px 16px 48px; }
    .peer-card { grid-template-columns: 1fr; }
    .peer-actions { justify-content: flex-start; }
    .cred-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .dot.up { animation: none; }
}
