/* Toasts, dialogs, drawers, command palette, popovers, tabs.
   Everything here escapes its stacking context via fixed positioning or
   <dialog>, so nothing gets clipped by a scrolling panel. */

/* ---- Toasts ----------------------------------------------------------- */
.toast-stack {
  position: fixed;
  bottom: var(--s-5);
  right: var(--s-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--s-2);
  width: min(384px, calc(100vw - var(--s-8)));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  border-radius: var(--r-lg);
  border: 1px solid var(--hairline);
  background: var(--chrome);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  cursor: pointer;
  touch-action: pan-y;
  animation: toast-in var(--d-slow) var(--ease);
  transition: transform var(--d-base) var(--ease), opacity var(--d-base) var(--ease);
}
.toast:hover { box-shadow: var(--shadow-4); }
.toast[data-out="true"] { opacity: 0; transform: translateX(24px) scale(0.97); }
.toast-icon { flex: none; margin-top: 1px; color: var(--ink-3); }
.toast-ok .toast-icon { color: var(--ok-ink); }
.toast-bad .toast-icon { color: var(--bad-ink); }
.toast-warn .toast-icon { color: var(--warn-ink); }
.toast-body { min-width: 0; flex: 1 1 auto; }
.toast-title { font-size: var(--t-13); font-weight: var(--w-semibold); }
.toast-msg { font-size: var(--t-12); color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }
.toast-close { flex: none; color: var(--ink-4); padding: 2px; border-radius: var(--r-sm); }
.toast-close:hover { color: var(--ink); background: var(--surface-hover); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(18px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .toast { animation: fade-in var(--d-fast) linear; } }

@media (max-width: 560px) {
  .toast-stack { left: var(--s-3); right: var(--s-3); bottom: var(--s-3); width: auto; }
}

/* ---- Dialog ----------------------------------------------------------- */
dialog.modal {
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--r-2xl);
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow-4);
  width: min(560px, calc(100vw - var(--s-8)));
  max-height: min(84dvh, 780px);
  overflow: visible;
}
dialog.modal-wide { width: min(860px, calc(100vw - var(--s-8))); }
/* The preview stands in for a real desktop mail client, so it gets the screen. */
dialog.modal-preview { width: min(1280px, calc(100vw - var(--s-8))); }
dialog.modal::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(3px);
  animation: fade-in var(--d-base) var(--ease);
}
dialog.modal[open] { animation: modal-in var(--d-slow) var(--ease); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-5) var(--s-3);
}
.modal-head h2 { font-size: var(--t-17); letter-spacing: -0.015em; }
.modal-head p { font-size: var(--t-13); color: var(--ink-3); margin-top: 2px; }
.modal-body { padding: 0 var(--s-5) var(--s-5); overflow-y: auto; max-height: 62dvh; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--hairline);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-2xl) var(--r-2xl);
}

/* ---- Drawer ----------------------------------------------------------- */
dialog.drawer {
  margin: 0 0 0 auto;
  height: 100dvh;
  max-height: none;
  width: min(680px, 100vw);
  border-radius: 0;
  border-width: 0 0 0 1px;
  display: flex;
  flex-direction: column;
}
dialog.drawer[open] { animation: drawer-in var(--d-slow) var(--ease); }
@keyframes drawer-in {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
dialog.drawer .modal-body { flex: 1 1 auto; max-height: none; }
dialog.drawer .modal-foot { border-radius: 0; }
@media (prefers-reduced-motion: reduce) {
  dialog.modal[open], dialog.drawer[open] { animation: fade-in var(--d-fast) linear; }
}

/* ---- Command palette --------------------------------------------------- */
dialog.palette {
  width: min(600px, calc(100vw - var(--s-6)));
  margin-top: 12vh;
  border-radius: var(--r-2xl);
  background: var(--chrome);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  overflow: hidden;
}
.palette-input {
  width: 100%;
  border: 0;
  background: none;
  padding: var(--s-4) var(--s-5);
  font-size: var(--t-15);
  border-bottom: 1px solid var(--hairline);
}
.palette-input:focus { outline: none; }
.palette-list { max-height: 46dvh; overflow-y: auto; padding: var(--s-2); }
.palette-group {
  padding: var(--s-3) var(--s-3) var(--s-1);
  font-size: var(--t-11);
  font-weight: var(--w-semibold);
  color: var(--ink-3);
}
.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--t-13);
  color: var(--ink);
  text-align: left;
}
.palette-item svg { color: var(--ink-4); }
.palette-item[aria-selected="true"] { background: var(--accent); color: var(--ink-invert); }
.palette-item[aria-selected="true"] svg,
.palette-item[aria-selected="true"] .palette-hint { color: var(--ink-invert); opacity: 0.8; }
.palette-hint { margin-left: auto; font-size: var(--t-11); color: var(--ink-3); }
.palette-foot {
  display: flex;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--hairline);
  font-size: var(--t-11);
  color: var(--ink-3);
}
.palette-foot .row { gap: 5px; }

/* ---- Popover ----------------------------------------------------------- */
.popover {
  position: fixed;
  z-index: var(--z-dropdown);
  min-width: 200px;
  max-height: 320px;
  overflow-y: auto;
  padding: var(--s-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-3);
  animation: rise var(--d-fast) var(--ease);
}
.popover-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: 6px var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--t-13);
  text-align: left;
  color: var(--ink);
}
.popover-item:hover, .popover-item:focus-visible { background: var(--surface-hover); outline: none; }
.popover-item .mono { color: var(--accent-ink); }
.popover-sep { height: 1px; background: var(--hairline); margin: var(--s-2) 0; }

/* ---- Tabs -------------------------------------------------------------- */
.tabs { display: flex; gap: var(--s-4); border-bottom: 1px solid var(--hairline); }
.tab {
  position: relative;
  padding: var(--s-2) 0 var(--s-3);
  font-size: var(--t-13);
  font-weight: var(--w-medium);
  color: var(--ink-3);
  transition: color var(--d-fast) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); font-weight: var(--w-semibold); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  animation: fade-in var(--d-base) var(--ease);
}
