/* ============================================================
   Martin Farmstead Apiary — Bee-themed styles
   ============================================================ */

:root {
  --honey:        #F4A800;
  --honey-dark:   #D4880F;
  --amber:        #B8860B;
  --brown:        #8B6914;
  --brown-dark:   #4A2C0A;
  --cream:        #FFF8E7;
  --cream-dark:   #FFF3CD;
  --white:        #FFFFFF;
  --text:         #2C1810;
  --text-muted:   #7A6B5E;
  --line:         #E8D5B8;

  --green:        #4CAF50;
  --green-soft:   #E8F5E9;
  --yellow:       #FFC107;
  --yellow-soft:  #FFF8E1;
  --red:          #F44336;
  --red-soft:     #FFEBEE;

  --shadow:       0 4px 20px rgba(139,105,20,0.12);
  --shadow-lg:    0 8px 32px rgba(139,105,20,0.18);
  --radius:       16px;
  --radius-sm:    10px;
}

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

body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Honeycomb background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(244,168,0,0.06) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(244,168,0,0.04) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ── */
.app-wrap {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #8B6914 0%, #D4880F 40%, #F4A800 100%);
  padding: 24px 24px 20px;
  color: #fff;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(139,105,20,0.3);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  font-size: 2rem;
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 900;
  text-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.header-subtitle {
  font-size: 0.8rem;
  opacity: 0.85;
  font-weight: 600;
}

.header-nav {
  display: flex;
  gap: 8px;
}

.header-nav a, .header-nav button {
  background: rgba(255,255,255,0.2);
  border: 1.5px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.header-nav a:hover, .header-nav button:hover {
  background: rgba(255,255,255,0.3);
}

/* ── Alert Banner ── */
.alert-banner {
  padding: 0 0 8px;
}

.alert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 700;
}

.alert-item.red {
  background: var(--red-soft);
  color: #C62828;
  border-left: 4px solid var(--red);
}

.alert-item.yellow {
  background: var(--yellow-soft);
  color: #F57F17;
  border-left: 4px solid var(--yellow);
}

.alert-item.green {
  background: var(--green-soft);
  color: #2E7D32;
  border-left: 4px solid var(--green);
}

.alert-hive {
  font-weight: 800;
  white-space: nowrap;
}

/* ── Section Titles ── */
.section-title {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--brown);
  margin: 28px 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--line);
  border-radius: 99px;
}

/* ── Cards ── */
.card {
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

/* ── Hive Cards Grid ── */
.hive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.hive-card {
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}

.hive-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.hive-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.hive-card.health-green::before { background: var(--green); }
.hive-card.health-yellow::before { background: var(--yellow); }
.hive-card.health-red::before { background: var(--red); }

.hive-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.hive-name {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--text);
}

.hive-type {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.hive-status {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-active { background: var(--green-soft); color: #2E7D32; }
.status-dead { background: var(--red-soft); color: #C62828; }

.hive-alerts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.hive-alert-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.hive-alert-badge.red { background: var(--red-soft); color: #C62828; }
.hive-alert-badge.yellow { background: var(--yellow-soft); color: #F57F17; }

.hive-inspections {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 10px;
}

.hive-inspection-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.82rem;
}

.inspection-date {
  color: var(--text-muted);
  font-weight: 600;
}

.inspection-summary {
  font-weight: 700;
  display: flex;
  gap: 6px;
  align-items: center;
}

.hive-tasks-count {
  font-size: 0.78rem;
  color: var(--honey-dark);
  font-weight: 700;
  margin-top: 8px;
}

/* ── Flow Panel ── */
.flow-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.flow-card {
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}

.flow-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.flow-value {
  font-size: 1.3rem;
  font-weight: 900;
}

.flow-value.high { color: var(--green); }
.flow-value.medium { color: var(--honey); }
.flow-value.low { color: var(--text-muted); }
.flow-value.none { color: #BDBDBD; }

.flow-sources {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Weather Widget ── */
.weather-card {
  background: linear-gradient(135deg, #E3F2FD 0%, #BBDEFB 100%);
  border: 1.5px solid #90CAF9;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.weather-temp {
  font-size: 2.4rem;
  font-weight: 900;
  color: #1565C0;
}

.weather-details {
  font-size: 0.85rem;
  color: #1976D2;
  line-height: 1.6;
  font-weight: 600;
}

.weather-forecast {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
}

.forecast-day {
  background: var(--white);
  border: 1px solid #90CAF9;
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  min-width: 80px;
  font-size: 0.78rem;
}

.forecast-day .day-name {
  font-weight: 800;
  color: #1565C0;
}

.forecast-day .day-temps {
  font-weight: 700;
  color: var(--text);
}

/* ── Tasks List ── */
.task-list {
  list-style: none;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}

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

.task-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--honey);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.task-check:hover {
  background: var(--honey);
  color: white;
}

.task-check.completed {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.task-hive {
  font-weight: 800;
  color: var(--honey-dark);
  white-space: nowrap;
  font-size: 0.78rem;
}

.task-text {
  flex: 1;
  font-weight: 600;
}

.task-priority {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.priority-high { background: var(--red-soft); color: #C62828; }
.priority-normal { background: var(--cream-dark); color: var(--brown); }
.priority-low { background: #F5F5F5; color: #757575; }

/* ── Treatments Timeline ── */
.treatment-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.treatment-date {
  font-weight: 700;
  color: var(--text-muted);
  min-width: 90px;
}

.treatment-hive {
  font-weight: 800;
  color: var(--honey-dark);
}

.treatment-detail {
  flex: 1;
  font-weight: 600;
}

/* ── Supply Row ── */
.supply-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.supply-date {
  font-weight: 700;
  color: var(--text-muted);
  min-width: 90px;
}

.supply-item {
  font-weight: 800;
  color: var(--brown);
}

.supply-amount {
  flex: 1;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 800;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.12s, transform 0.12s;
  font-family: inherit;
}

.btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--honey), var(--honey-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(244,168,0,0.3);
}

.btn-secondary {
  background: var(--cream-dark);
  color: var(--brown-dark);
  border: 1.5px solid var(--line);
}

.btn-danger {
  background: linear-gradient(135deg, var(--red), #D32F2F);
  color: #fff;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1rem;
  border-radius: 16px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* ── Inspection Form ── */
.form-section {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.form-section-header {
  background: var(--cream-dark);
  padding: 12px 16px;
  font-weight: 800;
  font-size: 0.92rem;
  color: var(--brown);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.form-section-header::after {
  content: '\25BC';
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.form-section.collapsed .form-section-header::after {
  transform: rotate(-90deg);
}

.form-section.collapsed .form-section-body {
  display: none;
}

.form-section-body {
  padding: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--honey);
  box-shadow: 0 0 0 3px rgba(244,168,0,0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Toggle switches */
.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-btn {
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  color: var(--text-muted);
}

.toggle-btn.active {
  border-color: var(--honey);
  background: rgba(244,168,0,0.1);
  color: var(--honey-dark);
}

.toggle-btn:hover {
  border-color: var(--honey);
}

/* Counter input */
.counter-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.counter-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--honey);
  background: var(--white);
  color: var(--honey);
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  font-family: inherit;
}

.counter-btn:hover {
  background: var(--honey);
  color: #fff;
}

.counter-value {
  font-size: 1.3rem;
  font-weight: 900;
  min-width: 30px;
  text-align: center;
}

/* ── Photo Grid ── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--line);
}

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

.photo-thumb .photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-upload-btn {
  aspect-ratio: 1;
  border: 3px dashed var(--honey);
  border-radius: var(--radius-sm);
  background: rgba(244,168,0,0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--honey);
  font-weight: 700;
  font-size: 0.75rem;
  gap: 4px;
}

.photo-upload-btn:hover {
  background: rgba(244,168,0,0.12);
}

.photo-upload-btn .camera-icon {
  font-size: 1.8rem;
}

.photo-uploading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--line);
  border-top-color: var(--honey);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Inspection History ── */
.inspection-card {
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.inspection-card:hover {
  box-shadow: var(--shadow-lg);
}

.inspection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.inspection-header-date {
  font-weight: 800;
  color: var(--brown);
}

.inspection-badges {
  display: flex;
  gap: 4px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.badge-green { background: var(--green-soft); color: #2E7D32; }
.badge-yellow { background: var(--yellow-soft); color: #F57F17; }
.badge-red { background: var(--red-soft); color: #C62828; }
.badge-blue { background: #E3F2FD; color: #1565C0; }

.inspection-notes {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 6px;
}

/* ── View / Navigation ── */
.view { display: none; }
.view.active { display: block; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--honey-dark);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 12px;
  font-family: inherit;
}

.back-btn:hover {
  color: var(--honey);
}

/* ── Auto-populated info bar ── */
.auto-info {
  background: var(--cream-dark);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.82rem;
  font-weight: 600;
}

.auto-info-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.auto-info-label {
  color: var(--text-muted);
}

.auto-info-value {
  font-weight: 800;
  color: var(--text);
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--line);
  border-top-color: var(--honey);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .bee-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

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

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  margin-bottom: 16px;
  color: var(--brown);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    gap: 8px;
  }

  #header-weather {
    flex-wrap: wrap;
    justify-content: center;
  }

  .hive-grid {
    grid-template-columns: 1fr;
  }

  .flow-panel {
    grid-template-columns: 1fr 1fr !important;
  }

  #tasks-alerts-row,
  #tasks-flow-row,
  #conditions-row,
  #records-row {
    grid-template-columns: 1fr !important;
  }

  .weather-card {
    flex-direction: column;
    text-align: center;
  }

  .weather-forecast {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

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

  .auto-info {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1.15rem;
  }

  .flow-panel {
    grid-template-columns: 1fr;
  }

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

/* ── Hive Detail Header ── */
.hive-detail-header {
  background: linear-gradient(135deg, rgba(244,168,0,0.08), rgba(244,168,0,0.02));
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.hive-detail-name {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 4px;
}

.hive-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.hive-detail-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab {
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  font-family: inherit;
  transition: color 0.15s;
}

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

.tab:hover {
  color: var(--honey);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Footer ── */
.footer {
  margin-top: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 16px;
}

.footer a {
  color: var(--honey-dark);
  text-decoration: none;
  font-weight: 700;
}
