/* ── Custom <dialog> modals ───────────────────────────────
   Replaces native alert/confirm/prompt and is also used for
   the scope-assignment editor on the admin dashboard. */

dialog.app-dialog {
  /* Force viewport centering. The :modal UA default uses `inset: 0; margin: auto`
     but it can drift to the top once we override padding / sizing, so set it
     explicitly here. */
  position: fixed;
  inset: 0;
  margin: auto;

  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 0;
  width: calc(100% - 2rem);
  max-width: 480px;
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .8);
  font-family: var(--sans);
}
dialog.app-dialog > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: inherit;
}
dialog.app-dialog .app-dialog__body {
  overflow-y: auto;
}
dialog.app-dialog[open] {
  animation: dialog-pop .15s ease-out;
}
dialog.app-dialog::backdrop {
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(2px);
}

@keyframes dialog-pop {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

.app-dialog__header {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .98rem;
}
.app-dialog__header .icon { color: var(--accent); }
.app-dialog__header--danger .icon { color: var(--red); }
.app-dialog__header--warning .icon { color: var(--yellow); }

.app-dialog__body {
  padding: 1.1rem 1.25rem;
  font-size: .9rem;
  color: var(--text-muted);
}
.app-dialog__body p + .input,
.app-dialog__body p + textarea {
  margin-top: .8rem;
}
.app-dialog__body .scope-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .55rem;
  margin-top: .25rem;
}
.app-dialog__body .scope-row {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .55rem .7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .12s;
}
.app-dialog__body .scope-row:hover { border-color: var(--border-hover); }
.app-dialog__body .scope-row input[type=checkbox] {
  margin-top: .25rem;
  accent-color: var(--accent);
}
.app-dialog__body .scope-row .scope-name {
  font-family: var(--mono);
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
}
.app-dialog__body .scope-row .scope-desc {
  font-size: .78rem;
  color: var(--text-dim);
  display: block;
  margin-top: .15rem;
}

.app-dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 12px 12px;
}

/* ── Toast container ──────────────────────────────────── */
#app-toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  z-index: 9999;
  pointer-events: none;
}

.app-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 240px;
  max-width: 360px;
  padding: .65rem .85rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .85rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, .5);
  animation: toast-in .18s ease-out;
}
.app-toast.is-leaving { animation: toast-out .18s ease-in forwards; }

.app-toast--success { border-color: #166534; }
.app-toast--success .icon { color: var(--green); }
.app-toast--error   { border-color: #7f1d1d; }
.app-toast--error   .icon { color: var(--red); }
.app-toast--info    .icon { color: var(--accent); }

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