/* ══════════════════════════════════════════════════════════════════════════
   KEEHNER FARMS BIN MONITOR — Design Language v1
   ──────────────────────────────────────────────────────────────────────────
   Adopts FarmBooks two-tier token system.

   TIER 1 — PRIMITIVES (raw palette). Named by what they ARE.
            Components never read these directly.
   TIER 2 — SEMANTIC TOKENS (roles). Named by what they DO.
            Components read only these.
   TIER 3 — BIN MONITOR EXTENSIONS. Concepts unique to grain monitoring
            (crop colors, grain fill graph colors). Layered on top.
   ══════════════════════════════════════════════════════════════════════════ */


/* ── TIER 1: PRIMITIVES ──────────────────────────────────────────────────── */
:root {
  /* brand green ramp */
  --c-green-900: #1A3A0A; --c-green-800: #1f4d1f; --c-green-700: #2D5A1B;
  --c-green-600: #2D6A2D; --c-green-500: #3D7A25; --c-green-400: #5A9E3A;
  --c-green-100: #EBF5E3; --c-green-50:  #F4FAF0;
  /* neutrals */
  --c-gray-900: #111827; --c-gray-700: #374151; --c-gray-600: #4B5563;
  --c-gray-500: #6B7280; --c-gray-400: #9CA3AF; --c-gray-300: #D1D5DB;
  --c-gray-200: #E5E7EB; --c-gray-100: #F3F4F6; --c-gray-50:  #F9FAFB;
  --c-white: #FFFFFF; --c-black: #0B0F0B;
  /* feedback hues */
  --c-pos-fill: #EAF3DE; --c-pos-text: #27500A; --c-pos-strong: #2D6A2D;
  --c-neg-fill: #FCEBEB; --c-neg-text: #A32D2D; --c-neg-strong: #B91C1C;
  --c-warn-fill: #FAEEDA; --c-warn-text: #854F0B; --c-warn-strong: #B8860B;
  --c-info-fill: #E6F1FB; --c-info-text: #185FA5; --c-info-strong: #1E4D8C;
  /* crop identity ramp (bin monitor specific — grain type) */
  --c-crop-corn: #E0A93B;      /* corn — warm gold */
  --c-crop-soybean: #63C463;   /* soybean — green */
  --c-crop-wheat: #B8935A;     /* wheat — tan/brown */
  --c-crop-empty: #A8A08A;     /* no crop assigned */
}


/* ── TIER 2: SEMANTIC TOKENS — DEFAULT theme ─────────────────────────────── */
:root, [data-theme="default"] {
  /* surfaces */
  --surface-page:   #f4f5f2;
  --surface:        #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: var(--c-gray-50);
  --surface-hover:  var(--c-green-50);
  --overlay:        rgba(15,28,15,0.45);

  /* text */
  --text-primary:   var(--c-gray-900);
  --text-secondary: var(--c-gray-600);
  --text-muted:     var(--c-gray-500);
  --text-on-accent: #ffffff;
  --text-link:      #3B6D11;

  /* borders */
  --border:        #e6e8e2;
  --border-strong: var(--c-gray-300);
  --divider:       #f1f2ee;

  /* brand / accent */
  --accent:        var(--c-green-600);
  --accent-hover:  var(--c-green-900);
  --accent-pale:   var(--c-green-100);
  --accent-ring:   rgba(45,106,45,0.30);

  /* feedback roles */
  --positive-fill:   var(--c-pos-fill);
  --positive-text:   var(--c-pos-text);
  --positive-border: #C9E0AE;
  --negative-fill:   var(--c-neg-fill);
  --negative-text:   var(--c-neg-text);
  --negative-border: #F1C9C9;
  --warning-fill:    var(--c-warn-fill);
  --warning-text:    var(--c-warn-text);
  --warning-border:  #EAD3A8;
  --info-fill:       var(--c-info-fill);
  --info-text:       var(--c-info-text);
  --info-border:     #C5DCF1;
  --neutral-fill:    var(--c-gray-100);
  --neutral-text:    var(--c-gray-600);
  --neutral-border:  var(--c-gray-200);

  /* numeric */
  --num-positive: var(--c-green-600);
  --num-negative: var(--c-neg-strong);

  /* sidebar / dark navigation zone (used by our header) */
  --sidebar-bg:          #0f1f0f;
  --sidebar-active-bg:   #1e3d1e;
  --sidebar-border:      #3a6a3a;
  --sidebar-text:        #d0e8d0;
  --sidebar-text-muted:  #3a5a3a;
  --sidebar-section:     #2e5a2e;

  /* non-color tokens */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-card: 13px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:   0 8px 28px rgba(15,28,15,0.16);
  --font-sans:   'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono:   'IBM Plex Mono', ui-monospace, monospace;
  --space:       8px;
}


/* ── TIER 3: BIN MONITOR EXTENSIONS ──────────────────────────────────────── */
:root {
  /* crop outline colors (semantic wrappers around tier-1 crop colors) */
  --crop-corn:    var(--c-crop-corn);
  --crop-soybean: var(--c-crop-soybean);
  --crop-wheat:   var(--c-crop-wheat);
  --crop-empty:   var(--c-crop-empty);

  /* grain fill graph colors (mirror positive/negative feedback for direction) */
  --grain-filling:   var(--num-positive);
  --grain-unloading: var(--num-negative);
  --grain-idle:      var(--text-muted);

  /* sweep line color (brown, distinct from crop wheat) */
  --sweep-line: #7a5a1a;

  /* CO2 status backgrounds (softer than the feedback fills for larger surfaces) */
  --co2-good-bg:   #dfeeda;
  --co2-warn-bg:   #f8e5b3;
  --co2-alarm-bg:  #f5c8b8;
  --co2-paused-bg: #eeeee8;
}


/* ══════════════════════════════════════════════════════════════════════════
   BASE
   ══════════════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  background: var(--surface-page);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}


/* ══════════════════════════════════════════════════════════════════════════
   HEADER (uses sidebar-* tokens — brand-forward dark zone)
   ══════════════════════════════════════════════════════════════════════════ */

#app-header {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--sidebar-border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.brandmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--sidebar-text);
}

.brandmark .leaf {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: var(--text-on-accent);
}

.site-status {
  font-size: 12.5px;
  color: var(--sidebar-text-muted);
}

.site-status-label {
  margin-right: 4px;
}

.site-status-value {
  color: var(--sidebar-text);
  font-weight: 500;
}

.site-status-value.harvest-lockout {
  color: #f4c67a;
}

.header-nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

.nav-btn {
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid transparent;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.nav-btn:hover {
  background: var(--sidebar-active-bg);
}

.nav-btn.active {
  background: var(--sidebar-active-bg);
  color: var(--c-white);
}

.badge-count {
  background: var(--negative-text);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 4px;
}

.auth-btn {
  margin-left: 12px;
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border);
}

.auth-btn:hover {
  background: var(--sidebar-border);
  color: var(--c-white);
}


/* ══════════════════════════════════════════════════════════════════════════
   MAIN LAYOUT
   ══════════════════════════════════════════════════════════════════════════ */

#app-main {
  flex: 1;
  padding: 24px;
  max-width: 1700px;
  margin: 0 auto;
  width: 100%;
}

.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}


/* ══════════════════════════════════════════════════════════════════════════
   PANEL / CARD (base container — matches FarmBooks .panel)
   ══════════════════════════════════════════════════════════════════════════ */

.panel,
.site-layout-card,
.admin-card,
.chart-card,
.alerts-container,
.bin-detail-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

.alerts-container {
  padding: 0;
  overflow: hidden;
}


/* ══════════════════════════════════════════════════════════════════════════
   OVERVIEW — Site layout with positioned bin cards
   ══════════════════════════════════════════════════════════════════════════ */

.overview-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.site-layout-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--divider);
  padding-bottom: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.site-layout-header h2 {
  font-size: 17px;
  color: var(--text-primary);
}

.legend-compact {
  display: flex;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  flex-wrap: wrap;
  align-items: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-sep {
  opacity: 0.4;
  padding: 0 2px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
}
.swatch.bg-co2-good    { background: var(--co2-good-bg); }
.swatch.bg-co2-warn    { background: var(--co2-warn-bg); }
.swatch.bg-co2-alarm   { background: var(--co2-alarm-bg); }
.swatch.bg-co2-paused  { background: var(--co2-paused-bg); }
.swatch.outline-corn    { background: transparent; border: 2px solid var(--crop-corn); }
.swatch.outline-soybean { background: transparent; border: 2px solid var(--crop-soybean); }
.swatch.outline-wheat   { background: transparent; border: 2px solid var(--crop-wheat); }

.site-layout-scroll {
  width: 100%;
  overflow: hidden;   /* auto-fit takes over; JS sets height */
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  min-height: 200px;
  transition: height 0.2s ease;
}

/* In edit mode we need scrolling for full canvas access */
.site-layout-scroll:has(.site-layout-canvas.edit-mode) {
  overflow: auto;
}

.site-layout-canvas {
  position: relative;
  /* size set inline by JS */
  /* transform set inline by autoFitCanvas() when in view mode */
}


/* ══════════════════════════════════════════════════════════════════════════
   BIN CIRCLE — the core visual for each bin
   ══════════════════════════════════════════════════════════════════════════ */

.bin-circle {
  position: absolute;
  border-radius: 50%;
  border-width: 3px;
  border-style: solid;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
  overflow: visible;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bin-circle:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
  z-index: 10;
}

/* CO2 status backgrounds */
.bin-circle.bg-co2-good     { background: var(--co2-good-bg); }
.bin-circle.bg-co2-warn     { background: var(--co2-warn-bg); }
.bin-circle.bg-co2-alarm    { background: var(--co2-alarm-bg); }
.bin-circle.bg-co2-paused   { background: var(--co2-paused-bg); }

/* Crop outlines */
.bin-circle.outline-corn    { border-color: var(--crop-corn); }
.bin-circle.outline-soybean { border-color: var(--crop-soybean); }
.bin-circle.outline-wheat   { border-color: var(--crop-wheat); }
.bin-circle.outline-empty,
.bin-circle.outline-other,
.bin-circle.outline-null    { border-color: var(--crop-empty); }

/* ══════════════════════════════════════════════════════════════════════════
   OVERVIEW SIDEBAR — site summary panel on the left
   ══════════════════════════════════════════════════════════════════════════ */

.overview-with-sidebar {
  display: flex;
  flex-direction: row;
  gap: 16px;
  align-items: flex-start;
}

.overview-with-sidebar .site-layout-card {
  flex: 1 1 auto;
  min-width: 0;  /* allow the card to shrink below its content's natural width */
  overflow: hidden;
}

.site-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  font-size: 13px;
}

/* Compact site summary — mobile-first collapsible bar */
.site-summary-compact {
  display: none;  /* hidden by default; shown at mobile widths */
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  user-select: none;
}
.site-summary-compact .ss-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
}
.site-summary-compact .ss-main-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 0;
}
.site-summary-compact .ss-main-labels {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  line-height: 1.3;
}
.site-summary-compact .ss-main-line1 {
  color: var(--text-secondary);
  font-weight: 600;
}
.site-summary-compact .ss-main-line2 {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.site-summary-compact .ss-act.filling   { color: var(--state-filling, #2D6A2D); }
.site-summary-compact .ss-act.unloading { color: var(--state-unloading, #B8531F); }
.site-summary-compact .ss-act.warn      { color: #C99B3A; }
.site-summary-compact .ss-act.alarm     { color: #C0392B; font-weight: 600; }
.site-summary-compact .ss-act.quiet     { color: var(--text-muted); font-style: italic; }
.site-summary-compact .ss-chevron {
  font-size: 20px;
  color: var(--text-muted);
  transform: rotate(90deg);
  transition: transform 0.2s;
}
.site-summary-compact.expanded .ss-chevron {
  transform: rotate(-90deg);
}
.site-summary-compact .ss-row-expand {
  display: none;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--divider);
  gap: 8px;
  flex-direction: column;
}
.site-summary-compact.expanded .ss-row-expand {
  display: flex;
}
.site-summary-compact .ss-grain-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.site-summary-compact .ss-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.site-summary-compact .ss-val {
  margin-left: auto;
  font-weight: 600;
  color: var(--text-primary);
}

/* Legend toggle button — hidden on desktop where legend is always visible */
.legend-toggle-btn {
  display: none;
}

/* ─── Desktop breakpoint (default): summary compact hidden, sidebar shown ─── */

/* ─── Tablet breakpoint ─── */
@media (max-width: 900px) {
  .overview-with-sidebar {
    flex-direction: column;
  }
  .site-sidebar {
    width: 100%;
  }
}

/* ─── Mobile breakpoint: sidebar hidden, compact bar shown ─── */
@media (max-width: 640px) {
  .site-summary-compact { display: block; }
  .site-sidebar { display: none; }

  /* Legend: hidden by default on mobile, shown via toggle */
  .legend-toggle-btn { display: inline-flex; }
  .legend-compact {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    box-shadow: var(--shadow-md);
    z-index: 20;
    flex-direction: column;
    gap: 6px;
    min-width: 160px;
  }
  .legend-compact.legend-open {
    display: flex;
  }
  .legend-sep { display: none; }
  .site-layout-controls { position: relative; }

  /* Tighter card padding on mobile */
  .site-layout-card { padding: 12px; }
  .site-layout-header {
    margin-bottom: 10px;
    padding-bottom: 8px;
  }
  .site-layout-header h2 { font-size: 15px; }

  /* App main uses tighter margins on mobile */
  .app-main { padding: 12px; }
  .overview-container { gap: 10px; }
}

.sidebar-section {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--divider);
}
.sidebar-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0 0 10px 0;
}

.sidebar-total-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
}

.sidebar-total-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sidebar-total-label {
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-capacity-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0 4px 0;
}

.sidebar-capacity-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.sidebar-capacity-text {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-grain-row {
  display: flex;
  align-items: center;
  padding: 5px 0;
  gap: 8px;
  font-size: 13px;
}

.sidebar-grain-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.sidebar-grain-swatch.bg-corn {
  background: var(--crop-corn, #E4C441);
}
.sidebar-grain-swatch.bg-soybean {
  background: var(--crop-soybean, #6B8E4F);
}
.sidebar-grain-swatch.bg-wheat {
  background: var(--crop-wheat, #C4A574);
}

.sidebar-grain-label {
  flex: 1;
  color: var(--text-primary);
}

.sidebar-grain-value {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-primary);
}

.sidebar-status-line {
  display: flex;
  align-items: center;
  padding: 4px 0;
  gap: 8px;
  font-size: 12.5px;
}

.sidebar-status-line.alarm {
  color: var(--co2-alarm-text, #B03030);
  font-weight: 500;
}

.sidebar-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-status-dot.dot-filling { background: var(--state-filling, #4A7C3A); }
.sidebar-status-dot.dot-unloading { background: var(--state-unloading, #C4664A); }
.sidebar-status-dot.dot-warn { background: var(--co2-warn-text, #C99B3A); }
.sidebar-status-dot.dot-alarm { background: var(--co2-alarm-text, #B03030); }

.sidebar-status-label {
  flex: 1;
}

.sidebar-status-count {
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Rig host badge — small indicator on host bins that have a rig deployed */
.rig-host-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  background: var(--info-fill, #E8F1F5);
  border: 2px solid var(--info-text, #2F7D95);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  z-index: 3;
  pointer-events: none;
}

.bin-circle.has-mobile-rig {
  border-style: dashed;
}


/* Placeholder bins — dashed outline to signal "not yet installed" */
.bin-circle.is-placeholder {
  border-style: dashed;
  opacity: 0.75;
}

.bin-circle.is-placeholder:hover {
  opacity: 1;
}

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE RIG CIRCLES — compact, distinct visual
   ══════════════════════════════════════════════════════════════════════════ */

.bin-circle.bin-mobile {
  border-width: 2px;
  border-style: dashed;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px;
  overflow: hidden;
  text-align: center;
  line-height: 1.1;
}

.bin-circle.bin-mobile.mobile-parked {
  background: rgba(47, 125, 149, 0.08);
  border-color: var(--info-text);
  color: var(--info-text);
  opacity: 0.65;
}

.bin-circle.bin-mobile.mobile-parked:hover {
  opacity: 1;
}

.bin-circle.bin-mobile.mobile-deployed {
  background: rgba(47, 125, 149, 0.2);
  border-color: var(--info-strong, var(--info-text));
  color: var(--info-text);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(47, 125, 149, 0.15);
}

.mobile-badge {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: currentColor;
  opacity: 0.7;
}

.mobile-sensor-label {
  font-size: 8px;
  font-weight: 600;
  color: currentColor;
  margin-top: 1px;
}

.mobile-reading {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1px;
}

.mobile-host-label {
  font-size: 7px;
  color: var(--text-secondary);
  margin-top: 1px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* SVG inside circle fills the space */
.bin-circle svg {
  display: block;
  width: 100%;
  height: 100%;
}


/* ══════════════════════════════════════════════════════════════════════════
   BIN CONTENTS SVG — bin rectangle, grain, hat/pants, text
   ══════════════════════════════════════════════════════════════════════════ */

.bin-outline-rect {
  fill: rgba(255,255,255,0.7);
  stroke: var(--text-secondary);
  stroke-width: 1.3;
}

.grain-fill {
  stroke: rgba(0,0,0,0.15);
  stroke-width: 0.5;
}
/* Active states: bright color = currently detecting movement */
.grain-fill.grain-filling-active   { fill: var(--grain-filling); }
.grain-fill.grain-unloading-active { fill: var(--grain-unloading); }
/* Idle states: muted gray = shape memory from last direction, not moving now */
.grain-fill.grain-idle-peak,
.grain-fill.grain-idle-dip         { fill: var(--grain-idle); opacity: 0.75; }

.sweep-line {
  stroke: var(--sweep-line);
  stroke-width: 1.2;
  stroke-dasharray: 2 2;
  opacity: 0.8;
}

/* Hat and pants direction arrows */
.direction-hat {
  stroke: rgba(0,0,0,0.15);
  stroke-width: 0.5;
}
.direction-hat.active { fill: var(--grain-filling); }
.direction-hat.idle   { fill: var(--grain-idle); opacity: 0.65; }

.direction-pants {
  stroke: rgba(0,0,0,0.15);
  stroke-width: 0.5;
}
.direction-pants.active { fill: var(--grain-unloading); }
.direction-pants.idle   { fill: var(--grain-idle); opacity: 0.65; }

/* Text inside/around the bin */
.bushels-text {
  fill: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
  dominant-baseline: middle;
}

.time-text {
  fill: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 500;
  dominant-baseline: middle;
}


/* ══════════════════════════════════════════════════════════════════════════
   SITE LANDMARKS — dump pit, tower dryer, grain leg
   ══════════════════════════════════════════════════════════════════════════ */

.site-landmark {
  position: absolute;
  background: rgba(90, 90, 85, 0.15);
  border: 1px dashed var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

.site-landmark.shape-rectangle {
  border-radius: 4px;
}

.site-landmark.shape-circle {
  border-radius: 50%;
}

.site-landmark span {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}


/* ══════════════════════════════════════════════════════════════════════════
   RESIZE HANDLES AND SHAPE TOGGLE (edit mode only)
   ══════════════════════════════════════════════════════════════════════════ */

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  pointer-events: auto;
  z-index: 5;
  cursor: nwse-resize;
  box-shadow: var(--shadow-sm);
}

.handle-nw { top: -6px;  left: -6px;  cursor: nwse-resize; }
.handle-ne { top: -6px;  right: -6px; cursor: nesw-resize; }
.handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }

.shape-toggle {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  z-index: 5;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.shape-toggle:hover {
  background: var(--accent-pale);
}

/* Actively resizing */
.site-landmark.resizing {
  opacity: 0.9;
  box-shadow: var(--shadow-md);
}


/* ══════════════════════════════════════════════════════════════════════════
   EDIT MODE — drag-and-drop positioning
   ══════════════════════════════════════════════════════════════════════════ */

.site-layout-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.edit-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 1px solid var(--divider);
  padding-left: 12px;
  margin-left: 4px;
}

.edit-mode-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-left: 8px;
}

/* Edit mode canvas — subtle grid background to show it's editable */
.site-layout-canvas.edit-mode {
  background-image:
    linear-gradient(to right, rgba(45,106,45,0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(45,106,45,0.04) 1px, transparent 1px);
  background-size: 60px 35px;
}

/* Draggable elements in edit mode */
.bin-circle.draggable,
.site-landmark.draggable {
  cursor: move;
  pointer-events: auto;  /* landmarks need this — they're pointer-events:none by default */
}

.bin-circle.draggable {
  /* Cursor already move; add a subtle outline to signal drag-ready */
  outline: 2px dashed rgba(45,106,45,0.3);
  outline-offset: 2px;
}

.site-landmark.draggable {
  border: 1px dashed var(--accent);
  background: rgba(45,106,45,0.08);
}

/* Actively-dragging element */
.bin-circle.dragging,
.site-landmark.dragging {
  opacity: 0.85;
  z-index: 100;
  box-shadow: var(--shadow-md);
  transform: scale(1.03);
}

/* Drag position tooltip */
.drag-tooltip {
  position: fixed;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  pointer-events: none;
  z-index: 3000;
  transform: translateX(-50%);
  display: none;
  box-shadow: var(--shadow-md);
}


/* ══════════════════════════════════════════════════════════════════════════
   BIN DETAIL VIEW
   ══════════════════════════════════════════════════════════════════════════ */

.bin-detail-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.back-link {
  color: var(--text-link);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-block;
  margin-bottom: 4px;
}

.back-link:hover {
  text-decoration: underline;
}

.bin-detail-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.bin-detail-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.bin-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.metric-block {
  padding: 14px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.metric-block-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 4px;
}

.metric-block-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-block-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}


/* ══════════════════════════════════════════════════════════════════════════
   BADGES (matches FarmBooks .badge)
   ══════════════════════════════════════════════════════════════════════════ */

.badge,
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.4;
  text-transform: none;
  letter-spacing: 0;
}

.badge::before,
.state-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.badge.success,
.state-pill.state-monitoring {
  background: var(--positive-fill);
  color: var(--positive-text);
  border-color: var(--positive-border);
}

.badge.warning,
.state-pill.state-filling {
  background: var(--warning-fill);
  color: var(--warning-text);
  border-color: var(--warning-border);
}

.badge.info,
.state-pill.state-unloading {
  background: var(--info-fill);
  color: var(--info-text);
  border-color: var(--info-border);
}

.badge.danger {
  background: var(--negative-fill);
  color: var(--negative-text);
  border-color: var(--negative-border);
}

.badge.neutral,
.state-pill.state-empty {
  background: var(--neutral-fill);
  color: var(--neutral-text);
  border-color: var(--neutral-border);
}


/* ══════════════════════════════════════════════════════════════════════════
   CHARTS
   ══════════════════════════════════════════════════════════════════════════ */

.chart-card h3 {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-range-buttons {
  display: flex;
  gap: 4px;
}

.range-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 12px;
  font-size: 11.5px;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 500;
}

.range-btn:hover {
  background: var(--surface-hover);
}

.range-btn.active {
  background: var(--accent-pale);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.chart-canvas-wrap {
  position: relative;
  height: 240px;
}


/* ══════════════════════════════════════════════════════════════════════════
   ALERTS
   ══════════════════════════════════════════════════════════════════════════ */

.alerts-header {
  padding: 16px 22px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.alert-row {
  padding: 14px 22px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background 0.15s;
}

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

.alert-row:hover {
  background: var(--surface-hover);
}

.alert-row.acknowledged {
  opacity: 0.55;
  background: var(--surface-sunken);
}

.alert-severity {
  width: 5px;
  height: 38px;
  border-radius: 2px;
  flex-shrink: 0;
}

.alert-severity.severity-info     { background: var(--info-text); }
.alert-severity.severity-warn     { background: var(--warning-strong, var(--c-warn-strong)); }
.alert-severity.severity-critical { background: var(--negative-text); }

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-message {
  font-size: 13.5px;
  color: var(--text-primary);
}

.alert-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.alert-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.no-alerts {
  padding: 48px 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}


/* ══════════════════════════════════════════════════════════════════════════
   ADMIN VIEW
   ══════════════════════════════════════════════════════════════════════════ */

.admin-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 900px;
}

.admin-card h2 {
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 8px;
}

.admin-card h3 {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 18px 0 10px;
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
}


/* ══════════════════════════════════════════════════════════════════════════
   INPUTS (matches FarmBooks .input, .fld)
   ══════════════════════════════════════════════════════════════════════════ */

label.fld,
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 0 5px;
}

.input,
.form-group input,
.form-group select,
.form-group textarea,
.modal input {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  padding: 8px 11px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.modal input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.input::placeholder,
.form-group input::placeholder {
  color: var(--text-muted);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}


/* ══════════════════════════════════════════════════════════════════════════
   BUTTONS (matches FarmBooks .btn)
   ══════════════════════════════════════════════════════════════════════════ */

.btn {
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  padding: 8px 16px;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: filter 0.15s, background 0.15s, border-color 0.15s;
  line-height: 1;
  font-family: inherit;
}

.btn:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 15px; }

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--negative-fill);
  color: var(--negative-text);
  border-color: var(--negative-border);
}
.btn-danger:hover { filter: brightness(0.97); }

.btn[disabled] { opacity: 0.5; cursor: not-allowed; }


/* ══════════════════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* CRITICAL: hidden attribute must override display: flex */
.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  background: var(--surface-raised);
  border-radius: var(--radius-card);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.modal h2 {
  font-size: 17px;
  margin-bottom: 6px;
}

.modal-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  margin-top: 12px;
  font-weight: 500;
}

.modal-error {
  color: var(--negative-text);
  background: var(--negative-fill);
  border: 1px solid var(--negative-border);
  font-size: 13px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}


/* ══════════════════════════════════════════════════════════════════════════
   FOOTER
   ══════════════════════════════════════════════════════════════════════════ */

#app-footer {
  padding: 10px 24px;
  background: var(--surface-sunken);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.separator {
  opacity: 0.4;
}

#connection-status.connected    { color: var(--positive-text); }
#connection-status.disconnected { color: var(--negative-text); }


/* ══════════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-width: 400px;
  pointer-events: auto;
  font-size: 13px;
  animation: slideIn 0.2s ease-out;
}

.toast.error {
  background: var(--negative-text);
  color: white;
}

.toast.success {
  background: var(--positive-text);
  color: white;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}


/* ══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 700px) {
  #app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
  }

  .header-nav {
    width: 100%;
    justify-content: space-between;
  }

  .nav-btn {
    flex: 1;
    text-align: center;
    padding: 6px 4px;
    font-size: 13px;
  }

  .auth-btn {
    margin-left: 0;
  }

  #app-main {
    padding: 14px;
  }

  .bin-detail-title {
    font-size: 20px;
  }

  .form-row {
    flex-direction: column;
  }
}
