/*
 * BioLink design system.
 *
 * Handwritten rather than generated by Tailwind, so the server needs no Node
 * toolchain and no build step — the whole front end is this file plus one small
 * script. That is what lets the app deploy by extracting a ZIP on ordinary
 * shared hosting.
 *
 * Public bio pages do NOT use these tokens: they render from the creator's own
 * theme via inline custom properties (see ThemeManager).
 */

/* --- Reset ------------------------------------------------------------- */

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

* { margin: 0; }

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

body {
  font-family: var(--font-sans);
  background: rgb(var(--c-bg));
  color: rgb(var(--c-fg));
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

img, svg, video { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }
table { border-collapse: collapse; width: 100%; }

:focus-visible {
  outline: 2px solid rgb(var(--c-brand));
  outline-offset: 2px;
}

::selection { background: rgb(var(--c-brand) / 0.2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Tokens ------------------------------------------------------------ */

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
    'Helvetica Neue', 'Noto Sans', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --c-bg: 247 248 251;
  --c-surface: 255 255 255;
  --c-border: 226 230 238;
  --c-muted: 102 112 133;
  --c-fg: 16 24 40;
  --c-brand: 54 94 245;
  --c-brand-dark: 33 63 224;
  --c-brand-soft: 238 244 255;

  --c-success: 5 150 105;
  --c-danger: 220 38 38;
  --c-warning: 217 119 6;

  /* Chart slots, validated for colour-vision deficiency against the white card
     surface: CVD ΔE 24.7, normal-vision ΔE 33.6, both ≥ 3:1 contrast. */
  --viz-1: #2a78d6;   /* clicks */
  --viz-2: #eb6834;   /* views  */
  --viz-grid: #e6e7ea;
  --viz-axis: #c3c2b7;
  --viz-muted: #898781;

  --radius: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 2px rgb(16 24 40 / 0.04), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow-lift: 0 12px 32px -8px rgb(16 24 40 / 0.16), 0 4px 12px -4px rgb(16 24 40 / 0.08);
}

/* --- Utilities --------------------------------------------------------- */

.wrap { width: 100%; max-width: 1152px; margin: 0 auto; padding: 0 20px; }
.stack > * + * { margin-top: var(--gap, 16px); }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.shrink-0 { flex-shrink: 0; }
.hide { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.text-muted { color: rgb(var(--c-muted)); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.mono { font-family: var(--font-mono); }
.center { text-align: center; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.mb-6 { margin-bottom: 24px; }

/* --- Typography -------------------------------------------------------- */

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; font-weight: 700; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.page-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  justify-content: space-between; margin-bottom: 24px; }
.page-head p { margin-top: 4px; color: rgb(var(--c-muted)); font-size: 15px; }

/* --- Cards ------------------------------------------------------------- */

.card {
  background: rgb(var(--c-surface));
  border: 1px solid rgb(var(--c-border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  min-width: 0;                     /* so a card in a grid can shrink */
}
.card-pad { padding: 20px; }
.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid rgb(var(--c-border));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 20px; }

/* --- Grids ------------------------------------------------------------- */

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

/*
 * Auto-fitting columns that never force the page wider than the viewport.
 *
 * A bare `minmax(320px, 1fr)` sets a hard 320px floor, so on a 320px phone the
 * column plus the page padding overflows and the whole page scrolls sideways.
 * `min(320px, 100%)` lets the track collapse to the available width instead.
 */
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid-auto-sm { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) {
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .grid-manage { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 899px) {
  .grid-main, .grid-manage { grid-template-columns: minmax(0, 1fr); }
}

/* --- Stat tiles -------------------------------------------------------- */

.stat { padding: 18px; }
.stat-label {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: rgb(var(--c-muted));
}
.stat-value { font-size: 28px; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; }
.stat-hint { font-size: 13px; color: rgb(var(--c-muted)); margin-top: 4px; }
.trend-up { color: rgb(var(--c-success)); font-weight: 600; }
.trend-down { color: rgb(var(--c-danger)); font-weight: 600; }

/* --- Buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius); padding: 10px 16px;
  font-size: 15px; font-weight: 600;
  transition: background-color .15s, border-color .15s, transform .1s, opacity .15s;
  border: 1px solid transparent; white-space: nowrap;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }

.btn-primary { background: rgb(var(--c-brand)); color: #fff; }
.btn-primary:hover { background: rgb(var(--c-brand-dark)); }

.btn-secondary {
  background: rgb(var(--c-surface));
  border-color: rgb(var(--c-border));
  color: rgb(var(--c-fg));
}
.btn-secondary:hover { background: rgb(var(--c-bg)); }

.btn-ghost { color: rgb(var(--c-muted)); }
.btn-ghost:hover { background: rgb(var(--c-bg)); color: rgb(var(--c-fg)); }

.btn-danger { background: rgb(var(--c-danger)); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }

.btn-link-danger { color: rgb(var(--c-danger)); }
.btn-link-danger:hover { background: #fef2f2; }

/* --- Forms ------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid rgb(var(--c-border));
  background: rgb(var(--c-surface));
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: rgb(var(--c-brand));
  box-shadow: 0 0 0 4px rgb(var(--c-brand) / 0.1);
}
.textarea { min-height: 90px; resize: vertical; }
.input-sm { padding: 7px 12px; font-size: 13.5px; }
.hint { font-size: 13px; color: rgb(var(--c-muted)); margin-top: 6px; }
.error-text { font-size: 13px; color: rgb(var(--c-danger)); font-weight: 500; margin-top: 6px; }

/* URL prefix + input, joined into one control. */
.input-group { display: flex; border: 1px solid rgb(var(--c-border));
  border-radius: var(--radius); overflow: hidden; }
.input-group:focus-within { border-color: rgb(var(--c-brand));
  box-shadow: 0 0 0 4px rgb(var(--c-brand) / 0.1); }
.input-group .prefix {
  background: rgb(var(--c-bg)); padding: 10px 12px; font-size: 13.5px;
  color: rgb(var(--c-muted)); white-space: nowrap; display: flex; align-items: center;
}
.input-group input { border: 0; border-radius: 0; flex: 1; min-width: 0; }
.input-group input:focus { box-shadow: none; }

.checkbox-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.checkbox-row input { margin-top: 3px; width: 16px; height: 16px; flex-shrink: 0; accent-color: rgb(var(--c-brand)); }

/* --- Alerts ------------------------------------------------------------ */

.alert { border-radius: var(--radius); padding: 12px 14px; font-size: 14px;
  font-weight: 500; margin-bottom: 16px; border: 1px solid transparent; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* --- Badges ------------------------------------------------------------ */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600;
}
.badge-active { background: rgb(var(--c-success) / .1); color: rgb(var(--c-success)); }
.badge-disabled { background: rgb(100 116 139 / .12); color: #475569; }
.badge-brand { background: rgb(var(--c-brand) / .1); color: rgb(var(--c-brand-dark)); }
.badge-admin { background: rgb(245 158 11 / .16); color: #b45309; }
.badge-danger { background: rgb(var(--c-danger) / .1); color: rgb(var(--c-danger)); }
.dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

.code-chip {
  display: inline-flex; border-radius: 6px; padding: 2px 7px;
  background: rgb(var(--c-fg) / .06); font-family: var(--font-mono);
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
}

/* --- App shell (dashboard + admin) ------------------------------------- */

.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 30;
  background: rgb(var(--c-surface)); border-right: 1px solid rgb(var(--c-border));
  display: flex; flex-direction: column;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 20px; }
.sidebar-nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.sidebar-foot { border-top: 1px solid rgb(var(--c-border)); padding: 12px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; color: rgb(var(--c-muted));
  transition: background-color .15s, color .15s;
}
.nav-item:hover { background: rgb(var(--c-bg)); color: rgb(var(--c-fg)); }
.nav-item.active { background: rgb(var(--c-brand) / .1); color: rgb(var(--c-brand-dark)); }

.main { padding: 24px 0 48px; }
.topbar {
  display: none; position: sticky; top: 0; z-index: 20; height: 56px;
  align-items: center; gap: 12px; padding: 0 16px;
  background: rgb(var(--c-surface) / .9); backdrop-filter: blur(8px);
  border-bottom: 1px solid rgb(var(--c-border));
}

@media (min-width: 1024px) {
  .shell-inner { padding-left: 248px; }
}
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: 270px; }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .scrim { position: fixed; inset: 0; background: rgb(15 23 42 / .5); z-index: 25; }
}

.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  background: rgb(var(--c-brand)); color: #fff;
  display: flex; align-items: center; justify-content: center;
}

.avatar-initial {
  border-radius: 999px; background: rgb(var(--c-brand) / .15);
  color: rgb(var(--c-brand-dark)); font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* --- Lists / rows ------------------------------------------------------ */

.divide > li + li,
.divide > .row-item + .row-item { border-top: 1px solid rgb(var(--c-border)); }
.row-item { display: flex; align-items: center; gap: 12px; padding: 14px 20px; }

.empty { padding: 56px 24px; text-align: center; }
.empty-icon {
  width: 56px; height: 56px; border-radius: var(--radius-lg); margin: 0 auto 16px;
  background: rgb(var(--c-brand) / .1); color: rgb(var(--c-brand));
  display: flex; align-items: center; justify-content: center;
}
.empty h3 { font-size: 16px; }
.empty p { color: rgb(var(--c-muted)); font-size: 14px; margin: 6px auto 0; max-width: 380px; }

/* --- Link manager rows ------------------------------------------------- */

.link-row { display: flex; align-items: center; gap: 14px; padding: 14px; }
.link-row.dragging { opacity: .5; }
.link-row.drag-over { border-color: rgb(var(--c-brand)); }
.drag-handle {
  cursor: grab; color: rgb(var(--c-muted)); padding: 6px; border-radius: 8px;
  flex-shrink: 0; touch-action: none;
}
.drag-handle:hover { background: rgb(var(--c-bg)); color: rgb(var(--c-fg)); }
.drag-handle:active { cursor: grabbing; }

.icon-chip {
  border-radius: var(--radius); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

/* --- Tabs / segmented -------------------------------------------------- */

.segmented {
  display: flex; gap: 4px; padding: 4px; border-radius: var(--radius);
  background: rgb(var(--c-bg)); overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button, .segmented a {
  flex: 1; padding: 7px 12px; border-radius: 9px; font-size: 13px;
  font-weight: 600; color: rgb(var(--c-muted)); white-space: nowrap; text-align: center;
}
.segmented button.active, .segmented a.active {
  background: rgb(var(--c-surface)); color: rgb(var(--c-fg)); box-shadow: var(--shadow-card);
}

/* --- Progress bar (link share) ----------------------------------------- */

.bar { height: 6px; border-radius: 999px; background: rgb(var(--c-bg)); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--viz-1); }

/* --- Modal ------------------------------------------------------------- */

dialog.modal {
  border: 0; padding: 0; background: transparent;
  max-width: 100%; max-height: 100%; width: 100%; height: 100%;
}
dialog.modal::backdrop { background: rgb(15 23 42 / .5); backdrop-filter: blur(2px); }
.modal-shell { display: flex; align-items: flex-end; justify-content: center;
  min-height: 100%; padding: 0; }
.modal-panel {
  background: rgb(var(--c-surface)); width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow-lift);
  display: flex; flex-direction: column; max-height: 92vh;
  animation: slide-up .22s cubic-bezier(.16,1,.3,1);
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid rgb(var(--c-border));
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 16px 20px; border-top: 1px solid rgb(var(--c-border));
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (min-width: 640px) {
  .modal-shell { align-items: center; padding: 16px; }
  .modal-panel { border-radius: var(--radius-lg); }
}
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* --- Toast ------------------------------------------------------------- */

.toast-area {
  position: fixed; inset: auto 0 0 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px;
  pointer-events: none;
}
@media (min-width: 640px) { .toast-area { inset: 0 0 auto auto; align-items: flex-end; } }
.toast {
  pointer-events: auto; border-radius: var(--radius); padding: 12px 16px;
  font-size: 14px; font-weight: 500; color: #fff; box-shadow: var(--shadow-lift);
  max-width: 380px; animation: slide-up .22s cubic-bezier(.16,1,.3,1);
}
.toast-success { background: rgb(var(--c-success)); }
.toast-error { background: rgb(var(--c-danger)); }

/* --- Icon picker ------------------------------------------------------- */

.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
@media (min-width: 520px) { .icon-grid { grid-template-columns: repeat(8, 1fr); } }
.icon-opt {
  aspect-ratio: 1; border-radius: 9px; border: 1px solid transparent;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.icon-opt:hover { border-color: rgb(var(--c-border)); background: rgb(var(--c-bg)); }
.icon-opt.selected {
  border-color: rgb(var(--c-brand)); background: rgb(var(--c-brand) / .1);
  box-shadow: 0 0 0 2px rgb(var(--c-brand) / .25);
}
.icon-scroll { max-height: 260px; overflow-y: auto; border: 1px solid rgb(var(--c-border));
  border-radius: var(--radius); padding: 12px; }
.icon-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: rgb(var(--c-muted)); margin-bottom: 8px;
}

/* --- Theme preset picker ----------------------------------------------- */

.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-opt { border: 2px solid transparent; border-radius: var(--radius); padding: 6px; }
.theme-opt.selected { border-color: rgb(var(--c-brand)); }
.theme-swatch { height: 44px; border-radius: 9px; padding: 6px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.theme-swatch span { display: block; height: 7px; border-radius: 3px; }

/* --- Pagination -------------------------------------------------------- */

.pagination { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pagination a, .pagination span {
  padding: 6px 11px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 1px solid rgb(var(--c-border)); color: rgb(var(--c-muted));
}
.pagination .active span { background: rgb(var(--c-brand)); border-color: rgb(var(--c-brand)); color: #fff; }
.pagination .disabled span { opacity: .45; }

/* --- Auth pages -------------------------------------------------------- */

.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; }
.auth-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0 20px 64px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-title { text-align: center; margin-bottom: 24px; }
.auth-title h1 { font-size: 24px; }
.auth-title p { color: rgb(var(--c-muted)); margin-top: 6px; font-size: 15px; }

/* --- Marketing --------------------------------------------------------- */

.hero { padding: 40px 0 56px; }
.hero h1 { font-size: 34px; line-height: 1.12; }
.hero p { font-size: 17px; color: rgb(var(--c-muted)); margin-top: 16px; max-width: 30em; }
@media (min-width: 900px) {
  .hero h1 { font-size: 46px; }
  .hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 56px; align-items: center; }
}
.feature { border: 1px solid rgb(var(--c-border)); border-radius: var(--radius-lg); padding: 20px; }
.feature h3 { font-size: 15.5px; }
.feature p { color: rgb(var(--c-muted)); font-size: 14px; margin-top: 6px; }
.cta {
  border-radius: 24px; background: rgb(var(--c-brand)); color: #fff;
  padding: 48px 24px; text-align: center;
}
.cta h2 { font-size: 26px; color: #fff; }
.cta p { color: rgb(var(--c-brand-soft)); margin-top: 10px; }

/* Phone mock on the marketing page — the product's real output, not stock art. */
.phone { max-width: 320px; margin: 0 auto; border: 10px solid #0f172a;
  border-radius: 36px; background: #0f172a; }
.phone-screen { border-radius: 26px; padding: 24px 16px;
  background: linear-gradient(175deg,#0b1020,#141b45 55%,#1c2a71); }
.phone-card {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid rgb(255 255 255 / .15); background: rgb(255 255 255 / .07);
  border-radius: var(--radius); margin-top: 8px;
}

/* --- Chart ------------------------------------------------------------- */

.chart-wrap { position: relative; width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 12px; align-items: baseline; }
.legend-item { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 999px; transform: translateY(1px); }
.chart-table { max-height: 220px; overflow: auto; border: 1px solid rgb(var(--c-border));
  border-radius: 10px; margin-top: 8px; }
.chart-table th, .chart-table td { padding: 6px 12px; font-size: 13px; text-align: left; }
.chart-table thead { position: sticky; top: 0; background: rgb(var(--c-bg)); }
.chart-table tbody tr + tr { border-top: 1px solid rgb(var(--c-border)); }

/* --- Tables (admin) ---------------------------------------------------- */

.table-scroll { overflow-x: auto; }
.data-table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: rgb(var(--c-muted)); padding: 10px 20px;
  border-bottom: 1px solid rgb(var(--c-border)); white-space: nowrap;
}
.data-table td { padding: 12px 20px; font-size: 14px; vertical-align: middle; }
.data-table tbody tr + tr td { border-top: 1px solid rgb(var(--c-border)); }
