/* ==========================================================================
   Velosearch design system
   Hand-rolled, dependency-free CSS. System fonts only (CSP-safe).
   ========================================================================== */

:root {
  --bg: #f6f7fb;
  --bg-tint: radial-gradient(1200px 600px at 100% -10%, #eef0ff 0%, rgba(238, 240, 255, 0) 60%),
             radial-gradient(900px 500px at -10% 0%, #eafff6 0%, rgba(234, 255, 246, 0) 55%);
  --surface: #ffffff;
  --surface-2: #fbfbfe;
  --border: #e6e8f0;
  --border-strong: #d4d7e3;

  --ink: #11131a;
  --ink-2: #3b4256;
  --muted: #6b7283;
  --faint: #9aa0b0;

  --brand: #5048e5;
  --brand-2: #7c3aed;
  --brand-ink: #ffffff;
  --brand-soft: #eef0ff;
  --brand-grad: linear-gradient(135deg, #5048e5 0%, #7c3aed 100%);

  --ok: #0f9d58;
  --ok-soft: #e7f7ee;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --danger: #d6324b;
  --danger-soft: #fdeaed;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;

  --shadow-sm: 0 1px 2px rgba(17, 19, 26, .06), 0 1px 1px rgba(17, 19, 26, .04);
  --shadow: 0 6px 24px -8px rgba(31, 35, 70, .18), 0 2px 6px rgba(31, 35, 70, .06);
  --shadow-lg: 0 24px 60px -20px rgba(31, 35, 70, .35);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;

  --maxw: 1080px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  background-image: var(--bg-tint);
  background-repeat: no-repeat;
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; font-weight: 700; }
h2 { font-size: 1.18rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0 0 .8em; }
a { color: var(--brand); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
small { color: var(--muted); }

code {
  font-family: var(--mono);
  font-size: .86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: .12em .4em;
  border-radius: 6px;
  color: var(--ink-2);
  word-break: break-all;
}

pre {
  font-family: var(--mono);
  font-size: .82rem;
  background: #0f1222;
  color: #d7def0;
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  overflow: auto;
  line-height: 1.5;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05);
}
pre code { background: none; border: 0; color: inherit; padding: 0; }

/* ---- Top bar ----------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, .8);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); font-size: 1.05rem; }
.topbar__brand:hover { text-decoration: none; }
.topbar__spacer { flex: 1; }
.topbar__nav { display: flex; gap: 4px; }
.topbar__nav a { color: var(--muted); font-weight: 550; padding: 6px 11px; border-radius: 8px; font-size: .9rem; }
.topbar__nav a:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.topbar__nav a.is-active { color: var(--brand); background: var(--brand-soft); }
.topbar__meta { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .85rem; }
.topbar__meta strong { color: var(--ink-2); font-weight: 600; }
.topbar form { margin: 0; }

.logo-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--brand-grad);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px rgba(255, 255, 255, .25);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 15px;
}

/* ---- Layout shells ----------------------------------------------------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: clamp(20px, 4vw, 40px); }
.page__head { margin-bottom: 22px; }
.page__head p { color: var(--muted); margin: 0; }

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}
.auth-card {
  width: 100%;
  max-width: 408px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 32px;
}
.auth-card__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 22px; }
.auth-card h1 { font-size: 1.32rem; }
.auth-card .sub { color: var(--muted); margin-top: -.3em; }
.auth-foot { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: .9rem; }
.auth-foot a { font-weight: 600; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; font-size: .9rem; }

/* ---- Cards / sections -------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.card > :last-child { margin-bottom: 0; }
.card__head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card__head h2 { margin: 0; }
.card__head .muted { margin: 0; }

.grid { display: grid; gap: 18px; }
@media (min-width: 720px) { .grid--2 { grid-template-columns: 1fr 1fr; } }

/* ---- Stat cards -------------------------------------------------------- */
.stat-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, 1fr); margin-bottom: 18px; }
@media (min-width: 760px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px;
}
.stat__label { color: var(--muted); font-size: .74rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat__sub { color: var(--faint); font-size: .82rem; margin-top: 2px; }

/* ---- Ranked list (popular searches) ----------------------------------- */
.ranklist { display: flex; flex-direction: column; gap: 14px; }
.rankrow { display: grid; grid-template-columns: 1.4rem 1fr auto; align-items: center; gap: 4px 12px; }
.rankrow__n { color: var(--faint); font-size: .85rem; text-align: right; font-variant-numeric: tabular-nums; }
.rankrow__q { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rankrow__count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.rankrow__bar { grid-column: 2 / 4; height: 6px; border-radius: 999px; background: var(--brand-soft); overflow: hidden; }
.rankrow__bar > span { display: block; height: 100%; background: var(--brand-grad); border-radius: 999px; }

.muted { color: var(--muted); }
.stack > * + * { margin-top: 12px; }

/* ---- Forms ------------------------------------------------------------- */
form { margin: 0; }
.field { display: block; margin-bottom: 14px; }
.field > label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="url"], input[type="number"], input[type="search"], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

/* Buttons — covers form.submit (input[type=submit]) and button_to (button) */
button, input[type="submit"], .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  padding: 10px 16px;
  background: var(--brand-grad);
  color: var(--brand-ink);
  box-shadow: var(--shadow-sm);
  transition: transform .04s ease, filter .15s, background .15s, border-color .15s;
  text-decoration: none;
}
button:hover, input[type="submit"]:hover, .btn:hover { filter: brightness(1.06); text-decoration: none; }
button:active, input[type="submit"]:active, .btn:active { transform: translateY(1px); }
input[type="submit"] { width: 100%; }

.btn--block { width: 100%; }
.btn--secondary, button.btn--secondary {
  background: var(--surface); color: var(--ink-2);
  border-color: var(--border-strong); box-shadow: var(--shadow-sm);
}
.btn--secondary:hover { background: var(--surface-2); filter: none; }
.btn--danger, button.btn--danger { background: var(--danger); }
.btn--ghost, button.btn--ghost {
  background: transparent; color: var(--brand); box-shadow: none; border-color: transparent; padding-inline: 4px;
}

/* ---- Badges ------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 650; letter-spacing: .01em;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--active { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge--pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---- Flash ------------------------------------------------------------- */
.flash-stack { max-width: var(--maxw); margin: 16px auto -4px; padding: 0 clamp(20px, 4vw, 40px); }
.auth-shell .flash-stack { max-width: 408px; margin: 0 auto 14px; padding: 0; }
.flash {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: .9rem;
  font-weight: 500;
  border: 1px solid transparent;
  margin-bottom: 10px;
}
.flash--notice { background: var(--ok-soft); color: #0b7a45; border-color: #c7ecd6; }
.flash--alert { background: var(--danger-soft); color: #b21f37; border-color: #f6cdd5; }

/* ---- Definition rows (key/value) -------------------------------------- */
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; color: var(--ink-2); }

/* ---- Callout (one-time secrets) --------------------------------------- */
.callout {
  border: 1px solid #d9d6ff;
  background: linear-gradient(180deg, #f7f6ff, #fdfdff);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.callout h2 { color: var(--brand); }
.callout .kv dd code { width: 100%; display: inline-block; }

/* ---- Integration list -------------------------------------------------- */
.conn {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--surface-2);
}
.conn + .conn { margin-top: 10px; }
.conn__id { font-weight: 650; }
.conn__meta { color: var(--muted); font-size: .85rem; }
.conn__spacer { flex: 1; }

.empty { text-align: center; color: var(--muted); padding: 22px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }

ul.clean { margin: 0; padding-left: 1.1em; }
ul.clean li { margin-bottom: 4px; }

.errors { background: var(--danger-soft); border: 1px solid #f6cdd5; color: #9f1c33; border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; }
.errors p { font-weight: 600; margin: 0 0 6px; }
.errors ul { margin: 0; padding-left: 1.1em; }

.toolbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.toolbar .field { margin-bottom: 0; }
.field--grow { flex: 1; min-width: 220px; }
.field--narrow { width: 140px; }
