/* --- Dialogs (js/components/dialog.js) ------------------------------------------------------ */

/* Elevation 3: --surface, a light edge, a deep shadow over --scrim. Only the OPEN dialog
   gets a layout: a display on .dialog itself would override the UA's
   "dialog:not([open]) { display: none }" and show it shut.

   <dialog class="dialog [dialog-wide]">
     <form|div class="dialog-frame">
       <div class="dialog-head"> .dialog-titles (h2.dialog-title, p.dialog-subtitle) + close
       <div class="dialog-body"> fields, notices: scrolls when tall
       <div class="dialog-foot"> Cancel, then the action                                  */
.dialog {
  width: min(32rem, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100dvh - 2rem);
  padding: 0;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius-xl);
  box-shadow: var(--elev-3);
}
.dialog-wide { width: min(44rem, calc(100vw - 2rem)); }
.dialog[open] {
  display: flex;
  flex-direction: column;
  transition: opacity var(--motion-slow) var(--ease), transform var(--motion-slow) var(--ease);
}
/* Entering: fade and rise 8px. A browser without @starting-style simply shows it; the
   reduced-motion block in app.css removes the transition. */
@starting-style {
  .dialog[open] { opacity: 0; transform: translateY(8px); }
}
/* ::backdrop does not inherit custom properties in every browser still in use, hence
   the fallback (the same value as --scrim). */
.dialog::backdrop { background: var(--scrim, rgba(0, 0, 0, .6)); }

.dialog-frame {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.dialog-titles { flex: 1; min-width: 0; }
/* A fixed string at card-title size: the chrome face at normal width, not the h2's
   display face (wide, tight tracking), which reads as a squeezed headline this small. */
.dialog-title {
  margin: 0;
  font-family: var(--font-chrome);
  font-stretch: 100%;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.3;
}
.dialog-subtitle { margin: var(--space-1) 0 0; color: var(--fg-muted); font-size: var(--text-sm); }
/* The close button sits in the corner without making the head taller. */
.dialog-close { flex: none; margin: -.625rem -.625rem -.625rem 0; }

/* Fields stack with the form gap. When the body is taller than the dialog it scrolls,
   and a hairline shows along its bottom edge, above the foot, until the end is reached:
   the line is fixed to the box (scroll), a --surface cover rides on the content's end
   (local) and hides it whenever the end is in view, which is always when nothing
   scrolls. */
.dialog-body {
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  gap: var(--space-4);
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--space-5);
  background:
    linear-gradient(var(--surface), var(--surface)) center bottom / 100% 2px no-repeat local,
    linear-gradient(var(--hairline), var(--hairline)) center bottom / 100% 1px no-repeat scroll;
}
.dialog-body > * { margin-top: 0; margin-bottom: 0; }
.dialog-body:last-child { padding-bottom: var(--space-5); }

.dialog-foot {
  display: flex;
  flex: none;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5) var(--space-5);
}
/* Cancel matches the brass pill's height beside it. */
.dialog-foot .btn { min-height: var(--target); }

/* Narrow screens: a bottom sheet, the action above Cancel, both full width. */
@media (max-width: 40rem) {
  /* Above the on-screen keyboard: dialog.js sets --keyboard (what the keyboard covers
     under the visual viewport) and --viewport-h (the visual viewport's height) while a
     dialog is open; without them this is the plain 92dvh sheet. */
  .dialog,
  .dialog-wide {
    width: 100%;
    max-height: min(92dvh, calc(var(--viewport-h, 100dvh) * .92));
    margin: auto 0 var(--keyboard, 0px);
    padding-bottom: var(--safe-b);
    border-width: 1px 0 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
  .dialog-head { padding: var(--space-4) var(--space-4) var(--space-3); }
  .dialog-body { padding: 0 var(--space-4); }
  .dialog-body:last-child { padding-bottom: var(--space-4); }
  .dialog-foot { flex-direction: column-reverse; padding: var(--space-4); }
  .dialog-foot .btn { width: 100%; }
  /* With the keyboard up (dialog.js .dialog-keyboard) the form has little room: the
     foot's buttons share one row, Cancel then the action. */
  .dialog-keyboard .dialog-foot { flex-direction: row; padding-block: var(--space-3); }
  .dialog-keyboard .dialog-foot .btn { flex: 1 1 0; width: auto; }
}

/* An action sheet (dialog.js actionSheet): a list of actions for one thing, each a
   full-width row at the touch height; narrow where it is a centred dialog, the full
   width where it is a bottom sheet. */
@media (min-width: 40.0625rem) {
  .action-sheet { width: min(22rem, calc(100vw - 2rem)); }
}
.action-sheet-list { display: grid; gap: var(--space-1); margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.action-sheet-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: var(--target);
  padding: 0 var(--space-3);
  background: none;
  color: var(--fg);
  border: 0;
  border-radius: var(--radius-md);
  font: 500 var(--text-base)/1.3 var(--font-chrome);
  text-align: left;
  transition: background-color var(--motion-fast) var(--ease);
}
.action-sheet-item:hover { background: rgba(255, 255, 255, .08); }
