/* Dialogs / bottom sheets and the programming screen. */
dialog.dlg {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
  box-shadow: 0 12px 32px var(--shadow);
}
dialog.dlg[open] { display: flex; flex-direction: column; }
dialog.dlg::backdrop { background: var(--scrim); }
dialog.picker { width: min(760px, calc(100vw - 32px)); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-1); padding: var(--sp-1) var(--gutter) var(--sp-1) var(--sp-2); border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: var(--fs-display); line-height: var(--lh-display); letter-spacing: -0.01em; }
.dlg-body { overflow-y: auto; padding: var(--sp-2); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); min-width: 0; }
@media (max-width: 767px) {
  dialog.dlg, dialog.picker { width: 100%; max-width: 100%; max-height: 85vh; margin: auto 0 0; border-radius: 16px 16px 0 0; border-bottom: 0; }
}

.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-1); }
.list-item { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-1); min-width: 0; padding: 12px var(--sp-2); border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface-2); }
.list-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.list-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.list-sub { color: var(--muted); font-size: var(--fs-small); line-height: var(--lh-small); }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-1); align-items: end; }
.text-input, .readonly-link { width: 100%; min-height: var(--tap); padding: 0 12px; background: var(--well); border: 1px solid var(--well-edge); box-shadow: var(--well-shade); border-radius: var(--radius-s); color: var(--text); }
.readonly-link { font-size: var(--fs-small); }
.form-error { color: var(--danger); font-size: var(--fs-small); line-height: var(--lh-small); }
.fields { width: 100%; border-collapse: collapse; font-size: var(--fs-small); font-family: var(--mono); }
.fields th, .fields td { text-align: left; padding: 4px 0; border-bottom: 1px solid var(--line); font-weight: 400; }
.fields td { text-align: right; padding-left: var(--sp-1); }
.fields th { color: var(--muted); }
.meta { color: var(--muted); font-size: var(--fs-small); font-family: var(--mono); }

/* Mode picker: grid of photo cells, detail bar pinned at the bottom */
.pick-grids { display: grid; gap: var(--sp-1); }
.pick-heading { font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; color: var(--muted); margin-top: var(--sp-1); }
.pick-grid { display: grid; gap: var(--sp-1); }
.pick-levels { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.pick-others { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pick { position: relative; overflow: hidden; min-width: 0; min-height: var(--tap); padding: 0; text-align: left; color: var(--photo-text); background: var(--photo-bg); background-clip: padding-box; border: 2px solid transparent; border-radius: var(--radius-s); }
.pick:hover, .pick:focus-visible { border-color: var(--key-edge); }
.pick[aria-current="true"] { border-color: var(--accent-strong); }
.pick-level { aspect-ratio: 1; }
.pick-wide { min-height: 72px; }
.pick-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 65%; }
/* Text sits on solid plates: the level number top-left, power (and percent) bottom-left, in the same place in every cell. */
.pick-num, .pick-level-text, .pick-text { position: absolute; z-index: 1; background: var(--plate); border-radius: var(--radius-plate); }
.pick-num { top: 6px; left: 6px; min-width: 24px; padding: 2px 5px; text-align: center; font-size: var(--fs-body); line-height: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pick-level-text { display: grid; left: 6px; bottom: 6px; max-width: calc(100% - 12px); padding: 2px 5px; }
.pick-power { font-size: 13px; line-height: 16px; font-weight: 600; }
.pick-percent { font-size: 11px; line-height: 14px; font-weight: 500; color: var(--photo-muted); }
.pick-text { display: grid; left: 6px; bottom: 6px; max-width: calc(100% - 12px); padding: 3px 6px; }
.pick-text b { font-size: 13px; line-height: 18px; font-weight: 600; overflow-wrap: anywhere; }
.pick-detail { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--photo-muted); overflow-wrap: anywhere; }
/* Not used: no photo, an empty well with quiet text instead of plates. */
.pick-unused { color: var(--text); background: var(--well); }
.pick-unused .pick-text { background: none; padding: 3px 4px; color: var(--muted); }
.pick-unused .pick-detail { color: var(--muted); }
.pick-plus { position: absolute; z-index: 1; top: 6px; right: 6px; color: var(--muted); font-size: var(--fs-title); line-height: 18px; }
.pick-unused[aria-current="true"] .pick-plus { display: none; }
/* Check on the picked cell: amber plate, dark check drawn with two borders. */
.pick-check { position: absolute; z-index: 1; top: 6px; right: 6px; width: 18px; height: 18px; background: var(--accent); border-radius: var(--radius-plate); }
.pick-check::after { content: ""; position: absolute; left: 6px; top: 3px; width: 4px; height: 8px; border: solid var(--on-accent); border-width: 0 2px 2px 0; transform: rotate(45deg); }
/* Open with a short fade and a 4 px rise; none under reduced motion. */
@keyframes pick-in { from { opacity: 0; transform: translateY(4px); } }
dialog.picker[open] { animation: pick-in 160ms ease-out; }
@media (prefers-reduced-motion: reduce) { dialog.picker[open] { animation: none; } }
.pick-detailbar { position: sticky; bottom: calc(-1 * var(--sp-2)); margin: 0 calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)); padding: var(--sp-1) var(--sp-2); background: var(--surface); border-top: 1px solid var(--line); font-size: var(--fs-small); line-height: var(--lh-small); min-height: var(--tap); display: flex; align-items: center; z-index: 2; }
@media (max-width: 767px) {
  .pick-levels { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pick-others { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.pick-signal { display: grid; gap: var(--sp-2); padding-top: var(--sp-2); border-top: 1px solid var(--line); }
.signal-grid { display: grid; gap: var(--sp-1); }
@media (min-width: 768px) { .signal-grid { grid-template-columns: 1fr 1fr; } }

/* Advanced rows */
.warning-banner { padding: var(--sp-2); border: 1px solid var(--danger); border-left-width: 4px; border-radius: var(--radius-s); }
.warning-banner strong { color: var(--danger); }
.danger-text { color: var(--danger); font-size: var(--fs-small); line-height: var(--lh-small); font-weight: 500; }
.pin-row select { font-family: var(--mono); }
.pin-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-1); }
