/* File details modal. Dialog frame, buttons and actions come from base.css. */

/* Fixed frame: collapsing a section scrolls the body, it never resizes the dialog. */
[id="file-modal"] {
  width: min(1480px, calc(100% - 32px));
  height: min(920px, calc(100dvh - 32px));
  max-height: none;
  background: var(--paper);
}
#file-modal-content { height: 100%; background: var(--paper); }

.file-modal { height: 100%; max-height: none; display: grid; grid-template-rows: minmax(0, 1fr) auto; padding: 0; overflow: hidden; background: var(--paper); }
.file-modal-scroll { min-height: 0; padding: 26px 32px 28px; overflow-y: auto; }
.file-modal-close { position: absolute; z-index: 3; top: 14px; right: 14px; background: color-mix(in srgb, var(--paper) 92%, transparent); }
.file-modal-title { display: flex; align-items: center; gap: 10px; max-width: calc(100% - 48px); font-size: 26px; overflow-wrap: anywhere; }
.file-modal .dialog-head { margin-bottom: 20px; }
.file-modal .dialog-actions { z-index: 2; flex-wrap: wrap; margin: 0; padding: 14px 32px; border-top: 1px solid var(--line); background: var(--paper); box-shadow: 0 -8px 22px rgba(34, 31, 25, .045); }

/* ── collapsible sections ── */

.modal-section { border: 1px solid var(--line); background: var(--paper-raised); box-shadow: 0 9px 28px rgba(34, 31, 25, .045); }
.modal-section + .modal-section { margin-top: 10px; }
.modal-section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  transition: color .12s;
}
.modal-section > summary::-webkit-details-marker { display: none; }
.modal-section > summary::before {
  content: "›";
  width: 14px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  transition: transform .14s ease-out;
}
.modal-section[open] > summary::before { transform: rotate(90deg); }
.modal-section > summary:hover { color: var(--blue); }
.section-title { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.section-note { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.section-body { padding: 4px 16px 18px; }
.section-empty { margin: 0; color: var(--muted); font-size: 12px; }

/* ── detail rows ── */

.detail-rows { display: grid; gap: 7px; }
.detail-row { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 16px; align-items: baseline; padding: 3px 0; }
.detail-row > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.detail-row > div { min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
.detail-row select { width: 100%; max-width: 280px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 2px; background: var(--paper); color: inherit; font-size: 12px; }
.sha { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.parse-error { color: var(--red); }

/* ── extracted data ── */

.col-pills { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.col-pill { padding: 5px 11px 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper-raised); color: var(--ink); font-size: 11px; line-height: 1.3; }

/* ── user metadata ── */

.meta-grid { min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 12px; }
.meta-grid .field { min-width: 0; gap: 4px; padding: 9px 11px; border: 1px solid var(--line); background: transparent; }
.meta-grid .field:focus-within { border-color: var(--blue); }
.meta-grid .field > span { font-size: 9px; font-weight: 600; letter-spacing: .09em; }
.meta-grid .field.is-wide { grid-column: 1 / -1; }
.meta-grid .field input, .meta-grid .field textarea, .meta-grid .field select {
  padding: 4px 0 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 12px;
  line-height: 1.35;
}
.meta-grid .field input:focus, .meta-grid .field textarea:focus, .meta-grid .field select:focus { box-shadow: none; }
.meta-grid .field textarea { min-height: 60px; font-family: inherit; }
.field-unit { font-weight: 400; text-transform: none; }
.field-hint { color: var(--muted); font-size: 9px; }
.field-static { padding: 4px 0 2px; font-size: 12px; line-height: 1.35; }

.plot-host { min-height: 340px; }
.plot-host .loading { height: 340px; }


.cell-name.is-link { padding: 0; border: 0; background: transparent; color: var(--ink); cursor: pointer; font: inherit; text-align: left; }
.cell-name.is-link:hover { color: var(--blue); text-decoration: underline; }

.file-modal .bulk-file-table th, .file-modal .bulk-file-table td { border-bottom: 0; }
.file-modal .bulk-file-table th { padding-bottom: 8px; }
.file-modal .bulk-file-table td { padding-top: 7px; padding-bottom: 7px; }

@media (max-width: 700px) {
  .file-modal-title { gap: 7px; font-size: 14px; }
  .file-modal-scroll { padding: 22px 18px 24px; }
  /* Up to five buttons on one line: they keep the row by giving up their
     padding and their minimum, and the labels ellipsis rather than wrap. */
  .file-modal .dialog-actions { flex-wrap: nowrap; gap: 6px; padding: 10px 14px; }
  .file-modal .dialog-actions .button {
    min-width: 0;
    min-height: 34px;
    flex: 0 1 auto;
    overflow: hidden;
    padding-inline: 10px;
    font-size: var(--text-control);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .file-modal .dialog-actions .danger { margin-right: 0; }
  .detail-row { grid-template-columns: 1fr; gap: 3px; }
  .meta-grid { grid-template-columns: 1fr; }
}

/* ── bundles ── */

.readiness { padding: 2px 8px 1px; border-radius: 999px; background: rgba(23, 23, 19, .07); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.readiness.is-ready { background: color-mix(in srgb, var(--green) 16%, var(--paper)); color: var(--green); }
.readiness.is-blocked, .readiness.is-incomplete { background: color-mix(in srgb, var(--red) 14%, var(--paper)); color: var(--red); }
.readiness-missing { color: var(--muted); font-size: 11px; }
.setup-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.member-index { width: 26px; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-order { width: 56px; padding-right: 0; white-space: nowrap; }
.col-order .row-action:disabled { opacity: .25; cursor: not-allowed; }

/* Bundle setup: instrument first, since it decides the roles below it. */
.setup-instrument { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 16px; }
.setup-instrument label { display: inline-flex; align-items: center; gap: 9px; }
.setup-instrument label > span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.setup-instrument select { min-width: 220px; padding: 7px 9px; border: 1px solid #cfc9bd; border-radius: 2px; background: var(--paper-raised); color: var(--ink); font-size: 12px; }
.setup-instrument select:hover { border-color: #aaa499; }
.setup-instrument select:focus { border-color: var(--blue); outline: 0; }
.setup-parse { margin-left: auto; min-height: 32px; }

/* Asset preview: figures, images and scripts. */
.asset-preview-host { min-height: 220px; }
.asset-image-wrap { display: grid; place-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 3px; background: var(--paper); }
.asset-image { max-width: 100%; max-height: 62vh; display: block; }
.asset-image-wrap.is-compact { padding: 0; border: 0; border-radius: 0; height: 100%; width: 100%; }
.asset-image-wrap.is-compact .asset-image { max-height: 170px; object-fit: contain; }
.asset-frame { width: 100%; height: 62vh; border: 1px solid var(--line); border-radius: 3px; background: var(--paper); }
.asset-frame.is-compact { height: 170px; border: 0; }
.asset-text { max-height: 62vh; margin: 0; padding: 14px 16px; overflow: auto; border: 1px solid var(--line); border-radius: 3px; background: var(--paper); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.55; white-space: pre; }
.asset-text.is-compact { max-height: 170px; padding: 8px 10px; border: 0; font-size: 10px; line-height: 1.45; }

/* Turn a phone sideways on a file that plots and the sheet becomes the plot:
   the metadata sections, the head and the action row all step aside, the way
   the organization tab's plot does. Guarded by :has(), so a file with nothing
   to plot is left alone — otherwise landscape would empty the sheet.
   Keyed on height: a phone in landscape is short, whatever its width. */
@media (max-height: 520px) and (orientation: landscape) {
  .file-modal:has(.modal-plot-section) .dialog-head,
  .file-modal:has(.modal-plot-section) .dialog-actions,
  .file-modal:has(.modal-plot-section) .modal-section:not(.modal-plot-section) { display: none; }
  .file-modal:has(.modal-plot-section) .file-modal-scroll { padding: 0; overflow: hidden; }
  .modal-plot-section { height: 100%; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
  .modal-plot-section > summary,
  .modal-plot-section .plot-controls { display: none; }
  /* Inset rather than edge-to-edge: a rounded corner or a notch eats the last
     few millimetres on either side, which on a plot is an axis. The safe-area
     insets are the horizontal ones here — in landscape the notch is beside the
     screen, not above it. */
  .modal-plot-section > .section-body {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 14px calc(20px + env(safe-area-inset-right)) 16px calc(20px + env(safe-area-inset-left));
  }
  .modal-plot-section .plot-host {
    width: 100%;
    max-width: 1000px;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-inline: auto;
  }
  .modal-plot-section .plot-canvas { min-height: 0; flex: 1; }
}
