/* 3D Print Manager 2 — functional UI pieces (Claude): dialogs, forms, toasts, empty states, lists.
   Uses ONLY Gemini's tokens (tokens.css) so the look follows the design system. Gemini may restyle freely;
   keep class names and data-* hooks (assets/js/p2-ui.js depends on them). */

/* Inputs */
.p2-input, .p2-field input:not([type=checkbox]):not([type=radio]), .p2-field select, .p2-field textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: var(--p2-radius-sm); border: 1px solid var(--p2-border-strong);
  background: var(--p2-bg-deep); color: var(--p2-text); font: 14px var(--p2-font-body);
}
.p2-field textarea { min-height: 84px; resize: vertical; }
.p2-input:focus, .p2-field input:focus, .p2-field select:focus, .p2-field textarea:focus { outline: 2px solid var(--p2-cyan); outline-offset: 1px; border-color: var(--p2-border-cyan); }
.p2-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--p2-text-muted); min-width: 0; }
.p2-field > span:first-child { font-weight: 600; letter-spacing: .02em; }
.p2-field small { color: var(--p2-text-dim); font-size: 11px; }
.p2-field-check { flex-direction: row; align-items: center; gap: 10px; color: var(--p2-text); font-size: 13px; }
.p2-field-check input { width: 18px; height: 18px; accent-color: var(--p2-green); }
.p2-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.p2-form-grid .p2-span-2 { grid-column: 1 / -1; }
.p2-form-error { display: none; margin: 0; padding: 10px 12px; border-radius: var(--p2-radius-sm); border: 1px solid var(--p2-border-red); background: color-mix(in srgb, var(--p2-red) 10%, transparent); color: var(--p2-text); font-size: 13px; }
.p2-form-error.is-shown { display: block; }
.p2-form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* Dialogs */
/* margin:auto centres the modal; app.css's "* { margin: 0 }" reset removes the browser default. */
.p2-dialog { margin: auto; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--p2-border-strong); border-radius: var(--p2-radius-lg);
  background: var(--p2-surface); color: var(--p2-text); box-shadow: var(--p2-shadow), var(--p2-glow-cyan); }
.p2-dialog.is-wide { width: min(920px, calc(100vw - 24px)); }
.p2-dialog::backdrop { background: color-mix(in srgb, var(--p2-bg-deep) 72%, transparent); backdrop-filter: blur(3px); }
.p2-dialog > form, .p2-dialog > .p2-dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.p2-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.p2-dialog-head h2 { font-size: 18px; }
.p2-dialog-close { background: none; border: 0; color: var(--p2-text-muted); font-size: 22px; cursor: pointer; line-height: 1; }

/* Toasts */
.p2-toasts { position: fixed; z-index: 100; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.p2-toast { padding: 12px 16px; border-radius: var(--p2-radius-sm); background: var(--p2-surface-2); border: 1px solid var(--p2-border-glow); color: var(--p2-text); box-shadow: var(--p2-shadow); font-size: 14px; }
.p2-toast.is-error { border-color: var(--p2-border-red); }
@media (max-width: 860px) { .p2-toasts { bottom: calc(var(--p2-bottom-nav-h) + 12px + env(safe-area-inset-bottom)); } }

/* Empty states, notices */
.p2-empty { text-align: center; padding: 36px 20px; border: 1px dashed var(--p2-border-strong); border-radius: var(--p2-radius); color: var(--p2-text-muted); }
.p2-empty b { display: block; color: var(--p2-text); font-size: 16px; margin-bottom: 6px; }
.p2-empty .p2-btn { margin-top: 14px; }
.p2-notice { padding: 12px 14px; border-radius: var(--p2-radius-sm); border: 1px solid var(--p2-border-amber); background: color-mix(in srgb, var(--p2-amber) 8%, transparent); color: var(--p2-text); font-size: 13px; }
.p2-notice.is-ok { border-color: var(--p2-border-glow); background: color-mix(in srgb, var(--p2-green) 8%, transparent); }
.p2-notice.is-bad { border-color: var(--p2-border-red); background: color-mix(in srgb, var(--p2-red) 8%, transparent); }
.p2-notice ul { margin: 6px 0 0; padding-left: 18px; }

/* Small bits */
.p2-swatch { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--p2-border-strong); vertical-align: middle; flex: none; }
.p2-swatch.is-lg { width: 34px; height: 34px; }
.p2-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--p2-radius-full); font: 600 11px var(--p2-font-mono); border: 1px solid var(--p2-border-strong); color: var(--p2-text-muted); }
.p2-tag.is-ok { color: var(--p2-green); border-color: var(--p2-border-glow); }
.p2-tag.is-info { color: var(--p2-cyan); border-color: var(--p2-border-cyan); }
.p2-tag.is-warn { color: var(--p2-amber); border-color: var(--p2-border-amber); }
.p2-tag.is-bad { color: var(--p2-red); border-color: var(--p2-border-red); }
.p2-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.p2-row.is-between { justify-content: space-between; }
.p2-stack { display: flex; flex-direction: column; gap: 14px; }
.p2-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.p2-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.p2-mono { font-family: var(--p2-font-mono); }
.p2-actions-cell { white-space: nowrap; text-align: right; }
.p2-actions-cell .p2-btn { min-height: 32px; padding: 0 10px; font-size: 12px; }
.p2-btn[disabled], .p2-btn.is-busy { opacity: .55; pointer-events: none; }
.p2-btn-sm { min-height: 32px !important; padding: 0 10px !important; font-size: 12px !important; }
.p2-stock { height: 8px; border-radius: 99px; background: var(--p2-bg-deep); overflow: hidden; border: 1px solid var(--p2-border); }
.p2-stock > i { display: block; height: 100%; background: var(--p2-grad-primary); }
.p2-stock.is-low > i { background: var(--p2-grad-heat); }
.p2-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.p2-filters .p2-btn { min-height: 34px; padding: 0 12px; font-size: 13px; }
.p2-pager { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.p2-kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.p2-kv dt { color: var(--p2-text-muted); }
.p2-kv dd { margin: 0; }
.p2-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.p2-timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 10px; border-left: 2px solid var(--p2-border-cyan); padding-left: 10px; }
.p2-timeline time { color: var(--p2-text-muted); font-family: var(--p2-font-mono); font-size: 11px; }

/* Catalog detail */
.p2-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.p2-gallery figure { margin: 0; position: relative; border-radius: var(--p2-radius-sm); overflow: hidden; border: 1px solid var(--p2-border); background: var(--p2-bg-deep); aspect-ratio: 1; }
.p2-gallery figure.is-cover { border-color: var(--p2-green); box-shadow: var(--p2-glow-green); }
.p2-gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.p2-gallery figcaption { position: absolute; inset: auto 0 0 0; display: flex; gap: 4px; justify-content: center; padding: 6px; background: linear-gradient(transparent, var(--p2-glass-heavy)); }
.p2-gallery figcaption .p2-btn { min-height: 26px; padding: 0 8px; font-size: 11px; }
.p2-hero-img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--p2-radius); border: 1px solid var(--p2-border); background: var(--p2-bg-deep); }
.p2-file { border: 1px solid var(--p2-border); border-radius: var(--p2-radius); padding: 14px 16px; background: var(--p2-glass-subtle, var(--p2-bg-deep)); display: flex; flex-direction: column; gap: 10px; }
.p2-file.is-archived { opacity: .6; }
.p2-file-plates { display: flex; gap: 8px; flex-wrap: wrap; }
.p2-plate { border: 1px solid var(--p2-border); border-radius: var(--p2-radius-sm); padding: 8px 10px; font-size: 12px; min-width: 160px; }

/* Print dialog: filament → tray rows */
.p2-map-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) minmax(0, 1.4fr); gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--p2-border); font-size: 13px; }
.p2-map-row select { min-height: 36px; }
/* AMS slot picker (print dialog): button + inline list, each option with its colour swatch */
.p2-swatch.is-md { width: 24px; height: 24px; }
.p2-swatch.is-none { background: repeating-linear-gradient(45deg, transparent 0 4px, var(--p2-border-strong) 4px 6px); border-style: dashed; }
.p2-pick { min-width: 0; }
.p2-map-row { align-items: start; }
.p2-map-row > .p2-swatch, .p2-map-row > span:not(.p2-swatch) { margin-top: 10px; }
.p2-pick-btn, .p2-pick-opt { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 6px 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--p2-border-strong); border-radius: var(--p2-radius-sm); background: var(--p2-bg-deep); color: var(--p2-text); font: 13px var(--p2-font-body); }
.p2-pick-btn:hover, .p2-pick-opt:hover { border-color: var(--p2-border-cyan); }
.p2-pick-btn:focus-visible, .p2-pick-opt:focus-visible { outline: 2px solid var(--p2-cyan); outline-offset: 1px; }
.p2-pick-btn[aria-expanded="true"] { border-color: var(--p2-border-cyan); }
.p2-pick-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.p2-pick-text b { font-size: 13px; }
.p2-pick-text small { color: var(--p2-text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p2-pick-caret { color: var(--p2-text-muted); }
.p2-pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; padding: 6px; border: 1px solid var(--p2-border); border-radius: var(--p2-radius-sm); background: var(--p2-surface); max-height: 300px; overflow-y: auto; }
.p2-pick-list[hidden] { display: none; }
.p2-pick-opt { border-color: var(--p2-border); }
.p2-pick-opt.is-on { border-color: var(--p2-border-glow); background: rgba(0, 230, 118, .07); }
@media (max-width: 860px) {
  .p2-map-row { grid-template-columns: 26px minmax(0, 1fr); }
  .p2-map-row .p2-pick { grid-column: 1 / -1; }
}

/* Cockpit */
.p2-cam-empty { aspect-ratio: 16 / 9; display: grid; place-items: center; text-align: center; padding: 20px; border-radius: var(--p2-radius); border: 1px dashed var(--p2-border-strong); color: var(--p2-text-muted); background: var(--p2-bg-deep); }
.p2-control-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.p2-jog { display: grid; grid-template-columns: repeat(4, auto); gap: 6px; align-items: center; justify-content: start; }

@media (max-width: 860px) {
  .p2-form-grid, .p2-grid-2, .p2-grid-3 { grid-template-columns: 1fr; }
  .p2-timeline li { grid-template-columns: 1fr; }
  .p2-table-wrap { margin: 0 -4px; }
}

[hidden] { display: none !important; }
.p2-model-badges .p2-tag { background: var(--p2-glass-heavy); }

/* Confirm modal (P2.confirm, replaces window.confirm) */
.p2-dialog.p2-confirm { width: min(440px, calc(100vw - 24px)); }
.p2-confirm .p2-dialog-head h2 { font-size: 17px; }
.p2-confirm-msg { margin: 0; color: var(--p2-text-muted); line-height: 1.5; white-space: pre-line; }
@media (max-width: 860px) { .p2-dialog.p2-confirm { margin: auto auto calc(12px + env(safe-area-inset-bottom)); } .p2-confirm .p2-form-actions .p2-btn { flex: 1; } }

/* AMS slot cards: AMS reading + assigned inventory spool (printer page) */
.p2-slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
/* Two columns: swatches (AMS colour on top, Filament-page colour beside a colour warning) | text. */
.p2-slot { display: grid; grid-template-columns: 34px minmax(0, 1fr); column-gap: 12px; row-gap: 8px; align-items: start; padding: 12px; border: 1px solid var(--p2-border); border-radius: var(--p2-radius); background: var(--p2-bg-deep); }
.p2-slot .p2-btn { margin-top: 2px; }
.p2-slot-name { font-weight: 600; color: var(--p2-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p2-slot-warn { font-size: 12px; color: var(--p2-amber); align-self: center; }
.p2-slot.is-mismatch { border-color: var(--p2-border-amber); }
.p2-swatch.is-mismatch { outline: 2px solid var(--p2-amber); outline-offset: 1px; }

/* Catalog file: filaments to load per colour slot (linked from the Filament page) */
.p2-fil-list { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--p2-border); border-radius: var(--p2-radius-sm); background: var(--p2-bg-deep); }
.p2-fil-row { display: grid; grid-template-columns: minmax(150px, .8fr) 18px minmax(0, 2fr); gap: 10px; align-items: center; }
.p2-fil-row > .p2-link-edit { grid-column: 3; }
.p2-fil-need, .p2-link-filament { display: flex; align-items: center; gap: 10px; min-width: 0; }
.p2-link-filament.is-empty { min-height: 34px; }
.p2-fil-arrow { color: var(--p2-text-dim); text-align: center; }
.p2-link-edit > summary { list-style: none; display: inline-flex; cursor: pointer; }
.p2-link-edit > summary::-webkit-details-marker { display: none; }
.p2-link-edit[open] > summary { margin-bottom: 8px; }
@media (max-width: 860px) {
  .p2-fil-row { grid-template-columns: minmax(0, 1fr); gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--p2-border); }
  .p2-fil-row > .p2-link-edit { grid-column: auto; }
  .p2-fil-arrow { display: none; }
}
.p2-pd-linked { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--p2-text-muted); }
