/* CINTI Portal Shell — shared CSS for every portal.
   Phase 1.2 of #44 Portal Modularization. Closes #1609.

   Portals include this stylesheet once. Design tokens come from CSS variables
   set on :root by portal-shell.js applyTokens() — themed portals (e.g. the
   projects portal with #7a88ff accent) override individual tokens via their
   manifest.json theme_overrides. This file ONLY uses var(--cinti-*) values
   so a token change is a one-place edit.

   What's in here:
     - Design-token variables (default values; JS overrides them on init)
     - Common typography baseline (Inter body, mono fallback)
     - Toast host + cards
     - Modal overlay + card + buttons
     - Avatar panel (right-side iframe drop-in)
     - Standard form input/select/textarea (matches the dev portal modal)
     - Skeleton-row loading state
     - Standard error / retry button

   What's NOT in here:
     - Portal-specific layout (each portal owns its own grid/tiles)
     - Portal-specific tile styling
     - Avatar-iframe internals (those live in the avatar app itself)
*/

/* ----- Design tokens (defaults; overridden by JS at runtime) -----
   CW Project #63 Wave 2 (2026-05-08): split into dark + light, plus a
   small bridge to the universal /portals/_shared/cinti-theme.css token
   layer. Portal-shell tokens (--cinti-bg / --cinti-text / --cinti-bg-card
   / etc.) override `cinti-theme.css` for portal pages; light mode adds
   matching values so the same shell renders on either palette. JS in
   portal-shell.js subscribes to CintiTheme.onChange and re-runs
   applyTokens() on theme flips so manifest theme_overrides survive. */
:root, [data-theme="dark"] {
  --cinti-accent:    #26bdd6;
  --cinti-accent-2:  #7ee2a8;
  --cinti-accent-3:  #ffb454;
  --cinti-accent-4:  #ff7a7a;
  --cinti-bg:        #0a0e1a;
  --cinti-bg-subtle: #080c1a;
  --cinti-bg-card:   #0e1420;
  --cinti-bg-input:  #0a0e1a;
  --cinti-border:    #1f2530;
  --cinti-border-2:  #1a1f2c;
  --cinti-text:      #cfd6e2;
  --cinti-text-dim:  #8a92a3;
  --cinti-text-mute: #5e6675;
  --cinti-font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --cinti-font-mono: 'SF Mono', 'JetBrains Mono', 'Monaco', monospace;
}

[data-theme="light"] {
  --cinti-accent:    #1a9ab5;
  --cinti-accent-2:  #00a050;
  --cinti-accent-3:  #d97500;
  --cinti-accent-4:  #d32f2f;
  --cinti-bg:        #f4f7fb;
  --cinti-bg-subtle: #ffffff;
  --cinti-bg-card:   #ffffff;
  --cinti-bg-input:  #eef2f7;
  --cinti-border:    rgba(26, 154, 181, 0.22);
  --cinti-border-2:  rgba(26, 154, 181, 0.12);
  --cinti-text:      #1a2332;
  --cinti-text-dim:  #5c6a82;
  --cinti-text-mute: #8a92a3;
}

/* ----- Toast ----- */
.cinti-toast-host {
  position: fixed;
  top: 64px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  pointer-events: none;
}
.cinti-toast {
  background: var(--cinti-bg-card);
  border: 1px solid var(--cinti-border);
  border-left: 3px solid var(--cinti-accent);
  padding: 10px 14px;
  border-radius: 4px;
  min-width: 260px;
  max-width: 380px;
  font-size: 12px;
  font-family: var(--cinti-font-body);
  color: var(--cinti-text);
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: cinti-toast-in 0.18s ease-out;
}
.cinti-toast.success { border-left-color: var(--cinti-accent-2); }
.cinti-toast.error   { border-left-color: var(--cinti-accent-4); }
.cinti-toast.pending { border-left-color: var(--cinti-accent-3); }
.cinti-toast .t-title {
  font-weight: 600;
  margin-bottom: 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.cinti-toast .t-body  { color: var(--cinti-text-dim); }
.cinti-toast .t-body a { color: var(--cinti-accent); text-decoration: none; }
.cinti-toast .t-close {
  float: right;
  cursor: pointer;
  color: var(--cinti-text-mute);
  padding-left: 8px;
  background: transparent;
  border: none;
  font-size: 14px;
  line-height: 1;
}
.cinti-toast .t-close:hover { color: var(--cinti-text); }
@keyframes cinti-toast-in {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ----- Modal ----- */
.cinti-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 26, 0.78);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  font-family: var(--cinti-font-body);
}
.cinti-modal-overlay.open { display: flex; }
.cinti-modal-card {
  width: min(640px, 92vw);
  max-height: 88vh;
  background: var(--cinti-bg-card);
  border: 1px solid var(--cinti-border);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
}
.cinti-modal-head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--cinti-border-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cinti-modal-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--cinti-text);
  letter-spacing: 0.3px;
}
.cinti-modal-close {
  background: none;
  border: none;
  color: var(--cinti-text-dim);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
}
.cinti-modal-close:hover { color: var(--cinti-text); }
.cinti-modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  color: var(--cinti-text);
  font-size: 13px;
  line-height: 1.55;
}
.cinti-modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--cinti-border-2);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

/* ----- Buttons (used in modal foot + ad-hoc) ----- */
.cinti-btn {
  font-family: inherit;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  padding: 7px 16px;
  border: 1px solid var(--cinti-border);
  background: transparent;
  color: var(--cinti-text-dim);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.cinti-btn:hover { color: var(--cinti-text); border-color: #2c3445; }
.cinti-btn.primary {
  background: var(--cinti-accent);
  color: var(--cinti-bg-subtle);
  border: none;
  font-weight: 600;
}
.cinti-btn.primary:hover { background: #3dcde0; }
.cinti-btn[disabled] { opacity: 0.6; cursor: not-allowed; }

/* ----- Form inputs (consumed by both modal forms and standalone) ----- */
.cinti-input,
.cinti-select,
.cinti-textarea {
  background: var(--cinti-bg-input);
  border: 1px solid var(--cinti-border);
  color: var(--cinti-text);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 4px;
  outline: none;
}
.cinti-input:focus,
.cinti-select:focus,
.cinti-textarea:focus { border-color: var(--cinti-accent); }
.cinti-textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.cinti-label {
  font-size: 11px;
  color: var(--cinti-text-dim);
  font-family: var(--cinti-font-mono);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ----- Avatar panel (right-side 440px iframe drop-in) ----- */
.cinti-avatar-panel {
  position: fixed;
  top: 56px;     /* below standard topbar */
  right: 0;
  bottom: 0;
  width: 440px;
  background: var(--cinti-bg-card);
  border-left: 1px solid var(--cinti-border);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.2s ease, width 0.2s ease, left 0.2s ease;
  z-index: 500;
}
.cinti-avatar-panel.collapsed {
  transform: translateX(calc(100% - 36px));
}
/* Expand cycle: normal → expanded (70%) → fullscreen → normal.
   Matches admin's .avatar-panel.expanded / .fullscreen behavior so any
   portal using portal-shell.js mountAvatar gets the same UX. */
.cinti-avatar-panel.expanded { width: 70vw; }
.cinti-avatar-panel.fullscreen {
  width: auto; left: 0; right: 0; top: 0; bottom: 0;
  border-left: none; z-index: 600;
}
.cinti-avatar-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: var(--cinti-bg);
}

/* ----- Canonical avatar header (orb + name + button cluster) -----
   CW #1911 + CW #2103 (Emmanuel 2026-05-12). Host page renders this header
   around the iframe; buttons postMessage into the iframe. Keep tokens in
   sync with admin/css/layout.css — the two patterns must look identical
   on the screen, only the wrapping selectors differ (.cinti-avatar-* vs
   admin's .avatar-*). */
.cinti-avatar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--cinti-border);
  background: var(--cinti-bg-subtle);
  flex: 0 0 auto;
}
.cinti-avatar-orb {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, rgba(38,189,214,0.6), rgba(38,189,214,0.15) 55%, transparent 70%);
  box-shadow: 0 0 10px rgba(38,189,214,0.3);
  animation: cintiOrbPulse 3s ease-in-out infinite;
}
@keyframes cintiOrbPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(38,189,214,0.3); }
  50%      { box-shadow: 0 0 16px rgba(38,189,214,0.5), 0 0 32px rgba(38,189,214,0.15); }
}
.cinti-avatar-name   { font-size: 13px; font-weight: 600; color: var(--cinti-accent); }
.cinti-avatar-status { font-size: 9px;  color: var(--cinti-success, #10b981); }

.avatar-hdr-cluster {
  display: flex; align-items: center; gap: 4px;
  margin-left: auto;
}
.avatar-hdr-btn {
  background: none; border: none; color: var(--cinti-text-dim);
  cursor: pointer; padding: 0; transition: color 0.2s;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 24px; box-sizing: border-box;
}
.avatar-hdr-btn:hover { color: var(--cinti-accent); }
.avatar-mute-btn.muted          { color: var(--cinti-danger, #ef4444); }
.avatar-mute-btn.muted:hover    { color: #ff7878; }
.avatar-cam-btn.active          { color: var(--cinti-accent); }
.avatar-cam-btn.preview         { color: var(--cinti-success, #10b981); }
.avatar-settings-btn.active     { color: var(--cinti-accent); }
/* Speed button is text-labeled (1x/1.25x/1.5x/2x). Mono+bold+tight tracking
   keeps it crisp at 13px so it visually matches the 16px SVGs next to it. */
.avatar-speed-btn {
  font-family: var(--cinti-font-mono);
  font-size: 13px; font-weight: 700; line-height: 1;
  letter-spacing: -0.04em;
}
.avatar-speed-btn:not(.baseline) { color: var(--cinti-accent); }
/* Mute icon's SVG geometry fills ~70% of its 24×24 viewBox — bump to 18px
   so its perceived weight matches the camera/settings icons. */
.avatar-mute-btn svg { width: 18px; height: 18px; }

/* ----- Skeleton loading row ----- */
.cinti-skeleton-row {
  height: 18px;
  background: linear-gradient(90deg, var(--cinti-bg-card) 0%, #161a22 50%, var(--cinti-bg-card) 100%);
  background-size: 200% 100%;
  border-radius: 3px;
  margin: 8px 0;
  animation: cinti-skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes cinti-skeleton-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ----- Error state with retry ----- */
.cinti-error-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--cinti-text-dim);
  font-size: 13px;
}
.cinti-error-state .reason {
  color: var(--cinti-text-mute);
  font-size: 11px;
  margin-top: 6px;
}
.cinti-error-state .cinti-btn { margin-top: 14px; }
