/*
 * Demo tools: the floating toolbar, its panels, the walkthrough ring and card,
 * and comment pins. Everything sits in #dmt-root above the app's pop-ups
 * (overlays are z-index 100): pins 1200, the hover outline 1250, the
 * walkthrough's dimming ring 1400, its card 1450, panels and the bar 1500.
 *
 * It follows the CRM's own look (Nick, 2026-11-16: "always follow the CRM's
 * visual style"). The bar is chrome, so it is the Back Office navy and gold in
 * every theme, like the phone's top and tab bars. Everything the bar opens
 * (panels, the step card, threads, the drawer) is drawn from the theme's own
 * variables: paper, ink, lines, the soft accent, the button tokens and the
 * display font. A theme switch repaints them with nothing here to change.
 */
#dmt-root{
  --dmt-bar:#000540; --dmt-bar-on:#1A2270; --dmt-bar-line:#1B2160;
  --dmt-on-bar:#E4E6F5; --dmt-on-bar-muted:#B5BAE0; --dmt-gold:#FFBE2A;
  --dmt-pin:var(--btn-bg); --dmt-pin-ink:var(--btn-ink); --dmt-pin-on:var(--btn-hover);
  --dmt-shadow:0 24px 64px rgba(0,5,64,.24), 0 2px 8px rgba(0,5,64,.10);
  font-family:var(--font-ui, inherit);
}
#dmt-root [hidden]{ display:none !important; }
/* On a dark page the navy bar is the page's own color, so its edge is drawn a
   step lighter or the bar melts into what it floats over (audit 2026-11-16). */
html[data-scheme="dark"] #dmt-root{ --dmt-bar-line:#2E3578; }
/* Titles wear the theme's heading color, as the CRM's own h2 and page titles do
   (core.css: Harbour steel blue, Midnight gold); other themes keep their ink. */
html[data-theme="harbour"] :is(.dmt-head-text strong, .dmt-card-title, .dmt-drawer-head strong){ color:#056BB6; }
html[data-theme="midnight"] :is(.dmt-head-text strong, .dmt-card-title, .dmt-drawer-head strong){ color:#FFBE2A; }

/* ---------- the bar ---------- */
.dmt-bar{
  position:fixed; z-index:1500; left:50%; bottom:var(--space-5); transform:translateX(-50%);
  display:flex; align-items:center; gap:var(--space-1); padding:var(--space-2);
  background:var(--dmt-bar); color:var(--dmt-on-bar); border-radius:var(--radius-lg);
  box-shadow:0 14px 40px rgba(0,5,64,.35), 0 0 0 1px var(--dmt-bar-line);
  user-select:none;
}
.dmt-bar.placed{ transform:none; bottom:auto; }
.dmt-bar button{ font:inherit; cursor:pointer; }
.dmt-bar button:focus-visible{ outline:3px solid var(--dmt-gold); outline-offset:2px; }
.dmt-grip{ width:22px; height:var(--touch); border:0; background:transparent; color:var(--dmt-on-bar-muted); display:flex; align-items:center; justify-content:center; cursor:grab !important; touch-action:none; }
.dmt-grip:active{ cursor:grabbing !important; }
.dmt-brand{ display:flex; flex-direction:column; gap:2px; padding:0 var(--space-3) 0 var(--space-1); max-width:220px; }
.dmt-eyebrow{ font-size:var(--text-xs); letter-spacing:.12em; text-transform:uppercase; color:var(--dmt-on-bar-muted); }
.dmt-name{ font-family:var(--font-display); font-size:var(--text-sm); font-weight:700; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.dmt-sep{ width:1px; height:32px; background:var(--dmt-bar-line); margin:0 var(--space-1); }
.dmt-tool{
  position:relative; width:76px; height:56px; border:0; border-radius:var(--radius-md); background:transparent; color:var(--dmt-on-bar);
  font-size:var(--text-xs) !important; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:var(--space-1);
}
.dmt-tool:hover{ background:rgba(255,255,255,.08); }
.dmt-tool.on{ background:var(--dmt-bar-on); color:var(--dmt-gold); font-weight:700; }
.dmt-badge{ position:absolute; top:var(--space-1); right:var(--space-3); min-width:18px; height:18px; padding:0 var(--space-1); box-sizing:border-box; border-radius:var(--radius-pill); background:var(--dmt-gold); color:var(--dmt-bar); font-size:var(--text-xs); font-weight:700; display:flex; align-items:center; justify-content:center; }
.dmt-tuck{ width:var(--touch); height:var(--touch); border:0; background:transparent; color:var(--dmt-on-bar-muted); display:flex; align-items:center; justify-content:center; border-radius:var(--radius-md); }
.dmt-tuck:hover{ background:rgba(255,255,255,.08); color:#fff; }
.dmt-txt{ height:var(--touch); padding:0 var(--space-3); border:0; border-radius:var(--radius-md); background:transparent; color:var(--dmt-on-bar); font-size:var(--text-sm) !important; }
.dmt-txt:hover:not(:disabled){ background:rgba(255,255,255,.08); }
.dmt-txt.on{ background:var(--dmt-gold); color:var(--dmt-bar); font-weight:700; }
.dmt-txt.on:hover{ background:#FFD066; }
.dmt-txt.edge{ border:1px solid #3A4180; }
.dmt-txt:disabled{ color:#6E73A3; cursor:default; }
.dmt-bar.tucked{ padding:var(--space-1); border-radius:var(--radius-pill); }
.dmt-untuck{ display:flex; align-items:center; gap:var(--space-2); height:var(--touch); padding:0 var(--space-4) 0 var(--space-3); border:0; border-radius:var(--radius-pill); background:transparent; color:#fff; font-size:var(--text-sm) !important; font-weight:700; touch-action:none; cursor:grab !important; }
.dmt-untuck svg{ color:var(--dmt-gold); }

/* ---------- panels: Ask and Show me ---------- */
.dmt-panel{
  position:fixed; z-index:1500; width:420px; max-height:min(640px, calc(100vh - 140px));
  display:flex; flex-direction:column; overflow:hidden;
  background:var(--paper-raised); color:var(--ink); border:1px solid var(--line); border-radius:var(--radius-lg);
  box-shadow:var(--dmt-shadow);
}
.dmt-head{ display:flex; align-items:center; gap:var(--space-3); padding:var(--space-3) var(--space-2) var(--space-3) var(--space-4); border-bottom:1px solid var(--line); }
.dmt-head-ic{ width:36px; height:36px; flex:none; border-radius:var(--radius-md); background:var(--sage-soft); color:var(--sage-ink); display:flex; align-items:center; justify-content:center; }
.dmt-head-text{ flex:1; min-width:0; display:flex; flex-direction:column; gap:2px; }
.dmt-head-text strong{ font-family:var(--font-display); font-size:var(--text-lg); font-weight:700; color:var(--ink); }
.dmt-head-text span{ font-size:var(--text-xs); color:var(--text-muted); }
.dmt-x{ width:var(--touch); height:var(--touch); flex:none; border:0; background:transparent; border-radius:var(--radius-md); color:var(--ink-soft); display:flex; align-items:center; justify-content:center; cursor:pointer; }
.dmt-x:hover{ background:var(--subtle-bg); color:var(--ink); }
.dmt-body{ flex:1; min-height:120px; overflow-y:auto; overscroll-behavior:contain; padding:var(--space-4); display:flex; flex-direction:column; gap:var(--space-3); background:var(--subtle-bg); }
.dmt-me{ align-self:flex-end; max-width:80%; background:var(--btn-bg); color:var(--btn-ink); border-radius:var(--radius-lg) var(--radius-lg) var(--space-1) var(--radius-lg); padding:var(--space-2) var(--space-3); font-size:var(--text-md); line-height:1.4; overflow-wrap:anywhere; }
.dmt-bot{ max-width:94%; font-size:var(--text-md); line-height:1.5; white-space:pre-line; color:var(--ink); }
.dmt-quiet{ margin:0; font-size:var(--text-sm); color:var(--text-muted); line-height:1.45; }
.dmt-chips{ display:flex; flex-wrap:wrap; gap:var(--space-2); }
.dmt-chip{ min-height:36px; padding:var(--space-1) var(--space-3); border:1px solid var(--line); background:var(--paper-raised); border-radius:var(--radius-pill); font:inherit; font-size:var(--text-sm); color:var(--sage-ink); cursor:pointer; text-align:left; }
.dmt-chip:hover{ border-color:var(--sage); background:var(--sage-soft); }
.dmt-also{ display:flex; flex-direction:column; gap:var(--space-2); }
.dmt-also > span{ font-size:var(--text-xs); letter-spacing:.08em; text-transform:uppercase; color:var(--text-muted); }
.dmt-guide{ background:var(--paper-raised); border:1px solid var(--line); border-radius:var(--radius-lg); padding:var(--space-3) var(--space-4); display:flex; flex-direction:column; gap:var(--space-3); }
.dmt-guide-head{ display:flex; align-items:baseline; gap:var(--space-2); }
.dmt-guide-head strong{ flex:1; font-family:var(--font-display); font-size:var(--text-lg); font-weight:700; color:var(--ink); }
.dmt-guide-head span{ font-size:var(--text-xs); color:var(--text-muted); white-space:nowrap; }
.dmt-steps{ margin:0; padding:0; list-style:none; display:flex; flex-direction:column; gap:var(--space-2); font-size:var(--text-md); color:var(--ink-soft); }
.dmt-steps li{ display:flex; align-items:center; gap:var(--space-2); }
.dmt-steps b{ width:22px; height:22px; flex:none; border-radius:50%; background:var(--sage-soft); color:var(--sage-ink); font-size:var(--text-xs); font-weight:700; display:flex; align-items:center; justify-content:center; }
.dmt-go{ width:100%; min-height:var(--touch); justify-content:center; }
.dmt-ask{ display:flex; gap:var(--space-2); padding:var(--space-3); border-top:1px solid var(--line); background:var(--paper-raised); }
.dmt-ask input{ flex:1; min-width:0; height:var(--touch); box-sizing:border-box; border:1px solid var(--line); border-radius:var(--radius-pill); padding:0 var(--space-4); font:inherit; font-size:var(--text-md); background:var(--subtle-bg); color:var(--ink); }
.dmt-ask input:focus{ border-color:var(--sage); outline:none; box-shadow:0 0 0 3px var(--sage-soft); }
.dmt-send{ width:var(--touch); height:var(--touch); flex:none; border:0; border-radius:50%; background:var(--btn-bg); color:var(--btn-ink); display:flex; align-items:center; justify-content:center; cursor:pointer; }
.dmt-send:hover:not(:disabled){ background:var(--btn-hover); }
.dmt-send:disabled{ opacity:.5; cursor:default; }

/* ---------- the walkthrough: a gold ring, as the CRM's focus ring ---------- */
.dmt-ring{
  position:fixed; z-index:1400; pointer-events:none; border-radius:var(--radius-md);
  box-shadow:0 0 0 3px var(--dmt-gold), 0 0 0 9px rgba(255,190,42,.35), 0 0 0 9999px rgba(0,5,64,.50);
  transition:left .18s ease, top .18s ease, width .18s ease, height .18s ease;
}
.dmt-card{
  position:fixed; z-index:1450; width:360px; max-width:calc(100vw - 24px); box-sizing:border-box;
  background:var(--paper-raised); color:var(--ink); border:1px solid var(--line); border-radius:var(--radius-lg); padding:var(--space-4) var(--space-5) var(--space-4);
  box-shadow:0 24px 64px rgba(0,5,64,.35); display:flex; flex-direction:column; gap:var(--space-3);
}
.dmt-card .dmt-eyebrow{ color:var(--text-muted); letter-spacing:.08em; }
.dmt-card-top{ display:flex; align-items:center; gap:var(--space-2); margin-right:calc(-1 * var(--space-3)); }
.dmt-card-top .dmt-eyebrow{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.dmt-card-title{ font-family:var(--font-display); font-size:var(--text-xl); font-weight:700; line-height:1.25; color:var(--ink); }
.dmt-card-body{ margin:0; font-size:var(--text-md); line-height:1.5; color:var(--ink-soft); }
.dmt-progress{ display:flex; gap:var(--space-1); }
.dmt-progress span{ flex:1; height:5px; border-radius:3px; background:var(--line); }
.dmt-progress span.on{ background:var(--btn-bg); }
.dmt-card-actions{ display:flex; align-items:center; gap:var(--space-2); }
.dmt-card-actions .dmt-quiet{ flex:1; }
.dmt-card-actions .btn{ min-height:var(--touch); }
.dmt-arrow{ position:absolute; width:16px; height:16px; background:var(--paper-raised); transform:rotate(45deg); border-radius:3px; }
.dmt-arrow.up{ top:-8px; border-left:1px solid var(--line); border-top:1px solid var(--line); }
.dmt-arrow.down{ bottom:-8px; border-right:1px solid var(--line); border-bottom:1px solid var(--line); }

/* ---------- comment mode ---------- */
body.dmt-commenting, body.dmt-commenting *{ cursor:crosshair !important; }
body.dmt-commenting #dmt-root, body.dmt-commenting #dmt-root *{ cursor:auto !important; }
body.dmt-commenting #dmt-root button{ cursor:pointer !important; }
.dmt-hover{ position:fixed; z-index:1250; pointer-events:none; border:2px dashed var(--dmt-pin); border-radius:var(--radius-md); }
.dmt-hover-tag{ position:absolute; left:-2px; top:calc(100% + 6px); background:var(--dmt-pin); color:var(--dmt-pin-ink); border-radius:var(--radius-sm); padding:3px var(--space-2); font-size:var(--text-xs); white-space:nowrap; }
.dmt-hint{ position:fixed; z-index:1500; background:var(--dmt-bar); color:#fff; border:1px solid var(--dmt-gold); border-radius:var(--radius-md); padding:var(--space-2) var(--space-3); font-size:var(--text-sm); white-space:nowrap; box-shadow:0 6px 18px rgba(0,5,64,.25); }
.dmt-pins{ position:fixed; inset:0; z-index:1200; pointer-events:none; }
.dmt-pin{
  position:absolute; transform:translate(-4px, calc(-100% + 4px)); pointer-events:auto;
  width:32px; height:32px; padding:0; border:2px solid var(--paper-raised); border-radius:50% 50% 50% 4px;
  background:var(--dmt-pin); color:var(--dmt-pin-ink); font:inherit; font-size:var(--text-sm); font-weight:700; cursor:pointer;
  box-shadow:0 3px 10px rgba(0,5,64,.25); display:flex; align-items:center; justify-content:center;
}
.dmt-pin.on{ background:var(--dmt-pin-on); box-shadow:0 0 0 4px var(--dmt-gold), 0 3px 10px rgba(0,5,64,.25); }
.dmt-pin.static{ position:static; transform:none; width:26px; height:26px; flex:none; font-size:var(--text-xs); box-shadow:none; border:0; cursor:default; }

/* A thread, or a new comment being written */
.dmt-pop{
  position:fixed; z-index:1500; width:400px; max-width:calc(100vw - 24px);
  background:var(--paper-raised); color:var(--ink); border:1px solid var(--line); border-radius:var(--radius-lg); overflow:hidden;
  box-shadow:var(--dmt-shadow);
}
.dmt-pop-head{ display:flex; align-items:center; gap:var(--space-2); padding:var(--space-2) var(--space-2) var(--space-2) var(--space-4); border-bottom:1px solid var(--line); }
.dmt-pop-head > span{ flex:1; min-width:0; font-size:var(--text-sm); color:var(--text-muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.dmt-pop-head strong{ color:var(--ink); font-weight:700; }
.dmt-pop-head .btn{ display:inline-flex; align-items:center; gap:var(--space-1); }
.dmt-pop-write{ padding:var(--space-3) var(--space-4) var(--space-4); display:flex; flex-direction:column; gap:var(--space-3); }
.dmt-pop-write textarea{ width:100%; box-sizing:border-box; border:1px solid var(--line); border-radius:var(--radius-md); padding:var(--space-2) var(--space-3); font:inherit; font-size:var(--text-md); line-height:1.45; resize:vertical; background:var(--paper-raised); color:var(--ink); }
.dmt-pop-write textarea:focus{ border-color:var(--sage); outline:none; box-shadow:0 0 0 3px var(--sage-soft); }
.dmt-pop-foot{ display:flex; align-items:center; gap:var(--space-3); }
.dmt-pop-foot .dmt-quiet{ flex:1; }
.dmt-pop-foot .btn{ min-height:var(--touch); padding-left:var(--space-5); padding-right:var(--space-5); }
.dmt-posts{ max-height:300px; overflow-y:auto; padding:var(--space-4); display:flex; flex-direction:column; gap:var(--space-4); }
.dmt-post{ display:flex; gap:var(--space-2); }
.dmt-post p{ margin:var(--space-1) 0 0; font-size:var(--text-md); line-height:1.5; white-space:pre-line; overflow-wrap:anywhere; }
.dmt-av{ width:32px; height:32px; flex:none; border-radius:50%; background:var(--sage-soft); color:var(--sage-ink); font-family:var(--font-display); font-size:var(--text-xs); font-weight:700; display:flex; align-items:center; justify-content:center; }
.dmt-who{ font-size:var(--text-sm); color:var(--text-muted); }
.dmt-who strong{ color:var(--ink); font-weight:700; }
.dmt-reply{ display:flex; gap:var(--space-2); padding:var(--space-3); border-top:1px solid var(--line); }
.dmt-reply input{ flex:1; min-width:0; height:var(--touch); box-sizing:border-box; border:1px solid var(--line); border-radius:var(--radius-md); padding:0 var(--space-3); font:inherit; font-size:var(--text-md); background:var(--subtle-bg); color:var(--ink); }
.dmt-reply .btn{ min-height:var(--touch); }
.dmt-del{ display:block; width:100%; min-height:var(--touch); border:0; border-top:1px solid var(--line); background:transparent; color:var(--brick); font:inherit; font-size:var(--text-sm); cursor:pointer; }
.dmt-del:hover{ background:var(--brick-soft); }

/* ---------- every comment ---------- */
.dmt-drawer{
  position:fixed; z-index:1500; top:0; right:0; bottom:0; width:440px; max-width:100vw;
  background:var(--paper-raised); color:var(--ink); border-left:1px solid var(--line); box-shadow:-20px 0 60px rgba(0,5,64,.18);
  display:flex; flex-direction:column;
}
.dmt-drawer-head{ display:flex; align-items:center; gap:var(--space-2); padding:var(--space-5) var(--space-4) var(--space-3) var(--space-5); }
.dmt-drawer-head strong{ flex:1; font-family:var(--font-display); font-size:var(--text-xl); font-weight:700; }
.dmt-drawer-filters{ display:flex; flex-direction:column; gap:var(--space-2); padding:0 var(--space-5) var(--space-3); border-bottom:1px solid var(--line); }
.dmt-drawer-filters .seg button{ flex:0 1 auto; }
.dmt-drawer-list{ flex:1; overflow-y:auto; padding:var(--space-4) var(--space-5) var(--space-7); display:flex; flex-direction:column; gap:var(--space-4); }
.dmt-group{ display:flex; flex-direction:column; gap:var(--space-2); }
.dmt-group > .dmt-eyebrow{ color:var(--text-muted); letter-spacing:.08em; }
.dmt-item{ border:1px solid var(--line); border-radius:var(--radius-md); padding:var(--space-3); display:flex; gap:var(--space-3); background:var(--paper-raised); }
.dmt-item-main{ flex:1; min-width:0; display:flex; flex-direction:column; gap:var(--space-1); }
.dmt-item-main p{ margin:0; font-size:var(--text-md); line-height:1.45; overflow-wrap:anywhere; }
.dmt-item-foot{ display:flex; align-items:center; gap:var(--space-3); }
.dmt-link{ min-height:32px; padding:0; border:0; background:transparent; color:var(--sage-ink); font:inherit; font-size:var(--text-sm); font-weight:700; text-decoration:underline; cursor:pointer; }

/* The bar floats over the foot of the page at every width, so while it sits in
   its own place the page ends higher: the last row of a list is never under it
   (audit 2026-11-16: Targets' last venue sat under the bar at full scroll). */
body:has(#dmt-bar:not([hidden]):not(.placed)) #view-root{ padding-bottom:calc(var(--space-7) + var(--space-3)); }
/* A tall pop-up's footer sticks to the foot of the screen, where the centered bar
   sat over its buttons (audit 2026-11-16: Cancel on Send report was hidden). While
   a pop-up is open the bar waits in the bottom left corner, over the dimmed menu;
   pop-ups put their buttons on the right. */
@media (min-width:821px){
  body:has(#modal-root .overlay) .dmt-bar:not(.placed){ left:var(--space-5); transform:none; }
}

/* ---------- a phone: the bar sits above the tab bar, panels are sheets ---------- */
@media (max-width:820px){
  /* Clear of the tab bar (66px) and the gold wheel that rises 22px out of it. */
  .dmt-bar{ bottom:calc(66px + 22px + var(--space-3) + env(safe-area-inset-bottom)); padding:var(--space-1); gap:2px; }
  /* The bar floats over the foot of the page, so the page ends higher while it
     sits there: the last thing on a screen is never under it. Moved elsewhere
     (.placed), it needs no room. */
  body:has(#dmt-bar:not([hidden]):not(.placed)) #view-root{ padding-bottom:calc(var(--space-7) + var(--space-5)); }
  .dmt-tool{ width:56px; height:48px; min-height:48px !important; }
  .dmt-tool span{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }
  .dmt-badge{ top:3px; right:4px; }
  .dmt-bar.touring{ left:var(--space-3); right:var(--space-3); transform:none; padding:0 var(--space-2) 0 var(--space-4); min-height:62px; }
  .dmt-bar.touring .dmt-brand{ flex:1; max-width:none; min-width:0; padding:0; }
  .dmt-bar.touring .dmt-sep{ display:none; }
  .dmt-bar.touring .dmt-txt.on{ display:none; }
  .dmt-panel{ left:0 !important; right:0; bottom:0 !important; top:auto !important; width:auto; max-height:calc(100vh - 100px); height:calc(100vh - 120px); border-radius:var(--space-5) var(--space-5) 0 0; border-bottom:0; }
  .dmt-ask{ padding-bottom:calc(var(--space-3) + env(safe-area-inset-bottom)); }
  .dmt-ask input, .dmt-reply input, .dmt-pop-write textarea{ font-size:16px; }
  .dmt-pop{ left:0 !important; right:0; bottom:0; top:auto !important; width:auto; max-width:none; border-radius:var(--space-5) var(--space-5) 0 0; border-bottom:0; padding-bottom:env(safe-area-inset-bottom); }
  .dmt-drawer{ width:100vw; border-left:0; }
  .dmt-hint{ white-space:normal; max-width:calc(100vw - 32px); text-align:center; }
  .dmt-card{ width:auto; }
  /* A walkthrough scrolls its element to the top of a phone (dmtScrollTo), clear of
     the top bar and a venue's sticky action bar, so the card above the tab bar
     leaves it in view (audit 2026-11-16: the card covered the window picker). */
  body:has(.dmt-bar.touring) [data-guide]{ scroll-margin-top:calc(var(--space-7) * 2 + var(--space-5)); }
  body.has-dmt .dmt-panel:not([hidden]) ~ .dmt-bar, body.has-dmt .dmt-pop:not([hidden]) ~ .dmt-bar, body.has-dmt .dmt-drawer:not([hidden]) ~ .dmt-bar{ display:none; }
}
@media (prefers-reduced-motion:reduce){ .dmt-ring{ transition:none; } }
