:root {
  --bg: #0e1014;
  --panel: #161920;
  --panel-2: #1c2029;
  --hover: #222733;
  --border: #292e3a;
  --text: #e7e9ee;
  --muted: #98a1b1;
  --accent: #4fd07e;
  --accent-strong: #3cb96a;
  --accent-ink: #05230f;
  --danger: #f2716f;
  --danger-bg: rgba(242, 113, 111, .12);
  --warn: #f3bd4d;
  --warn-bg: rgba(243, 189, 77, .12);
  --info: #6aa8ff;
  --log-bg: #0a0c0f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #f7f8fa;
    --hover: #eef0f4;
    --border: #e1e4ea;
    --text: #1a1d24;
    --muted: #5f6878;
    --accent: #1f9d55;
    --accent-strong: #188447;
    --accent-ink: #ffffff;
    --danger: #d23f3c;
    --danger-bg: rgba(210, 63, 60, .09);
    --warn: #a86a00;
    --warn-bg: rgba(230, 160, 20, .14);
    --info: #2563eb;
    --log-bg: #11141a;
    --shadow: 0 10px 30px rgba(20, 30, 50, .12);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: inherit; }
code { font-family: var(--mono); font-size: .92em; background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 .35em; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- layout ---- */
.layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px; background: var(--panel); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 0 6px; }
.brand img { border-radius: 8px; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.server-pill {
  display: flex; align-items: center; gap: 8px; margin: 0 6px; padding: 7px 11px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel-2); font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
[data-state="active"] .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(79, 208, 126, .18); }
[data-state="activating"] .dot, [data-state="deactivating"] .dot, [data-state="busy"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }
[data-state="failed"] .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--hover); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.account { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; font-size: 12.5px; }
.main { padding: 26px clamp(16px, 3vw, 36px) 60px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

@media (max-width: 860px) {
  /* minmax(0, …): otherwise the scrollable nav's full width stretches the column */
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; height: auto; z-index: 5; flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 10px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); min-width: 0;
  }
  .brand small, .account .muted { display: none; }
  .server-pill { margin: 0; }
  .nav { order: 3; flex-direction: row; overflow-x: auto; width: 100%; gap: 4px; scrollbar-width: none; }
  .nav a { padding: 7px 10px; white-space: nowrap; }
  .nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .account { margin: 0 0 0 auto; flex-direction: row; padding: 0; }
  .main { padding-top: 18px; }
}

/* ---- cards & grids ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 28px; }
.subhead { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat { gap: 4px; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.stat-sub { color: var(--muted); font-size: 12.5px; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.columns > .stack { gap: 18px; }

/* ---- banners, badges ---- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-2);
}
.banner.warn { border-color: rgba(243, 189, 77, .45); background: var(--warn-bg); }
.banner.danger { border-color: rgba(242, 113, 111, .45); background: var(--danger-bg); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; border: 1px solid var(--border); color: var(--muted); background: var(--panel-2); white-space: nowrap;
}
.badge.green { color: var(--accent); border-color: rgba(79, 208, 126, .4); background: rgba(79, 208, 126, .1); }
.badge.yellow { color: var(--warn); border-color: rgba(243, 189, 77, .4); background: var(--warn-bg); }
.badge.red { color: var(--danger); border-color: rgba(242, 113, 111, .4); background: var(--danger-bg); }
.badge.blue { color: var(--info); border-color: rgba(106, 168, 255, .4); background: rgba(106, 168, 255, .1); }

/* ---- buttons & inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--hover); }
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-bg); }
.btn.ghost { background: transparent; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: var(--hover); }
.input {
  height: 36px; padding: 0 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font: inherit; min-width: 0; width: 100%;
}
select.input { padding-right: 28px; }
.input::placeholder { color: var(--muted); opacity: .8; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline .input { width: auto; min-width: 180px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .input { flex: 1 1 160px; width: auto; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; color: var(--muted); font-size: 13px; }
.check input, .radio input { accent-color: var(--accent); width: 16px; height: 16px; }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.slider { width: 36px; height: 20px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .slider { opacity: .5; }
.switch.big .switch-label { font-size: 18px; font-weight: 650; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 5px 12px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.on { background: var(--hover); color: var(--text); font-weight: 600; }

/* ---- rows (lists) ---- */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rows > li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--border); min-width: 0; }
.rows > li:first-child { border-top: 0; }
.rows.compact > li { padding: 7px 2px; }
.rows .empty { color: var(--muted); justify-content: center; padding: 18px 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.head { width: 28px; height: 28px; border-radius: 5px; image-rendering: pixelated; background: var(--panel-2); flex: none; }
.mod-icon { width: 38px; height: 38px; border-radius: 8px; background: var(--panel-2); object-fit: cover; flex: none; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.empty { text-align: center; color: var(--muted); padding: 22px; }
.table td:last-child { text-align: right; }
.table .nowrap { white-space: nowrap; }

/* ---- console ---- */
.console { padding: 0; gap: 0; overflow: hidden; }
.console-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.console-toolbar .input { flex: 1 1 200px; width: auto; }
.conn { margin-left: auto; font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.conn[data-state="open"]::before { background: var(--accent); }
.conn[data-state="closed"]::before { background: var(--danger); }
.log {
  height: min(64vh, 720px); overflow-y: auto; background: var(--log-bg); color: #cfd5df; padding: 12px 14px;
  font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.log .l-warn { color: #f3c969; }
.log .l-error { color: #ff8b88; }
.log .l-cmd { color: #7fe0a4; font-weight: 600; margin-top: 6px; }
.log .l-out { color: #e8ecf2; border-left: 2px solid #3b4252; padding-left: 10px; margin-bottom: 6px; }
.log .l-sys { color: #7f8aa0; font-style: italic; }
.log .l-hidden { display: none; }
.console-input { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.console-input .prompt { font-family: var(--mono); color: var(--accent); font-weight: 700; }

/* ---- settings ---- */
.settings-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 14px; }
.settings-form .full { grid-column: 1 / -1; }
.settings-form footer { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.rule-value { width: 110px; flex: none; }

/* ---- floating: toasts, job panel, dialog ---- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--panel); border: 1px solid var(--border);
  box-shadow: var(--shadow); border-left: 4px solid var(--accent); animation: rise .18s ease-out; white-space: pre-line;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.job-panel {
  position: fixed; right: 16px; bottom: 16px; width: min(460px, calc(100vw - 32px)); z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.job-panel header { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.job-panel .job-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-panel .job-status { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); animation: pulse 1.2s infinite; flex: none; }
.job-panel[data-status="done"] .job-status { background: var(--accent); animation: none; }
.job-panel[data-status="failed"] .job-status { background: var(--danger); animation: none; }
.job-lines { list-style: none; margin: 0; padding: 10px 14px; max-height: 240px; overflow-y: auto; font: 12.5px/1.6 var(--mono); color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.job-lines li:last-child { color: var(--text); }
.job-panel[data-status="failed"] .job-lines li:last-child { color: var(--danger); }
body:has(.job-panel:not([hidden])) .toasts { bottom: 300px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text);
  padding: 0; width: min(500px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 8, 12, .6); backdrop-filter: blur(2px); }
dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog h2 { font-size: 17px; }
.dialog-body { color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.dialog-body p { margin: 0; }
.dialog-fields { display: flex; flex-direction: column; gap: 12px; }
.dialog-fields:empty { display: none; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.radio:has(input:checked) { border-color: var(--accent); background: rgba(79, 208, 126, .06); }
.radio input { margin-top: 2px; }
.radio span { display: flex; flex-direction: column; }
.radio small { color: var(--muted); }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---- login ---- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.login-card img { border-radius: 10px; }
.login-card p { margin: -8px 0 4px; }
.login-card .stack { gap: 12px; }
