/* SparkDNS dashboard — hand-rolled CSS
   Dark futuristic ops-console matching CyberSpark design tokens.
   No frameworks. Total < 30KB. Mobile responsive (single column < 720px).
   ============================================================ */

:root {
  --accent: #d62839;
  --accent-light: #ff4d5a;
  --green: #22c55e;
  --amber: #f59e0b;
  --bg: #0a0c10;
  --bg2: #12151e;
  --card: #161a26;
  --border: rgba(255, 255, 255, 0.06);
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --term-bg: #0d1117;
  --r-card: 16px;
  --r-btn: 10px;
  --glow: 0 0 0 1px rgba(214, 40, 57, 0.25), 0 4px 24px rgba(214, 40, 57, 0.14);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  /* layered dark background */
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(214, 40, 57, 0.06), transparent),
    linear-gradient(180deg, var(--bg) 0%, #08090d 100%);
  background-attachment: fixed;
}

a { color: var(--accent-light); text-decoration: none; transition: color .15s; }
a:hover { color: var(--text); }

code, pre, .mono { font-family: var(--mono); }

/* ---- Top navigation ---- */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 16, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.wordmark {
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.wordmark::before {
  content: "";
  width: 10px; height: 10px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(214, 40, 57, 0.5);
}

.nav-user { display: flex; align-items: center; gap: 1rem; }
.nav-email {
  color: var(--text2);
  font-size: .875rem;
  font-family: var(--mono);
}

/* ---- Layout ---- */
.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
  flex: 1 0 auto;
}

.container-narrow { max-width: 460px; }

.section { margin-bottom: 2.5rem; }

/* ---- Typography ---- */
h1, h2, h3 {
  font-family: "Syne", sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.page-title { font-size: 2rem; margin-bottom: .25rem; }
.page-sub { color: var(--text2); font-size: .95rem; margin-bottom: 2rem; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.section-head h2 { font-size: 1.25rem; }
.section-head .actions { display: flex; gap: .5rem; align-items: center; }

.muted { color: var(--text2); }
.dim { color: var(--text3); }

/* ---- Cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}
.card-tight { padding: 1.25rem; }

.card-title {
  font-family: "Syne", sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

/* ---- Auth pages (centered card) ---- */
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
}
.auth-card .wordmark { justify-content: center; margin-bottom: .5rem; font-size: 1.6rem; }
.auth-card .auth-sub { text-align: center; color: var(--text2); margin-bottom: 1.75rem; font-size: .9rem; }

/* ---- Forms ---- */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-btn);
  color: var(--text);
  padding: .7rem .9rem;
  font-family: "DM Sans", sans-serif;
  font-size: .95rem;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--text3); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(214, 40, 57, 0.14);
}
.form-hint { font-size: .8rem; color: var(--text3); margin-top: .35rem; }
.form-hint code { color: var(--text2); }

.form-row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; margin-bottom: 0; }

.field-preview {
  font-family: var(--mono);
  font-size: .9rem;
  color: var(--accent-light);
  padding: .5rem .75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-btn);
  margin-top: .35rem;
}

/* compact inputs for the super-admin editable table rows */
.input-sm {
  font-size: .85rem;
  padding: .45rem .6rem;
}

/* per-row form living inside a <td> (inputs associate via form="") */
.row-form { display: inline; margin: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-family: "DM Sans", sans-serif;
  font-weight: 500;
  font-size: .9rem;
  padding: .6rem 1.1rem;
  border-radius: var(--r-btn);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
  box-shadow: var(--glow);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  color: var(--text2);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255,255,255,0.15); }
.btn-danger {
  background: transparent;
  color: var(--accent-light);
  border-color: rgba(214, 40, 57, 0.3);
}
.btn-danger:hover { background: rgba(214, 40, 57, 0.1); color: var(--accent-light); }
.btn-sm { padding: .4rem .75rem; font-size: .82rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Status badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  font-weight: 600;
  padding: .25rem .6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-family: var(--mono);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.badge-active    { color: var(--green); background: rgba(34, 197, 94, 0.1);  border: 1px solid rgba(34,197,94,.25); }
.badge-active::before    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.badge-past_due  { color: var(--amber); background: rgba(245, 158, 11, 0.1); border: 1px solid rgba(245,158,11,.25); }
.badge-past_due::before  { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.badge-suspended { color: var(--accent-light); background: rgba(214, 40, 57, 0.1);  border: 1px solid rgba(214,40,57,.25); }
.badge-suspended::before { background: var(--accent-light); box-shadow: 0 0 6px var(--accent-light); }
.badge-disabled  { color: var(--text3); background: rgba(100, 116, 139, 0.1); border: 1px solid rgba(100,116,139,.25); }
.badge-disabled::before  { background: var(--text3); }

/* host status also maps: active→green, suspended→red, disabled→dim */
.badge-ok   { color: var(--green); background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.25); }
.badge-ok::before   { background: var(--green); box-shadow: 0 0 6px var(--green); }
.badge-bad  { color: var(--accent-light); background: rgba(214,40,57,.1); border: 1px solid rgba(214,40,57,.25); }
.badge-bad::before  { background: var(--accent-light); box-shadow: 0 0 6px var(--accent-light); }

/* status line ✓ / ✗ */
.status-line { font-family: var(--mono); font-size: .85rem; }
.status-ok   { color: var(--green); }
.status-bad  { color: var(--accent-light); }

/* ---- Tables ---- */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg2); }
th {
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
}
td {
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
td .fqdn { font-family: var(--mono); color: var(--text); }
td .ip { font-family: var(--mono); color: var(--text2); font-size: .85rem; }
td .dim-small { color: var(--text3); font-size: .82rem; font-family: var(--mono); }

.empty-row td { text-align: center; color: var(--text3); padding: 2.5rem 1rem; }

/* ---- Terminal blocks ---- */
.terminal {
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-btn);
  overflow: hidden;
  margin-bottom: 1rem;
}
.terminal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem .85rem;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}
.terminal-title {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.terminal-title::before {
  content: "● ● ●";
  color: var(--text3);
  font-size: .5rem;
  letter-spacing: 2px;
}
.terminal-body {
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .85rem;
  line-height: 1.6;
  color: var(--text2);
  white-space: pre;
}
.terminal-body code { color: inherit; }
.prompt { color: var(--accent-light); user-select: none; }
.term-comment { color: var(--text3); }
.term-var { color: var(--green); }

/* copy button */
.btn-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text3);
  font-family: var(--mono);
  font-size: .72rem;
  padding: .25rem .55rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.btn-copy:hover { color: var(--text); border-color: rgba(255,255,255,0.15); }
.btn-copy.copied { color: var(--green); border-color: rgba(34,197,94,.3); }

/* ---- Token warning block ---- */
.token-warn {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  padding: .75rem 1rem;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--r-btn);
  font-size: .85rem;
  color: var(--amber);
  margin-bottom: 1rem;
}
.token-warn .warn-icon { font-size: 1rem; line-height: 1.4; }

/* ---- Flash messages ---- */
.flash {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1rem 2rem 0;
}
.flash-msg {
  padding: .8rem 1.1rem;
  border-radius: var(--r-btn);
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .5rem;
}
.flash-error {
  background: rgba(214, 40, 57, 0.1);
  border: 1px solid rgba(214, 40, 57, 0.25);
  color: var(--accent-light);
}
.flash-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: var(--green);
}
.flash-info {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text2);
}

/* create-host error flash (host_new re-renders) — prominent red accent */
.flash-create-error {
  border-color: rgba(214, 40, 57, 0.45);
  box-shadow: var(--glow);
  font-weight: 500;
}
.flash-icon {
  font-family: var(--mono);
  font-weight: 700;
}

/* ---- Grid helpers ---- */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-btn);
  padding: 1rem 1.25rem;
}
.stat .stat-label { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; }
.stat .stat-value { font-family: "Syne", sans-serif; font-size: 1.75rem; font-weight: 700; color: var(--text); }

/* ---- Detail layout ---- */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.detail-header h1 { font-size: 1.5rem; }
.detail-header h1 .fqdn { font-family: var(--mono); font-weight: 600; }

.kv-list { list-style: none; }
.kv-list li {
  display: flex;
  justify-content: space-between;
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.kv-list li:last-child { border-bottom: none; }
.kv-list .kv-key { color: var(--text2); }
.kv-list .kv-val { font-family: var(--mono); color: var(--text); }

/* ---- Log entries ---- */
.log-ts { color: var(--text3); font-family: var(--mono); font-size: .82rem; white-space: nowrap; }
.log-ip { font-family: var(--mono); font-size: .85rem; }
.log-arrow { color: var(--text3); padding: 0 .25rem; }
.log-new { color: var(--green); }
.log-old { color: var(--text3); text-decoration: line-through; }
.log-src { font-family: var(--mono); font-size: .8rem; color: var(--text2); }

/* htmx loading indicator */
.htmx-indicator { display: none; opacity: .6; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; }

/* ---- Footer ---- */
.footer {
  text-align: center;
  padding: 1.5rem 2rem 2rem;
  color: var(--text3);
  font-size: .82rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.footer code { color: var(--text2); }

/* ---- Misc ---- */
.spacer { height: 1rem; }
.text-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mt-2 { margin-top: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.nowrap { white-space: nowrap; }

/* ---- Mobile responsive (< 720px) ---- */
@media (max-width: 720px) {
  .topnav { padding: 0 1rem; }
  .container { padding: 1.5rem 1rem; }
  .flash { padding: 1rem 1rem 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row .form-group { min-width: 0; }
  .detail-header { flex-direction: column; align-items: flex-start; }
  .section-head { flex-direction: column; align-items: flex-start; }
  /* table → stacked cards on mobile */
  .table-wrap { border: none; box-shadow: none; background: transparent; }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    margin-bottom: .75rem;
    padding: .25rem 0;
    box-shadow: var(--shadow);
  }
  td { display: flex; justify-content: space-between; align-items: center; border: none; padding: .5rem 1rem; }
  td::before {
    content: attr(data-label);
    color: var(--text3);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
  }
  td[data-full] { flex-direction: column; align-items: flex-start; }
  td[data-full]::before { margin-bottom: .25rem; }
  /* editable admin rows: keep the field label and the input side by side */
  td input, td select { max-width: 62%; }
  .empty-row td::before { content: ""; }
  .terminal-body { font-size: .78rem; }
}