/* Shared admin primitives. Every class is prefixed .ui- so nothing here can
 * catch a page's own markup, and every value is a token from tokens.css.
 * The React side is frontend/src/shared/ui/ — prefer those components; the
 * classes are public so PHP-rendered chrome can use them too.
 *
 * Geometry mirrors the majority of what the pages already had (34px controls,
 * 16px radius on buttons, 12px on inputs), so adopting a primitive changes
 * nothing the user would notice. */

/* ── Button ─────────────────────────────────────────────────────────────── */
.ui-btn {
  cursor: pointer; border: none; outline: none; font-family: inherit; text-decoration: none;
  height: 34px; padding: 0 1rem; border-radius: var(--radius-lg);
  font-size: var(--fs-sm); font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; white-space: nowrap;
  background: var(--accent); color: var(--text-inverse);
  transition: filter .15s, background .15s, color .15s;
}
.ui-btn:hover { filter: brightness(1.1); }
.ui-btn:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.ui-btn:disabled { opacity: .55; cursor: default; filter: none; }
.ui-btn-danger { background: var(--danger); }
.ui-btn-secondary { background: var(--surface-3); color: var(--text); }
.ui-btn-ghost { background: transparent; color: var(--text-muted); }
.ui-btn-ghost:hover { background: var(--surface-2); filter: none; }
/* Quiet outline that only turns red on hover — discarding is not deleting (UI_GUIDELINES 6). */
.ui-btn-outline { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }
.ui-btn-outline:hover { filter: none; background: var(--surface-2); }
.ui-btn-outline.ui-btn-danger-hover:hover { color: var(--danger-strong); box-shadow: inset 0 0 0 1px var(--danger); background: var(--danger-soft); }
.ui-btn-sm { height: 30px; padding: 0 .7rem; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.ui-btn-lg { height: 42px; padding: 0 1.4rem; font-size: var(--fs-md); }
.ui-btn-icon { width: 34px; padding: 0; border-radius: var(--radius-sm); }
.ui-btn-icon.ui-btn-sm { width: 30px; }
.ui-btn-block { width: 100%; }
@media (max-width: 600px) { .ui-btn { height: 42px; } .ui-btn-sm { height: 36px; } }

/* ── Section ────────────────────────────────────────────────────────────── */
/* Heading row with its actions on the right, so the controls sit above the
   content and are on screen without scrolling (UI_GUIDELINES 2). */
.ui-section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.ui-section-head h2 { margin-bottom: 0; }
.ui-section-head.is-actions-only { justify-content: flex-end; }
.ui-section-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.ui-section-lede { margin: -.5rem 0 1rem; color: var(--text-muted); font-size: var(--fs-md); }
@media (max-width: 600px) {
  .ui-section-head { flex-direction: column; align-items: stretch; gap: .6rem; }
  .ui-section-actions .ui-btn { flex: 1; }
}

/* ── Field ──────────────────────────────────────────────────────────────── */
.ui-field { display: flex; flex-direction: column; gap: .25rem; }
.ui-field > label { display: block; margin: 0; font-weight: 600; font-size: var(--fs-sm); color: var(--text-strong); }
.ui-field.is-inline { flex-direction: row; align-items: center; gap: .6rem; }
.ui-hint { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.35; }
.ui-error { font-size: var(--fs-xs); color: var(--danger-strong); font-weight: 600; line-height: 1.35; }
.ui-field input[type="text"], .ui-field input[type="password"], .ui-field input[type="email"], .ui-field input[type="url"],
.ui-field input[type="number"], .ui-field input[type="search"], .ui-field textarea, .ui-field select {
  width: 100%; padding: .4rem .7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  font-size: var(--fs-md); font-family: inherit; background: var(--surface); color: var(--text); box-sizing: border-box;
}
.ui-field input:not([type="checkbox"]):not([type="radio"]), .ui-field select { height: 34px; }
.ui-field textarea { resize: vertical; min-height: 54px; line-height: 1.35; }
.ui-field input:focus, .ui-field textarea:focus, .ui-field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.ui-field.has-error input, .ui-field.has-error textarea, .ui-field.has-error select {
  border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
}
@media (max-width: 600px) { .ui-field input:not([type="checkbox"]):not([type="radio"]), .ui-field select { height: 42px; } }

/* Toggle: label on the left, switch on the right, one 34px row. */
/* .main-content label (dashboard.css) is more specific than .ui-toggle and
   turns it into a block, which leaves the inline .ui-switch with no box —
   the switch vanishes. Both selectors here so the primitive wins anywhere. */
.ui-toggle, .main-content label.ui-toggle { position: relative; display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: 0; cursor: pointer; user-select: none; min-height: 34px; max-width: 620px; }
.ui-toggle-text { display: flex; flex-direction: column; font-weight: 600; font-size: var(--fs-sm); color: var(--text-strong); }
.ui-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.ui-switch { display: block; flex-shrink: 0; width: 40px; height: 22px; border-radius: var(--radius-xl); background: var(--surface-4); position: relative; transition: background .2s; }
.ui-switch::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: var(--surface); transition: transform .2s; }
.ui-toggle input:checked + .ui-switch { background: var(--accent); }
.ui-toggle input:checked + .ui-switch::before { transform: translateX(18px); }
.ui-toggle input:focus-visible + .ui-switch { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }

/* Segmented: mutually exclusive pills in a track. */
.ui-segmented { display: inline-flex; gap: .2rem; padding: .2rem; background: var(--surface-2); border-radius: var(--radius-md); align-self: flex-start; }
.ui-segmented label { margin: 0; padding: .35rem .8rem; border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.ui-segmented label.is-on { background: var(--accent); color: var(--text-inverse); }
.ui-segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.ui-segmented-mini label { padding: .25rem .6rem; font-size: var(--fs-xs); }

/* ── Flash ──────────────────────────────────────────────────────────────── */
.ui-flash { padding: .55rem .9rem; margin: 0 0 1rem; border-radius: var(--radius-md); font-weight: 600; display: flex; align-items: center; gap: .6rem; }
.ui-flash p { margin: 0; }
.ui-flash-success { background: var(--success-soft); color: var(--success-strong);}
.ui-flash-error   { background: var(--danger-soft);  color: var(--danger-strong);}
.ui-flash-warning { background: var(--warning-soft); color: var(--warning-strong);}
.ui-flash-info    { background: var(--accent-soft);  color: var(--accent);}

/* ── Badge ──────────────────────────────────────────────────────────────── */
.ui-badge { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .55rem; border-radius: var(--radius-lg); font-size: var(--fs-xs); font-weight: 700; line-height: 1.4; white-space: nowrap; background: var(--surface-3); color: var(--text); }
.ui-badge-neutral { background: var(--surface-inverse-soft); color: var(--text-inverse); }
.ui-badge-accent  { background: var(--accent-soft);  color: var(--accent); }
.ui-badge-success { background: var(--success-soft); color: var(--success-strong); }
.ui-badge-danger  { background: var(--danger-soft);  color: var(--danger-strong); }
.ui-badge-warning { background: var(--warning-soft); color: var(--warning-strong); }

/* ── Empty state ────────────────────────────────────────────────────────── */
/* Says what to do next, not just what is absent (UI_GUIDELINES 8). */
.ui-empty { text-align: center; padding: 1.5rem 1rem; color: var(--text-faint); font-size: var(--fs-sm); }
.ui-empty i { display: block; font-size: var(--fs-2xl); margin-bottom: .5rem; opacity: .6; }
.ui-empty .ui-btn { margin-top: .75rem; }

/* ── Colour picker ──────────────────────────────────────────────────────── */
/* Suggestions on a ring, the chosen colour in the middle (also the native
   picker), a hex field underneath. Dots are positioned by --x/--y. */
.ui-colour { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.ui-colour-ring { position: relative; width: 196px; height: 196px; margin: .2rem auto; }
.ui-colour-dot { position: absolute; left: var(--x); top: var(--y); width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); cursor: pointer; padding: 0; transition: transform .15s; }
.ui-colour-dot:hover { transform: scale(1.2); }
.ui-colour-dot.is-on { transform: scale(1.35); box-shadow: 0 0 0 2px var(--text-strong), 0 1px 3px rgba(0,0,0,.25); z-index: 1; }
.ui-colour-ring label.ui-colour-centre { position: absolute; left: 50%; top: 50%; width: 92px; height: 92px; margin: -46px 0 0 -46px; display: flex; border-radius: 50%; display: flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 4px var(--surface), 0 2px 8px rgba(0,0,0,.2); transition: background .2s; cursor: pointer; color: rgba(255,255,255,.85); font-size: var(--fs-lg); }
.ui-colour-centre input[type="color"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: none; padding: 0; }
.ui-colour-centre i { pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.ui-colour-hex { display: flex; align-items: center; gap: .3rem; font-weight: 600; color: var(--text-muted); font-size: var(--fs-md); }
.ui-colour-hex input[type="text"] { width: 5.4em; height: 30px; padding: .2rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-family: ui-monospace, monospace; font-size: var(--fs-sm); text-transform: lowercase; background: var(--surface); color: var(--text); }
.ui-colour-hex input:focus { outline: none; border-color: var(--accent); }

/* Visually hidden, still read by screen readers (icon-only buttons). */
.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; }

/* ── Top-bar notice + upload pill ──────────────────────────────────────── */
/* One slot between the logo and the storage pill, shared by the notification
   (js/notify.js) and the upload progress pill (js/upload-manager.js). Both are
   the height of the pills beside them. While a notice is up the upload pill
   steps aside and returns unchanged when the notice goes. Both margins are auto
   so the pill centres in the free space; the storage pill gives up its own
   auto margin while either is on screen or the space would split three ways. */
.tb-notice, .upload-hud {
  display: none; align-items: center; gap: .5rem;
  height: 48px; box-sizing: border-box; margin: 0 auto; flex: 0 0 auto; min-width: 0;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.15;
}
.tb-notice.is-visible, .upload-hud.is-visible { display: flex; }
body.has-tb-notice .upload-hud.is-visible { display: none; }
body.has-tb-notice .top-bar .storage-info,
body.has-upload-hud .top-bar .storage-info { margin-left: 0; }

.tb-notice { padding: 0 .35rem 0 1rem; max-width: min(560px, 60%); cursor: default; }
.tb-notice-icon { flex: 0 0 auto; font-size: var(--fs-base); }
.tb-notice-text { min-width: 0; flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-notice-close, .upload-hud-cancel {
  flex: 0 0 auto; width: 30px; height: 30px; border: none; border-radius: 50%;
  background: transparent; color: inherit; opacity: .6; font-size: var(--fs-sm); cursor: pointer;
  display: grid; place-items: center; transition: opacity .15s ease, background-color .15s ease;
}
.tb-notice-close:hover, .upload-hud-cancel:hover { opacity: 1; background: rgba(0,0,0,.08); }
/* Hidden but keeping its slot, so the text does not shift when the × goes. */
.tb-notice-close.is-hidden, .upload-hud-cancel.is-hidden { visibility: hidden; pointer-events: none; }

.tb-notice-success  { background: var(--success-soft); color: var(--success-strong);}
.tb-notice-error    { background: var(--danger-soft);  color: var(--danger-strong);}
.tb-notice-warning  { background: var(--warning-soft); color: var(--warning-strong);}
.tb-notice-info,
.tb-notice-progress { background: var(--accent-soft);  color: var(--accent);}

/* Upload pill: same shell, fixed width so the text change at the end of a batch
   ("Uploading 3 of 12" → "12 files uploaded") does not twitch the top bar. */
.upload-hud { width: 250px; padding: 0 .35rem 0 .9rem; background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.upload-hud-link { display: flex; align-items: center; gap: .5rem; min-width: 0; flex: 1 1 auto; text-decoration: none; color: inherit; }
.upload-hud-icon { flex: 0 0 auto; font-size: var(--fs-base); }
.upload-hud-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 auto; }
.upload-hud-text { font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-hud-track { height: 5px; border-radius: var(--radius-pill); background: rgba(var(--accent-rgb), .18); overflow: hidden; }
.upload-hud-fill { display: block; height: 100%; width: 0; border-radius: var(--radius-pill); background: var(--accent); transition: width .25s ease; }
.upload-hud.is-done { background: var(--success-soft); color: var(--success-strong); border-color: var(--success-border); }
.upload-hud.is-done .upload-hud-fill { background: var(--success); }
.upload-hud.is-warn { background: var(--warning-soft); color: var(--warning-strong); border-color: var(--warning-border); }
.upload-hud.is-warn .upload-hud-fill { background: var(--warning); }

/* No top bar (onboarding, quick start, deletion) or too narrow for a third
   pill: the notice — and the upload pill, during onboarding's first upload —
   floats at the bottom of the viewport instead. */
.tb-notice.is-floating, .upload-hud.is-floating { position: fixed; z-index: 1300; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.18); }
/* Floating pill keeps its desktop size on every viewport — it is not competing
   with other pills for top-bar room, so the ≤600px shrink rules below must not
   apply to it. */
.upload-hud.is-floating { height: 48px; width: 250px; padding: 0 .35rem 0 .9rem; gap: .5rem; }
.upload-hud.is-floating .upload-hud-icon { display: block; }
.upload-hud.is-floating .upload-hud-body { gap: 4px; }
@media (max-width: 900px) { .upload-hud { width: 190px; } .tb-notice { max-width: 45%; } }
@media (max-width: 600px) {
  .upload-hud { height: 40px; width: 140px; padding-left: .6rem; gap: .3rem; }
  .upload-hud-icon { display: none; }
  .upload-hud-body { gap: 3px; }
  /* Row 1 has no room for a third pill, so the notice takes the URL pill's row
     instead — exactly its box (order 99, full width, 32px, see _header.php),
     with the URL pill hidden underneath it until the notice goes. Nothing else
     in the top bar changes size. The upload pill stays in row 1. */
  .tb-notice:not(.is-floating) { order: 99; flex: 1 1 100%; height: 32px; margin: 0; max-width: none; padding: 0 .2rem 0 14px; gap: .4rem; }
  .tb-notice-close { width: 26px; height: 26px; }
  body.has-tb-notice .top-bar .site-link-group { display: none; }
  /* The desktop rule drops this margin to centre the notice in row 1; here the
     notice is in row 2, so the storage pill keeps its place on the right. */
  body.has-tb-notice .top-bar .storage-info { margin-left: auto; }
  body.has-tb-notice .upload-hud.is-visible { display: flex; }
}
@media (prefers-reduced-motion: reduce) { .upload-hud-fill { transition: none; } }

/* ── CodeInput: six one-digit boxes (sign-up verification style) ───────── */
.ui-code { display: flex; justify-content: center; gap: .5rem; margin: 1.25rem 0 .5rem; }
.ui-code-box { width: 2.75rem; height: 3.25rem; text-align: center; font-size: var(--fs-2xl); font-weight: 600; font-variant-numeric: tabular-nums; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--text-strong); padding: 0; }
.ui-code-box:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ui-code-box:disabled { background: var(--surface-3); color: var(--text-disabled); }
@media (max-width: 480px) {
  .ui-code { gap: .35rem; }
  .ui-code-box { width: 2.4rem; height: 3rem; }
}
