:root {
  color-scheme: light;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-raised: #eff2f5;
  --line: #d1d9e0;
  --line-soft: #e3e8ee;
  --text: #1f2328;
  --text-strong: #1f2328;
  --muted: #59636e;
  --blue: #0969da;
  --green: #1a7f37;
  --orange: #9a6700;
  --red: #d1242f;
  --red-strong: #d1242f;
  --inset-bg: #f6f8fa;
  --hover-line: #8d96a0;
  --on-accent: #ffffff;
  --terminal-bg: #090b0d;
  --terminal-line: #30363d;
  --terminal-text: #c9d1d9;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111315;
    --surface: #191c1f;
    --surface-raised: #22262a;
    --line: #30363d;
    --line-soft: #292e33;
    --text: #f0f3f6;
    --text-strong: #c9d1d9;
    --muted: #8b949e;
    --blue: #58a6ff;
    --green: #3fb950;
    --orange: #d29922;
    --red: #f85149;
    --red-strong: #ff7b72;
    --inset-bg: #0d1117;
    --hover-line: #6e7681;
    --on-accent: #08111c;
    --terminal-bg: #090b0d;
    --terminal-line: #30363d;
    --terminal-text: #c9d1d9;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, sans-serif; }
button, input, select, textarea { font: inherit; }
button { border: 1px solid var(--line); border-radius: 6px; background: var(--surface-raised); color: var(--text); padding: 6px 12px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--hover-line); background: var(--line-soft); }
button:disabled { opacity: .45; cursor: default; }
button.danger:hover:not(:disabled), button.danger:focus { border-color: var(--red); color: var(--red-strong); }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--inset-bg); color: var(--text); padding: 7px 9px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--blue) 32%, transparent); border-color: var(--blue); }
code, .terminal, .json { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar { display: flex; min-height: 56px; align-items: center; gap: 18px; padding: 9px 20px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--blue); color: var(--on-accent); font-weight: 900; }
.topbar nav { display: flex; gap: 14px; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); }
.server-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.server-title strong { white-space: nowrap; }
.meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { margin-left: auto; display: flex; gap: 7px; }
.accountmenu { position: relative; }
.accountmenu summary {
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: 150px;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1;
  cursor: pointer;
  list-style: none;
}
.accountmenu summary::-webkit-details-marker { display: none; }
.accountmenu summary:hover { color: var(--text); background: var(--surface-raised); }
.accountmenu summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.accountname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accountchevron { font-size: 11px; transition: transform .12s ease; }
.accountmenu[open] .accountchevron { transform: rotate(180deg); }
.accountpanel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 7px);
  right: 0;
  min-width: 150px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .24);
}
.accountform { margin: 0; }
.accountform button { width: 100%; border: 0; padding: 6px 8px; text-align: left; background: transparent; }
.accountform button:hover { background: var(--surface-raised); }
.accountform button:focus-visible { outline: 2px solid var(--blue); outline-offset: -1px; }
.badge { padding: 2px 9px; border-radius: 999px; background: var(--surface-raised); color: var(--muted); font-size: 12px; font-weight: 650; }
.badge.running { color: var(--green); background: color-mix(in srgb, var(--green) 13%, transparent); }
.badge.building, .badge.stopping { color: var(--orange); background: color-mix(in srgb, var(--orange) 13%, transparent); }
.badge.failed { color: var(--red-strong); background: color-mix(in srgb, var(--red) 13%, transparent); }

main { max-width: 1500px; margin: 0 auto; padding: 0 22px 48px; }
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 14px 3px 11px; color: var(--muted); }
.tab:hover:not(:disabled) { background: transparent; color: var(--text); border-color: var(--hover-line); }
.tab.active { color: var(--text); border-color: var(--orange); }
.panel { display: none; }
.panel.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; min-width: 0; }
.card.grow { flex: 1; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card h3 { color: var(--text-strong); font-size: 13px; margin: 0 0 9px; }
.card h4 { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin: 0 0 5px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2, .card-head h3, .card-head p { margin-top: 0; margin-bottom: 4px; }
.split { display: flex; gap: 14px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.tile .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.health { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 8px; }
.health div, .profile-facts div { border-left: 2px solid var(--line); padding-left: 9px; }
.health span, .profile-facts span { display: block; color: var(--muted); font-size: 11px; }
.health strong, .profile-facts strong { display: block; margin-top: 2px; font-weight: 600; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(320px, 1fr)); gap: 14px; margin-bottom: 14px; }
.chart-card { margin: 0; padding: 12px 14px; }
.chart-card figcaption { color: var(--text-strong); font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.chart { height: 150px; position: relative; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-cursor { stroke: var(--text-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-label, .chart-empty { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; color: var(--text-strong); font-size: 11px; }
.legend .swatch, .tooltip .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: baseline; }
.legend .val { color: var(--text); font-variant-numeric: tabular-nums; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 18px; margin: 0; min-width: 280px; }
dt { color: var(--muted); } dd { margin: 0; text-align: right; }
.muted { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.error { color: var(--red-strong); }

.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .055em; white-space: nowrap; }
td { font-size: 12px; max-width: 340px; overflow-wrap: anywhere; }
td.num { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 5px; white-space: nowrap; }
.row-actions button { padding: 4px 7px; font-size: 11px; }

.terminal { background: var(--terminal-bg); border: 1px solid var(--terminal-line); border-radius: 6px; color: var(--terminal-text); padding: 11px 13px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
#log { height: 350px; margin: 0; }
.incident-row { cursor: pointer; }
.incident-row:hover td { background: var(--surface-raised); }
#incident-log { max-height: 520px; margin: 12px 0 0; }
.console-card { max-width: 1200px; margin-left: auto; margin-right: auto; }
.console-output { height: 520px; margin: 12px 0 8px; }
.command-line { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; color: var(--green); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.command-line input { font-family: inherit; }

.database-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 14px; align-items: start; }
.profiles-card { position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.search { display: flex; gap: 7px; margin-bottom: 10px; }
.profile-results { overflow: auto; }
.profile-row { display: grid; width: 100%; gap: 3px; text-align: left; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0; background: transparent; padding: 10px 7px; }
.profile-row:hover, .profile-row.selected { background: var(--surface-raised); }
.profile-row > span:first-child { display: flex; justify-content: space-between; gap: 8px; }
.profile-row code { color: var(--muted); font-size: 10px; }
.profile-row > span:nth-child(2) { color: var(--text-strong); font-size: 11px; }
.moderation-tags { min-height: 1em; color: var(--red-strong); font-size: 10px; text-transform: uppercase; }
.profile-detail code { color: var(--muted); font-size: 11px; }
.profile-facts { display: grid; grid-template-columns: repeat(5, minmax(100px, 1fr)); gap: 8px; margin: 15px 0; }
.detail-section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: 150px 150px minmax(220px, 1fr) auto; gap: 9px; align-items: end; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.owned-grid { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips span { padding: 2px 7px; border-radius: 999px; background: var(--surface-raised); color: var(--text-strong); font-size: 11px; }
.moderation-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.moderation-row > div { display: grid; gap: 2px; }
.moderation-row strong { text-transform: uppercase; color: var(--red-strong); font-size: 10px; }
.moderation-row small { color: var(--muted); }
.json { max-height: 320px; overflow: auto; background: var(--terminal-bg); border-radius: 6px; padding: 10px; color: var(--terminal-text); }

dialog { width: min(500px, calc(100vw - 32px)); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 18px; box-shadow: 0 24px 80px rgba(0, 0, 0, .65); }
dialog::backdrop { background: rgba(0, 0, 0, .72); }
dialog form { display: grid; gap: 13px; }
dialog textarea { min-height: 90px; resize: vertical; }
.quiet { border: 0; background: transparent; color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 430px; padding: 10px 14px; border: 1px solid var(--green); border-radius: 7px; background: var(--surface-raised); box-shadow: 0 8px 30px rgba(0, 0, 0, .45); }
.toast.failed { border-color: var(--red); color: var(--red-strong); }
.tooltip { position: fixed; pointer-events: none; z-index: 40; min-width: 150px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-raised); color: var(--text); box-shadow: 0 4px 16px rgba(0, 0, 0, .4); font-size: 12px; font-variant-numeric: tabular-nums; }
.tooltip .row { display: flex; gap: 12px; justify-content: space-between; }
.tooltip .t { color: var(--muted); }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .health { grid-template-columns: repeat(3, 1fr); }
  .database-layout { grid-template-columns: 1fr; }
  .profiles-card { position: static; max-height: 430px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .owned-grid { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
  .meta, .topbar nav { display: none; }
}

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; padding: 9px 12px; gap: 9px; }
  .server-title { order: 3; width: 100%; }
  main { padding: 0 12px 30px; }
  .tabs { overflow-x: auto; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .health, .profile-facts, .owned-grid { grid-template-columns: 1fr 1fr; }
  .split { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .actions { gap: 4px; }
  .actions button { padding: 5px 8px; }
}
