/*
 * Getwebup design system.
 * Light + dark themes via prefers-color-scheme and CSS custom properties.
 * No external fonts or CDNs: system font stacks only.
 *
 * Spacing scale: 4 8 12 16 24 32 48 64 (--space-1 … --space-8). Radius: 8px.
 */

/* ------------------------------------------------------------------ tokens */

:root {
  color-scheme: light dark;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-full: 999px;

  --sidebar-w: 248px;
  --topbar-h: 56px;
  --header-h: 64px;
  --container: 1120px;

  /* surfaces & text */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e7ebf0;
  --row-hover: #f8f9fb;
  --border: #e3e7ed;
  --border-strong: #cfd5de;
  --text: #0f1729;
  --text-2: #344054;
  --muted: #5b6577;

  /* brand / primary (white text on --primary: 6.3:1) */
  --brand: #4f46e5;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-fg: #ffffff;
  --primary-soft: #eef0ff;
  --primary-text: #4338ca;
  --focus: #6366f1;
  --focus-ring: rgba(79, 70, 229, 0.22);

  /* status colours: text / soft background / border */
  --success-text: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --danger-text: #b42318;
  --danger-soft: #fef3f2;
  --danger-border: #fecdca;
  --warning-text: #93370d;
  --warning-soft: #fffaeb;
  --warning-border: #fedf89;
  --warning-bar: #f79009;
  --info-text: #1849a9;
  --info-soft: #eff8ff;
  --info-border: #b2ddff;
  --gray-text: #344054;
  --gray-soft: #f2f4f7;
  --gray-border: #e3e7ed;

  /* code blocks are dark in both themes */
  --code-bg: #0f1729;
  --code-fg: #e6e9f0;
  --code-muted: #8a94a8;
  --code-border: #0f1729;
  --code-btn-bg: rgba(255, 255, 255, 0.07);
  --code-btn-hover: rgba(255, 255, 255, 0.14);

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 16px 40px -12px rgba(16, 24, 40, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14;
    --surface: #121620;
    --surface-2: #181d29;
    --surface-3: #232a3a;
    --row-hover: #151a25;
    --border: #252b3a;
    --border-strong: #353d52;
    --text: #e8ebf2;
    --text-2: #c3c9d6;
    --muted: #949db0;

    --brand: #5850ec;
    --primary: #5850ec;
    --primary-hover: #4f46e5;
    --primary-fg: #ffffff;
    --primary-soft: rgba(99, 102, 241, 0.16);
    --primary-text: #a5b4fc;
    --focus: #818cf8;
    --focus-ring: rgba(129, 140, 248, 0.35);

    --success-text: #75e0a7;
    --success-soft: rgba(23, 178, 106, 0.12);
    --success-border: rgba(23, 178, 106, 0.35);
    --danger: #d92d20;
    --danger-hover: #b42318;
    --danger-text: #fda29b;
    --danger-soft: rgba(240, 68, 56, 0.12);
    --danger-border: rgba(240, 68, 56, 0.38);
    --warning-text: #fec84b;
    --warning-soft: rgba(247, 144, 9, 0.12);
    --warning-border: rgba(247, 144, 9, 0.38);
    --warning-bar: #f79009;
    --info-text: #84caff;
    --info-soft: rgba(46, 144, 250, 0.12);
    --info-border: rgba(46, 144, 250, 0.38);
    --gray-text: #c3c9d6;
    --gray-soft: rgba(148, 157, 176, 0.12);
    --gray-border: rgba(148, 157, 176, 0.28);

    --code-bg: #07090e;
    --code-border: #252b3a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, 0.7);
  }
}

/* -------------------------------------------------------------------- base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 80px;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}

p, ul, ol, dl, figure, blockquote { margin: 0; }
form { margin: 0; }
strong, b { font-weight: 600; }

a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.92em; }
:not(pre) > code, kbd {
  padding: 0.1em 0.4em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-wrap: anywhere;
}

img, svg, video { vertical-align: middle; }
img { max-width: 100%; height: auto; }
.icon { width: 16px; height: 16px; flex: none; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
main:focus { outline: none; }

::selection { background: var(--focus-ring); }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -48px;
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--primary);
  color: var(--primary-fg);
  border-radius: var(--radius);
  font-weight: 600;
}
.skip-link:focus { top: var(--space-2); text-decoration: none; }

/* ------------------------------------------------------------------- brand */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--text); }
.logo-mark { width: 28px; height: 28px; flex: none; }
.logo-bg { fill: var(--brand); }
.wordmark-sub { color: var(--muted); font-weight: 500; margin-left: -4px; }
.brand-sm { font-size: 15px; gap: 8px; }
.brand-sm .logo-mark { width: 22px; height: 22px; }

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

.container {
  width: 100%;
  max-width: var(--container);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
}
.container-narrow { max-width: 484px; }
/* A container nested in another (e.g. a public-style page rendered inside the
   app shell) does not add a second gutter. */
.container .container {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

/* Vertical rhythm for public pages; sections inside the app shell are flush. */
.section { padding: var(--space-8) 0; }
.section-sm { padding: var(--space-6) 0; }
.main .section,
.main .section-sm { padding: 0; }
.section-title {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  letter-spacing: -0.025em;
  text-align: center;
}
.section-sub {
  max-width: 60ch;
  margin: var(--space-2) auto 0;
  color: var(--muted);
  text-align: center;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  flex: none;
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: var(--space-4) var(--space-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) var(--space-5);
}
.brand-tag { margin-left: auto; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  flex: 1;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.nav-link .icon { color: var(--muted); transition: color 0.12s ease; }
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav-link:hover .icon { color: var(--text-2); }
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary-text);
}
.nav-link.active .icon { color: currentColor; }

.sidebar-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.main > main.container {
  flex: 1;
  padding-top: var(--space-6);
  padding-bottom: var(--space-7);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding: 0 var(--space-6);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-weight: 600;
}
.topbar-page {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.topbar-email { max-width: 260px; color: var(--text-2); }
.topbar-plan:hover { text-decoration: none; border-color: var(--primary-text); }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-size: 13px;
  font-weight: 600;
}

.app-footer {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-top: var(--space-4);
  padding-bottom: var(--space-5);
}
.app-footer a.muted:hover { color: var(--text); }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.page-title {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.page-subtitle {
  margin-top: var(--space-1);
  max-width: 72ch;
  color: var(--muted);
}

/* ------------------------------------------------------------- public site */

body.layout-public,
body.layout-auth {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.site-main { flex: 1; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-height: var(--header-h);
}
.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.site-nav a {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}
.site-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.site-nav a.active { color: var(--text); background: var(--surface-2); }
.site-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.hero {
  padding: 96px 0 72px;
  text-align: center;
  background: radial-gradient(ellipse 60% 55% at 50% 0%, var(--primary-soft), transparent 72%);
}
.hero-compact {
  padding: var(--space-7) var(--space-4);
  border-radius: var(--radius);
}
.hero-title {
  max-width: 18ch;
  margin: var(--space-4) auto 0;
  font-size: clamp(32px, 6vw, 56px);
  font-weight: 750;
  line-height: 1.07;
  letter-spacing: -0.035em;
}
.hero-compact .hero-title { font-size: clamp(26px, 4vw, 36px); }
.hero-sub {
  max-width: 60ch;
  margin: var(--space-4) auto 0;
  font-size: clamp(16px, 2.2vw, 19px);
  line-height: 1.6;
  color: var(--muted);
}
.hero .row { justify-content: center; margin-top: var(--space-6); }

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  align-items: stretch;
}
.plan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.plan-card.featured {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow-lg);
}
.plan-ribbon,
.plan-card.featured .plan-ribbon {
  position: absolute;
  top: -11px;
  right: var(--space-4);
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}
.plan-name { font-size: 16px; font-weight: 600; }
.plan-price {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.plan-period {
  margin-left: var(--space-1);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}
.plan-features {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-1) 0 var(--space-2);
  padding: 0;
  list-style: none;
}
.plan-features li {
  position: relative;
  padding-left: 24px;
}
.plan-features li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 0.42em;
  width: 10px;
  height: 5px;
  border-left: 2px solid var(--success-text);
  border-bottom: 2px solid var(--success-text);
  transform: rotate(-45deg);
}

.footer {
  margin-top: var(--space-8);
  padding: 40px 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.footer-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: var(--space-4) var(--space-6);
}
.footer-brand { display: flex; flex-direction: column; gap: var(--space-2); }
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) 20px;
}
.footer-links a { color: var(--muted); font-weight: 500; }
.footer-links a:hover { color: var(--text); }
.footer-copy { grid-column: 1 / -1; }

/* -------------------------------------------------------------------- auth */

.flash-container { padding-top: var(--space-5); }
.flash-container .flashes { margin-bottom: 0; }

.auth-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: 56px var(--space-4) var(--space-8);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.auth-card .form { margin-top: var(--space-5); }
.auth-title {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.auth-title + p { margin-top: var(--space-1); color: var(--muted); }
.auth-foot {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.auth-demo { padding: 0; }
.auth-demo .auth-card { max-width: none; box-shadow: var(--shadow-sm); }

/* ----------------------------------------------------------------- content */

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-3) 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) 20px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}
.card > .table-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.card > .table-wrap:first-child { border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0; }
.card > .table-wrap:last-child { border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px); }
.card > .table-wrap:only-child { border-radius: calc(var(--radius) - 1px); }
.card-danger { border-color: var(--danger-border); }
.card-danger > .card-header { border-bottom-color: var(--danger-border); }
.card-danger .card-title { color: var(--danger-text); }

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

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-5); }

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.row-center { justify-content: center; }
.row-nowrap { flex-wrap: nowrap; }
.row > .input,
.row > .select,
.row > .input-group { flex: 1 1 220px; width: auto; }

.spacer { flex: 1 1 auto; }

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 18px 20px;
}
.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.stat-value {
  font-size: 26px;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-sub {
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--primary-fg);
}
.btn-primary:disabled { background: var(--primary); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #ffffff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled),
.btn-ghost.active {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  gap: 5px;
  font-size: 13px;
}
.btn-sm .icon { width: 14px; height: 14px; }

.btn-block {
  display: flex;
  width: 100%;
}

.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.card > .form { gap: 0; }

.form-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.form-row > .field { flex: 1 1 220px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}
.form-grid > .field-full { grid-column: 1 / -1; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.help {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}
.field-error .help { color: var(--danger-text); }

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.textarea {
  height: auto;
  min-height: 84px;
  padding: var(--space-2) 10px;
  line-height: 1.5;
  resize: vertical;
}
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.input::placeholder,
.textarea::placeholder { color: var(--muted); opacity: 0.8; }
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  background-color: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
.input[readonly] { background-color: var(--surface-2); }
.input[aria-invalid="true"],
.field-error .input,
.field-error .select,
.field-error .textarea { border-color: var(--danger); }
.input[aria-invalid="true"]:focus,
.field-error .input:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.input-sm { height: 30px; font-size: 13px; }

.input-group {
  display: flex;
  min-width: 0;
}
.input-group > .input {
  flex: 1 1 auto;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.input-addon {
  display: flex;
  align-items: center;
  max-width: 60%;
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}
.checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
  accent-color: var(--primary);
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

/* .confirm marks forms that ask for confirmation before submitting; the
   behaviour lives in app.js (with data-confirm="question" for custom text). */
form.confirm { margin: 0; }

/* -------------------------------------------------------------------- data */

.table-wrap {
  position: relative;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table th {
  padding: 10px var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--row-hover); }
.table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.table .actions {
  text-align: right;
  white-space: nowrap;
}
.table .actions > * + * { margin-left: var(--space-1); }
.table td .truncate { max-width: 340px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-full);
  background: var(--gray-soft);
  color: var(--gray-text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
a.badge:hover { text-decoration: none; }
.badge .icon { width: 12px; height: 12px; }
.badge-green { background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.badge-red { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); }
.badge-yellow { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning-text); }
.badge-gray { background: var(--gray-soft); border-color: var(--gray-border); color: var(--gray-text); }
.badge-blue { background: var(--primary-soft); border-color: transparent; color: var(--primary-text); }
.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: 40px var(--space-4);
  text-align: center;
  color: var(--muted);
}
.empty-state > .icon {
  box-sizing: content-box;
  width: 22px;
  height: 22px;
  padding: 11px;
  margin-bottom: var(--space-1);
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.empty-state h3 { color: var(--text); font-size: 15px; font-weight: 600; }
.empty-state p { max-width: 46ch; }
.empty-state .btn { margin-top: var(--space-2); }

.kv {
  display: grid;
  grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  align-items: baseline;
  gap: 10px var(--space-5);
  margin: 0;
}
.kv > :nth-child(odd) { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.truncate {
  display: inline-block;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.text-success { color: var(--success-text); }
.text-danger { color: var(--danger-text); }
.text-warning { color: var(--warning-text); }

/* ---------------------------------------------------------------- feedback */

.flashes {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: 20px;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: var(--space-3) 14px;
  border: 1px solid var(--info-border);
  border-radius: var(--radius);
  background: var(--info-soft);
  color: var(--info-text);
  line-height: 1.5;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.alert > .icon { width: 18px; height: 18px; margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-body a { color: inherit; text-decoration: underline; }
.alert-close {
  display: inline-grid;
  place-items: center;
  flex: none;
  margin: -3px -6px -3px 0;
  padding: 4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
}
.alert-close:hover { opacity: 1; background: rgba(127, 127, 127, 0.14); }
.alert.is-hiding { opacity: 0; transform: translateY(-4px); }
.alert-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.alert-error { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); }
.alert-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info-text); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning-text); }

.progress {
  height: 8px;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: var(--radius-full);
}
.progress-bar {
  width: var(--w, 0%);
  max-width: 100%;
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width 0.4s ease;
}
.progress-bar.warn { background: var(--warning-bar); }
.progress-bar.danger { background: var(--danger); }

.code-block {
  position: relative;
  min-width: 0;
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}
pre.code-block,
.code-block > pre {
  margin: 0;
  padding: 14px var(--space-4);
  overflow-x: auto;
  white-space: pre;
  font-size: 13px;
}
/* leave room for a copy button placed before or after the <pre> */
.code-block > .copy-btn + pre { padding-right: 96px; }
.code-block:has(> .copy-btn) > pre { padding-right: 96px; }
.code-block code {
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font-size: inherit;
}
.code-block .prompt {
  color: var(--code-muted);
  user-select: none;
  -webkit-user-select: none;
}
.code-block .comment { color: var(--code-muted); }

.copy-btn { cursor: pointer; }
.copy-btn:not(.btn) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.copy-btn:not(.btn):hover { background: var(--surface-2); color: var(--text); }
.copy-btn .icon { width: 14px; height: 14px; }
.code-block .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}
.code-block .copy-btn:not(.btn) {
  border-color: rgba(255, 255, 255, 0.14);
  background: var(--code-btn-bg);
  color: var(--code-fg);
}
.code-block .copy-btn:not(.btn):hover { background: var(--code-btn-hover); color: #ffffff; }
.copy-btn.copied,
.copy-btn.copied:hover { color: var(--success-text); }
.code-block .copy-btn.copied { color: #75e0a7; }

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  margin-bottom: -1px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active,
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--primary);
}
.tab-panel { min-width: 0; }

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
  padding-top: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.bar {
  flex: 1 1 0;
  min-width: 3px;
  height: var(--h, 0%);
  min-height: 2px;
  max-height: 100%;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  opacity: 0.72;
  transition: opacity 0.12s ease;
}
.bar:hover,
.bar.today { opacity: 1; }
.bar.muted { background: var(--border-strong); }
.chart-axis {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

/* styleguide helpers */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: var(--space-2);
}
.icon-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  overflow-wrap: anywhere;
}
.icon-cell .icon { width: 20px; height: 20px; }

/* long-form content such as the docs page */
.prose { max-width: 76ch; line-height: 1.7; }
.prose h2 { margin: 40px 0 var(--space-3); font-size: 20px; letter-spacing: -0.015em; }
.prose h3 { margin: 28px 0 var(--space-2); font-size: 16px; }
.prose h2:first-child, .prose h3:first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose .table-wrap { margin: 0 0 14px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li + li { margin-top: var(--space-1); }
.prose .code-block, .prose pre.code-block { margin: var(--space-3) 0 18px; }

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

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .container { padding-left: var(--space-4); padding-right: var(--space-4); }

  /* The sidebar becomes a top navigation bar. */
  .app-shell { flex-direction: column; }
  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    width: auto;
    height: auto;
    overflow: visible;
    padding: var(--space-2) var(--space-4) 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand { flex: 1; min-height: 36px; padding: 0; }
  .sidebar-nav {
    order: 3;
    flex: none;
    flex-direction: row;
    gap: var(--space-1);
    width: calc(100% + 2 * var(--space-4));
    margin: 0 calc(-1 * var(--space-4));
    padding: var(--space-2) var(--space-4) 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-group { flex-direction: row; flex: none; gap: var(--space-1); }
  .nav-section { display: none; }
  .nav-link { padding: 6px 10px; white-space: nowrap; }
  .sidebar-footer { display: none; }

  /* The top bar's user controls join the brand row of the top navigation. */
  .app-shell { position: relative; }
  .brand-tag { margin-left: 0; }
  .topbar {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 5;
    height: 52px;
    padding: 0 var(--space-4);
    background: transparent;
    border-bottom: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .topbar-title { display: none; }
  .main > main.container { padding-top: var(--space-5); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .grid-2,
  .grid-3,
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .page-header { align-items: flex-start; }
  .page-title { font-size: 21px; }
  .card-header,
  .card-footer { padding-left: var(--space-4); padding-right: var(--space-4); }
  .card-body { padding: var(--space-4); }
  .topbar-email { display: none; }

  .site-header-inner {
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    padding-top: 10px;
    padding-bottom: 6px;
  }
  .site-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    margin-left: -10px;
  }
  .footer-inner { grid-template-columns: minmax(0, 1fr); }
  .hero { padding: 64px 0 48px; }
  .auth-wrap { padding-top: var(--space-6); }
  .auth-card { padding: var(--space-5) 20px; }

  /* 16px inputs stop iOS from zooming on focus */
  .input, .select, .textarea { font-size: 16px; }
  .input-sm { font-size: 14px; }
}

@media (max-width: 520px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .topbar-logout-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .wordmark-sub { display: none; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv > :nth-child(even) { margin-bottom: 10px; }
  .code-block > .copy-btn + pre { padding-right: var(--space-4); padding-top: 44px; }
  .code-block:has(> .copy-btn) > pre { padding-right: var(--space-4); padding-top: 44px; }
}

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

@media print {
  .sidebar, .topbar, .site-header, .footer, .app-footer, .copy-btn, .alert-close { display: none !important; }
  body { background: #ffffff; color: #000000; }
  .card, .table-wrap { box-shadow: none; }
}
