/* Help widget, notification bell and menu — every page (templates/_support_widget.html).
   Tokens only; see docs/design/design-tokens-guidelines.md. */

.sp-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── Launcher ─────────────────────────────────────────────────────────── */
.sp-launcher {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-4) 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s;
}
.sp-launcher:hover { background: var(--surface-soft); border-color: var(--border-strong); transform: none; }
.sp-launcher:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sp-launcher-icon { flex: 0 0 auto; color: var(--accent-text); }
.sp-launcher-dot,
.sp-bell-count {
  position: absolute;
  top: -3px;
  right: -3px;
}
.sp-launcher-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
}
.sp-launcher-dot[hidden],
.sp-bell-count[hidden] { display: none; }
/* Consent's corner pill (pages without their own cookie link) owns that spot. */
body:has(.consent-fab) .sp-launcher { bottom: 64px; }
.sp-open .sp-launcher { visibility: hidden; }

/* ── Panel ────────────────────────────────────────────────────────────── */
.sp-backdrop {
  position: fixed;
  inset: 0;
  z-index: 4090;
  background: transparent;
}
.sp-backdrop[hidden] { display: none; }
.sp-panel {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 4100;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 2 * var(--space-5)));
  max-height: calc(100vh - 2 * var(--space-5));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-ui);
  animation: sp-in 0.16s ease-out;
}
.sp-panel[hidden] { display: none; }
.sp-panel.is-drag { outline: 2px dashed var(--accent-border); outline-offset: -6px; }
@keyframes sp-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.sp-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-2) var(--space-5);
}
.sp-title { margin: 0; font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.01em; }
.sp-promise { margin: var(--space-1) 0 0; color: var(--ink-soft); font-size: var(--text-sm); }
.sp-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-soft);
}
.sp-icon-btn:hover { background: var(--surface-soft); color: var(--ink); transform: none; }
.sp-icon-btn svg { flex: 0 0 auto; }

.sp-body {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5) var(--space-4);
  overflow-y: auto;
}
.sp-body[hidden] { display: none; }

.sp-kinds {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}
.sp-kind { position: relative; display: block; margin: 0; cursor: pointer; }
.sp-kind input { position: absolute; opacity: 0; pointer-events: none; }
.sp-kind span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 var(--space-2);
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: var(--text-md);
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}
.sp-kind:hover span { color: var(--ink); }
.sp-kind input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--border-strong), 0 1px 2px rgba(0, 0, 0, 0.06);
}
.sp-kind input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.sp-textarea,
.sp-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
}
.sp-textarea {
  min-height: 116px;
  max-height: 40vh;
  padding: var(--space-3);
  line-height: 1.5;
  resize: vertical;
}
.sp-input { min-height: 40px; padding: 0 var(--space-3); }
.sp-textarea:focus,
.sp-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.sp-textarea[aria-invalid="true"],
.sp-input[aria-invalid="true"] { border-color: var(--danger); }
.sp-mono { font-family: var(--font-mono); font-size: var(--text-sm); }

.sp-attach-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
}
.sp-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: var(--text-sm);
  font-weight: 600;
}
.sp-chip-btn:hover { background: var(--surface-soft); color: var(--ink); transform: none; }
.sp-chip-btn svg { flex: 0 0 auto; }
.sp-chip-btn[hidden] { display: none; }
.sp-check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--ink-soft);
  font-size: var(--text-sm);
  cursor: pointer;
}
.sp-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.sp-check[hidden] { display: none; }

.sp-preview {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}
.sp-preview[hidden] { display: none; }
.sp-preview img {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.sp-preview-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--ink-soft);
}
.sp-link-btn {
  padding: var(--space-1) var(--space-2);
  border: 0;
  background: none;
  color: var(--accent-text);
  font-size: var(--text-sm);
  font-weight: 600;
}
.sp-link-btn:hover { text-decoration: underline; transform: none; }

.sp-email { display: grid; gap: var(--space-1); }
.sp-label { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.sp-optional { margin-left: var(--space-1); font-weight: 500; color: var(--ink-soft); }
.sp-help { margin: 0; font-size: var(--text-sm); color: var(--ink-soft); line-height: 1.45; }
.sp-field-error,
.sp-form-error { margin: 0; font-size: var(--text-sm); color: var(--danger-text); }
.sp-form-error {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--danger-soft);
}
.sp-field-error[hidden],
.sp-form-error[hidden] { display: none; }

.sp-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Global details/summary render as a bordered card; this is a quiet footnote. */
.sp-context {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: var(--text-sm);
  color: var(--ink-soft);
}
.sp-context summary {
  padding: 0;
  cursor: pointer;
  list-style: none;
  font-weight: 500;
  color: var(--ink-soft);
  line-height: 1.45;
}
.sp-context summary:hover { color: var(--ink); }
.sp-context summary::-webkit-details-marker { display: none; }
.sp-context summary::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 var(--space-2) 2px 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.12s;
}
.sp-context[open] summary::before { transform: rotate(45deg); }
.sp-context summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sp-context-list {
  display: grid;
  gap: 2px;
  margin: var(--space-2) 0 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--surface-soft);
}
.sp-context-list div { display: flex; gap: var(--space-3); }
.sp-context-list dt { flex: 0 0 76px; color: var(--ink-soft); }
.sp-context-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  color: var(--ink);
}

.sp-actions { display: flex; align-items: center; gap: var(--space-3); }
.sp-send { min-width: 120px; min-height: 42px; }
.sp-kbd {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-soft);
}

/* Sent */
.sp-sent { justify-items: start; padding-top: var(--space-4); outline: none; }
.sp-sent-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success-text);
}
.sp-sent-title { margin: 0; font-size: var(--text-xl); }
.sp-sent-ref { margin: 0; color: var(--ink-soft); font-size: var(--text-md); }
.sp-sent-ref code {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-soft);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  color: var(--ink);
}
.sp-sent-note { margin: 0; color: var(--ink); line-height: 1.5; }
.sp-sent-link { display: grid; gap: var(--space-2); width: 100%; }
.sp-sent-link[hidden] { display: none; }
.sp-copy-row { display: flex; gap: var(--space-2); }
.sp-copy-row .sp-input { flex: 1 1 auto; min-width: 0; }
.sp-copy { flex: 0 0 auto; }
.sp-sent-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }

.sp-foot {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-light);
}
.sp-foot-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--ink-soft);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
}
.sp-foot-link:hover { color: var(--ink); text-decoration: underline; }
.sp-foot-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: 18px;
  text-align: center;
}
.sp-foot-count[hidden] { display: none; }

/* ── Bells (sidebar head + mobile top bar) ─────────────────────────────── */
.appnav-bell,
.topbar-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
}
.appnav-bell { width: 34px; height: 34px; margin-left: auto; margin-right: var(--space-1); border-radius: var(--radius); }
.topbar-icon-btn { width: 40px; height: 40px; border-radius: 9px; }
.appnav-bell:hover,
.topbar-icon-btn:hover { background: var(--surface-soft); color: var(--ink); transform: none; }
.appnav-bell[aria-expanded="true"],
.topbar-icon-btn[aria-expanded="true"] { background: var(--surface-soft); border-color: var(--border); color: var(--ink); }
.appnav-bell[hidden],
.topbar-icon-btn[hidden] { display: none; }
.appnav-bell svg,
.topbar-icon-btn svg { flex: 0 0 auto; }
.sp-bell-count {
  top: 1px;
  right: 0;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
  color: #fff;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 600;
  line-height: 17px;
  text-align: center;
}
.mobile-topbar-actions { display: flex; align-items: center; gap: var(--space-1); margin-left: auto; }
/* Master's touch search already takes the free space to the right; sit beside it. */
.mobile-topbar-search + .mobile-topbar-actions { margin-left: 0; }
.appnav-count--accent { background: var(--danger-soft); color: var(--danger-text); }

/* ── Bell menu ────────────────────────────────────────────────────────── */
.sp-menu {
  position: fixed;
  z-index: 4200;
  max-height: min(480px, calc(100vh - 80px));
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-ui);
}
.sp-menu[hidden] { display: none; }
.sp-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-light);
  font-size: var(--text-md);
  font-weight: 700;
}
.sp-menu-head a { color: var(--accent-text); font-size: var(--text-sm); font-weight: 600; text-decoration: none; }
.sp-menu-head a:hover { text-decoration: underline; }
.sp-menu-claim {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-light);
  background: var(--accent-light);
}
.sp-menu-claim p { margin: 0; font-size: var(--text-sm); color: var(--ink); }
.sp-menu-claim .tiny-btn { justify-self: start; }
.sp-menu-empty { margin: 0; padding: var(--space-5) var(--space-4); color: var(--ink-soft); font-size: var(--text-sm); }
.sp-menu-list { list-style: none; margin: 0; padding: var(--space-1) 0; }
.sp-menu-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--ink);
  text-decoration: none;
}
.sp-menu-item:hover,
.sp-menu-item:focus-visible { background: var(--surface-soft); outline: none; }
.sp-menu-item:focus-visible { box-shadow: inset 2px 0 0 var(--accent); }
.sp-menu-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; }
.sp-menu-item.is-unread .sp-menu-dot { background: var(--accent); }
.sp-menu-text { display: grid; gap: 2px; min-width: 0; }
.sp-menu-line { font-size: var(--text-sm); color: var(--ink-soft); }
.sp-menu-item.is-unread .sp-menu-line { color: var(--ink); font-weight: 600; }
.sp-menu-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-md);
}
.sp-menu-time { font-size: var(--text-xs); color: var(--ink-soft); white-space: nowrap; margin-top: 2px; }

/* ── Phones ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* The shell's top bar carries help + bell on phones; nothing floats over
     the upload and review actions. Pages without the shell keep the launcher. */
  body:has(#app-sidebar) .sp-launcher { display: none; }
  .appnav-bell { display: none; }
}
@media (max-width: 640px) {
  .sp-launcher { right: var(--space-4); bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); padding: 0 var(--space-3); min-height: 44px; }
  .sp-backdrop { background: rgba(0, 0, 0, 0.45); }
  .sp-open,
  .sp-open body { overflow: hidden; }
  .sp-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 92dvh;
    border-width: 1px 0 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation-name: sp-sheet-in;
  }
  .sp-textarea,
  .sp-input { font-size: var(--text-lg); } /* 16px: stops iOS zooming on focus */
  .sp-send { flex: 1 1 auto; min-height: 48px; }
  .sp-kbd { display: none; }
  .sp-sent-actions > * { flex: 1 1 auto; text-align: center; }
}
@keyframes sp-sheet-in {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .sp-panel { animation: none; }
}
