/* DTW incident toolbar refinement */
#toolbar {
  flex-wrap: nowrap !important;
  gap: 8px !important;
  min-width: 0;
  padding: 8px 10px !important;
  overflow: visible !important;
}

#toolbar > .spacer { flex: 0 0 2px !important; }
#toolbar button,
#toolbar .dropdown-toggle,
#toolbar select {
  min-height: 40px !important;
  padding: 0 12px !important;
  border: 1px solid #657483 !important;
  border-radius: 8px !important;
  background: #3c4956;
  color: #fff;
  font-size: 15px !important;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

#toolbar button:focus-visible,
.dtw-menu-button:focus-visible,
.dtw-sidebar-toggle:focus-visible,
.dtw-brand-link:focus-visible {
  outline: 3px solid #5cc8ff !important;
  outline-offset: 2px;
}

#btnModePen,
#btnModeErase { min-width: 74px; }
#btnUndo,
#btnRedo { min-width: 48px; width: 48px; padding: 0 !important; font-size: 0 !important; }
#btnUndo::before { content: "↶"; font-size: 25px; line-height: 1; }
#btnRedo::before { content: "↷"; font-size: 25px; line-height: 1; }
#btnMoreActions { min-width: 48px; width: 48px; padding: 0 !important; font-size: 0 !important; }
#btnMoreActions::before { content: "•••"; font-size: 19px; letter-spacing: 2px; }

/* Strong, consistent selected-state feedback */
#toolbar button.dtw-tool-active,
#toolbar button[aria-pressed="true"],
#toolbar .dtw-menu-button[aria-expanded="true"],
#toolbar select.dtw-has-selection {
  background: #0878b9 !important;
  border-color: #67d0ff !important;
  color: #fff !important;
  box-shadow: 0 0 0 2px rgba(73,190,244,.25), 0 4px 12px rgba(0,0,0,.28) !important;
}
#toolbar #btnModePen.dtw-tool-active {
  background: #0a78c2 !important;
  border-color: #78d3ff !important;
}
#toolbar #btnModeErase.dtw-tool-active {
  background: #b83280 !important;
  border-color: #f9a8d4 !important;
}
#toolbar #initParBtn.par-active {
  background: #c62828 !important;
  border-color: #ff8a80 !important;
}

#modeLabel,
.dtw-worksheet-mark:not(.dtw-brand-watermark) { display: none !important; }

.toolbar-dropdown { position: relative; }
.dropdown-menu,
.dtw-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 15000;
  display: none;
  min-width: 250px;
  max-height: min(70vh, 590px);
  overflow-y: auto;
  padding: 8px;
  border: 1px solid #657483;
  border-radius: 12px;
  background: #26313b;
  box-shadow: 0 14px 34px rgba(0,0,0,.38);
}
.dropdown-menu.open,
.dtw-popover.open { display: grid !important; gap: 6px; }
.dropdown-menu button,
.dtw-popover button {
  width: 100%;
  min-height: 48px !important;
  justify-content: flex-start !important;
  margin: 0 !important;
  padding: 0 14px !important;
  border-color: transparent !important;
  background: #3d4a56 !important;
  text-align: left;
}
.dtw-popover button[aria-checked="true"] {
  border-color: #62c8ff !important;
  background: #176ca7 !important;
}
.dtw-popover button[aria-checked="true"]::after {
  content: "✓";
  margin-left: auto;
}
.dtw-menu-section {
  padding: 8px 10px 2px;
  color: #aebdca;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.dtw-popover--map { grid-template-columns: repeat(2, minmax(126px, 1fr)); min-width: 286px; }
.dtw-popover--map .dtw-menu-section { grid-column: 1 / -1; }

@media (max-width: 1366px) {
  #toolbar { gap: 6px !important; }
  #toolbar button,
  #toolbar .dropdown-toggle,
  #toolbar select { padding-inline: 10px !important; font-size: 14px !important; }
  #btnModePen,
  #btnModeErase { min-width: 66px; }
}

@media (max-width: 1100px) {
  #toolbar {
    gap: 4px !important;
    padding: 5px 6px !important;
    min-height: 46px !important;
  }
  #toolbar button,
  #toolbar .dropdown-toggle,
  #toolbar select {
    min-height: 36px !important;
    height: 36px !important;
    padding-inline: 8px !important;
    border-radius: 7px !important;
    font-size: 12px !important;
  }
  #btnUndo,
  #btnRedo,
  #btnMoreActions { width: 38px !important; min-width: 38px !important; }
  #btnModePen,
  #btnModeErase { min-width: 54px !important; }
  #toolbar .command-assist-label-long { display: none; }

}

@media print {
  .dtw-brand-link,
  .dtw-sidebar-toggle { display: none !important; }
}

/* Body-level menus escape the toolbar's touch-scrolling clipping context. */
body > .dtw-popover {
  position: fixed !important;
  right: auto !important;
  bottom: auto !important;
  z-index: 2147483647 !important;
  min-width: 0 !important;
  box-sizing: border-box;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  grid-auto-rows: min-content;
  align-content: start;
}
body > .dtw-popover button {
  height: auto !important;
  min-height: 44px !important;
  padding: 10px 12px !important;
  font: 600 14px/1.3 Arial, sans-serif !important;
  white-space: normal !important;
  color: #fff !important;
  border: 1px solid #657483 !important;
  border-radius: 6px;
  cursor: pointer;
}
body > .dtw-popover button:disabled { opacity: .45; cursor: not-allowed; }
body #moreMenu.open {
  overflow-y: auto !important;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  grid-auto-rows: min-content;
  align-content: start;
}
body #toolbar #btnUndo, body #toolbar #btnRedo {
  width: auto !important;
  min-width: 54px !important;
  font-size: calc(.875rem * var(--dtw-control-scale, 1)) !important;
}
body #toolbar #btnUndo::before, body #toolbar #btnRedo::before { content: none !important; }
body #toolbar #btnMoreActions { font-size: 0 !important; }
body #toolbar #btnToggleSidebar { display: inline-flex !important; }
body #toolbar #btnModePen[aria-pressed="true"] { background: #0a78c2 !important; }
body #toolbar #btnModeErase[aria-pressed="true"] { background: #b83280 !important; }
body #toolbar #btnRadioAssistRecord[aria-pressed="true"] { background: #0878b9 !important; }

.dtw-worksheet-mark, .dtw-brand-link { display: none !important; }

/* Toolbar placement follows the existing unit-menu order (Unit 40, Text 50). */
body #toolbar > #btnToggleSidebar {
  order: -10 !important;
  margin-left: 0 !important;
}
body #toolbar > .dtw-map-control { order: 45 !important; }
body #toolbar > .dtw-more-control { order: 140 !important; }

/* Generated menu triggers share the same size and surface as native controls. */
body #toolbar .dtw-enhanced-select > .dtw-menu-button,
body #toolbar #btnMoreActions {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  height: calc(var(--dtw-control-height, 2.5rem) * var(--dtw-control-scale, 1)) !important;
  min-height: calc(var(--dtw-control-height, 2.5rem) * var(--dtw-control-scale, 1)) !important;
  width: auto !important;
  min-width: calc(54px * var(--dtw-control-scale, 1)) !important;
  padding: 0 calc(11px * var(--dtw-control-scale, 1)) !important;
  border: 1px solid #ffffff38 !important;
  border-radius: var(--dtw-control-radius, 6px) !important;
  background: #3b4855 !important;
  color: #f8fafc !important;
  font: 600 calc(.875rem * var(--dtw-control-scale, 1))/1.2 Arial, sans-serif !important;
  letter-spacing: 0 !important;
}
body #toolbar .dtw-more-control > .dtw-menu-button {
  font-size: calc(19px * var(--dtw-control-scale, 1)) !important;
}
body #toolbar #btnMoreActions { font-size: 0 !important; }
body #toolbar #btnMoreActions::before {
  font-size: calc(19px * var(--dtw-control-scale, 1)) !important;
}
body #toolbar .dtw-enhanced-select > .dtw-menu-button[aria-expanded="true"] {
  background: #0878b9 !important;
  border-color: #67d0ff !important;
}
/* New Incident clears the worksheet and its incident report. */
body > .dtw-popover button.dtw-menu-danger,
body #moreMenu #btnNewIncident {
  background: #7a2620 !important;
  border-color: #b2483f !important;
  color: #fff !important;
}
