/* Clip Lab — design tokens and the shared layer every page sits on.
 *
 * Written against Apple's Human Interface Guidelines. What is taken from the HIG is
 * the *system*, not the look: the fixed type ramp, the 4/8pt spacing grid, a minimum
 * 44pt tap target, one accent per view, focus rings for keyboards only, and motion
 * that yields to a reduce-motion preference. The two colour schemes already in this
 * app (warm cream for the app, dark for admin) are kept exactly as they were.
 *
 * The palette lives here and nowhere else. Both themes deliberately keep the old
 * variable names (--card, --ink, --muted, --border ...) as aliases, so the per-page
 * component styles that were written against them keep working unchanged.
 */

:root {
  /* ---- type ramp ------------------------------------------------------------
     Apple's sizes in px, expressed in rem so a reader who raises their browser's
     base font size actually gets bigger text. Nothing below caption2 (11px) is
     used for anything that has to be read. */
  --fs-large-title: 2.125rem;   /* 34 */
  --fs-title1:      1.75rem;    /* 28 */
  --fs-title2:      1.375rem;   /* 22 */
  --fs-title3:      1.25rem;    /* 20 */
  --fs-headline:    1.0625rem;  /* 17, semibold */
  --fs-body:        1.0625rem;  /* 17 */
  --fs-callout:     1rem;       /* 16 */
  --fs-subhead:     0.9375rem;  /* 15 */
  --fs-footnote:    0.8125rem;  /* 13 */
  --fs-caption1:    0.75rem;    /* 12 */
  --fs-caption2:    0.6875rem;  /* 11 */

  --lh-tight: 1.2;
  --lh-body: 1.5;

  /* ---- spacing: a 4pt grid, no ad-hoc numbers ---------------------------- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;

  /* ---- shape ------------------------------------------------------------- */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* ---- motion ------------------------------------------------------------ */
  --dur-fast: 120ms;
  --dur: 200ms;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);

  /* ---- the one number that matters for touch ----------------------------- */
  --tap-min: 44px;

  /* ---- warm theme: the app. These are the exact values it shipped with. --- */
  --bg: #f6f4ef;
  --card: #ffffff;
  --field: #fbfaf7;
  --fill-subtle: #f5f1e9;
  --fill-track: #eeeae2;
  --ink: #2b2b2b;
  --muted: #7a7a7a;
  --border: #e5e0d6;
  --accent: #e2574c;
  --accent-dark: #c4463c;
  --accent-tint: #fdf1ef;
  --ok: #3d9a5f;
  --warn: #9a6b12;
  --bad: #b03a2f;
  --radius: 14px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-raised: 0 1px 3px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}

/* ---- admin theme: the same product, on a dark surface.
   The accent is the app's own red, not a second colour — a third accent that appears
   on one screen is most of what makes a screen feel like a different app. --------- */
html[data-theme="admin"] {
  --bg: #14161a;
  --card: #1d2026;
  --card2: #23262e;
  --field: #23262e;
  --fill-subtle: #23262e;
  --fill-track: #23262e;
  --ink: #e8e6e1;
  --muted: #8b8f98;
  --border: #2c3038;
  --accent: #e2574c;
  --accent-dark: #f07b71;
  --accent-tint: #2b1715;
  --ok: #3d9a5f;
  --warn: #d9a13b;
  --bad: #e2574c;
  --radius: 14px;
  --shadow-card: none;
  --shadow-raised: none;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* stops iOS inflating text in landscape and breaking the layout */
  -webkit-text-size-adjust: 100%;
}

/* Headings follow the ramp rather than whatever each page felt like. */
h1 { font-size: var(--fs-title1); line-height: var(--lh-tight); letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: var(--fs-title3); line-height: var(--lh-tight); letter-spacing: -0.01em; font-weight: 600; }
h3 { font-size: var(--fs-headline); line-height: var(--lh-tight); font-weight: 600; }

/* ---- focus ------------------------------------------------------------------
   A ring is for the keyboard. Drawing one on every mouse click is the thing the
   HIG calls out, so :focus-visible gates it and the mouse gets nothing. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
/* Inputs keep a ring on any focus — the field is the only thing on the page that
   can be focused, and losing track of the caret mid-typing is worse. */
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}

/* ---- touch targets ----------------------------------------------------------
   A pointer that can hover is a mouse: 32px is comfortable there and keeps the
   admin tables dense. A coarse pointer is a finger, and fingers get 44. */
button, .btn, a.btn, summary, select {
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
@media (pointer: fine) {
  button.btn.sm, .btn.sm, td.acts .btn, .job .confirm button, .job .prompt .copy {
    min-height: 34px;
  }
}

/* ---- icons -------------------------------------------------------------------
   One 24-unit grid, one stroke weight, tinted with currentColor. Emoji are gone:
   they carry their own colour, sit off the baseline, and render as a different
   picture on every OS — none of which survives contact with a design system. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic {
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.18em;
}
.ic-lg { width: 1.4em; height: 1.4em; }

/* ---- motion ------------------------------------------------------------------
   Everything that moves is decoration, so it all stops when the reader has asked
   for less. Short, eased, and never blocking. */
@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;
  }
}

/* ============================================================================
   COMPONENTS — one definition each, used by the app and the admin alike.
   If a button looks different on two screens, it is because one of them stopped
   using this file.
   ========================================================================== */

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap-min);
  padding: var(--sp-3) var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: var(--fs-headline);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              opacity var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { background: var(--accent-dark); }
.btn:active:not(:disabled) { opacity: 0.82; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  font-weight: 600;
}
.btn.ghost:hover:not(:disabled) { background: var(--fill-subtle); color: var(--ink); border-color: var(--muted); }

.btn.bad  { background: var(--bad); color: #fff; }
.btn.bad:hover:not(:disabled)  { background: color-mix(in srgb, var(--bad) 82%, #000); }
.btn.ok   { background: var(--ok);  color: #fff; }
.btn.ok:hover:not(:disabled)   { background: color-mix(in srgb, var(--ok) 82%, #000); }

/* Inline size: sits beside other controls rather than owning the row. */
.btn.sm, .btn.inline {
  display: inline-flex;
  width: auto;
  min-height: 34px;
  padding: 6px var(--sp-3);
  font-size: var(--fs-subhead);
  font-weight: 600;
  border-radius: var(--r-sm);
}
@media (pointer: coarse) {
  .btn.sm, .btn.inline { min-height: var(--tap-min); padding-inline: var(--sp-4); }
}

/* A button that closes a card or a form gets air above it. Buttons sitting in a
   flex row (toolbars, table cells) must not, which is why this is scoped. */
.card > .btn, form .btn { margin-top: var(--sp-4); }
.card > .btn + .btn { margin-top: var(--sp-2); }

/* ---- surfaces ------------------------------------------------------------ */
.card, .panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-card);
}
.card { margin-top: var(--sp-4); }
.card > h2, .panel > h2 { margin-bottom: var(--sp-1); }

/* ---- form controls ------------------------------------------------------- */
label { display: block; font-weight: 600; font-size: var(--fs-subhead); margin: var(--sp-4) 0 6px; }
label .sub { font-weight: 400; color: var(--muted); font-size: var(--fs-footnote); }

input[type=text], input[type=email], input[type=password], input[type=number],
textarea, select {
  width: 100%;
  min-height: var(--tap-min);
  padding: 11px var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--field);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-body);
  transition: border-color var(--dur-fast) var(--ease);
}
textarea { min-height: 76px; resize: vertical; line-height: var(--lh-body); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }

label.chk { display: flex; align-items: center; gap: var(--sp-2); cursor: pointer; min-height: var(--tap-min); margin: var(--sp-3) 0 0; }
label.chk input[type=checkbox] { flex: 0 0 auto; width: 20px; height: 20px; accent-color: var(--accent); }
.chk-note { color: var(--muted); font-size: var(--fs-footnote); margin: 0 0 0 28px; }

/* ---- segmented control ----------------------------------------------------
   Two mutually exclusive choices. The track holds the options, the selected one is
   a white pill that sits on top — the HIG pattern, and the same on both themes. */
.sub-label {
  margin: var(--sp-5) 0 6px;
  font-size: var(--fs-footnote);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.toggle {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-1);
  background: var(--fill-track);
  border-radius: var(--r-md);
}
.toggle button {
  flex: 1;
  min-height: 38px;
  padding: var(--sp-2) 6px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: var(--fs-subhead);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.toggle button:hover { color: var(--ink); }
.toggle button.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
}
@media (pointer: coarse) {
  .toggle button { min-height: var(--tap-min); }
}

/* ---- job card ------------------------------------------------------------ */
.job {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  margin-top: var(--sp-2);
  background: var(--field);
}
.job .t { font-weight: 600; font-size: var(--fs-subhead); }
.job .meta { color: var(--muted); font-size: var(--fs-footnote); margin-top: 2px; line-height: var(--lh-body); }
.job a { color: var(--accent-dark); font-weight: 600; word-break: break-all; }
.job .st { display: inline-block; margin-top: var(--sp-2); }

/* ---- prompt surfaces ----------------------------------------------------- */
.prompt-box, .ptext {
  background: var(--fill-subtle);
  border-radius: var(--r-sm);
  padding: var(--sp-3);
  font-size: var(--fs-subhead);
  border-left: 3px solid var(--accent);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: var(--lh-body);
}

/* ---- drop target --------------------------------------------------------- */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-5);
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: var(--field);
  margin-top: var(--sp-3);
  min-height: var(--tap-min);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: var(--fs-subhead);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.file-drop:hover { border-color: var(--accent); color: var(--ink); }
.file-drop.drag { border-color: var(--accent); background: var(--accent-tint); }
.file-drop img { max-width: 100%; max-height: 200px; border-radius: var(--r-sm); margin-top: var(--sp-1); }

/* ---- progress ------------------------------------------------------------ */
.spin {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rot 0.9s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }
.queue { display: flex; gap: var(--sp-2); align-items: center; margin-top: var(--sp-3); font-size: var(--fs-subhead); color: var(--muted); }
.hidden { display: none !important; }
.foot { text-align: center; color: var(--muted); font-size: var(--fs-footnote); margin-top: var(--sp-6); }
.notice { font-size: var(--fs-footnote); color: var(--muted); margin-top: var(--sp-3); line-height: var(--lh-body); }
.notice b { color: var(--ink); font-weight: 600; }
.err {
  background: color-mix(in srgb, var(--bad) 12%, var(--card));
  color: var(--bad);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  margin-top: var(--sp-3);
  font-size: var(--fs-subhead);
}

/* Semantic colour, so a status reads the same on both themes. */
.st {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-caption1);
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.st.pending   { background: color-mix(in srgb, var(--warn) 16%, var(--bg));   color: var(--warn); }
.st.queued    { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); color: var(--accent-dark); }
.st.rendering { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); color: var(--accent-dark); }
.st.done      { background: color-mix(in srgb, var(--ok) 16%, var(--bg));     color: var(--ok); }
.st.failed    { background: color-mix(in srgb, var(--bad) 14%, var(--bg));    color: var(--bad); }
.st.approved  { background: color-mix(in srgb, var(--ok) 16%, var(--bg));     color: var(--ok); }
.st.denied,
.st.admin     { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); color: var(--accent-dark); }
