/* ==========================================================================
   AI Creation Studio — design system (shared by index.html and admin.html)
   Zero dependencies: no web fonts, no CDN, no external images.
   All icons are inline SVG, all placeholders are CSS gradients.
   Theme: light, paper-like surfaces with one calm blue accent. No glows,
   no neon, no gradient chrome — it should read like a classroom tool.
   ========================================================================== */

/* ---------- 1. Design tokens ---------- */
:root {
  /* Background layers, darkest to lightest, to give the page some depth */
  --bg: #f5f6f8;
  --bg-grad-a: #f8f9fb;
  --bg-grad-b: #eef1f5;
  --surface: #ffffff;          /* card base */
  --surface-2: #f3f5f8;      /* inset blocks, one step below the card surface */
  --surface-raise: #f1f4f8;

  /* Borders: translucent so nothing looks hard-drawn */
  --line: rgba(15, 23, 42, 0.10);
  --line-strong: rgba(15, 23, 42, 0.22);
  --line-glow: rgba(47, 95, 208, 0.35);

  /* Text */
  --text: #171c27;
  --text-dim: #4a5566;
  --text-mute: #7c8596;

  /* Accent and semantic colours */
  --c-cyan: #2f5fd0;
  --c-violet: #7c8aa5;
  --grad: #2f5fd0;
  --grad-soft: rgba(47, 95, 208, 0.08);

  --ok: #1c855c;
  --warn: #b7791f;
  --err: #c23b32;
  --info: #2b6cb0;

  /* Radii */
  --r-xl: 20px;
  --r-lg: 14px;
  --r-md: 12px;
  --r-sm: 8px;
  --r-pill: 999px;

  /* Transitions */
  --t: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 30px -18px rgba(15, 23, 42, 0.22);
  --shadow-pop: 0 24px 60px -24px rgba(15, 23, 42, 0.35);

  /* Latin system UI stack first, CJK fallbacks after it so Chinese prompts
     and names still render with the right glyphs. No web fonts. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono",
    "Noto Sans Mono CJK SC", monospace;

  --topbar-h: 60px;
}

/* ---------- 2. Base reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  /* A barely-there paper gradient: light enough to stay quiet on a projector */
  background-image: linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: break-word;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; }
p { margin: 0; }

a { color: var(--c-cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

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

::selection { background: rgba(47, 95, 208, 0.28); }

/* Focus ring: visible for keyboard users, out of the way for mouse users */
:focus-visible {
  outline: 2px solid var(--c-cyan);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Thin scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.22);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.4); background-clip: content-box; }

/* ---------- 3. Utility classes ---------- */
.hidden { 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;
}
/* Rows wrap by default: English labels are wider than the Chinese ones this
   layout was first drawn for, so nothing is allowed to push the page sideways. */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.dim { color: var(--text-dim); }
.mute { color: var(--text-mute); }
.tiny { font-size: 12px; }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- 4. Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(150%) blur(12px);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--grad);
  color: #fff;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.brand-mark svg { width: 18px; height: 18px; display: block; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }

/* Status chips in the top bar */
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 4px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.06);
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.chip svg { width: 14px; height: 14px; flex: 0 0 auto; opacity: 0.85; }
.chip b { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.chip.is-active { border-color: var(--line-glow); background: rgba(47, 95, 208, 0.09); color: #1f4f8f; }
.chip.is-warn { border-color: rgba(183, 121, 31, 0.35); background: rgba(183, 121, 31, 0.09); color: #7a5a12; }
.chip.is-err { border-color: rgba(194, 59, 50, 0.35); background: rgba(194, 59, 50, 0.09); color: #95303a; }
.chip.is-ok { border-color: rgba(28, 133, 92, 0.32); background: rgba(28, 133, 92, 0.09); color: #1a6b49; }

/* Pulsing dot inside the queue chip */
.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c-cyan);
  flex: 0 0 auto;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(47, 95, 208, 0.5); }
  50% { opacity: 0.55; box-shadow: 0 0 0 5px rgba(47, 95, 208, 0); }
}

/* ---------- 5. Page containers ---------- */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 20px 80px;
}
.page-narrow { max-width: 900px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}
.section-head h2 { font-size: 17px; }
.section-head .hint { font-size: 13px; color: var(--text-mute); }

/* ---------- 6. Cards ---------- */
.card {
  position: relative;
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  transition: border-color var(--t), transform var(--t), box-shadow var(--t);
}
.card-pad { padding: 18px; }

/* Border brightens and the card lifts slightly — only where hover exists */
@media (hover: hover) {
  .card-hover:hover {
    border-color: var(--line-strong);
    transform: translateY(-2px);
    box-shadow: 0 16px 36px -24px rgba(15, 23, 42, 0.30), 0 0 0 1px rgba(47, 95, 208, 0.06);
  }
}

.card-title { font-size: 15px; font-weight: 650; }

/* Gradient hairline border for accent cards (login, empty states) */
.card-accent::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: var(--grad);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- 7. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
  text-align: center;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
}
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn:hover { background: rgba(15, 23, 42, 0.14); border-color: var(--line-strong); }
.btn:active { transform: scale(0.98); }
.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

/* Primary button: one solid accent colour, white label */
.btn-primary {
  border-color: transparent;
  background: var(--grad);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 6px 16px -12px rgba(47, 95, 208, 0.45);
}
.btn-primary:hover { background: var(--grad); filter: brightness(0.94); }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: rgba(15, 23, 42, 0.08); }

.btn-danger { border-color: rgba(194, 59, 50, 0.4); color: #95303a; background: rgba(194, 59, 50, 0.1); }
.btn-danger:hover { background: rgba(194, 59, 50, 0.18); }

.btn-sm { min-height: 31px; padding: 4px 11px; font-size: 13px; border-radius: var(--r-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { min-height: 46px; padding: 10px 24px; font-size: 15px; border-radius: var(--r-lg); }
.btn-block { width: 100%; }

/* Loading spinner inside a button */
.spinner {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}
.btn-ghost .spinner, .btn-danger .spinner, .btn:not(.btn-primary) .spinner {
  border-color: rgba(15, 23, 42, 0.3);
  border-top-color: var(--c-cyan);
}
/* Standalone spinner (first paint) — visible on the light background */
.spinner-lg {
  width: 20px; height: 20px; border-width: 2.5px;
  border-color: rgba(15, 23, 42, 0.22);
  border-top-color: var(--c-cyan);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* First-paint placeholder so waiting on api/me never shows a blank page */
.boot-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- 8. Segmented control (replaces native <select>) ---------- */
.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
  max-width: 100%;
}
.seg-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  min-height: 32px;
  padding: 4px 13px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.seg-btn:hover { color: var(--text); background: rgba(15, 23, 42, 0.08); }
.seg-btn[aria-checked="true"] {
  color: #1f2a44;
  background: rgba(47, 95, 208, 0.10);
  border-color: rgba(47, 95, 208, 0.35);
  box-shadow: none;
}
.seg-btn .seg-note { font-size: 11px; opacity: 0.7; margin-left: 5px; font-weight: 500; }
.seg-sm .seg-btn { min-height: 27px; padding: 2px 10px; font-size: 12.5px; }
.seg-block { display: flex; width: 100%; }
.seg-block .seg-btn { flex: 1 1 auto; }

/* ---------- 9. Form controls ---------- */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.field-label .req { color: var(--c-cyan); }
.field-hint { font-size: 12px; color: var(--text-mute); margin-top: 7px; }

.input, .textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  padding: 11px 13px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-mute); }
.input:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--line-glow);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 95, 208, 0.10);
}
.textarea { resize: vertical; min-height: 108px; line-height: 1.65; }

/* Character counter: amber near the limit, red past it */
.counter { font-variant-numeric: tabular-nums; transition: color var(--t-fast); }
.counter.is-warn { color: var(--warn); }
.counter.is-over { color: var(--err); }

/* Toggle switch (hand-drawn checkbox) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 42px; height: 24px;
  border-radius: var(--r-pill);
  background: rgba(15, 23, 42, 0.2);
  border: 1px solid var(--line);
  position: relative;
  flex: 0 0 auto;
  transition: background var(--t), border-color var(--t);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--t), background var(--t);
}
.switch input:checked + .switch-track {
  background: var(--c-cyan);
  border-color: var(--c-cyan);
}
.switch input:checked + .switch-track::after { transform: translateX(18px); background: #ffffff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--c-cyan); outline-offset: 2px; }
.switch-text { font-size: 13.5px; color: var(--text-dim); }

/* Range input */
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1 1 auto; accent-color: var(--c-cyan); }
.range-val {
  font-variant-numeric: tabular-nums;
  min-width: 52px;
  text-align: center;
  font-weight: 650;
  color: #1f2a44;
}

/* File upload: the native input is hidden, the label acts as the button */
.upload-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 13px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.upload-box:hover { border-color: var(--line-glow); background: rgba(47, 95, 208, 0.04); }
.upload-box input[type="file"] { display: none; }
.upload-thumb {
  width: 46px; height: 46px;
  border-radius: var(--r-sm);
  object-fit: cover;
  border: 1px solid var(--line);
  flex: 0 0 auto;
  background: linear-gradient(135deg, #f3f5f9, #e7ebf2);
}
.upload-preview {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.5);
}
.upload-meta { min-width: 0; flex: 1 1 auto; }
.upload-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 10. Prompt idea pills ---------- */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.06);
  color: var(--text-dim);
  border-radius: var(--r-pill);
  padding: 6px 13px;
  font-size: 13px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.pill:hover {
  color: #1f2a44;
  border-color: var(--line-glow);
  background: rgba(47, 95, 208, 0.1);
  transform: translateY(-1px);
}
.pill:active { transform: translateY(0); }

/* ---------- 11. Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 22px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  min-height: 40px;
  padding: 6px 20px;
  border-radius: var(--r-md);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  flex: 1 1 auto;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.tab svg { width: 16px; height: 16px; }
.tab:hover { color: var(--text); background: rgba(15, 23, 42, 0.07); }
.tab[aria-selected="true"] {
  color: #1f2a44;
  background: rgba(47, 95, 208, 0.09);
  border-color: rgba(47, 95, 208, 0.30);
}
.tab .tab-badge {
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: rgba(15, 23, 42, 0.18);
  font-variant-numeric: tabular-nums;
}

/* ---------- 12. Create page layout ---------- */
.studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 22px;
  align-items: start;
}
@media (max-width: 1000px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
}

.panel-params { position: sticky; top: calc(var(--topbar-h) + 14px); }
@media (max-width: 1000px) {
  .panel-params { position: static; }
}

/* Estimated cost bar */
.cost-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.05);
  font-size: 13px;
  color: var(--text-dim);
}
.cost-bar .cost-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--c-cyan);
}
.cost-bar.is-warn { border-color: rgba(183, 121, 31, 0.3); background: rgba(183, 121, 31, 0.07); }

.submit-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.submit-row .btn-primary { flex: 1 1 auto; min-width: 180px; }

/* Two-column parameter grid, single column on narrow screens */
.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 620px) { .param-grid { grid-template-columns: 1fr; gap: 16px; } }

/* ---------- 13. Job cards ---------- */
.job-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.job-list-wide { grid-template-columns: minmax(0, 1fr); }

.job {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--r-lg);
}

/* Media area: fixed aspect placeholder so loading never shifts the layout */
.job-media {
  position: relative;
  width: 100%;
  background: linear-gradient(135deg, #eef1f6, #e2e7ef);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.job-media.ratio-1-1 { aspect-ratio: 1 / 1; }
.job-media.ratio-4-3 { aspect-ratio: 4 / 3; }
.job-media.ratio-3-4 { aspect-ratio: 3 / 4; }
.job-media.ratio-16-9 { aspect-ratio: 16 / 9; }
.job-media.ratio-9-16 { aspect-ratio: 9 / 16; }
.job-media.ratio-adaptive { aspect-ratio: 16 / 9; }

.job-media img,
.job-media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #e8ecf2;
  transition: opacity var(--t-slow);
}
.job-media img.is-loading { opacity: 0; }
.job-media img.is-ready { opacity: 1; }

/* Badges overlaid on the media */
.media-badge {
  position: absolute;
  top: 8px; left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  color: var(--text-dim);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.media-badge.right { left: auto; right: 8px; }
.media-badge svg { width: 12px; height: 12px; }

.job-body { padding: 13px 14px 14px; display: flex; flex-direction: column; gap: 9px; flex: 1 1 auto; }

/* Prompt text: clamped, click to expand */
.prompt-text {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color var(--t-fast);
}
.prompt-text:hover { color: #1f2a44; }
.prompt-text.is-open {
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
  display: block;
}

.job-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-mute);
}
.job-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: 0.6; }

.job-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 2px; }

/* Status badge */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.08);
  color: var(--text-dim);
  white-space: nowrap;
}
.status svg { width: 12px; height: 12px; }
.status-queued { border-color: rgba(43, 108, 176, 0.35); background: rgba(43, 108, 176, 0.1); color: #24518f; }
.status-running { border-color: rgba(47, 95, 208, 0.4); background: rgba(47, 95, 208, 0.1); color: #1f4f8f; }
.status-succeeded { border-color: rgba(28, 133, 92, 0.35); background: rgba(28, 133, 92, 0.1); color: #1a6b49; }
.status-failed { border-color: rgba(194, 59, 50, 0.4); background: rgba(194, 59, 50, 0.1); color: #95303a; }
.status-canceled { border-color: var(--line); background: rgba(15, 23, 42, 0.08); color: var(--text-mute); }

/* Error block */
.error-box {
  font-size: 12.5px;
  line-height: 1.55;
  color: #95303a;
  background: rgba(194, 59, 50, 0.09);
  border: 1px solid rgba(194, 59, 50, 0.28);
  border-radius: var(--r-sm);
  padding: 9px 11px;
}

/* ---------- 14. Skeletons / loading states ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.09);
  border-radius: var(--r-sm);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton-text { height: 12px; margin-bottom: 8px; }
.skeleton-text.w-40 { width: 40%; }
.skeleton-text.w-70 { width: 70%; }
.skeleton-media { width: 100%; aspect-ratio: 1 / 1; border-radius: 0; }

/* Soft ripple while a job is generating (shown over the media area) */
.gen-anim {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 50%, rgba(47, 95, 208, 0.12), transparent 62%),
    linear-gradient(135deg, #eef1f6, #e2e7ef);
}
.gen-rings { position: relative; width: 58px; height: 58px; }
.gen-rings span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(47, 95, 208, 0.5);
  animation: ripple 2s ease-out infinite;
}
.gen-rings span:nth-child(2) { animation-delay: 0.66s; border-color: rgba(124, 138, 165, 0.5); }
.gen-rings span:nth-child(3) { animation-delay: 1.33s; border-color: rgba(47, 95, 208, 0.35); }
@keyframes ripple {
  0% { transform: scale(0.35); opacity: 0.9; }
  100% { transform: scale(1.25); opacity: 0; }
}

/* Elapsed-time digits */
.timer { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 650; color: #1f4f8f; }

/* Queue position bar */
.qbar {
  height: 4px;
  border-radius: var(--r-pill);
  background: rgba(15, 23, 42, 0.16);
  overflow: hidden;
}
.qbar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--grad);
  transition: width var(--t-slow);
}

/* ---------- 15. Gallery (masonry) ---------- */
.masonry {
  columns: 4 250px;
  column-gap: 16px;
}
.masonry > * {
  break-inside: avoid;
  margin: 0 0 16px;
  display: block;
}
@media (max-width: 1200px) { .masonry { columns: 3 240px; } }
@media (max-width: 820px) { .masonry { columns: 2 160px; column-gap: 12px; } .masonry > * { margin-bottom: 12px; } }
@media (max-width: 460px) { .masonry { columns: 1; } }

/* Gallery media: natural aspect ratio, width-driven */
.gallery-media {
  position: relative;
  width: 100%;
  background: linear-gradient(135deg, #eef1f6, #e2e7ef);
  overflow: hidden;
  min-height: 80px;
}
.gallery-media img,
.gallery-media video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 78vh;
  object-fit: cover;
  background: #e8ecf2;
}
.gallery-media img.is-loading { opacity: 0; }
.gallery-media img.is-ready { opacity: 1; transition: opacity var(--t-slow); }

/* Play overlay: videos never autoplay, the user has to click */
.play-btn {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.05), rgba(15, 23, 42, 0.5));
  cursor: pointer;
  transition: background var(--t);
}
.play-btn:hover { background: linear-gradient(180deg, rgba(15, 23, 42, 0.02), rgba(15, 23, 42, 0.35)); }
.play-btn svg { width: 46px; height: 46px; filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.45)); }

/* ---------- 16. Empty states ---------- */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 54px 22px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  background: rgba(15, 23, 42, 0.035);
}
.empty-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--grad-soft);
  border: 1px solid var(--line);
}
.empty-icon svg { width: 26px; height: 26px; }
.empty h3 { font-size: 16px; margin-bottom: 6px; }
.empty p { color: var(--text-mute); font-size: 13.5px; max-width: 420px; margin: 0 auto; }

/* ---------- 17. Toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: min(92vw, 440px);
  pointer-events: none;
}
.toast {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-pop);
  font-size: 13.5px;
  pointer-events: auto;
  animation: toast-in var(--t-slow) both;
}
.toast.is-out { animation: toast-out var(--t) both; }
.toast svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }
.toast-ok { border-color: rgba(28, 133, 92, 0.4); }
.toast-ok svg { color: var(--ok); }
.toast-err { border-color: rgba(194, 59, 50, 0.45); }
.toast-err svg { color: var(--err); }
.toast-info svg { color: var(--info); }
.toast-text { min-width: 0; flex: 1 1 auto; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* ---------- 18. Hover tooltip (used to reveal absolute timestamps) ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 9px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 11.5px;
  white-space: nowrap;
  z-index: 60;
  pointer-events: none;
  box-shadow: var(--shadow-pop);
}

/* ---------- 19. Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 20px;
}
.login-card {
  width: min(100%, 420px);
  padding: 34px 30px 28px;
  border-radius: var(--r-xl);
  animation: rise var(--t-slow) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
.login-logo {
  width: 58px; height: 58px;
  margin: 0 auto 18px;
  border-radius: 18px;
  background: var(--grad);
  color: #fff;
  display: grid;
  place-items: center;
}
.login-logo svg { width: 30px; height: 30px; }
.login-card h1 { text-align: center; font-size: 26px; letter-spacing: 0.01em; margin-bottom: 8px; }
.login-sub { text-align: center; color: var(--text-dim); font-size: 13.5px; margin-bottom: 26px; }
.login-note {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--text-mute);
  font-size: 12.5px;
  line-height: 1.7;
}

/* ---------- 20. Teacher console ---------- */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  padding: 15px 16px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background-color: var(--surface);
}
.stat-label {
  font-size: 12px;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  letter-spacing: 0.02em;
}
.stat-label svg { width: 13px; height: 13px; }
.stat-val {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat-sub { font-size: 12px; color: var(--text-mute); margin-top: 5px; }
.stat-val.is-cyan { color: var(--c-cyan); }
.stat-val.is-violet { color: var(--c-violet); }
.stat-val.is-ok { color: var(--ok); }
.stat-val.is-warn { color: var(--warn); }
.stat-val.is-err { color: var(--err); }

/* Tables scroll horizontally on narrow screens instead of squeezing */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 860px;
}
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 11px 13px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  letter-spacing: 0.03em;
  background: #f7f8fa;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data tbody td {
  padding: 10px 13px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  vertical-align: middle;
}
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: rgba(15, 23, 42, 0.05); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.is-hidden-row { opacity: 0.5; }
.cell-prompt {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.cell-prompt.is-open { white-space: normal; max-width: 420px; }
.cell-thumb {
  width: 42px; height: 42px;
  border-radius: var(--r-sm);
  object-fit: cover;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #f3f5f9, #e7ebf2);
  cursor: pointer;
  display: block;
}

/* Console banners (paused state and friends) */
.banner {
  display: flex;
  align-items: center;
  gap: 11px;
  flex-wrap: wrap;
  padding: 12px 15px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.06);
}
.banner svg { width: 17px; height: 17px; flex: 0 0 auto; }
.banner-warn { border-color: rgba(183, 121, 31, 0.4); background: rgba(183, 121, 31, 0.09); color: #7a5a12; }
.banner-ok { border-color: rgba(28, 133, 92, 0.35); background: rgba(28, 133, 92, 0.08); color: #1a6b49; }
.banner-err { border-color: rgba(194, 59, 50, 0.4); background: rgba(194, 59, 50, 0.09); color: #95303a; }

/* Config form: compact number inputs */
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.cfg-item .field-label { font-size: 12px; margin-bottom: 6px; }
.input-num { width: 100%; text-align: center; font-variant-numeric: tabular-nums; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .input { width: auto; min-width: 150px; flex: 0 1 auto; }

/* Lightbox for enlarged images */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fade-in var(--t) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.lightbox img,
.lightbox video {
  max-width: 94vw;
  max-height: 86vh;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  background: #e8ecf2;
}
.lightbox-close {
  position: absolute;
  top: 18px; right: 18px;
  width: 40px; height: 40px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: background var(--t-fast);
}
.lightbox-close:hover { background: rgba(15, 23, 42, 0.08); }
.lightbox-close svg { width: 18px; height: 18px; }

/* ---------- 21. Small screens ---------- */
@media (max-width: 720px) {
  body { font-size: 14.5px; }
  .page { padding: 16px 16px 90px; }
  .topbar { padding: 9px 16px; gap: 10px; }
  .brand-name { font-size: 15px; }
  .chip { min-height: 28px; padding: 3px 10px; font-size: 12px; }
  .tab { padding: 6px 13px; font-size: 13.5px; min-height: 38px; }
  .login-card { padding: 28px 22px 24px; }
  .login-card h1 { font-size: 22px; }
  .stat-val { font-size: 21px; }
  .btn { min-height: 36px; }
}

/* ---------- 22. Accessibility / reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print: black on white so a teacher can print the job list */
/* Practice (mock) mode. Deliberately loud: it must be impossible to run a real
   lesson in it by accident. */
.mock-banner {
  position: sticky;
  top: 0;
  z-index: 60;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #1a1205;
  background: repeating-linear-gradient(45deg, #f7c948, #f7c948 12px, #f2b705 12px, #f2b705 24px);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
}

@media print {
  body { background: #fff; color: #000; }
  .topbar, .toasts, .tabs, .toolbar, .mock-banner { display: none !important; }
  .card { border-color: #ccc; box-shadow: none; }
}
