/* AMAADOR Chemical Safety Studio — r6 polish layer (2026-11-26).
   Loaded after chem-pro-r5. Only refines: focus, motion, type, depth, mobile, RTL, and the new
   undo toast / search keyboard / shortcuts sheet. Delete this file to fall back to r5. */

/* ---------- 1. Tokens: one radius scale, richer depth, premium accent ---------- */
#chem-pro-app,
.cp-spot-backdrop,
.cp-toast {
  --cp-r-xs: 6px;
  --cp-r-sm: 10px;
  --cp-r: 14px;
  --cp-r-lg: 20px;
  --cp-ease: cubic-bezier(.22, 1, .36, 1);
  --cp-ring: 0 0 0 3px color-mix(in srgb, var(--cp-ac) 35%, transparent);
  --cp-hair: inset 0 1px 0 rgba(255, 255, 255, .55);
  --cp-grad: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 55%, #4c1d95 100%);
}
html[data-theme=dark] #chem-pro-app,
html[data-theme=dark] .cp-spot-backdrop,
html[data-theme=dark] .cp-toast {
  --cp-hair: inset 0 1px 0 rgba(255, 255, 255, .06);
  --cp-grad: linear-gradient(135deg, #a78bfa 0%, #7c3aed 60%, #5b21b6 100%);
}

/* Numbers line up in tables, rings, KPIs */
#chem-pro-app { font-feature-settings: "tnum" 1, "cv11" 1; }
#chem-pro-app b, #chem-pro-app strong { font-weight: 700; }

/* ---------- 2. Arabic: real Arabic typeface instead of system fallback ---------- */
@font-face { font-family: 'IBM Plex Sans Arabic'; src: url('/assets/hse-immersive/fonts/ibm-plex-sans-arabic-400.woff2') format('woff2'); font-weight: 400 500; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans Arabic'; src: url('/assets/hse-immersive/fonts/ibm-plex-sans-arabic-600.woff2') format('woff2'); font-weight: 600 800; font-display: swap; }
#chem-pro-app[dir=rtl],
.cp-spot-backdrop[dir=rtl],
.cp-toast[dir=rtl] {
  font-family: 'Geist', 'IBM Plex Sans Arabic', system-ui, sans-serif;
}
#chem-pro-app[dir=rtl] .cp-kicker,
#chem-pro-app[dir=rtl] .cp-nav-sec,
.cp-spot-backdrop[dir=rtl] .cp-spot-group { letter-spacing: 0; text-transform: none; }

/* ---------- 3. Keyboard focus that is visible but quiet ---------- */
#chem-pro-app :is(button, a, select, input, textarea, label, [tabindex]):focus-visible,
.cp-spot-backdrop :is(button, input):focus-visible,
.cp-toast button:focus-visible {
  outline: none !important;
  box-shadow: var(--cp-ring) !important;
  border-radius: var(--cp-r-sm);
}
#chem-pro-app input:focus, #chem-pro-app select:focus, #chem-pro-app textarea:focus {
  border-color: var(--cp-ac) !important;
  box-shadow: var(--cp-ring) !important;
}

/* ---------- 4. Depth & surfaces ---------- */
#chem-pro-app {
  border-radius: var(--cp-r-lg);
}
#chem-pro-app .cp-rings-card,
#chem-pro-app .cp-card,
#chem-pro-app .cp-kpi,
#chem-pro-app .cp-area-card,
#chem-pro-app .cp-exp-card,
#chem-pro-app .cp-cab {
  box-shadow: var(--cp-hair), var(--cp-sh);
  transition: transform 220ms var(--cp-ease), box-shadow 220ms var(--cp-ease), border-color 220ms ease;
}
#chem-pro-app .cp-exp-card:hover,
#chem-pro-app .cp-area-card:hover,
#chem-pro-app .cp-cab:hover {
  transform: translateY(-2px);
  border-color: var(--cp-ln-strong);
}
#chem-pro-app .cp-btn-pri {
  background: var(--cp-grad) !important;
  border-color: transparent !important;
  color: #fff !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 6px 18px color-mix(in srgb, var(--cp-ac) 35%, transparent);
}
#chem-pro-app .cp-btn-pri:hover { filter: brightness(1.06); }
#chem-pro-app .cp-btn { transition: background-color 140ms ease, border-color 140ms ease, transform 120ms var(--cp-ease), filter 140ms ease; }
#chem-pro-app .cp-btn:active { transform: scale(.97); }
#chem-pro-app .cp-logo { background: var(--cp-grad) !important; color: #fff !important; box-shadow: 0 6px 16px color-mix(in srgb, var(--cp-ac) 40%, transparent); }

/* Sticky app toolbar that docks under the floating site header while you work */
#chem-pro-app .cp-topbar {
  position: sticky;
  top: 74px;
  z-index: 30;
  border-radius: var(--cp-r-lg) var(--cp-r-lg) 0 0;
  background: color-mix(in srgb, var(--cp-card) 88%, transparent) !important;
  backdrop-filter: blur(14px) saturate(160%) !important;
  -webkit-backdrop-filter: blur(14px) saturate(160%) !important;
}
#chem-pro-app .cp-sidebar { top: 140px; }

/* Nav: animated active pill */
#chem-pro-app .cp-nav-btn { transition: background-color 160ms ease, color 160ms ease; position: relative; }
#chem-pro-app .cp-nav-btn.on::before {
  content: ""; position: absolute; inset-inline-start: -2px; top: 22%; bottom: 22%; width: 3px;
  border-radius: 3px; background: var(--cp-ac);
}

/* Stage fades in on every view switch */
#chem-pro-app .cp-stage > * { animation: cp-in 260ms var(--cp-ease) both; }
@keyframes cp-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* …but not while typing (re-render after an edit must not flicker) */
#chem-pro-app.cp-editing .cp-stage > * { animation: none; }

/* Ring fills animate */
#chem-pro-app .cp-ring-anim { transition: stroke-dashoffset 700ms var(--cp-ease); }

/* ---------- 5. Loading state for buttons ---------- */
#chem-pro-app .is-loading { position: relative; color: transparent !important; pointer-events: none; }
#chem-pro-app .is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: cp-spin 700ms linear infinite;
}
@keyframes cp-spin { to { transform: rotate(360deg); } }

/* ---------- 6. Toast: logical position, action button, RTL ---------- */
.cp-toast {
  right: auto !important;
  inset-inline-end: 22px;
  display: flex; align-items: center; gap: 14px;
  padding: 11px 12px 11px 16px;
  border-radius: var(--cp-r);
  max-width: min(440px, calc(100vw - 32px));
}
.cp-toast.show { pointer-events: auto; }
.cp-toast-act {
  font: inherit; font-weight: 700; font-size: .78rem;
  border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer;
  background: var(--cp-ac); color: #fff;
}
html[data-theme=dark] .cp-toast-act { color: #1e1033; }
.cp-toast-act:hover { filter: brightness(1.08); }

/* ---------- 7. Search palette: active row, footer hints, kbd ---------- */
.cp-spot-card { border-radius: var(--cp-r-lg) !important; overflow: hidden; }
.cp-spot-row.is-active { background: var(--cp-ac-soft); box-shadow: inset 3px 0 0 var(--cp-ac); }
.cp-spot-backdrop[dir=rtl] .cp-spot-row.is-active { box-shadow: inset -3px 0 0 var(--cp-ac); }
.cp-spot-foot {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 9px 14px; border-top: 1px solid var(--cp-ln);
  font-size: .72rem; color: var(--cp-mu); background: var(--cp-soft);
}
.cp-spot-foot span { display: inline-flex; align-items: center; gap: 4px; }
.cp-spot-backdrop kbd, #chem-pro-app kbd {
  font: 600 .68rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-width: 20px; padding: 3px 6px; border-radius: 6px; text-align: center;
  border: 1px solid var(--cp-ln-strong); border-bottom-width: 2px;
  background: var(--cp-card); color: var(--cp-tx);
}
@media (hover: none) { .cp-spot-foot { display: none; } }

/* Shortcuts sheet */
.cp-help .cp-help-card { max-width: 440px; padding: 6px 0 10px; }
.cp-help-hd { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px 8px; font-size: .95rem; }
.cp-help-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 18px; font-size: .84rem; border-top: 1px solid var(--cp-ln); }
.cp-help-row span:last-child { display: inline-flex; gap: 4px; }
.cp-help[hidden], .cp-spot-backdrop[hidden] { display: none !important; }

/* ---------- 8. Mobile: swipeable nav, compact top bar ---------- */
@media (max-width: 820px) {
  #chem-pro-app .cp-shell { grid-template-columns: minmax(0, 1fr) !important; }
  #chem-pro-app .cp-sidebar { min-width: 0; }
  #chem-pro-app .cp-topbar { position: relative; top: auto; }
  #chem-pro-app .cp-nav {
    flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none;
    margin: 0 -12px; padding: 2px 12px 6px; scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
            mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
  }
  #chem-pro-app .cp-nav::-webkit-scrollbar { display: none; }
  #chem-pro-app .cp-nav-btn { scroll-snap-align: start; border: 1px solid var(--cp-ln); border-radius: 999px !important; white-space: nowrap; }
  #chem-pro-app .cp-nav-btn.on { background: var(--cp-ac) !important; color: #fff !important; border-color: transparent; }
  #chem-pro-app .cp-nav-btn.on .cp-nav-cnt { background: rgba(255, 255, 255, .22); color: #fff; }
  #chem-pro-app .cp-nav-btn.on::before { display: none; }
  #chem-pro-app .cp-rings-card { padding: 12px 14px; }
  .cp-toast { inset-inline: 16px; bottom: 16px; max-width: none; justify-content: space-between; }
}
@media (max-width: 720px) {
  #chem-pro-app .cp-preset-sel, #chem-pro-app .cp-vdiv { display: none; }
  #chem-pro-app .cp-top-act { width: 100%; justify-content: flex-end; }
  #chem-pro-app .cp-top-act .cp-btn-pri { flex: 1; justify-content: center; }
}
/* Site header: keep the logo readable next to the language pill on small phones */
@media (max-width: 420px) {
  .hx-nav .hx-sub { display: none !important; }
  .hx-nav .hx-brand { flex-shrink: 1; min-width: 0; }
  .hx-nav .hx-lk { width: 100px; height: auto; }
}

/* ---------- 9. Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #chem-pro-app *, .cp-spot-backdrop *, .cp-toast { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  #chem-pro-app .cp-topbar { position: static; backdrop-filter: none !important; }
  .cp-toast, .cp-help { display: none !important; }
}

/* ---------- 10. Next steps card ---------- */
#chem-pro-app .cp-next { border: 1px solid var(--cp-ln); border-radius: var(--cp-r-lg); padding: 12px 10px 8px; box-shadow: var(--cp-hair), var(--cp-sh); }
#chem-pro-app .cp-next-hd { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 6px; }
#chem-pro-app .cp-next-tip { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .68rem; font-weight: 700; color: var(--cp-mu); border: 1px solid var(--cp-ln-strong); cursor: help; }
#chem-pro-app .cp-next-row {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 6px; border: 0; border-radius: var(--cp-r-sm);
  background: transparent; color: var(--cp-tx); font: inherit; font-size: .78rem; text-align: start; cursor: pointer; line-height: 1.3;
  transition: background-color 140ms ease;
}
#chem-pro-app .cp-next-row:hover { background: var(--cp-soft); }
#chem-pro-app .cp-next-row span { flex: 1; }
#chem-pro-app .cp-next-row i { font-style: normal; color: var(--cp-mu); transition: transform 160ms var(--cp-ease); }
#chem-pro-app[dir=rtl] .cp-next-row i { transform: scaleX(-1); }
#chem-pro-app .cp-next-row:hover i { transform: translateX(2px); }
#chem-pro-app .cp-next-n { min-width: 26px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; font-size: .74rem; }
#chem-pro-app .cp-next-n.err { background: var(--cp-err-soft); color: var(--cp-err); }
#chem-pro-app .cp-next-n.warn { background: var(--cp-warn-soft); color: var(--cp-warn); }
#chem-pro-app .cp-next-n.info { background: var(--cp-info-soft); color: var(--cp-info); }
#chem-pro-app .cp-next-ok { display: flex; gap: 8px; align-items: center; padding: 4px 6px 6px; font-size: .78rem; color: var(--cp-ok); }
@media (max-width: 820px) { #chem-pro-app .cp-next { order: 2; } }

@media (hover: none) { #chem-pro-app .cp-kbd { display: none; } }
#chem-pro-app .cp-insp-hd { scroll-margin-top: 84px; }
