/* RodmanVision — visuals adapted from RodmanSlides with a teal theme. */

:root {
  --primary: #1a8e9a;
  --primary-dark: #136872;
  --primary-light: #2bb1bf;
  --tab-active: #ffffff;
  --tab-inactive: #f3f3f3;
  --ribbon-bg: #f3f3f3;
  --ribbon-border: #d6d6d6;
  --workspace-bg: #e6e6e6;
  --pane-bg: #f3f3f3;
  --pane-border: #d6d6d6;
  --text: #222;
  --muted: #666;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  --status-bg: #1a8e9a;
  --status-fg: #fff;
  --hover: rgba(26, 142, 154, 0.1);
  --active: rgba(26, 142, 154, 0.22);
  --selection: #b6e2e6;
  --canvas-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--workspace-bg);
  overflow: hidden;
}

body {
  display: grid;
  /* `minmax(0, 1fr)` (not the implicit `auto`) pins the single
     grid column to viewport width. Without it, any row whose
     content is wider than 100vw (Insert/Home ribbon-panel on
     mobile) inflates the implicit column, which then makes the
     title-bar's right-aligned content scroll off-screen and
     defeats the ribbon-panel's own `overflow-x: auto`. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto 1fr auto;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}
/* All direct grid children must be allowed to shrink below their
   content's natural width — otherwise a fat ribbon row's
   intrinsic min-width climbs back up the grid and re-inflates
   the parent. */
body > .title-bar,
body > .tabs,
body > .ribbon,
body > .workspace,
body > .status-bar { min-width: 0; }

/* Title bar ----------------------------------------------------------------- */
.title-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 36px;
  padding: 5px 12px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
  user-select: none;
}

.rodmanoffice-back {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  color: inherit; text-decoration: none;
  font-size: 12px; font-weight: 500;
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
}
.rodmanoffice-back:hover { background: rgba(255, 255, 255, 0.25); }
.rodmanoffice-back svg { display: block; }

.app-brand {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
.app-logo {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  background: #fff;
  color: var(--primary);
  border-radius: 4px;
  font-weight: 800; font-size: 13px;
  flex-shrink: 0;
}
.app-title { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.doc-title {
  background: transparent; border: 1px solid transparent;
  color: inherit; font-size: 13px; font-weight: 600;
  padding: 2px 6px; border-radius: 3px;
  width: 280px; max-width: 44vw;
}
.doc-title:hover { border-color: rgba(255, 255, 255, 0.3); }
.doc-title:focus { outline: none; border-color: rgba(255, 255, 255, 0.7); background: rgba(255,255,255,0.08); }
.app-subtitle {
  font-size: 11px; opacity: 0.85; padding-left: 6px;
}

.title-actions {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}

/* Document tabs — between the diagram name and the title actions.
   Sized so the header height never grows past the app logo. */
.doc-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.doc-tabs::-webkit-scrollbar { height: 0; width: 0; }
.doc-tab {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  height: 24px;
  max-width: 160px;
  padding: 0 2px 0 8px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid transparent;
  border-radius: 4px 4px 0 0;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.doc-tab:hover { background: rgba(255, 255, 255, 0.2); }
.doc-tab.active { background: rgba(255, 255, 255, 0.28); font-weight: 600; }
.doc-tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-tab-close {
  flex-shrink: 0;
  width: 16px; height: 16px; line-height: 14px;
  padding: 0;
  border: 0; border-radius: 2px;
  background: transparent; color: inherit;
  font-size: 11px; cursor: pointer; opacity: 0.6;
}
.doc-tab-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.3); }
.doc-tab-new {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  padding: 0;
  border: 0; border-radius: 3px;
  background: rgba(255, 255, 255, 0.15); color: #fff;
  font-size: 15px; line-height: 1; cursor: pointer;
}
.doc-tab-new:hover { background: rgba(255, 255, 255, 0.28); }

.title-bar .ask-claude {
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border-radius: 3px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}
.title-bar .ask-claude:hover,
.title-bar .ask-claude[aria-expanded="true"] { background: rgba(255, 255, 255, 0.28); }
.save-indicator {
  font-size: 12px; opacity: 0.85;
  padding: 0 8px;
}
.icon-btn {
  background: transparent; border: none; color: inherit;
  width: 30px; height: 28px; border-radius: 3px;
  cursor: pointer; display: grid; place-items: center;
  font-size: 14px; font-family: inherit;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.15); }

/* Claude panel -------------------------------------------------------------- */
.claude-panel {
  position: fixed;
  top: 44px;
  right: 12px;
  bottom: 16px;
  width: min(360px, calc(100vw - 24px));
  z-index: 1200;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--ribbon-border);
  border-radius: 6px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}
.claude-panel[hidden] { display: none !important; }
.claude-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px;
  background: var(--primary); color: #fff;
  font-size: 13px; font-weight: 600;
}
.claude-panel-header button {
  background: transparent; border: 0; color: inherit;
  font-size: 20px; line-height: 1; padding: 0 4px; cursor: pointer;
}
.claude-panel-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.claude-panel-notice {
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  color: #155e75;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px; line-height: 1.4;
}
.claude-api-key-row { display: flex; flex-direction: column; gap: 6px; }
.claude-api-key-row span { font-weight: 600; }
.claude-api-key-row input {
  width: 100%; box-sizing: border-box;
  border: 1px solid #a5f3fc; border-radius: 4px;
  padding: 7px 8px; font: inherit; color: var(--text); background: #fff;
}
.claude-panel-intro {
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  border-radius: 6px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.claude-panel-intro h3 { margin: 0; font-size: 14px; color: var(--primary-dark); }
.claude-panel-intro p { margin: 0; font-size: 12.5px; line-height: 1.5; }
.claude-panel-label {
  margin-top: 4px !important;
  font-size: 11px !important; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted);
}
.claude-panel-chips { display: flex; flex-direction: column; gap: 6px; }
.claude-panel-chips button {
  text-align: left;
  background: #fff; color: var(--text);
  border: 1px solid var(--ribbon-border);
  border-radius: 14px; padding: 6px 12px;
  font: inherit; font-size: 12px; line-height: 1.4; cursor: pointer;
}
.claude-panel-chips button:hover { background: var(--hover); border-color: var(--primary-light); }
.claude-panel-output {
  margin: 0 12px 12px; padding: 10px 12px;
  border: 1px solid var(--ribbon-border); border-radius: 6px;
  background: #fff; color: var(--text);
  font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.claude-panel-output.status { color: var(--muted); }
.claude-panel-output.error {
  border-color: #fecaca; background: #fef2f2; color: #991b1b;
}
.claude-panel-input {
  flex-shrink: 0; display: flex; gap: 8px;
  padding: 8px; border-top: 1px solid var(--ribbon-border);
  background: var(--ribbon-bg);
}
.claude-panel-input textarea {
  flex: 1; min-width: 0; resize: none;
  border: 1px solid var(--ribbon-border); border-radius: 4px;
  padding: 6px 8px; font: inherit; font-size: 13px;
  background: #fff; color: var(--text);
}
.claude-panel-input button {
  border: 0; border-radius: 4px; padding: 6px 14px;
  background: var(--primary); color: #fff;
}
.claude-panel-input button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tabs --------------------------------------------------------------------- */
.tabs {
  background: var(--primary);
  display: flex; padding: 0;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: transparent; border: none;
  color: rgba(255, 255, 255, 0.85);
  font-family: inherit; font-size: 13px;
  padding: 8px 18px; cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tab.active {
  background: var(--tab-active); color: var(--text);
  border-bottom-color: var(--tab-active);
}

/* Ribbon ------------------------------------------------------------------- */
.ribbon {
  background: var(--ribbon-bg);
  border-bottom: 1px solid var(--ribbon-border);
  width: 100%; box-sizing: border-box;
  overflow-x: hidden; overflow-y: visible;
}
.ribbon.collapsed { display: none !important; }
.ribbon > .group { display: none !important; }

/* "▾" / "▴" toggle anchored at the right edge of the .tabs row.
   Single-tap collapses or shows the ribbon — a visible
   affordance for the dbltap gesture, which Safari handles
   unreliably on mobile. */
.ribbon-collapse-btn {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.9);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 12px;
}
.ribbon-collapse-btn:hover { background: rgba(255, 255, 255, 0.12); }

.ribbon-panel {
  display: none;
  flex-wrap: wrap;
  align-items: flex-start; align-content: flex-start;
  row-gap: 4px; width: 100%;
  min-height: 88px; max-height: 280px;
  padding: 6px 8px; box-sizing: border-box;
  overflow-x: hidden; overflow-y: auto;
  touch-action: pan-x;
}
.ribbon-panel.active { display: flex; animation: panelIn 0.15s ease; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}

.group {
  display: flex; flex-direction: column; justify-content: space-between;
  border-right: 1px solid var(--ribbon-border);
  padding: 4px 10px; min-width: 0; min-height: 76px; flex-shrink: 0;
}
.group-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.group-label { font-size: 11px; color: var(--muted); text-align: center; margin-top: 2px; }

.ribbon-btn {
  background: transparent; border: 1px solid transparent;
  color: var(--text); font-family: inherit; font-size: 13px;
  padding: 4px 8px; min-width: 30px; height: 30px;
  border-radius: 3px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 4px; white-space: nowrap;
}
.ribbon-btn:hover { background: var(--hover); border-color: var(--ribbon-border); }
.ribbon-btn.active, .ribbon-btn:active {
  background: var(--active); border-color: var(--ribbon-border);
}
.ribbon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ribbon-btn.wide { min-width: 90px; padding: 4px 10px; }

.select {
  font-family: inherit; font-size: 13px;
  height: 28px; padding: 2px 6px; min-width: 110px;
  border: 1px solid var(--ribbon-border);
  background: #fff; border-radius: 3px; color: var(--text);
}
.select.sm { width: auto; min-width: 56px; }

.color-input {
  width: 30px; height: 30px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px; padding: 0; background: #fff; cursor: pointer;
}

.zoom-display { min-width: 48px; text-align: center; font-size: 12px; color: var(--muted); }

/* Theme strip (Design tab) */
.theme-card {
  width: 96px; height: 56px;
  border: 1px solid var(--ribbon-border); border-radius: 4px;
  cursor: pointer; position: relative; overflow: hidden; flex-shrink: 0;
}
.theme-card:hover { border-color: var(--primary); }
.theme-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(26, 142, 154, 0.3); }
.theme-card .tc-bar { position: absolute; top: 6px; left: 6px; right: 6px; height: 4px; border-radius: 2px; }
.theme-card .tc-swatches { position: absolute; top: 14px; left: 6px; right: 6px; height: 20px; display: flex; gap: 2px; }
.theme-card .tc-swatch { flex: 1; border-radius: 1px; }
.theme-card .tc-name {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, 0.92);
  font-size: 10px; padding: 2px 4px;
  border-top: 1px solid var(--ribbon-border);
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Workspace: stencils | canvas | (props + layers) ------------------------- */
.workspace {
  display: grid;
  grid-template-columns: 200px 1fr 240px;
  min-height: 0;
  background: var(--workspace-bg);
  position: relative;
}

/* Stencil rail */
.stencil-pane {
  background: var(--pane-bg);
  border-right: 1px solid var(--pane-border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.stencil-search {
  padding: 8px;
  border-bottom: 1px solid var(--pane-border);
}
.stencil-search input {
  width: 100%; padding: 5px 8px;
  border: 1px solid var(--ribbon-border); border-radius: 3px;
  font: inherit; font-size: 12px;
}
.stencil-list {
  flex: 1; overflow-y: auto; padding: 4px 6px;
}
.stencil-category {
  margin-bottom: 8px;
}
.stencil-category-header {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 6px 4px;
  user-select: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.stencil-category-header::after {
  content: '▾'; font-size: 10px; color: var(--muted);
}
.stencil-category.collapsed .stencil-category-header::after {
  content: '▸';
}
.stencil-category.collapsed .stencil-grid { display: none; }
.stencil-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.stencil-tile {
  background: #fff;
  border: 1px solid var(--pane-border);
  border-radius: 3px;
  padding: 4px;
  cursor: grab;
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  font-size: 10px; color: var(--muted);
  text-align: center;
  user-select: none;
}
.stencil-tile:hover { border-color: var(--primary); background: var(--hover); }
.stencil-tile:active { cursor: grabbing; }
.stencil-tile svg { display: block; pointer-events: none; }
.stencil-tile-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  width: 100%;
}

/* Canvas area */
.canvas-area {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  min-width: 0;
}
.canvas-scroll {
  flex: 1; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  /* Modest padding around the canvas. Earlier attempts to give
     the helper "always-on" two-finger pan room used `padding:
     50vh 50vw` (PR #63) and `padding: 400px` (PR #64), but
     both fight `* { box-sizing: border-box }`: on a 390 px
     iPhone, 400 px padding eats more than the entire element
     width, leaving the canvas wedged off-screen at the right
     edge. Reverted to small absolute padding — two-finger pan
     now works whenever the canvas overflows (i.e. when zoomed
     in past fit), which is the standard pattern Slides uses
     and matches how maps-style apps behave. */
  padding: 24px;
  background: var(--workspace-bg);
}
.canvas-shadow {
  box-shadow: var(--canvas-shadow);
  background: #fff;
  border-radius: 2px;
  position: relative;
  transform-origin: top left;
  /* Two-finger gestures are handled by lib/ui/gestures.js, which
     pans the parent .canvas-scroll and pinches state.zoom. */
  touch-action: none;
  /* PR #73 pinned the body grid column to viewport width, which
     cascaded down to .canvas-scroll. Without this, the
     flex-centered shadow shrinks below its inline `style.width =
     page.w * zoom` to fit the constrained parent, so the SVG
     inside renders at a different scale than the overlay-layer
     (which is `position: absolute` and immune to flex layout) —
     selection handles drift away from their shapes at any zoom
     above fit. flex-shrink: 0 keeps the shadow at its specified
     pixel size; .canvas-scroll's `overflow: auto` then provides
     horizontal scroll when zoomed past fit. */
  flex-shrink: 0;
}
.canvas-svg { display: block; width: 100%; height: 100%; }

/* Wrapper for absolute-positioned overlays (selection handles,
   port dots, marquee, AutoConnect arrows, smart guides, text-edit
   overlay). Sized to page coordinates (page.w × page.h) and
   transformed via `scale(state.zoom)` set inline by renderCanvas,
   so overlay code can keep using page-coord positions (e.g.
   `style.left = shape.x + 'px'`) without per-call math while
   still visually aligning with the scaled SVG. */
.overlay-layer {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  transform-origin: top left;
}

/* Shape interactions */
.shape { cursor: move; }
.shape.is-selected > * {
  filter: drop-shadow(0 0 0 var(--primary));
}
.selection-overlay {
  position: absolute;
  pointer-events: none;
  border: 1.5px dashed var(--primary);
  z-index: 50;
}
.selection-handles {
  position: absolute;
  pointer-events: none;
  z-index: 60;
}
.selection-handle {
  position: absolute;
  width: 10px; height: 10px;
  background: #fff;
  border: 1.5px solid var(--primary);
  border-radius: 1px;
  pointer-events: auto;
  cursor: pointer;
}
.selection-handle.h-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.selection-handle.h-n  { top: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.selection-handle.h-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.selection-handle.h-e  { top: calc(50% - 5px); right: -5px; cursor: ew-resize; }
.selection-handle.h-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.selection-handle.h-s  { bottom: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.selection-handle.h-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.selection-handle.h-w  { top: calc(50% - 5px); left: -5px; cursor: ew-resize; }
.selection-handle.h-rot {
  top: -22px; left: calc(50% - 5px);
  border-radius: 50%;
  cursor: alias;
}

/* Port dots — visible on hover, used to start a connector drag */
.port-dot {
  position: absolute;
  width: 9px; height: 9px;
  background: var(--primary);
  border: 1.5px solid #fff;
  border-radius: 50%;
  cursor: crosshair;
  pointer-events: auto;
  z-index: 70;
}

/* Marquee selection rectangle */
.marquee {
  position: absolute;
  pointer-events: none;
  border: 1px dashed var(--primary);
  background: rgba(26, 142, 154, 0.06);
  z-index: 40;
}

/* Text editor overlay */
.text-edit-overlay {
  position: absolute;
  z-index: 80;
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid var(--primary);
  outline: none;
  padding: 4px;
  text-align: center;
}

/* Connector drag preview */
.connector-preview {
  position: absolute;
  pointer-events: none;
  z-index: 65;
}

/* Right rail: properties + layers ------------------------------------------ */
.side-pane {
  background: var(--pane-bg);
  border-left: 1px solid var(--pane-border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.side-pane-tabs {
  display: flex;
  border-bottom: 1px solid var(--pane-border);
}
.side-pane-tab {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 8px 6px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.side-pane-tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}
.side-pane-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.side-pane-body[hidden] { display: none; }

/* Properties form */
.props-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 6px 8px;
  align-items: center;
  font-size: 12px;
}
.props-grid label { color: var(--muted); }
.props-grid input[type="text"],
.props-grid input[type="number"],
.props-grid select {
  width: 100%; box-sizing: border-box;
  font: inherit; font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
}
.props-grid input[type="color"] {
  width: 28px; height: 24px; padding: 0;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
}
.props-grid input[type="range"] { width: 100%; }
.props-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 4px; }
.props-section-title {
  grid-column: 1 / -1;
  font-size: 11px; font-weight: 700; color: var(--primary);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 8px 0 2px;
}

/* Layers list */
.layers-toolbar {
  display: flex; gap: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--pane-border);
  margin-bottom: 6px;
}
.layers-toolbar button {
  flex: 1; background: transparent;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  font: inherit; font-size: 11px;
  padding: 4px;
  cursor: pointer;
}
.layers-toolbar button:hover { background: var(--hover); }
.layer-row {
  display: grid;
  grid-template-columns: 18px 18px 1fr 60px;
  gap: 4px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 3px;
  align-items: center;
  font-size: 12px;
  cursor: pointer;
}
.layer-row.active {
  background: var(--hover);
  border-color: var(--primary-light);
}
.layer-row .layer-toggle {
  background: transparent; border: 0;
  cursor: pointer; font-size: 12px;
  padding: 0;
}
.layer-row .layer-name {
  background: transparent; border: 0;
  font: inherit; font-size: 12px;
  width: 100%;
  padding: 2px;
}
.layer-row .layer-opacity {
  width: 100%;
}

/* Page strip --------------------------------------------------------------- */
.page-strip {
  display: flex; align-items: center;
  background: var(--pane-bg);
  border-top: 1px solid var(--pane-border);
  padding: 4px 8px;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  touch-action: pan-x;
  flex-shrink: 0;
}
.page-tab {
  background: #fff;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  font: inherit; font-size: 12px;
  white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}
.page-tab.active {
  background: var(--primary); color: #fff;
  border-color: var(--primary-dark);
}
.page-tab .page-close {
  background: transparent; border: 0; color: inherit;
  padding: 0 2px; font-size: 14px; line-height: 1; cursor: pointer;
  opacity: 0.7;
}
.page-tab .page-close:hover { opacity: 1; }
.page-add {
  background: transparent;
  border: 1px dashed var(--pane-border);
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  font: inherit; font-size: 12px;
  color: var(--muted);
}
.page-add:hover { border-color: var(--primary); color: var(--primary); }

/* Status bar */
.status-bar {
  background: var(--status-bg);
  color: var(--status-fg);
  display: flex; align-items: center;
  padding: 4px 12px;
  gap: 16px;
  font-size: 12px;
}
.status-bar .status-spacer { flex: 1; }

/* Wave 1: Tool-mode indicator + group frame + lasso visuals --------------- */
.ribbon-btn.tool-btn.active {
  background: var(--active);
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 700;
}
body[data-tool="pan"] .canvas-svg,
body[data-tool="pan"] .canvas-shadow { cursor: grab; }
body[data-tool="pan"] .canvas-svg:active,
body[data-tool="pan"] .canvas-shadow:active { cursor: grabbing; }
body[data-tool="eyedropper"] .canvas-svg { cursor: crosshair; }
body[data-tool="lasso"] .canvas-svg { cursor: crosshair; }
body[data-tool="stamp"] .canvas-svg { cursor: copy; }
body[data-tool="connect"] .canvas-svg { cursor: crosshair; }
body[data-tool="connect"] .canvas-svg .shape { cursor: pointer; }
.group-frame {
  position: absolute;
  pointer-events: none;
  border: 1.5px dashed rgba(26, 142, 154, 0.65);
  border-radius: 4px;
  z-index: 38;
}

/* Wave 2: Template picker + tile size variants -------------------------- */
.template-pick {
  display: block;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--ribbon-border);
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font: inherit;
}
.template-pick:hover { border-color: var(--primary); background: var(--hover); }
.template-pick-name { font-weight: 600; font-size: 13px; color: var(--primary-dark); }
.template-pick-summary { font-size: 12px; color: var(--text); margin: 2px 0; }
.template-pick-counts { font-size: 11px; color: var(--muted); }
/* Stencil grid tile sizes (controlled by parent #stencilList[data-tile-size]) */
#stencilList[data-tile-size="small"]  .stencil-grid { grid-template-columns: 1fr 1fr 1fr; }
#stencilList[data-tile-size="small"]  .stencil-tile { font-size: 9px; padding: 2px; }
#stencilList[data-tile-size="medium"] .stencil-grid { grid-template-columns: 1fr 1fr; }
#stencilList[data-tile-size="large"]  .stencil-grid { grid-template-columns: 1fr; }
#stencilList[data-tile-size="large"]  .stencil-tile { font-size: 12px; padding: 6px; }
.stencil-size-toggle {
  display: flex;
  gap: 2px;
  padding: 2px 6px 4px;
  border-bottom: 1px solid var(--ribbon-border);
}
.stencil-size-btn {
  flex: 1;
  padding: 2px 0;
  background: #fff;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.stencil-size-btn:hover { background: var(--hover); }
.stencil-size-btn.active {
  background: var(--active);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* Wave 4: presentation, reviewer, bookmarks --------------------------- */
#presentationOverlay[hidden] { display: none !important; }
#presentationOverlay {
  position: fixed; inset: 0; background: #000; z-index: 9999;
  display: flex; flex-direction: column;
}
#presentationToolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; color: #fff; font: 13px 'Segoe UI', sans-serif;
}
#presentationToolbar button {
  background: transparent; color: #fff; border: 1px solid #444;
  border-radius: 3px; padding: 2px 10px; cursor: pointer;
}
#presentationToolbar button:hover { background: #222; }
#presentationSurface {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 16px; min-height: 0;
}
#presentationSurface svg { max-width: 100%; max-height: 100%; }

body.reviewer-mode .ribbon-tab[data-tab="home"],
body.reviewer-mode .ribbon-tab[data-tab="insert"],
body.reviewer-mode .ribbon-tab[data-tab="design"] { opacity: 0.5; }
body.reviewer-mode .stencil-pane,
body.reviewer-mode .side-pane { opacity: 0.6; pointer-events: none; }
body.reviewer-mode .canvas-svg .shape,
body.reviewer-mode .canvas-svg .connector { cursor: pointer; }
body.reviewer-mode .selection-handles,
body.reviewer-mode .resize-handle,
body.reviewer-mode .rotate-handle { display: none !important; }

.bookmark-item {
  font-size: 11px;
  padding: 2px 6px;
  background: #fff;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  cursor: pointer;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bookmark-item:hover { background: var(--hover); border-color: var(--primary); }
.status-bar .status-zoom-fit {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: inherit;
  font: inherit;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
}
.status-bar .status-zoom-fit:hover { background: rgba(255, 255, 255, 0.18); }
.status-bar .status-zoom-fit:active { background: rgba(255, 255, 255, 0.28); }

/* Save dialog -------------------------------------------------------------- */
dialog.save-dialog {
  border: 0; border-radius: 8px;
  padding: 0;
  width: min(440px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
dialog.save-dialog::backdrop {
  background: rgba(20, 20, 20, 0.38);
}
.save-dialog form { margin: 0; }
.save-dialog header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--primary); color: #fff;
}
.save-dialog header h3 { margin: 0; font-size: 14px; }
.save-dialog header button {
  background: transparent; border: 0; color: inherit;
  font-size: 20px; line-height: 1; cursor: pointer;
}
.save-dialog .body {
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.save-dialog label { font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.save-dialog input[type="text"],
.save-dialog select {
  padding: 5px 8px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  font: inherit;
}
.save-dialog footer {
  display: flex; justify-content: flex-end; gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--pane-border);
  background: var(--pane-bg);
}
.save-dialog footer button {
  padding: 5px 12px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.save-dialog footer button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}

/* Help modal (carries Office "F1" shortcut + about content) */
.help-modal {
  position: fixed; inset: 0; z-index: 1200;
  display: grid; place-items: center;
  background: rgba(20, 20, 20, 0.38);
  padding: 20px;
}
.help-modal[hidden] { display: none; }
.help-modal-card {
  width: min(560px, 92vw); max-height: min(520px, 86vh);
  display: flex; flex-direction: column;
  background: var(--pane-bg); color: var(--text);
  border: 1px solid var(--pane-border);
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
.help-modal-card header,
.help-modal-card footer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--pane-border);
}
.help-modal-card footer {
  justify-content: flex-end;
  border-top: 1px solid var(--pane-border); border-bottom: 0;
}
.help-modal-card h3 { margin: 0; font-size: 15px; }
.help-modal-card header .icon-btn { margin-left: auto; color: var(--text); }
.help-modal-body { overflow: auto; padding: 14px 16px; font-size: 13px; line-height: 1.5; }
.help-modal-body ul { margin: 0; padding-left: 18px; }
.help-modal-body li + li { margin-top: 8px; }

/* Rulers ------------------------------------------------------------------ */
.canvas-area.with-rulers .canvas-scroll {
  padding-top: 22px;
  padding-left: 22px;
}
.ruler {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  background: #f8fafc;
  border: 1px solid var(--pane-border);
}
.ruler-top {
  top: 0;
  left: 22px;
  right: 0;
  height: 22px;
  border-bottom: 1px solid var(--pane-border);
}
.ruler-left {
  left: 0;
  top: 22px;
  bottom: 0;
  width: 22px;
  border-right: 1px solid var(--pane-border);
}

/* Format painter ---------------------------------------------------------- */
body.format-painter-active .shape { cursor: crosshair; }
body.format-painter-active .canvas-svg { cursor: crosshair; }

/* Find dialog ------------------------------------------------------------- */
.find-dialog .find-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--ribbon-border);
  border-radius: 4px;
  padding: 4px;
  background: #fff;
}
.find-dialog .find-result {
  text-align: left;
  background: transparent;
  border: 0;
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.find-dialog .find-result:hover {
  background: var(--hover);
}

/* AutoConnect arrows ------------------------------------------------------- */
.autoconnect-arrow {
  position: absolute;
  width: 16px; height: 16px;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary-dark);
  border-radius: 50%;
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  z-index: 65;
  opacity: 0.85;
  transition: transform 0.1s, opacity 0.1s;
}
.autoconnect-arrow:hover {
  transform: scale(1.25);
  opacity: 1;
}

/* Connector handles (bend / waypoint) ------------------------------------- */
.connector-handle {
  position: absolute;
  z-index: 75;
}
.connector-handle.waypoint {
  width: 10px; height: 10px;
  background: var(--primary);
  border: 1.5px solid #fff;
  border-radius: 50%;
  cursor: grab;
}
.connector-handle.midpoint {
  width: 8px; height: 8px;
  background: #fff;
  border: 1px dashed var(--primary);
  border-radius: 50%;
  cursor: grab;
  opacity: 0.7;
}
.connector-handle.midpoint:hover { opacity: 1; }

/* Data side-pane tab ------------------------------------------------------ */
.data-field-list,
.comment-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.data-field-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px;
  align-items: center;
  font-size: 12px;
}
.data-field-row.hyperlink-row {
  grid-template-columns: 36px 1fr auto;
}
.data-field-name {
  font-size: 10px;
  color: var(--muted);
  text-align: right;
}
.data-field-val {
  width: 100%;
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--ribbon-border);
  border-radius: 3px;
  padding: 2px 6px;
}
.hyperlink-kind {
  font-size: 10px;
  background: #dbeafe;
  color: #1e3a8a;
  padding: 1px 4px;
  border-radius: 3px;
  text-align: center;
}
.hyperlink-label {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comment-row {
  position: relative;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 4px;
  padding: 6px 22px 6px 8px;
  font-size: 12px;
}
.comment-row .comment-meta {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}
.comment-row > button {
  position: absolute;
  top: 4px; right: 4px;
}
.ribbon-btn.sm {
  height: 22px;
  min-width: 22px;
  padding: 1px 6px;
  font-size: 11px;
}

/* Mini-map ---------------------------------------------------------------- */
#miniMap {
  position: fixed;
  right: 16px;
  bottom: 36px;
  background: #fff;
  border: 1px solid var(--pane-border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 600;
  cursor: pointer;
  overflow: hidden;
}
#miniMap[hidden] { display: none; }
#miniMap svg { display: block; pointer-events: none; }
.minimap-viewport {
  position: absolute;
  border: 1.5px solid var(--primary);
  background: rgba(26, 142, 154, 0.1);
  pointer-events: none;
}

/* Ask Claude — diagram-spec result card ----------------------------------- */
.claude-panel-output.diagram-card {
  white-space: normal;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #ecfeff;
  border-color: #a5f3fc;
}
.claude-diagram-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--primary-dark);
}
.claude-diagram-counts {
  font-size: 12px;
  color: var(--text);
}
.claude-diagram-actions {
  display: flex;
  gap: 6px;
}
.claude-diagram-insert {
  flex: 1;
  border: 0;
  border-radius: 4px;
  padding: 6px 10px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.claude-diagram-insert:hover { background: var(--primary-dark); }
.claude-diagram-discard {
  border: 1px solid var(--ribbon-border);
  border-radius: 4px;
  padding: 6px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.claude-diagram-discard:hover { background: var(--hover); }

/* Mobile / small screens --------------------------------------------------- */
@media (max-width: 720px) {
  body { font-size: 14px; }
  .title-bar {
    gap: 8px;
    padding: 5px 8px;
  }
  .app-subtitle,
  .save-indicator { display: none; }
  /* Hide ALL title-bar icon buttons on mobile — they ate the
     horizontal space that title-actions needs to keep Ask Claude
     visible. Stencils + Properties are reachable via the View
     ribbon tab; matches the Slides pattern. */
  .title-bar .title-actions .icon-btn { display: none; }
  .doc-title {
    /* Wide enough for "Untitled Diagram" to fit at 13px without
       clipping (~110px text + 12px padding). Anything longer
       falls back to text-overflow: ellipsis — works on <input>
       in WebKit / Blink. */
    width: min(200px, 50vw);
    max-width: 50vw;
    font-size: 13px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  .title-actions { gap: 2px; }
  /* Mobile Ask Claude: hide the " Ask Claude" label span so the
     visible content is just the 🤖 emoji (real text in the
     .ask-claude-emoji span, not a ::before pseudo). This is
     more reliable than the prior font-size:0 + ::before hack
     which combined badly with display:grid on iOS Safari. */
  .title-bar .ask-claude {
    padding: 0 8px;
    height: 28px;
    border-radius: 4px;
  }
  .ask-claude-label { display: none; }
  .tab { padding: 8px 14px; font-size: 12px; }
  .ribbon { overflow: visible; }
  .ribbon-panel {
    flex-wrap: nowrap !important;
    align-items: center; align-content: center;
    width: 100%; box-sizing: border-box;
    overflow-x: auto; overflow-y: hidden;
    /* Explicit height so the ribbon row is the same size on every
       tab. With max-height + min-height, Insert / Design / View
       (taller groups) caused the workspace 1fr row to shrink and
       the canvas scroll position to shift between tab switches. */
    height: 52px;
    padding: 2px 4px; gap: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    /* Explicit pan-x so single-finger horizontal swipes scroll
       the ribbon on iOS Safari. Without this, swipes that land
       on the empty gap between groups may be interpreted
       ambiguously and not pan. */
    touch-action: pan-x;
  }
  /* Buttons / inputs inside the ribbon must not block the parent's
     horizontal pan. `manipulation` keeps tap-to-click instant and
     disables the 300ms tap delay + double-tap-to-zoom — exactly
     right for a toolbar that's also scrollable. */
  .ribbon-panel .ribbon-btn,
  .ribbon-panel .select,
  .ribbon-panel input,
  .ribbon-panel button,
  .ribbon-panel label {
    touch-action: manipulation;
  }
  .group {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center;
    flex-shrink: 0;
    border-right: 1px solid var(--ribbon-border);
    padding: 2px 6px;
    gap: 2px;
    min-height: 0;
  }
  .group-row { display: contents; }
  .group-label { display: none; }
  .ribbon-btn {
    height: 32px; min-width: 32px;
    padding: 2px 6px; font-size: 12px;
    flex-shrink: 0;
  }
  .ribbon-btn.wide { min-width: 60px; padding: 2px 8px; }
  .select {
    height: 28px; font-size: 12px;
    min-width: 64px; max-width: 126px;
    padding: 1px 6px;
    flex-shrink: 0;
  }
  .select.sm { min-width: 50px; }
  .color-input { width: 32px; height: 32px; flex-shrink: 0; }
  .theme-card { width: 76px; height: 46px; flex-shrink: 0; }
  /* grid-template-rows: 1fr forces the workspace's single row
     to fill its full height. Without it, the auto row sizes to
     its in-flow children's max-content height; on mobile the
     side panes are position: fixed (out of flow) so only
     canvas-area is in flow, and its max-content is just the
     page-strip (~30 px) because canvas-shadow's size is set by
     JS *after* initial layout. That collapsed the canvas-area to
     ~30 px tall on iPhone, hiding the canvas entirely. */
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  /* Both panes are hidden off-screen by default on mobile. The
     `bottom: -100vh` mechanic guarantees the entire pane sits below
     the viewport — replaces the old transform: translateY(100%) which
     left ~100 px of the pane visible because the pane's bottom edge
     started inside the viewport (bottom: 100px). When .is-open is
     applied (by toggleStencils / toggleSidePane), the pane slides up
     to bottom: 100px, sitting above the page-strip. */
  .stencil-pane {
    position: fixed; left: 0; right: 0; top: auto;
    bottom: -100vh;
    z-index: 800;
    max-height: 45vh;
    border-top: 1px solid var(--pane-border);
    border-right: 0;
    transition: bottom 0.2s;
  }
  .stencil-pane.is-open { bottom: 100px; }
  .side-pane {
    position: fixed; left: 0; right: 0; top: auto;
    bottom: -100vh;
    z-index: 800;
    max-height: 45vh;
    border-top: 1px solid var(--pane-border);
    border-left: 0;
    transition: bottom 0.2s;
  }
  .side-pane.is-open { bottom: 100px; }
  .canvas-scroll { padding: 12px; }
  .claude-panel {
    top: 42px; right: 8px; bottom: 8px;
    width: calc(100vw - 16px);
  }
}

/* Window-level drag-and-drop highlight. pointer-events:none is essential —
   the overlay must not become a drag target, or it would generate its own
   dragenter/dragleave storm. */
.drop-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(26, 142, 154, 0.12);
  z-index: 9000;
  pointer-events: none;
}
.drop-overlay.is-active { display: flex; }
.drop-overlay-card {
  border: 3px dashed var(--primary);
  border-radius: 14px;
  padding: 28px 44px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  text-align: center;
  min-width: 260px;
}
.drop-overlay-icon { font-size: 38px; color: var(--primary); line-height: 1; margin-bottom: 8px; }
.drop-overlay-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.drop-overlay-sub { font-size: 12px; opacity: 0.7; }
