/* Theorymaker: minimal layout + splitter + light typography */

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: #fff;
  /* Page layout: navbar (top) + main (fills) + footer (bottom) */
  display: flex;
  flex-direction: column;
}

/* -----------------------------
   Navbar brand/title styling
   ----------------------------- */

.tm-brand {
  /* Purpose: make the "theorymaker" brand larger + more modern without affecting the rest of Bootstrap typography */
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-weight: 700; /* match loaded weights; keep it crisp */
  font-size: clamp(1.25rem, 1.05rem + 0.9vw, 1.9rem);
  letter-spacing: -0.02em;
}

/* -----------------------------
   Intro.js: make the tour feel Bootstrap-native
   ----------------------------- */

.tm-intro-tooltip.introjs-tooltip {
  /* Bigger tooltip for desktop, but still clamps on small screens */
  width: 520px;
  max-width: calc(100vw - 32px);
  font-size: 150%; /* 50% larger tour text overall */
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
}

.tm-intro-tooltip .introjs-tooltiptext {
  font-size: 1em;
  line-height: 1.4;
}

/* Footer/button bar layout: left = don't-show checkbox, right = nav buttons */
.tm-intro-tooltip .introjs-tooltipbuttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tm-intro-tooltip .tm-intro-footer {
  margin-right: auto; /* push the buttons to the right */
}

/* Bootstrap's .small would shrink tour text; keep it consistent inside the tour */
.tm-intro-tooltip .small {
  font-size: 1em;
}

/* Make footer controls (Back/Next + Don't show again) smaller than the main tour text */
.tm-intro-tooltip .introjs-tooltipbuttons,
.tm-intro-tooltip .introjs-tooltipbuttons .introjs-button,
.tm-intro-tooltip .tm-intro-footer .form-check-label {
  font-size: 0.72em;
}

.tm-intro-tooltip .tm-intro-footer .form-check-input {
  transform: scale(0.9);
  transform-origin: left center;
}

/* Make "Skip" act as a small close button */
.tm-intro-tooltip .introjs-skipbutton {
  text-decoration: none;
  color: #6c757d; /* Bootstrap secondary */
  font-weight: 700;
  font-size: 1.25em;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
}

.tm-intro-tooltip .introjs-skipbutton:hover {
  background: rgba(108, 117, 125, 0.12);
  color: #495057;
}

.tm-intro-tooltip .introjs-button {
  border-radius: 8px;
  font-size: 1em;
}

/* Main area fills the remaining viewport between navbar and footer */
.tm-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: row;
  min-height: 0;
}

/* Left editor panel (resizable) */
.tm-left {
  flex-shrink: 0; /* don't let Templates/Help content squeeze the editor panel */
  /* Default width: match the Styles drawer (so the left panel feels consistent). */
  width: 520px;
  min-width: 240px;
  max-width: 75%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px dotted gray;
}

@media (min-width: 992px) {
  .tm-left {
    width: 600px; /* match #tm-style-modal desktop width */
  }
}

.tm-panel-header {
  flex: 0 0 auto;
}

.tm-chat-input {
  /* Multi-line prompt: grows via JS on focus/input */
  resize: none;
  overflow: hidden;
  line-height: 1.25;
}

.tm-chat-input::placeholder {
  /* Make placeholder a bit lighter + italic (without affecting typed text) */
  color: #6c757d; /* Bootstrap "secondary" - darker */
  font-style: italic;
}

/* Footer icons (CC / GitHub / favicon) */
.tm-footer-icons i {
  font-size: 18px;
  line-height: 1;
}

.tm-footer-favicon {
  width: 18px;
  height: 18px;
  display: block;
}

.tm-footer-carousel {
  /* Purpose: rotating footer message (subtle discoverability) */
  min-width: 220px;
  max-width: min(820px, 70vw);
}

.tm-footer-carousel-icon {
  /* Purpose: icon slot (image or emoji) */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.tm-footer-carousel-icon img {
  width: 18px;
  height: 18px;
  display: block;
  border-radius: 3px;
}

.tm-footer-carousel-text {
  /* Purpose: keep footer tidy */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-footer-carousel-site {
  /* Purpose: only the site name is clickable, with black underline */
  color: inherit;
  text-decoration: underline;
  text-decoration-color: #000;
  text-underline-offset: 2px;
}

.tm-footer-carousel-site:hover {
  color: inherit;
  text-decoration-thickness: 2px;
}

.tm-fade-swap {
  transition: opacity 260ms ease;
}

.tm-fade-swap.tm-fade-out {
  opacity: 0;
}

.tm-editor-wrap {
  /* Editor section content: header + Ace editor fill remaining space */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tm-editor {
  flex: 1 1 auto;
  min-height: 220px; /* ensure the editor is visibly editable when disclosed */
  margin: 12px; /* space around the editor block */
  border: 1px solid #e9ecef;
  border-radius: 8px;
}

/* Ace editor: force a very light gray background (theme-override) */
.tm-editor.ace_editor,
.tm-editor.ace_editor .ace_scroller {
  background: #f8f9fa; /* Bootstrap "light" */
}

/* -----------------------------
   Recommended colour swatches (shown on-demand beside <input type="color">)
   ----------------------------- */
.tm-color-swatches {
  /* Purpose: compact "stripe" of quick-pick colours */
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap; /* keep usable on narrow drawers */
}

.tm-color-swatches-popover {
  /* Purpose: shared swatch strip that appears only when a colour input is clicked */
  position: fixed;
  z-index: 2500; /* keep above drawers/toolbars/overlays */
  padding: 4px 6px;
  background: #fff;
  border: 1px solid #dee2e6; /* Bootstrap border */
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  max-width: 190px; /* keep it tidy; wrap into rows */
  gap: 3px; /* slightly tighter than default */
}

.tm-color-input-wrap {
  /* Purpose: keep a colour input + swatch trigger button on one line */
  display: inline-flex;
  align-items: center;
  gap: 2px; /* keep picker + palette button close together */
  padding: 2px;
  background: #fff;
  border: 1px solid #ced4da; /* Bootstrap input border */
  border-radius: 0.375rem; /* Bootstrap default radius */
}

.tm-color-swatch-trigger {
  /* Purpose: tiny palette button that opens the swatch popover (without opening native picker) */
  padding: 2px 4px;
  line-height: 1;
  border: 0; /* border is on the wrapper */
}

.tm-color-input-wrap input[type="color"].form-control-color {
  /* Purpose: avoid double borders; wrapper provides the border */
  border: 0;
  box-shadow: none;
}

.tm-color-input-wrap:focus-within {
  /* Purpose: mimic Bootstrap focus ring for the combined control */
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.tm-color-swatch {
  /* Purpose: tiny square button with just background colour */
  width: 18px;
  height: 14px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 3px;
  background: transparent;
}

.tm-color-swatch:hover {
  border-color: #0d6efd; /* Bootstrap primary */
}

.tm-color-swatch:focus {
  outline: 2px solid rgba(13, 110, 253, 0.35);
  outline-offset: 1px;
}

.tm-color-swatch-sep {
  width: 6px;
  height: 12px;
  border-left: 1px solid #ced4da; /* Bootstrap border */
  margin: 0 2px;
}

.tm-color-swatch-break {
  /* Purpose: force a new row inside the swatch flex strip */
  flex-basis: 100%;
  height: 0;
}

/* Splitter */
.tm-splitter {
  width: 14px; /* wider grab area for resizing editor/diagram */
  cursor: col-resize;
  background: #f6f6f6;
  border-left: 1px solid #e5e5e5;
  border-right: 1px solid #e5e5e5;
}

.tm-splitter:hover {
  background: #efefef;
}

/* Right panel */
.tm-right {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tm-tabs {
  flex: 0 0 auto;
  user-select: none;
}

.tm-tab {
  color: #444;
  text-decoration: none;
  font-weight: 600;
  padding: 0 2px;
}

.tm-tab.active {
  color: #0d6efd; /* Bootstrap primary */
}

/* Styles drawer: make direction arrows big/bold for quick scanning */
#tm-style-direction-btns > button.btn {
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1;
  padding-left: 0.55rem;
  padding-right: 0.55rem;
}

.tm-right-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.tm-tab-panel {
  height: 100%;
  min-height: 0;
}

.tm-viz-wrap {
  height: calc(100% - 56px); /* keep existing right-panel header height assumption */
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0; /* allow flex children to shrink; prevents horizontal overflow pushing panel */
  position: relative; /* anchor diagram UI */
}

/* Quick link drawer: slides in from the far left of the viewport, but stops flush against the diagram's left edge */
.tm-viz-drawer {
  --tm-viz-drawer-w: 360px;
  --tm-viz-drawer-open-x: 0px; /* set by JS so right edge touches diagram */
  --tm-viz-drawer-top: 0px; /* set by JS to align with diagram panel */
  --tm-viz-drawer-h: 100vh; /* set by JS to align with diagram panel */
  position: fixed;
  top: var(--tm-viz-drawer-top);
  left: 0;
  height: var(--tm-viz-drawer-h);
  width: var(--tm-viz-drawer-w);
  max-width: min(420px, 92vw);
  background: #fff;
  border-right: 1px solid #e9ecef;
  z-index: 200; /* above left panel; should not overlap diagram due to JS positioning */
  overflow: auto;
  /* Strong shadow so the drawer stands out over the left panel */
  box-shadow: -18px 0 32px rgba(0, 0, 0, 0.22), -6px 0 12px rgba(0, 0, 0, 0.12);
  transform: translateX(-100%); /* start offscreen at far left */
  transition: transform 180ms ease;
  pointer-events: auto;
}

.tm-viz-drawer.tm-open {
  transform: translateX(var(--tm-viz-drawer-open-x));
}

.tm-viz-toolbar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
  user-select: none;
}

.tm-viz-hint-wrap {
  /* Purpose: compact info callout beside the toolbar buttons */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 6px 10px;
  padding-right: 40px; /* room for the dismiss X + extra spacing from text */
  border-radius: 10px;
  border: 1px solid #b6d4fe; /* Bootstrap-ish info */
  background: #e7f1ff;
  max-width: min(640px, 55vw);
  position: relative; /* anchor dismiss X */
}

.tm-viz-hint-dismiss {
  /* Purpose: subtle dismiss X (session-only) */
  position: absolute;
  top: 6px;
  right: 8px;
  opacity: 0.45;
  transform: scale(0.6); /* ~30% smaller than before */
}

.tm-viz-hint-wrap:hover .tm-viz-hint-dismiss,
.tm-viz-hint-dismiss:focus {
  opacity: 0.75;
}

.tm-viz-hint {
  /* Purpose: short guidance line */
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-viz-status {
  /* Purpose: transient status line (may be empty) */
  display: block;
}

@keyframes tm-callout-pulse {
  0% {
    border-color: #b6d4fe;
  }
  60% {
    border-color: #0b5ed7; /* darker, Bootstrap-ish */
  }
  100% {
    border-color: #b6d4fe;
  }
}

.tm-callout-pulse {
  /* Purpose: draw attention to callout on load / status changes */
  animation: tm-callout-pulse 700ms ease-out;
}

@keyframes tm-callout-pulse-slow {
  /* Purpose: very gentle "breathing" pulse for the hint callout on initial load */
  0%,
  100% {
    border-color: #b6d4fe;
  }
  50% {
    border-color: #6ea8fe; /* slightly darker */
  }
}

.tm-callout-pulse-slow {
  /* Purpose: slow repeating pulse over ~15s */
  animation: tm-callout-pulse-slow 7.5s ease-in-out infinite;
}

.tm-toolbar-group {
  /* Toolbar group = label + button(s) */
  display: inline-flex;
  /* Put label to the LEFT of the buttons (not above) */
  flex-direction: row;
  align-items: center;
  gap: 4px;
}

.tm-toolbar-label {
  /* Keep labels subtle and compact */
  font-size: 11px;
  line-height: 1;
  color: #6c757d; /* Bootstrap secondary */
  white-space: nowrap;
}

/* Inline form rows: fixed-width label column so widgets align nicely */
.tm-inline-label-col {
  width: 7.5rem;
  flex: 0 0 auto;
}

.tm-icon-btn {
  width: 34px; /* consistent square buttons for icons */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.tm-viz-status {
  min-width: 140px;
}

.tm-viz {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0; /* keep scroll containment inside right panel */
  overflow: auto;
  padding: 12px;
  background: #fff;
  --tm-node-shadow: none; /* MapScript can override via Default box shadow */
  position: relative; /* anchor for hover delete button */
}

/* Viz legend: MapScript "Description: ..." shown under the diagram */
.tm-viz-legend {
  flex: 0 0 auto;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid #e9ecef;
  white-space: pre-wrap; /* allow multi-line descriptions */
}

/* Viz interactivity */
.tm-viz svg .node,
.tm-viz svg .edge,
.tm-viz svg .cluster,
.tm-viz svg g.cluster text,
.tm-viz svg g.graph > text {
  cursor: pointer;
}

/* Cursor-adjacent hint (diagram) */
.tm-viz-hint-float {
  /* Purpose: show the current diagram hint adjacent to the cursor */
  position: fixed;
  z-index: 2100; /* above SVG + hover controls */
  pointer-events: none; /* never block clicks */
  max-width: min(420px, 60vw);
  padding: 9px 15px; /* ~50% bigger */
  border-radius: 10px;
  border: 1px solid rgba(13, 110, 253, 0.30);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  color: #212529;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18), 0 2px 10px rgba(0, 0, 0, 0.12);
  font-size: 18px; /* 12px * 1.5 */
  line-height: 1.25;
  transform: translate(-100%, -100%); /* anchor top-left of cursor (bubble sits up+left) */
  white-space: pre-line; /* allow wrapping + render \n as line breaks */
  overflow-wrap: anywhere;
}

/* Hover glow: subtle highlight for anything clickable-to-edit in the diagram (nodes, links, cluster boxes, title). */
.tm-viz svg .tm-viz-hover-glow {
  filter: drop-shadow(0 0 2px rgba(13, 110, 253, 0.55)) drop-shadow(0 0 8px rgba(13, 110, 253, 0.18));
}

/* Edge labels: faint translucent "halo" behind glyphs (no box), improves readability on crossings */
.tm-viz svg g.edge text {
  paint-order: stroke fill;
  stroke: rgba(255, 255, 255, 0.65);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* Hover delete button (red X) shown when hovering nodes/links */
.tm-viz-hover-delete {
  position: absolute;
  z-index: 30;
  display: none;
  line-height: 1;
  padding: 2px 6px; /* match hover checkbox button */
  min-width: auto;
}

.tm-viz-hover-delete.tm-show {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Hover checkbox button (bottom-left) shown when hovering nodes */
.tm-viz-hover-checkbox {
  position: absolute;
  z-index: 30;
  display: none;
  line-height: 1;
  padding: 2px 6px;
  min-width: auto;
}

.tm-viz-hover-checkbox.tm-show {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Hover checkbox button shown when hovering group boxes (clusters) */
.tm-viz-hover-cluster-checkbox {
  position: absolute;
  z-index: 30;
  display: none;
  line-height: 1;
  padding: 2px 6px;
  min-width: auto;
}

.tm-viz-hover-cluster-checkbox.tm-show {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tm-viz-hover-cluster-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

/* Cluster checkbox overlays (SVG foreignObject). Note: "z-index" isn't meaningful in SVG; DOM order controls stacking. */
.tm-cluster-checkbox {
  pointer-events: auto;
}

.tm-viz-hover-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

/* Compact sliders used for "width" and "size" widgets in small modals/popovers */
.tm-range-compact {
  width: 160px;
  max-width: 100%;
}

.tm-viz svg .tm-viz-selected polygon,
.tm-viz svg .tm-viz-selected path,
.tm-viz svg .tm-viz-selected ellipse {
  stroke-width: 2px !important;
}

/* Subtle “modern” look: apply shadow to Graphviz node shapes (SVG) */

/* ------------------------------------------------------------
   Small, icon-like buttons (used for Default node shape)
   ------------------------------------------------------------ */
.tm-shape-btn {
  /* Keep the control compact + consistent across fonts */
  width: 42px;
  padding-left: 0;
  padding-right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tm-shape-preview {
  width: 22px;
  height: 16px;
  border: 2px solid currentColor; /* follows btn text colour */
  background: transparent;
  display: inline-block;
}

.tm-shape-preview-rounded {
  border-radius: 8px;
}
.tm-viz svg .node polygon,
.tm-viz svg .node path,
.tm-viz svg .node ellipse {
  filter: var(--tm-node-shadow);
}

.tm-errors {
  font-size: 0.9rem;
  color: #842029; /* bootstrap danger-ish */
  background: #f8d7da;
  border: 1px solid #f5c2c7;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.tm-help {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  padding: 10px;
  overflow: auto;
}

/* Help tab: fixed quick reference + scrollable markdown body */
.tm-help-tab {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tm-help-header {
  flex: 0 0 auto;
}

.tm-help-md {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  padding: 12px;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  background: #ffffff;
}

.tm-help-quickref {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Help sub-tabs (intro|usage|syntax) */
.tm-help-subtabs {
  user-select: none;
  margin-bottom: 8px;
}

.tm-help-subtab {
  color: #444;
  text-decoration: none;
  font-weight: 600;
  padding: 0 2px;
}

.tm-help-subtab.active {
  color: #0d6efd;
}

/* Minimal markdown typography */
.tm-help-md h1,
.tm-help-md h2,
.tm-help-md h3,
.tm-help-md h4,
.tm-help-md h5,
.tm-help-md h6 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.tm-help-md pre {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  padding: 10px;
}

.tm-help-pre-wrap {
  position: relative;
}

.tm-help-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
}

.tm-help-md code {
  background: #f8f9fa;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
}

/* Templates */
#tab-templates {
  /* Keep scrolling inside the right panel so switching tabs doesn't change overall page width. */
  overflow: auto;
}

.tm-templates-card {
  cursor: pointer;
}

.tm-templates-card:hover {
  border-color: #0d6efd;
}

.tm-templates-card {
  position: relative;
}

.tm-templates-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

.tm-templates-actions .btn {
  background: rgba(255, 255, 255, 0.92);
}

.tm-templates-thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-bottom: 1px solid #e9ecef;
  background: #fff;
}

.tm-templates-thumb-placeholder {
  width: 100%;
  height: 140px;
  border-bottom: 1px solid #e9ecef;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 50%, #f1f3f5 100%);
}

.tm-templates-thumb-wrap {
  position: relative; /* anchor overlay */
}

/* On-hover overlay description (from MapScript "Description: ...") */
.tm-templates-thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  color: #fff;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.00) 0%, rgba(0, 0, 0, 0.70) 100%);
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none; /* don't block clicking the card */
  white-space: pre-wrap;
}

.tm-templates-card:hover .tm-templates-thumb-overlay,
.tm-templates-card:focus-visible .tm-templates-thumb-overlay {
  opacity: 1;
}

/* Ace editor popover (style current line) */
.tm-ace-popover {
  position: fixed;
  z-index: 2000; /* above Ace + toolbar */
  min-width: 260px;
  max-width: 320px;
  background: #fff;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.tm-ace-cursor-style-btn {
  position: fixed;
  z-index: 1999; /* just under the popover */
  padding: 2px 6px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
}

.tm-ace-popover-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Style drawer: preset selector grid + chevron details */
.tm-style-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)); /* bigger preset tiles */
  gap: 6px;
}

@media (max-width: 576px) {
  .tm-style-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)); /* bigger preset tiles on small screens */
  }
}

/* Styles drawer sizing: wider than the other drawers (so presets are easier to browse) */
#tm-style-modal {
  --tm-viz-drawer-w: 520px;
  max-width: min(680px, 92vw); /* override .tm-viz-drawer default cap (420px) */
}

/* Unified Selection drawer: match the Styles drawer width so the combined UI has room. */
#tm-viz-selection-drawer {
  --tm-viz-drawer-w: 520px;
  max-width: min(680px, 92vw); /* override .tm-viz-drawer default cap (420px) */
}

/* Cluster (group box) drawer: match the unified Selection drawer width */
#tm-viz-edit-modal {
  --tm-viz-drawer-w: 520px;
  max-width: min(680px, 92vw); /* override .tm-viz-drawer default cap (420px) */
}

@media (min-width: 992px) {
  .tm-style-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr)); /* bigger preset tiles on desktop */
  }

  #tm-style-modal {
    --tm-viz-drawer-w: 600px;
    max-width: min(760px, 92vw);
  }

  #tm-viz-selection-drawer {
    --tm-viz-drawer-w: 600px;
    max-width: min(760px, 92vw);
  }

  #tm-viz-edit-modal {
    --tm-viz-drawer-w: 600px;
    max-width: min(760px, 92vw);
  }
}

/* Style modal accordion: make the non-opened panel look like a distinct, clickable panel */
#tm-style-modal #tm-style-accordion .accordion-button.collapsed {
  background: #f8f9fa; /* subtle tint so the "other panel" is obvious */
  border: 1px solid #e9ecef;
}

/* Selection drawer accordion: match the Styles drawer "prominent headers" feel. */
#tm-viz-selection-drawer #tm-viz-selection-accordion .accordion-button {
  font-weight: 700;
}

/* Cluster drawer accordion: match the unified Selection drawer header weight */
#tm-viz-edit-modal .accordion .accordion-button {
  font-weight: 700;
}

/* Stronger, distinctive header colours for the two main panels (shared helpers) */
.tm-viz-acc-style .accordion-button {
  background: #e7f1ff; /* Bootstrap-ish "primary" tint */
  border: 1px solid #cfe2ff;
  color: #084298;
}

.tm-viz-acc-actions .accordion-button {
  background: #e8f5e9; /* green tint */
  border: 1px solid #c8e6c9;
  color: #0f5132;
}

/* Keep collapsed panels visually "clickable" like the Styles drawer */
#tm-viz-selection-drawer #tm-viz-selection-accordion .accordion-button.collapsed,
#tm-viz-edit-modal .accordion .accordion-button.collapsed {
  filter: saturate(0.92);
  box-shadow: none;
}

.tm-style-preset-btn {
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 0;
  background: #fff;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.tm-style-preset-btn:hover {
  border-color: #0d6efd;
}

.tm-style-preset-btn.tm-selected {
  border-color: #0d6efd;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.tm-style-preset-btn.tm-selected .tm-style-thumb {
  outline: 2px solid rgba(13, 110, 253, 0.45);
  outline-offset: -2px;
}

.tm-style-thumb {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.tm-style-thumb-node {
  position: absolute;
  left: 10%;
  top: 16%;
  width: 50%;
  height: 44%;
  background: #e7f5ff;
  border: 1px solid #1e90ff;
  border-radius: 0; /* default: truly square; rounded presets override inline */
}

.tm-style-thumb-edge {
  position: absolute;
  left: 14%;
  top: 68%;
  width: 72%;
  height: 0;
  border-top: 2px solid #6c757d;
  transform: rotate(-8deg);
  transform-origin: left center;
}

.tm-details {
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

/* -----------------------------
   Chat UI: standard "thread + composer"
   - Starts as just the input (thread hidden)
   - Grows upward until ~40% of viewport height, then thread scrolls
   ----------------------------- */

#tm-chat-panel {
  /* Purpose: behave like a normal chat container (thread above, input below) */
  display: flex;
  flex-direction: column;
  max-height: 40vh;
  overflow: hidden; /* thread provides the scroll */
}

.tm-chat-thread {
  /* Purpose: message history area above the composer */
  flex: 1 1 auto;
  min-height: 0; /* required for flex scroll areas */
  overflow-y: auto;
  border: 1px solid #e9ecef;
  border-radius: 10px;
  background: #f8f9fa;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tm-chat-bubble {
  /* Purpose: single chat bubble */
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid #e9ecef;
  background: #ffffff;
  white-space: pre-wrap; /* keep newlines (AI comments often have line breaks) */
}

.tm-chat-bubble-user {
  align-self: flex-end;
  border-color: #cfe2ff;
  background: #e7f1ff;
}

.tm-chat-bubble-assistant {
  align-self: flex-start;
  border-color: #d1e7dd;
  background: #eaf7ef;
}

.tm-chat-bubble-clickable {
  /* Purpose: indicate the bubble is interactive (restore state) */
  cursor: pointer;
}

.tm-chat-bubble-clickable:hover {
  border-color: #0d6efd; /* Bootstrap primary */
}

.tm-editor-details {
  /* Make the editor disclosure fill the remaining left panel height */
  flex: 1 1 auto;
  min-height: 0;
  margin: 10px;
  padding: 0; /* summary will provide padding; avoid double-padding with Ace margin */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tm-editor-details-summary {
  padding: 10px;
  border-bottom: 1px solid #e9ecef;
}

.tm-editor-details > .tm-editor-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.tm-details-summary {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tm-details-summary::-webkit-details-marker {
  display: none;
}

.tm-chevron {
  transition: transform 120ms ease-out;
}

details[open] .tm-chevron {
  transform: rotate(90deg);
}

/* -----------------------------
   Mobile: single-screen mode (hamburger menu)
   - Below Bootstrap lg, we show ONE panel at a time via JS (Chat/Editor/Diagram/Templates/Help)
   - Make whichever panel is visible fill the width; hide splitter + top-right tabs
   ----------------------------- */
@media (max-width: 991.98px) {
  .tm-left {
    width: 100% !important;
    min-width: 0;
    max-width: 100% !important;
    border: 0;
  }

  .tm-right {
    width: 100% !important;
    min-width: 0;
  }

  .tm-splitter {
    display: none;
  }

  .tm-tabs {
    display: none; /* hamburger replaces tabs on narrow screens */
  }
}



