/* ═══════════════════════════════════════════════════════
   Nigerian Crop Calendar – Utilitarian High-Contrast CSS
   Designed for outdoor use on budget smartphones.
   ═══════════════════════════════════════════════════════ */

/* ── Custom Properties ── */
:root {
  --color-text:       #1a1a1a;
  --color-bg:         #ffffff;
  --color-bg-alt:     #f5f5f5;
  --color-border:     #333333;
  --color-border-lt:  #999999;
  --color-accent:     #2E7D32;
  --color-accent-bg:  #e8f5e9;

  /* Activity palette */
  --color-land-prep:    #8B4513;
  --color-planting:     #2E7D32;
  --color-fertilizing:  #1565C0;
  --color-weeding:      #E65100;
  --color-harvesting:   #F9A825;

  /* Layout */
  --max-width:  960px;
  --top-bar-h:  56px;
  --zone-bar-h: 52px;
  --tab-h:      48px;

  /* Typography */
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-stack);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Offline Banner ── */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #d32f2f;
  color: #fff;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 700;
  padding: 6px 12px;
}

.offline-banner[hidden] { display: none; }

/* When banner is visible, push everything down */
body.is-offline .top-bar { top: 30px; }
body.is-offline .zone-bar { top: calc(var(--top-bar-h) + 30px); }
body.is-offline .tabs { top: calc(var(--top-bar-h) + var(--zone-bar-h) + 30px); }
body.is-offline .container {
  padding-top: calc(var(--top-bar-h) + var(--zone-bar-h) + var(--tab-h) + 30px + 16px);
}

/* ── Top Bar ── */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--top-bar-h);
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}

.app-title {
  font-size: 1.125rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-select {
  min-height: 36px;
  padding: 4px 8px;
  border: 2px solid rgba(255,255,255,0.6);
  border-radius: 6px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.lang-select option { color: var(--color-text); background: var(--color-bg); }

.lang-select:focus {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ── Zone Bar ── */
.zone-bar {
  position: fixed;
  top: var(--top-bar-h);
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--color-bg-alt);
  border-bottom: 2px solid var(--color-border);
  padding: 6px 12px;
}

.zone-select {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  appearance: auto;
}

.zone-select:focus {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.zone-info {
  margin-top: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #555;
}

.zone-info[hidden] { display: none; }

/* ── Tabs ── */
.tabs {
  position: fixed;
  top: calc(var(--top-bar-h) + var(--zone-bar-h));
  left: 0;
  right: 0;
  z-index: 98;
  display: flex;
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-border);
}

.tab {
  flex: 1;
  min-height: var(--tab-h);
  padding: 10px 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.tab:hover { background: var(--color-bg-alt); }
.tab:focus { outline: 3px solid var(--color-accent); outline-offset: -3px; }

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

/* ── Container ── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: calc(var(--top-bar-h) + var(--zone-bar-h) + var(--tab-h) + 16px) 12px 24px;
}

.view[hidden] { display: none; }

/* ── Loading State ── */
.loading {
  text-align: center;
  padding: 48px 16px;
  font-size: 1.125rem;
  font-weight: 700;
  color: #666;
}

/* ── Legend ── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--color-bg-alt);
  border: 2px solid var(--color-border-lt);
  border-radius: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 700;
}

.legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
  flex-shrink: 0;
}

/* ── Calendar Grid ── */
.calendar-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.month-card {
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}

.month-header {
  padding: 10px 12px;
  background: var(--color-accent-bg);
  border-bottom: 2px solid var(--color-border);
  font-size: 1rem;
  font-weight: 800;
  color: var(--color-text);
}

.month-body {
  padding: 8px 10px;
  min-height: 40px;
}

.month-empty {
  padding: 12px 10px;
  color: #888;
  font-size: 0.875rem;
  font-style: italic;
  text-align: center;
}

/* Activity pills */
.activity-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 3px 4px 3px 0;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  border: none;
  line-height: 1.3;
  transition: opacity 0.15s ease;
}

.activity-pill:hover  { opacity: 0.85; }
.activity-pill:focus  { outline: 3px solid var(--color-text); outline-offset: 2px; }

.activity-land_prep    { background: var(--color-land-prep); }
.activity-planting     { background: var(--color-planting); }
.activity-fertilizing  { background: var(--color-fertilizing); }
.activity-weeding      { background: var(--color-weeding); }
.activity-harvesting   { background: var(--color-harvesting); color: var(--color-text); }

/* ── Crops Grid ── */
.crops-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.crop-card {
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.crop-card:hover { border-color: var(--color-accent); }
.crop-card:focus { outline: 3px solid var(--color-accent); outline-offset: 2px; }

.crop-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.crop-icon {
  font-size: 2.25rem;
  line-height: 1;
  flex-shrink: 0;
}

.crop-name {
  font-size: 1.125rem;
  font-weight: 800;
}

.crop-meta {
  font-size: 0.875rem;
  color: #333;
  margin-bottom: 6px;
}

.crop-meta strong { font-weight: 800; }

/* pH bar */
.ph-bar-container {
  margin: 6px 0;
}

.ph-bar-label {
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.ph-bar-track {
  position: relative;
  height: 10px;
  background: linear-gradient(to right, #d32f2f, #f9a825, #2E7D32, #1565C0, #6a1b9a);
  border-radius: 5px;
  border: 1px solid #999;
}

.ph-bar-range {
  position: absolute;
  top: -3px;
  height: 16px;
  background: rgba(0,0,0,0.25);
  border: 2px solid var(--color-text);
  border-radius: 4px;
}

/* Mini schedule bar on crop cards */
.mini-schedule {
  display: flex;
  gap: 2px;
  margin-top: 8px;
}

.mini-month {
  flex: 1;
  height: 8px;
  background: #e0e0e0;
  border-radius: 2px;
}

.mini-month.has-activity { background: var(--color-accent); }

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0,0,0,0.5);
}

.modal[hidden] { display: none; }

.modal-content {
  position: relative;
  width: 100%;
  max-width: var(--max-width);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--color-bg);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  border: 2px solid var(--color-border);
  border-bottom: none;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  width: 44px;
  height: 44px;
  font-size: 1.25rem;
  font-weight: 800;
  background: var(--color-bg-alt);
  border: 2px solid var(--color-border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.modal-close:focus { outline: 3px solid var(--color-accent); outline-offset: 2px; }

/* Modal internals */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-icon { font-size: 3rem; line-height: 1; }

.detail-name {
  font-size: 1.5rem;
  font-weight: 800;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 6px;
  border-bottom: 2px solid var(--color-border-lt);
  padding-bottom: 4px;
}

.detail-text {
  font-size: 0.9375rem;
  line-height: 1.6;
}

.companion-list {
  list-style: none;
}

.companion-item {
  padding: 8px 0;
  border-bottom: 1px solid #ddd;
  font-size: 0.9375rem;
}

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

.companion-icon {
  font-size: 1.25rem;
  margin-right: 6px;
}

.companion-benefit {
  display: block;
  font-size: 0.8125rem;
  color: #555;
  margin-top: 2px;
  padding-left: 2rem;
}

/* Detail calendar pills */
.detail-events {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Responsive ── */
@media (min-width: 600px) {
  .calendar-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .crops-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-content {
    max-height: 80vh;
    border-radius: 12px;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 24px;
  }

  .modal {
    align-items: center;
  }
}

@media (min-width: 900px) {
  .calendar-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .crops-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .container {
    padding-left: 24px;
    padding-right: 24px;
  }
}

/* ── Print ── */
@media print {
  .top-bar,
  .zone-bar,
  .tabs,
  .modal,
  .offline-banner,
  .lang-select {
    display: none !important;
  }

  .container {
    padding-top: 0 !important;
    max-width: 100%;
  }

  .month-card,
  .crop-card {
    break-inside: avoid;
    border-color: #000;
  }

  .activity-pill {
    border: 1px solid #000;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
