/* Nexo — lightweight admin console styles. No framework, no build step. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2330;
  --muted: #5f6b7c;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #15803d;      --ok-bg: #dcfce7;
  --warn: #a16207;    --warn-bg: #fef3c7;
  --err: #b91c1c;     --err-bg: #fee2e2;
  --info: #1d4ed8;    --info-bg: #dbeafe;
  --muted-bg: #e8ebf0;
  --code-bg: #0f1520;
  --code-text: #d5dbe5;
  --sidebar: #111827;
  --sidebar-text: #c4cad4;
  --sidebar-active: #1f2937;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b24;
    --surface-2: #1b2330;
    --border: #2a3342;
    --text: #e3e8ef;
    --muted: #8d98a8;
    --accent: #3b82f6;
    --ok: #4ade80;      --ok-bg: #12301f;
    --warn: #fbbf24;    --warn-bg: #3a2c0a;
    --err: #f87171;     --err-bg: #3b1515;
    --info: #60a5fa;    --info-bg: #13274a;
    --muted-bg: #252d3a;
    --code-bg: #0a0e14;
    --sidebar: #0a0e14;
    --sidebar-active: #1b2330;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, #3b82f6, #06b6d4); display: grid; place-items: center; font-size: 14px; color: #fff; }
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.nav a {
  color: var(--sidebar-text); padding: 8px 12px; border-radius: 6px;
  display: flex; align-items: center; gap: 10px; font-weight: 500;
}
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .ico { width: 16px; text-align: center; opacity: .8; }
.sidebar-foot { padding: 12px 18px 18px; border-top: 1px solid #1f2937; font-size: 12px; }
.sidebar-foot form { margin-top: 8px; }
.sidebar-foot button { width: 100%; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar .crumbs { color: var(--muted); font-size: 13px; }
.content { padding: 24px 28px 48px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush > .card-head { padding: 14px 18px 0; }
.grid { display: grid; gap: 16px; margin-bottom: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; }
progress.meter { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 6px; border: none; border-radius: 3px; overflow: hidden; margin-top: 8px; background: var(--muted-bg); color: var(--accent); }
progress.meter::-webkit-progress-bar { background: var(--muted-bg); }
progress.meter::-webkit-progress-value { background: var(--accent); }
progress.meter::-moz-progress-bar { background: var(--accent); }
progress.meter.warn::-webkit-progress-value { background: var(--warn); }
progress.meter.warn::-moz-progress-bar { background: var(--warn); }
progress.meter.err::-webkit-progress-value { background: var(--err); }
progress.meter.err::-moz-progress-bar { background: var(--err); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.port-list { display: flex; flex-direction: column; gap: 2px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--muted-bg); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--info); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 12px; }

/* ---------- buttons & forms ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; line-height: 1.4;
}
.btn:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); }
.btn.danger, button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn.danger.solid, button.danger.solid { background: var(--err); color: #fff; border-color: var(--err); }
.btn.sm, button.sm { padding: 2px 9px; font-size: 12.5px; }
button:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.sidebar-foot button { background: transparent; color: var(--sidebar-text); border-color: #374151; }
.sidebar-foot button:hover { background: var(--sidebar-active); color: #fff; }

input[type=text], input[type=password], input[type=search], input[type=date], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-weight: 500; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented a { padding: 5px 12px; color: var(--text); border-right: 1px solid var(--border); background: var(--surface); }
.segmented a:last-child { border-right: none; }
.segmented a.active { background: var(--accent); color: #fff; }
.segmented a:hover { text-decoration: none; }
.check { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; cursor: pointer; user-select: none; }

/* ---------- alerts ---------- */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert pre { margin: 8px 0 0; white-space: pre-wrap; color: inherit; }

/* ---------- code / logs ---------- */
pre.code, .logview, textarea.editor {
  background: var(--code-bg); color: var(--code-text);
  border-radius: var(--radius); padding: 14px 16px; margin: 0;
  overflow: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
}
pre.code { max-height: 70vh; tab-size: 4; }
pre.code.numbered { counter-reset: ln; padding-left: 0; }
pre.code.numbered .ln { display: block; padding-left: 56px; position: relative; min-height: 1.55em; }
pre.code.numbered .ln::before { counter-increment: ln; content: counter(ln); position: absolute; left: 0; width: 42px; text-align: right; color: #5c6779; }
.hl-c { color: #6b7a90; font-style: italic; }
.hl-d { color: #7cc4ff; }
.hl-s { color: #a5d6a7; }
.hl-v { color: #f0b37e; }
.hl-p { color: #c792ea; }
textarea.editor { width: 100%; min-height: 60vh; resize: vertical; border: 1px solid var(--border); white-space: pre; tab-size: 4; }

.logview { height: 68vh; white-space: pre-wrap; word-break: break-all; }
.logview .line { display: block; }
.logview .ts { color: #6b7a90; margin-right: 8px; }
.logview.no-ts .ts { display: none; }
.logview mark { background: #854d0e; color: #fff; border-radius: 2px; }
.logview .sys { color: #fbbf24; font-style: italic; }
.logstatus { font-size: 12px; }

.diff { background: var(--code-bg); color: var(--code-text); border-radius: var(--radius); padding: 10px 0; overflow: auto; max-height: 50vh; font-family: var(--mono); font-size: 12.5px; margin: 0 0 14px; }
.diff div { padding: 0 14px; white-space: pre; }
.diff .add { background: rgba(34, 197, 94, .18); color: #bbf7d0; }
.diff .del { background: rgba(239, 68, 68, .18); color: #fecaca; }
.diff .hunk { color: #93c5fd; }
.diff .hdr { color: #94a3b8; }

/* ---------- tree ---------- */
.explorer { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.tree { font-family: var(--mono); font-size: 12.5px; max-height: 78vh; overflow: auto; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; border-left: 1px dashed var(--border); }
.tree > ul { padding-left: 0; border-left: none; }
.tree li { padding: 1px 0; }
.tree details > summary { cursor: pointer; list-style: none; padding: 2px 4px; border-radius: 4px; }
.tree details > summary::-webkit-details-marker { display: none; }
.tree details > summary::before { content: "▸ "; color: var(--muted); }
.tree details[open] > summary::before { content: "▾ "; }
.tree a, .tree .nolink { display: block; padding: 2px 6px; border-radius: 4px; color: var(--text); white-space: nowrap; }
.tree .nolink { color: var(--muted); }
.tree a.selected { background: var(--accent); color: #fff; }
.tree a:hover { background: var(--surface-2); text-decoration: none; }
.tree a.selected:hover { background: var(--accent); }
.tree .link { color: var(--muted); font-size: 11px; }

/* ---------- network topology ---------- */
.topology { font-family: var(--mono); font-size: 13px; line-height: 1.7; }
.topology .node { margin-left: 18px; position: relative; padding-left: 18px; }
.topology .node::before { content: "├─"; position: absolute; left: 0; color: var(--muted); }
.topology .node:last-child::before { content: "└─"; }
.flow { font-family: var(--mono); font-size: 12.5px; line-height: 1.8; }
.flow .step { padding-left: 20px; position: relative; }
.flow .step::before { content: "↳"; position: absolute; left: 4px; color: var(--muted); }

/* ---------- dialog ---------- */
dialog.confirm {
  border: 1px solid var(--border); border-radius: 10px; padding: 22px 22px 18px;
  background: var(--surface); color: var(--text); width: min(420px, 92vw);
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
dialog.confirm::backdrop { background: rgba(10, 14, 20, .55); }
dialog.confirm p { margin: 0 0 18px; font-size: 15px; }
dialog.confirm .buttons { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login-card .brand { color: var(--text); padding: 0 0 18px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 6px; padding: 9px; }

/* ---------- htmx ---------- */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .explorer { grid-template-columns: 1fr; }
  .tree { max-height: 40vh; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding: 12px 14px; }
  .nav { flex-direction: row; overflow-x: auto; padding: 0 8px 8px; flex-basis: 100%; order: 3; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .sidebar-foot { border: none; padding: 8px 14px; margin-left: auto; display: flex; gap: 10px; align-items: center; }
  .sidebar-foot form { margin: 0; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  dl.kv { grid-template-columns: 1fr; gap: 0 0; }
  dl.kv dd { margin-bottom: 8px; }
}
.mt { margin-top: 18px; }
