:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #4bbd98;
  --accent-2: #3aa, 0;
  --danger: #e5534b;
  --warn: #e3b341;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 13px; }

.container { max-width: 880px; margin: 0 auto; padding: 24px 20px 80px; }

h1 { font-size: 24px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 28px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.flash { background: rgba(75,189,152,.12); border: 1px solid var(--accent); color: #c9f3e3; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.error { background: rgba(229,83,75,.12); border-color: var(--danger); color: #f6c9c6; }
.flash.warn { background: rgba(227,179,65,.12); border-color: var(--warn); color: #f3e3b3; }

input, select, button, textarea {
  font: inherit; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); padding: 8px 12px;
}
textarea { resize: vertical; min-height: 60px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
button { cursor: pointer; background: var(--accent); color: #08130f; border: none; font-weight: 600; }
button:hover { filter: brightness(1.08); }
.linkbtn { background: none; border: none; color: var(--danger); padding: 0 4px; font-weight: 500; }
.linkbtn:hover { text-decoration: underline; }

form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }

/* Stacked form card (e.g. create invite). */
.form-card { display: grid; gap: 16px; max-width: 560px; padding: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.form-card .field { display: grid; gap: 5px; }
.form-card .field-narrow { max-width: 160px; }
.form-card label { font-size: 13px; color: var(--muted); }
.form-card .hint { margin-top: 1px; }
.form-actions { display: flex; gap: 8px; }

/* Data tables. */
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; font-size: 14px; }
table.grid thead th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
table.grid td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: rgba(255,255,255,.02); }
table.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.grid .nowrap { white-space: nowrap; color: var(--muted); }
table.grid .actions { text-align: right; }
table.grid .welcome-cell { max-width: 280px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Sortable data tables (admin users). */
table.grid thead th.sortable { cursor: pointer; user-select: none; -webkit-user-select: none; }
table.grid thead th.sortable:hover { color: var(--text); }
table.grid thead th.sortable::after { content: "\2195"; opacity: .35; margin-left: 5px; font-size: 10px; }
table.grid thead th.sortable[data-dir="asc"]::after { content: "\2191"; opacity: .9; color: var(--accent); }
table.grid thead th.sortable[data-dir="desc"]::after { content: "\2193"; opacity: .9; color: var(--accent); }

/* Admin overview headline stats. */
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 18px 0 4px; }
.stat { flex: 1 1 140px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.stat-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Admin overview cards. */
.cards { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card:hover { border-color: var(--accent); }
.card-head { display: flex; align-items: center; gap: 8px; }
.card .cname { font-weight: 600; font-size: 16px; }
.card-meta { color: var(--muted); font-size: 13px; margin: 0; flex: 1 1 auto; }
.card-actions { margin-top: 2px; }

.complist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.crow { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.swatch { flex: none; width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset; }
.crow-main { flex: 1 1 auto; min-width: 0; }
.crow-head { display: flex; align-items: center; gap: 8px; }
.cname { font-weight: 600; font-size: 16px; }
.crow-desc { font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.crow-actions { flex: none; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { display: inline-block; background: var(--accent); color: #08130f; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; }
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn-lg { font-size: 17px; padding: 13px 26px; }
.btn-ico { display: none; }

.open-cta { display: flex; gap: 10px; align-items: center; margin: 18px 0 6px; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); text-transform: lowercase; }
.state-active { color: #08130f; background: var(--accent); border-color: var(--accent); }
.state-missing { color: #fff; background: var(--danger); border-color: var(--danger); }
.state-creating, .state-deploying { color: #08130f; background: var(--warn); border-color: var(--warn); }
.state-local { color: var(--muted); background: var(--panel-2); border-style: dashed; }

.detail-head { display: flex; align-items: center; gap: 12px; }
.props { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); margin: 16px 0; }
.props div { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.props dt { color: var(--muted); font-size: 12px; }
.props dd { margin: 2px 0 0; font-weight: 600; }

.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }

.rowbtns { display: flex; gap: 8px; align-items: center; margin: 8px 0 4px; }
.muted { color: var(--muted); }

/* Links table: per-link access list + row actions. */
.links-grid td { vertical-align: middle; }
.links-grid .num { color: var(--text); }
.links-grid a { overflow-wrap: anywhere; }
.linkname .host { font-weight: 700; }
.linkname .dom { color: var(--muted); font-weight: 400; }
.acl { list-style: none; padding: 0; margin: 0 0 6px; display: flex; flex-direction: column; gap: 4px; }
.acl li { display: flex; align-items: center; gap: 6px; }
.acl .linkbtn { font-size: 15px; line-height: 1; }
.add-user { color: var(--accent); white-space: nowrap; }
.custom-domains { margin-top: 6px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.cd-row { display: flex; align-items: center; gap: 8px; }
.cd-name { font-weight: 700; }
.cd-row .linkbtn { font-size: 15px; line-height: 1; }
.dns-records { list-style: none; padding-left: 0; margin: 4px 0; }
.copyable { cursor: pointer; }
.copyable:hover { text-decoration: underline; text-decoration-style: dotted; }
.copyable.copied { color: var(--accent); }
.cell-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.cell-actions form.inline { width: auto; }

/* Native <dialog> modal (e.g. grant link access). */
dialog.modal { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); padding: 20px; width: min(92vw, 420px); }
dialog.modal::backdrop { background: rgba(0,0,0,.55); }
dialog.modal h3 { margin: 0 0 12px; font-size: 16px; }
dialog.modal form { display: grid; gap: 10px; }
dialog.modal input[type="email"] { width: 100%; }
dialog.modal .hint { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.addlink { margin-top: 14px; }
section.danger { margin-top: 36px; border-top: 1px solid var(--border); padding-top: 16px; }

.login { max-width: 360px; margin: 8vh auto 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login h1 span { color: var(--accent); }
.login form { display: grid; gap: 12px; margin-top: 14px; }
.login label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.login .welcome { margin-top: 14px; padding: 12px 14px; background: var(--bg); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; font-size: 14px; color: var(--text); white-space: pre-wrap; }
.login .or { display: flex; align-items: center; gap: 12px; margin: 18px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.login .or::before, .login .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.login button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.login button.secondary:hover { background: var(--accent); color: #08130f; filter: none; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .container { padding: 16px 14px 60px; }
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar nav { gap: 10px; }
  h1 { font-size: 21px; }

  /* Multi-field inline forms (create computer, add link, share, clone) stack
     vertically with full-width controls. Small "remove" (.linkbtn) forms stay put. */
  form.inline { flex-direction: column; align-items: stretch; }
  form.inline > input,
  form.inline > select,
  form.inline > textarea,
  form.inline > button:not(.linkbtn) { width: 100%; }
  form.inline > .hint { text-align: left; }

  /* Computer rows: put the deep-link buttons under the name/description
     and render them as compact icon buttons instead of floating right. */
  .crow { flex-wrap: wrap; }
  .crow-actions { flex: 1 0 100%; justify-content: flex-start; gap: 8px; margin-top: 10px; }
  .crow-actions .btn { flex: 1 1 auto; min-width: 52px; text-align: center; padding: 10px; font-size: 17px; }
  .crow-actions .btn-txt { display: none; }
  .crow-actions .btn-ico { display: inline; }

  /* Detail page niceties. */
  .props { grid-template-columns: 1fr; }
  .open-cta { flex-wrap: wrap; }
  .open-cta .btn-lg { flex: 1 1 auto; text-align: center; }

  /* Admin tables scroll horizontally instead of overflowing the viewport. */
  table.grid { display: block; overflow-x: auto; white-space: nowrap; }

  /* Links table becomes a stack of cards (no horizontal scroll). Each row is a
     card; the header is hidden and cells stack, ordered link → port → access →
     actions. Overrides the generic table.grid rules above via source order. */
  table.links-grid { display: block; overflow: visible; white-space: normal; border: none; background: none; }
  table.links-grid thead { display: none; }
  table.links-grid tbody { display: flex; flex-direction: column; gap: 10px; }
  table.links-grid tr { display: flex; flex-direction: column; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
  table.links-grid td { display: block; padding: 0; border: none; }
  table.links-grid .link-cell { order: 1; }
  table.links-grid .link-cell a { font-weight: 600; }
  table.links-grid .num { order: 2; text-align: left; color: var(--muted); }
  table.links-grid .num::before { content: "port "; }
  table.links-grid .access-cell { order: 3; }
  table.links-grid td.actions { order: 4; text-align: left; }
  table.links-grid .cell-actions { justify-content: flex-start; gap: 16px; }
}
