/* Shared chrome — the signed-in user "pill" (avatar + name + caret) and its
   dropdown panel. Used by both surfaces that show a signed-in operator:
   the inline content editor (core/cms/inject.php) and the operator
   dashboard (core/dashboard/load.php). Previously lived in cms.css
   and was double-loaded from dashboard — that leaky upward dep is
   why this file exists.

   Class names keep the `.admin-profile-*` prefix because "admin" here
   means the *signed-in user role*, not a dir name. */

/* Central UI design tokens + pure-visual components + functional-
 * component styles — every admin surface that loads chrome.css picks
 * them up automatically. CSS-only components and the SHELLS of
 * functional components (modal/dropdown/popover frame styling) live
 * here so the markup works even without their companion JS loaded.
 * The companion JS for functional components self-loads on the first
 * render_<name>() PHP-helper call (same pattern as core/lib/toast.php).
 * See core/lib/ui/README.md for the full reference. */
@import url('./ui/tokens.css');
@import url('./ui/components.css');
@import url('./ui/modal.css');
@import url('./ui/forms.css');
@import url('./ui/feedback.css');

/* ─── Top admin chrome bar — shared by CMS / Newsletter studio / Platform
 *      dashboard / public-when-signed-in. Each surface adds the
 *      .admin-chrome-bar base alongside its own module class (.admin-bar,
 *      .topbar, .dashboard-bar) for module-specific children. The base
 *      owns: dark palette, terra underline, fixed-top positioning,
 *      z-index above everything else.
 *
 *      Variants:
 *        .admin-chrome-bar--inline  — sit inside a grid track instead of
 *                                     overlaying the page (newsletter
 *                                     studio uses a grid layout where
 *                                     row 1 is the bar).
 *        .admin-chrome-bar--public  — green status dot variant, used by
 *                                     render_public_admin_bar().
 * ─────────────────────────────────────────────────────────────────────── */
.admin-chrome-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--ui-chrome-bg);
  color: var(--ui-chrome-text);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  font-family: var(--ui-font-family-sans);
  font-size: 13px;
  z-index: 10000;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  border-bottom: 2px solid var(--ui-chrome-accent);
  transition: transform 0.2s ease-out;
}
/* Auto-hide during scrolling on mobile — iOS Chrome's dynamic
 * URL bar makes position:fixed drift during scroll. Sliding the
 * bar off-screen entirely sidesteps that drift. cms.js adds the
 * class while the user is actively scrolling down and removes it
 * on scroll-up or scroll-end. Scoped to body.is-edit-mode so the
 * dashboard's identical bar isn't affected. */
body.is-edit-mode .admin-chrome-bar.is-scroll-hidden {
  transform: translateY(-100%);
}
.admin-chrome-bar--inline {
  position: static;
  grid-column: 1 / -1;
  top: auto; left: auto; right: auto;
}
@media (max-width: 600px) {
  .admin-chrome-bar { padding: 0 14px; gap: 12px; }
}

/* CMS layout — title left, right-block right. */
.admin-bar { justify-content: space-between; }
.admin-bar-title       { font-weight: 500; letter-spacing: 0.4px; display: flex; align-items: center; gap: 10px; }
.admin-bar-title .admin-bar-sub { opacity: 0.55; margin-left: 10px; font-weight: 400; }

/* Staging warning chip — leads the (red-striped) chrome bar. A dark inset
   keeps the text legible over the diagonal stripes. */
.admin-bar-staging {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.30);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.admin-bar-staging-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #fff; flex: 0 0 auto;
  animation: adminStagingPulse 1.4s infinite;
}
.admin-bar-staging-label { font-weight: 700; }
.admin-bar-staging-meta  { font-weight: 400; text-transform: none; letter-spacing: 0.02em; opacity: 0.9; }
@keyframes adminStagingPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (max-width: 640px) { .admin-bar-staging-meta { display: none; } }
.admin-bar-right       { display: flex; align-items: center; gap: 14px; }
.admin-bar-link        { color: var(--ui-chrome-text); opacity: 0.7; text-decoration: none; transition: opacity .15s; }
.admin-bar-link:hover  { opacity: 1; }
/* Public variant: green status dot to distinguish from CMS edit mode. */
.admin-chrome-bar--public .admin-bar-dot,
.admin-bar--public .admin-bar-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ui-chrome-dot-public);
  box-shadow: 0 0 6px var(--ui-chrome-dot-public);
}

/* Body-scroll lock while any admin-bar dropdown is open. Same pattern
 * as body.ui-modal-open for modals — prevents the page behind from
 * scrolling when the user swipes inside a dropdown (especially relevant
 * on iOS Safari where overscroll-behavior:contain alone doesn't kick in
 * when the inner content isn't tall enough to scroll). :has() is widely
 * supported (Safari 15.4+, Chrome 105+, Firefox 121+). */
body:has(.cms-pages-menu:not([hidden])),
body:has(.admin-profile-panel:not([hidden])),
body:has(.admin-chrome-bell__panel:not([hidden])) {
  overflow: hidden;
}

.admin-profile-wrap { position: relative; }
.admin-profile-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  background: var(--ui-chrome-surface);
  border: 1px solid var(--ui-chrome-border);
  border-radius: 20px;
  color: var(--ui-chrome-text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.admin-profile-btn:hover {
  background: var(--ui-chrome-surface-hover);
  border-color: var(--ui-chrome-border);
}
.admin-profile-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: block;
}
.admin-profile-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ui-chrome-accent);
  color: var(--ui-chrome-text);
  font-weight: 600;
  font-size: 11px;
}
.admin-profile-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-profile-caret {
  font-size: 9px;
  opacity: 0.6;
}

/* Profile-panel popover frame + dropdown items use central
 * .ui-popover.ui-popover--dark + .ui-dropdown + .ui-dropdown__item
 * (see core/lib/ui/components.css). Only the chrome-specific sub-
 * elements (header, section labels, subitem indent, item-icon
 * styling) live here. */
.admin-profile-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  z-index: 10001;
  overflow: hidden;
  padding: 0;
}
.admin-profile-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--ui-chrome-border-soft);
}
.admin-profile-header-name {
  color: var(--ui-chrome-text);
  font-weight: 600;
  font-size: 12px;
}
.admin-profile-header-email {
  color: var(--ui-chrome-text-dim);
  font-size: 11px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-profile-item-icon { opacity: 0.6; }
.admin-profile-section-label {
  padding: 10px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(246, 241, 237, 0.45);
}
.admin-profile-subitem { padding-left: 32px; }

/* Modal overlay used by admin-context modals (debug-media iframe, cms
 * page-info, etc). Backdrop / centering / [hidden] come from .ui-modal
 * in core/lib/ui/components.css; the dialect overrides z-index (must
 * clear the admin chrome bar at 10000) and removes the default 16px
 * inset so the per-modal frame can use 95vw / 90vh sizing as before. */
.admin-modal-overlay {
  z-index: 10010;
  padding: 0;
}
.admin-modal-frame {
  position: relative;
  width: min(720px, 95vw);
  /* svh = smallest viewport height (browser chrome fully expanded).
   * Guarantees the modal fits even after iOS Safari's URL bar /
   * bottom toolbar reappear — with dvh the modal sizes to the CURRENT
   * (possibly collapsed-chrome) viewport and clips when chrome returns.
   * 88% leaves headroom for backdrop padding + safe-area-insets so the
   * close button is always reachable on iPhone 15. */
  max-height: 88vh;
  max-height: 88svh;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  /* Flex column so .admin-modal-content (or any flex-1 child) can be the
   * scroll container — title/header stays pinned while the body scrolls
   * within the frame's viewport-capped height. This is the
   * design-system-wide pattern; matches .ui-modal__frame in modal.css. */
  display: flex;
  flex-direction: column;
}
[data-theme="dark"] .admin-modal-frame { background: #0f1117; }
.admin-modal-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.admin-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f6f1ed;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background .15s, transform .15s;
}
.admin-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}


/* ── .ai-badge ──────────────────────────────────────────────────────
 * Small inline pill for marking actions that call a paid AI model
 * (i.e. log to /dashboard/?p=usage and cost real money).
 *
 * Convention: append to any button/action label that triggers an
 * Anthropic call so users can distinguish deterministic actions
 * (recipes, validators, deterministic fixes) from AI-spending ones.
 *
 * Usage:
 *   <button>Auto-fix <span class="ai-badge">AI</span></button>
 *   <button class="ai-action">Suggest</button>     ← .ai-action sets ::after badge
 *
 * Don't apply to widgets/pages that USE AI internally but aren't
 * triggered per click — only to user-triggered actions.
 */
.ai-badge {
  display: inline-block;
  padding: 1px 6px;
  margin-left: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.4;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff;
  border-radius: 4px;
  vertical-align: middle;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
}
.ai-action::after {
  content: 'AI';
  display: inline-block;
  padding: 1px 6px;
  margin-left: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.4;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff;
  border-radius: 4px;
  vertical-align: middle;
  text-transform: uppercase;
}
[data-theme="dark"] .ai-badge,
[data-theme="dark"] .ai-action::after {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
}
/* ─── "Send feedback" modal (Alovai) ─────────────────────────────────
   Opened from the .admin-bar profile menu. Multipart submit to
   /core/cms/api/feedback.php; attachments go through the uploads repo,
   email goes to alovai.feedback_email (core/config/secrets.json). */

.admin-modal-frame--feedback {
  width: min(620px, 95vw);
  /* height auto + max-height inherited from base .admin-modal-frame
   * (88svh with vh fallback). svh ensures iOS Safari's expanded chrome
   * doesn't clip the modal. */
  display: flex;
  flex-direction: column;
}
.admin-modal-frame--feedback .admin-modal-content {
  padding: 30px 32px 24px;
  overflow-y: auto;
}
.admin-modal-frame--feedback h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 600;
}
.afb-intro {
  margin: 0 0 18px;
  color: #6b6b78;
  font-size: 0.9rem;
  line-height: 1.5;
}
[data-theme="dark"] .afb-intro { color: #9aa0ad; }

.afb-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.afb-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.afb-label {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6b6b78;
  font-weight: 600;
}
[data-theme="dark"] .afb-label { color: #8a90a0; }
.afb-opt {
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: #aaa;
}

/* .afb-input / .afb-select / .afb-textarea → .ui-input / .ui-select /
 * .ui-textarea (core/lib/ui/forms.css). The feedback modal's
 * markup already carries the canonical primitive classes; this layer
 * only kept the visual chrome that the primitives now own. */

.afb-attachments {
  background: rgba(124, 77, 255, 0.05);
  border: 1px dashed rgba(124, 77, 255, 0.28);
  border-radius: 8px;
  padding: 12px 14px;
}
[data-theme="dark"] .afb-attachments {
  background: var(--ui-color-brand-soft);
}
.afb-dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.afb-pick-btn {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  color: #1f1f24;
  transition: border-color .15s, color .15s;
}
.afb-pick-btn:hover { border-color: var(--ui-color-brand); color: var(--ui-color-brand); }
[data-theme="dark"] .afb-pick-btn {
  background: #1a1d24;
  color: #e6e6ec;
  border-color: rgba(255,255,255,0.14);
}
.afb-dropzone-hint {
  font-size: 0.82rem;
  color: #888;
  font-style: italic;
}
[data-theme="dark"] .afb-dropzone-hint { color: #8a90a0; }

.afb-file-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.afb-file-list:empty { display: none; }
.afb-file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  font-size: 0.86rem;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .afb-file-item {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.08);
}
.afb-file-thumb {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.afb-file-name {
  font-family: var(--ui-font-family-mono);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.afb-file-size {
  color: #888;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}
.afb-file-remove {
  background: none;
  border: 0;
  color: #c0392b;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 4px;
}
.afb-file-remove:hover { background: rgba(192, 57, 43, 0.1); }

.afb-actions {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.afb-meta {
  font-size: 0.78rem;
  color: #888;
}
.afb-submit {
  background: var(--ui-color-brand);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, transform .15s;
}
.afb-submit:hover  { background: var(--ui-color-brand-strong); }
.afb-submit:active { transform: translateY(1px); }
.afb-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.afb-result {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.afb-result--ok  { background: #e7f7ee; color: #16703a; }
.afb-result--err { background: #fdebe9; color: #a31a13; }
[data-theme="dark"] .afb-result--ok  { background: rgba(22,112,58,0.18); color: #80d99f; }
[data-theme="dark"] .afb-result--err { background: rgba(163,26,19,0.18); color: #f49a93; }
