:root {
    --bg: #0b1220;
    --bg-2: #111a2e;
    --card: #16213a;
    --card-2: #1c2942;
    --line: #243352;
    --text: #e7edf7;
    --muted: #9fb0cc;
    --accent: #4f8cff;
    --green: #2fbf71;
    --green-bg: #133527;
    --red: #ef4f5a;
    --red-bg: #3a1820;
    --amber: #f0a93b;
    --amber-bg: #3a2c12;
    --radius: 14px;
    --shadow: 0 6px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    background: radial-gradient(1200px 600px at 80% -10%, #16233f 0%, var(--bg) 55%);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- App bar ---- */
.appbar {
    position: sticky; top: 0; z-index: 50;
    background: rgba(11,18,32,.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: env(safe-area-inset-top) 0 0;
}
.appbar-row {
    display: flex; align-items: center; gap: 10px;
    max-width: 1100px; margin: 0 auto; padding: 10px 16px;
}
.srv {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--card); border: 1px solid var(--line); color: var(--text);
    padding: 8px 12px; border-radius: 999px; cursor: pointer; font-weight: 600;
    max-width: 52vw; overflow: hidden;
}
.srv .srv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srv .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green);
    box-shadow: 0 0 0 3px rgba(47,191,113,.18); flex: none; }
.ip-badge {
    font: 600 13px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    background: var(--bg-2); border: 1px solid var(--line); color: var(--accent);
    padding: 6px 10px; border-radius: 8px; letter-spacing: .3px;
}
.spacer { flex: 1; }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a, .topnav .link {
    color: var(--muted); padding: 8px 10px; border-radius: 8px; font-weight: 600;
    background: none; border: none; cursor: pointer; font-size: 14px;
}
.topnav a:hover, .topnav .link:hover { color: var(--text); background: var(--card); text-decoration: none; }
.inline { display: inline; margin: 0; }
.burger { display: none; background: var(--card); border: 1px solid var(--line); color: var(--text);
    width: 42px; height: 42px; border-radius: 10px; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.burger:hover { border-color: var(--accent); }
.ip-extra { max-width: 1100px; margin: 0 auto; padding: 0 16px 8px; color: var(--muted); font-size: 12px; }

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }
h1 { font-size: 22px; margin: 6px 0 16px; }
h2 { font-size: 16px; margin: 26px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.muted { color: var(--muted); }

/* ---- Toolbar / search ---- */
.toolbar { display: flex; gap: 10px; align-items: center; margin: 12px 0 16px; flex-wrap: wrap; }
.search {
    flex: 1; min-width: 180px; display: flex; align-items: center; gap: 8px;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px;
}
.search input { flex: 1; background: none; border: none; color: var(--text); padding: 11px 0; outline: none; font-size: 15px; }
.search svg { color: var(--muted); flex: none; }
.count-chip { color: var(--muted); font-size: 13px; }

/* ---- Cards ---- */
.cards { display: grid; gap: 12px; }
.card {
    background: linear-gradient(180deg, var(--card) 0%, var(--card-2) 100%);
    border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
    box-shadow: var(--shadow);
}
.card-top { display: flex; align-items: center; gap: 10px; }
.card-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }
.card-meta code { color: var(--text); background: var(--bg-2); padding: 1px 6px; border-radius: 5px; }

/* ---- Page head + sections ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.block { margin-top: 8px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 26px 0 10px; }
.section-head h2 { margin: 0; }
.summary { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.summary .s-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.summary .s-dot.started { background: var(--green); }
.summary .s-dot.stopped { background: var(--red); }
.summary .s-total { margin-left: 4px; }
.icon-btn { padding: 9px; min-height: 40px; }
.btn.ghost { background: transparent; }

/* ---- Filter chips ---- */
.chips { display: flex; gap: 6px; }
.chip {
    background: var(--card); border: 1px solid var(--line); color: var(--muted);
    padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 13px; cursor: pointer; min-height: 38px;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: transparent; color: #fff; }

/* ---- Status pill ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 12px;
    padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.started { color: var(--green); background: var(--green-bg); }
.pill.stopped { color: var(--red); background: var(--red-bg); }
.pill.transition { color: var(--amber); background: var(--amber-bg); }
.pill.unknown { color: var(--muted); background: var(--bg-2); }

/* ---- Buttons ---- */
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
    appearance: none; border: 1px solid var(--line); background: var(--card-2); color: var(--text);
    padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-green { background: var(--green-bg); color: var(--green); border-color: transparent; }
.btn-red { background: var(--red-bg); color: var(--red); border-color: transparent; }
.btn-amber { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-block { width: 100%; justify-content: center; }
.btn-lg { padding: 13px 18px; font-size: 16px; }

/* ---- Card identity + meta ---- */
.card-id { min-width: 0; flex: 1; }
.hide-xs { }

/* ---- Card actions: primary recycle + overflow ---- */
.card-actions { display: flex; gap: 8px; margin-top: 14px; align-items: stretch; }
.btn-recycle {
    flex: 1; justify-content: center; background: var(--accent); color: #fff; border-color: transparent;
    font-weight: 700; box-shadow: 0 2px 10px rgba(79,140,255,.25);
}
.btn-recycle:hover { background: #5d97ff; border-color: transparent; }
.btn-recycle svg { opacity: .95; }

.menu-wrap { position: relative; flex: none; }
.kebab { padding: 0 14px; min-width: 48px; justify-content: center; font-size: 20px; line-height: 1; color: var(--muted); }
.menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px;
    min-width: 180px; box-shadow: var(--shadow); display: none;
}
.menu.open { display: block; }
.menu-item {
    display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
    background: none; border: none; color: var(--text); padding: 11px 12px; border-radius: 8px;
    font-weight: 600; font-size: 14px; cursor: pointer;
}
.menu-item:hover { background: var(--card-2); }
.menu-item.green { color: var(--green); }
.menu-item.red { color: var(--red); }

/* ---- Card busy state ---- */
.card.busy { pointer-events: none; }
.card.busy::after {
    content: ""; position: absolute; inset: 0; border-radius: var(--radius);
    background: rgba(11,18,32,.45); backdrop-filter: blur(1px);
}
.card.busy::before {
    content: ""; position: absolute; z-index: 2; top: 50%; left: 50%; width: 26px; height: 26px;
    margin: -13px 0 0 -13px; border: 3px solid var(--accent); border-top-color: transparent;
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
.card { position: relative; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- Confirmation dialog ---- */
dialog.confirm-dialog {
    border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text);
    width: min(440px, 92vw); padding: 22px; box-shadow: var(--shadow);
}
dialog.confirm-dialog.danger { border-color: #5a2530; }
.cd-head { display: flex; gap: 14px; align-items: flex-start; }
.cd-icon {
    flex: none; width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center;
    justify-content: center; font-size: 20px; background: var(--amber-bg); color: var(--amber);
}
.cd-icon.green { background: var(--green-bg); color: var(--green); }
.cd-icon.red { background: var(--red-bg); color: var(--red); }
.cd-head h3 { margin: 2px 0 6px; font-size: 18px; }
.cd-head p { margin: 0; font-size: 14px; }
.cd-check { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; font-size: 14px; }
.cd-check input { width: 18px; height: 18px; }
.cd-field { margin: 14px 0 2px; }
.cd-field label { display: block; font-size: 13px; margin-bottom: 6px; }
.cd-input { width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
    padding: 11px 13px; border-radius: 10px; font-size: 16px; outline: none; }
.cd-input:focus { border-color: var(--accent); }
.cd-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.cd-actions .btn { min-width: 110px; justify-content: center; }

/* ---- Forms / auth ---- */
.auth { max-width: 400px; margin: 8vh auto 0; }
.auth .brand { text-align: center; margin-bottom: 22px; }
.auth .brand .logo { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.auth .brand .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 22px; box-shadow: var(--shadow); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input {
    width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
    padding: 12px 14px; border-radius: 10px; font-size: 16px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.code-input { letter-spacing: 8px; text-align: center; font: 700 22px ui-monospace, monospace; }
.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.alert-error { background: var(--red-bg); color: #ffd7da; border: 1px solid #5a2530; }
.alert-ok { background: var(--green-bg); color: #c7f5dd; border: 1px solid #1f5a3e; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }

/* ---- QR enrollment ---- */
.qr-wrap { text-align: center; }
.qr-wrap img { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 12px; }
.secret { font: 600 14px ui-monospace, monospace; background: var(--bg-2); padding: 10px;
    border-radius: 8px; word-break: break-all; margin: 12px 0; border: 1px solid var(--line); }

/* ---- Tables (admin) ---- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tbl th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.tbl tr:hover td { background: rgba(255,255,255,.02); }
.tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--bg-2); color: var(--muted); }
.tag.admin { background: #2a2350; color: #c4b6ff; }
.tag.danger { background: var(--red-bg); color: var(--red); }

/* ---- Server dialog ---- */
dialog.server-dialog {
    border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text);
    width: min(440px, 92vw); padding: 0; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(2,6,16,.6); backdrop-filter: blur(2px); }
.sd-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sd-head .x { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.server-list { list-style: none; margin: 0; padding: 8px; max-height: 46vh; overflow: auto; }
.server-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; }
.server-list li:hover { background: var(--card-2); }
.server-list .si-name { font-weight: 700; }
.server-list .si-url { color: var(--muted); font-size: 12px; }
.server-list .go { margin-left: auto; }
.server-list .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.add-server { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 18px; border-top: 1px solid var(--line); }
.add-server input { flex: 1; min-width: 120px; background: var(--bg-2); border: 1px solid var(--line);
    color: var(--text); border-radius: 8px; padding: 10px; }
.add-server button { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
.hint { color: var(--muted); font-size: 12px; padding: 0 18px 16px; margin: 0; }

/* ---- Danger zone ---- */
.danger-zone { margin-top: 30px; border: 1px solid #4a2330; background: linear-gradient(180deg, #1d1320, #221016);
    border-radius: var(--radius); padding: 16px; }
.danger-zone h2 { color: var(--red); margin-top: 0; }

/* ---- Toast ---- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex;
    flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: var(--card-2); border: 1px solid var(--line); color: var(--text); padding: 11px 16px;
    border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; max-width: 90vw; }
.toast.ok { border-color: #1f5a3e; }
.toast.err { border-color: #5a2530; }

@media (max-width: 620px) {
    .srv { max-width: 40vw; }
    .section-head { margin-top: 20px; }
    .toolbar { gap: 8px; }
    .chips { width: 100%; }
    .chip { flex: 1; text-align: center; }

    /* Collapse the top nav into a burger dropdown */
    .burger { display: inline-flex; }
    .topnav {
        position: absolute; top: calc(100% + 6px); right: 12px; z-index: 60;
        flex-direction: column; align-items: stretch; gap: 2px;
        background: var(--card); border: 1px solid var(--line); border-radius: 12px;
        padding: 6px; min-width: 190px; box-shadow: var(--shadow);
        display: none;
    }
    .topnav.open { display: flex; }
    .topnav a, .topnav .link { padding: 12px 14px; border-radius: 8px; text-align: left; width: 100%; }
    .topnav .inline, .topnav .inline .link { display: block; width: 100%; }
}

@media (max-width: 480px) {
    .hide-xs { display: none; }
    .summary { width: 100%; }
    .cd-actions { flex-direction: column-reverse; }
    .cd-actions .btn { width: 100%; }
}
