:root {
    --bg: #10141b;
    --panel: #171d27;
    --panel-2: #1e2632;
    --border: #2a3546;
    --text: #e6edf6;
    --muted: #8fa0b8;
    --accent: #4c8dff;
    --accent-hover: #6ba0ff;
    --ok: #2fbf71;
    --warn: #e0a23c;
    --error: #ef5a5a;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

a {
    color: var(--accent);
    text-decoration: none;
}

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

/* ---------------------------------------------------------------- layout */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
}

.full {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 57px);
}

/* ----------------------------------------------------------------- stats */
.stats {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 16px;
}

.stats b {
    color: var(--text);
}

/* ----------------------------------------------------------------- cards */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    word-break: break-word;
}

.card-meta {
    color: var(--muted);
    font-size: 13px;
    margin: 6px 0 0;
    word-break: break-word;
}

.card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* ---------------------------------------------------------------- status */
.status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
}

.status-RUNNING .dot { background: var(--ok); }
.status-RUNNING { color: var(--ok); }
.status-ERROR .dot, .status-PROXY_ERROR .dot { background: var(--error); }
.status-ERROR, .status-PROXY_ERROR { color: var(--error); }
.status-STARTING .dot,
.status-STOPPING .dot,
.status-IMPORTING_COOKIES .dot { background: var(--warn); animation: pulse 1s infinite; }
.status-STARTING,
.status-STOPPING,
.status-IMPORTING_COOKIES { color: var(--warn); }
.status-STOPPED { color: var(--muted); }

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

.error-box {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(239, 90, 90, 0.12);
    border: 1px solid rgba(239, 90, 90, 0.35);
    color: #ffbdbd;
    font-size: 13px;
    word-break: break-word;
}

/* --------------------------------------------------------------- buttons */
button, .btn {
    font: inherit;
    font-size: 14px;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
}

button:hover:not(:disabled), .btn:hover {
    border-color: var(--accent);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #06121f;
    font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-danger {
    color: #ffc9c9;
    border-color: rgba(239, 90, 90, 0.5);
}

.btn-danger:hover:not(:disabled) {
    border-color: var(--error);
}

/* ----------------------------------------------------------------- forms */
label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    font: inherit;
    font-size: 14px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

input:disabled, select:disabled, textarea:disabled {
    opacity: 0.5;
}

.field {
    margin-bottom: 14px;
}

.row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.row > * {
    flex: 1 1 140px;
}

.radio-row {
    display: flex;
    gap: 18px;
    align-items: center;
    margin-bottom: 10px;
}

.radio-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: var(--text);
    font-size: 14px;
}

.hint {
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 6px;
}

.hint-warn {
    color: var(--warn);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    word-break: break-all;
}

.readonly-value {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
}

dl.props {
    display: grid;
    grid-template-columns: minmax(120px, 200px) 1fr;
    gap: 8px 16px;
    margin: 0;
    font-size: 14px;
}

dl.props dt {
    color: var(--muted);
}

dl.props dd {
    margin: 0;
    word-break: break-word;
}

/* ---------------------------------------------------------------- dialog */
dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    padding: 20px;
    width: min(520px, 92vw);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

dialog h2 {
    margin: 0 0 16px;
    font-size: 17px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

/* --------------------------------------------------------------- browser */
.browser-workspace {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
}

.browser-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.browser-tools label {
    color: var(--muted);
    font-size: 13px;
}

.browser-tools textarea {
    flex: 1 1 280px;
    min-width: 120px;
    max-height: 84px;
    resize: vertical;
    padding: 7px 9px;
}

.browser-tools button {
    white-space: nowrap;
}

.browser-view-status {
    color: var(--muted);
    font-size: 12px;
    min-width: 92px;
    text-align: right;
}

.browser-screen {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #000;
}

.browser-screen canvas {
    outline: none;
}

@media (max-width: 850px) {
    .browser-tools {
        flex-wrap: wrap;
    }

    .browser-tools textarea {
        order: 5;
        flex-basis: 100%;
    }
}

.notice {
    padding: 16px;
    color: var(--muted);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    max-width: min(560px, 92vw);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    z-index: 40;
}

.toast.ok { border-color: rgba(47, 191, 113, 0.6); }
.toast.err { border-color: rgba(239, 90, 90, 0.6); }

.empty {
    text-align: center;
    color: var(--muted);
    padding: 48px 16px;
}

/* ================================================================ 0.3 ==== */
.nav {
    display: flex;
    gap: 14px;
    margin-right: auto;
    margin-left: 22px;
    font-size: 14px;
}

.nav a {
    color: var(--muted);
    padding: 4px 2px;
}

.nav a:hover {
    color: var(--text);
}

.container-wide {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* --------------------------------------------------------- server strip */
.server-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.metric {
    flex: 1 1 150px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.metric-label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    font-size: 18px;
    font-weight: 600;
    margin-top: 2px;
}

.metric-sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.bar {
    height: 4px;
    border-radius: 2px;
    background: var(--panel-2);
    margin-top: 7px;
    overflow: hidden;
}

.bar > span {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.bar.warn > span { background: var(--warn); }
.bar.crit > span { background: var(--error); }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 14px;
}

.toolbar .field {
    margin-bottom: 0;
}

.toolbar .grow {
    flex: 1 1 240px;
}

.toolbar select,
.toolbar input {
    min-width: 130px;
}

/* ------------------------------------------------------------------ table */
.table-wrap {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

table.accounts {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table.accounts th,
table.accounts td {
    padding: 9px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.accounts th {
    color: var(--muted);
    font-weight: 500;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    user-select: none;
}

table.accounts th.plain {
    cursor: default;
}

table.accounts tbody tr:last-child td {
    border-bottom: 0;
}

table.accounts tbody tr:hover {
    background: var(--panel-2);
}

table.accounts td.name {
    white-space: normal;
    min-width: 180px;
}

table.accounts td.actions {
    text-align: right;
}

table.accounts td.actions button,
table.accounts td.actions .btn {
    padding: 4px 10px;
    font-size: 13px;
}

.checkbox-cell {
    width: 34px;
}

.muted {
    color: var(--muted);
}

.sort-active::after {
    content: " \25B4";
    color: var(--accent);
}

.sort-active.desc::after {
    content: " \25BE";
}

/* ------------------------------------------------------------------- tags */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 12px;
    color: var(--muted);
}

.chip button {
    all: unset;
    cursor: pointer;
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
}

.chip button:hover {
    color: var(--error);
}

.chip.group {
    color: var(--text);
    border-color: var(--accent);
}

/* ------------------------------------------------------------ bulk result */
.bulk-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}

.bulk-result {
    margin-top: 12px;
}

.bulk-result li {
    margin-bottom: 4px;
}

.bulk-result .bad {
    color: #ffbdbd;
}

.health-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
}

.health-HEALTHY { background: var(--ok); }
.health-DEGRADED { background: var(--warn); }
.health-UNHEALTHY { background: var(--error); }

/* --------------------------------------------------------------- activity */
table.log {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

table.log td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.log tr:last-child td {
    border-bottom: 0;
}

table.log td.when {
    color: var(--muted);
    white-space: nowrap;
    width: 150px;
}

table.log td.what {
    color: var(--muted);
    white-space: nowrap;
    width: 210px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.pager {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 12px;
    color: var(--muted);
    font-size: 13px;
}

/* =============================================================== auth ==== */
.signed-in-user {
    color: var(--muted);
    font-size: 13px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-form {
    margin: 0;
}

.logout-form button {
    padding: 5px 10px;
}

.auth-page {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 18% 12%, rgba(76, 141, 255, 0.17), transparent 32rem),
        radial-gradient(circle at 82% 85%, rgba(47, 191, 113, 0.09), transparent 28rem),
        var(--bg);
}

.auth-shell {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    background: rgba(23, 29, 39, 0.94);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 34px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.auth-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--accent), #7aa9ff);
    color: #07101d;
    font-weight: 800;
    letter-spacing: -0.04em;
    margin-bottom: 22px;
}

.auth-eyebrow {
    margin: 0 0 5px;
    color: var(--accent-hover);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
}

.auth-card h1 {
    margin: 0;
    font-size: 30px;
    letter-spacing: -0.03em;
}

.auth-intro {
    margin: 8px 0 25px;
    color: var(--muted);
}

.auth-form .field:last-of-type {
    margin-bottom: 20px;
}

.auth-submit {
    width: 100%;
    padding: 10px 16px;
}

.auth-error,
.auth-locked {
    border: 1px solid rgba(239, 90, 90, 0.42);
    background: rgba(239, 90, 90, 0.10);
    color: #ffd2d2;
    border-radius: 9px;
    padding: 11px 13px;
    margin-bottom: 18px;
}

.auth-locked p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.auth-footer {
    margin: 24px 0 0;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

@media (max-width: 520px) {
    .auth-shell { padding: 14px; }
    .auth-card { padding: 25px 20px; }
}
