/* ═══════════════════════════════════════════════════
   Plant-O-Manager — Design Tokens & Global Styles
   Estate Intelligence Platform · Killara, Sakleshpur
═══════════════════════════════════════════════════ */

/* ── Tokens ── */
:root {
  --green-900: #0d2b1e;
  --green-800: #1b4332;
  --green-700: #2d6a4f;
  --green-600: #40916c;
  --green-400: #52b788;
  --green-300: #74c69d;
  --green-100: #d8f3dc;
  --green-50:  #f0faf2;

  /* Zone colours */
  --zone-red:    #e74c3c;
  --zone-white:  #bdc3c7;
  --zone-purple: #8e44ad;
  --zone-orange: #e67e22;
  --zone-yellow: #f1c40f;
  --zone-green:  #27ae60;
  --zone-blue:   #2980b9;
  --zone-violet: #9b59b6;

  --bg:       #f4f6f0;
  --surface:  #ffffff;
  --border:   #dde8d8;
  --text:     #1a2e1a;
  --text-mid: #4a6a4a;
  --text-low: #7a9a7a;

  --warn-bg:   #fff3cd;
  --warn-text: #856404;
  --alert-bg:  #f8d7da;
  --alert-text:#842029;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.07);
  --shadow-md: 0 2px 10px rgba(0,0,0,0.10);

  --sidebar-w: 240px;
  --header-h:  56px;
  --nav-h:     60px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 15px;
  /* Prevent font size inflation on iOS */
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height — respects iOS browser chrome */
  /* iOS safe area support */
  padding-top: env(safe-area-inset-top);
}
a { color: var(--green-700); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Layout Shell ── */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--green-800);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform 0.25s ease;
  /* Ensure sidebar never overflows the viewport */
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}
.sidebar-logo {
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-logo-text {
  color: white;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.2px;
}
.sidebar-logo-text span { color: var(--green-300); }
.sidebar-logo-sub {
  color: rgba(255,255,255,0.45);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0;
}
.nav-section-label {
  padding: 10px 18px 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.35);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,0.75);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}
.nav-item.active {
  background: rgba(255,255,255,0.1);
  color: white;
  border-left-color: var(--green-300);
}
.nav-item .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--zone-red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
}
.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,0.7);
  font-size: 12px;
}
.sidebar-user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--green-700);
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-name { font-weight: 600; color: white; }
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,0.45); }

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Top header bar ── */
.top-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-header-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--green-800);
  flex: 1;
}
.top-header-date {
  font-size: 12px;
  color: var(--text-low);
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--green-800);
  padding: 4px;
}

/* ── Page content ── */
#page-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
}

/* ── Bottom nav (mobile) ── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 200;
  /* Height + iPhone home bar */
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-inner {
  display: flex;
  height: var(--nav-h);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-low);
  font-size: 10px;
  font-weight: 500;
  border: none;
  background: none;
  transition: color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* Larger tap target */
  min-height: 44px;
}
.bottom-nav-item .bn-icon { font-size: 18px; }
.bottom-nav-item.active { color: var(--green-700); }
.bottom-nav-item.active .bn-icon { color: var(--green-800); }

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 190;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Stat cards ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--green-600);
}
.stat-card.red    { border-left-color: var(--zone-red); }
.stat-card.orange { border-left-color: var(--zone-orange); }
.stat-card.yellow { border-left-color: var(--zone-yellow); }
.stat-card.green  { border-left-color: var(--zone-green); }
.stat-label { font-size: 11px; color: var(--text-low); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--green-800); margin: 4px 0 2px; line-height: 1; }
.stat-sub   { font-size: 11px; color: var(--text-low); }

/* ── Grid layouts ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

/* ── Alert rows ── */
.alert-list { list-style: none; }
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.alert-item:last-child { border-bottom: none; }
.alert-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.alert-dot.warn    { background: var(--zone-orange); }
.alert-dot.info    { background: var(--green-400); }
.alert-dot.danger  { background: var(--zone-red); }
.alert-text { flex: 1; color: var(--text); }
.alert-time { font-size: 11px; color: var(--text-low); white-space: nowrap; }

/* ── Weather widget ── */
.weather-main {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}
.weather-temp {
  font-size: 48px;
  font-weight: 300;
  color: var(--green-800);
  line-height: 1;
}
.weather-temp sup { font-size: 20px; }
.weather-desc { font-size: 14px; color: var(--text-mid); }
.weather-location { font-size: 11px; color: var(--text-low); }
.weather-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.weather-stat {
  background: var(--green-50);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}
.weather-stat .ws-label { font-size: 10px; color: var(--text-low); text-transform: uppercase; }
.weather-stat .ws-value { font-size: 15px; font-weight: 700; color: var(--green-800); margin-top: 2px; }
.weather-forecast {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.forecast-day {
  background: var(--green-50);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
  flex-shrink: 0;
  min-width: 58px;
}
.forecast-day.today { background: var(--green-800); color: white; }
.forecast-day .fd-day { font-size: 10px; font-weight: 700; text-transform: uppercase; }
.forecast-day .fd-icon { font-size: 18px; margin: 4px 0; }
.forecast-day .fd-temp { font-size: 12px; font-weight: 700; }
.forecast-day .fd-rain { font-size: 10px; color: #2980b9; }
.forecast-day.today .fd-rain { color: #74c69d; }

/* ── Activity advisory ── */
.activity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.activity-card {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.activity-card.go   { background: #d8f3dc; }
.activity-card.warn { background: var(--warn-bg); }
.activity-card.stop { background: var(--alert-bg); }
.activity-card .ac-icon { font-size: 20px; }
.activity-card .ac-label { font-size: 11px; font-weight: 700; margin: 4px 0 2px; }
.activity-card.go   .ac-label { color: #1b4332; }
.activity-card.warn .ac-label { color: #856404; }
.activity-card.stop .ac-label { color: #842029; }
.activity-card .ac-reason { font-size: 10px; color: var(--text-low); }

/* ── Price ticker ── */
.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.price-card {
  background: var(--green-50);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.price-card .pc-crop { font-size: 11px; font-weight: 700; color: var(--text-mid); text-transform: uppercase; letter-spacing: 0.5px; }
.price-card .pc-price { font-size: 20px; font-weight: 700; color: var(--green-800); margin: 4px 0 2px; }
.price-card .pc-unit  { font-size: 10px; color: var(--text-low); }
.price-card .pc-change { font-size: 11px; font-weight: 700; margin-top: 4px; }
.price-card .pc-change.up   { color: #27ae60; }
.price-card .pc-change.down { color: var(--zone-red); }
.price-card .pc-change.flat { color: var(--text-low); }
.price-source { font-size: 10px; color: var(--text-low); margin-top: 10px; text-align: right; }

/* ── Block map ── */
.block-map-wrap {
  position: relative;
  background: var(--green-900);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#block-map { width: 100%; height: 340px; }
.map-legend {
  position: absolute;
  bottom: 10px; left: 10px;
  background: rgba(13,43,30,0.85);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  max-width: 240px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: rgba(255,255,255,0.75);
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Labour attendance cards ── */
.labour-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  transition: border-color 0.15s;
}
.labour-card.saved {
  border-color: var(--green-400);
}
.worker-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.worker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.worker-row:hover, .worker-row:active { background: var(--green-50); }
.inactive-list .worker-row { opacity: 0.55; }
.worker-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--green-700);
  color: white;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.worker-info { flex: 1; min-width: 0; }
.worker-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}
.worker-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.zone-badge {
  display: inline-block;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  color: white;
}
.zone-badge.A-red    { background: var(--zone-red); }
.zone-badge.A-white  { background: var(--zone-white); color: #333; }
.zone-badge.A-purple { background: var(--zone-purple); }
.zone-badge.B-orange { background: var(--zone-orange); }
.zone-badge.B-yellow { background: var(--zone-yellow); color: #333; }
.zone-badge.B-green  { background: var(--zone-green); }
.zone-badge.C-orange { background: var(--zone-orange); }
.zone-badge.C-yellow { background: var(--zone-yellow); color: #333; }
.zone-badge.D-violet { background: var(--zone-violet); }
.zone-badge.blue     { background: var(--zone-blue); }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  background: var(--green-800);
  color: white;
  padding: 9px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
}
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--green-50); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-mid); margin-bottom: 5px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  /* Minimum 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  /* iOS: prevent inner shadow on inputs */
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--green-600);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* ── Harvest block rows ── */
.harvest-block-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-light);
  gap: 8px;
}
.harvest-block-row:last-child { border-bottom: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  /* Remove 300ms tap delay on iOS */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--green-700); color: white; }
.btn-primary:hover { background: var(--green-800); }
.btn-secondary { background: var(--green-100); color: var(--green-800); }
.btn-secondary:hover { background: var(--green-300); }
.btn-danger { background: var(--alert-bg); color: var(--alert-text); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Loading / spinner ── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--green-100);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { text-align: center; padding: 40px 20px; color: var(--text-low); font-size: 13px; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-low);
}
.empty-state .es-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .es-title { font-size: 15px; font-weight: 700; color: var(--text-mid); margin-bottom: 6px; }
.empty-state .es-sub { font-size: 13px; }

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  bottom: 80px; right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--green-800);
  color: white;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 300px;
}
.toast.success { background: var(--green-700); }
.toast.error   { background: #842029; }
.toast.warn    { background: #856404; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Login screen ── */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--green-900) 0%, var(--green-800) 60%, var(--green-700) 100%);
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
}
.login-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-text {
  font-size: 22px;
  font-weight: 900;
  color: var(--green-800);
  letter-spacing: -0.5px;
}
.login-logo-text span { color: var(--green-600); }
.login-logo-sub { font-size: 11px; color: var(--text-low); letter-spacing: 1px; text-transform: uppercase; margin-top: 2px; }
.login-title { font-size: 18px; font-weight: 700; color: var(--green-800); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-low); margin-bottom: 24px; }
.login-error {
  background: var(--alert-bg);
  color: var(--alert-text);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.login-error.show { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; }
  .bottom-nav { display: block; }
  .menu-toggle { display: block; }
  #page-content {
    padding: 16px 14px;
    /* Bottom padding = nav bar + home indicator + a little breathing room */
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .top-header {
    padding: 0 14px;
    /* Top header sits below status bar on iPhone */
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-h) + env(safe-area-inset-top));
  }
  .top-header-date { display: none; }

  /* Login card — tighter on small screens */
  .login-card {
    padding: 28px 20px;
    border-radius: var(--radius-md);
  }
  .login-logo { margin-bottom: 20px; }

  /* Sidebar safe area on iPhone */
  .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Weather forecast: full scroll on mobile */
  .weather-forecast { gap: 4px; }
  .forecast-day { min-width: 52px; padding: 6px 8px; }

  /* Activity advisory: 2 cols on small phone */
  .activity-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Toast above bottom nav */
  #toast-container {
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
    right: 12px;
    left: 12px;
    align-items: flex-end;
  }
  .toast { max-width: 100%; }

  /* Offline banner — account for iOS notch */
  #offline-banner {
    top: calc(var(--header-h) + env(safe-area-inset-top));
  }
}

@media (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .activity-grid { grid-template-columns: repeat(2, 1fr); }
  .login-card { padding: 24px 16px; }
}

/* ════════════════════════════════════════
   SPRINT 12 — OFFLINE MODE
════════════════════════════════════════ */

/* Offline banner */
#offline-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid #ffc107;
  padding: 0 16px;
  position: sticky;
  top: var(--header-h);
  z-index: 99;
  flex-shrink: 0;
}

/* Mutation buttons disabled offline via assertOnline() in JS */

/* ════════════════════════════════════════
   PHASE 3 — AI PANEL
════════════════════════════════════════ */

#ai-fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 16px;
  z-index: 200;
  background: var(--green-800);
  color: white;
  border: none;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 6px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#ai-panel {
  position: fixed;
  bottom: 0; right: 0;
  width: 100%;
  max-width: 480px;
  height: 70vh;
  max-height: 600px;
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
}
#ai-panel.open { transform: translateY(0); }

.ai-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-close {
  background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--text-low); padding: 4px;
  flex-shrink: 0;
}
.ai-mode-select {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green-800);
  background: var(--green-50);
  cursor: pointer;
}
.ai-mode-desc {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-low);
  background: var(--green-50);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--green-700);
  color: white;
  border-bottom-right-radius: 4px;
}
.ai-msg.assistant {
  align-self: flex-start;
  background: #f0f4f0;
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.ai-msg.thinking {
  align-self: flex-start;
  background: #f0f4f0;
  color: var(--text-low);
  font-style: italic;
}
.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  resize: none;
  font-family: inherit;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
}
.ai-send {
  background: var(--green-700);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  align-self: flex-end;
}
.ai-send:disabled { opacity: 0.5; }
.ai-key-bar {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--warn-bg);
  flex-shrink: 0;
}
.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 14px 12px;
}
.ai-chip {
  background: var(--green-50);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--green-800);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ai-chip:active { background: var(--green-100); }


/* ═══════════════════════════════════════════════════
   Dashboard redesign — new component styles
═══════════════════════════════════════════════════ */

/* ── Dashboard header ── */
.dash-header {
  margin-bottom: 16px;
}
.dash-date {
  font-size: 12px;
  color: var(--text-low);
  margin-bottom: 2px;
}
.dash-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--green-800);
  line-height: 1.2;
}
.dash-title-loc {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-low);
}

/* ── Section spacing ── */
.dash-section {
  margin-bottom: 16px;
}

/* ── Alert banner ── */
.dash-alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fff3cd;
  border: 1px solid #ffe082;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
}
.dash-alert-banner:hover { background: #ffeaa0; }
.banner-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.banner-pills {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.banner-pill {
  font-size: 12px;
  font-weight: 600;
  border-radius: 10px;
  padding: 2px 9px;
}
.banner-pill.danger { background: #f8d7da; color: #842029; }
.banner-pill.warn   { background: #fff3cd; color: #856404; border: 1px solid #f5c542; }
.banner-pill.info   { background: var(--green-100); color: var(--green-800); }
.banner-arrow {
  font-size: 18px;
  color: #856404;
  flex-shrink: 0;
  align-self: center;
}

/* ── Quick-glance tiles ── */
.dash-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.dash-tile {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 12px 12px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--green-600);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.dash-tile:hover  { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.dash-tile:active { transform: translateY(0); }
.dash-tile.tile-red    { border-left-color: var(--zone-red); }
.dash-tile.tile-orange { border-left-color: var(--zone-orange); }
.dash-tile.tile-yellow { border-left-color: var(--zone-yellow); }
.dash-tile.tile-green  { border-left-color: var(--green-600); }
.dash-tile.tile-neutral{ border-left-color: var(--text-low); }
.dt-icon  { font-size: 18px; margin-bottom: 6px; }
.dt-value { font-size: 28px; font-weight: 700; color: var(--green-800); line-height: 1; margin-bottom: 2px; }
.dt-label { font-size: 11px; font-weight: 700; color: var(--text-mid); text-transform: uppercase; letter-spacing: 0.5px; }
.dt-sub   { font-size: 10px; color: var(--text-low); margin-top: 2px; }

/* ── Weather collapse toggle ── */
.dash-collapse-toggle { cursor: pointer; user-select: none; }
.dash-collapse-toggle:hover { opacity: 0.8; }

/* ── Zone rows ── */
.zone-row {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.zone-row:last-of-type { border-bottom: none; }
.zone-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  flex-wrap: wrap;
  gap: 4px;
}
.zone-dot  { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.zone-name { font-size: 13px; font-weight: 700; color: var(--green-900); }
.zone-meta { font-size: 11px; color: var(--text-low); }
.zone-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.zone-tag  {
  font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 8px; white-space: nowrap;
}
.zone-tag.ok     { background: #d8f3dc; color: #1b4332; }
.zone-tag.warn   { background: #fff3cd; color: #856404; }
.zone-tag.danger { background: #fde0e0; color: #842029; }
.zone-bar-row {
  display: flex; align-items: center; gap: 8px;
}
.zone-bar-track {
  flex: 1; height: 6px; background: var(--green-50); border-radius: 3px; overflow: hidden;
}
.zone-bar-fill  { height: 100%; border-radius: 3px; opacity: 0.75; transition: width 0.4s; }
.zone-bar-label { font-size: 11px; font-weight: 700; color: var(--text-mid); white-space: nowrap; }
.zone-no-harvest{ font-size: 11px; color: var(--text-low); }
.zone-total     { font-size: 11px; color: var(--text-low); margin-top: 8px; text-align: right; }

/* ── Ops snapshot ── */
.snap-row {
  display: flex; gap: 12px; margin-bottom: 10px;
}
.snap-stat {
  flex: 1; text-align: center;
  background: var(--green-50); border-radius: var(--radius-sm);
  padding: 10px 8px; border-top: 3px solid var(--green-600);
}
.snap-val  { font-size: 26px; font-weight: 700; line-height: 1; }
.snap-lbl  { font-size: 11px; color: var(--text-low); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.4px; }
.snap-last { font-size: 12px; color: var(--text-low); padding-top: 4px; }

/* ── Plan progress ── */
.plan-progress { display: flex; flex-direction: column; gap: 8px; }
.plan-bar-track {
  height: 10px; background: var(--green-50); border-radius: 5px; overflow: hidden;
}
.plan-bar-fill  { height: 100%; border-radius: 5px; transition: width 0.5s ease; }
.plan-progress-label {
  display: flex; align-items: baseline; gap: 10px;
}

/* ── Inventory + nursery mini-panel ── */
.inv-section  { padding: 4px 0 6px; }
.inv-heading  {
  font-size: 12px; font-weight: 700; color: var(--text-mid);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;
}
.inv-count    {
  background: #fde0e0; color: #842029;
  font-size: 10px; padding: 1px 7px; border-radius: 8px; font-weight: 700;
  text-transform: none; letter-spacing: 0;
}
.inv-items    { display: flex; flex-direction: column; gap: 4px; }
.inv-item     {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--text);
}
.inv-name     { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-qty      { font-size: 12px; font-weight: 700; flex-shrink: 0; margin-left: 8px; }

/* ── Price ticker ── */
.dash-price-ticker {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ticker-label  { font-size: 12px; font-weight: 700; color: var(--text-mid); text-transform: uppercase; letter-spacing: 0.5px; }
.ticker-price  { font-size: 18px; font-weight: 700; color: var(--green-800); }
.ticker-unit   { font-size: 11px; font-weight: 400; color: var(--text-low); }
.ticker-raw    { font-size: 11px; color: var(--text-low); }
.ticker-chg    { font-size: 12px; font-weight: 700; }
.ticker-source { font-size: 10px; color: var(--text-low); }
.ticker-unavail{ font-size: 13px; color: var(--text-low); }

/* ── Responsive ── */
@media (max-width: 600px) {
  .dash-tiles {
    grid-template-columns: repeat(2, 1fr);
  }
  .dt-value { font-size: 24px; }
  .dash-price-ticker {
    gap: 7px;
  }
  .ticker-raw, .ticker-source { display: none; }
}
