/* Deputary popup design system — "Quiet Operator"
 * Single source of truth for modals, dropdowns, popovers, toasts, inline panels.
 * Design tokens come from the CSS variables defined in base.html. */

[x-cloak] { display: none !important; }

/* ─── Scrim ──────────────────────────────────────────────────────────────── */

.sp-scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

/* ─── Modal ──────────────────────────────────────────────────────────────── */

.sp-modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.10);
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sp-modal--sm { max-width: 380px; }
.sp-modal--md { max-width: 480px; }
.sp-modal--lg { max-width: 640px; }

.sp-modal__head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sp-modal__head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.sp-modal__head .sp-muted {
  margin: 4px 0 0 0;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.4;
}

.sp-modal__body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1 1 auto;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
}

.sp-modal__foot {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-2, transparent);
}

/* ─── Icon close button ──────────────────────────────────────────────────── */

.sp-icon-btn {
  background: transparent;
  border: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, color 120ms ease;
}
.sp-icon-btn:hover {
  background: var(--line);
  color: var(--ink);
}

/* ─── Dropdown ───────────────────────────────────────────────────────────── */

.sp-dropdown {
  position: relative;
  display: inline-block;
}

.sp-dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  min-width: 180px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.10);
  padding: 6px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sp-dropdown__menu--right { right: 0; }
.sp-dropdown__menu--left { left: 0; }

.sp-dropdown__menu .sp-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.sp-dropdown__menu .sp-menu-item:hover {
  background: var(--line);
}
.sp-dropdown__menu .sp-menu-item.danger {
  color: var(--crit);
}
.sp-dropdown__menu .sp-menu-item.danger:hover {
  background: var(--crit-bg, rgba(220, 38, 38, 0.08));
}
.sp-dropdown__menu .sp-menu-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 2px;
}

/* ─── Popover (anchored, like notification bell) ─────────────────────────── */

.sp-popover {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.10);
  z-index: 100;
  display: flex;
  flex-direction: column;
  max-height: 520px;
  overflow: hidden;
}

.sp-popover__head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.sp-popover__body {
  padding: 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  font-size: 13px;
  color: var(--ink);
}

.sp-popover__foot {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */

.sp-toast-wrap {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.sp-toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.10);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.sp-toast--ok    { border-left-color: var(--ok, #22c55e); }
.sp-toast--warn  { border-left-color: var(--warn, #f59e0b); }
.sp-toast--error { border-left-color: var(--crit, #dc2626); }

.sp-toast__close {
  margin-left: auto;
  background: transparent;
  border: 0;
  font-size: 16px;
  color: var(--ink-3);
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
.sp-toast__close:hover { color: var(--ink); }

/* ─── Inline panel (collapse/expand region) ──────────────────────────────── */

.sp-inline-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.sp-inline-panel__trigger {
  width: 100%;
  background: transparent;
  border: 0;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: inherit;
}
.sp-inline-panel__trigger:hover { background: var(--line); }

.sp-inline-panel__body {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink);
}

.sp-inline-panel__chev {
  transition: transform 160ms ease;
  color: var(--ink-3);
  font-size: 11px;
}
.sp-inline-panel--open .sp-inline-panel__chev {
  transform: rotate(180deg);
}

/* ─── Drawer (right-side slide-in) ───────────────────────────────────────── */

.sp-drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, 0.35);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
  z-index: 900;
}

.sp-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -1px 0 3px rgba(0, 0, 0, 0.04), -12px 0 32px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 901;
  max-width: calc(100vw - 32px);
  transition: transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1),
              opacity 200ms ease;
}

/* Slide-in / slide-out states (used by Alpine x-transition keyframes). */
.sp-drawer--off { transform: translateX(100%); opacity: 0; }
.sp-drawer--on  { transform: translateX(0);    opacity: 1; }

.sp-drawer__head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: none;
}

.sp-drawer__head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.sp-drawer__head .sp-muted {
  margin: 4px 0 0 0;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.4;
}

.sp-drawer__body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1 1 auto;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
}

.sp-drawer__foot {
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-2, transparent);
  flex: none;
}

@media (prefers-reduced-motion: reduce) {
  .sp-drawer { transition: none; }
}

/* ─── Animations ─────────────────────────────────────────────────────────── */

.sp-anim-in {
  animation: sp-pop-in 160ms ease-out;
}

.sp-anim-out {
  animation: sp-pop-out 100ms ease-in forwards;
}

@keyframes sp-pop-in {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes sp-pop-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.97); }
}

.sp-toast {
  animation: sp-toast-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes sp-toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Focus ring ─────────────────────────────────────────────────────────── */

.sp-modal :focus-visible,
.sp-dropdown :focus-visible,
.sp-popover :focus-visible,
.sp-inline-panel :focus-visible,
.sp-toast :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── Reduced-motion respect ─────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .sp-anim-in, .sp-anim-out, .sp-toast {
    animation: none;
  }
}
