:root {
  --bg: #f6f7f9; --fg: #1b1f24; --muted: #5f6b7a; --card: #fff; --line: #dde2e8;
  --accent: #2563eb; --accent-fg: #fff; --danger: #c62828; --ok: #1b7f3b; --warn: #a15c00;
  --code: #f0f2f5; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --fg: #e6e9ee; --muted: #93a0b0; --card: #1a1f25; --line: #2c333c;
    --accent: #4f8cff; --danger: #ef5350; --ok: #4caf50; --warn: #f0a030; --code: #20262e;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--fg); }
h1, h2, h3 { margin: 0 0 .6em; }
h2 { font-size: 1.15em; }
h3 { font-size: 1em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, code, pre { font-family: var(--mono); font-size: 12.5px; }
.error { color: var(--danger); white-space: pre-wrap; overflow-wrap: anywhere; }

button {
  font: inherit; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--fg); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link { border: 0; background: none; color: inherit; text-decoration: underline; }
input, select, textarea {
  font: inherit; width: 100%; padding: 6px 8px; margin-top: 4px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg); color: var(--fg);
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
label { display: block; margin-bottom: 12px; }
label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }

.login { display: grid; place-items: center; min-height: 100vh; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: min(420px, 92vw); }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; }
.tabs button[aria-selected="true"] { background: var(--code); font-weight: 600; }
main { padding: 16px 20px; }
.banner { display: flex; gap: 12px; justify-content: space-between; margin: 12px 20px 0; padding: 8px 12px; border: 1px solid var(--danger); border-radius: 6px; background: var(--card); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.empty { color: var(--muted); text-align: center; padding: 24px; }
td.actions { white-space: nowrap; }
td.actions button { padding: 2px 7px; font-size: 12px; margin: 1px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.running { color: var(--ok); border: 1px solid var(--ok); }
.badge.paused { color: var(--warn); border: 1px solid var(--warn); }
.badge.busy { margin-left: 4px; color: var(--muted); border: 1px dashed var(--muted); font-weight: 400; }
button.copy-id { border: 0; background: none; padding: 0; color: inherit; text-align: left; }
button.copy-id::after { content: "copy"; margin-left: 6px; font: 11px system-ui, sans-serif; color: var(--muted); }
button.copy-id:hover::after { color: var(--accent); }
.chip { display: inline-block; margin: 1px 4px 1px 0; padding: 0 6px; border-radius: 4px; background: var(--code); font-family: var(--mono); font-size: 12px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(480px, 94vw); background: var(--card); color: var(--fg); }
dialog.wide { width: min(900px, 96vw); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dlg-body { max-height: 70vh; overflow: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
pre.output { background: #0d1117; color: #d6dde6; padding: 10px; border-radius: 6px; min-height: 160px; max-height: 50vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.output .stderr { color: #ff8a80; }
pre.output .cmd { color: #8ab4f8; }

.block { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.block-head { display: flex; justify-content: space-between; align-items: center; }
pre.code { background: var(--code); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0 0; }
table.kv th { width: 140px; border: 0; }
table.kv td { border: 0; overflow-wrap: anywhere; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast { background: var(--fg); color: var(--bg); padding: 8px 12px; border-radius: 6px; max-width: 420px; overflow-wrap: anywhere; }

/* Small buttons and link-buttons (Copy, Open, Detect ports, Use). */
button.mini, a.btn { padding: 2px 7px; font-size: 12px; }
a.btn {
  display: inline-block; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg);
  text-decoration: none; line-height: inherit;
}
a.btn:hover { border-color: var(--accent); }
td.id-cell { white-space: nowrap; }
/* URL column: port input, URL (truncated, full text in the title), Copy / Open / Detect ports. */
td.url-cell { min-width: 250px; }
.url-line { display: flex; gap: 6px; align-items: center; }
input.port { width: 6.5em; margin: 0; padding: 2px 6px; flex: none; }
.url { display: inline-block; max-width: 24em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; min-width: 0; }
.url.dim { opacity: .5; }
.url-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
ul.ports { list-style: none; padding: 0; margin: 6px 0 12px; }
ul.ports li { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
ul.ports .url { max-width: 36em; }
.offscreen { position: fixed; top: 0; left: -10000px; width: 1px; height: 1px; opacity: 0; }
details.system-ports { margin: 6px 0 12px; }
details.system-ports summary { cursor: pointer; color: var(--muted); }

/* ---- URLs column (automatic port URLs, js/instances.js urlsCell) ---- */
td.urls-cell { min-width: 230px; max-width: 360px; }
.visit-list { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.visit-item { display: inline-flex; gap: 3px; align-items: center; white-space: nowrap; }
a.btn.visit { font-weight: 600; color: var(--accent); border-color: var(--accent); }
a.btn.visit:hover { background: var(--accent); color: var(--accent-fg); }
button.mini.visit:disabled { font-weight: 600; }
/* The refresh icon is drawn by CSS (a data: SVG mask in currentColor; img-src allows data:), so it does not depend on
   a font having U+21BB. The button's name comes from its aria-label. */
button.mini.icon { width: 2.4em; align-self: stretch; position: relative; }
button.mini.icon::before {
  content: ""; position: absolute; inset: 0; margin: auto; width: 13px; height: 13px; background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='black' stroke-width='2' stroke-linecap='round' d='M13.5 8a5.5 5.5 0 1 1-1.6-3.9'/%3E%3Cpath d='M14.5 1.5v5h-5z'/%3E%3C/svg%3E") center / contain no-repeat;
}
a.btn:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* While detecting, the refresh icon stays focusable (aria-disabled, not disabled) so keyboard focus survives. */
button.mini.icon[aria-disabled="true"] { opacity: .45; cursor: default; }
/* ---- end URLs column ---- */
