:root {
  --bg: #0f1216; --card: #171b21; --line: #262c35; --fg: #e6e9ee;
  --muted: #8b95a5; --accent: #4da3ff; --ok: #2ea043; --warn: #d29922;
  --bad: #f85149; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: light) {
  :root { --bg:#f5f7fa; --card:#fff; --line:#dfe4ec; --fg:#1b2027; --muted:#6b7688; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
body.busy { cursor: progress; }
body.busy button { opacity: .55; pointer-events: none; }

header { padding: 1.6rem 1.5rem .6rem; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
h1 span { color: var(--accent); }
.tag { margin: .25rem 0 0; color: var(--muted); }

main { padding: 1rem 1.5rem 3rem; max-width: 1240px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}
h2 { margin: 0 0 .9rem; font-size: 1.05rem; display: flex; align-items: center; gap: .55rem; }
h3 { margin: 0 0 .5rem; font-size: .8rem; text-transform: uppercase;
     letter-spacing: .06em; color: var(--muted); }
.step {
  display: grid; place-items: center; width: 1.5rem; height: 1.5rem;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: .8rem;
}

button {
  font: inherit; font-size: .88rem; padding: .45rem .85rem; border-radius: 8px;
  border: 1px solid var(--line); background: #222834; color: var(--fg); cursor: pointer;
}
@media (prefers-color-scheme: light) { button { background: #eef1f6; } }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger:hover { border-color: var(--bad); color: var(--bad); }

input, textarea, select {
  font: inherit; font-size: .88rem; padding: .45rem .6rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); width: 100%;
}
textarea { font-family: var(--mono); font-size: .82rem; resize: vertical; }
label { display: block; font-size: .8rem; color: var(--muted); }
label input, label textarea { margin-top: .25rem; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-top: .8rem; }
.grid .wide, .grid button { grid-column: 1 / -1; }
.findbar { display: flex; gap: .5rem; flex-wrap: wrap; }
.findbar select { width: auto; min-width: 12rem; }
.findbar input { flex: 1; min-width: 14rem; }
.findbar button { white-space: nowrap; }

.group { padding: .8rem 0; border-top: 1px solid var(--line); display: flex;
         flex-wrap: wrap; gap: .5rem; align-items: center; }
.group h3 { width: 100%; }
.inline { display: flex; gap: .4rem; align-items: center; }
.inline.wide { width: 100%; }
.inline.wide input { flex: 1; }

.nodes { display: grid; gap: .5rem; }
.node { display: flex; justify-content: space-between; align-items: center; gap: .5rem;
        padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 9px; }
.node > div { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }

.pill { font-size: .72rem; padding: .12rem .5rem; border-radius: 999px;
        border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.pill.dim { opacity: .6; }

.hit { border: 1px solid var(--ok); border-radius: 10px; padding: .9rem; margin-top: .9rem; }
.miss { border: 1px solid var(--bad); color: var(--bad); border-radius: 10px;
        padding: .8rem; margin-top: .9rem; }
.hitline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.big { font-size: 1.15rem; font-weight: 650; font-family: var(--mono); }
dl { display: grid; grid-template-columns: 7.5rem 1fr; gap: .25rem .8rem; margin: 0 0 .7rem; font-size: .85rem; }
dt { color: var(--muted); }
dd { margin: 0; font-family: var(--mono); word-break: break-all; }
.ports { display: flex; gap: .35rem; flex-wrap: wrap; }
.hint { margin: .7rem 0 0; padding: .55rem .7rem; border-radius: 8px;
        background: rgba(210,153,34,.12); border: 1px solid var(--warn); font-size: .85rem; }

.tablewrap { overflow-x: auto; margin-top: .9rem; border: 1px solid var(--line); border-radius: 10px; }
table.vms { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.vms th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: .55rem .7rem;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.vms td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.vms tbody tr:last-child td { border-bottom: 0; }
table.vms tbody tr:hover { background: rgba(77,163,255,.07); }
table.vms .mono { font-family: var(--mono); }
table.vms .small { font-size: .78rem; }
a.ipsel { color: var(--accent); text-decoration: none; font-family: var(--mono); border-bottom: 1px dotted currentColor; }
a.ipsel:hover { border-bottom-style: solid; }
p.small { font-size: .8rem; }

pre#out {
  font-family: var(--mono); font-size: .8rem; line-height: 1.45; margin: 0;
  white-space: pre-wrap; word-break: break-word; max-height: 30rem; overflow: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: .8rem;
}
details summary { cursor: pointer; color: var(--accent); font-size: .88rem; }
details[open] summary { margin-bottom: .5rem; }
code { font-family: var(--mono); }
@media (max-width: 620px) { .grid { grid-template-columns: 1fr; } }

table.vms .nowrap { white-space: nowrap; }

/* ---- header actions ---- */
.headrow { display: flex; justify-content: space-between; align-items: flex-start;
           gap: 1rem; flex-wrap: wrap; max-width: 1240px; }
.headbtns { display: flex; gap: .5rem; }

/* ---- login ---- */
body.loginpage { display: grid; place-items: center; min-height: 100vh; }
.loginwrap { width: 100%; max-width: 26rem; padding: 1.5rem; }
.logincard h1 { font-size: 1.5rem; margin-bottom: .3rem; }
.logincard form { display: grid; gap: .7rem; margin-top: 1rem; }
.logincard label { font-size: .82rem; }
button.wide { width: 100%; }
.loginerr { margin: .8rem 0 0; color: var(--bad); font-size: .85rem; }
.foot { margin: 1.1rem 0 0; font-size: .75rem; }

/* ---- settings dialog ---- */
dialog#settingsDlg {
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  color: var(--fg); max-width: 34rem; width: calc(100% - 2rem); padding: 1.25rem;
}
dialog#settingsDlg::backdrop { background: rgba(0,0,0,.55); }
dialog#settingsDlg h3 { margin-top: 1.2rem; }
dialog#settingsDlg form[method="dialog"] { float: right; }
button.close { border: 0; background: transparent; font-size: 1rem; }
label.chk, label.wide input[type="checkbox"] { display: inline; width: auto; margin-right: .4rem; }

/* ---- ask AI ---- */
.ailog { display: grid; gap: .5rem; max-height: 26rem; overflow-y: auto; margin-bottom: .7rem; }
.ailog:empty { display: none; }
.bub { padding: .55rem .8rem; border-radius: 10px; font-size: .87rem;
       white-space: pre-wrap; word-break: break-word; max-width: 90%; }
.bub.me { background: var(--accent); color: #fff; justify-self: end; }
.bub.ai { background: var(--bg); border: 1px solid var(--line); justify-self: start; }
.bub.pending { opacity: .6; font-style: italic; }
.bub.err { border-color: var(--bad); color: var(--bad); }
.bub.note { border: 0; color: var(--muted); font-size: .78rem; padding: .1rem .3rem; }
.airow { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.airow .spacer { flex: 1; }
.airow .chk { font-size: .8rem; color: var(--muted); }

/* ---- shared bits ---- */
.spacer { flex: 1; }
button.mini { padding: .15rem .5rem; font-size: .78rem; }
h2 button { font-weight: 400; }
label.chk input { width: auto; }
fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.bare:disabled { opacity: .55; }

/* ---- fleet dashboard ---- */
.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .6rem; }
.fleet > p { margin: 0; }
.tile {
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: .7rem .8rem; cursor: pointer; display: flex; flex-direction: column; gap: .45rem;
}
.tile:hover { border-color: var(--accent); }
.tile.err { border-color: var(--bad); cursor: default; }
.tilehead { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.tilehead strong { font-size: .95rem; }
.tilehead .tilehost { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
                      white-space: nowrap; font-family: var(--mono); font-size: .75rem; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.tilestats { display: grid; grid-template-columns: 1fr 1fr; gap: .15rem .8rem; font-size: .82rem; }
.tilestats .muted { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
.tilestats b { font-family: var(--mono); font-weight: 600; }
.tilestats .hot { color: var(--bad); }
.tilefoot { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; font-size: .78rem; }
.tileerr { color: var(--bad); font-size: .8rem; word-break: break-word; }

/* ---- dialogs (create VM / node defaults) ---- */
dialog#createDlg, dialog#nodeDlg {
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  color: var(--fg); width: calc(100% - 2rem); padding: 1.25rem;
}
dialog#createDlg { max-width: 44rem; }
dialog#nodeDlg { max-width: 34rem; }
dialog#createDlg::backdrop, dialog#nodeDlg::backdrop { background: rgba(0,0,0,.55); }
dialog#createDlg form[method="dialog"], dialog#nodeDlg form[method="dialog"] { float: right; }
dialog h2 code { font-size: .95em; }

/* ---- create VM wizard ---- */
.ipmode { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.ipmode .ipmodelab { font-size: .8rem; color: var(--muted); }
.ipmode .chk { font-size: .85rem; }
.manualip { flex-wrap: wrap; }
.manualip input { flex: 1; min-width: 9rem; }
.manualip input[type="number"] { flex: none; width: 7.5rem; min-width: 0; }
.manualip button { flex: none; }
.verdict { font-size: .85rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
label .inline { margin-top: .25rem; }
.inline input { min-width: 0; }
#cPass { flex: 1; }
.createbtns { margin-top: .9rem; width: 100%; }
.checks { margin-top: .8rem; display: grid; gap: .3rem; font-size: .83rem; }
.checks.stale { opacity: .45; }
.checkrow { display: flex; gap: .5rem; align-items: baseline; }
.checkrow .pill { flex: none; }
.checkrow b { font-family: var(--mono); font-weight: 600; }
.checkrow .detail { color: var(--muted); font-family: var(--mono); font-size: .78rem;
                    word-break: break-word; }
pre.steps {
  font-family: var(--mono); font-size: .78rem; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem; margin: .4rem 0 0;
}
#cResult .miss { margin-top: .8rem; }
#cResult .hit { margin-top: .8rem; }

/* ---- danger zone ---- */
.dangerzone h3 { color: var(--bad); }
.delrow { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; width: 100%; }
.delrow input[type="text"], .delrow > input:first-child { flex: 1; min-width: 12rem; }
.delrow .chk { font-size: .8rem; color: var(--muted); white-space: nowrap; }
button.dangerfill { background: var(--bad); border-color: var(--bad); color: #fff; }
button.dangerfill:hover { border-color: var(--bad); color: #fff; opacity: .9; }
button.dangerfill:disabled { opacity: .4; cursor: not-allowed; }

/* ---- API keys / audit (settings) ---- */
.keylist { display: grid; gap: .4rem; margin: .4rem 0 .6rem; }
.keyrow { display: flex; align-items: center; gap: .6rem; font-size: .83rem; flex-wrap: wrap; }
.keynew {
  margin-top: .6rem; padding: .6rem .7rem; border: 1px solid var(--warn);
  border-radius: 8px; font-size: .83rem;
}
.keynew code {
  user-select: all; word-break: break-all; background: var(--bg);
  padding: .15rem .35rem; border-radius: 6px; display: inline-block; margin: .3rem .3rem .3rem 0;
}
.auditlist {
  font-family: var(--mono); font-size: .74rem; line-height: 1.5; max-height: 16rem;
  overflow: auto; border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .6rem; margin-top: .5rem; white-space: pre-wrap; word-break: break-word;
}

/* ---- console page ---- */
body.consolepage { display: flex; flex-direction: column; height: 100vh; background: #000; }
.conbar {
  display: flex; align-items: center; gap: .6rem; padding: .45rem .8rem;
  background: var(--card); border-bottom: 1px solid var(--line); flex: none;
}
.conbar strong { font-family: var(--mono); font-size: .95rem; }
#screen { flex: 1; min-height: 0; background: #000; }
.conmsg {
  position: fixed; top: 4rem; left: 50%; transform: translateX(-50%);
  max-width: 34rem; width: calc(100% - 2rem); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem;
  font-size: .9rem; white-space: pre-wrap; word-break: break-word; color: var(--fg);
}
