/* ============================================================
   ARBOX app styles — tokens, shell and shared components.
   The only place these classes are defined: page stylesheets
   (home.css, arbox.css, editor.css) may position and size them,
   never restyle their look. Colours come from the tokens below.
   ============================================================ */

:root {
  /* NEST GUI palette */
  --primary: #5ecbff;
  --primary-dark: #3fb2ff;
  --secondary: #6b5cff;
  --accent: #ff8bb8;
  --background: #070b17;
  --surface: #10162c;
  --surface-light: #182043;
  --surface-hover: #222b58;
  --text: #fff;
  --text-secondary: #a7b0d1;
  --text-muted: #6d7696;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --border: rgba(255, 255, 255, .08);
  --border-light: rgba(255, 255, 255, .12);
  --shadow: 0 4px 24px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, .5);
  --gradient-soft: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  --glass: rgba(255, 255, 255, .03);
  --card-surface: rgba(16, 22, 44, .76);
  --card-surface-strong: rgba(12, 18, 36, .82);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;

  /* Channels for translucent tints: rgba(var(--primary-rgb), .2) */
  --primary-rgb: 94, 203, 255;
  --secondary-rgb: 107, 92, 255;
  --success-rgb: 16, 185, 129;
  --warning-rgb: 245, 158, 11;
  --error-rgb: 239, 68, 68;
  --ink-rgb: 7, 11, 23;
  --white-rgb: 255, 255, 255;

  /* Readable status text on dark surfaces */
  --success-text: #6ee7b7;
  --warning-text: #fcd34d;
  --error-text: #fca5a5;

  --focus-ring: 0 0 0 3px rgba(var(--primary-rgb), .25);
  --focus-ring-error: 0 0 0 3px rgba(var(--error-rgb), .25);
  --glow: 0 0 28px rgba(var(--primary-rgb), .18);
  --popover-surface: rgba(16, 22, 44, .97);
  --modal-surface: linear-gradient(160deg, rgba(20, 27, 54, .98) 0%, rgba(12, 18, 36, .98) 100%);
  --overlay: rgba(3, 6, 16, .62);
  --footer-bg: rgba(10, 14, 28, .86);
  --scrollbar: rgba(var(--white-rgb), .14);

  --ease: cubic-bezier(.2, .7, .2, 1);
  --t-fast: 150ms;
  --t: 200ms;
}

/* ── Base ─────────────────────────────────────────────────────── */

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

html { height: 100%; }

[hidden] { display: none !important; }

body.app-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--background);
  color: var(--text);
  font-family: var(--ui-font-family);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scrollbar-color: var(--scrollbar) transparent;
  scrollbar-width: thin;
}

/* NEST background: cyan glow top-left, indigo bottom-right, deep navy wash */
body.app-page::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 760px at 6% -10%, rgba(var(--primary-rgb), .22) 0%, transparent 60%),
    radial-gradient(900px 640px at 94% 110%, rgba(var(--secondary-rgb), .16) 0%, transparent 65%),
    radial-gradient(700px 420px at 50% 30%, rgba(var(--secondary-rgb), .10) 0%, transparent 70%),
    linear-gradient(160deg, rgba(7, 10, 24, .98) 0%, rgba(12, 16, 36, .96) 45%, rgba(6, 9, 20, .99) 100%);
}

#mycelium {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.app-page ::selection { background: rgba(var(--primary-rgb), .32); color: var(--text); }

/* :where() keeps these base rules at single-class specificity, so component rules (.btn-*, .x:focus-visible) win. */
.app-page :where(:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

.app-page h1, .app-page h2, .app-page h3, .app-page p { margin: 0; }

/* Links are blue — except the header's .ch-link pills (Explore is the only <a> among them), which take the header's
   own grey / white-on-hover like the API and Logout buttons beside them. */
.app-page :where(a:not(.ch-link)) { color: var(--primary); }

.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;
}

.muted { color: var(--text-muted); }

/* ── Shell ────────────────────────────────────────────────────── */

.app-shell {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  /* minmax(0, 1fr): the header's widest content (its nav scrolls itself) never widens the page past the viewport. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.app-main {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.app-footer {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-size: 11px;
  letter-spacing: .02em;
  color: var(--text-muted);
  background: var(--footer-bg);
  border-top: 1px solid var(--border);
  white-space: nowrap;
}

/* ── Header additions ─────────────────────────────────────────── */

.ch-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  height: 32px;
  margin-right: 6px;
  padding: 3px 12px 3px 3px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  flex: 0 1 auto;
  min-width: 0;
}

.ch-user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  background: var(--gradient-soft);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-shadow: 0 1px 2px rgba(var(--ink-rgb), .45);
  box-shadow: 0 0 0 2px rgba(var(--ink-rgb), .6), 0 0 14px rgba(var(--primary-rgb), .25);
}

.ch-user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-link.ch-back {
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text-secondary);
}

.ch-link.ch-back:hover {
  color: var(--text);
  border-color: rgba(var(--primary-rgb), .35);
  background: rgba(var(--primary-rgb), .08);
}

/* → Sign in (signed-out visitors on pages anyone may read) */
.ch-link.ch-signin {
  margin-left: 4px;
  padding: 6px 12px;
  border: 1px solid rgba(var(--primary-rgb), .42);
  background: rgba(var(--primary-rgb), .1);
  color: var(--text);
}

.ch-link.ch-signin:hover {
  border-color: rgba(var(--primary-rgb), .7);
  background: rgba(var(--primary-rgb), .2);
  box-shadow: var(--glow);
}

@media (max-width: 540px) {
  .ch-user { padding: 3px; margin-right: 2px; }
  .ch-user-name { display: none; }
  .ch-link.ch-signin { margin-left: 2px; padding: 7px 9px; }
}

/* ── Icons ────────────────────────────────────────────────────── */

/* Every UI icon: a line drawing from /assets/icons.svg (<svg class="ic"><use href="…#name"/></svg>, or
   Arbox.ui.icon(name)), 1.15em square, in the one ARBOX gold whatever the text colour around it. The stroke is set
   here, never in the sprite, so the whole set shares one weight. Size variants: .ic-sm (status dots, meta lines),
   .ic-lg (empty states). */
svg.ic {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  display: inline-block;
  vertical-align: -0.2em;
  color: var(--arbox-gold);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}
svg.ic.ic-sm { width: 1em; height: 1em; vertical-align: -0.14em; }
svg.ic.ic-lg { width: 1.6em; height: 1.6em; }

/* Blue buttons: on the brand gradient the icon is white like the label — gold on blue reads badly. */
.btn-primary svg.ic { color: #fff; }

/* A busy button shows its spinner in place of the icon; an icon-only one shows the spinner alone. */
.btn.is-busy > .ic { display: none; }
.btn-icon.is-busy:not(.btn) .ic { visibility: hidden; }

/* ── Buttons ──────────────────────────────────────────────────── */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: 600 13px/1 var(--ui-font-family);
  letter-spacing: .01em;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--t) ease, border-color var(--t) ease, color var(--t) ease,
    box-shadow var(--t) ease, transform var(--t-fast) ease, filter var(--t) ease, opacity var(--t) ease;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--gradient-soft);
  color: var(--text);
  text-shadow: 0 1px 2px rgba(var(--ink-rgb), .25);
  box-shadow: 0 4px 16px rgba(var(--primary-rgb), .2), inset 0 1px 0 rgba(var(--white-rgb), .18);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08) saturate(1.05);
  box-shadow: 0 6px 22px rgba(var(--secondary-rgb), .38), inset 0 1px 0 rgba(var(--white-rgb), .22);
}

.btn-secondary {
  background: var(--glass);
  border-color: var(--border-light);
  color: var(--text-secondary);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(var(--primary-rgb), .08);
  border-color: rgba(var(--primary-rgb), .35);
  color: var(--text);
}

.btn-danger {
  background: rgba(var(--error-rgb), .14);
  border-color: rgba(var(--error-rgb), .4);
  color: var(--error-text);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(var(--error-rgb), .26);
  border-color: rgba(var(--error-rgb), .6);
  color: var(--text);
  box-shadow: 0 4px 18px rgba(var(--error-rgb), .22);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(var(--white-rgb), .06);
  color: var(--text);
}

.btn-sm {
  height: 30px;
  padding: 0 11px;
  gap: 5px;
  font-size: 12px;
  border-radius: 8px;
}

/* Icon-only button; complete on its own or combined with .btn */
.btn-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  flex: none;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: 500 15px/1 var(--ui-font-family);
  cursor: pointer;
  transition: background-color var(--t) ease, border-color var(--t) ease, color var(--t) ease, opacity var(--t) ease;
}

.btn-icon:hover:not(:disabled),
.btn-icon[aria-expanded="true"] {
  background: rgba(var(--white-rgb), .08);
  color: var(--text);
}

.btn.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 28px; height: 28px; font-size: 13px; border-radius: 7px; }

.btn:disabled,
.btn-icon:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
  filter: none;
}

/* Busy: a .spinner child shows; without one, the button draws its own ring */
.btn .spinner { display: none; }
.btn.is-busy .spinner { display: inline-block; }
.btn.is-busy,
.btn-icon.is-busy { pointer-events: none; }
.btn.is-busy:disabled { opacity: .8; }

.btn.is-busy:not(:has(> .spinner))::before {
  content: '';
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 50%;
  border: 2px solid rgba(var(--white-rgb), .25);
  border-top-color: currentColor;
  animation: arbox-spin .7s linear infinite;
}

.btn-icon.is-busy:not(.btn) { color: transparent; }
.btn-icon.is-busy:not(.btn)::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(var(--white-rgb), .2);
  border-top-color: var(--primary);
  animation: arbox-spin .7s linear infinite;
}

/* ── Forms ────────────────────────────────────────────────────── */

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

.form-field + .form-field { margin-top: 16px; }

.form-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--text-secondary);
}

.form-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.form-input,
.form-textarea {
  display: block;
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: rgba(var(--ink-rgb), .45);
  color: var(--text);
  font: 400 14px/1.4 var(--ui-font-family);
  outline: none;
  transition: border-color var(--t) ease, box-shadow var(--t) ease, background-color var(--t) ease;
}

.form-textarea {
  height: auto;
  min-height: 88px;
  padding: 10px 12px;
  line-height: 1.5;
  resize: vertical;
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-input:hover:not(:disabled):not(:focus),
.form-textarea:hover:not(:disabled):not(:focus) { border-color: rgba(var(--white-rgb), .2); }

.form-input:focus,
.form-textarea:focus,
.form-input:focus-visible,
.form-textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  background: rgba(var(--ink-rgb), .6);
  box-shadow: var(--focus-ring);
}

.form-input[aria-invalid="true"],
.form-textarea[aria-invalid="true"] { border-color: rgba(var(--error-rgb), .7); }

.form-input[aria-invalid="true"]:focus,
.form-textarea[aria-invalid="true"]:focus { border-color: var(--error); box-shadow: var(--focus-ring-error); }

.form-input:disabled,
.form-textarea:disabled { opacity: .55; cursor: not-allowed; }

/* Keep browser autofill on the dark surface */
.form-input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  box-shadow: 0 0 0 1000px var(--surface-light) inset;
  transition: background-color 9999s ease 0s;
}
.form-input:-webkit-autofill:focus { box-shadow: 0 0 0 1000px var(--surface-light) inset, var(--focus-ring); }

/* An input with a trailing icon button (e.g. show password) */
.form-input-wrap { position: relative; }
.form-input-wrap .form-input { padding-right: 44px; }
.form-input-wrap .btn-icon {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
}

.form-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(var(--error-rgb), .32);
  background: rgba(var(--error-rgb), .1);
  color: var(--error-text);
  font-size: 12.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.form-error::before {
  content: '!';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  border-radius: 50%;
  background: rgba(var(--error-rgb), .85);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.form-error:empty { display: none; }

/* ── Cards ────────────────────────────────────────────────────── */

.section-card {
  position: relative;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Element-qualified on purpose: app.css resets margins with `.app-page h1, h2, h3, p`, which
   outranks a lone class — an unqualified selector here would silently have no margin at all. */
h1.section-title,
h3.section-title,
p.section-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--primary);
}

/* ── Spinner ──────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex: none;
  vertical-align: middle;
  border-radius: 50%;
  border: 2px solid rgba(var(--white-rgb), .16);
  border-top-color: var(--primary);
  border-right-color: rgba(var(--secondary-rgb), .9);
  animation: arbox-spin .7s linear infinite;
}

.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

@keyframes arbox-spin { to { transform: rotate(360deg); } }

/* ── Toasts ───────────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  --toast-rgb: var(--primary-rgb);
  --toast-color: var(--primary);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 12px 10px 13px 14px;
  overflow: hidden;
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--toast-color);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(var(--toast-rgb), .14) 0%, transparent 60%),
    var(--popover-surface);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  pointer-events: auto;
  animation: toast-in var(--t) var(--ease);
  transition: opacity var(--t) ease, transform var(--t) var(--ease);
}

.toast-success { --toast-rgb: var(--success-rgb); --toast-color: var(--success); }
.toast-error   { --toast-rgb: var(--error-rgb);   --toast-color: var(--error); }
.toast-warning { --toast-rgb: var(--warning-rgb); --toast-color: var(--warning); }
.toast-info    { --toast-rgb: var(--primary-rgb); --toast-color: var(--primary); }

.toast.is-leaving { opacity: 0; transform: translateX(24px); }

.toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(var(--toast-rgb), .18);
  color: var(--toast-color);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.toast-message {
  padding-top: 2px;
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.toast-close:hover { background: rgba(var(--white-rgb), .08); color: var(--text); }

.toast-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--toast-color);
  opacity: .55;
  transform-origin: left center;
  animation: toast-progress linear forwards;
}

.toast.is-paused .toast-progress { animation-play-state: paused; }

@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

@media (max-width: 540px) {
  .toast-stack { top: 60px; right: 8px; width: calc(100vw - 16px); }
}

/* ── Modal ────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in var(--t) ease;
}

.modal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: hidden;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--modal-surface);
  box-shadow: var(--shadow-lg), 0 30px 80px rgba(0, 0, 0, .35);
  outline: none;
  animation: modal-in var(--t) var(--ease);
}

/* NEST hairline across the top edge */
.modal-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(var(--primary-rgb), .7), rgba(var(--secondary-rgb), .7), transparent);
  pointer-events: none;
}

.modal-card.modal-confirm { width: min(440px, 100%); }

.modal-backdrop.is-closing { animation: fade-out var(--t) ease forwards; }
.modal-backdrop.is-closing .modal-card { animation: modal-out var(--t) ease forwards; }

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 12px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.005em;
}

.modal-body {
  min-height: 0;
  padding: 18px 20px 20px;
  overflow: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: rgba(var(--ink-rgb), .3);
}

.confirm-message {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }

@media (max-width: 540px) {
  .modal-backdrop { padding: 12px; }
  .modal-card { max-height: calc(100dvh - 24px); }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px 14px; }
  .modal-footer .btn { flex: 1 1 0; }
}

/* ── Menu ─────────────────────────────────────────────────────── */

.menu {
  position: fixed;
  z-index: 2500;
  min-width: 184px;
  max-width: min(300px, calc(100vw - 16px));
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  background: var(--popover-surface);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(var(--ink-rgb), .4);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  outline: none;
  transform-origin: top right;
  animation: menu-in var(--t-fast) var(--ease);
}

.menu.is-above { transform-origin: bottom right; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px 8px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font: 500 13px/1.25 var(--ui-font-family);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), .1);
  color: var(--text);
}

.menu-item-icon {
  display: inline-flex;
  justify-content: center;
  width: 20px;
  flex: none;
  font-size: 14px;
}

.menu-item-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.menu-item.is-danger { color: var(--error-text); }

.menu-item.is-danger:hover:not(:disabled),
.menu-item.is-danger:focus-visible {
  background: rgba(var(--error-rgb), .14);
  color: var(--text);
}

.menu-item:disabled { opacity: .4; cursor: not-allowed; }

.menu-sep {
  height: 1px;
  margin: 5px 6px;
  background: var(--border);
}

@keyframes menu-in { from { opacity: 0; transform: scale(.96); } }

/* ── Dropzone ─────────────────────────────────────────────────── */

.dropzone {
  position: relative;
  border: 1.5px dashed rgba(var(--primary-rgb), .28);
  border-radius: var(--radius);
  background: rgba(var(--primary-rgb), .03);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--t) ease, background-color var(--t) ease, box-shadow var(--t) ease, color var(--t) ease;
}

.dropzone:hover {
  border-color: rgba(var(--primary-rgb), .5);
  background: rgba(var(--primary-rgb), .06);
  color: var(--text);
}

.dropzone:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.dropzone.is-dragover {
  border-style: solid;
  border-color: var(--primary);
  background: rgba(var(--primary-rgb), .1);
  color: var(--text);
  box-shadow: 0 0 0 4px rgba(var(--primary-rgb), .12), 0 0 36px rgba(var(--primary-rgb), .28);
}

.dropzone.is-disabled,
.dropzone[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Filter chips, owners, visibility ─────────────────────────────
   Tags are not part of the UI any more; what is left here is the ✕ of the Explore author filter. */

.filter-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 20px;
  height: 20px;
  margin-left: 4px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font: 700 10px/1 var(--ui-font-family);
  cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}

.filter-chip-remove:hover {
  background: rgba(var(--white-rgb), .12);
  color: var(--text);
}

.filter-chip-remove:focus-visible {
  outline: none;
  background: rgba(var(--primary-rgb), .2);
  box-shadow: var(--focus-ring);
  color: var(--text);
}

/* Owner: avatar initials + name. data-tone="0…3" (optional, e.g. from the owner id) varies the avatar gradient. */
.owner-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 100%;
  padding: 2px 9px 2px 2px;
  border-radius: 999px;
  color: var(--text-secondary);
  font: 500 12.5px/1.2 var(--ui-font-family);
  text-decoration: none;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}

a.owner-chip:hover {
  background: rgba(var(--white-rgb), .07);
  color: var(--text);
}

a.owner-chip:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  color: var(--text);
}

.owner-chip-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gradient-soft);
  color: var(--text);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(var(--ink-rgb), .45);
  box-shadow: 0 0 0 1.5px rgba(var(--ink-rgb), .6);
}

.owner-chip-avatar[data-tone="1"] { background: linear-gradient(135deg, var(--secondary) 0%, var(--accent) 100%); }
.owner-chip-avatar[data-tone="2"] { background: linear-gradient(135deg, var(--success) 0%, var(--primary) 100%); }
.owner-chip-avatar[data-tone="3"] { background: linear-gradient(135deg, var(--accent) 0%, var(--warning) 100%); }

.owner-chip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.owner-chip-by { color: var(--text-muted); }

/* 🔒 Private / 🌐 Public — data-visibility="private|public" (or .is-private / .is-public) picks the tint.
   Dark glass of its own, so it reads on top of a cover image. */
.visibility-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 9px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: rgba(var(--ink-rgb), .66);
  color: var(--text-secondary);
  font: 600 11px/1 var(--ui-font-family);
  letter-spacing: .02em;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.visibility-badge[data-visibility="public"],
.visibility-badge.is-public {
  border-color: rgba(var(--success-rgb), .45);
  color: var(--success-text);
}

.visibility-badge[data-visibility="private"],
.visibility-badge.is-private {
  border-color: rgba(var(--white-rgb), .16);
  color: var(--text-secondary);
}

/* ── Login page ───────────────────────────────────────────────── */

.login-main {
  display: flex;
  padding: 32px 16px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: min(400px, 100%);
  margin: auto;
  padding: 32px 28px 28px;
  background: var(--card-surface-strong);
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg), var(--glow);
}

.login-card::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(var(--primary-rgb), .8), rgba(var(--secondary-rgb), .8), transparent);
}

.login-card .cr-brand { font-family: var(--ui-font-family); }

/* brand.js sizes the logo to the wordmark; this is its size until that runs */
.login-card .cr-brand-logo { width: 140px; }

.login-form {
  display: flex;
  flex-direction: column;
}

.login-form .btn-primary {
  width: 100%;
  height: 42px;
  margin-top: 22px;
  font-size: 14px;
}

.login-methods {
  display: flex;
  flex-direction: column;
}

.login-methods .form-error:not(:empty) { margin-top: 14px; }

/* Google's dark-theme sign-in button (brand guidelines: #131314 fill, #8e918f stroke, #e3e3e3 label, full-colour G). */
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid #8e918f;
  border-radius: var(--radius-sm);
  background: #131314;
  color: #e3e3e3;
  font: 500 14px/1 var(--ui-font-family);
  text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.google-btn:hover {
  background: #1f1f20;
  border-color: #c4c7c5;
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .12);
}

.google-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .35);
}

.google-btn svg { flex: 0 0 auto; }

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 4px;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

@media (max-width: 540px) {
  .login-main { padding: 20px 12px; }
  .login-card { padding: 26px 18px 20px; }
}

/* ── Motion preferences ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .app-page *,
  .app-page *::before,
  .app-page *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  /* Spinners are the only way to show progress, so they keep turning, slower. */
  .app-page .spinner,
  .app-page .btn.is-busy::before,
  .app-page .btn-icon.is-busy::after {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }

  .app-page .toast-progress { display: none; }
}
