/* ═══════════════════════════════════════════════════
   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; }

/* ── 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%; }
}

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