:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c2230; --border: #2a3242;
  --text: #e6edf3; --muted: #8b96a8; --accent: #4f8cff; --accent2: #3a6fd8;
  --green: #3fb950; --yellow: #d29922; --red: #f85149; --grey: #6e7681;
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1em; margin: 6px 0 0; white-space: pre-wrap; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h3 { margin: 0 0 12px; font-size: 15px; }

/* brand */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #4f8cff, #8a5cff); display: inline-block; }
.host { font-weight: 400; font-size: 12px; font-family: var(--mono); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-card p { margin: 0; }

/* layout: fixed left sidebar (off-canvas on small screens) + main column */
:root { --side: 232px; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side); z-index: 20; display: flex; flex-direction: column;
  gap: 4px; padding: 16px 12px; background: var(--panel); border-right: 1px solid var(--border);
  transition: transform .2s ease; }
.side-host { padding: 0 4px 14px 35px; margin-top: -2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.side-foot { margin-top: auto; }
.side-foot .btn { width: 100%; text-align: left; }
.tab { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0;
  color: var(--muted); padding: 9px 12px; border-radius: 8px; cursor: pointer; font: inherit; }
.tab .ico { width: 16px; text-align: center; opacity: .8; }
.tab:hover { color: var(--text); background: var(--panel2); }
.tab.active { color: var(--text); background: #243049; }
.count { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.main { margin-left: var(--side); min-width: 0; transition: margin .2s ease; }
body.side-collapsed .sidebar { transform: translateX(-100%); }
body.side-collapsed .main { margin-left: 0; }
.scrim { display: none; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 22px; background: rgba(13,17,23,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 0; font-size: 16px; font-weight: 600; }
.burger { font-size: 18px; line-height: 1; padding: 6px 10px; }
.topbar-right { margin-left: auto; display: flex; gap: 6px; }
.tab-panel { padding: 22px; max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h3 { margin: 0; flex: 1; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.settings fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0;
  display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.settings legend { color: var(--text); font-weight: 600; padding: 0 6px; }
.settings > p, .settings > .dialog-actions { grid-column: 1 / -1; margin: 0; }
.alert-row { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.alert-row:last-child { border-bottom: 0; }
.alert-row .when { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
details.cves summary { cursor: pointer; color: var(--accent); }
details.cves ul { margin: 6px 0 0; padding-left: 18px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bar { height: 6px; background: var(--panel2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.warn > span { background: var(--yellow); }
.bar.bad > span { background: var(--red); }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar p { margin: 0; }
.spacer { flex: 1; }
.inline { display: flex; gap: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv .k { color: var(--muted); }

/* controls */
input, select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font: inherit; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
input[type=search] { width: 280px; }
#pull-image { width: 320px; }
label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3d4759; background: #222a3a; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: #ffb4ae; }
.btn.danger:hover { background: #3a1d1f; border-color: #6e2b2b; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #1a2029; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.name { font-weight: 600; }
.small { font-size: 12px; }
.stack { margin-bottom: 4px; }
.stack-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.stack-head .title { font-weight: 650; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--panel2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--grey); }
.badge.plain::before { display: none; }
.badge.green { color: #8fe3a0; } .badge.green::before { background: var(--green); }
.badge.yellow { color: #f0c46a; } .badge.yellow::before { background: var(--yellow); }
.badge.red { color: #ffb4ae; } .badge.red::before { background: var(--red); }
.port { font-family: var(--mono); font-size: 12px; background: var(--panel2); padding: 1px 6px; border-radius: 4px; margin-right: 4px; display: inline-block; }
.port.public { color: #f0c46a; }

/* vhost cards */
.vhosts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.vhost .top { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.vhost .domain { font-size: 15px; font-weight: 650; }
.vhost .meta { margin: 12px 0; }
.vhost .actions { justify-content: flex-start; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  padding: 0; width: min(520px, 94vw); }
dialog.wide { width: min(1100px, 96vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-head { display: flex; align-items: center; gap: 10px; }
.dialog-head h3 { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-tools { display: flex; gap: 6px; align-items: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.domain-input { display: flex; gap: 6px; }
.domain-input input { flex: 1; }
pre.code { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font: 12px/1.5 var(--mono); max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* terminal + config editor */
.term-box { height: 72vh; background: #0d1117; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.term-box .xterm { height: 100%; }
#term-dialog { width: min(1300px, 97vw); }
textarea.code-edit { width: 100%; height: 62vh; resize: vertical; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px; font: 12.5px/1.55 var(--mono); tab-size: 4; white-space: pre; }
textarea.code-edit:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }

/* toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--panel2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 24px rgba(0,0,0,.4); white-space: pre-wrap; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---- responsive ---- */
@media (max-width: 900px) {
  /* sidebar becomes an overlay drawer, closed by default */
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .main, body.side-collapsed .main { margin-left: 0; }
  body.side-open .sidebar { transform: none; }
  body.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.5); }
  .grid.two { grid-template-columns: 1fr; }
  .vhosts { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .topbar { padding: 8px 12px; }
  .tab-panel { padding: 12px; gap: 12px; }
  .grid.stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 19px; }
  .card { padding: 12px; }
  .toolbar > *, .toolbar input[type=search], #pull-image, .inline { width: 100%; }
  .inline input { flex: 1; min-width: 0; }
  .toolbar .spacer { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv .k { margin-top: 6px; font-size: 12px; }
  .table .hide-sm { display: none; }
  /* tables turn into stacked cards: one row = one block */
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr:first-child:has(th) { display: none; }
  .table tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .table td { padding: 3px 0; border: 0; }
  .table tr:hover td { background: none; }
  .actions { justify-content: flex-start; margin-top: 6px; }
  .stack-head { flex-wrap: wrap; }
  .stack-head .actions { width: 100%; }
  .vhost .top { flex-wrap: wrap; }
  .domain-input { flex-direction: column; }
  .row { grid-template-columns: 1fr; }
  dialog, dialog.wide, #term-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    margin: 0; border-radius: 0; border: 0; }
  .dialog-body { padding: 14px; height: 100%; }
  .term-box { height: calc(100dvh - 90px); }
  textarea.code-edit { height: calc(100dvh - 260px); }
  pre.code { max-height: calc(100dvh - 90px); }
  .dialog-head { flex-wrap: wrap; }
  #toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  input[type=search] { width: 100%; }
  .alert-row { flex-wrap: wrap; }
  .alert-row > span:nth-child(2) { flex: 1 1 60%; }
  .alert-row .when { margin-left: 0; flex-basis: 100%; }
}
