/* Monochrome design system. Layout is fluid from 320px to ultrawide. */

:root {
  color-scheme: dark;

  --bg: #050505;
  --surface: rgba(17, 17, 17, 0.72);
  --surface-solid: #0e0e0e;
  --surface-hover: rgba(255, 255, 255, 0.05);
  --surface-active: rgba(255, 255, 255, 0.09);

  --border: rgba(255, 255, 255, 0.1);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.22);
  --border-focus: #fff;

  --text: #f4f4f4;
  --text-secondary: #b0b0b0;
  --text-muted: #8c8c8c;
  --text-dim: #6e6e6e;

  --accent: #f4f4f4;
  --accent-text: #000;
  --accent-hover: #fff;

  /* Status is carried by shape and weight, not hue. admin.js reads --danger. */
  --ok: #fff;
  --warn: #c8c8c8;
  --danger: #fff;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 0.18s;
  --slow: 0.6s;
  --gutter: clamp(16px, 4vw, 32px);
  --sticky: 88px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
::selection { background: #fff; color: #000; }

html {
  background: var(--bg);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font: 400 14px/1.55 var(--font-sans);
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

/* Ambient backdrop: fine grid plus a slow drifting glow */
body::before, body::after {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
}

body::before {
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 10%, transparent 75%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 10%, transparent 75%);
}

body::after {
  top: -30vmax;
  left: 50%;
  width: 90vmax;
  height: 60vmax;
  margin-left: -45vmax;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.1), transparent);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(-12%, 0, 0) scale(1); }
  to { transform: translate3d(12%, 6%, 0) scale(1.15); }
}

@keyframes rise {
  from { opacity: 0; transform: translate3d(0, 12px, 0); }
  to { opacity: 1; transform: none; }
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5); }
  70%, 100% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); }
}
@keyframes eq {
  from { transform: scaleY(0.25); }
  to { transform: scaleY(1); }
}
@keyframes grow { from { transform: scaleX(0); } }

/* Typography */
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.025em; color: var(--text); }
h1 { font-size: 22px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.3; }
h3 { font-size: 14px; line-height: 1.4; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

.muted { color: var(--text-muted); }
.hint { font-size: 13px; color: var(--text-muted); }
.mono { font-family: var(--font-mono); font-size: 12px; }

code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 2px 6px;
  color: var(--text);
  overflow-wrap: anywhere;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--text-dim);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--fast);
}
a:hover { text-decoration-color: #fff; }

:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Brand */
.brand { display: flex; align-items: center; min-width: 0; }

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand-badge .muted { overflow: hidden; text-overflow: ellipsis; }

.eq-mark { display: inline-flex; align-items: center; gap: 2px; height: 16px; flex: none; }
.eq-mark i {
  width: 2.5px;
  height: 100%;
  border-radius: 2px;
  background: #fff;
  transform-origin: center;
  animation: eq 0.9s ease-in-out infinite alternate;
}
.eq-mark i:nth-child(2) { animation-delay: -0.5s; animation-duration: 0.7s; }
.eq-mark i:nth-child(3) { animation-delay: -0.2s; animation-duration: 1.1s; }
.eq-mark i:nth-child(4) { animation-delay: -0.7s; animation-duration: 0.8s; }

/* Sticky navigation */
.topbar, .public-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 max(var(--gutter), calc((100% - 1216px) / 2));
  background: rgba(5, 5, 5, 0.72);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar { height: 56px; }
.public-nav { height: 64px; border-bottom: 1px solid var(--border-subtle); grid-column: 1 / -1; grid-row: 1; }
.topbar-actions { display: flex; align-items: center; gap: 4px; flex: none; }

.subnav-wrap {
  position: sticky;
  top: 56px;
  z-index: 99;
  background: rgba(5, 5, 5, 0.72);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border);
  padding: 0 max(var(--gutter), calc((100% - 1216px) / 2));
  overflow-x: auto;
  scrollbar-width: none;
}
.subnav-wrap::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }

.subnav, .tabs, .mode-switch { position: relative; display: flex; }
.subnav { width: max-content; min-width: 100%; gap: 2px; }

.subnav-btn, .tabs .tab {
  position: relative;
  z-index: 1;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--fast);
}
.subnav-btn { padding: 14px 14px; }
.tabs .tab { padding: 10px 14px; flex: none; }
.subnav-btn:hover, .tabs .tab:hover, .subnav-btn.active, .tabs .tab.active { color: var(--text); }
.subnav-btn:active, .tabs .tab:active { transform: none; }

.tabs {
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}

/* Sliding indicator, positioned by ui.js */
.nav-indicator {
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--w, 0);
  height: 2px;
  background: #fff;
  border-radius: 2px 2px 0 0;
  transform: translateX(var(--x, 0));
  pointer-events: none;
}
.nav-indicator.ready {
  transition: transform 0.4s var(--ease), width 0.4s var(--ease);
}

.mode-switch {
  gap: 0;
  flex: 0 1 auto;
  min-width: 0;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}
.mode-switch button {
  position: relative;
  z-index: 1;
  flex: 1;
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  color: var(--text-muted);
  font-size: 13px;
  transition: color 0.25s;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.active { color: #000; }
.mode-switch .nav-indicator {
  top: 3px;
  bottom: 3px;
  height: auto;
  border-radius: 999px;
}

main {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px) var(--gutter) 64px;
}

/* Surfaces with a pointer-tracking spotlight */
.card, .stat-card, .login-card, .doc-grid {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.25s;
}
.card::after, .stat-card::after, .login-card::after, .doc-grid::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(320px circle at var(--mx, 50%) var(--my, 0%), rgba(255, 255, 255, 0.055), transparent 70%);
  opacity: 0;
  transition: opacity 0.35s;
  pointer-events: none;
}
.card:hover::after, .stat-card:hover::after, .login-card:hover::after, .doc-grid:hover::after { opacity: 1; }

.card {
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.5vw, 24px);
  margin-bottom: 20px;
}
.card > *, .login-card > * { position: relative; z-index: 1; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
}
.analytics-card {
  min-width: 0;
  min-height: 116px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.018);
}
.analytics-label {
  display: block;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.065em;
  line-height: 1.35;
  text-transform: uppercase;
}
.analytics-value {
  display: block;
  margin-top: 9px;
  color: var(--text);
  font-size: clamp(16px, 1.5vw, 21px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}
.analytics-detail {
  margin-top: 7px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.analytics-card[data-state="good"] .analytics-value { color: #9be6bd; }
.analytics-card[data-state="warn"] .analytics-value { color: #ffd27a; }
.analytics-card[data-state="bad"] .analytics-value { color: #ff9b9b; }
.analytics-bar { height: 4px; margin-top: 10px; overflow: hidden; background: var(--border); border-radius: 99px; }
.analytics-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

.portal-link-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.portal-link-copy { display: flex; flex-direction: column; min-width: 0; gap: 8px; }
.portal-link-copy .stat-label { margin: 0; }
.portal-link-copy code { overflow-wrap: anywhere; }
.portal-actions { display: flex; flex: none; gap: 8px; }
.portal-notes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.portal-note { display: flex; flex-direction: column; gap: 5px; min-height: 76px; padding: 13px; border: 1px solid var(--border); border-radius: var(--radius-md); }
.portal-note strong { font-size: 12px; font-weight: 500; }
.portal-note .muted { font-size: 11.5px; line-height: 1.45; }

.view-panel { animation: rise var(--slow) var(--ease) both; }

/* Metrics: 5 / 3+2 / 2+2+1 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stats-grid:empty { display: none; }
main:has(> [data-view="docs"]:not([hidden])) > .stats-grid { display: none; }

.stat-card {
  min-width: 0;
  border-radius: var(--radius-md);
  padding: 16px;
  animation: rise var(--slow) var(--ease) both;
}
.stat-card:nth-child(2) { animation-delay: 50ms; }
.stat-card:nth-child(3) { animation-delay: 100ms; }
.stat-card:nth-child(4) { animation-delay: 150ms; }
.stat-card:nth-child(5) { animation-delay: 200ms; }
.stat-card:hover { border-color: var(--border-hover); }
.stat-card[data-state="good"] .stat-value { color: #9be6bd; }
.stat-card[data-state="warn"] .stat-value { color: #ffd27a; }
.stat-card[data-state="bad"] .stat-value { color: #ff9b9b; }
.stat-detail { margin-top: 7px; color: var(--text-muted); font-size: 11px; line-height: 1.45; }
.analytics-bar { height: 4px; margin-top: 9px; overflow: hidden; background: var(--border); border-radius: 99px; }
.analytics-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

.module-card {
  width: 100%;
  min-height: 158px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  text-align: left;
  white-space: normal;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.module-card:hover { transform: translateY(-2px); background: var(--surface-hover); }
.module-card:focus-visible { outline: 2px solid var(--text-secondary); outline-offset: 3px; }
.module-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.module-card-top .stat-label { margin: 0 0 10px; }
.module-card-arrow { color: var(--text-muted); font-size: 16px; line-height: 1; }
.module-card .stat-value { display: block; margin-bottom: 7px; white-space: normal; overflow-wrap: anywhere; }
.module-card-detail { display: block; color: var(--text-muted); font-size: 11.5px; line-height: 1.45; }
.module-card-extra { display: block; min-height: 16px; margin-top: 7px; color: var(--text-secondary); font-size: 10.5px; line-height: 1.4; }
.module-card-action { display: flex; align-items: center; gap: 5px; margin-top: auto; padding-top: 13px; color: var(--text-secondary); font-size: 11.5px; }
.module-progress { display: block; height: 4px; margin-top: 9px; overflow: hidden; background: var(--border); border-radius: 99px; }
.module-progress i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.module-card-action span { transition: transform var(--fast) var(--ease); }
.module-card:hover .module-card-action span { transform: translateX(3px); }
.module-card[data-state="online"] .stat-value { color: #9be6bd; }
.module-card[data-state="offline"] .stat-value { color: #ff9b9b; }
.module-card[data-state="busy"] .stat-value { color: #ffd27a; }

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value {
  display: block;
  font-size: clamp(19px, 2vw, 24px);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: normal;
  overflow-wrap: anywhere;
}
.stat-detail { min-width: 0; overflow-wrap: anywhere; }

/* Buttons */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--fast), border-color var(--fast), color var(--fast), box-shadow var(--fast), transform var(--fast) var(--ease);
}
button:active:not(:disabled), .button:active { transform: scale(0.97); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.primary {
  position: relative;
  overflow: hidden;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.primary::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(0, 0, 0, 0.12) 50%, transparent 65%);
  transform: translateX(-100%);
  transition: transform 0.7s var(--ease);
}
button.primary:hover:not(:disabled) { background: #fff; box-shadow: 0 0 28px rgba(255, 255, 255, 0.22); }
button.primary:hover:not(:disabled)::before { transform: translateX(100%); }
button.primary:disabled::after {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

button.secondary { background: rgba(255, 255, 255, 0.04); border-color: var(--border); }
button.secondary:hover:not(:disabled) { background: var(--surface-active); border-color: var(--border-hover); }

button.ghost, .button.ghost { color: var(--text-muted); }
button.ghost:hover:not(:disabled), .button.ghost:hover { color: var(--text); background: var(--surface-hover); }

button.ghost.danger, button.danger { color: var(--text-secondary); min-height: 30px; }
button.ghost.danger:hover:not(:disabled), button.danger:hover:not(:disabled) { background: #fff; color: #000; }

.copy-btn {
  flex: none;
  min-height: 28px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
}
.copy-btn:hover { color: var(--text); border-color: var(--border-hover); background: var(--surface-active); }
.copy-btn.copied { background: #fff; border-color: #fff; color: #000; animation: pop 0.3s var(--ease); }

/* Forms */
label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
}
label span { font-weight: 500; color: var(--text); }

input, textarea, select {
  width: 100%;
  min-height: 40px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--fast), box-shadow var(--fast), background-color var(--fast);
}
input:hover, textarea:hover { border-color: var(--border-hover); }
input:focus, textarea:focus, select:focus {
  border-color: #fff;
  background: #000;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
textarea { display: block; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; resize: vertical; }

.row { display: flex; gap: 12px; align-items: flex-end; margin-top: 12px; flex-wrap: wrap; }
.row .grow { flex: 1 1 150px; min-width: 0; }
.row button { min-height: 40px; }

.tab-body { animation: rise 0.4s var(--ease) both; }
.tab-body > .row:first-child { margin-top: 0; }

#public-oauth-step2, #oauth-step2, #public-addon-result, #custom-limit-wrap, #custom-expiry-wrap {
  animation: rise 0.45s var(--ease) both;
}

#public-oauth-link, #oauth-link {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  padding: 10px 12px;
  border: 1px dashed var(--border-hover);
  border-radius: var(--radius-sm);
  transition: background-color var(--fast);
}
#public-oauth-link:hover, #oauth-link:hover { background: var(--surface-hover); }

details.add { border-top: 1px solid var(--border-subtle); padding-top: 12px; }
details.add summary {
  list-style: none;
  width: fit-content;
  color: var(--text-secondary);
  transition: color var(--fast);
}
details.add summary::-webkit-details-marker { display: none; }
details.add summary:hover, details.add[open] summary { color: var(--text); }
details.add[open] > div { animation: rise 0.4s var(--ease) both; }

/* Data tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.35);
  scrollbar-width: thin;
}

table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13.5px; }

th {
  padding: 11px 14px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
  transition: background-color var(--fast), color var(--fast);
}
td strong { color: var(--text); font-weight: 500; }
tr:last-child td { border-bottom: 0; }
.table-wrap tbody tr:hover td { background: var(--surface-hover); color: var(--text); }
.table-wrap tbody tr { animation: rise 0.5s var(--ease) both; }
.table-wrap tbody tr:nth-child(2) { animation-delay: 40ms; }
.table-wrap tbody tr:nth-child(3) { animation-delay: 80ms; }
.table-wrap tbody tr:nth-child(n + 4) { animation-delay: 120ms; }
td.empty { padding: 44px 16px; text-align: center; color: var(--text-muted); }
#tokens td:nth-child(3) > div > div > div { transform-origin: left; animation: grow 0.9s var(--ease) both; }
#tokens, #accounts { min-width: 760px; }

/* Status pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}
.pill.ok { color: var(--text); }
.pill.ok::before { background: #fff; animation: pulse 2.4s ease-out infinite; }
.pill.warn { color: var(--warn); border-style: dashed; border-color: var(--border-hover); }
.pill.warn::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--warn); }
.pill.danger, .pill.error { background: #fff; border-color: #fff; color: #000; }
.pill.danger::before, .pill.error::before { background: #000; border-radius: 1px; }

/* Preset chips */
.preset-group { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.preset-chip {
  min-height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 999px;
}
.preset-chip:hover { color: var(--text); border-color: var(--border-hover); }
.preset-chip.active { background: #fff; color: #000; border-color: #fff; }

/* Public shell */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(var(--gutter), 1fr) minmax(0, 768px) minmax(0, 448px) minmax(var(--gutter), 1fr);
  grid-template-rows: auto 1fr;
  animation: fade 0.5s ease both;
}

.login-card {
  grid-column: 3;
  grid-row: 2;
  align-self: center;
  width: auto;
  margin: 32px 0;
  padding: clamp(20px, 3vw, 32px);
  border-radius: 20px;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: rise 0.7s var(--ease) both;
}
.login-card h1 { margin-bottom: 6px; }
.login-card .muted { display: block; margin-bottom: 20px; }
#view-submit, #login-form { animation: rise 0.45s var(--ease) both; }

.hero {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  min-width: 0;
  padding: 32px clamp(32px, 6vw, 88px) 32px 0;
}
.login-card[hidden] ~ .hero { display: none; }
.hero > * { animation: rise 0.8s var(--ease) both; }
.hero > :nth-child(2) { animation-delay: 80ms; }
.hero > :nth-child(3) { animation-delay: 160ms; }
.hero > :nth-child(4) { animation-delay: 240ms; }

.hero-title {
  margin: 0 0 18px;
  font-size: clamp(38px, 5.2vw, 68px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.05em;
  background: linear-gradient(180deg, #fff 30%, #777);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-copy { max-width: 42ch; margin: 0 0 28px; color: var(--text-secondary); font-size: clamp(15px, 1.3vw, 17px); }

.wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 72px;
  margin-bottom: 28px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, #000 55%, transparent);
  mask-image: linear-gradient(90deg, #000 55%, transparent);
}
.wave i {
  flex: none;
  width: 3px;
  height: var(--h);
  border-radius: 3px;
  background: #fff;
  animation: eq var(--d) ease-in-out var(--o) infinite alternate;
}

.spec-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.spec-list li {
  padding: 4px 11px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: fade 0.25s ease both;
}
.modal {
  width: 100%;
  max-width: 500px;
  margin: auto;
  padding: clamp(18px, 3vw, 28px);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: modal-in 0.45s var(--ease) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translate3d(0, 20px, 0) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
.modal-close {
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 20px;
}
.modal-close:hover { color: var(--text); background: var(--surface-active); transform: rotate(90deg); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Toasts and messages */
.toast-container {
  position: fixed;
  right: 24px;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: min(380px, calc(100vw - 32px));
  padding: 11px 16px;
  font-size: 13.5px;
  background: #f4f4f4;
  color: #000;
  font-weight: 500;
  border-radius: 999px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  animation: toast-in 0.45s var(--ease);
}
.toast.error {
  background: #000;
  color: #fff;
  box-shadow: inset 0 0 0 1.5px #fff, 0 16px 40px rgba(0, 0, 0, 0.7);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.94); }
  to { opacity: 1; transform: none; }
}

.msg {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 12px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  overflow-wrap: anywhere;
  animation: rise 0.35s var(--ease) both;
}
.msg.ok { color: var(--text); border-color: var(--border-hover); }
.msg.error { color: #fff; font-weight: 500; border: 1px solid #fff; background: rgba(255, 255, 255, 0.07); }
.msg.hint {
  background: linear-gradient(90deg, var(--text-muted) 40%, #fff 50%, var(--text-muted) 60%) 0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 1.6s linear infinite;
}

/* Docs */
.docs-wrap {
  grid-column: 1 / -1;
  grid-row: 2;
  min-width: 0;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px var(--gutter) 64px;
  animation: rise 0.5s var(--ease) both;
}
#app { --sticky: 126px; }
#app-docs-panel { min-width: 0; }

.docs-layout {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: clamp(24px, 3vw, 48px);
  align-items: start;
}
.docs-sidebar {
  position: sticky;
  top: var(--sticky);
  max-height: calc(100vh - var(--sticky) - 16px);
  overflow-y: auto;
  scrollbar-width: none;
}
.docs-sidebar-section { margin-bottom: 22px; }
.docs-sidebar-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 6px;
  padding-left: 12px;
}
.docs-link {
  display: block;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  border-left: 1px solid var(--border-subtle);
  transition: color var(--fast), border-color var(--fast), padding-left 0.3s var(--ease);
}
.docs-link:hover { color: var(--text); border-left-color: var(--border-hover); }
.docs-link.active { color: #fff; font-weight: 500; border-left-color: #fff; padding-left: 16px; }

.docs-content { min-width: 0; }
.docs-intro {
  margin-bottom: 40px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: var(--sticky);
}
.docs-intro h1 { font-size: clamp(30px, 4vw, 44px); letter-spacing: -0.04em; margin-bottom: 12px; }
.docs-intro p { color: var(--text-secondary); font-size: 15px; max-width: 68ch; }

.doc-section { margin-bottom: 44px; scroll-margin-top: var(--sticky); }
.doc-endpoint-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; min-width: 0; }

.badge-method {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-hover);
  color: var(--text);
}
.badge-method.post { background: #fff; border-color: #fff; color: #000; }
.endpoint-path { font-family: var(--font-mono); font-size: 14.5px; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }

.doc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: clamp(16px, 2.5vw, 28px);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.5vw, 24px);
}
.doc-grid:hover { border-color: var(--border-hover); }
.doc-left, .doc-right { position: relative; z-index: 1; display: flex; flex-direction: column; min-width: 0; }
.doc-left { gap: 10px; }
.doc-right { gap: 12px; }
.doc-desc { font-size: 14px; color: var(--text-secondary); margin-bottom: 4px; }
.doc-subhead {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-top: 10px;
}

.doc-table { font-size: 13px; }
/* Parameter tables declare a Type column but render type beneath the name. */
.doc-table thead th:nth-child(2):not(:last-child) { display: none; }
.doc-table th { padding: 6px 12px 6px 0; font-size: 10.5px; }
.doc-table td { padding: 10px 12px 10px 0; vertical-align: top; }
.doc-table td:first-child { width: 36%; }
.param-name { font-family: var(--font-mono); font-size: 12.5px; color: var(--text); font-weight: 500; overflow-wrap: anywhere; }
.param-type { display: block; margin-top: 2px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.param-required, .param-optional { font-size: 11px; margin-right: 4px; }
.param-required { color: #fff; font-weight: 600; }
.param-optional { color: var(--text-muted); }

.code-panel {
  min-width: 0;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-muted);
}
.code-body {
  margin: 0;
  padding: 14px;
  max-height: 340px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: #e4e4e4;
  white-space: pre;
  scrollbar-width: thin;
}

/* Laptop and below */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .stat-card { grid-column: span 2; }
  .stat-card:nth-child(n + 4) { grid-column: span 3; }
  .analytics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .doc-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Tablet: single column shell, docs nav becomes a scrolling rail */
@media (max-width: 920px) {
  .login-wrap { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; }
  .hero, .docs-wrap { grid-column: 1; grid-row: 2; }
  .hero { width: 100%; max-width: 520px; margin: 0 auto; padding: 32px var(--gutter) 0; text-align: center; }
  .hero-title { margin-bottom: 10px; font-size: clamp(30px, 8vw, 44px); }
  .hero-copy { margin: 0 auto 20px; font-size: 14px; }
  .wave { height: 36px; margin: 0 0 18px; justify-content: center; -webkit-mask-image: linear-gradient(90deg, transparent, #000 25%, #000 75%, transparent); mask-image: linear-gradient(90deg, transparent, #000 25%, #000 75%, transparent); }
  .spec-list { display: none; }
  .login-card {
    grid-column: 1;
    grid-row: 3;
    align-self: start;
    width: calc(100% - 2 * var(--gutter));
    max-width: 480px;
    margin: 24px auto 40px;
  }

  .docs-wrap { padding-top: 20px; }
  .docs-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .docs-sidebar {
    top: var(--sticky-rail, 64px);
    z-index: 50;
    display: flex;
    gap: 2px;
    margin: 0 calc(-1 * var(--gutter));
    padding: 8px var(--gutter);
    max-height: none;
    overflow-x: auto;
    background: rgba(5, 5, 5, 0.85);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
  }
  #app .docs-sidebar { --sticky-rail: 105px; }
  .docs-sidebar-section { display: contents; }
  .docs-sidebar-title { display: none; }
  .docs-link, .docs-link.active { flex: none; padding: 6px 12px; border: 0; border-radius: 999px; }
  .docs-link.active { background: #fff; color: #000; }
  .doc-section, .docs-intro { scroll-margin-top: calc(var(--sticky) + 56px); }
}

/* Phone: data tables become stacked cards */
@media (max-width: 760px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .analytics-card { min-height: 108px; padding: 12px; }
  .stat-card, .stat-card:nth-child(n + 4) { grid-column: auto; padding: 14px; }
  .module-card { min-height: 148px; }
  .stat-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .portal-link-box { align-items: stretch; flex-direction: column; }
  .portal-actions > * { flex: 1; }
  .portal-notes { grid-template-columns: 1fr; }

  .table-wrap { overflow: visible; }
  #tokens, #accounts { display: block; min-width: 0; }
  #tokens thead, #accounts thead { display: none; }
  #tokens tbody, #accounts tbody { display: block; }
  #tokens tr, #accounts tr { display: block; padding: 8px 14px; border-bottom: 1px solid var(--border); }
  #tokens tr:last-child, #accounts tr:last-child { border-bottom: 0; }
  #tokens td, #accounts td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 36px;
    padding: 5px 0;
    border: 0;
    background: none !important;
    text-align: right;
  }
  #tokens td > *, #accounts td > * { min-width: 0; }
  #tokens td::before, #accounts td::before {
    flex: none;
    font-size: 12px;
    color: var(--text-muted);
  }
  #tokens td:first-child, #accounts td:first-child { display: block; text-align: left; font-size: 15px; }
  #tokens td:first-child::before, #accounts td:first-child::before,
  #tokens td:last-child::before, #accounts td:last-child::before { content: none; }
  #tokens td:last-child, #accounts td:last-child { justify-content: flex-end; }
  #tokens td:last-child:empty, #accounts td:last-child:empty { display: none; }
  #tokens td.empty, #accounts td.empty { display: block; padding: 32px 0; text-align: center; }
  #tokens td.empty::before, #accounts td.empty::before { content: none; }

  #tokens td:nth-child(2)::before { content: "Status"; }
  #tokens td:nth-child(3)::before { content: "Daily quota"; }
  #tokens td:nth-child(4)::before { content: "Expires"; }
  #tokens td:nth-child(5)::before { content: "URL"; }
  #tokens td:nth-child(5) code { max-width: none !important; }
  #accounts td:nth-child(2)::before { content: "Account"; }
  #accounts td:nth-child(3)::before { content: "Tier"; }
  #accounts td:nth-child(4)::before { content: "Region"; }
  #accounts td:nth-child(5)::before { content: "Customer ID"; }
  #accounts td:nth-child(6)::before { content: "Status"; }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    margin: auto 0 0;
    max-width: none;
    border-radius: 20px 20px 0 0;
    border-width: 1px 0 0;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    animation-name: sheet-in;
  }
  .modal-actions button { flex: 1; min-height: 44px; }
  .row:has(> button) > button { flex: 1 1 100%; }
  .toast-container { left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); align-items: center; }

  /* Keeps iOS from zooming on focus */
  input, textarea, select { font-size: 16px; }
}

@media (max-width: 420px) {
  .analytics-grid { grid-template-columns: 1fr; }
}
@keyframes sheet-in { from { transform: translate3d(0, 100%, 0); } to { transform: none; } }

@media (max-width: 480px) {
  .public-nav .brand-badge strong { display: none; }
  .public-nav { height: 60px; }
  .public-nav .mode-switch { flex: 1; }
  .mode-switch button { padding: 7px 8px; font-size: 12.5px; }
  .topbar .muted { display: none; }
  .doc-table td:first-child { width: 42%; }
}

/* Touch: comfortable targets, no hover-only effects */
@media (pointer: coarse) {
  button, .button { min-height: 44px; }
  .copy-btn, button.ghost.danger { min-height: 36px; }
  .preset-chip { min-height: 40px; }
  .mode-switch button { min-height: 36px; }
  .modal-close { min-height: 0; width: 44px; height: 44px; }
  .docs-link { padding-block: 8px; }
}

/* Short landscape screens: don't let the hero push the form away */
@media (max-height: 560px) and (max-width: 920px) {
  .hero { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
