/* OBJ Folder Viewer — all styles for the library and viewer pages. Design tokens per SPEC §8. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dfe3e8;
  --text: #15181d;
  --muted: #5f6670;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --header-h: 56px;
  --bar-h: 52px;
  --canvas-dark: #1b1e24;
  --canvas-light: #e9ecef;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body.page-viewer { overflow: hidden; }

a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 20px; margin: 0 0 8px; }
p { margin: 0 0 12px; }
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------------------
   Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn svg, .icon-btn svg, .tool svg { flex: none; }

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.is-active { color: var(--accent); background: #e8efff; }
.icon-btn-sm { width: 30px; height: 30px; border-radius: 7px; }
.icon-btn.has-warnings::after {
  content: '';
  position: absolute;
  top: 7px; right: 7px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------------------------------------------------------------------------
   Library header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
}
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------------------
   Library */

.library { max-width: 1400px; margin: 0 auto; padding: 20px; }
.library-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.search { position: relative; display: flex; align-items: center; flex: 1 1 260px; max-width: 420px; }
.search-icon { position: absolute; left: 12px; display: flex; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px 0 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.library-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(16, 24, 40, .06), 0 14px 32px rgba(16, 24, 40, .12); }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-thumb { aspect-ratio: 16 / 10; background: var(--surface-2); overflow: hidden; }
.card-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 12px 14px 14px; }
.card-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta { font-size: 13px; color: var(--muted); }
.card-admin { position: absolute; top: 8px; right: 8px; }
.card-menu-btn { width: 36px; height: 36px; background: rgba(255, 255, 255, .92); box-shadow: var(--shadow); }
.card-menu-btn:hover { background: #fff; }
.menu {
  position: absolute;
  top: 42px;
  right: 0;
  z-index: 5;
  min-width: 170px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.is-danger { color: var(--danger); }
.card-confirm {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: rgba(255, 255, 255, .97);
}
.card-confirm p { margin: 0; overflow-wrap: anywhere; }
.card-confirm-actions { display: flex; gap: 8px; }

.empty-state {
  max-width: 560px;
  margin: 0 auto;
  padding: 64px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-icon { color: #aeb5bf; }
.empty-state h2 { margin: 12px 0 8px; color: var(--text); }
.empty-actions { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }

.library-login { display: flex; justify-content: center; padding: 48px 0; }
.login-card {
  width: min(100%, 420px);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------------------
   Forms */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 13px; font-weight: 500; }
.field-hint { font-size: 12px; color: var(--muted); }
.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.field textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.form-error { margin: 0 0 12px; color: var(--danger); font-size: 13px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------------------------------------------------------------------------
   Dialogs */

.dialog {
  width: min(calc(100vw - 32px), 460px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(16, 24, 40, .25);
}
.dialog-wide { width: min(calc(100vw - 32px), 660px); }
.dialog::backdrop { background: rgba(16, 24, 40, .45); }
/* No bottom padding here: the sticky action row below carries it, so the row sits flush with the
   scroll edge in every browser (some inset the sticky rectangle by the container's padding). */
.dialog-content { max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); padding: 20px 22px 0; overflow: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
/* The action row stays visible while a long form (upload file list) scrolls inside the dialog. */
.dialog .form-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: 8px -22px 0;
  padding: 12px 22px 22px;
  background: var(--surface);
}

/* Upload dropzone and file list */
.dropzone {
  margin-bottom: 12px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.is-dragover { border-color: var(--accent); background: #eaf1ff; }
.dropzone-icon { color: var(--accent); }
.dropzone p { margin: 8px 0 0; }
.dropzone-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.upload-summary { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; font-size: 13px; }
.upload-files {
  max-height: 220px;
  margin: 0 0 12px;
  padding: 0;
  overflow: auto;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.upload-files:empty { display: none; }
.upload-files li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.upload-files li:last-child { border-bottom: 0; }
.upload-files li.is-skipped .file-path { color: var(--muted); text-decoration: line-through; }
.file-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.upload-progress { margin: 4px 0 10px; }
.progress-text { margin-top: 6px; font-size: 12px; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  vertical-align: middle;
  white-space: nowrap;
}
.badge-loaded { background: #dcfce7; color: #166534; }
.badge-loading { background: #dbeafe; color: #1e40af; }
.badge-missing, .badge-error { background: #fee2e2; color: #991b1b; }
.badge-unsupported { background: #fef3c7; color: #92400e; }

.progress { position: relative; height: 8px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.progress-bar { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .15s; }
.is-indeterminate .progress-bar { width: 40% !important; animation: indeterminate 1.2s ease-in-out infinite; }
@keyframes indeterminate { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------------------------------------------------------------------------
   Toasts */

.toasts {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: #15181d;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  animation: toast-in .2s ease-out;
  transition: opacity .2s;
}
/* Above the floating toolbar, and above the "Load all blocks" notice while it is shown (--notice-offset). */
.page-viewer .toasts { bottom: calc(76px + var(--notice-offset, 0px)); }
.toast-error { background: var(--danger); }
.toast-success { background: var(--ok); }
.toast-warning { background: #b45309; } /* a darker --warn: white text stays readable (contrast ≈ 5:1) */
.toast.is-leaving { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------------------
   Viewer layout */

.viewer {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}
/* Explicit grid placement: when the header is hidden (embed mode) its auto row collapses to 0
   and the stage still fills the whole frame instead of leaving an empty 1fr row below it. */
.viewer-bar {
  grid-row: 1;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--bar-h);
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
/* contain: inline-size keeps the nowrap title and stats out of the bar's minimum width: a phone browser
   would otherwise widen its layout viewport to fit them and push the panel toggle off-screen. */
.viewer-heading { flex: 1; display: flex; flex-direction: column; justify-content: center; min-width: 0; contain: inline-size; }
.viewer-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.viewer-stats { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.obj-switch select {
  max-width: 240px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.viewer-stage { grid-row: 2; grid-column: 1; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.viewer-stage[data-bg="dark"] { background: radial-gradient(ellipse at 50% 40%, #272b34 0%, var(--canvas-dark) 70%); }
.viewer-stage[data-bg="light"] { background: radial-gradient(ellipse at 50% 40%, #f5f6f8 0%, var(--canvas-light) 70%); }
.viewer-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewer-stage.is-measuring .viewer-canvas { cursor: crosshair; }
.labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.measure-label {
  position: absolute;
  top: 0; left: 0;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.viewer.is-dragover .viewer-stage::after {
  content: 'Drop to open';
  position: absolute;
  inset: 12px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--accent);
  border-radius: 14px;
  background: rgba(37, 99, 235, .25);
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  pointer-events: none;
}

/* Toolbar */
.toolbar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100% - 24px);
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}
.tool {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: none;
  min-width: 40px;
  height: 40px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  transition: background .15s, color .15s;
}
.tool:hover { background: var(--surface-2); }
.tool.is-active, .tool[aria-pressed="true"] { background: #e8efff; color: var(--accent); }
.tool:disabled { opacity: .4; cursor: not-allowed; }
.tool-text { font-size: 12px; font-weight: 600; }
.tool-badge { position: absolute; right: 5px; bottom: 4px; font-size: 9px; font-weight: 700; line-height: 1; }
.tool-sep { flex: none; width: 1px; height: 24px; margin: 0 3px; background: var(--border); }
.tool-group { position: relative; display: flex; }
.popover {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  z-index: 6;
  min-width: 180px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.popover-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
}
.popover-item:hover { background: var(--surface-2); }

/* Floating chips and feedback */
.chip {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 6;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .94);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow);
}
/* Centred chips are sized to their text (an absolutely positioned box at left: 50% would otherwise
   shrink to half the stage and wrap) and never wider than the stage. */
.chip-measure { left: 50%; width: max-content; max-width: calc(100% - 24px); transform: translateX(-50%); text-align: center; background: #f59e0b; color: #1f1300; }
.chip-progress { display: flex; align-items: center; gap: 8px; max-width: calc(100% - 24px); }
.chip-spinner {
  flex: none;
  width: 14px; height: 14px;
  border: 2px solid rgba(37, 99, 235, .25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-bar { flex: none; width: 56px; height: 4px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.chip-bar-fill { display: block; width: 0; height: 100%; border-radius: 999px; background: var(--accent); transition: width .15s; }
.chip-progress.is-indeterminate .chip-bar-fill { width: 40%; animation: indeterminate 1.2s ease-in-out infinite; }
/* The notice wraps onto two lines on narrow screens: a card radius keeps the text inside the shape. */
.chip-notice {
  top: auto;
  bottom: 76px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border-radius: 12px;
  transform: translateX(-50%);
  text-align: center;
}
.chip-notice .chip-text { white-space: normal; }
.chip-notice .btn { flex: none; min-height: 30px; padding: 0 10px; font-size: 12px; }
.coords {
  position: absolute;
  top: 0; left: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(21, 24, 29, .9);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: pre;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.coords-srs { color: #bfdbfe; }
.share-feedback {
  position: absolute;
  left: 50%;
  bottom: 76px;
  z-index: 6;
  max-width: calc(100% - 24px);
  padding: 8px 14px;
  border-radius: 8px;
  background: #15181d;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  transform: translateX(-50%);
}
.embed-bar { position: absolute; top: 10px; right: 10px; z-index: 6; display: flex; align-items: center; gap: 6px; }
.embed-bar .btn, .embed-bar .icon-btn { background: rgba(255, 255, 255, .94); box-shadow: var(--shadow); }

/* Loading / error / local dropzone / help overlays */
.loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  background: rgba(27, 30, 36, .55);
  color: #fff;
  text-align: center;
}
.viewer-stage[data-bg="light"] .loading { background: rgba(233, 236, 239, .7); color: var(--text); }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(128, 128, 128, .35);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label { font-size: 15px; font-weight: 600; }
.loading-detail { min-height: 1.4em; font-size: 13px; opacity: .85; font-variant-numeric: tabular-nums; }
.loading .progress { width: min(320px, 70vw); background: rgba(128, 128, 128, .3); }
.loading-note { margin-top: 6px; font-size: 12px; opacity: .85; }

.error-state, .local-dropzone, .help-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.error-state { z-index: 9; }
.local-dropzone { z-index: 7; }
.help-overlay { z-index: 25; background: rgba(16, 24, 40, .35); }
.error-card, .dropzone-card, .help-card {
  width: 100%;
  max-width: 460px;
  padding: 28px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .3);
}
.error-icon { color: var(--danger); }
.error-title { margin: 8px 0; }
.error-message { margin: 0 0 16px; color: var(--muted); overflow-wrap: anywhere; }
.error-actions { display: flex; justify-content: center; gap: 8px; }
.dropzone-card p { color: var(--muted); }
.dropzone-card h2 { margin-top: 8px; }
.help-card { max-width: 640px; max-height: 100%; overflow: auto; text-align: left; }
.help-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.help-head h2 { margin: 0; }
.help-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.help-card h3 { margin: 16px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.help-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.help-list dt { font-weight: 500; }
.help-list dd { margin: 0; color: var(--muted); }

/* Panel */
.panel {
  grid-row: 2;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  width: 340px;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
/* Five tabs with badges fit the panel; should they not (larger fonts), the strip scrolls on its own
   instead of widening the panel. */
.panel-tabs { display: flex; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.panel-tabs::-webkit-scrollbar { display: none; }
.panel-tab {
  flex: 1 0 auto;
  min-height: 44px;
  padding: 0 4px;
  font-size: 13px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.panel-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-tab .badge { margin-left: 2px; background: #fef3c7; color: #92400e; }
.panel-close { display: none; margin: 0 4px; }
.panel-section { padding: 14px 16px 20px; }
.panel-section h3 {
  margin: 18px 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.panel-section h3:first-child { margin-top: 0; }
.panel-empty, .panel-help { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.file-list, .material-list, .texture-list, .warning-list, .measure-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.file-list li, .texture-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--surface-2); }
.material-list li { padding: 6px 0; border-bottom: 1px solid var(--surface-2); }
.material-name { font-weight: 500; overflow-wrap: anywhere; }
.material-map { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.warning-list li {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fef3c7;
  color: #92400e;
  overflow-wrap: anywhere;
}
.warning-list svg { flex: none; margin-top: 2px; }
.measure-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--surface-2); }
.measure-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}
.measure-value { flex: 1; font-variant-numeric: tabular-nums; }
.admin-settings { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.admin-settings h3 { margin-top: 0; }

/* Blocks tab */
.blocks-actions { margin: 0 0 8px; }
.block-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.block-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--surface-2); }
.block-toggle { display: flex; align-items: center; justify-content: center; flex: none; min-width: 32px; min-height: 32px; cursor: pointer; }
.block-check { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.block-main { flex: 1; min-width: 0; }
.block-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.block-meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.block-row.is-error .block-meta { color: var(--danger); }
.block-status { flex: none; }
.badge-idle { background: var(--surface-2); color: var(--muted); }
.blocks-summary { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

/* Library cards: block count and optimisation badge (SPEC §15 "Library v2") */
.card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge-done { background: #dcfce7; color: #166534; }
.badge-queued, .badge-running { background: #dbeafe; color: #1e40af; }
.badge-none { background: var(--surface-2); color: var(--muted); }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-partial { background: #fef3c7; color: #92400e; }
.upload-warning { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; background: #fef3c7; color: #92400e; font-size: 13px; }

/* Embed mode: no header, compact toolbar */
.viewer.is-embed .toolbar { bottom: 8px; padding: 2px; }
.viewer.is-embed .tool { min-width: 34px; height: 34px; }
.viewer.is-embed .tool-sep { height: 18px; }
.viewer.is-embed .share-feedback { bottom: 56px; }

/* ---------------------------------------------------------------------------
   Responsive */

@media (max-width: 720px) {
  .app-header { gap: 8px; padding: 0 12px; }
  .header-actions .btn { padding: 0 10px; font-size: 13px; gap: 6px; }
  .library { padding: 12px; }
  .viewer { grid-template-columns: 1fr; }
  .toolbar {
    left: 0; right: 0; bottom: 0;
    max-width: none;
    justify-content: flex-start;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    border-left: 0; border-right: 0; border-bottom: 0;
    border-radius: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    transform: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .popover { position: fixed; left: 12px; right: 12px; bottom: 64px; min-width: 0; }
  .share-feedback, .chip-measure { bottom: auto; top: 12px; }
  .chip-progress { top: 48px; max-width: calc(100% - 24px); }
  .chip-notice { bottom: 80px; flex-wrap: wrap; justify-content: center; }
  .coords { font-size: 11px; }
  .viewer.is-embed .share-feedback { bottom: auto; }
  .panel {
    grid-row: auto;
    grid-column: auto; /* auto lines = the grid container's padding box, so the sheet spans the stage */
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 15;
    width: auto;
    max-height: 60%;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgba(16, 24, 40, .15);
  }
  .panel-close { display: inline-flex; }
  .help-columns, .field-row { grid-template-columns: 1fr; }
  .dialog, .dialog-wide { width: calc(100vw - 16px); }
  .dialog-content { padding: 16px 16px 0; }
  .dialog .form-actions { margin: 8px -16px 0; padding: 12px 16px 16px; }
  .toasts { left: 12px; right: 12px; bottom: 72px; max-width: none; }
}

@media (max-width: 480px) {
  .brand span { display: none; }
  .viewer-bar { gap: 6px; padding: 0 6px; }
  .obj-switch select { max-width: 140px; }
  .empty-state { padding: 40px 8px; }
}

@media (hover: none) {
  .btn, .icon-btn, .tool { min-height: 40px; }
  .tool { height: 40px; }
  .viewer.is-embed .tool { height: 40px; min-width: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .btn, .toast { transition: none; animation: none; }
}

/* ---- Project passwords: start page and client-access dialog ---- */
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.link-button:hover { color: var(--text); }
.access-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin: 16px 0 0; font-size: 13px; }
.access-footer > span { margin-left: auto; }
.field-inline { display: flex; gap: 8px; }
.field-inline input { flex: 1; min-width: 0; }
.form-actions .spacer { flex: 1; }
.badge-protected { background: #fef3c7; color: #92400e; display: inline-flex; align-items: center; gap: 4px; }
