/* ============================================================
   Dashboard — product register.
   The working instrument: familiar, dense, calm.
   Built on tokens.css (color, type, spacing, motion).
   ============================================================ */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand-mark { width: 20px; height: 20px; display: inline-block; flex: 0 0 auto; }

/* ---------- auth ---------- */
.auth {
  display: grid; place-items: center; min-height: 100vh;
  padding: var(--sp-6); background:
    radial-gradient(50% 40% at 50% 0%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--sp-6);
  box-shadow: var(--shadow-2);
}
.auth-brand { margin-bottom: var(--sp-5); }
.auth-h1 { margin: 0 0 var(--sp-1); font-size: var(--fs-xl); letter-spacing: -0.02em; }
.auth-sub { margin: 0 0 var(--sp-4); font-size: var(--fs-sm); }
.muted { color: var(--text-muted); }
.hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-2); line-height: var(--lh-normal); }
code { background: var(--surface-2); padding: 2px 6px; border-radius: var(--radius-sm); font-size: 0.85em; font-family: var(--font-mono); }

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-4); }
label { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }
input, select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-md); padding: 10px var(--sp-3); font-size: 1rem; width: 100%;
  font-family: var(--font-ui);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
input::placeholder { color: var(--text-faint); }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus-visible, select:focus-visible {
  outline: none; border-color: var(--focus); box-shadow: var(--focus-ring);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-md); padding: 9px 14px; font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; font-family: var(--font-ui);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); border-color: oklch(0.42 0.1 25); }
.btn.danger:hover { background: var(--down-soft); border-color: var(--down); }
.btn.block { width: 100%; }

.error { color: var(--down); font-size: var(--fs-sm); margin-top: var(--sp-3); }
.banner { margin: var(--sp-3) var(--sp-6) 0; padding: var(--sp-3) var(--sp-4); background: var(--down-soft); border: 1px solid oklch(0.42 0.1 25); border-radius: var(--radius-md); font-size: var(--fs-sm); }
.approval-banner { margin: var(--sp-3) var(--sp-6) 0; padding: var(--sp-3) var(--sp-4); background: var(--warn-soft); border: 1px solid oklch(0.45 0.09 85); border-radius: var(--radius-md); color: var(--warn); font-size: var(--fs-sm); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-3) var(--sp-6); background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-brand { font-size: var(--fs-md); }
.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }
.pill {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 3px var(--sp-3); border-radius: 999px; font-size: var(--fs-xs); color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- layout ---------- */
.container { max-width: 980px; margin: 0 auto; padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-5); }
.card h2 { margin: 0 0 var(--sp-4); font-size: var(--fs-lg); letter-spacing: -0.01em; }
.row-form { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.row-form input, .row-form select { flex: 1; min-width: 160px; }
.row-form .btn { flex: 0 0 auto; }

/* ---------- endpoint cards ---------- */
.endpoint-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.endpoint {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.endpoint:hover { border-color: var(--border-strong); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.status-dot.up { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-dot.down { background: var(--down); box-shadow: 0 0 8px var(--down); }
.status-dot.unknown { background: var(--text-faint); }
.endpoint-info { flex: 1; min-width: 0; }
.endpoint-name { font-weight: 600; display: flex; align-items: center; gap: var(--sp-2); }
.endpoint-url { color: var(--text-muted); font-size: var(--fs-xs); word-break: break-all; }
.endpoint-meta { display: flex; gap: var(--sp-4); margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--text-muted); }
.endpoint-meta strong { font-weight: 600; }
.badge { font-size: var(--fs-xs); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); font-weight: 600; }
.badge.down { color: var(--down); border-color: oklch(0.42 0.1 25); background: var(--down-soft); }
.badge.up { color: var(--ok); border-color: oklch(0.4 0.08 155); background: var(--ok-soft); }
.badge.admin { color: var(--warn); border-color: oklch(0.45 0.09 85); background: var(--warn-soft); }

/* ---------- billing ---------- */
.billing-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }
.billing-head h2 { margin: 0; }
.plans-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-3); margin-top: var(--sp-3); }
.plan-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3);
}
.plan-card.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.plan-card h3 { margin: 0; font-size: var(--fs-md); }
.plan-price { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.plan-price span { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 400; }
.plan-card ul { margin: 0; padding-left: var(--sp-5); font-size: var(--fs-sm); color: var(--text-muted); display: flex; flex-direction: column; gap: var(--sp-1); flex: 1; }
.plan-btn { margin-top: var(--sp-2); }

/* ---------- admin stats ---------- */
.admin-stats { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.stat {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5); min-width: 110px; display: flex; flex-direction: column; gap: var(--sp-1);
}
.stat-num { font-size: var(--fs-2xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--fs-xs); color: var(--text-muted); }
.endpoint-actions { display: flex; gap: var(--sp-2); flex-shrink: 0; }
.mini-btn {
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius-sm); padding: 5px 10px; font-size: var(--fs-xs); font-weight: 500;
  cursor: pointer; font-family: var(--font-ui);
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.mini-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.mini-btn.danger:hover { color: var(--down); border-color: var(--down); background: var(--down-soft); }
.mini-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- history ---------- */
.chart-wrap { margin: var(--sp-4) 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-3); }
#history-chart { width: 100%; height: 120px; display: block; }
.history-meta { font-size: var(--fs-sm); }
.table-wrap { overflow-x: auto; }
.checks-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.checks-table th, .checks-table td { text-align: left; padding: var(--sp-2) var(--sp-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.checks-table th { color: var(--text-muted); font-weight: 500; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: var(--tracking-label); }
.checks-table td:first-child, .checks-table th:first-child { padding-left: 0; }
.checks-table td:last-child, .checks-table th:last-child { padding-right: 0; }
.checks-table tr:last-child td { border-bottom: none; }
.ok { color: var(--ok); }
.fail { color: var(--down); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: oklch(0.1 0.01 75 / 0.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: var(--sp-4); backdrop-filter: blur(4px); }
.modal-box { background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: var(--sp-5); width: 100%; max-width: 480px; box-shadow: var(--shadow-2); }
.modal-box h3 { margin: 0 0 var(--sp-4); }

/* ---------- admin ---------- */
.admin-subhead { margin: var(--sp-5) 0 var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); }
.admin-sites td { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.grants-form { margin: var(--sp-3) 0 var(--sp-4); }
.grants-form input { max-width: 320px; }
.grants-table { margin-top: var(--sp-2); }
.contact-msg { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-actions { display: flex; gap: var(--sp-2); }
.contact-actions .btn { flex: 0 0 auto; }
.tid {
  font-family: var(--font-mono); font-size: 0.8em; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1px 6px; word-break: break-all; white-space: nowrap;
}
.admin-tenants td:first-child { font-weight: 600; }
/* Keep the tenants table inside its container: truncate the long ID + owner
   columns instead of forcing a horizontal scroll on the whole panel. */
.admin-tenants th:nth-child(2), .admin-tenants td:nth-child(2),
.admin-tenants th:nth-child(3), .admin-tenants td:nth-child(3) {
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-tenants td:nth-child(2) .tid {
  display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom;
}
.tenant-box { max-width: 720px; }
.tenant-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-3); }
.tenant-head h3 { margin: 0; }
.tenant-meta { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--sp-3); }
textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-md); padding: 10px var(--sp-3); font-size: 1rem; width: 100%;
  font-family: var(--font-ui); resize: vertical;
}
textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: var(--focus-ring); }

@media (max-width: 640px) {
  .endpoint { flex-wrap: wrap; }
  .endpoint-actions { width: 100%; flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; gap: var(--sp-2); }
  .topbar-right { flex-wrap: wrap; }
  .billing-head { flex-direction: column; align-items: flex-start; gap: var(--sp-2); }
}

hr { border: none; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }
details summary { cursor: pointer; color: var(--accent); margin-bottom: var(--sp-2); font-size: var(--fs-sm); }
details summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
