/* ─────────────────────────────────────────────────────────────────────────
   ARD Converter – web shell stylesheet
   ───────────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: 'Segoe UI', sans-serif; font-size: 9pt; }

/* Form controls don't inherit font-family from the page by default in any
   browser (they use UA-provided system fonts, typically Arial-like on
   Windows). Force them to match the rest of the UI so toolbars, selects
   and buttons all read in Segoe UI. */
button, input, select, textarea, optgroup {
  font-family: inherit;
}

/* ── App root ──────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100%; }

/* ── File bar ──────────────────────────────────────────────────────────── */
#file-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: #f0f0f0;
  border-bottom: 1px solid #ccc;
  flex-shrink: 0;
  min-height: 26px;
}
#file-bar button {
  height: 24px;
  box-sizing: border-box;
  padding: 0 10px;
}
#file-name {
  flex: 1 1 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 8pt;
  color: #555;
}
#file-name .file-name-text { font-weight: 700; }
.debug-truncation-note {
  flex-shrink: 0;
  font: 7.5pt 'Segoe UI', sans-serif;
  color: #8d5a00;
  background: #fff3cd;
  border: 1px solid #f0d58a;
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
}
#browse-btn {
  flex-shrink: 0;
  font: 8.5pt 'Segoe UI', sans-serif;
  cursor: pointer;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 24px;
  min-width: 24px;
  box-sizing: border-box;
  padding: 0 10px;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #f8f8f8;
  color: #555;
  font: 8.5pt 'Segoe UI', sans-serif;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.icon-btn:hover {
  background: #fff;
  border-color: #999;
  color: #222;
}
.icon-btn .btn-label { white-space: nowrap; }
.icon-btn.img-btn img {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
#ui-scale-btn {
  min-width: 64px;
  padding: 0 8px;
}
#ui-scale-btn .btn-label {
  font: 8.5pt 'Segoe UI', sans-serif;
}
.ui-scale-step-btn {
  min-width: 24px;
  width: 24px;
  padding: 0;
  font: 10pt 'Segoe UI', sans-serif;
}
.account-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.account-menu-btn {
  min-width: 0;
}
.account-menu-btn .btn-label {
  display: block;
  min-width: 0;
  white-space: nowrap;
}
.account-menu-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  width: max-content;
  max-width: min(320px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  padding: 6px 0;
  z-index: 50;
}
.account-menu-popover .item,
.account-menu-popover .account-menu-item,
.account-menu-popover .profile-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: none;
  color: #222;
  text-align: left;
  text-decoration: none;
  font: 9pt 'Segoe UI', sans-serif;
  cursor: pointer;
}
.account-menu-popover .item:hover,
.account-menu-popover .item:focus-visible,
.account-menu-popover .account-menu-item:hover,
.account-menu-popover .account-menu-item:focus-visible,
.account-menu-popover .profile-menu-item:hover,
.account-menu-popover .profile-menu-item:focus-visible {
  background: #f3f3f3;
  outline: none;
}
.account-menu-popover .sep,
#profile-menu-sep-main,
#profile-menu-sep-debug {
  height: 1px;
  background: #ddd;
  margin: 6px 0;
}
/* ── Main content area (below file bar) ────────────────────────────────── */
#content { display: flex; flex: 1 1 0; min-height: 0; }

/* ── Left panel ────────────────────────────────────────────────────────── */
#left-panel {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Tab bar */
#tab-bar {
  display: flex;
  background: #e8e8e8;
  border-bottom: 1px solid #ccc;
  flex-shrink: 0;
}
#tab-bar .tab {
  padding: 4px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-right: 1px solid transparent;
  cursor: pointer;
  font: 8.5pt 'Segoe UI', sans-serif;
  color: #555;
}
#tab-bar .tab:not(:last-child) { border-right-color: rgba(0,0,0,0.10); }
#tab-bar .tab.active {
  border-bottom-color: #c1272c;
  color: #c1272c;
  font-weight: 600;
}
#tab-bar .tab:hover:not(.active) { background: #ddd; }
#tab-bar .tab.needs-file-tab:disabled,
#tab-bar .tab.feature-tab:disabled,
#tab-bar .tab.debug-tab:disabled {
  opacity: 0.5;
  cursor: default;
  color: #888;
}
#tab-bar .tab.needs-file-tab:disabled:hover,
#tab-bar .tab.feature-tab:disabled:hover,
#tab-bar .tab.debug-tab:disabled:hover { background: none; }

/* Tab content panes */
.tab-content {
  display: none;
  flex: 1 1 0;
  overflow: hidden;
  position: relative;
}
.tab-content.active { display: flex; flex-direction: column; }

/* ── Preview tab ────────────────────────────────────────────────────────── */
#tab-preview {
  position: relative;
  overflow: hidden;
}
#wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #f0f0f0;
  user-select: none;
  /* Stop the browser from generating pan/zoom gestures; viewer.js owns them. */
  touch-action: none;
  -ms-touch-action: none;
  overscroll-behavior: contain;
}
#svg-root {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
}
#svg-root.dragging { cursor: grabbing; }
#hint {
  position: absolute;
  bottom: 6px; right: 8px;
  font: 10px/1.4 'Segoe UI', sans-serif;
  color: #999;
  pointer-events: none;
}
#zoom-pct {
  font: 11px/1.4 'Segoe UI', sans-serif;
  color: #555;
  background: rgba(255,255,255,0.82);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid #c8c8c8;
  cursor: pointer;
  user-select: none;
  min-width: 42px;
  text-align: center;
}
#zoom-pct:hover { background: #fff; border-color: #999; color: #222; }
#canvas-toolbar #zoom-actual-btn {
  background: rgba(255,255,255,0.82);
  border: 1px solid #c8c8c8;
  border-radius: 3px;
  font-size: 12px;
  padding: 0 8px;
  color: #555;
  cursor: pointer;
}
#canvas-toolbar #zoom-actual-btn:hover { background: #fff; border-color: #999; color: #222; }

/* SVG entity highlight */
.highlighted {
  stroke: #00ffff !important;
  filter: drop-shadow(0 0 2px #00ffff);
}
/* Groups: suppress filter on the container — children carry the glow individually */
g.highlighted { filter: none !important; }
/* Text: use fill highlight only — glow on text is distractingly large */
text.highlighted { fill: #00ffff !important; stroke: none !important; filter: none !important; }

/* ── Design Info tab ────────────────────────────────────────────────────── */
#tab-design .tab-empty-hint {
  display: none;
  margin: 10px;
  padding: 10px 12px;
  border: 1px dashed #c8c8c8;
  border-radius: 4px;
  background: #fafafa;
  color: #777;
  font: 12px 'Segoe UI', sans-serif;
}
body:not(.has-file) .tab-content.active .tab-empty-hint { display: block; }
body.dark-mode .tab-empty-hint {
  border-color: #4a4a4a;
  background: #242424;
  color: #9aa0a6;
}
.text-pane {
  flex: 1;
  padding: 8px 10px;
  font: 8.5pt Consolas, 'Courier New', monospace;
  white-space: pre;
  line-height: 1.4;
}

/* ── Embedded graphics list (Design Info tab) ───────────────────────────── */
#tab-design {
  flex-direction: column;
  overflow: auto;
  min-height: 0;
}
#tab-design .text-pane {
  flex: 0 0 auto;
  overflow: visible;
}
#graphics-panel {
  border-top: 1px solid rgba(0,0,0,0.12);
  padding: 8px 10px 12px 10px;
}
.graphics-header {
  font: 600 9pt 'Segoe UI', sans-serif;
  margin-bottom: 6px;
  opacity: 0.8;
}
.graphics-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 8px;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 4px;
  margin-bottom: 4px;
  background: rgba(0,0,0,0.02);
}
.graphics-item.is-thumbnail { opacity: 0.55; }
.graphics-meta {
  font: 8.5pt Consolas, 'Courier New', monospace;
}
.graphics-download {
  font: 8.5pt 'Segoe UI', sans-serif;
  text-decoration: none;
  padding: 3px 10px;
  border: 1px solid #4a90e2;
  border-radius: 3px;
  color: #fff;
  background: #4a90e2;
}
.graphics-download:hover { background: #357abd; border-color: #357abd; }
.graphics-nodownload {
  font: 8.5pt 'Segoe UI', sans-serif;
  opacity: 0.5;
  font-style: italic;
}
body.dark-mode #graphics-panel { border-top-color: rgba(255,255,255,0.12); }
body.dark-mode .graphics-item  { border-color: rgba(255,255,255,0.1); background: rgba(255,255,255,0.03); }

/* ── Debug tabs (JSON, Decode Dump) ─────────────────────────────────────── */
/* Hidden in web context unless body has .debug-mode (set via ?debug=1).    */
/* Always visible in plugin/host context (body.debug-mode added on init).   */
.debug-tab        { display: none; }
body.debug-mode .debug-tab { display: inline-block; }

/* Generic debug-only UI element: hidden unless body.debug-mode is set. */
.debug-only { display: none !important; }
body.debug-mode .debug-only { display: inline-flex !important; }

.debug-tab-content { display: none !important; overflow: hidden; }
body.debug-mode .debug-tab-content { display: none !important; }
body.debug-mode .debug-tab-content.active { display: flex !important; flex-direction: column; }

.debug-tab-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #f5f5dc;
  border-bottom: 1px solid #d0c880;
  flex-shrink: 0;
}
.debug-tab-label {
  font: 600 8pt 'Segoe UI', sans-serif;
  color: #665500;
  flex: 1;
}
.debug-truncation-badge {
  font: 8pt 'Segoe UI', sans-serif;
  color: #8d5a00;
  background: #fff3cd;
  border: 1px solid #f0d58a;
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
}
.debug-copy-btn {
  font: 8pt 'Segoe UI', sans-serif;
  padding: 2px 8px;
  border: 1px solid #bba040;
  border-radius: 3px;
  background: #fffff0;
  cursor: pointer;
  color: #554400;
}
.debug-copy-btn:hover { background: #ffffd0; }

.debug-pane {
  overflow: auto;
  background: #fffff8;
  color: #222;
  font-size: 7.5pt;
}

/* ── Left panel drag-over highlight (non-preview tabs) ───────────────────── */
#left-panel.drag-over {
  outline: 2px dashed #4a90d9;
  outline-offset: -2px;
}

/* ── Right panel ────────────────────────────────────────────────────────── */
#right-panel {
  width: 308px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #ccc;
  background: #fff;
  overflow: hidden;
}

/* Section header */
.section-header {
  font: 600 8.5pt 'Segoe UI', sans-serif;
  padding: 3px 6px;
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section-header > label {
  font-weight: 400;
  font-size: 8pt;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.section-header > label > input[type="checkbox"] { margin: 0; }
.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#inspector-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  color: #888;
  padding: 0 2px;
}
#inspector-close:hover { color: #333; }

/* Visibility section */
#section-visibility {
  overflow-y: auto;
  flex-shrink: 0;
  max-height: 55%;
}

/* Summary section */
#section-summary {
  flex-shrink: 0;
  border-top: 1px solid #ccc;
}
#section-summary .section-header {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
#section-summary.collapsed .collapse-arrow { transform: rotate(-90deg); }
#section-summary.collapsed #summary-text { display: none; }
.summary-pane {
  font: 7.5pt Consolas, 'Courier New', monospace;
  padding: 4px 6px;
  white-space: pre;
  line-height: 1.4;
}

/* Inspector section */
#section-inspector {
  flex: 1;
  overflow: auto;
  border-top: 1px solid #ccc;
}
.insp-hint {
  font: italic 7.5pt 'Segoe UI', sans-serif;
  color: #aaa;
  text-align: center;
  padding: 10px 6px;
  margin: 0;
}
#inspector-content {
  padding: 2px 4px;
}

/* ── Legend section ──────────────────────────────────────────────── */
#section-legend {
  flex-shrink: 0;
  margin-top: auto;   /* pin to bottom of the panel */
  border-top: 1px solid #ccc;
  /* Prevent the legend from consuming the full panel height and eclipsing
     the inspector / summary sections above it. */
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 25vh;
  overflow: hidden;
}
#section-legend .section-header {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.collapse-arrow { font-size: 9px; color: #888; transition: transform 0.15s; display: inline-block; }
#section-legend.collapsed .collapse-arrow { transform: rotate(-90deg); }
#legend-body { padding: 3px 6px 4px; overflow-y: auto; min-height: 0; }
#section-legend.collapsed #legend-body { display: none; }
.legend-item { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.legend-swatch { flex-shrink: 0; overflow: visible; }
.legend-label { font: 7.5pt Consolas, 'Courier New', monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #333; flex: 1 1 auto; min-width: 0; }
.legend-length { font: 7pt Consolas, 'Courier New', monospace; color: #888; white-space: nowrap; flex-shrink: 0; }

/* Visibility list items */
.vis-list { padding: 1px 4px 3px 4px; }
.vis-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 0;
  font: 7.5pt Consolas, 'Courier New', monospace;
}
.vis-item input[type="checkbox"] { margin: 0; cursor: pointer; flex-shrink: 0; }
.vis-item label {
  cursor: pointer;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vis-item label:hover { color: #c1272c; }
.vis-item.disabled label { color: #bbb; cursor: default; }
.vis-sep { height: 1px; background: #ddd; margin: 3px 0; }
.vis-sublist {
  margin: 0 0 3px 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.vis-subitem {
  display: flex;
  align-items: center;
  gap: 4px;
}
.vis-subitem input[type="checkbox"] { margin: 0; cursor: pointer; flex-shrink: 0; }
.vis-subitem-btn {
  border: 1px solid #ddd;
  background: #f8f8f8;
  border-radius: 3px;
  text-align: left;
  padding: 1px 6px;
  font: 7.5pt Consolas, 'Courier New', monospace;
  color: #555;
  cursor: pointer;
  flex: 1;
}
.vis-subitem-btn:hover { border-color: #c1272c; color: #c1272c; background: #fff; }
.vis-subitem-btn.selected { border-color: #c1272c; background: #fff1f1; color: #8d1c20; }

/* Right-click context menu for visibility lists */
.vis-ctx-menu {
  position: fixed;
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.15);
  z-index: 9999;
  min-width: 140px;
}
.vis-ctx-menu button {
  display: block;
  width: 100%;
  padding: 4px 12px;
  background: none;
  border: none;
  text-align: left;
  font: 8.5pt 'Segoe UI', sans-serif;
  cursor: pointer;
}
.vis-ctx-menu button:hover { background: #e8f0fe; }
.vis-ctx-sep { height: 1px; background: #ddd; margin: 2px 0; }

/* Inspector rows */
.insp-row {
  display: flex;
  gap: 4px;
  min-height: 18px;
  align-items: center;
}
.insp-label {
  width: 82px;
  flex-shrink: 0;
  color: #888;
  font: 7.5pt 'Segoe UI', sans-serif;
  text-align: right;
  padding-right: 2px;
}
.insp-value {
  flex: 1;
  font: 7.5pt 'Segoe UI', sans-serif;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
  border-radius: 2px;
  padding: 0 2px;
}
.insp-value:hover { background: #f0f0f0; cursor: pointer; }
.insp-row-action .insp-label { pointer-events: none; }
.insp-value-action { background: transparent !important; cursor: default !important; }
.insp-download-btn {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid #4a90e2;
  border-radius: 3px;
  background: #4a90e2;
  color: #fff;
  text-decoration: none;
  font: 8pt 'Segoe UI', sans-serif;
}
.insp-download-btn:hover { background: #357abd; border-color: #357abd; }
.insp-sep { height: 1px; background: #e8e8e8; margin: 2px 0; }

/* ── Context-aware visibility ───────────────────────────────────────────── */
body.context-web    .impact-only { display: none !important; }
body.context-host   .impact-only { display: none !important; }
body.context-plugin .host-only   { display: none !important; }
body.context-web    .host-only   { display: none !important; }

/* web-only: hidden in all contexts; only the combined rule below ever shows these */
.web-only { display: none !important; }
/* web-only elements that DON'T require a file: show whenever in web context */
body.context-web .web-only:not(.needs-file) { display: initial !important; }

/* needs-file: hidden until a file is loaded (body.has-file set by JS) */
.needs-file { display: none !important; }
body.has-file .needs-file:not(.web-only) { display: initial !important; }
/* Combined: web-only + needs-file — show only in web context after file load */
body.context-web.has-file .web-only.needs-file { display: initial !important; }

/* ── Save As button ─────────────────────────────────────────────────────── */
#saveas-btn {
  flex-shrink: 0;
  font: 8.5pt 'Segoe UI', sans-serif;
  cursor: pointer;
}

/* ── Save As modal overlay ──────────────────────────────────────────────── */
#saveas-overlay,
#profile-update-overlay,
#profile-password-overlay,
#profile-api-keys-overlay,
#profile-api-key-create-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
#saveas-overlay.open,
#profile-update-overlay.open,
#profile-password-overlay.open,
#profile-api-keys-overlay.open,
#profile-api-key-create-overlay.open { display: flex; }

#saveas-dialog,
#profile-update-dialog,
#profile-password-dialog,
#profile-api-keys-dialog,
#profile-api-key-create-dialog {
  background: #fff;
  border: 1px solid #bbb;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  border-radius: 4px;
  padding: 18px 20px 14px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#profile-update-dialog { min-width: 640px; max-width: min(94vw, 760px); }
#profile-api-keys-dialog { min-width: 760px; max-width: min(94vw, 980px); }
#profile-api-key-create-dialog { min-width: 460px; max-width: min(90vw, 560px); }

.profile-api-keys-toolbar {
  justify-content: flex-end;
}
#profile-api-keys-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
#profile-api-keys-table th,
#profile-api-keys-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #e5e5e5;
  vertical-align: middle;
}
#profile-api-keys-table th {
  text-align: left;
  font-weight: 600;
}
#profile-api-keys-table th:nth-child(1),
#profile-api-keys-table td:nth-child(1) { width: 24%; }
#profile-api-keys-table th:nth-child(2),
#profile-api-keys-table td:nth-child(2) { width: 56%; }
#profile-api-keys-table th:nth-child(3),
#profile-api-keys-table td:nth-child(3) { width: 10%; }
#profile-api-keys-table th:nth-child(4),
#profile-api-keys-table td:nth-child(4) { width: 10%; text-align: right; }
#profile-api-keys-table .row-actions {
  display: flex;
  justify-content: flex-end;
}
#profile-api-keys-table .profile-api-key-code {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.dark-mode #profile-api-keys-table th,
body.dark-mode #profile-api-keys-table td {
  border-bottom-color: #3a3a3a;
}

#saveas-title,
#profile-update-title,
#profile-password-title,
#profile-api-keys-title,
#profile-api-key-create-title {
  font: 600 10pt 'Segoe UI', sans-serif;
  color: #222;
  margin-bottom: 2px;
}

.saveas-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.saveas-row label {
  width: 106px;
  flex-shrink: 0;
  font: 9pt 'Segoe UI', sans-serif;
  color: #444;
}
.saveas-row select,
.saveas-row input {
  flex: 1;
  font: 9pt 'Segoe UI', sans-serif;
  padding: 2px 4px;
  border: 1px solid #bbb;
  border-radius: 3px;
}
#profile-update-dialog .saveas-row {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  align-items: center;
}
#profile-update-dialog .saveas-row label {
  width: auto;
}
#profile-update-dialog .saveas-row input {
  width: 100%;
}
.profile-password-feedback {
  margin: -4px 0 2px 114px;
  min-height: 14px;
  font: 8pt 'Segoe UI', sans-serif;
  color: #666;
}
.profile-password-feedback.ok { color: #2e7d32; }
.profile-password-feedback.warn { color: #8d5a00; }
.profile-password-feedback.error { color: #c1272c; }
/* ── Drop zone (empty state — web context only) ──────────────────────────── */
#drop-zone {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  cursor: pointer;
  border: 3px dashed transparent;
  box-sizing: border-box;
  transition: background 0.15s, border-color 0.15s;
}
body:not(.has-file) #drop-zone { display: flex; }
#drop-zone.drag-over {
  background: #eef4ff;
  border-color: #4a90d9;
}
#drop-zone-inner {
  text-align: center;
  pointer-events: none;
  user-select: none;
}
#drop-icon {
  width: 52px;
  height: 52px;
  stroke: #c0c0c0;
  display: block;
  margin: 0 auto 14px;
}
#drop-title {
  font: 600 14px/1.4 'Segoe UI', sans-serif;
  color: #666;
  margin: 0 0 5px;
}
#drop-sub {
  font: 12px/1.4 'Segoe UI', sans-serif;
  color: #aaa;
  margin: 0;
}
/* Drag-over highlight when a file is already loaded */
body.has-file #wrap.drag-over {
  outline: 2px dashed #4a90d9;
  outline-offset: -3px;
}

.saveas-note {
  font: 8pt 'Segoe UI', sans-serif;
  color: #999;
}

/* ── Error banner ───────────────────────────────────────────────── */
#error-banner {
  display: none;
  background: #fee2e2;
  border-bottom: 1px solid #fca5a5;
  padding: 4px 10px;
  font: 11px/1.4 'Segoe UI', sans-serif;
  color: #991b1b;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
#error-banner.visible { display: flex; }
#error-msg { flex: 1; }
#error-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: #991b1b;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
#error-close:hover { color: #7f1d1d; }

/* ── Loading overlay ────────────────────────────────────────── */
#loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  background: rgba(240,240,240,0.75);
}
body.loading-file #loading-overlay { display: flex; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #d0d0d0;
  border-top-color: #4a90d9;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Canvas toolbar (fit button) ────────────────────────────── */
#canvas-toolbar {
  position: absolute;
  top: 6px; right: 8px;
  z-index: 5;
  display: flex;
  gap: 4px;
  align-items: stretch;
}
/* Uniform sizing for every button in the canvas toolbar so flip/fit/measure
   all line up at the same height regardless of icon vs. text content. */
#canvas-toolbar > button {
  height: 28px;
  box-sizing: border-box;
  padding: 0 10px;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#canvas-toolbar #fit-btn { font-size: 14px; padding: 0 8px; }
#canvas-toolbar .measure-btn { min-width: 32px; }
#canvas-toolbar .canvas-toolbar-sep { align-self: center; }
/* Pill info (e.g. 3D origin readout) needs to match the 28px button height
   used in the canvas toolbars; the default .toolbar-pill height (22px)
   makes it shorter than its neighbours and visibly off-baseline. */
#canvas-toolbar .toolbar-pill,
#preview3d-toolbar .toolbar-pill {
  height: 28px;
  align-self: center;
  border-radius: 14px;
}
/* Visible-face flip button */
#flip-btn {
  background: rgba(255,255,255,0.82);
  border: 1px solid #c8c8c8;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  padding: 3px 7px;
  color: #005c8a;
  letter-spacing: 0.03em;
}
#flip-btn:hover { background: #fff; border-color: #999; color: #003f60; }
#flip-btn:disabled { display: none; }
#flip-btn.flip-btn-inside  { color: #7a4400; }  /* warm tone for inside face */
#flip-btn.flip-btn-outside { color: #005c8a; }  /* cool tone for outside face */

#fit-btn {
  background: rgba(255,255,255,0.82);
  border: 1px solid #c8c8c8;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 6px;
  color: #555;
}
#fit-btn:hover { background: #fff; border-color: #999; color: #222; }

/* ── Icon buttons (dark-mode toggle etc.) ────────────────────── */
.icon-btn {
  background: none;
  border: 1px solid #ccc;
  cursor: pointer;
  font-size: 14px;
  padding: 0 5px;
  border-radius: 3px;
  line-height: 1;
  color: #555;
}
.icon-btn:hover { background: rgba(0,0,0,0.07); border-color: #aaa; }

/* Shared account-menu component (viewer + admin) */
.account-menu-wrap { position: relative; display: inline-block; }
.account-menu-btn {
  min-width: 0;
  width: auto;
  text-align: left;
  padding: 0 10px;
  font: 8.5pt 'Segoe UI', sans-serif;
}
.account-menu-btn .btn-label { white-space: nowrap; }
.account-menu-popover {
  display: none;
  position: absolute;
  right: 0;
  top: 28px;
  min-width: 180px;
  width: max-content;
  max-width: min(320px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  z-index: 55;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  padding: 6px 0;
}
.account-menu-popover .item,
.account-menu-popover .account-menu-item,
.account-menu-popover .profile-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  background: transparent;
  border: 0;
  color: #333;
  text-decoration: none;
  font: 12px 'Segoe UI', sans-serif;
  cursor: pointer;
}
.account-menu-popover .item:hover,
.account-menu-popover .item:focus-visible,
.account-menu-popover .account-menu-item:hover,
.account-menu-popover .account-menu-item:focus-visible,
.account-menu-popover .profile-menu-item:hover,
.account-menu-popover .profile-menu-item:focus-visible {
  background: #eceff3;
  color: #222;
  outline: none;
}
.account-menu-popover .sep { height: 1px; background: #ddd; margin: 6px 0; }

/* Profile toggle button in file bar */
.profile-btn { font-weight: 600; font-size: 11px; min-width: 20px; }
.profile-btn.profile-artioscad { color: #FF7A2F; } /* keep orange — ArtiosCAD brand */
.profile-btn.profile-impact    { color: #CC0000; }
/* Units indicator button in file bar (read-only, always disabled) */
.units-btn { font-weight: 600; font-size: 11px; min-width: 28px; letter-spacing: 0.03em; }
.units-btn:disabled { opacity: 0.65; cursor: default; color: #555; }
.units-btn.units-inches { color: #7a4400; }
.units-btn.units-mm     { color: #005c8a; }
/* ── Panel toggle (between left & right panels) ────────────────── */
#panel-toggle {
  background: #e8e8e8;
  border: none;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
  width: 14px;
  min-width: 14px;
  font-size: 10px;
  cursor: pointer;
  color: #888;
  flex-shrink: 0;
  align-self: stretch;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#panel-toggle:hover { background: #d8d8d8; color: #333; }
#right-panel {
  transition: width 0.2s ease, min-width 0.2s ease;
}
/* Hide sidebar (and its toggle/handle) until a file is loaded */
body:not(.has-file) #right-panel,
body:not(.has-file) #panel-toggle,
body:not(.has-file) #resize-handle {
  display: none;
}
body.panel-collapsed #right-panel {
  width: 0;
  min-width: 0;
  border-left: none;
  overflow: hidden;
}
body.panel-collapsed #panel-toggle { border-right: none; }

/* ── Dark mode ────────────────────────────────────────────────── */
body.dark-mode { background: #1a1a1a; color: #ddd; }
body.dark-mode #file-bar  { background: #252525; border-bottom-color: #3a3a3a; }
body.dark-mode #file-name { color: #bbb; }
body.dark-mode #tab-bar   { background: #1e1e1e; border-bottom-color: #3a3a3a; }
body.dark-mode #tab-bar .tab         { color: #999; }
body.dark-mode #tab-bar .tab.active  { color: #c1272c; border-bottom-color: #c1272c; }
body.dark-mode #tab-bar .tab:hover:not(.active) { background: #2a2a2a; }
body.dark-mode #tab-bar .tab.needs-file-tab:disabled,
body.dark-mode #tab-bar .tab.feature-tab:disabled { color: #666; }
body.dark-mode #tab-bar .tab.needs-file-tab:disabled:hover,
body.dark-mode #tab-bar .tab.feature-tab:disabled:hover { background: none; }
body.dark-mode #right-panel   { background: #1e1e1e; border-left-color: #3a3a3a; }
body.dark-mode #panel-toggle  { background: #252525; border-color: #3a3a3a; color: #666; }
body.dark-mode #panel-toggle:hover { background: #2e2e2e; color: #aaa; }
body.dark-mode .section-header { background: #252525; border-bottom-color: #333; color: #bbb; }
body.dark-mode #drop-zone { background: #1a1a1a; }
body.dark-mode #drop-zone.drag-over { background: #1a2a3a; border-color: #4a90d9; }
body.dark-mode #drop-icon  { stroke: #444; }
body.dark-mode #drop-title { color: #666; }
body.dark-mode #drop-sub   { color: #444; }
body.dark-mode #hint { color: #555; }
body.dark-mode #zoom-pct { background: rgba(40,40,40,0.8); color: #888; border-color: #444; }
body.dark-mode #zoom-pct:hover { background: rgba(55,55,55,0.9); color: #ccc; }
body.dark-mode #fit-btn { background: rgba(40,40,40,0.8); border-color: #444; color: #888; }
body.dark-mode #fit-btn:hover { background: rgba(55,55,55,0.9); color: #ccc; }
body.dark-mode #zoom-actual-btn { background: rgba(40,40,40,0.8); border-color: #444; color: #888; }
body.dark-mode #zoom-actual-btn:hover { background: rgba(55,55,55,0.9); color: #ccc; }
body.dark-mode #flip-btn { background: rgba(40,40,40,0.8); border-color: #444; color: #40aadd; }
body.dark-mode #flip-btn:hover { background: rgba(55,55,55,0.9); color: #80ccee; }
body.dark-mode #flip-btn.flip-btn-inside  { color: #e08030; }
body.dark-mode #flip-btn.flip-btn-outside { color: #40aadd; }
body.dark-mode .icon-btn { color: #999; border-color: #555; }
body.dark-mode .icon-btn:hover { background: rgba(255,255,255,0.06); border-color: #777; }
body.dark-mode #ui-scale-btn .btn-label { color: #bbb; }
body.dark-mode .account-menu-popover,
body.admin-page .account-menu-popover {
  background: #2a2f35;
  border-color: #353b42;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
body.dark-mode .account-menu-popover .item,
body.dark-mode .account-menu-popover .account-menu-item,
body.dark-mode .account-menu-popover .profile-menu-item,
body.admin-page .account-menu-popover .item,
body.admin-page .account-menu-popover .account-menu-item,
body.admin-page .account-menu-popover .profile-menu-item {
  color: #e6e6e6;
}
body.dark-mode .account-menu-popover .item:hover,
body.dark-mode .account-menu-popover .item:focus-visible,
body.dark-mode .account-menu-popover .account-menu-item:hover,
body.dark-mode .account-menu-popover .account-menu-item:focus-visible,
body.dark-mode .account-menu-popover .profile-menu-item:hover,
body.dark-mode .account-menu-popover .profile-menu-item:focus-visible,
body.admin-page .account-menu-popover .item:hover,
body.admin-page .account-menu-popover .item:focus-visible,
body.admin-page .account-menu-popover .account-menu-item:hover,
body.admin-page .account-menu-popover .account-menu-item:focus-visible,
body.admin-page .account-menu-popover .profile-menu-item:hover,
body.admin-page .account-menu-popover .profile-menu-item:focus-visible {
  background: #353b42;
  color: #fff;
}
body.dark-mode .account-menu-popover .sep,
body.admin-page .account-menu-popover .sep { background: #353b42; }
body.dark-mode .text-pane  { color: #bbb; }
body.dark-mode .debug-pane { background: #111108; color: #cccc99; }
body.dark-mode .debug-tab-toolbar { background: #2a2a10; border-bottom-color: #4a4a20; }
body.dark-mode .debug-tab-label { color: #aa9940; }
body.dark-mode .debug-truncation-badge {
  color: #e3c37d;
  background: #3a321d;
  border-color: #6b5b2b;
}
body.dark-mode .debug-copy-btn { background: #1a1a08; border-color: #665500; color: #ccaa44; }
body.dark-mode .debug-copy-btn:hover { background: #2a2a10; }
body.dark-mode .summary-pane { color: #bbb; }
body.dark-mode .vis-item { color: #bbb; }
body.dark-mode #loading-overlay { background: rgba(26,26,26,0.75); }
body.dark-mode .inspector-row { border-bottom-color: #2a2a2a; color: #ccc; }
body.dark-mode .inspector-label { color: #888; }
body.dark-mode .insp-download-btn {
  background: #2f5f9f;
  border-color: #4f7fbf;
  color: #fff;
}
body.dark-mode .insp-download-btn:hover { background: #3b6fb5; border-color: #5a8bc9; }
body.dark-mode #inspector-close { color: #666; }
body.dark-mode #inspector-close:hover { color: #ccc; }
body.dark-mode #section-legend { border-top-color: #3a3a3a; }
body.dark-mode .legend-label { color: #bbb; }
body.dark-mode .legend-length { color: #666; }
body.dark-mode .saveas-row label,
body.admin-page #profile-update-dialog .saveas-row label { color: #bbb; }
body.dark-mode #saveas-dialog,
body.dark-mode #profile-update-dialog,
body.dark-mode #profile-password-dialog,
body.dark-mode #profile-api-keys-dialog,
body.dark-mode #profile-api-key-create-dialog,
body.admin-page #profile-update-dialog { background: #252525; border-color: #444; color: #ddd; }
body.dark-mode #saveas-title,
body.dark-mode #profile-update-title,
body.dark-mode #profile-password-title,
body.dark-mode #profile-api-keys-title,
body.dark-mode #profile-api-key-create-title,
body.admin-page #profile-update-title { color: #eee; }
body.dark-mode .saveas-row select,
body.dark-mode .saveas-row input,
body.admin-page #profile-update-dialog .saveas-row input { background: #333; border-color: #555; color: #ddd; }
body.dark-mode .profile-password-feedback,
body.admin-page .profile-password-feedback { color: #aaa; }
body.dark-mode .profile-password-feedback.ok,
body.admin-page .profile-password-feedback.ok { color: #8bcf90; }
body.dark-mode .profile-password-feedback.warn,
body.admin-page .profile-password-feedback.warn { color: #e3c37d; }
body.dark-mode .profile-password-feedback.error,
body.admin-page .profile-password-feedback.error { color: #ff8a8a; }
body.admin-page #profile-update-dialog #saveas-footer button { background: #333; border-color: #555; color: #ccc; }
body.admin-page #profile-update-dialog #saveas-footer button.saveas-primary { background: #1a5fa0 !important; border-color: #1a5fa0 !important; color: #fff !important; }
body.admin-page #profile-update-dialog #saveas-footer button.saveas-primary:hover { background: #2b6faf !important; }

#profile-menu-sep-main,
#profile-menu-sep-debug {
  height: 1px;
  background: #ddd;
  margin: 6px 0;
}
body.dark-mode #saveas-cancel { background: #333; border-color: #555; color: #ccc; }
body.dark-mode .saveas-primary { background: #1a5fa0; }
body.dark-mode #error-banner { background: #3b1212; border-bottom-color: #7f1d1d; color: #fca5a5; }
body.dark-mode #error-close  { color: #fca5a5; }

/* ── Canvas default cursor ───────────────────────────────────────── */
#wrap { cursor: crosshair; }

/* ── Resize handle (between panel-toggle and right-panel) ───────────── */
#resize-handle {
  width: 4px;
  min-width: 4px;
  flex-shrink: 0;
  align-self: stretch;
  cursor: ew-resize;
  background: transparent;
  transition: background 0.15s;
}
#resize-handle:hover { background: rgba(0,120,212,0.25); }
body.dark-mode #resize-handle:hover { background: rgba(74,158,255,0.3); }

/* ── Version badge ─────────────────────────────────────────────── */
.version-badge {
  font: 7.5pt 'Segoe UI', sans-serif;
  color: #aaa;
  flex-shrink: 0;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.version-badge:hover {
  color: #c1272c;
  text-decoration: underline;
}
body.dark-mode .version-badge { color: #555; }
body.dark-mode .version-badge:hover { color: #c1272c; }
body.dark-mode .debug-truncation-note,
body.admin-page .debug-truncation-note {
  color: #e3c37d;
  background: #3a321d;
  border-color: #6b5b2b;
}

/* ── Help modal ──────────────────────────────────────────────── */
#help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.35);
  align-items: center;
  justify-content: center;
}
#help-overlay.open { display: flex; }
#help-dialog {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 16px 20px;
  min-width: 300px;
  max-width: 420px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  font: 9pt 'Segoe UI', sans-serif;
}
#help-title {
  font: 600 11pt 'Segoe UI', sans-serif;
  margin-bottom: 12px;
  color: #222;
}
#help-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
#help-table td { padding: 4px 8px; }
#help-table td:first-child {
  font: 8.5pt Consolas, monospace;
  background: #f4f4f4;
  border-radius: 3px;
  color: #c1272c;
  white-space: nowrap;
  width: 1%;
}
#help-table tr + tr td { border-top: 1px solid #f0f0f0; }
#help-table td:last-child { padding-left: 14px; color: #444; }
#help-links-block { margin-top: 10px; margin-bottom: 12px; }
#help-footer { text-align: right; margin-top: 8px; }
#help-close {
  padding: 3px 14px;
  font: 8.5pt 'Segoe UI', sans-serif;
  cursor: pointer;
  background: #c1272c;
  color: #fff;
  border: none;
  border-radius: 3px;
}
#help-close:hover { background: #a01e23; }
body.dark-mode #help-dialog { background: #252525; border-color: #444; }
body.dark-mode #help-title { color: #eee; }
body.dark-mode #help-table td:first-child { background: #333; color: #c1272c; }
body.dark-mode #help-table td:last-child { color: #bbb; }
body.dark-mode #help-table tr + tr td { border-top-color: #333; }

/* ── Guided tour overlay ──────────────────────────────────────────────── */
#tour-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 12000;
}
#tour-highlight {
  position: fixed;
  border: 2px solid #c1272c;
  border-radius: 6px;
  /* Spotlight effect: dim everything outside the highlighted target. */
  box-shadow:
    0 0 0 4px rgba(193,39,44,0.2),
    0 0 0 9999px rgba(0,0,0,0.42);
  z-index: 12001;
  pointer-events: none;
}
#tour-pop {
  position: fixed;
  max-width: 320px;
  background: #fff;
  border: 1px solid #c8c8c8;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 12002;
  font: 12px 'Segoe UI', sans-serif;
  color: #222;
}
#tour-pop .tour-head { padding: 10px 12px 6px; font-weight: 600; }
#tour-pop .tour-body { padding: 0 12px 10px; line-height: 1.4; }
#tour-pop .tour-foot { display:flex; justify-content:space-between; align-items:center; border-top:1px solid #eee; padding:8px 10px; }
#tour-pop .tour-foot button { border:1px solid #bbb; border-radius:4px; background:#f0f0f0; padding:4px 10px; cursor:pointer; font:12px 'Segoe UI', sans-serif; }
#tour-pop .tour-foot button.primary { background:#c1272c; border-color:#c1272c; color:#fff; }
body.dark-mode #tab-bar .tab:not(:last-child) { border-right-color: rgba(255,255,255,0.08); }
  font-style: italic;
  display: none;
}
#saveas-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
#saveas-footer button {
  padding: 3px 16px;
  font: 9pt 'Segoe UI', sans-serif;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #f0f0f0;
  cursor: pointer;
}
#saveas-footer button:hover { background: #e0e0e0; }
.saveas-primary {
  background: #c1272c !important;
  color: #fff !important;
  border-color: #a01e23 !important;
}
.saveas-primary:hover { background: #a01e23 !important; }
.saveas-primary:disabled { background: #aaa !important; border-color: #aaa !important; cursor: default !important; }


/* ── Internal layers label ─────────────────────────────────────────────────── */
#internal-layers-label {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  font: 8.5pt 'Segoe UI', sans-serif;
  color: #444;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
#internal-layers-label input { cursor: pointer; margin: 0; }
body.has-file #internal-layers-label { display: flex !important; }
#internal-layers-label.disabled { opacity: 0.45; cursor: not-allowed; }
#internal-layers-label.disabled input { cursor: not-allowed; }
body.dark-mode #internal-layers-label { color: #aaa; }
body.dark-mode .profile-btn.profile-artioscad { color: #6666FF; }
body.dark-mode .profile-btn.profile-impact    { color: #FF5555; }
body.dark-mode .units-btn:disabled { color: #999; }
body.dark-mode .units-btn.units-inches { color: #e08030; }
body.dark-mode .units-btn.units-mm     { color: #40aadd; }

/* ── Debug Archive dialog ─────────────────────────────────────────────────── */
#debug-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
#debug-overlay.open { display: flex; }

#debug-dialog {
  background: #fff;
  border: 1px solid #bbb;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  border-radius: 4px;
  padding: 18px 20px 14px;
  width: 420px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#debug-title {
  font: 600 10pt 'Segoe UI', sans-serif;
  color: #222;
  margin-bottom: 2px;
}

#debug-includes {
  font: 8.5pt 'Segoe UI', sans-serif;
  color: #444;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 3px;
  padding: 6px 10px;
}
#debug-includes ul {
  margin: 4px 0 0 0;
  padding-left: 16px;
  color: #555;
}
#debug-includes li { margin: 2px 0; }

.debug-field { display: flex; flex-direction: column; gap: 3px; }
.debug-field label {
  font: 8.5pt 'Segoe UI', sans-serif;
  color: #444;
}
.debug-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 8.5pt 'Segoe UI', sans-serif;
  color: #444;
  cursor: pointer;
}
.debug-checkbox-label input[type="checkbox"] { margin: 0; cursor: pointer; }
.field-optional { color: #999; font-style: italic; }
.debug-field textarea, .debug-field input[type="text"] {
  font: 9pt 'Segoe UI', sans-serif;
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 4px 6px;
  resize: vertical;
}
.debug-field textarea:focus, .debug-field input[type="text"]:focus {
  outline: none;
  border-color: #c1272c;
  box-shadow: 0 0 0 2px rgba(193,39,44,0.15);
}
.debug-field input[type="file"] {
  font: 8.5pt 'Segoe UI', sans-serif;
  border: 1px solid #bbb;
  border-radius: 3px;
  padding: 3px 4px;
  background: #fff;
  cursor: pointer;
}

#debug-status {
  font: 8.5pt 'Segoe UI', sans-serif;
  min-height: 1.2em;
}

#debug-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#debug-actions { display: flex; gap: 6px; flex-wrap: wrap; }
#debug-footer button, #debug-actions button {
  padding: 3px 14px;
  font: 9pt 'Segoe UI', sans-serif;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #f0f0f0;
  cursor: pointer;
}
#debug-footer button:hover, #debug-actions button:hover { background: #e0e0e0; }
.debug-primary {
  background: #c1272c !important;
  color: #fff !important;
  border-color: #a01e23 !important;
}
.debug-primary:hover { background: #a01e23 !important; }
.debug-secondary {
  background: #f0f0f0;
}
button:disabled { opacity: 0.55; cursor: default !important; }

.debug-note {
  font: 8pt 'Segoe UI', sans-serif;
  color: #777;
  margin: 0;
  line-height: 1.4;
}
.debug-note code { background: #f0f0f0; padding: 1px 4px; border-radius: 2px; }

/* Dark mode for debug dialog */
body.dark-mode #debug-dialog { background: #252525; border-color: #444; }
body.dark-mode #debug-title { color: #eee; }
body.dark-mode #debug-includes { background: #2a2a2a; border-color: #444; color: #bbb; }
body.dark-mode #debug-includes ul { color: #aaa; }
body.dark-mode .debug-field label { color: #bbb; }
body.dark-mode .debug-checkbox-label { color: #bbb; }
body.dark-mode .debug-field textarea,
body.dark-mode .debug-field input[type="text"],
body.dark-mode .debug-field input[type="file"] {
  background: #1e1e1e; border-color: #555; color: #ddd;
}
body.dark-mode #debug-footer button,
body.dark-mode #debug-actions button { background: #333; border-color: #555; color: #ccc; }
body.dark-mode #debug-footer button:hover,
body.dark-mode #debug-actions button:hover { background: #444; }
body.dark-mode .debug-note { color: #888; }
body.dark-mode .debug-note code { background: #333; }

/* ── Analysis prompt modal ─────────────────────────────────────────────── */
#analysis-prompt-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 220;
  background: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
}
#analysis-prompt-overlay.open { display: flex; }
#analysis-prompt-dialog {
  width: 420px;
  max-width: 92vw;
  background: #fff;
  border: 1px solid #bbb;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  padding: 16px 18px 14px;
}
#analysis-prompt-title {
  font: 600 10pt 'Segoe UI', sans-serif;
  color: #222;
  margin-bottom: 8px;
}
#analysis-prompt-body {
  font: 9pt 'Segoe UI', sans-serif;
  color: #444;
  white-space: pre-wrap;
  margin-bottom: 10px;
}
#analysis-prompt-suppress-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 8.5pt 'Segoe UI', sans-serif;
  color: #555;
  margin-bottom: 12px;
  cursor: pointer;
}
#analysis-prompt-suppress-label input[type="checkbox"] { margin: 0; cursor: pointer; }
#analysis-prompt-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
#analysis-prompt-actions button {
  padding: 3px 14px;
  font: 9pt 'Segoe UI', sans-serif;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #f0f0f0;
  cursor: pointer;
}
#analysis-prompt-actions button:hover { background: #e0e0e0; }
#analysis-prompt-actions .analysis-primary {
  background: #c1272c;
  color: #fff;
  border-color: #a01e23;
}
#analysis-prompt-actions .analysis-primary:hover { background: #a01e23; }
body.dark-mode #analysis-prompt-dialog { background: #252525; border-color: #444; }
body.dark-mode #analysis-prompt-title { color: #eee; }
body.dark-mode #analysis-prompt-body { color: #bbb; }
body.dark-mode #analysis-prompt-suppress-label { color: #aaa; }
body.dark-mode #analysis-prompt-actions button { background: #333; border-color: #555; color: #ccc; }
body.dark-mode #analysis-prompt-actions button:hover { background: #444; }
body.dark-mode #analysis-prompt-actions .analysis-primary { background: #c1272c; color: #fff; border-color: #a01e23; }

/* ── Measure tools ─────────────────────────────────────────────── */
.measure-btn {
  background: rgba(255,255,255,0.82);
  border: 1px solid #c8c8c8;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  padding: 3px 7px;
  color: #555;
  min-width: 26px;
}
.measure-btn:hover { background: #fff; border-color: #999; color: #222; }
.measure-btn.active {
  background: #2a78c8;
  border-color: #1a5896;
  color: #fff;
}
#btn-pick-3d-origin.active {
  background: #2a78c8;
  border-color: #1a5896;
  color: #fff;
}

/* ── 3D Preview tab ─────────────────────────────────────────────────────── */
/* The 3D tab uses the .canvas-toolbar *class* (not the #canvas-toolbar id).
   Give it a normal docked toolbar look + proper layout for the viewer area. */
#tab-preview3d.tab-content { padding: 0; }
#tab-preview3d .canvas-toolbar {
  position: static;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #f5f5f5;
  border-bottom: 1px solid #d0d0d0;
}
#tab-preview3d .canvas-toolbar > button {
  height: 28px; box-sizing: border-box; padding: 0 10px;
  font-size: 12px; line-height: 1; border-radius: 4px;
  border: 1px solid #b8b8b8; background: #fff; color: #222; cursor: pointer;
}
#tab-preview3d .canvas-toolbar > button:hover:not(:disabled) { border-color: #888; background: #f0f0f0; }
#tab-preview3d .canvas-toolbar > button:disabled { opacity: 0.5; cursor: default; }
body.dark-mode #tab-preview3d .canvas-toolbar { background: #1e1e1e; border-bottom-color: #333; }
body.dark-mode #tab-preview3d .canvas-toolbar > button {
  background: #2a2a2a; border-color: #444; color: #ddd;
}
body.dark-mode #tab-preview3d .canvas-toolbar > button:hover:not(:disabled) { background: #353535; }

#preview3d-wrap {
  flex: 1 1 auto;
  position: relative;
  min-height: 300px;
  background: #1d1f23;
}
body:not(.dark-mode) #preview3d-wrap { background: #f0f0f0; }
#preview3d-empty { padding: 24px; }

/* Compact text pill for toolbar info (format, origin, etc.). Unlike
   .toolbar-grain (which is sized for a single 16px icon) this expands
   horizontally with its content and never wraps. */
.toolbar-pill {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 8px;
  font-size: 11px; line-height: 1; white-space: nowrap;
  border-radius: 11px;
  background: #e8e8e8; color: #333; border: 1px solid #ccc;
}
body.dark-mode .toolbar-pill { background: #2a2a2a; color: #ddd; border-color: #444; }

/* Service-state pill: grey unknown, amber checking/warming, green ok, red down. */
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px;
  font-size: 11px; line-height: 1; border-radius: 11px;
  background: #e8e8e8; color: #444; border: 1px solid #ccc;
}
.svc-state::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: #999; box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}
.svc-state.state-checking { background: #fff4d6; color: #6a4a00; border-color: #e6c97a; }
.svc-state.state-checking::before { background: #e0a000; animation: svc-pulse 1.2s ease-in-out infinite; }
.svc-state.state-ok        { background: #e1f4e1; color: #1f5a1f; border-color: #9ed09e; }
.svc-state.state-ok::before        { background: #2bb24c; }
.svc-state.state-warn      { background: #fff0e0; color: #6e3500; border-color: #f0b078; }
.svc-state.state-warn::before      { background: #ee7a17; }
.svc-state.state-down      { background: #fde2e2; color: #7a1818; border-color: #e69a9a; }
.svc-state.state-down::before      { background: #d22b2b; }
@keyframes svc-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
body.dark-mode .svc-state { background: #2a2a2a; color: #bbb; border-color: #444; }
body.dark-mode .svc-state.state-checking { background: #3a2f00; color: #ffd877; border-color: #6a5400; }
body.dark-mode .svc-state.state-ok       { background: #14361b; color: #9ce8a8; border-color: #2f6f3a; }
body.dark-mode .svc-state.state-warn     { background: #3a2310; color: #ffc99a; border-color: #7a4a1f; }
body.dark-mode .svc-state.state-down     { background: #3a1414; color: #ff9a9a; border-color: #7a2424; }

/* Pick-origin banner shown over the 2D preview when prompting the user. */
.pick-origin-banner {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  z-index: 10;
  background: #2a78c8; color: #fff;
  padding: 8px 14px; border-radius: 4px; font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  display: flex; align-items: center; gap: 12px;
}
.pick-origin-banner button {
  background: rgba(255,255,255,0.18); color: #fff;
  border: 1px solid rgba(255,255,255,0.4); border-radius: 3px;
  padding: 3px 8px; font-size: 12px; cursor: pointer;
}
.pick-origin-banner button:hover { background: rgba(255,255,255,0.3); }
.pick-origin-banner .face-choice.active {
  background: #fff; color: #2a78c8; border-color: #fff; font-weight: 600;
}
#pick-origin-face-choices { display: inline-flex; gap: 4px; }
.canvas-toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 16px;
  background: #c8c8c8;
  margin: 0 4px;
}
body.dark-mode .measure-btn {
  background: rgba(40,40,40,0.8);
  border-color: #444;
  color: #aaa;
}
body.dark-mode .measure-btn:hover { background: rgba(55,55,55,0.9); color: #eee; }
body.dark-mode .measure-btn.active { background: #2a78c8; color: #fff; border-color: #1a5896; }
body.dark-mode .canvas-toolbar-sep { background: #444; }

/* SVG overlay group */
.measure-overlay {
  color: #c8302e; /* used by stroke="currentColor" / fill="currentColor" */
  pointer-events: none;
}
/* Committed state: keep the same red as live preview — only snap markers
   (circles) grey out so they fade into the background. */
.measure-overlay .measure-committed { color: #c8302e; }
.measure-overlay .measure-committed .measure-snap { color: #aaa; }
body.dark-mode .measure-overlay { color: #ff7a55; }
body.dark-mode .measure-overlay .measure-committed { color: #ff7a55; }
body.dark-mode .measure-overlay .measure-committed .measure-snap { color: #888; }

/* Picked / selected line during live hover — bright cyan so the reference
   line stands out clearly while measuring.  No CSS filter (performance). */
.measure-overlay .measure-pickedline {
  stroke: #00ffff !important;
  stroke-width: 6 !important;
}
/* Dashed committed line — used for both picked reference lines and the
   p2p span after a measurement is placed.  Inherits currentColor (red). */
.measure-overlay .measure-dashed {
  stroke-dasharray: 6 4 !important;
  stroke-width: 3 !important;
}

/* Floating HUD readout */
#measure-hud {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  background: rgba(252,252,252,0.96);
  border: 1px solid #b8b8b8;
  border-left: 3px solid #2a78c8;
  border-radius: 3px;
  padding: 5px 8px;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 11px;
  color: #222;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  min-width: 130px;
  line-height: 1.45;
}
#measure-hud .row { white-space: nowrap; }
#measure-hud .row b { font-weight: 700; }
#measure-hud .row.len { border-top: 1px solid #ddd; margin-top: 2px; padding-top: 2px; }
#measure-hud .sep { border-top: 1px solid #ddd; margin: 3px 0; }
#measure-hud .prompt { font-weight: 700; color: #2a78c8; }
#measure-hud .hint   { font-size: 10px; color: #888; margin-top: 2px; }
#measure-hud.parallel { border-left-color: #2a78c8; }
#measure-hud.parallel .prompt { color: #2a78c8; }
#measure-hud.warn { border-left-color: #d08000; }
#measure-hud.warn .prompt, #measure-hud.warn .hint { color: #d08000; }
body.dark-mode #measure-hud {
  background: rgba(35,35,35,0.96);
  border-color: #555;
  color: #eee;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
body.dark-mode .vis-subitem-btn { background: #2b2b2b; border-color: #555; color: #bbb; }
body.dark-mode .vis-subitem-btn:hover { border-color: #c1272c; color: #ff8a8e; background: #333; }
body.dark-mode .vis-subitem-btn.selected { border-color: #c1272c; background: #412326; color: #ffd5d8; }
body.dark-mode #measure-hud .row.len { border-top-color: #444; }
body.dark-mode #measure-hud .sep { border-top-color: #444; }
body.dark-mode #measure-hud .hint { color: #999; }

/* Sticky result label — pinned to the design-space midpoint of the last
   committed measurement until the next pick or tool deactivation. */
.measure-result {
  position: fixed;
  z-index: 1001;
  pointer-events: none;
  background: rgba(255,255,255,0.97);
  border: 1px solid #b8b8b8;
  border-left: 3px solid #c8302e;
  border-radius: 3px;
  padding: 3px 7px;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 600;
  color: #222;
  box-shadow: 0 2px 6px rgba(0,0,0,0.22);
  white-space: nowrap;
}
.measure-result b { font-weight: 700; margin-right: 3px; }
.measure-result.parallel { border-left-color: #2a78c8; }
body.dark-mode .measure-result {
  background: rgba(30,30,30,0.97);
  border-color: #555;
  color: #eee;
  box-shadow: 0 2px 8px rgba(0,0,0,0.65);
}

/* Measure status banner — pinned to the bottom so it stays out of the way. */
#measure-status {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(42,120,200,0.92);
  color: #fff;
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  pointer-events: none;
  max-width: 70%;
  text-align: center;
}
body.dark-mode #measure-status { box-shadow: 0 2px 8px rgba(0,0,0,0.6); }

/* ── Touch / coarse-pointer ergonomics ─────────────────────────────────── */
/* On touch devices buttons need bigger hit targets and the HUD/result label
   need to sit clear of fat fingers. The viewer already uses Pointer Events
   so gestures (pinch, pan, double-tap, long-press) work everywhere. */
@media (pointer: coarse) {
  #canvas-toolbar > button,
  #canvas-toolbar .measure-btn,
  #canvas-toolbar #zoom-pct,
  #canvas-toolbar #fit-btn,
  #canvas-toolbar #zoom-actual-btn {
    min-height: 34px;
    min-width: 34px;
    font-size: 13px;
    padding: 0 10px;
  }
  #canvas-toolbar { gap: 6px; padding: 4px 6px; }
  #measure-hud   { font-size: 13px; padding: 6px 10px; }
  #measure-result{ font-size: 13px; padding: 4px 8px; }
  #measure-status{ font-size: 13px; padding: 6px 12px; bottom: 10px; }
  #internal-layers-label { min-height: 30px; padding: 4px 6px; }
  #internal-layers-chk { width: 18px; height: 18px; }
}

/* ── Image buttons (Lens icon set) ─────────────────────────────── */
.img-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.img-btn > img { width: 18px; height: 18px; display: block; pointer-events: none; }
.measure-btn.img-btn { padding: 4px 8px; }
.measure-btn.img-btn > img { width: 16px; height: 16px; }
#fit-btn.img-btn { padding: 4px 8px; }
#fit-btn.img-btn > img { width: 16px; height: 16px; }
#browse-btn.img-btn, #saveas-btn.img-btn { padding: 5px 14px 5px 12px; font-size: 12px; white-space: nowrap; flex: 0 0 auto; width: auto; min-width: 0; }
#browse-btn.img-btn .btn-label, #saveas-btn.img-btn .btn-label { white-space: nowrap; }
#profile-menu-btn { font-size: 12px; font-family: 'Segoe UI', sans-serif; }
#profile-menu-btn .btn-label { white-space: nowrap; }
#profile-menu-user {
  padding: 6px 10px;
  color: #666;
  font: 12px 'Segoe UI', sans-serif;
  cursor: default;
  user-select: none;
}
body.dark-mode #profile-menu-user { color: #9aa0a6; }
/* Visibility rules (.web-only/.needs-file) toggle display: initial !important,
   which collapses the .img-btn flex layout. Re-assert inline-flex when visible. */
body.context-web .img-btn.web-only:not(.needs-file),
body.has-file .img-btn.needs-file:not(.web-only),
body.context-web.has-file .img-btn.web-only.needs-file { display: inline-flex !important; }
.measure-btn.active.img-btn > img { filter: invert(1) brightness(2); }
body.dark-mode .img-btn > img { filter: invert(0.85); }
body.dark-mode .measure-btn.active.img-btn > img { filter: none; }

/* ── Profile pill (replaces single-letter A/I) ─────────────────── */
.profile-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid #ccc; border-radius: 11px;
  padding: 2px 8px 2px 6px; cursor: pointer; line-height: 1;
  font-size: 11px; font-weight: 600; color: #333;
}
.profile-pill:hover { background: rgba(0,0,0,0.06); border-color: #888; }
.profile-pill .profile-swatch {
  width: 10px; height: 10px; border-radius: 50%;
  background: #c1272c; border: 1px solid rgba(0,0,0,0.2);
}
.profile-pill.profile-impact    .profile-swatch { background: #cc0000; }
.profile-pill.profile-artioscad .profile-swatch { background: #FF7A2F; }
body.dark-mode .profile-pill { color: #ddd; border-color: #555; }
body.dark-mode .profile-pill:hover { background: rgba(255,255,255,0.06); border-color: #888; }

/* ── Canvas corner overlays (units + flute/grain) ──────────────── */
.canvas-corner {
  position: absolute; z-index: 5;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px; font-weight: 600; color: #333;
  pointer-events: none;
  user-select: none;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.canvas-corner.corner-tl { top: 8px; left: 8px; }
.canvas-corner.corner-tr { top: 8px; right: 8px; padding: 3px; }
.canvas-corner.corner-bl { bottom: 8px; left: 8px; }
.canvas-corner.corner-br { bottom: 8px; right: 8px; padding: 3px; }
#corner-grain > img { width: 20px; height: 20px; display: block; }
#corner-grain.grain-horizontal > img { transform: rotate(90deg); }
body.dark-mode .canvas-corner {
  background: rgba(30,30,30,0.85);
  border-color: rgba(255,255,255,0.15);
  color: #ddd;
}
body.dark-mode #corner-grain > img { filter: invert(0.9); }

/* ── Inline toolbar grain indicator (next to Inside/Outside) ────── */
.toolbar-grain {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; width: 30px; padding: 4px 6px;
  box-sizing: border-box;
  border: 1px solid #ccc; border-radius: 3px;
  background: rgba(255,255,255,0.6);
  vertical-align: middle;
}
.toolbar-grain > img { width: 16px; height: 16px; display: block; pointer-events: none; }
.toolbar-grain.grain-horizontal > img { transform: rotate(90deg); }
body.dark-mode .toolbar-grain { background: rgba(255,255,255,0.06); border-color: #555; }
body.dark-mode .toolbar-grain > img { filter: invert(0.85); }

/* The grain indicator is a <span>, but it carries .needs-file. The visibility
   rule (display: initial !important) would override its inline-flex layout
   once a file loads, so re-assert it explicitly when shown. */
body.has-file .toolbar-grain.needs-file { display: inline-flex !important; }


