/* Dashboard - main app, device rows, charts, modals */
.print-header,
.print-footer {
  display: none;
}

.app {
  max-width: 1200px;
  margin: 22px auto;
  padding: 0 14px 40px;
}

.topbar {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 260px;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  overflow: hidden;
  flex: 0 0 auto;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Fallback if image doesn't load */
.logo-fallback {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(102, 187, 106, 0.22), rgba(179, 229, 252, 0.55));
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0.2px;
  color: rgba(15, 23, 42, 0.9);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand .sub {
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 360px;
  min-width: 260px;
}

.search {
  flex: 1;
  min-width: 180px;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.search-icon {
  color: var(--muted);
  font-size: 14px;
  transition:
    opacity 0.15s ease,
    width 0.15s ease;
}

.search:focus-within .search-icon {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.search input {
  border: none;
  outline: none;
  width: 100%;
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  background: transparent;
  color: var(--text);
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: #fff;
  color: rgba(15, 23, 42, 0.92);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  white-space: nowrap;
}

.btn:hover {
  background: rgba(246, 247, 251, 0.75);
}

.btn:focus {
  outline: none;
  box-shadow:
    0 0 0 4px var(--focus),
    0 2px 10px rgba(15, 23, 42, 0.06);
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-reset {
  background: transparent;
  border-color: rgba(100, 116, 139, 0.25);
  color: rgba(100, 116, 139, 0.85);
  font-size: 14px;
  padding: 9px 12px;
}

.btn-reset:hover {
  background: rgba(239, 83, 80, 0.08);
  border-color: rgba(239, 83, 80, 0.3);
  color: var(--c3);
}

.btn-reset svg {
  width: 14px;
  height: 14px;
}

.btn-secondary {
  background: transparent;
  border-color: rgba(100, 116, 139, 0.3);
  color: rgba(100, 116, 139, 0.9);
}

.btn-secondary:hover {
  background: rgba(100, 116, 139, 0.08);
  border-color: rgba(100, 116, 139, 0.4);
}

.btn-primary {
  background: rgba(34, 139, 34, 0.92);
  border-color: rgba(34, 139, 34, 1);
  color: #fff;
}

.btn-primary:hover {
  background: rgba(34, 139, 34, 1);
}

.btn-danger {
  background: #dc3545;
  border-color: #dc3545;
  color: #fff;
}

.btn-danger:hover {
  background: #b02a37;
  border-color: #b02a37;
}

.btn-icon-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  border: 2px solid rgba(34, 139, 34, 0.8);
  background: rgba(34, 139, 34, 0.08);
  color: rgba(34, 139, 34, 0.9);
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-icon-add:hover {
  background: rgba(34, 139, 34, 0.92);
  border-color: rgba(34, 139, 34, 1);
  color: #fff;
}

.btn-icon-add svg {
  width: 22px;
  height: 22px;
}

/* Stage Manager — crop selector bar */
.stage-manager-modal {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.stage-crop-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.stage-crop-select {
  flex: 1;
  font-weight: 600;
}

.stage-unit-badge {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

/* Stage Manager — card list */
.stage-card-list {
  padding: 12px 24px 4px;
}

.stage-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: #fff;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.stage-card:hover {
  border-color: rgba(37, 99, 235, 0.25);
}

.stage-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.stage-card-body {
  flex: 1;
  min-width: 0;
}

.stage-card-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: none;
  padding: 0;
  width: 100%;
  outline: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

.stage-card-name:focus {
  border-bottom-color: var(--accent);
}

.stage-card-name:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.stage-card-desc {
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-card-trigger {
  display: flex;
  align-items: baseline;
  gap: 2px;
  flex-shrink: 0;
}

.stage-card-trigger .input,
.stage-add-fields .field-trigger .input {
  -moz-appearance: textfield;
}

.stage-card-trigger .input::-webkit-outer-spin-button,
.stage-card-trigger .input::-webkit-inner-spin-button,
.stage-add-fields .field-trigger .input::-webkit-outer-spin-button,
.stage-add-fields .field-trigger .input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stage-card-trigger .input {
  width: 56px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  padding: 6px 4px;
  border-radius: 6px;
}

.stage-card-trigger .trigger-unit {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.stage-card-action {
  flex-shrink: 0;
  margin-left: 4px;
}

/* Locked stage cards */
.stage-card.stage-locked {
  background: rgba(148, 163, 184, 0.06);
}

.stage-card.stage-locked .stage-card-icon {
  opacity: 0.6;
}

/* Stage Manager — add stage row */
.stage-add-row {
  padding: 0 24px 12px;
}

.stage-add-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px dashed rgba(37, 99, 235, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.stage-add-toggle:hover {
  background: rgba(37, 99, 235, 0.04);
  border-color: rgba(37, 99, 235, 0.5);
}

.stage-add-toggle svg {
  width: 16px;
  height: 16px;
}

.stage-add-row.expanded .stage-add-toggle {
  display: none;
}

.stage-add-fields {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

.stage-add-row.expanded .stage-add-fields {
  display: flex;
}

.stage-add-fields .field-stage {
  flex: 2;
  min-width: 0;
}

.stage-add-fields .field-trigger {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.stage-add-fields .field-trigger .input {
  width: 56px;
  text-align: center;
  padding: 6px 4px;
}

.stage-add-fields .field-suffix {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.stage-add-fields .btn-sm {
  padding: 7px 14px;
  font-size: 14px;
}

.stage-add-row.expanded #stageAddHint {
  display: block;
  margin-top: 8px;
  padding-left: 14px;
  font-size: 14px;
}

/* Stage Manager — drag states on cards */
.stage-card.dragging {
  opacity: 0.3;
  background: rgba(179, 229, 252, 0.15);
}

.stage-card.drag-over {
  border-top: 3px solid var(--c1);
  box-shadow: 0 -3px 10px rgba(102, 187, 106, 0.2);
}

.stage-card.drag-over-below {
  border-bottom: 3px solid var(--c1);
  box-shadow: 0 3px 10px rgba(102, 187, 106, 0.2);
}

/* Stage Manager — edit mode */
#stageModal.stage-edit-mode .stage-card {
  cursor: grab;
}

#stageModal.stage-edit-mode .stage-card:active {
  cursor: grabbing;
}

#stageModal.stage-edit-mode .stage-card.stage-locked {
  cursor: not-allowed;
  opacity: 0.7;
}

#stageModal.stage-edit-mode .stage-add-row,
#stageModal.stage-edit-mode .stage-card input,
#stageModal.stage-edit-mode .stage-card .btn-icon-muted,
#stageModal.stage-edit-mode #stageCropSelect,
#stageModal.stage-edit-mode #resetStagesBtn {
  pointer-events: none;
  opacity: 0.5;
}

.btn-icon-muted {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: none;
  background: transparent;
  color: rgba(100, 116, 139, 0.5);
  cursor: pointer;
  border-radius: 6px;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}

.btn-icon-muted:hover {
  color: rgba(239, 83, 80, 0.85);
  background: rgba(239, 83, 80, 0.08);
}

.btn-icon-muted svg {
  width: 18px;
  height: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.note {
  font-size: 14px;
  color: var(--muted);
  margin-top: 10px;
  padding: 0 16px 14px;
  line-height: 1.4;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex: 0 1 auto;
  flex-wrap: wrap;
}

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  text-align: right;
}

.legend .chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  display: inline-block;
}

.table-wrap {
  overflow: visible;
  -webkit-overflow-scrolling: touch;
}

tbody {
  overflow: visible;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 750px; /* gives desktop-friendly spacing; mobile uses card layout below */
}

.device-table {
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  color: rgba(15, 23, 42, 0.82);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 12px 12px;
  text-align: left;
  white-space: nowrap;
}

thead th:first-child {
  padding-left: 50px; /* 12px base + 38px (28px caret + 10px gap) */
}

/* Sortable column headers — desktop only */
@media (min-width: 769px) {
  thead th.sortable-th {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: color 0.15s;
  }
  thead th.sortable-th:hover {
    color: var(--accent);
  }
  thead th.sortable-th::after {
    content: "";
    display: inline-block;
    width: 0;
    margin-left: 4px;
    vertical-align: middle;
    opacity: 0;
    transition: opacity 0.15s;
  }
  thead th.sortable-th:hover::after {
    content: "⇅";
    opacity: 0.4;
  }
  thead th.sortable-th.sort-asc::after {
    content: "↑";
    opacity: 0.8;
  }
  thead th.sortable-th.sort-desc::after {
    content: "↓";
    opacity: 0.8;
  }
  thead th.sortable-th.sort-asc,
  thead th.sortable-th.sort-desc {
    color: var(--accent);
  }
}

tbody td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 15px;
  overflow: visible;
}
/* Tighten gap between stress reading and status bar */
tbody td[data-label="Stress"] {
  padding-right: 4px;
}
tbody td[data-label="Status"] {
  padding-left: 4px;
}

tbody tr.device-row:hover {
  background: rgba(179, 229, 252, 0.08);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
  transform: translateY(-1px);
}

tbody tr.device-row {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  overflow: visible;
  transition:
    box-shadow 0.15s ease,
    transform 0.15s ease,
    background 0.15s ease,
    border-left-color 0.3s ease;
  border-left: 4px solid transparent;
}

/* Stress-band left-edge color stripe */
tbody tr.device-row[data-stress-color] {
  border-left-color: var(--row-stress-color);
}
tbody tr.device-row[aria-expanded="true"] td {
  border-bottom-color: transparent;
}

tbody tr.device-row[data-expandable="1"] {
  cursor: pointer;
}

/* Drag and drop styles */
tbody tr.device-row.dragging {
  opacity: 0.3;
  background: rgba(179, 229, 252, 0.15);
}

tbody tr.device-row.drag-over {
  border-top: 3px solid var(--c1);
  box-shadow: 0 -4px 12px rgba(102, 187, 106, 0.25);
}

tbody tr.device-row.drag-over-below {
  border-bottom: 3px solid var(--c1);
  box-shadow: 0 4px 12px rgba(102, 187, 106, 0.25);
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.95;
  transform: scale(1.02) rotate(0.5deg);
  box-shadow:
    0 16px 48px rgba(15, 23, 42, 0.3),
    0 6px 16px rgba(15, 23, 42, 0.2);
  border-radius: 12px;
  background: #fff;
  border: 2px solid var(--c1);
  overflow: hidden;
  transition: transform 0.05s ease;
  user-select: none;
  -webkit-user-select: none;
}

.drag-ghost td {
  border: none;
}

body.is-dragging {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing;
}

body.is-dragging * {
  cursor: grabbing;
}

.drag-handle {
  display: none;
}

/* Edit mode - whole row is draggable, disable other interactions */
body.edit-mode tbody .device-row {
  cursor: grab;
}

body.edit-mode tbody .device-row:active {
  cursor: grabbing;
}

body.edit-mode .device-row .row-toggle,
body.edit-mode .device-row .stage-pill,
body.edit-mode .device-row .stress-tap,
body.edit-mode .device-row .pill,
body.edit-mode .device-row .status-wrap {
  pointer-events: none;
  opacity: 0.5;
}

/* Edit mode button active state */
#toggleEditMode[aria-pressed="true"] {
  background: rgba(59, 130, 246, 0.95);
  border-color: rgba(59, 130, 246, 1);
  color: #fff;
}

/* Keep already-expanded rows visible in edit mode (only those with .visible class) */
body.edit-mode tr.expansion-row.visible {
  display: table-row;
  visibility: visible;
}

.cell-main {
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-tip {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.25;
  margin-top: 4px;
}

.inline-flex {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row-toggle {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.row-toggle:hover {
  background: rgba(246, 247, 251, 0.75);
}

.row-toggle:focus {
  outline: none;
  box-shadow:
    0 0 0 4px var(--focus),
    0 2px 10px rgba(15, 23, 42, 0.06);
}

.row-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.15s ease;
  color: rgba(15, 23, 42, 0.75);
}

.device-row[aria-expanded="true"] .row-toggle svg {
  transform: rotate(90deg);
}

/* Block cell: allow text truncation inside flex child */
td[data-label="Block"] .inline-flex > div {
  min-width: 0;
}

/* Crop subtitle under block name */
.crop-subtitle {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.variety-hint {
  color: var(--muted);
  font-style: italic;
}
.block-note {
  font-size: 14px;
  color: var(--muted);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    background 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease;
}

.pill.wait {
  background: #dcfce7;
  border-color: rgba(22, 101, 52, 0.25);
  color: #166534;
}

.pill.irrigate {
  background: rgba(239, 83, 80, 0.14);
  border-color: rgba(239, 83, 80, 0.35);
  color: rgba(153, 27, 27, 0.95);
}

.instruction-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Mobile verdict badge (hidden on desktop, shown on mobile inside instruction-wrap) */
.mobile-verdict {
  display: none;
}

/* ON now pulsing dot */
.irrig-now-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 4px;
  vertical-align: middle;
  animation: irrig-pulse 2s ease-in-out infinite;
}
@keyframes irrig-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* Reading value update animation */
@keyframes reading-update {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}
.reading-updated {
  animation: reading-update 0.3s ease;
}

/* Irrigation start ripple animation */
@keyframes irrig-ripple {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.3);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(37, 99, 235, 0);
  }
}
.irrig-ripple {
  animation: irrig-ripple 1s ease-out;
}

tr.irrig-on td[data-label="Irrigation"] .cell-main {
  color: #16a34a;
  font-weight: 600;
}
.last-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.last-main {
  display: flex;
  flex-direction: column;
}

.reading-wrap {
  display: flex;
  align-items: center;
  gap: 0 5px;
  position: relative;
}

.reading-wrap .cell-main {
  white-space: nowrap;
}

.reading-wrap .cell-sub {
  display: none;
  width: 100%;
}

.reading-wrap .cell-tip {
  display: none;
}

.trend-arrow {
  font-size: 1.3em;
  cursor: default;
  margin-left: 2px;
  letter-spacing: -2px;
  color: var(--muted) !important;
}
.trend-arrow.trend-flat {
  text-shadow:
    0 0 0.5px currentColor,
    0 0 0.5px currentColor;
}

/* Show trend rate tooltip on hover (only when tip has content) */
.reading-wrap:hover .cell-tip:not(:empty) {
  display: block;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--text);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  pointer-events: none;
  z-index: 10;
}

/* Tappable stress reading — opens crop stress level guide */
.stress-tap {
  cursor: pointer;
  border-bottom: 1px dotted transparent;
  transition:
    border-color 0.15s,
    color 0.15s;
}
.stress-tap:hover,
.stress-tap:focus-visible {
  border-bottom-color: var(--accent);
  color: var(--accent);
}
.stress-tap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Efficiency button in title bar */
.efficiency-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
}
.efficiency-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.efficiency-btn .grade {
  font-size: 14px;
}
.efficiency-btn .pct {
  opacity: 0.9;
}
@media (max-width: 600px) {
  .efficiency-btn.dormant .pct {
    display: none;
  }
}

/* Efficiency breakdown popup */
.efficiency-breakdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  padding: 14px 16px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  min-width: 280px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}
.efficiency-breakdown.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
/* Header: grade + label + pct */
.efficiency-breakdown .eff-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.efficiency-breakdown .eff-header-grade {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}
.efficiency-breakdown .eff-header-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.efficiency-breakdown .eff-header-pct {
  margin-left: auto;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
/* Stacked bar */
.efficiency-breakdown .eff-bar-wrap {
  margin-bottom: 8px;
}
.efficiency-breakdown .eff-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
}
/* Stat rows */
.efficiency-breakdown .stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}
.efficiency-breakdown .stat:has(+ :not(.stat)),
.efficiency-breakdown .stat:last-child {
  border-bottom: none;
}
.efficiency-breakdown .stat .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.efficiency-breakdown .stat .label {
  flex-shrink: 0;
  color: var(--text);
  font-weight: 500;
}
.efficiency-breakdown .stat .sub {
  flex: 1;
  color: var(--muted);
  font-size: 14px;
  margin-left: 4px;
}
.efficiency-breakdown .stat .count {
  font-weight: 700;
  min-width: 24px;
  text-align: right;
  white-space: nowrap;
}
/* Footer */
.efficiency-breakdown .eff-footer {
  padding-top: 6px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}
.efficiency-breakdown .eff-footer:empty {
  display: none;
}
/* Tip */
.efficiency-breakdown .eff-tip {
  padding-top: 6px;
  font-size: 14px;
  color: var(--muted);
  opacity: 0.7;
  font-style: italic;
}
/* Backdrop (mobile bottom sheet) */
.efficiency-backdrop {
  display: none;
}
.efficiency-wrap {
  position: relative;
}
/* Mobile: bottom sheet */
@media (max-width: 600px) {
  .efficiency-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .efficiency-backdrop.visible {
    display: block;
    opacity: 1;
  }
  .efficiency-breakdown {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    margin-top: 0;
    border-radius: 16px 16px 0 0;
    min-width: 0;
    width: 100%;
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 16px);
    z-index: 9999;
    transform: translateY(100%);
    opacity: 1;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.2);
  }
  .efficiency-breakdown.visible {
    transform: translateY(0);
    opacity: 1;
  }
  .efficiency-breakdown .eff-header-grade {
    font-size: 24px;
  }
  .efficiency-breakdown .eff-header-label {
    font-size: 14px;
  }
  .efficiency-breakdown .eff-header-pct {
    font-size: 16px;
  }
  .efficiency-breakdown .eff-bar {
    height: 10px;
  }
  .efficiency-breakdown .stat {
    padding: 8px 0;
    font-size: 14px;
  }
  .efficiency-breakdown .eff-footer {
    font-size: 14px;
  }
  .efficiency-breakdown .eff-tip {
    font-size: 14px;
  }
}

/* Water usage badge */
.water-usage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
  border: none;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
}
.water-usage-badge:hover {
  background: rgba(59, 130, 246, 0.2);
  transform: scale(1.02);
}
.water-usage-badge:active {
  transform: scale(0.98);
}
.water-usage-badge svg {
  width: 14px;
  height: 14px;
  opacity: 0.8;
}
.water-usage-badge .value {
  font-weight: 700;
}
.water-usage-badge .no-data {
  opacity: 0.6;
  font-style: italic;
}

/* Water Usage Popup - Fixed positioning to avoid overflow clipping */
.water-usage-popup {
  position: fixed;
  background: white;
  border-radius: 12px;
  box-shadow:
    0 10px 40px rgba(15, 23, 42, 0.25),
    0 4px 12px rgba(15, 23, 42, 0.15);
  border: 1px solid rgba(15, 23, 42, 0.1);
  padding: 16px;
  min-width: 280px;
  max-width: 340px;
  z-index: 99999;
  pointer-events: auto;
}
.water-usage-popup h4 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
}
.water-usage-popup .stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.water-usage-popup .stat-item {
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px;
}
.water-usage-popup .stat-item .label {
  font-size: 14px;
  color: #64748b;
  margin-bottom: 2px;
}
.water-usage-popup .stat-item .value {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
}
.water-usage-popup .stat-item .sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
}
.water-usage-popup .breakdown {
  border-top: 1px solid #e2e8f0;
  padding-top: 12px;
  margin-top: 4px;
}
.water-usage-popup .breakdown h5 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.water-usage-popup .tip {
  font-size: 14px;
  color: #64748b;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
}
.water-usage-popup .tip .configure-link {
  color: #2563eb;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  font: inherit;
  padding: 0;
}
.water-usage-popup .tip .configure-link:hover {
  color: #1d4ed8;
}
/* Irrigation frequency ring */
.water-usage-popup .freq-ring {
  display: flex;
  align-items: center;
  gap: 8px;
}
.water-usage-popup .freq-ring svg {
  flex-shrink: 0;
}
.water-usage-popup .freq-ring .freq-text .value {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
}
.water-usage-popup .freq-ring .freq-text .sub {
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
}
/* Peak day stat */
.water-usage-popup .peak-day {
  background: #fef3c7;
  border-radius: 8px;
  padding: 10px;
}
.water-usage-popup .peak-day .label {
  font-size: 14px;
  color: #92400e;
  margin-bottom: 2px;
}
.water-usage-popup .peak-day .value {
  font-size: 16px;
  font-weight: 700;
  color: #92400e;
}
.water-usage-popup .peak-day .sub {
  font-size: 14px;
  color: #b45309;
  margin-top: 2px;
}
/* Weekly breakdown bar chart */
.water-usage-popup .week-row {
  display: flex;
  align-items: center;
  font-size: 14px;
  padding: 3px 0;
  gap: 8px;
}
.water-usage-popup .week-row .week-label {
  color: #64748b;
  min-width: 72px;
  flex-shrink: 0;
}
.water-usage-popup .week-row .week-bar-track {
  flex: 1;
  height: 14px;
  background: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
}
.water-usage-popup .week-row .week-bar {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #93c5fd, #3b82f6);
  border-radius: 4px;
  min-width: 2px;
  transition: width 0.4s ease;
}
.water-usage-popup .week-row .week-value {
  font-weight: 600;
  color: #1e293b;
  min-width: 60px;
  text-align: right;
  flex-shrink: 0;
}
.water-usage-popup .savings-section {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.water-usage-popup .savings-section h5 {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 6px;
}
.water-usage-popup .savings-pct {
  font-size: 22px;
  font-weight: 800;
  color: #16a34a;
}
.water-usage-popup .savings-detail {
  font-size: 14px;
  color: var(--muted);
}
/* Entrance animation */
@keyframes water-popup-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
.water-usage-popup {
  animation: water-popup-in 0.18s ease-out;
}
/* Mobile bottom sheet */
@media (max-width: 480px) {
  .water-usage-popup {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    max-width: 100%;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 80vh;
    overflow-y: auto;
    animation: water-popup-slide-up 0.25s ease-out;
  }
  @keyframes water-popup-slide-up {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  .water-usage-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99998;
    animation: water-overlay-fade 0.2s ease-out;
  }
  @keyframes water-overlay-fade {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
}

/* Hidden select kept in DOM for data compatibility (StageGuide.save dispatches change on it) */
.stage-select[hidden] {
  display: none;
}

.stage-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Tappable stage pill — replaces stage select + ? button */
.stage-pill {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  background: #fff;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  white-space: nowrap;
  transition:
    border-color 0.15s,
    background 0.15s,
    box-shadow 0.15s;
}
.stage-pill:hover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.03);
}
.stage-pill:focus-visible {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  border-color: var(--accent);
  outline: none;
}
.stage-pill.nudge-tint {
  background: #fffbeb;
  border-color: rgba(217, 119, 6, 0.45);
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.1);
}

/* Status bar component */
.status-wrap {
  position: relative;
  width: 100%;
  padding-top: 14px;
  padding-bottom: 4px;
  overflow: visible;
  touch-action: auto;
  cursor: crosshair;
}

/* Raise z-index when tooltip is visible to prevent clipping by other rows */
.status-wrap:has(.status-tooltip.visible) {
  z-index: 50;
}

.status-scale {
  height: 10px;
  width: 100%;
  border-radius: 999px;
  overflow: visible;
  position: relative;
  border: 1px solid rgba(15, 23, 42, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  /* Gradient set dynamically per crop via JS */
  background: #e0e0e0;
  cursor: crosshair;
  transition:
    margin-left 0.2s ease,
    width 0.2s ease;
  touch-action: auto;
}

.status-positive-bar {
  display: none;
}

/* Zero-point separator (shown when bar has a positive zone) */
.status-scale::after {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 1.5px;
  background: #fff;
  box-shadow: none;
  left: var(--zero-pct, -10px);
  z-index: 2;
  border-radius: 1px;
  pointer-events: none;
  display: none;
}
.status-scale.has-positive::after {
  display: block;
}

/* Trigger marker — flag + dashed pole + label */
.trigger-tick {
  position: absolute;
  top: -12px;
  left: 70%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.trigger-tick svg {
  display: block;
  width: 22px;
  height: 30px;
}
/* Reading pip — downward-pointing arrow (20px, with glow) */
.reading-pip {
  position: absolute;
  top: -18px;
  width: 20px;
  height: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  transition: left 0.2s ease;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}
.reading-pip svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Glow halo behind reading pip */
.pip-glow {
  position: absolute;
  top: -4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
  animation: pip-pulse 2s ease-in-out infinite;
  opacity: 0.5;
  transition: left 0.2s ease;
  will-change: transform, opacity;
}

@keyframes pip-pulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.45;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.35);
    opacity: 0.2;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .pip-glow {
    animation: none;
    opacity: 0.35;
  }
  .irrig-now-dot {
    animation: none;
  }
  .sync-status.syncing .sync-status-dot {
    animation: none;
  }
  .timeline-step.is-suggested .timeline-dot {
    animation: none;
  }
  .pdf-progress-bar::after {
    animation: none;
  }
  .dist-icon--irrigating {
    animation: none;
  }
}

/* Verdict badge next to status bar */
.status-verdict {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
  padding: 3px 0;
  border-radius: 6px;
  white-space: nowrap;
  width: 42px;
  text-align: center;
  box-sizing: border-box;
  background: rgba(148, 163, 184, 0.15);
  color: var(--muted);
  transition:
    background 0.3s ease,
    color 0.3s ease;
}
.verdict-dormant {
  width: auto;
  padding: 3px 10px;
  background: #dbeafe;
  color: #1e40af;
}
.verdict-ok {
  background: #dcfce7;
  color: #166534;
}
.verdict-warn {
  background: #fef3c7;
  color: #92400e;
}
.verdict-bad {
  background: #fee2e2;
  color: #991b1b;
}

.status-tooltip {
  position: absolute;
  top: -30px;
  left: 0;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.96);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.12s ease,
    visibility 0.12s ease;
  z-index: 1000;
  box-shadow:
    0 4px 16px rgba(15, 23, 42, 0.3),
    0 2px 6px rgba(15, 23, 42, 0.2);
  text-align: center;
  line-height: 1.4;
}

.status-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

.status-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(15, 23, 42, 0.96);
}

/* When tooltip is positioned above on mobile (override mobile below-positioning) */
.status-tooltip.above {
  top: -50px;
  bottom: auto;
}
.status-tooltip.above::after {
  top: 100%;
  bottom: auto;
  border-top-color: rgba(15, 23, 42, 0.96);
  border-bottom-color: transparent;
}

/* When tooltip is flipped below bar (first device row clipping) */
.status-tooltip.below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: rgba(15, 23, 42, 0.96);
}

/* Vertical guide line when hovering on status bar */
.status-hover-line {
  position: absolute;
  top: -1px;
  height: 18px;
  width: 2px;
  background: rgba(15, 23, 42, 0.7);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 100;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
  border-radius: 1px;
  transform: translateX(-50%);
}

.status-hover-line.visible {
  opacity: 1;
}

/* Stress level color swatch in tooltip */
.tooltip-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

tr.device-row {
  position: relative;
}

tr.device-row > td[data-label="Block"] {
  position: relative;
}

/* Expanded row (time series) */
tr.expansion-row td {
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(246, 247, 251, 0.45);
}

/* Row expand/collapse animation */
tr.expansion-row {
  display: none;
}

tr.expansion-row.expanding,
tr.expansion-row.collapsing,
tr.expansion-row.visible {
  display: table-row;
}

tr.expansion-row .expanded {
  overflow: hidden;
  transition:
    max-height 0.3s ease-out,
    opacity 0.25s ease-out;
}

tr.expansion-row.expanding .expanded {
  max-height: 0;
  opacity: 0;
}

tr.expansion-row.visible .expanded {
  max-height: 2000px;
  opacity: 1;
}

tr.expansion-row.collapsing .expanded {
  max-height: 0;
  opacity: 0;
  transition:
    max-height 0.25s ease-in,
    opacity 0.2s ease-in;
}

.expanded {
  padding: 2px 14px 16px;
}

.expanded-panel {
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 14px;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.expanded-head {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.1);
}

.expanded-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.expanded-mobile-title {
  display: none;
  font-weight: 700;
  font-size: 14px;
}

.expanded-toolbar .device-id-label {
  color: var(--muted);
  font-size: 14px;
  font-family: ui-monospace, monospace;
}

.toolbar-spacer {
  flex: 1;
}

.range-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  background: #fff;
  font-size: 14px;
  color: var(--text);
  outline: none;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}
.range-select:focus {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  border-color: var(--accent);
}

/* Mobile: block name already visible in card above, no need to repeat */
@media (max-width: 820px) {
  .expanded-mobile-title {
    display: none;
  }
  .expanded-toolbar {
    flex-wrap: nowrap;
    gap: 5px;
  }
  .expanded-toolbar .device-settings-btn {
    padding: 2px;
  }
  .expanded-toolbar .efficiency-btn {
    padding: 3px 7px;
  }
  .expanded-toolbar .efficiency-btn .pct {
    display: none;
  }
  .expanded-toolbar .water-usage-badge {
    padding: 3px 7px;
    gap: 4px;
  }
  .expanded-toolbar .water-usage-badge svg {
    display: none;
  }
  .expanded-toolbar .plot-notes-wrap,
  .expanded-toolbar .add-note-btn {
    display: none;
  }
  .range-select {
    margin-left: auto;
    padding: 4px 6px;
  }
}

.chart-shell {
  position: relative;
  padding: 10px 12px 12px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  border-radius: 12px;
  background: rgba(246, 247, 251, 0.55);
  border: 1px solid rgba(15, 23, 42, 0.1);
  overflow: hidden;
}

canvas.ts-canvas {
  display: block;
  width: 100%;
  height: 270px;
  touch-action: none;
}

.chart-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  font-size: 14px;
  line-height: 1.25;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 10;
}

.chart-tooltip.visible {
  opacity: 1;
}
.chart-tooltip .tooltip-add-note {
  pointer-events: auto;
  touch-action: manipulation;
}

.chart-tooltip::after {
  display: none;
}

.chart-zoom-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.chart-zoom-hint.visible {
  opacity: 1;
}

/* Reset zoom button - appears when zoomed in */
.chart-reset-zoom {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  z-index: 5;
  transition: background 0.15s;
}
.chart-reset-zoom:hover {
  background: rgba(15, 23, 42, 0.95);
}
.chart-reset-zoom:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}
.chart-reset-zoom.visible {
  display: flex;
}

/* 24-7 mode toggle (clock icon in toolbar) */
.chart-mode-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}
.chart-mode-toggle svg {
  width: 18px;
  height: 18px;
}
.chart-mode-toggle:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.2);
}
.chart-mode-toggle.active {
  background: rgba(37, 99, 235, 0.1);
  color: rgba(37, 99, 235, 0.9);
  border-color: rgba(37, 99, 235, 0.3);
}
.chart-mode-toggle.active:hover {
  background: rgba(37, 99, 235, 0.15);
}
.chart-mode-toggle.loading {
  opacity: 0.5;
  pointer-events: none;
}

/* Chart export button (download icon) */
.chart-export-btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}
.chart-export-btn svg {
  width: 18px;
  height: 18px;
}
.chart-export-btn:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.2);
}

/* Researcher legend (inline in toolbar) */
.researcher-legend {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: 4px;
  font-size: 14px;
  color: rgba(15, 23, 42, 0.65);
}
.researcher-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.researcher-legend-swatch {
  display: inline-block;
  width: 16px;
  height: 3px;
  border-radius: 2px;
}

/* WhatsApp help button - in page footer */
.whatsapp-help {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #25d366;
  color: #fff;
  border-radius: 24px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition:
    transform 0.15s,
    box-shadow 0.15s;
}
.whatsapp-help:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}
.whatsapp-help svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
@media (max-width: 600px) {
  .whatsapp-help {
    padding: 10px 14px;
    font-size: 14px;
  }
}

/* Page footer with help buttons */
.page-footer {
  display: flex;
  align-items: center;
  padding: 12px 16px;
}
.page-footer .debug-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(34, 211, 238, 0.8);
  color: #0f172a;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border: none;
}
.page-footer .debug-btn:hover {
  background: #67e8f9;
}
body.debug-mode .page-footer .debug-btn {
  display: flex;
}
.page-footer .whatsapp-help {
  margin-left: auto;
}

/* =============================================
     HELP DRAWER
     ============================================= */

.help-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.25s ease,
    visibility 0.25s ease;
}

.help-drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 90vw;
  background: #fff;
  box-shadow: -4px 0 20px rgba(15, 23, 42, 0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  z-index: 2001;
}

.help-drawer-backdrop.open .help-drawer {
  transform: translateX(0);
}

.help-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.help-drawer-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-drawer-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition:
    background 0.15s,
    color 0.15s;
}

.help-drawer-close:hover {
  background: #f1f5f9;
  color: var(--text);
}
.help-drawer-close:focus-visible {
  outline: none;
  background: #e0f2fe;
  color: var(--text);
}

.help-drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
}

.help-drawer-tab {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition:
    color 0.15s,
    border-color 0.15s;
  margin-bottom: -1px;
}

.help-drawer-tab:hover {
  color: var(--text);
}
.help-drawer-tab:focus-visible {
  outline: none;
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--muted);
}

.help-drawer-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.help-drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.help-drawer-panel {
  display: none;
}

.help-drawer-panel.active {
  display: block;
}

/* Glossary styles */
.glossary-item {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.glossary-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.glossary-term {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.glossary-term .aka {
  font-weight: 400;
  color: var(--muted);
  font-size: 14px;
}

.glossary-definition {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

/* Getting Started styles */
.getting-started-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.getting-started-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.getting-started-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
}

.getting-started-text {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin: 0 0 12px;
}

.getting-started-text:last-child {
  margin-bottom: 0;
}

.getting-started-list {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.8;
}

.getting-started-list li {
  margin-bottom: 4px;
}

.getting-started-diagram {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  font-size: 14px;
}

.cycle-step {
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: nowrap;
}

.cycle-arrow {
  color: var(--muted);
  font-size: 14px;
}

.hint-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 14px 16px;
}

/* FAQ styles */
.faq-item {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.faq-question {
  width: 100%;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: #fafbfc;
  border: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: background 0.15s;
}

.faq-question:hover {
  background: #f1f5f9;
}

.faq-question .faq-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--muted);
  transition: transform 0.2s;
}

.faq-item.open .faq-question .faq-icon {
  transform: rotate(180deg);
}

.faq-answer {
  display: none;
  padding: 0 16px 16px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  background: #fff;
}

.faq-item.open .faq-answer {
  display: block;
}

/* Help button in header */
.help-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  transition: all 0.15s;
}

.help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37, 99, 235, 0.05);
}

.admin-btn {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  border-color: #f59e0b;
  color: #fff;
}

.admin-btn:hover {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.admin-btn svg {
  color: #fff;
}

/* Planned irrigation tooltip input */
.chart-tooltip .plan-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}
.chart-tooltip .plan-input {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 16px; /* Prevents iOS zoom on focus */
  text-align: center;
  -webkit-appearance: none;
  -moz-appearance: textfield;
}
.chart-tooltip .plan-input::-webkit-outer-spin-button,
.chart-tooltip .plan-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.chart-tooltip .plan-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.25);
}
.chart-tooltip .plan-save-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 4px;
  background: #3b82f6;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.chart-tooltip .plan-save-btn:hover,
.chart-tooltip .plan-save-btn:active {
  background: #2563eb;
}
.chart-tooltip .plan-clear-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}
.chart-tooltip .plan-clear-btn:hover,
.chart-tooltip .plan-clear-btn:active {
  background: rgba(255, 255, 255, 0.25);
}
.chart-tooltip.future-day {
  min-width: 200px;
  touch-action: none;
  pointer-events: auto;
  cursor: pointer;
}
.chart-tooltip .future-label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-style: italic;
}
.chart-tooltip .plan-input-row {
  touch-action: manipulation;
}

/* Weather forecast bar */
.weather-forecast-bar {
  position: relative;
  margin-top: 12px;
  padding: 2px 16px 2px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.08) 0%, rgba(245, 158, 11, 0.08) 100%);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: 10px;
}
.weather-forecast-title {
  position: absolute;
  top: 4px;
  left: 12px;
  font-size: 14px;
  font-weight: 700;
  color: #92400e;
}
.weather-forecast-days {
  position: relative;
  height: 72px;
}
.weather-forecast-days.scrollable {
  display: flex;
  gap: 4px;
  height: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.weather-forecast-days.scrollable::-webkit-scrollbar {
  display: none;
}
.weather-forecast-days.grid-mobile {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  height: auto;
}
.weather-day {
  padding: 4px 4px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  text-align: center;
  font-size: 12px;
  border: 1px solid transparent;
}
.weather-forecast-days:not(.scrollable):not(.grid-mobile) .weather-day {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  width: 66px;
}
.weather-forecast-days.scrollable .weather-day {
  flex: 0 0 auto;
  width: 70px;
}
.weather-day.today {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.weather-day-name {
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 1px;
  font-size: 12px;
}
.weather-day-temp {
  color: #dc2626;
  font-weight: 600;
}
.weather-day-eto {
  color: #0284c7;
  font-size: 11px;
  margin-top: 1px;
}
.weather-day-precip {
  color: #059669;
  font-size: 11px;
}
.weather-loading {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 8px;
}
@media (max-width: 820px) {
  .weather-forecast-title {
    display: none;
  }
}
@media (max-width: 600px) {
  .weather-forecast-days {
    height: auto;
  }
  .weather-forecast-days.grid-mobile .weather-day {
    width: auto;
    padding: 8px 4px;
    font-size: 14px;
  }
  .weather-day {
    width: 60px;
    padding: 6px 4px;
    font-size: 14px;
  }
  .weather-day-eto {
    font-size: 14px;
  }
}
.weather-day-gdd {
  color: #16a34a;
  font-size: 11px;
  margin-top: 1px;
}
.weather-forecast-gdd {
  text-align: center;
  font-size: 12px;
  color: #16a34a;
  font-weight: 600;
  padding: 4px 0 2px;
  letter-spacing: 0.02em;
}
@media (max-width: 600px) {
  .weather-day-gdd {
    font-size: 14px;
  }
}

.mini-legend {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.mini-legend .chip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  padding: 2px 6px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-bottom-width: 2px;
  border-radius: 8px;
  background: #fff;
  color: rgba(15, 23, 42, 0.85);
  white-space: nowrap;
}

/* Stage manager modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  position: relative;
  width: 860px;
  max-width: 100%;
  background: #fff;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(to bottom, rgba(246, 247, 251, 0.7), rgba(255, 255, 255, 0));
}

.modal-head .title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-head .title .h1 {
  font-weight: 900;
}
.modal-head .title .h2 {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.35;
  max-width: 72ch;
}

.modal-body {
  padding: 12px 16px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
}

.modal-footer .btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.input {
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  outline: none;
}

.input:focus {
  box-shadow: 0 0 0 4px var(--focus);
  border-color: rgba(179, 229, 252, 0.95);
}

/* (stage-table removed — replaced by stage-card-list) */

.danger {
  color: rgba(153, 27, 27, 0.95);
  border-color: rgba(239, 83, 80, 0.35);
  background: rgba(239, 83, 80, 0.08);
}

.muted-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

/* (old stage-row styles removed — replaced by stage-card)  */

#toggleStageEditMode[aria-pressed="true"] {
  background: rgba(59, 130, 246, 0.95);
  border-color: rgba(59, 130, 246, 1);
  color: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 2000;
}

.toast.show {
  opacity: 1;
}

/* Settings modals */
.settings-section {
  margin-bottom: 24px;
}
.settings-section:last-child {
  margin-bottom: 0;
}
.settings-section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}
.settings-row:last-child {
  border-bottom: none;
}
.settings-row-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-row-label .main {
  font-weight: 600;
  font-size: 14px;
}
.settings-row-label .sub {
  font-size: 14px;
  color: var(--muted);
}
.settings-row-control {
  flex-shrink: 0;
}
.settings-row-control select,
.settings-row-control input[type="text"],
.settings-row-control input[type="email"],
.settings-row-control input[type="tel"],
.settings-row-control input[type="number"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* Prevents iOS zoom on focus */
  width: 220px;
  box-sizing: border-box;
}
.settings-row-control input[type="number"] {
  width: 100px;
}
.settings-row-control textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* Prevents iOS zoom on focus */
  min-width: 200px;
  resize: vertical;
  min-height: 60px;
}
.settings-row-control select:focus,
.settings-row-control input:focus,
.settings-row-control textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  display: block;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.15);
  transition: background 0.2s;
  position: relative;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-track {
  background: var(--accent);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
}
.toggle input:focus-visible + .toggle-track {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.toggle input:disabled + .toggle-track {
  opacity: 0.4;
  cursor: not-allowed;
}

.settings-device-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: rgba(15, 23, 42, 0.06);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}

/* Device settings header identity strip */
.device-settings-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}
.device-settings-identity .crop-emoji {
  font-size: 22px;
  line-height: 1;
}
.device-settings-identity .identity-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.device-settings-identity .identity-block-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.device-settings-identity .identity-device-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  color: var(--muted);
}

/* Two-column layout for device settings */
#deviceSettingsModal .modal {
  max-width: 480px;
}
@media (min-width: 641px) {
  #deviceSettingsModal .modal {
    max-width: 680px;
  }
  .device-settings-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
  }
  .device-settings-columns .settings-section {
    margin-bottom: 16px;
  }
  .device-settings-full-width {
    grid-column: 1 / -1;
  }
}
@media (max-width: 640px) {
  .device-settings-columns {
    display: block;
  }
}

/* Dirty-state: changed field indicator */
.settings-row-control.is-dirty input,
.settings-row-control.is-dirty select,
.settings-row-control.is-dirty textarea {
  border-left: 3px solid var(--accent);
}

/* Save button disabled state */
#saveDeviceSettings:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.settings-warning {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: #92400e;
  margin-top: 8px;
  display: none;
}
.settings-warning.visible {
  display: block;
}
.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-export:hover {
  background: #1d4ed8;
}
.btn-export svg {
  width: 18px;
  height: 18px;
}

/* CSV Export Toggle */
.csv-export-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.csv-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.csv-toggle-btn {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}
.csv-toggle-btn.active {
  background: var(--accent);
  color: #fff;
}
.csv-toggle-btn:not(.active):hover {
  background: rgba(37, 99, 235, 0.08);
}
.csv-toggle-hint {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-top: -4px;
}

/* PDF Report Modal Styles */
.pdf-option-row {
  padding: 10px 0;
  border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}

.pdf-option-row:last-child {
  border-bottom: none;
}

.pdf-checkbox-label,
.pdf-radio-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.pdf-checkbox-label input,
.pdf-radio-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-text,
.radio-text {
  flex: 1;
}

.pdf-device-list {
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.pdf-device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
}

.pdf-device-item input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.pdf-generate-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-generate-pdf {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
}

.btn-generate-pdf:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.btn-generate-pdf:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-generate-pdf svg {
  width: 20px;
  height: 20px;
}

.pdf-progress {
  display: none;
  margin-top: 16px;
  text-align: center;
}

.pdf-progress.visible {
  display: block;
}

.pdf-progress-bar {
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.pdf-progress-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  border-radius: 2px;
  animation: progress-slide 1.5s ease-in-out infinite;
}

@keyframes progress-slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}

.pdf-progress-text {
  font-size: 14px;
  color: var(--muted);
}

.device-settings-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--muted);
  border-radius: 6px;
  transition:
    color 0.15s,
    background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.device-settings-btn:hover {
  color: var(--text);
  background: rgba(15, 23, 42, 0.08);
}
.device-settings-btn svg {
  width: 18px;
  height: 18px;
}

/* Make pills clickable */
.pill {
  cursor: pointer;
  transition:
    background 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    transform 0.1s ease,
    box-shadow 0.1s ease;
}

.pill:hover {
  transform: scale(1.05);
}

.pill:active {
  transform: scale(0.98);
}

/* Active filter indicator */
.pill.filter-active,
.cell-main.filter-active,
.status-verdict.filter-active,
.mobile-verdict.filter-active {
  box-shadow:
    0 0 0 2px var(--ink),
    0 2px 8px rgba(15, 23, 42, 0.2);
  border-radius: 6px;
}

/* Clickable verdict badges */
.status-verdict.verdict-ok,
.status-verdict.verdict-warn,
.status-verdict.verdict-bad,
.status-verdict.verdict-dormant,
.mobile-verdict.mv-ok,
.mobile-verdict.mv-warn,
.mobile-verdict.mv-bad,
.mobile-verdict.mv-dormant {
  cursor: pointer;
}

/* Filter states - hide non-matching rows */
body.filter-instruction-irrigate tr.device-row:not([data-instruction="irrigate"]) {
  display: none;
}

body.filter-instruction-wait tr.device-row:not([data-instruction="wait"]) {
  display: none;
}

body.filter-verdict-ok tr.device-row:not([data-verdict="ok"]) {
  display: none;
}

body.filter-verdict-soon tr.device-row:not([data-verdict="soon"]) {
  display: none;
}

body.filter-verdict-due tr.device-row:not([data-verdict="due"]) {
  display: none;
}

body.filter-verdict-dormant tr.device-row:not([data-verdict="dormant"]) {
  display: none;
}

/* API Error Banner (inline above table) */
.api-error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}
.api-error-banner .dismiss-btn {
  background: none;
  border: none;
  color: #991b1b;
  cursor: pointer;
  font-size: 18px;
  padding: 0 4px;
}

/* Responsive adjustments */
@media (max-width: 980px) {
  .status-wrap {
    width: 240px;
  }
  table {
    min-width: 720px;
  }
}

/* Phone portrait/landscape friendly layout */
@media (max-width: 820px) {
  .app {
    padding: 0 0 34px;
  }
  .controls {
    padding: 0 10px;
  }
  .brand h1 {
    font-size: 18px;
  }
  .controls {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .search {
    flex: 1;
    min-width: 100px;
    max-width: none;
    padding: 8px 10px;
  }
  .controls .btn {
    padding: 12px 12px;
    font-size: 14px;
    gap: 4px;
    flex-shrink: 0;
  }
  .controls .btn svg {
    width: 16px;
    height: 16px;
  }
  .meta {
    display: none;
  }

  /* Mobile: Hide text on Order and Settings buttons (icon only) */
  /* Keep Tips and Stages text visible */
  #toggleEditMode #editModeLabel,
  #openAccountSettings .btn-text {
    display: none;
  }

  /* Mobile: Sync status as dot only */
  .sync-status {
    padding: 4px;
    gap: 0;
    min-width: auto;
    min-height: auto;
    justify-content: center;
    background: transparent;
  }
  .sync-status .sync-status-dot {
    width: 10px;
    height: 10px;
  }
  .sync-status.offline .sync-status-dot {
    background: #d97706;
  }
  .sync-status.error .sync-status-dot {
    background: #dc2626;
  }
  .sync-status.syncing .sync-status-dot {
    background: #2563eb;
  }
  .sync-status #syncStatusText {
    display: none;
  }
  .sync-status .sync-queue-badge {
    display: none;
  }

  /* API ERROR STYLING */
  .api-error-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
  }
  .api-error-banner .dismiss-btn {
    background: none;
    border: none;
    color: #991b1b;
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
  }

  /* Switch the table into a stacked card list */
  .table-wrap {
    overflow: visible;
  }
  table {
    min-width: 0;
    display: block;
  }
  thead {
    display: none;
  }
  tbody {
    display: block;
  }

  /* Compact card layout using CSS Grid — 3 columns:
     col 1 (flexible): Block / Stage
     col 2 (auto):     Stress number + ? — never squeezed
     col 3 (flexible): Instructions pill / Irrigation */
  tbody tr.device-row {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) auto minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 6px 8px;
    margin: 0 0 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 0;
    background: #fff;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
    width: 100%;
    cursor: pointer;
  }

  tbody tr.device-row:hover {
    background: #fff;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
    transform: none;
  }

  tbody tr.device-row > td {
    display: flex;
    align-items: center;
    padding: 0;
    border: none;
    gap: 4px;
  }

  tbody tr.device-row > td::before {
    display: none;
  }

  /* Line 1: Block name (cols 1-2) + IRRIGATE/WAIT pill (col 3) */
  tbody tr.device-row > td[data-label="Block"] {
    grid-column: 1 / 3;
    grid-row: 1;
    overflow: hidden;
    min-width: 0;
  }
  tbody tr.device-row > td[data-label="Block"] .inline-flex {
    gap: 4px;
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Block"] .inline-flex > div {
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Block"] .drag-handle {
    display: none;
  }
  tbody tr.device-row > td[data-label="Block"] .row-toggle {
    display: none;
  }
  tbody tr.device-row > td[data-label="Block"] .cell-main {
    font-size: 16px;
  }
  tbody tr.device-row > td[data-label="Block"] .crop-subtitle {
    font-size: 14px;
  }
  tbody tr.device-row > td[data-label="Block"] .block-note {
    display: none;
  }

  /* Remove bottom margin on expanded row so expansion card sits flush */
  tbody tr.device-row[aria-expanded="true"] {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
  tr.expansion-row.visible {
    margin-top: 0;
  }

  /* Line 1: Block (left) + IRRIGATE/WAIT pill (right) */
  tbody tr.device-row > td[data-label="Status"] {
    display: contents;
  }
  tbody tr.device-row > td[data-label="Status"] .status-cell {
    display: contents;
  }
  tbody tr.device-row > td[data-label="Instructions"] .status-verdict {
    display: none;
  }
  tbody tr.device-row > td[data-label="Instructions"] {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
  /* Line 2: Stage (col 1), Stress (col 2 auto), Irrigation (col 3) */
  tbody tr.device-row > td[data-label="Stage"] {
    grid-column: 1;
    grid-row: 2;
    justify-content: flex-start;
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Stage"] .stage-wrap {
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Stage"] .stage-pill {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  tbody tr.device-row > td[data-label="Stress"] {
    grid-column: 2;
    grid-row: 2;
    white-space: nowrap;
  }
  tbody tr.device-row > td[data-label="Stress"] .reading-wrap {
    flex-wrap: nowrap;
    margin-left: 16px;
  }
  tbody tr.device-row > td[data-label="Stress"] .cell-main {
    font-size: 18px;
    font-weight: 700;
  }
  tbody tr.device-row > td[data-label="Stress"] .cell-sub,
  tbody tr.device-row > td[data-label="Stress"] .cell-tip {
    display: none;
  }
  tbody tr.device-row > td[data-label="Irrigation"] {
    grid-column: 3;
    grid-row: 2;
    justify-content: flex-end;
    font-size: 14px;
    gap: 3px;
  }
  tbody tr.device-row > td[data-label="Irrigation"] .cell-main {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
  }
  tbody tr.device-row > td[data-label="Irrigation"] .cell-sub {
    font-size: 14px;
    margin: 0;
    color: var(--muted);
  }
  tbody tr.device-row > td[data-label="Instructions"] .instruction-wrap {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }
  tbody tr.device-row > td[data-label="Instructions"] .pill {
    padding: 8px 12px;
    font-size: 14px;
  }
  tbody tr.device-row > td[data-label="Instructions"] .mobile-verdict {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    padding: 6px 0;
    border-radius: 6px;
    white-space: nowrap;
    width: 48px;
    text-align: center;
    background: rgba(148, 163, 184, 0.15);
    color: var(--muted);
  }
  tbody tr.device-row > td .mobile-verdict.mv-ok {
    background: #dcfce7;
    color: #166534;
  }
  tbody tr.device-row > td .mobile-verdict.mv-warn {
    background: #fef3c7;
    color: #92400e;
  }
  tbody tr.device-row > td .mobile-verdict.mv-bad {
    background: #fee2e2;
    color: #991b1b;
  }
  tbody tr.device-row > td .mobile-verdict.mv-dormant {
    width: auto;
    padding: 6px 10px;
    background: #dbeafe;
    color: #1e40af;
  }
  /* Line 3: Status bar full width */
  tbody tr.device-row > td[data-label="Status"] .status-wrap {
    grid-column: 1 / -1;
    grid-row: 3;
    width: 100%;
    padding-bottom: 4px;
    padding-top: 2px;
    overflow: visible;
  }

  tbody tr.device-row > td[data-label="Status"] .status-scale {
    height: 8px;
  }
  tbody tr.device-row > td[data-label="Status"] .trigger-tick svg {
    width: 16px;
    height: 22px;
  }
  tbody tr.device-row > td[data-label="Status"] .trigger-tick {
    top: -8px;
  }
  tbody tr.device-row > td[data-label="Status"] .reading-pip {
    width: 16px;
    height: 16px;
    top: -14px;
  }
  tbody tr.device-row > td[data-label="Status"] .pip-glow {
    width: 22px;
    height: 22px;
    top: -6px;
  }
  /* Enable tooltip on mobile - position below bar for better visibility */
  tbody tr.device-row > td[data-label="Status"] .status-tooltip {
    font-size: 14px;
    padding: 12px 16px;
    top: auto;
    bottom: -60px;
  }
  tbody tr.device-row > td[data-label="Status"] .status-tooltip::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: rgba(15, 23, 42, 0.96);
  }

  tr.expansion-row.visible {
    display: block;
    width: 100%;
  }
  tr.expansion-row.visible td {
    display: block;
    background: transparent;
    border: none;
    width: 100%;
  }
  .expanded {
    padding: 0 0 10px;
  }
  .expanded-panel {
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }
  canvas.ts-canvas {
    height: 260px;
  }

  .note {
    padding: 0 4px 14px;
  }

  .modal {
    max-height: 92vh;
  }
  .modal-backdrop {
    align-items: flex-start;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  /* Pill filter hidden rows on mobile */
  body.filter-instruction-irrigate tbody tr.device-row:not([data-instruction="irrigate"]),
  body.filter-instruction-wait tbody tr.device-row:not([data-instruction="wait"]),
  body.filter-verdict-ok tbody tr.device-row:not([data-verdict="ok"]),
  body.filter-verdict-soon tbody tr.device-row:not([data-verdict="soon"]),
  body.filter-verdict-due tbody tr.device-row:not([data-verdict="due"]),
  body.filter-verdict-dormant tbody tr.device-row:not([data-verdict="dormant"]) {
    display: none;
  }

  /* Stage manager mobile layout */
  .stage-manager-modal {
    max-width: calc(100vw - 32px);
    width: calc(100vw - 32px);
  }

  .stage-crop-bar {
    padding: 12px 14px;
  }

  .stage-card-list {
    padding: 10px 14px 4px;
  }

  .stage-card {
    gap: 8px;
    padding: 10px 10px;
  }

  .stage-card-icon {
    width: 40px;
    height: 40px;
    font-size: 15px;
    border-radius: 6px;
  }

  .stage-card-name {
    font-size: 14px;
  }

  .stage-card-desc {
    font-size: 14px;
  }

  .stage-card-trigger .input {
    width: 48px;
    font-size: 16px;
  }

  .stage-add-row {
    padding: 0 14px 10px;
  }

  .stage-add-fields {
    flex-wrap: wrap;
    padding: 8px 10px;
  }

  .stage-add-fields .field-stage {
    flex: 1 1 100%;
    margin-bottom: 4px;
  }
}

@media (max-width: 420px) {
  tbody tr.device-row td::before {
    flex-basis: 78px;
  }
  .controls .btn {
    padding: 12px;
    gap: 4px;
  }
  .controls .btn svg {
    width: 16px;
    height: 16px;
  }
  /* Keep Tips and Stages text visible, hide only Order and Settings */
  #toggleEditMode #editModeLabel,
  #openAccountSettings .btn-text {
    display: none;
  }
  /* Also hide Admin text if shown */
  #openAdminPanel .btn-text {
    display: none;
  }
}

/* Landscape phone: compact grid layout similar to portrait */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .app {
    padding: 0 10px 20px;
    margin-top: 10px;
  }
  .topbar {
    margin-bottom: 8px;
  }
  .brand h1 {
    font-size: 18px;
  }
  .brand .sub {
    display: none;
  }
  .note {
    display: none;
  }

  .table-wrap {
    overflow: visible;
  }
  table {
    min-width: 0;
    display: block;
  }
  thead {
    display: none;
  }
  tbody {
    display: block;
  }

  /* Grid layout for landscape cards — same 3-column structure */
  tbody tr.device-row {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) auto minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 4px 8px;
    margin: 6px 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.04);
    width: 100%;
    cursor: pointer;
  }

  tbody tr.device-row:hover {
    background: #fff;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.04);
    transform: none;
  }

  tbody tr.device-row > td {
    display: flex;
    align-items: center;
    padding: 0;
    border: none;
    gap: 4px;
  }

  tbody tr.device-row > td::before {
    display: none;
  }

  /* Line 1: Block name (cols 1-2) + IRRIGATE/WAIT pill (col 3) */
  tbody tr.device-row > td[data-label="Block"] {
    grid-column: 1 / 3;
    grid-row: 1;
    overflow: hidden;
    min-width: 0;
  }
  tbody tr.device-row > td[data-label="Block"] .inline-flex {
    gap: 4px;
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Block"] .inline-flex > div {
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Block"] .drag-handle {
    display: none;
  }
  tbody tr.device-row > td[data-label="Block"] .row-toggle {
    display: none;
  }
  tbody tr.device-row > td[data-label="Block"] .cell-main {
    font-size: 16px;
  }
  tbody tr.device-row > td[data-label="Block"] .crop-subtitle {
    font-size: 14px;
  }
  tbody tr.device-row > td[data-label="Block"] .block-note {
    display: none;
  }
  tbody tr.device-row[aria-expanded="true"] {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  /* Line 1: Block (left) + IRRIGATE/WAIT pill (right) */
  tbody tr.device-row > td[data-label="Status"] {
    display: contents;
  }
  tbody tr.device-row > td[data-label="Status"] .status-cell {
    display: contents;
  }
  tbody tr.device-row > td[data-label="Instructions"] .status-verdict {
    display: none;
  }
  tbody tr.device-row > td[data-label="Instructions"] {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
  /* Line 2: Stage (col 1), Stress (col 2 auto), Irrigation (col 3) */
  tbody tr.device-row > td[data-label="Stage"] {
    grid-column: 1;
    grid-row: 2;
    justify-content: flex-start;
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Stage"] .stage-wrap {
    min-width: 0;
    overflow: hidden;
  }
  tbody tr.device-row > td[data-label="Stage"] .stage-pill {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 14px;
    border-radius: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  tbody tr.device-row > td[data-label="Stress"] {
    grid-column: 2;
    grid-row: 2;
    justify-content: center;
    white-space: nowrap;
  }
  tbody tr.device-row > td[data-label="Stress"] .reading-wrap {
    justify-content: center;
    flex-wrap: nowrap;
  }
  tbody tr.device-row > td[data-label="Stress"] .cell-main {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
  }
  tbody tr.device-row > td[data-label="Stress"] .stress-tap {
    font-size: 18px;
  }
  tbody tr.device-row > td[data-label="Stress"] .cell-sub,
  tbody tr.device-row > td[data-label="Stress"] .cell-tip {
    display: none;
  }
  tbody tr.device-row > td[data-label="Irrigation"] {
    grid-column: 3;
    grid-row: 2;
    justify-content: flex-end;
    font-size: 14px;
    gap: 3px;
  }
  tbody tr.device-row > td[data-label="Irrigation"] .cell-main {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
  }
  tbody tr.device-row > td[data-label="Irrigation"] .cell-sub {
    font-size: 14px;
    margin: 0;
    color: var(--muted);
  }
  tbody tr.device-row > td[data-label="Instructions"] .instruction-wrap {
    flex-direction: row;
    align-items: center;
    gap: 5px;
  }
  tbody tr.device-row > td[data-label="Instructions"] .pill {
    padding: 8px 12px;
    font-size: 14px;
  }
  tbody tr.device-row > td[data-label="Instructions"] .mobile-verdict {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    padding: 6px 0;
    border-radius: 6px;
    white-space: nowrap;
    width: 48px;
    text-align: center;
    background: rgba(148, 163, 184, 0.15);
    color: var(--muted);
  }
  tbody tr.device-row > td .mobile-verdict.mv-ok {
    background: #dcfce7;
    color: #166534;
  }
  tbody tr.device-row > td .mobile-verdict.mv-warn {
    background: #fef3c7;
    color: #92400e;
  }
  tbody tr.device-row > td .mobile-verdict.mv-bad {
    background: #fee2e2;
    color: #991b1b;
  }
  tbody tr.device-row > td .mobile-verdict.mv-dormant {
    width: auto;
    padding: 2px 8px;
    background: #dbeafe;
    color: #1e40af;
  }
  /* Line 3: Status bar full width */
  tbody tr.device-row > td[data-label="Status"] .status-wrap {
    grid-column: 1 / -1;
    grid-row: 3;
    width: 100%;
    padding-bottom: 4px;
    padding-top: 2px;
    overflow: visible;
  }

  tbody tr.device-row > td[data-label="Status"] .status-scale {
    height: 7px;
  }
  tbody tr.device-row > td[data-label="Status"] .trigger-tick svg {
    width: 14px;
    height: 20px;
  }
  tbody tr.device-row > td[data-label="Status"] .trigger-tick {
    top: -6px;
  }
  tbody tr.device-row > td[data-label="Status"] .reading-pip {
    width: 14px;
    height: 14px;
    top: -12px;
  }
  tbody tr.device-row > td[data-label="Status"] .pip-glow {
    width: 20px;
    height: 20px;
    top: -5px;
  }
  /* Enable tooltip on small mobile */
  tbody tr.device-row > td[data-label="Status"] .status-tooltip {
    font-size: 14px;
    padding: 10px 14px;
  }

  /* Expansion row in landscape */
  tr.expansion-row.visible {
    display: block;
    width: 100%;
  }
  tr.expansion-row.visible td {
    display: block;
    background: transparent;
    border: none;
    width: 100%;
  }
  .expanded {
    padding: 0 0 8px;
  }
  .expanded-panel {
    border-radius: 0 0 10px 10px;
    border-top: none;
  }
  .expanded-head {
    padding: 6px 10px;
  }
  .range-select {
    font-size: 14px;
    padding: 10px 12px;
  }
  canvas.ts-canvas {
    height: 180px;
  }
  /* Stages modal in landscape */
  .modal-head .title .h2 {
    font-size: 14px;
    line-height: 1.2;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
     DEBUG PANEL STYLES
     ═══════════════════════════════════════════════════════════════════════ */
.debug-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  max-height: 70vh;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  font-family: ui-monospace, "SF Mono", Monaco, monospace;
  font-size: 11px;
  z-index: 10000;
  display: none;
  overflow: hidden;
}
.debug-panel.visible {
  display: flex;
  flex-direction: column;
}
.debug-panel.minimized {
  max-height: 44px;
}
.debug-panel.minimized .debug-body {
  display: none;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #0f172a;
  border-bottom: 1px solid #334155;
  cursor: pointer;
  user-select: none;
}
.debug-header .title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: #22d3ee;
}
.debug-header .title svg {
  width: 16px;
  height: 16px;
}
.debug-header .controls {
  display: flex;
  gap: 8px;
}
.debug-header .btn {
  background: #334155;
  border: none;
  color: #94a3b8;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
}
.debug-header .btn:hover {
  background: #475569;
  color: #fff;
}

.debug-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.debug-section {
  border-bottom: 1px solid #334155;
}
.debug-section:last-child {
  border-bottom: none;
}

.debug-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #1e293b;
  cursor: pointer;
  user-select: none;
}
.debug-section-header:hover {
  background: #273548;
}
.debug-section-header .label {
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
}
.debug-section-header .badge {
  background: #334155;
  color: #22d3ee;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 9px;
}
.debug-section-header .badge.error {
  background: #7f1d1d;
  color: #fca5a5;
}
.debug-section-header .badge.warning {
  background: #713f12;
  color: #fde047;
}
.debug-section-header .badge.success {
  background: #14532d;
  color: #86efac;
}
.debug-section-header .chevron {
  color: #64748b;
  transition: transform 0.15s;
}
.debug-section.open .debug-section-header .chevron {
  transform: rotate(90deg);
}

.debug-section-content {
  display: none;
  padding: 10px 14px;
  background: #0f172a;
  max-height: 200px;
  overflow-y: auto;
}
.debug-section.open .debug-section-content {
  display: block;
}

.debug-log-entry {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #1e293b;
}
.debug-log-entry:last-child {
  border-bottom: none;
}
.debug-log-entry .time {
  color: #64748b;
  flex-shrink: 0;
}
.debug-log-entry .type {
  flex-shrink: 0;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 9px;
  text-transform: uppercase;
}
.debug-log-entry .type.api {
  background: #1e3a5f;
  color: #7dd3fc;
}
.debug-log-entry .type.cache {
  background: #365314;
  color: #bef264;
}
.debug-log-entry .type.write {
  background: #4c1d95;
  color: #c4b5fd;
}
.debug-log-entry .type.error {
  background: #7f1d1d;
  color: #fca5a5;
}
.debug-log-entry .type.info {
  background: #334155;
  color: #94a3b8;
}
.debug-log-entry .msg {
  flex: 1;
  word-break: break-word;
}

.debug-table {
  width: 100%;
  border-collapse: collapse;
}
.debug-table th {
  text-align: left;
  color: #64748b;
  font-weight: 500;
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid #334155;
}
.debug-table td {
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid #1e293b;
}
.debug-table tr:last-child td {
  border-bottom: none;
}
.debug-table .val {
  color: #22d3ee;
}
.debug-table .val.success {
  color: #86efac;
}
.debug-table .val.error {
  color: #fca5a5;
}
.debug-table .val.warning {
  color: #fde047;
}

.debug-json {
  background: #0f172a;
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #94a3b8;
  max-height: 150px;
}

.debug-device-select {
  width: 100%;
  background: #334155;
  border: 1px solid #475569;
  color: #e2e8f0;
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 11px;
}

.debug-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: #0f172a;
  border-top: 1px solid #334155;
}
.debug-actions button {
  background: #334155;
  border: 1px solid #475569;
  color: #e2e8f0;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
}
.debug-actions button:hover {
  background: #475569;
}
.debug-actions button.danger {
  background: #7f1d1d;
  border-color: #991b1b;
}
.debug-actions button.danger:hover {
  background: #991b1b;
}

/* Location button */
.location-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  cursor: pointer;
  transition: background 0.15s;
}
.location-btn:hover {
  background: rgba(59, 130, 246, 0.2);
}
.location-btn svg {
  width: 16px;
  height: 16px;
}

/* Map modal */
.map-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.map-modal-overlay.visible {
  display: flex;
}
.map-modal {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 10001;
}
.map-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.map-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
}
.map-modal-header .close-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.map-modal-header .close-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}
.map-modal-body {
  padding: 0;
  position: relative;
}
#locationMap {
  width: 100%;
  height: 400px;
  background: #e5e7eb;
}
#locationMap iframe {
  display: block;
}
.map-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #e2e8f0;
  font-size: 14px;
  color: #1e293b;
  background: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}
.map-modal-footer a {
  color: #3b82f6;
  text-decoration: none;
}
.map-modal-footer a:hover {
  text-decoration: underline;
}
@media (max-width: 600px) {
  .map-modal {
    max-width: 100%;
    max-height: 80vh;
  }
  #locationMap {
    height: 300px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
     WELCOME MODAL & TOOLTIP TOUR
     ═══════════════════════════════════════════════════════════════════════════ */

.welcome-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.welcome-modal-backdrop.open {
  display: flex;
}

.welcome-modal {
  background: #fff;
  border-radius: 16px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  animation: modalSlideIn 0.3s ease;
  margin: auto;
}

@media (max-width: 600px) {
  .welcome-modal-backdrop {
    padding: 12px;
    align-items: flex-start;
  }
  .welcome-modal {
    max-width: calc(100vw - 24px);
    width: calc(100vw - 24px);
    max-height: none;
    margin-top: 20px;
    margin-bottom: 20px;
    border-radius: 12px;
  }
  .welcome-header {
    padding: 24px 20px;
  }
  .welcome-header .welcome-icon {
    font-size: 36px;
  }
  .welcome-header h1 {
    font-size: 20px;
  }
  .welcome-body {
    padding: 20px;
  }
  .welcome-features {
    gap: 12px;
  }
  .welcome-feature .feature-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  .welcome-footer {
    flex-direction: column;
  }
  .welcome-footer .btn-tour,
  .welcome-footer .btn-start {
    width: 100%;
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.welcome-header {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  padding: 32px 28px;
  color: #fff;
  text-align: center;
}

.welcome-header .welcome-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.welcome-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px;
}

.welcome-header p {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;
}

.welcome-body {
  padding: 24px 28px;
}

.welcome-features {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.welcome-feature {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.welcome-feature .feature-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.welcome-feature .feature-text h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
}

.welcome-feature .feature-text p {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.welcome-footer {
  display: flex;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.welcome-footer .btn-tour {
  flex: 1;
  padding: 12px 20px;
  border: 2px solid var(--accent);
  background: #fff;
  color: var(--accent);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.welcome-footer .btn-tour:hover {
  background: #eff6ff;
}

.welcome-footer .btn-start {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.welcome-footer .btn-start:hover {
  background: #1d4ed8;
}

.welcome-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
}

.welcome-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* Tooltip Tour */
.tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  display: none;
}

.tour-overlay.active {
  display: block;
  pointer-events: auto;
}

.tour-spotlight {
  position: fixed;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.75);
  border-radius: 8px;
  z-index: 9999;
  pointer-events: none;
  transition: all 0.3s ease;
}

.tour-tooltip {
  position: fixed;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  max-width: 320px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  z-index: 10000;
  animation: tooltipFadeIn 0.25s ease;
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tour-tooltip::before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  transform: rotate(45deg);
}

.tour-tooltip.arrow-top::before {
  top: -6px;
  left: 24px;
}

.tour-tooltip.arrow-bottom::before {
  bottom: -6px;
  left: 24px;
}

.tour-tooltip.arrow-left::before {
  left: -6px;
  top: 24px;
}

.tour-tooltip.arrow-right::before {
  right: -6px;
  top: 24px;
}

.tour-tooltip h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}

.tour-tooltip p {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

.tour-tooltip-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tour-progress {
  font-size: 14px;
  color: var(--muted);
}

.tour-buttons {
  display: flex;
  gap: 8px;
}

.tour-buttons .btn-skip {
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.tour-buttons .btn-skip:hover {
  color: var(--text);
}

.tour-buttons .btn-next {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.tour-buttons .btn-next:hover {
  background: #1d4ed8;
}

/* Stage Guide Modal */
.stage-guide-modal {
  max-width: 560px;
}

.stage-guide-modal .modal-body {
  padding: 0;
}

.stage-guide-intro {
  padding: 20px 24px;
  background: #eff6ff;
  border-bottom: 1px solid #dbeafe;
}

.stage-guide-intro p {
  font-size: 14px;
  color: #1e40af;
  margin: 0;
  line-height: 1.5;
}

/* ── Stage Timeline ────────────────────────────────────────────────── */
.stage-timeline {
  display: flex;
  align-items: flex-start;
  padding: 16px 24px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
  background: #fafbfd;
}
.stage-timeline::-webkit-scrollbar {
  display: none;
}

.timeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  flex-shrink: 0;
  min-width: 48px;
}

.timeline-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f1f5f9;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition:
    border-color 0.2s,
    background 0.2s,
    box-shadow 0.2s;
}

.timeline-step:hover .timeline-dot {
  border-color: #94a3b8;
  background: #f0f4f8;
}

.timeline-step.is-current .timeline-dot {
  border-color: var(--accent);
  background: #dbeafe;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.timeline-step.is-suggested .timeline-dot {
  border-color: #16a34a;
  background: #dcfce7;
  animation: suggestedPulse 2.5s ease-in-out infinite;
}

.timeline-step.is-active .timeline-dot {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

@keyframes suggestedPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.25);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
}

.timeline-label {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
  max-width: 64px;
}
.timeline-step.is-current .timeline-label {
  color: var(--accent);
  font-weight: 600;
}

.timeline-connector {
  flex: 1;
  height: 2px;
  background: var(--border);
  min-width: 12px;
  margin-top: 17px; /* center with 34px dot */
}

/* GDD Progress Bar (inside stage guide modal) */
.gdd-progress {
  padding: 8px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.gdd-track {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: #e2e8f0;
  overflow: visible;
  display: flex;
}
.gdd-segment {
  height: 100%;
  position: relative;
  border-right: 1px solid rgba(255, 255, 255, 0.6);
}
.gdd-segment:first-child {
  border-radius: 5px 0 0 5px;
}
.gdd-segment:last-child {
  border-radius: 0 5px 5px 0;
  border-right: none;
}
.gdd-segment.is-current {
  opacity: 1;
}
.gdd-segment.is-past {
  opacity: 0.7;
}
.gdd-segment.is-future {
  opacity: 0.35;
}
.gdd-segment-label {
  font-size: 9px;
  color: rgba(0, 0, 0, 0.5);
  line-height: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
  pointer-events: none;
}
.gdd-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 16px;
  background: var(--text);
  border-radius: 2px;
  z-index: 2;
  transform: translateX(-2px);
}
.gdd-marker-label {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.gdd-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-top: 14px;
}
.gdd-info-current {
  color: var(--text);
  font-weight: 600;
}
.gdd-info-next {
  color: #16a34a;
  font-weight: 500;
}

/* ── Stage List ────────────────────────────────────────────────────── */
.stage-list {
  padding: 16px 24px;
}

.stage-item {
  display: flex;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  margin: 0 -24px;
  padding-left: 24px;
  padding-right: 24px;
  outline: none;
}

.stage-item:last-child {
  border-bottom: none;
}

.stage-item:hover {
  background: #f8fafc;
}

.stage-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}

.stage-item.selected {
  background: #eff6ff;
}

.stage-item .stage-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.stage-item.selected .stage-icon {
  background: #dbeafe;
}

.stage-item .stage-info h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stage-item .stage-info h4 .current-badge {
  font-size: 14px;
  font-weight: 500;
  padding: 2px 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
}

.stage-item .stage-info h4 .suggested-badge {
  font-size: 14px;
  font-weight: 500;
  padding: 2px 6px;
  background: #dcfce7;
  color: #15803d;
  border-radius: 4px;
  border: 1px solid #bbf7d0;
}
.stage-item .stage-info h4 .gdd-suggested-badge {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.stage-item .stage-info p {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}

.stage-long-desc {
  font-size: 14px;
  color: #475569;
  line-height: 1.6;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: none;
}
.stage-item.selected .stage-long-desc {
  display: block;
  line-height: 1.4;
}

.stage-item .stage-trigger {
  margin-left: auto;
  text-align: right;
  flex-shrink: 0;
}

.stage-item .stage-trigger .trigger-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.stage-item .stage-trigger .trigger-label {
  font-size: 14px;
  color: var(--muted);
}
.stage-gdd-range {
  display: block;
  font-size: 11px;
  color: #16a34a;
  font-weight: 500;
  margin-top: 2px;
  white-space: nowrap;
}

.stage-guide-footer {
  padding: 16px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.stage-guide-footer-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stage-customize-link {
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stage-customize-link:hover {
  color: var(--accent);
}

.stage-customize-link::after {
  content: "\2192";
}

.stage-guide-footer .btn-cancel {
  padding: 10px 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

.stage-guide-footer .btn-save {
  padding: 10px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.stage-guide-footer .btn-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Stage Manager scoped mode (opened from Stage Guide for a single crop) */
.stage-manager-modal.scoped-crop .stage-crop-bar {
  display: none;
}

/* ── Stage guide mobile ────────────────────────────────────────────── */
@media (max-width: 820px) {
  /* Reduce modal backdrop padding + widen modal to reclaim whitespace */
  #stageGuideModal {
    padding-left: 6px;
    padding-right: 6px;
  }
  .stage-guide-modal {
    max-width: calc(100vw - 12px);
    width: calc(100vw - 12px);
    border-radius: 12px;
  }

  /* Timeline compact */
  .stage-timeline {
    padding: 12px 10px;
  }
  .timeline-dot {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  .timeline-connector {
    min-width: 8px;
    margin-top: 20px; /* center with 40px dot */
  }
  .timeline-label {
    font-size: 14px;
    max-width: 54px;
  }
  .timeline-step {
    min-width: 40px;
  }

  /* Stage list — tight padding for more text room */
  .stage-list {
    padding: 10px 10px;
  }
  .stage-item {
    margin: 0 -10px;
    padding-left: 10px;
    padding-right: 10px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .stage-item .stage-icon {
    width: 40px;
    height: 40px;
    font-size: 18px;
    border-radius: 6px;
  }
  .stage-item .stage-info {
    min-width: 0;
    flex: 1;
  }
  .stage-item .stage-info h4 {
    font-size: 14px;
    gap: 4px;
  }
  .stage-item .stage-info h4 .suggested-badge {
    font-size: 14px;
    padding: 1px 5px;
  }
  .stage-item .stage-info p {
    font-size: 14px;
  }
  .stage-item .stage-trigger .trigger-value {
    font-size: 14px;
  }
  .stage-item .stage-trigger .trigger-label {
    font-size: 14px;
  }
  /* When selected, long desc spans full width below icon+info+trigger */
  .stage-item.selected .stage-long-desc {
    flex-basis: 100%;
    font-size: 14px;
    line-height: 1.45;
    margin-top: 6px;
    padding-top: 6px;
  }
  .stage-guide-intro {
    padding: 12px 10px;
  }
  .stage-guide-intro p {
    font-size: 14px;
  }
  .stage-guide-footer {
    padding: 12px 10px;
  }
  .stage-guide-footer .btn-cancel {
    padding: 12px 16px;
    font-size: 14px;
  }
  .stage-guide-footer .btn-save {
    padding: 12px 18px;
    font-size: 14px;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
     STAGE NUDGE BANNER  (expansion panel — proactive stage-transition cue)
     ═══════════════════════════════════════════════════════════════════════════ */

.stage-nudge-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 12px 12px 0;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: 14px;
  color: #1e40af;
}
.stage-nudge-icon {
  font-size: 16px;
  flex-shrink: 0;
}
.stage-nudge-text {
  flex: 1;
  line-height: 1.4;
}
.stage-nudge-text strong {
  font-weight: 600;
}
.stage-nudge-action {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.stage-nudge-action:hover {
  background: #1d4ed8;
}
.stage-nudge-dismiss {
  background: none;
  border: none;
  color: #1e40af;
  cursor: pointer;
  padding: 4px 6px;
  font-size: 14px;
  opacity: 0.5;
  flex-shrink: 0;
}
.stage-nudge-dismiss:hover {
  opacity: 1;
}
@media (max-width: 600px) {
  .stage-nudge-banner {
    flex-wrap: wrap;
  }
  .stage-nudge-text {
    flex-basis: calc(100% - 36px);
  }
  .stage-nudge-action {
    margin-left: 24px;
    margin-top: 6px;
  }
}

/* Stage nudge — collapsed-row amber tint on stage pill */
/* .stage-pill.nudge-tint is defined alongside the .stage-pill base styles */

/* Transition cue in Stage Guide modal */
.stage-transition-cue {
  font-size: 14px;
  color: #1e40af;
  background: #eff6ff;
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 6px;
  line-height: 1.4;
}

/* Stage nudge GDD hint */
.stage-nudge-gdd {
  font-size: 12px;
  color: #16a34a;
  font-weight: 500;
  margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
     ADMIN PANEL
     ═══════════════════════════════════════════════════════════════════════════ */

.admin-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9000;
  display: none;
}

.admin-panel-backdrop.open {
  display: block;
}

.admin-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 900px;
  height: 100vh;
  background: #f8fafc;
  z-index: 9001;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.admin-panel-backdrop.open .admin-panel {
  transform: translateX(0);
}

/* Admin-only mode: hide all dashboard content, full-width panel */
.app.admin-mode > *:not(.admin-panel-backdrop) {
  display: none;
}
.app.admin-mode .admin-panel-backdrop {
  background: none;
  backdrop-filter: none;
}
.app.admin-mode .admin-panel {
  max-width: 100%;
}
.app.admin-mode .admin-panel-close {
  display: none;
}

.admin-panel-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  padding: 20px 24px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.admin-panel-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-panel-header .admin-badge {
  font-size: 14px;
  padding: 3px 8px;
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  border-radius: 4px;
  font-weight: 500;
}

.admin-panel-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
}

.admin-panel-close:hover {
  color: #fff;
}

.admin-tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.admin-tab {
  flex: 1;
  padding: 14px 16px;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.admin-tab:hover {
  color: var(--text);
  background: #f8fafc;
}

.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.admin-tab-panel {
  display: none;
}

.admin-tab-panel.active {
  display: block;
}

/* Customer List */
.admin-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.admin-stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
}

.admin-stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.admin-stat-card .stat-label {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}

.admin-stat-card.green .stat-value {
  color: #16a34a;
}
.admin-stat-card.orange .stat-value {
  color: #ea580c;
}
.admin-stat-card.red .stat-value {
  color: #dc2626;
}

.admin-search {
  margin-bottom: 16px;
}

.admin-search input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.admin-table {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.admin-table table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.admin-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table tr:hover td {
  background: #f8fafc;
}

.customer-name {
  font-weight: 600;
  color: var(--text);
}

.customer-email {
  font-size: 14px;
  color: var(--muted);
}

.device-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #eff6ff;
  color: var(--accent);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
}

.status-badge.active {
  background: #dcfce7;
  color: #16a34a;
}

.status-badge.inactive {
  background: #fef3c7;
  color: #d97706;
}

.status-badge.churned {
  background: #fee2e2;
  color: #dc2626;
}

/* Device Health Dashboard */
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.health-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.health-card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.health-card-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.health-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.health-status.online {
  background: #22c55e;
}
.health-status.stale {
  background: #f59e0b;
  animation: pulse-stale 2s infinite;
}
.health-status.offline {
  background: #ef4444;
  animation: pulse-offline 2s infinite;
}

.health-card-body {
  padding: 14px 16px;
}

.health-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.health-row .label {
  color: var(--muted);
}

.health-row .value {
  font-weight: 500;
  color: var(--text);
}

.health-card-footer {
  padding: 12px 16px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}

/* Alerts Log */
.alerts-filters {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.alerts-filters select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

.alert-item {
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  gap: 14px;
}

.alert-item:last-child {
  margin-bottom: 0;
}

.alert-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.alert-icon.warning {
  background: #fef3c7;
}

.alert-icon.error {
  background: #fee2e2;
}

.alert-icon.info {
  background: #dbeafe;
}

.alert-icon.success {
  background: #dcfce7;
}

.alert-content {
  flex: 1;
}

.alert-content h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
}

.alert-content p {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.alert-meta {
  text-align: right;
  flex-shrink: 0;
}

.alert-meta .alert-time {
  font-size: 14px;
  color: var(--muted);
}

.alert-meta .alert-customer {
  font-size: 14px;
  color: var(--accent);
  margin-top: 4px;
}

@media (max-width: 768px) {
  .admin-stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .admin-panel {
    max-width: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
     OFFLINE-FIRST SYNC STATUS
     ═══════════════════════════════════════════════════════════════════════════ */

.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s;
}

.sync-status.online {
  display: none;
}

.sync-status.offline {
  background: #fef3c7;
  color: #d97706;
}

.sync-status.syncing {
  background: #dbeafe;
  color: #2563eb;
}

.sync-status.error {
  background: #fee2e2;
  color: #dc2626;
}

.sync-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.sync-status.syncing .sync-status-dot {
  animation: pulse-sync 1s infinite;
}

@keyframes pulse-sync {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

.sync-queue-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: #ef4444;
  color: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  margin-left: 4px;
}

.sync-queue-badge:empty {
  display: none;
}

.offline-data-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fefce8;
  border: 1px solid #fef08a;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  color: #854d0e;
}

.offline-data-notice.hidden {
  display: none;
}

.cached-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  opacity: 0;
  transition: opacity 0.3s;
}

.device-row.cached .cached-indicator {
  opacity: 1;
}

/* Cached row visual indicator */
.device-row.cached {
  position: relative;
}

.device-row.cached::before {
  content: "📦";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  opacity: 0.5;
  z-index: 1;
}

.device-row.cached td:first-child {
  padding-left: 28px;
}

/* Cache Statistics */
.cache-stats {
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px 16px;
  border: 1px solid var(--border);
}

.cache-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}

.cache-stat-row:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.cache-stat-label {
  color: var(--muted);
}

.cache-stat-value {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════ */
/* Stress Info Button (right of status bar)                       */
/* ═══════════════════════════════════════════════════════════════ */
.status-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.status-cell .status-wrap {
  flex: 1;
  min-width: 0;
}

/* ═══════════════════════════════════════════════════════════════ */
/* Stress Level Guide Modal Content                              */
/* ═══════════════════════════════════════════════════════════════ */
.stress-band-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.stress-band-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}
.stress-band-row:last-child {
  border-bottom: none;
}
.stress-band-row.active {
  background: rgba(102, 187, 106, 0.06);
  border-radius: 8px;
  padding: 10px 8px;
  margin: 0 -8px;
}
.stress-band-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
  border: 1px solid rgba(15, 23, 42, 0.1);
}
.stress-band-info {
  flex: 1;
  min-width: 0;
}
.stress-band-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.stress-band-label {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}
.stress-band-range {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.stress-band-current {
  font-size: 14px;
  font-weight: 700;
  color: rgba(34, 139, 34, 0.95);
  background: rgba(34, 139, 34, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
}
.stress-band-desc {
  font-size: 14px;
  color: rgba(71, 85, 105, 0.85);
  line-height: 1.5;
  margin-top: 3px;
}
.stress-info-unit-note {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(246, 247, 251, 0.7);
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, 0.06);
}

/* ═══════════════════════════════════════════════════════════════ */
/* Invite User Modal                                              */
/* ═══════════════════════════════════════════════════════════════ */
.invite-device-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.invite-device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}
.invite-device-item:last-child {
  border-bottom: none;
}
.invite-device-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.invite-device-label {
  flex: 1;
  min-width: 0;
}
.invite-device-label .main {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.invite-device-label .sub {
  font-size: 14px;
  color: var(--muted);
}
.invite-select-all {
  font-size: 14px;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 4px;
  font-weight: 600;
}
.invite-select-all:hover {
  text-decoration: underline;
}

/* Backend instructions styling */
.backend-instructions {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
.backend-instructions h3 {
  font-size: 14px;
  font-weight: 800;
  margin: 16px 0 6px;
  color: var(--text);
}
.backend-instructions h3:first-child {
  margin-top: 0;
}
.backend-instructions ul {
  margin: 4px 0 12px;
  padding-left: 20px;
}
.backend-instructions li {
  margin-bottom: 4px;
}
.backend-instructions code {
  font-size: 14px;
  background: rgba(15, 23, 42, 0.05);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "SF Mono", Monaco, monospace;
}
.backend-instructions .question-box {
  background: rgba(234, 179, 8, 0.08);
  border: 1px solid rgba(234, 179, 8, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 12px 0;
}
.backend-instructions .question-box strong {
  color: rgba(146, 64, 14, 0.95);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DISTRIBUTOR MODE
   ═══════════════════════════════════════════════════════════════════════════ */

/* Brand area — make clickable for distributor */
.brand {
  position: relative;
}

.dist-switcher-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.dist-switcher-btn:hover {
  background: rgba(15, 23, 42, 0.06);
}
.dist-switcher-btn[aria-expanded="true"] {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
}

/* Customer switcher dropdown */
.dist-switcher-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 320px;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow:
    0 8px 32px rgba(15, 23, 42, 0.12),
    0 2px 8px rgba(15, 23, 42, 0.06);
  z-index: 500;
  overflow: hidden;
}

.dist-switcher-list {
  max-height: 380px;
  overflow-y: auto;
}

.dist-switch-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  transition: background 0.1s;
}
.dist-switch-item:hover {
  background: rgba(37, 99, 235, 0.05);
}
.dist-switch-item.active {
  background: rgba(37, 99, 235, 0.08);
}
.dist-switch-item--all {
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.dist-switch-item--inactive {
  opacity: 0.55;
}
.dist-switch-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.dist-switch-icon--all {
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
}
.dist-switch-icon--customer {
  background: rgba(34, 139, 34, 0.1);
  color: rgba(34, 139, 34, 0.9);
}
.dist-switch-info {
  flex: 1;
  min-width: 0;
}
.dist-switch-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dist-switch-location {
  font-size: 14px;
  color: var(--muted);
}
.dist-switch-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.dist-switch-badge {
  font-size: 14px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.dist-switch-badge--count {
  background: rgba(15, 23, 42, 0.06);
  color: var(--muted);
}
.dist-switch-badge--inactive {
  background: rgba(239, 68, 68, 0.08);
  color: #dc2626;
  font-size: 14px;
}
.dist-switch-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Context bar */
.dist-context-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(37, 99, 235, 0.04);
  border: 1px solid rgba(37, 99, 235, 0.1);
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 14px;
}
.dist-ctx-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.dist-ctx-back:hover {
  background: rgba(37, 99, 235, 0.08);
}
.dist-ctx-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dist-ctx-count {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.dist-ctx-nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.dist-ctx-arrow {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  color: var(--muted);
  transition:
    background 0.1s,
    color 0.1s;
}
.dist-ctx-arrow:hover {
  background: rgba(37, 99, 235, 0.06);
  color: var(--accent);
  border-color: rgba(37, 99, 235, 0.2);
}

/* Aggregate overview */
.dist-overview {
  margin-bottom: 20px;
}
.dist-summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.dist-stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.dist-stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.dist-stat-label {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}
.dist-stat-card--alert .dist-stat-value {
  color: #dc2626;
}

.dist-customer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.dist-cust-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition:
    box-shadow 0.15s,
    border-color 0.15s;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  position: relative;
}
.dist-cust-card:hover {
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
  border-color: rgba(37, 99, 235, 0.25);
}
.dist-cust-card--inactive {
  opacity: 0.55;
}
.dist-cust-card--inactive::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  pointer-events: none;
}

/* Distributor card reorder mode */
.dist-reorder-mode .dist-cust-card {
  cursor: grab;
  user-select: none;
}
.dist-reorder-mode .dist-cust-card:active {
  cursor: grabbing;
}
.dist-cust-card.dist-dragging {
  opacity: 0.3;
}
.dist-cust-card.dist-drop-target {
  box-shadow:
    0 0 0 2px var(--accent),
    0 4px 16px rgba(37, 99, 235, 0.2);
  border-color: var(--accent);
}
.dist-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.85;
  transform: rotate(2deg) scale(1.03);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  transition: none;
}

.dist-cust-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.dist-cust-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.dist-cust-location {
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
}
.dist-cust-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.dist-cust-badge {
  font-size: 14px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.dist-cust-badge--devices {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
}
.dist-cust-badge--inactive {
  background: rgba(239, 68, 68, 0.08);
  color: #dc2626;
}
.dist-cust-crops {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}
.dist-cust-crop {
  font-size: 14px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(34, 139, 34, 0.06);
  color: rgba(34, 139, 34, 0.85);
  font-weight: 500;
}
.dist-cust-stress {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 14px;
}
.dist-cust-stress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.dist-cust-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dist-cust-view {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.dist-cust-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}
.dist-cust-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #dc2626;
  flex-shrink: 0;
}

/* ─── Status icons & sparkline ─────────────────────────────────────── */
.dist-cust-status {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dist-icon {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
}
.dist-icon b {
  font-size: 14px;
}
.dist-icon--irrigating {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.1);
  animation: dist-blink 1.5s ease-in-out infinite;
}
@keyframes dist-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}
.dist-icon--stale {
  color: #d97706;
  background: rgba(217, 119, 6, 0.1);
}
.dist-icon--overdue {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.1);
}

/* ─── Field View (reuses distributor pattern) ───────────────────────── */
.field-context-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.field-ctx-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.field-ctx-back:hover {
  background: #e0e7ff;
}
.field-ctx-name {
  font-weight: 600;
  color: var(--text);
}
.field-ctx-count {
  color: var(--muted);
  font-size: 13px;
}
.field-ctx-nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.field-ctx-arrow {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
.field-ctx-arrow:hover {
  background: var(--bg);
}

.field-overview {
  padding: 20px;
}
.field-summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.field-stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  text-align: center;
}
.field-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}
.field-stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}
.field-stat-card--alert .field-stat-value {
  color: #dc2626;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.field-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px 16px;
  cursor: pointer;
  transition:
    box-shadow 0.15s,
    border-color 0.15s;
}
.field-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  border-color: var(--accent);
}
.field-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}
.field-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.field-card-badges {
  display: flex;
  gap: 6px;
}
.field-card-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
}
.field-card-badge--devices {
  background: #eff6ff;
  color: #2563eb;
}
.field-card-crops {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}
.field-card-crop {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f0fdf4;
  color: #16a34a;
  font-weight: 500;
}
.field-card-stress {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.field-card-stress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.field-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-card-view {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.field-card-status {
  display: flex;
  align-items: center;
  gap: 6px;
}
@media (max-width: 640px) {
  .field-summary-cards {
    grid-template-columns: 1fr;
  }
  .field-grid {
    grid-template-columns: 1fr;
  }
  .field-context-bar {
    flex-wrap: wrap;
  }
}

/* ─── Seasonal Awards ────────────────────────────────────────────────── */
.seasonal-awards {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding: 2px 0;
}
.award-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #fefce8 0%, #fff7ed 100%);
  border: 1px solid #fde68a;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
.award-icon {
  font-size: 24px;
}
.award-info {
  min-width: 0;
}
.award-title {
  font-size: 14px;
  font-weight: 700;
  color: #92400e;
}
.award-subtitle {
  font-size: 12px;
  color: #b45309;
  margin-top: 1px;
}
.award-dismiss {
  background: none;
  border: none;
  color: #b45309;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  opacity: 0.4;
  margin-left: auto;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}
.award-dismiss:hover {
  opacity: 1;
}

/* ─── Mobile responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .dist-switcher-dropdown {
    min-width: 100%;
    left: 0;
    right: 0;
    max-width: none;
    border-radius: 0 0 12px 12px;
  }
  .dist-context-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .dist-ctx-back {
    order: 1;
  }
  .dist-ctx-name {
    order: 2;
    flex: 0 1 auto;
  }
  .dist-ctx-count {
    display: none;
  }
  .dist-ctx-nav {
    order: 3;
    margin-left: auto;
  }
  .dist-summary-cards {
    grid-template-columns: 1fr;
  }
  .dist-customer-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Draft Recovery Banner (FormDraftManager) ─────────────────────── */
.draft-recovery-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: 13px;
  color: #1e40af;
  margin-bottom: 12px;
}
.draft-restore-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.draft-restore-btn:hover {
  background: #1d4ed8;
}
.draft-dismiss-btn {
  background: transparent;
  color: #64748b;
  border: none;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.draft-dismiss-btn:hover {
  color: #475569;
}

/* ─── Discard Changes Overlay (shared by Account & Device Settings) ── */
.discard-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 12px;
  animation: discard-fade-in 0.15s ease;
}
@keyframes discard-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.discard-dialog {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  text-align: center;
}
.discard-dialog h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.discard-dialog p {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.4;
}
.discard-dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.discard-dialog-actions button {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}
.discard-dialog .discard-keep-btn {
  background: var(--accent);
  color: #fff;
}
.discard-dialog .discard-keep-btn:hover {
  background: #1d4ed8;
}
.discard-dialog .discard-discard-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.discard-dialog .discard-discard-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* ─── Irrigation Cost Section (Water Usage Popup) ──────────────────── */
.water-usage-popup .cost-section {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.water-usage-popup .cost-section h5 {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.water-usage-popup .cost-total {
  font-size: 22px;
  font-weight: 800;
  color: #1e293b;
}
.water-usage-popup .cost-detail {
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
}
.water-usage-popup .cost-savings {
  font-size: 14px;
  color: #16a34a;
  font-weight: 600;
  margin-top: 4px;
}
.water-usage-popup .cost-prompt {
  font-size: 14px;
  color: var(--muted);
  font-style: italic;
}
.water-usage-popup .cost-prompt .configure-link {
  color: #2563eb;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  font: inherit;
  font-style: normal;
  padding: 0;
}
.water-usage-popup .cost-prompt .configure-link:hover {
  color: #1d4ed8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Season Heatmap View
   ═══════════════════════════════════════════════════════════════════════════ */
.heatmap-view {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  overflow-x: auto;
}
.heatmap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.heatmap-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.heatmap-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(15, 23, 42, 0.1);
}
.heatmap-legend-label {
  margin: 0 6px 0 2px;
}
.heatmap-row {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 3px;
}
.heatmap-row-label {
  width: 120px;
  min-width: 120px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding-right: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.heatmap-row-cells {
  display: flex;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
.heatmap-cell {
  flex: 1;
  min-width: 3px;
  max-width: 8px;
  height: 18px;
  border-radius: 2px;
  background: #e2e8f0;
  cursor: crosshair;
  position: relative;
}
.heatmap-cell:hover {
  outline: 2px solid var(--text);
  outline-offset: -1px;
  z-index: 1;
}
.heatmap-month-labels {
  display: flex;
  gap: 1px;
  margin-left: 120px;
  margin-top: 4px;
  margin-bottom: 8px;
}
.heatmap-month-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* DEVICE NOTES                                                               */
/* ═══════════════════════════════════════════════════════════════════════════ */
.add-note-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition:
    color 0.15s,
    background 0.15s;
}
.add-note-btn svg {
  width: 18px;
  height: 18px;
}
.add-note-btn:hover {
  color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
}
.note-count-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  pointer-events: none;
}

.plot-notes-wrap {
  display: inline-flex;
  align-items: center;
}
.plot-notes-select {
  font-size: 12px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  max-width: 120px;
}
.plot-notes-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Note modal */
.device-note-modal .modal-body {
  padding: 16px 20px;
}
.note-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.note-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.note-form input,
.note-form select,
.note-form textarea {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}
.note-form input:focus,
.note-form select:focus,
.note-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.note-numeric-row {
  display: flex;
  gap: 10px;
}
.note-numeric-row label {
  flex: 1;
}
.note-save-btn {
  margin-top: 4px;
  align-self: flex-start;
}
.note-existing-list {
  margin-top: 8px;
}
.note-existing-item:last-child {
  border-bottom: none !important;
}
