/* ============================================================================
   Mainline — Modern Farm Water Design, Built for the Field
   Stylesheet: Dark GIS Workspace, Glass Pipe Badges, Draggable Widgets & A4 Print
   ============================================================================ */

html,
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: #0b1120;
  color: #e2e8f0;
  overflow: hidden;
  max-width: 100vw;
}

.font-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Custom Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* Map Node Badges & Pulse Animations */
.map-node-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.65);
  transition: transform 0.15s ease;
}

@keyframes activePulse {
  0%   { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.9), 0 4px 12px rgba(0,0,0,0.65); }
  70%  { box-shadow: 0 0 0 13px rgba(56, 189, 248, 0), 0 4px 12px rgba(0,0,0,0.65); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0), 0 4px 12px rgba(0,0,0,0.65); }
}

.active-parent-ring {
  animation: activePulse 1.6s infinite;
  outline: 2.5px solid #38bdf8 !important;
  outline-offset: 2px;
}

@keyframes selectedPulse {
  0%   { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.95), 0 0 16px rgba(250, 204, 21, 0.85); }
  70%  { box-shadow: 0 0 0 16px rgba(250, 204, 21, 0), 0 0 16px rgba(250, 204, 21, 0.55); }
  100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0), 0 0 16px rgba(250, 204, 21, 0.85); }
}

.selected-node-ring {
  animation: selectedPulse 1.3s infinite;
  outline: 3px solid #facc15 !important;
  outline-offset: 3px;
  transform: scale(1.18);
  z-index: 1000 !important;
}

/* Compact 2-Line Auto-Sizing Glass Pipe Badges */
.pipe-label-marker {
  background: transparent !important;
  border: none !important;
  overflow: visible !important;
}

.pipe-label-pill {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: max-content;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  background: rgba(9, 15, 30, 0.88);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  border: 1px solid rgba(148, 163, 184, 0.38);
  border-radius: 7px;
  padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  line-height: 1.28;
  color: #e2e8f0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  gap: 1px;
}

.pipe-label-pill.is-selected {
  border-color: rgba(250, 204, 21, 0.85);
  box-shadow: 0 0 0 1.5px rgba(250, 204, 21, 0.35), 0 4px 14px rgba(0, 0, 0, 0.7);
}

.pipe-label-pill.is-compact {
  padding: 1px 5px;
  font-size: 9px;
  border-radius: 5px;
  background: rgba(9, 15, 30, 0.82);
}

.pipe-label-pill.is-ring {
  border-color: rgba(129, 140, 248, 0.65);
}

.pipe-label-line1,
.pipe-label-line2 {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.pipe-label-sep {
  color: #64748b;
}

/* Hydraulic Flow Direction Arrows & Animated Stream Pulses on Map */
.pipe-flow-arrow-marker {
  background: transparent !important;
  border: none !important;
  pointer-events: none !important;
  overflow: visible !important;
}

.pipe-flow-arrow-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.85));
}

@keyframes pipeFlowMarch {
  from { stroke-dashoffset: 26; }
  to   { stroke-dashoffset: 0; }
}

@keyframes pipeArrowGlide {
  0%, 100% { transform: translateX(-2.2px) scale(0.96); opacity: 0.78; }
  50%      { transform: translateX(2.4px) scale(1.06); opacity: 1; }
}

.pipe-flow-pulse {
  pointer-events: none !important;
  animation: pipeFlowMarch 0.95s linear infinite;
}
.pipe-flow-pulse.pipe-flow-slow  { animation-duration: 1.45s; }
.pipe-flow-pulse.pipe-flow-med   { animation-duration: 0.95s; }
.pipe-flow-pulse.pipe-flow-fast  { animation-duration: 0.62s; }
.pipe-flow-pulse.pipe-flow-turbo { animation-duration: 0.40s; }

.pipe-flow-arrow-svg {
  display: block;
  will-change: transform, opacity;
  animation: pipeArrowGlide 1.15s ease-in-out infinite;
}
.pipe-flow-arrow-svg.pipe-flow-slow  { animation-duration: 1.65s; }
.pipe-flow-arrow-svg.pipe-flow-med   { animation-duration: 1.15s; }
.pipe-flow-arrow-svg.pipe-flow-fast  { animation-duration: 0.80s; }
.pipe-flow-arrow-svg.pipe-flow-turbo { animation-duration: 0.55s; }

@media (prefers-reduced-motion: reduce) {
  .pipe-flow-pulse, .pipe-flow-arrow-svg { animation: none !important; }
}
@media print {
  .pipe-flow-pulse { display: none !important; }
  .pipe-flow-arrow-svg { animation: none !important; opacity: 1 !important; transform: none !important; }
}

/* Draggable Map Widgets */
.map-floating-widget {
  position: absolute;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

.map-floating-widget.is-dragging {
  cursor: grabbing;
  z-index: 980 !important;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.75), 0 0 0 1.5px rgba(56, 189, 248, 0.7) !important;
  opacity: 0.96;
}

.widget-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  color: #64748b;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: -1px;
  padding: 1px 4px;
  border-radius: 4px;
  transition: color 0.15s ease, background-color 0.15s ease;
  touch-action: none;
}

.widget-drag-handle:hover {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.14);
}

.map-floating-widget.is-dragging .widget-drag-handle {
  cursor: grabbing;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.2);
}

/* Leaflet dark popup styling */
.leaflet-popup-content-wrapper {
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.65);
}

.leaflet-popup-tip {
  background: #0f172a;
}

.leaflet-container {
  background: #0b1120;
}

.leaflet-bottom.leaflet-left .leaflet-control-zoom {
  margin-bottom: 96px;
  margin-left: 76px;
  border: 1px solid #334155 !important;
  border-radius: 10px !important;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55) !important;
}

.leaflet-control-zoom a {
  background: #0f172a !important;
  color: #e2e8f0 !important;
  border-bottom-color: #334155 !important;
}

.leaflet-control-zoom a:hover {
  background: #1e293b !important;
  color: #38bdf8 !important;
}

/* Resizable Sidebar Splitter Handle */
#sidebarResizeHandle {
  width: 10px;
  cursor: col-resize;
  touch-action: none;
  background: #0f172a;
  border-left: 1px solid #1e293b;
  border-right: 1px solid #1e293b;
  transition: background-color 0.15s ease;
}

#sidebarResizeHandle:hover,
#sidebarResizeHandle.resizing {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.65);
}

#sidebarResizeHandle .grip-dots {
  width: 4px;
  height: 44px;
  border-radius: 9999px;
  background: repeating-linear-gradient(
    to bottom,
    #64748b 0px,
    #64748b 3px,
    transparent 3px,
    transparent 7px
  );
  transition: background 0.15s ease;
}

#sidebarResizeHandle:hover .grip-dots,
#sidebarResizeHandle.resizing .grip-dots {
  background: repeating-linear-gradient(
    to bottom,
    #38bdf8 0px,
    #38bdf8 3px,
    transparent 3px,
    transparent 7px
  );
}

body.is-resizing-sidebar {
  cursor: col-resize !important;
  user-select: none !important;
}

body.is-resizing-sidebar #map,
body.is-resizing-sidebar #terrain3DCanvasHost {
  pointer-events: none;
}

/* Node Inspector Enhanced Readability */
#nodeInspectorBox label {
  color: #94a3b8;
  font-size: 10.5px;
  font-weight: 500;
}

#nodeInspectorBox input[type="number"],
#nodeInspectorBox input[type="text"],
#nodeInspectorBox select {
  font-size: 12px;
}

/* CSS Container Queries for Auto-Resizing Sidebar Boxes */
.sidebar-container {
  container-type: inline-size;
  container-name: sidebar;
}

.auto-grid-2 {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.5rem;
}

.auto-grid-3 {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.5rem;
}

.auto-grid-fittings {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.35rem;
}

.auto-grid-wq {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.5rem;
}

.auto-chart-box {
  height: 14rem;
}

@container sidebar (min-width: 340px) {
  .auto-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auto-grid-wq { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@container sidebar (min-width: 370px) {
  .auto-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@container sidebar (min-width: 540px) {
  .auto-grid-fittings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auto-grid-wq { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .auto-chart-box { height: 18rem; }
}

@container sidebar (min-width: 740px) {
  .auto-grid-fittings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .auto-grid-wq { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .auto-chart-box { height: 22rem; }
}

/* Print A4 Branded Farmer Proposal & MPNZ Student Calculation Report */
#printReportSheet {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 14mm 14mm 16mm 14mm;
  }

  html, body {
    background: #ffffff !important;
    color: #0f172a !important;
    overflow: visible !important;
    height: auto !important;
    width: auto !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #appRoot, #customModal, #toastBanner, #siteQuestionnaireModal, #labImportModal, #autoDesignerModal, #mobileFieldDock, #mobileFieldPinSheet, #mainlineHelpModal, #mainlineLicenseModal {
    display: none !important;
  }

  #printReportSheet {
    display: block !important;
    padding: 0;
    background: #ffffff;
    color: #0f172a;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 10.5px;
    line-height: 1.45;
  }

  #printReportSheet .proposal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    border-bottom: 2.5px solid #0284c7;
    padding-bottom: 12px;
    margin-bottom: 14px;
  }

  #printReportSheet .proposal-logo {
    max-height: 62px;
    max-width: 190px;
    object-fit: contain;
    display: block;
    margin-bottom: 6px;
  }

  #printReportSheet .proposal-section-title {
    font-size: 12.5px;
    font-weight: 800;
    color: #0369a1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 3px;
    margin: 16px 0 8px;
    page-break-after: avoid;
  }

  #printReportSheet .proposal-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 10px;
    page-break-inside: avoid;
  }

  #printReportSheet .proposal-map-figure {
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    overflow: hidden;
    margin: 8px 0 12px;
    background: #0b1120;
    page-break-inside: avoid;
  }

  #printReportSheet .proposal-map-img {
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: contain;
    display: block;
  }

  #printReportSheet .proposal-map-caption {
    background: #f1f5f9;
    color: #334155;
    font-size: 9px;
    padding: 4px 8px;
    border-top: 1px solid #cbd5e1;
    display: flex;
    justify-content: space-between;
  }

  #printReportSheet table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0 12px;
    font-size: 9.8px;
  }

  #printReportSheet th,
  #printReportSheet td {
    border: 1px solid #cbd5e1;
    padding: 5px 7px;
    text-align: left;
    vertical-align: top;
  }

  #printReportSheet th {
    background: #f1f5f9;
    font-weight: 700;
    color: #0f172a;
  }

  #printReportSheet tr {
    page-break-inside: avoid;
  }

  #printReportSheet .num {
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
  }

  #printReportSheet .totals-row td {
    background: #f1f5f9;
    font-weight: 700;
  }

  #printReportSheet .grand-total-row td {
    background: #0f172a;
    color: #ffffff;
    font-weight: 800;
    font-size: 11px;
  }

  #printReportSheet .sig-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 16px;
    page-break-inside: avoid;
  }

  #printReportSheet .sig-line {
    border-bottom: 1px solid #475569;
    height: 28px;
    margin-bottom: 4px;
  }

  .page-break {
    page-break-before: always;
  }
}

/* ============================================================================
   WAVE 4: LEFT VERTICAL CAD TOOL RAIL, SCROLLABLE TABS & CONTEXT MENU
   ============================================================================ */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.cad-rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  padding: 5px 2px;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  transition: background-color 0.14s ease, color 0.14s ease, transform 0.1s ease;
}

.cad-rail-btn:active {
  transform: scale(0.95);
}

.ctx-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  color: inherit;
  transition: background-color 0.12s ease;
}

.ctx-menu-item:hover {
  background: rgba(56, 189, 248, 0.16);
}

.ctx-label {
  display: block;
  font-size: 9.5px;
  color: #94a3b8;
  margin-bottom: 2px;
  font-weight: 600;
}

.ctx-input {
  background: #0b1120;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 10.5px;
  color: #f8fafc;
  outline: none;
}

.ctx-input:focus {
  border-color: #38bdf8;
}

.ctx-step-btn {
  padding: 3px 6px;
  border-radius: 6px;
  background: #1e293b;
  border: 1px solid #475569;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  transition: background-color 0.12s ease;
}

.ctx-step-btn:hover {
  background: #334155;
}

.ctx-chip {
  padding: 4px 6px;
  border-radius: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.ctx-chip:hover {
  background: #334155;
  border-color: #64748b;
}

.ctx-pill {
  padding: 3px 4px;
  border-radius: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  font-weight: 700;
  color: #cbd5e1;
  text-align: center;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.ctx-pill:hover {
  background: #334155;
}

.ctx-pill.is-active {
  background: #0284c7;
  border-color: #38bdf8;
  color: #ffffff;
}

body.theme-sunlight .ctx-chip,
body.theme-sunlight .ctx-pill,
body.theme-sunlight .ctx-step-btn {
  background: #f1f5f9 !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
}

body.theme-sunlight .ctx-pill.is-active {
  background: #0284c7 !important;
  border-color: #0284c7 !important;
  color: #ffffff !important;
}

body.theme-sunlight .ctx-label {
  color: #475569 !important;
}

/* ============================================================================
   SUNLIGHT / FIELD MODE (HIGH-CONTRAST DAYLIGHT OUTDOOR THEME)
   ============================================================================ */
body.theme-sunlight {
  background-color: #f1f5f9;
  color: #0f172a;
}

body.theme-sunlight header,
body.theme-sunlight #sidebarDrawer,
body.theme-sunlight #leftCadRail,
body.theme-sunlight #widgetsDropdownMenu,
body.theme-sunlight #mapContextMenu,
body.theme-sunlight #velocityLegendWidget,
body.theme-sunlight #activeParentBanner,
body.theme-sunlight #boundaryOverlayWidget,
body.theme-sunlight #kmzOverlayWidget,
body.theme-sunlight .leaflet-popup-content-wrapper {
  background-color: rgba(255, 255, 255, 0.96) !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}

body.theme-sunlight .leaflet-popup-tip {
  background: #ffffff !important;
}

body.theme-sunlight nav,
body.theme-sunlight header .bg-\[\#0b1120\],
body.theme-sunlight #sidebarDrawer .bg-\[\#0b1120\],
body.theme-sunlight #sidebarDrawer .bg-\[\#0f172a\],
body.theme-sunlight #sidebarDrawer .bg-slate-900,
body.theme-sunlight #mapContainer .bg-\[\#0b1120\] {
  background-color: #f8fafc !important;
  border-color: #cbd5e1 !important;
}

body.theme-sunlight #sidebarDrawer .bg-\[\#1e293b\],
body.theme-sunlight #mapContainer .bg-\[\#0f172a\]\/95 {
  background-color: #ffffff !important;
  border-color: #cbd5e1 !important;
}

body.theme-sunlight #sidebarDrawer .bg-slate-800,
body.theme-sunlight header .bg-slate-800,
body.theme-sunlight #mapContainer .bg-slate-800 {
  background-color: #e2e8f0 !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}

body.theme-sunlight #sidebarDrawer .text-white,
body.theme-sunlight header .text-white,
body.theme-sunlight #mapContainer .text-white {
  color: #0f172a !important;
}

/* Preserve white text on solid coloured primary action buttons */
body.theme-sunlight button.bg-sky-600,
body.theme-sunlight button.bg-sky-700,
body.theme-sunlight button.bg-emerald-600,
body.theme-sunlight button.bg-cyan-700,
body.theme-sunlight button.bg-indigo-600,
body.theme-sunlight button.bg-amber-600,
body.theme-sunlight button.bg-rose-600,
body.theme-sunlight button.bg-purple-600,
body.theme-sunlight .bg-sky-600,
body.theme-sunlight .bg-emerald-600 {
  color: #ffffff !important;
}

body.theme-sunlight .text-slate-200,
body.theme-sunlight .text-slate-300 {
  color: #1e293b !important;
}

body.theme-sunlight .text-slate-400 {
  color: #475569 !important;
}

body.theme-sunlight .text-sky-300,
body.theme-sunlight .text-sky-200 {
  color: #0369a1 !important;
}

body.theme-sunlight .text-emerald-300,
body.theme-sunlight .text-emerald-200 {
  color: #047857 !important;
}

body.theme-sunlight .text-amber-300,
body.theme-sunlight .text-amber-200 {
  color: #b45309 !important;
}

body.theme-sunlight .text-rose-300,
body.theme-sunlight .text-rose-400 {
  color: #be123c !important;
}

body.theme-sunlight .text-cyan-300,
body.theme-sunlight .text-cyan-200 {
  color: #0e7490 !important;
}

body.theme-sunlight .text-purple-300,
body.theme-sunlight .text-indigo-300 {
  color: #4338ca !important;
}

body.theme-sunlight input,
body.theme-sunlight select,
body.theme-sunlight textarea {
  background-color: #ffffff !important;
  color: #0f172a !important;
  border-color: #94a3b8 !important;
}

body.theme-sunlight #sidebarResizeHandle {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

body.theme-sunlight .leaflet-control-zoom a {
  background: #ffffff !important;
  color: #0f172a !important;
  border-bottom-color: #cbd5e1 !important;
}

body.theme-sunlight .pipe-label-pill {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 23, 42, 0.45);
  color: #0f172a;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

body.theme-sunlight .pipe-label-pill span {
  color: #0f172a !important;
}

/* Simplified Mobile / Tablet Field Dock Clearance (< 1024px) */
@media (max-width: 1023px) {
  #velocityLegendWidget:not(.widget-user-moved) { bottom: 76px !important; left: 72px !important; }
  #activeParentBanner:not(.widget-user-moved) { bottom: 118px !important; left: 72px !important; }
  #sidebarDrawer { padding-bottom: 72px; }
  #leftCadRail { max-height: calc(100% - 86px) !important; }
}

/* Solid Opaque Dropdowns & Field Dock in Sunlight Mode */
body.theme-sunlight #headerToolsDropdown,
body.theme-sunlight #widgetsDropdownMenu,
body.theme-sunlight #mapContextMenu,
body.theme-sunlight #mobileFieldDock,
body.theme-sunlight #mobileFieldPinSheet {
  background-color: #ffffff !important;
  color: #0f172a !important;
  border-color: #94a3b8 !important;
}

/* LINZ 1m LiDAR Hillshade Relief Overlay */
.linz-hillshade-overlay {
  mix-blend-mode: multiply;
  pointer-events: none;
}
