/*
 * components/dialogs.css — Modal dialog + slideover components (Session 4).
 *
 * Paired with the `dialog()`/`slideover()` macros in
 * templates/components/dialogs.html and the open/close/focus-trap
 * behavior in static/js/components/dialogs.js. Both use the native
 * `<dialog>` element (no vendored library needed, D2/E2) with a small JS
 * shim for the trigger/backdrop-click/ESC wiring `<dialog>` doesn't give
 * for free in every browser.
 */

.dialog {
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 0;
  max-width: 30rem;
  width: calc(100% - var(--space-6));
  background: var(--color-surface);
  color: var(--color-fg);
}

.dialog::backdrop {
  background: rgba(31, 35, 41, 0.5);
}

.dialog[open] {
  animation: dialog-in var(--dur-base) var(--ease-standard);
}

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

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border-1);
}

.dialog__head h2,
.dialog__head h3 {
  margin: 0;
  font-size: var(--fs-lg);
}

.dialog__close {
  appearance: none;
  border: none;
  background: transparent;
  font-size: var(--fs-lg);
  line-height: 1;
  color: var(--color-fg-muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
}

.dialog__close:hover {
  background: var(--color-surface-2);
}

.dialog__close:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.dialog__body {
  padding: var(--space-5);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: var(--border-1);
}

/* Full-surface dialog: 90vw x 90vh with a fixed head and a scrolling body.
   Used by the application quick-view pop-up (the merged application
   surface). The head stays put while the body scrolls; nested pop-ups
   opened from inside still stack above it on the top layer. */
.dialog--full {
  display: flex;
  flex-direction: column;
  width: 90vw;
  max-width: 90vw;
  height: 90vh;
  max-height: 90vh;
}

/* A closed <dialog> is display:none by UA default, but .dialog--full sets
   display:flex which overrides that — making the dialog visible at the
   bottom of the page even when not open. Guard it explicitly. */
.dialog--full:not([open]) {
  display: none;
}

.dialog--full .dialog__head {
  flex: 0 0 auto;
}

.dialog__body--scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

/* Logs pop-up: 90% of the parent quick-view panel (which is 90vw × 90vh),
   so 81vw × 81vh. Fixed head, scrolling body. Nested above the parent
   dialog via showModal() — Escape closes only this pop-up (native
   top-layer semantics). */
.dialog--logs {
  display: flex;
  flex-direction: column;
  width: 81vw;
  max-width: 81vw;
  height: 81vh;
  max-height: 81vh;
}

.dialog--logs:not([open]) {
  display: none;
}

.dialog--logs .dialog__head {
  flex: 0 0 auto;
}

/* Make the dialog body a flex column so the log viewer can fill it
   entirely. The body's padding provides equal spacing on all sides. */
.dialog--logs .dialog__body {
  display: flex;
  flex-direction: column;
}

/* Log viewer fills the body: lift the default max-width and max-height
   caps so it expands to the full available area. */
.dialog--logs .log-viewer {
  max-width: none;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dialog--logs .log-viewer__summary,
.dialog--logs .log-viewer__toolbar {
  flex: 0 0 auto;
}

.dialog--logs .log-viewer__output {
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
}

/* Profile pop-up: 80vw with a fixed head and a scrolling body.
   Escape and the X button close it (native <dialog> + dialogs.js). */
.dialog--profile {
  display: flex;
  flex-direction: column;
  width: 80vw;
  max-width: 80vw;
  height: 80vh;
  max-height: 80vh;
}

.dialog--profile:not([open]) {
  display: none;
}

.dialog--profile .dialog__head {
  flex: 0 0 auto;
}

.dialog--profile .dialog__body {
  display: flex;
  flex-direction: column;
}

/* Slideover: a `<dialog>` pinned to the right edge, full viewport height. */

.slideover {
  border: none;
  border-radius: 0;
  box-shadow: var(--shadow-pop);
  padding: 0;
  margin: 0 0 0 auto;
  height: 100vh;
  max-height: 100vh;
  width: min(28rem, 100vw);
  max-width: 100vw;
  background: var(--color-surface);
  color: var(--color-fg);
  display: flex;
  flex-direction: column;
}

.slideover:not([open]) {
  display: none;
}

.slideover::backdrop {
  background: rgba(31, 35, 41, 0.5);
}

.slideover[open] {
  animation: slideover-in var(--dur-slow) var(--ease-standard);
}

@keyframes slideover-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.slideover .dialog__head {
  flex: none;
}

.slideover .dialog__body {
  flex: 1;
  overflow-y: auto;
}

.slideover .dialog__actions {
  flex: none;
}

@media (max-width: 640px) {
  .slideover {
    width: 100vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slideover[open] {
    animation: none;
  }
  .dialog[open] {
    animation: none;
  }
}
