/* SOS core — componentes compartilhados por todos os layouts (toast, modal de confirmação,
   loading, foco visível, skip link, movimento reduzido). Usa os tokens do layout quando existem. */

:root {
  --sos-primary: var(--primary, #6c5ce7);
  --sos-danger: var(--red, #e03131);
  --sos-success: var(--green, #12b886);
  --sos-warn: var(--accent-2, #f59f00);
  --sos-surface: var(--surface, #fff);
  --sos-text: var(--text, #1f2440);
  --sos-muted: var(--text-soft, var(--muted, #6b7192));
  --sos-border: var(--border, #e6e8f0);
  --sos-radius: var(--radius-sm, 12px);
  --sos-shadow: var(--shadow-lg, 0 18px 44px rgba(20, 24, 48, .18));
  --sos-focus: color-mix(in srgb, var(--sos-primary) 70%, white);
}

/* ---- Foco visível (só teclado) ------------------------------------------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--sos-focus);
  outline-offset: 2px;
  border-radius: 6px;
}
:where(a, button, input, select, textarea, summary, [tabindex]):focus:not(:focus-visible) {
  outline: none;
}

/* ---- Skip link ----------------------------------------------------------- */
.sos-skip {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 10000;
  padding: 10px 16px;
  background: var(--sos-primary);
  color: #fff;
  border-radius: 10px;
  font: 600 14px/1 'Inter', system-ui, sans-serif;
  text-decoration: none;
  transition: top .15s ease;
}
.sos-skip:focus { top: 12px; }

/* ---- Toasts ---------------------------------------------------------------- */
.sos-toasts {
  position: fixed;
  left: 50%;
  bottom: max(var(--sos-toast-bottom, 18px), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9990;
  width: min(92vw, 460px);
  pointer-events: none;
}
.sos-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--sos-radius);
  background: #1f2440;
  color: #fff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
  font: 500 14px/1.4 'Inter', system-ui, sans-serif;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease;
  border-left: 4px solid var(--sos-primary);
}
.sos-toast.is-in { opacity: 1; transform: none; }
.sos-toast.is-success { border-left-color: var(--sos-success); }
.sos-toast.is-error { border-left-color: var(--sos-danger); }
.sos-toast.is-warn { border-left-color: var(--sos-warn); }
.sos-toast-text { flex: 1; word-break: break-word; }
.sos-toast-x {
  flex: none;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  opacity: .7;
  padding: 0 2px;
}
.sos-toast-x:hover { opacity: 1; }

/* ---- Modal de confirmação ---------------------------------------------------- */
.sos-modal {
  position: fixed;
  inset: 0;
  z-index: 9980;
  display: grid;
  place-items: center;
  padding: 16px;
}
.sos-modal[hidden] { display: none; }
.sos-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 22, 58, .45);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .18s ease;
}
.sos-modal-box {
  position: relative;
  width: min(100%, 420px);
  background: var(--sos-surface);
  color: var(--sos-text);
  border-radius: 18px;
  padding: 22px 22px 18px;
  box-shadow: var(--sos-shadow);
  font-family: 'Inter', system-ui, sans-serif;
  opacity: 0;
  transform: translateY(10px) scale(.98);
  transition: opacity .18s ease, transform .18s ease;
}
.sos-modal.is-open .sos-modal-backdrop { opacity: 1; }
.sos-modal.is-open .sos-modal-box { opacity: 1; transform: none; }
.sos-modal-title { font-size: 1.0625rem; font-weight: 700; margin: 0 0 8px; }
.sos-modal-text { font-size: .90625rem; line-height: 1.5; color: var(--sos-muted); margin: 0 0 18px; white-space: pre-line; }
.sos-modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
html.sos-modal-open { overflow: hidden; }

.sos-btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 18px;
  font: 600 14px/1 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: filter .12s ease, transform .08s ease;
}
.sos-btn:active { transform: translateY(1px); }
.sos-btn-primary { background: var(--sos-primary); color: #fff; }
.sos-btn-danger { background: var(--sos-danger); color: #fff; }
.sos-btn-ghost { background: transparent; color: var(--sos-text); border-color: var(--sos-border); }
.sos-btn:hover { filter: brightness(.95); }

/* ---- Loading -------------------------------------------------------------- */
[aria-busy="true"] { cursor: progress; }
button[aria-busy="true"], .is-busy > button[type="submit"] {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
button[aria-busy="true"]::after, .is-busy > button[type="submit"]::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  animation: sos-spin .7s linear infinite;
}
.sos-skeleton {
  display: inline-block;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .06) 25%, rgba(0, 0, 0, .12) 37%, rgba(0, 0, 0, .06) 63%);
  background-size: 400% 100%;
  animation: sos-shimmer 1.4s ease infinite;
  min-height: 1em;
}
@keyframes sos-spin { to { transform: rotate(360deg); } }
@keyframes sos-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---- Movimento reduzido ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
