/* DNS Insight — single dark theme. */

:root {
  --bg: #0b0e14;
  --surface: #131826;
  --border: #232a3b;
  --text: #e6e9f0;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --success: #2fbf71;
  --danger: #e5534b;
  --warn: #d4a72c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
}

.muted { color: var(--muted); }
.danger { color: var(--danger); }
.success { color: var(--success); }
.warn { color: var(--warn); }

/* -- layout ---------------------------------------------------------------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* -- top bar ---------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11, 14, 20, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 52px;
}

.wordmark {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .02em;
  color: var(--text);
  white-space: nowrap;
}
.wordmark span { color: var(--accent); }
.wordmark:hover { text-decoration: none; }

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.nav::-webkit-scrollbar { display: none; }

.nav-link {
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: .9rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-link:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.nav-link.active { color: var(--text); background: var(--surface); }

.topbar-right { margin-left: auto; flex-shrink: 0; }

/* -- cards ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.error-card { border-color: var(--danger); }
.error-card h2 { color: var(--danger); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  font-size: .95rem;
}

/* -- tables (dense, sticky header) ------------------------------------------ */

.table-wrap { overflow-x: auto; max-width: 100%; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(79, 140, 255, .05); }
tr.clickable { cursor: pointer; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* -- chips ------------------------------------------------------------------ */

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip-danger { color: var(--danger); background: rgba(229, 83, 75, .12); border-color: rgba(229, 83, 75, .35); }
.chip-accent { color: var(--accent); background: rgba(79, 140, 255, .12); border-color: rgba(79, 140, 255, .35); }
.chip-warn   { color: var(--warn);   background: rgba(212, 167, 44, .12); border-color: rgba(212, 167, 44, .35); }
.chip-muted  { color: var(--muted);  background: rgba(138, 147, 166, .10); border-color: rgba(138, 147, 166, .30); }
.chip-success { color: var(--success); background: rgba(47, 191, 113, .12); border-color: rgba(47, 191, 113, .35); }

/* -- buttons ---------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: .88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter .12s ease;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; filter: none; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); }

.btn-danger { background: var(--danger); }
.btn-success { background: var(--success); }

.btn-sm { padding: 4px 10px; font-size: .8rem; }

/* -- forms ------------------------------------------------------------------ */

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="password"], input[type="search"],
input[type="number"], textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .92rem;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 60px; }

.field { margin-bottom: 12px; }

.form-error {
  color: var(--danger);
  font-size: .88rem;
  margin: 8px 0;
}

/* -- badges ----------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  line-height: 1;
}

/* -- spinner ---------------------------------------------------------------- */

.spinner-wrap { display: flex; justify-content: center; padding: 48px 0; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* -- stats / misc ----------------------------------------------------------- */

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.domain-link { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

.chart { width: 100%; min-height: 44px; }

.why-chain { border-left: 2px solid var(--border); padding-left: 12px; margin: 8px 0; }
.why-chain .why-step { margin-bottom: 8px; font-size: .9rem; }
.why-chain .why-step:last-child { margin-bottom: 0; }

details.expand > summary { cursor: pointer; list-style: none; }
details.expand > summary::-webkit-details-marker { display: none; }

/* -- uPlot dark tweaks ------------------------------------------------------ */

.u-legend { color: var(--muted); font-size: 11px; }
.u-legend .u-marker { border-radius: 2px; }
.u-select { background: rgba(79, 140, 255, .1); }

/* -- responsive ------------------------------------------------------------- */

@media (max-width: 800px) {
  .grid { grid-template-columns: 1fr; }
  .main { padding: 12px 10px 40px; }
  .topbar-inner { padding: 0 10px; gap: 10px; }
  .wordmark span { display: none; }
  table { font-size: .82rem; }
  thead th, tbody td { padding: 5px 6px; }
}

/* -- assistant chat (added with the Assistant view) ------------------------- */

/* A chip that is actually a button (starter prompts). */
.chip-btn {
  font-family: inherit;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
}
.chip-btn:hover { filter: brightness(1.25); }
.chip-btn:disabled { opacity: .5; cursor: default; filter: none; }

.chat-log { display: flex; flex-direction: column; gap: 12px; }

.chat-turn { display: flex; }
.chat-turn.user { justify-content: flex-end; }

.chat-bubble {
  max-width: 78%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
}
.chat-turn.user .chat-bubble {
  background: rgba(79, 140, 255, .12);
  border-color: rgba(79, 140, 255, .35);
}
.chat-bubble > div > *:first-child { margin-top: 0; }
.chat-bubble p:last-child, .chat-bubble ul:last-child { margin-bottom: 0; }
.chat-bubble ul { padding-left: 20px; margin: 6px 0; }
.chat-bubble pre {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: .82rem;
}

.chat-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: .74rem;
}

.chat-composer { display: flex; gap: 10px; align-items: flex-end; }
.chat-composer textarea { min-height: 48px; }

/* The write switch: unmistakable when it is on. */
.chat-allow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.chat-allow.on {
  color: var(--warn);
  border-color: rgba(212, 167, 44, .55);
  background: rgba(212, 167, 44, .12);
}

@media (max-width: 800px) {
  .chat-bubble { max-width: 92%; }
  .chat-composer { flex-direction: column; align-items: stretch; }
  .chat-composer .row { justify-content: space-between; }
}

/* --- OAuth sign-in buttons (login view) ------------------------------------ */
.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin: 6px 0;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}
.btn-oauth:hover { border-color: var(--accent); background: #182034; }
.or-rule {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.or-rule::before, .or-rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* --- Insight stat tiles (Insights page + admin overview strip) -------------
   The tile markup ships in views/insights.js (StatTile / InsightCards); these
   are the rules that give it a grid, stack the label above the value, and keep
   long device names from blowing the column width out. */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  background: #0e1220;
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 0;
}
.stat-tile .tile-label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1.2;
}
.stat-tile .tile-value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.stat-tile .tile-value.text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
}
.stat-tile .tile-unit {
  font-size: .85rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 2px;
}
.stat-tile .tile-trend {
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
}
.stat-tile .tile-trend.up { color: var(--success); }
.stat-tile .tile-trend.down { color: var(--danger); }
.stat-tile .tile-trend.flat,
.stat-tile .tile-trend.neutral { color: var(--muted); }
.stat-tile .tile-detail {
  font-size: .72rem;
  color: var(--muted);
  line-height: 1.3;
}
@media (max-width: 800px) {
  .stat-tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
