:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #646b78;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #c02626;
  --bad-soft: #fdecec;
  --term-bg: #0f1115;
  --term-text: #d7dbe2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .22);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --panel: #16191f;
    --panel-2: #1d2128;
    --border: #2a2f38;
    --text: #e8eaee;
    --muted: #949bab;
    --accent: #818cf8;
    --accent-soft: #23264a;
    --accent-text: #0e1014;
    --ok: #4ade80;
    --ok-soft: #12291b;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --bad: #f87171;
    --bad-soft: #301617;
    --term-bg: #0a0b0e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
svg.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: none; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 700;
}
.brand-name { font-weight: 650; line-height: 1.2; }
.brand-host { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a, .nav-foot a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover, .nav-foot a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a.unavailable { opacity: .5; }
.nav-foot { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-foot .ver { color: var(--muted); font-size: 12px; padding: 4px 10px; }

.main { flex: 1; min-width: 0; padding: 24px 32px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; flex: 1; min-width: 160px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topbar { display: none; }

/* Cards and grids */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 14px; margin: 0; font-weight: 600; flex: 1; }
.card-body { padding: 14px 16px; }
.card-body.flush { padding: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 24px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.attention { display: flex; flex-direction: column; gap: 8px; }
.attention a { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); padding: 8px 10px; border-radius: 8px; background: var(--panel-2); }
.attention a:hover { outline: 1px solid var(--border); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--panel-2) 55%, transparent); }
td.actions-cell { white-space: nowrap; text-align: right; }
td.actions-cell .btn + .btn { margin-left: 4px; }
td .desc { color: var(--muted); font-size: 12.5px; }
tr.group td { background: var(--panel-2); font-weight: 600; font-size: 12.5px; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); padding: 24px 16px; text-align: center; }
.clickable { cursor: pointer; }
.clickable:hover { color: var(--accent); }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; line-height: 1.4; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; border-radius: 6px; }
.btn .icon { width: 16px; height: 16px; }
.btn.icon-only { padding: 6px; }

input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { width: 100%; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 360px; line-height: 1.5; tab-size: 4; white-space: pre; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { flex: 1; min-width: 160px; max-width: 360px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: var(--panel); padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.run::before { animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-family: var(--mono); font-size: 12px; background: var(--panel-2); border-radius: 5px; padding: 0 6px; }

.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.banner > span { flex: 1; min-width: 200px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

pre.term {
  background: var(--term-bg); color: var(--term-text); border-radius: 8px; padding: 12px 14px; margin: 0;
  overflow: auto; max-height: 62vh; min-height: 120px; white-space: pre-wrap; word-break: break-word;
}
pre.plain { margin: 0; white-space: pre-wrap; word-break: break-word; background: var(--panel-2); border-radius: 8px; padding: 10px 12px; max-height: 340px; overflow: auto; }
details > summary { cursor: pointer; padding: 10px 16px; font-weight: 500; }
details[open] > summary { border-bottom: 1px solid var(--border); }
details + details { border-top: 1px solid var(--border); }
details > pre.plain { margin: 12px 16px; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.dialog { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; }
.dialog.wide { max-width: 980px; }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h3 { margin: 0; font-size: 16px; flex: 1; overflow-wrap: anywhere; }
.dialog-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-weight: 500; font-size: 13px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.field input, .field select { width: 100%; }
.form-error { color: var(--bad); white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow-lg); white-space: pre-wrap; overflow-wrap: anywhere; }
.toast.error { border-left-color: var(--bad); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px; }
.login .brand { padding: 0 0 4px; }
.login .btn { justify-content: center; padding: 9px; }
.login input { width: 100%; }

.loading { color: var(--muted); padding: 32px 0; text-align: center; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* Phone and tablet */
@media (max-width: 860px) {
  .shell { display: block; }
  .topbar {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
  }
  .topbar .brand { padding: 0; flex: 1; min-width: 0; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { padding: 16px 16px 40px; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: 19px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 20px; }
  .hide-sm { display: none; }
  th, td { padding: 8px 10px; }
}
