/* ============================================================
   BUREAU OF LOST TIMELINES — ADVISORY DIALOGS  (css/ui.css)
   Consumes js/ui.js and the tokens in css/tokens.css.

   The sheet is a stamped notice: the record-row spine on the left, a
   dashed header strip carrying the stamp eyebrow and a REF number, paper
   type over ink, and the action buttons in the footer. Red is the only
   colour an alert is allowed to use — it is the colour of authority here,
   so a refusal, a warning and a destructive action all arrive in it, and
   phosphor is kept for the one tone that is a machine talking ('ok').
   ============================================================ */

/* The dialog layer outranks every surface sheet in the archive. The highest
   existing surface is the avatar modal (z-index 10000), and a notice raised
   from inside it must be readable, so the layer sits above the whole stack. */
.ui-layer {
  position: fixed;
  inset: 0;
  z-index: 20000;
  pointer-events: none;
}

html.ui-locked {
  overflow: hidden;
}

/* ---------- overlay ---------- */
.ui-sheet-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: var(--s-3);
  padding: var(--gutter);
  background: rgba(5, 6, 8, 0.76);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: auto;
  animation: ui-veil var(--dur-2) var(--ease-out);
  overflow: auto;
}

@keyframes ui-veil {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- the sheet ---------- */
.ui-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - (var(--gutter) * 2));
  display: flex;
  flex-direction: column;
  background: var(--ink-1);
  background-image: var(--fibre);
  border: 1px solid var(--line-strong);
  border-left: var(--spine) solid var(--tone, var(--alert));
  box-shadow: var(--shadow-2);
  animation: ui-sheet-in var(--dur-3) var(--ease-out);
}

/* A rejection reason, a file body or a long error can outgrow the sheet;
   the header and footer stay put and the body scrolls between them. */
.ui-sheet-main {
  overflow: auto;
  overscroll-behavior: contain;
}

.ui-sheet-wrap.is-closing .ui-sheet {
  animation: ui-sheet-out var(--dur-1) ease-in forwards;
}

/* The sheet stays in the DOM for the length of its fade so it can animate out.
   It must not take clicks or focus while it does — a double-click on CANCEL
   would otherwise land on a dead sheet. */
.ui-sheet-wrap.is-closing {
  pointer-events: none;
  visibility: hidden;
}

@keyframes ui-sheet-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}
@keyframes ui-sheet-out {
  to { opacity: 0; transform: translateY(6px) scale(0.99); }
}

/* header strip: stamp, eyebrow, reference */
.ui-sheet-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 9px var(--s-3);
  background: var(--tone-wash, var(--alert-wash));
  border-bottom: 1px dashed var(--line-strong);
}

.ui-seal {
  flex: none;
  width: 10px;
  height: 10px;
  background: var(--tone, var(--alert));
  box-shadow: 0 0 10px var(--tone-glow, var(--alert-glow));
  transform: rotate(45deg);
}

.ui-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--tone-text, var(--alert-bright));
}

.ui-ref {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-mono);
  color: var(--muted);
}

/* body */
.ui-sheet-main {
  padding: var(--s-4) var(--s-4) var(--s-3);
}

.ui-sheet-title {
  margin: 0 0 var(--s-2);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(21px, 3.4vw, 28px);
  line-height: var(--lh-tight);
  letter-spacing: var(--tr-flat);
  text-transform: uppercase;
  color: var(--paper-bright);
}

.ui-sheet-message {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  white-space: pre-line;
  color: var(--paper);
  overflow-wrap: anywhere;
}

/* The Burmese restatement keeps the same left spine the record modals use,
   so a two-language notice reads as one document. */
.ui-sheet-my {
  margin: var(--s-3) 0 0;
  padding-left: var(--s-2);
  border-left: var(--spine) solid var(--line-strong);
  font-family: var(--font-my);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-line;
  color: var(--paper-dim);
}

.ui-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* one field (prompt) or a stack of them (form) */
.ui-fields {
  margin-top: var(--s-3);
}

.ui-field {
  display: block;
  margin-top: var(--s-3);
}

.ui-fields > .ui-field:first-child {
  margin-top: 0;
}

.ui-field-label {
  display: block;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--muted-strong);
}

.ui-input {
  width: 100%;
  padding: 10px var(--s-2);
  background: var(--ink-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  color: var(--paper-bright);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: var(--tr-mono);
}

.ui-input::placeholder {
  color: var(--muted);
}

.ui-input:focus-visible {
  outline: none;
  border-color: var(--tone, var(--alert));
  box-shadow: 0 0 0 1px var(--tone-glow, var(--alert-glow));
}

/* A record body is prose, not a code line: set it in the reading face, keep its
   line breaks, and let the editor grow the box instead of clipping the copy. */
.ui-textarea {
  min-height: 96px;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  letter-spacing: normal;
  resize: vertical;
}

.ui-field-hint {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-mono);
  color: var(--muted);
}

/* footer */
.ui-sheet-foot {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  background: rgba(0, 0, 0, 0.28);
  border-top: 1px solid var(--line);
}

.ui-kbd {
  margin-right: auto;
  padding: 1px 6px;
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--muted);
}

.ui-btn {
  padding: 9px 18px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--paper-dim);
  transition: background var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease);
}

.ui-btn-ghost:hover,
.ui-btn-ghost:focus-visible {
  border-color: var(--paper-dim);
  color: var(--paper-bright);
}

.ui-btn-primary {
  background: var(--ink-3);
  color: var(--paper-bright);
}

.ui-btn-primary:hover,
.ui-btn-primary:focus-visible {
  background: var(--ink-4);
  border-color: var(--paper-dim);
}

/* the action that closes the notice — stamp red */
.ui-btn-solid {
  background: var(--alert);
  border-color: var(--alert);
  color: #0b0c0e;
  font-weight: 500;
}

.ui-btn-solid:hover,
.ui-btn-solid:focus-visible {
  background: var(--alert-bright);
  border-color: var(--alert-bright);
  box-shadow: 0 0 18px var(--alert-glow);
}

.ui-btn:focus-visible {
  outline: 2px solid var(--tone-text, var(--alert-bright));
  outline-offset: 2px;
}

/* ---------- tones ---------- */
.ui-sheet[data-tone="alert"],
.ui-sheet[data-tone="danger"] {
  --tone: var(--alert);
  --tone-wash: var(--alert-wash);
  --tone-glow: var(--alert-glow);
  --tone-text: var(--alert-bright);
}

.ui-sheet[data-tone="notice"] {
  --tone: var(--muted-strong);
  --tone-wash: rgba(154, 161, 169, 0.10);
  --tone-glow: rgba(154, 161, 169, 0.25);
  --tone-text: var(--paper-dim);
}

.ui-sheet[data-tone="ok"] {
  --tone: var(--phosphor);
  --tone-wash: var(--phosphor-wash);
  --tone-glow: rgba(51, 255, 102, 0.22);
  --tone-text: var(--phosphor-bright);
}

.ui-sheet[data-tone="warn"] {
  --tone: var(--folklore);
  --tone-wash: var(--folklore-wash);
  --tone-glow: rgba(232, 163, 61, 0.24);
  --tone-text: var(--folklore);
}

/* A destructive confirmation gets the hatched strip — the diagonal of a
   cover sheet marked for destruction. Static, so it costs no attention
   once read. */
.ui-sheet[data-tone="danger"] .ui-sheet-head {
  background:
    repeating-linear-gradient(135deg,
      var(--alert-wash-2) 0 6px,
      transparent 6px 12px),
    var(--alert-wash);
}

/* ---------- toasts ---------- */
.ui-toasts {
  position: fixed;
  right: var(--gutter);
  bottom: var(--gutter);
  z-index: 20100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s-2);
  pointer-events: none;
  max-width: min(380px, calc(100vw - (var(--gutter) * 2)));
}

.ui-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  width: 100%;
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-3);
  background: var(--ink-1);
  border: 1px solid var(--line-strong);
  border-left: var(--spine) solid var(--tone, var(--phosphor));
  box-shadow: var(--shadow-1);
  pointer-events: auto;
  animation: ui-toast-in var(--dur-2) var(--ease-out);
}

.ui-toast.is-out {
  animation: ui-toast-out var(--dur-2) ease-in forwards;
}

@keyframes ui-toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes ui-toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

.ui-toast-seal {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: 6px;
  background: var(--tone, var(--phosphor));
  transform: rotate(45deg);
}

.ui-toast-body {
  min-width: 0;
}

.ui-toast-label {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  color: var(--tone-text, var(--phosphor-bright));
}

.ui-toast-text {
  margin-top: 2px;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  color: var(--paper);
  overflow-wrap: anywhere;
}

.ui-toast-my {
  margin-top: 3px;
  font-family: var(--font-my);
  font-size: 12px;
  line-height: 1.6;
  color: var(--paper-dim);
}

.ui-toast-x {
  margin-left: auto;
  flex: none;
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: var(--tr-label);
  text-transform: uppercase;
  cursor: pointer;
}

.ui-toast-x:hover,
.ui-toast-x:focus-visible {
  border-color: var(--line-strong);
  color: var(--paper-bright);
}

.ui-toast[data-tone="ok"]       { --tone: var(--phosphor);  --tone-text: var(--phosphor-bright); }
.ui-toast[data-tone="alert"],
.ui-toast[data-tone="danger"]   { --tone: var(--alert);     --tone-text: var(--alert-bright); }
.ui-toast[data-tone="warn"]     { --tone: var(--folklore);  --tone-text: var(--folklore); }
.ui-toast[data-tone="notice"]   { --tone: var(--muted-strong); --tone-text: var(--paper-dim); }

/* ---------- small screens ---------- */
@media (max-width: 480px) {
  .ui-sheet-wrap {
    place-items: end center;
  }
  .ui-sheet-main {
    padding: var(--s-3) var(--s-3) var(--s-2);
  }
  .ui-sheet-foot {
    flex-wrap: wrap;
    padding: var(--s-2) var(--s-3) var(--s-3);
  }
  .ui-kbd {
    display: none;
  }
  .ui-btn {
    flex: 1 1 auto;
    text-align: center;
  }
  .ui-toasts {
    left: var(--gutter);
    right: var(--gutter);
    align-items: stretch;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ui-sheet-wrap,
  .ui-sheet,
  .ui-sheet-wrap.is-closing .ui-sheet,
  .ui-toast,
  .ui-toast.is-out {
    animation: none;
  }
  .ui-btn,
  .ui-input {
    transition: none;
  }
}
