/* Import theme variables */
@import url('theme.css');

body {
  font-family: var(--font-primary, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif);
  margin: 0;
  padding: 0;
  background: var(--bg-color, #f0fdf4);
  color: var(--text-color, #333);
  transition: background 0.3s ease, color 0.3s ease;
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

/* Header */
header {
  background: linear-gradient(135deg, var(--primary-green, #2e7d32), var(--secondary-green, #66bb6a));
  color: #fff;
  padding: 1.5rem 2rem;
  text-align: center;
  position: relative;
  min-height: 70px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

header h1 {
  margin: 0;
  font-size: 2.2rem;
  font-weight: 600;
  background: linear-gradient(45deg, #fff, #f0fdf4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  position: absolute;
  right: 2rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 1rem;
}

/* Theme toggle button */
.theme-toggle {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 50px;
  font-size: 0.9rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.25);
}

.back-btn {
  color: #fff;
  text-decoration: none;
  font-size: 1rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Crop filter */
.filter-container {
  margin: 1.5rem;
  text-align: center;
}

#cropSelect {
  padding: 0.5rem 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 1rem 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  color: black;
}

.legend-item.sow { 
  background: #c8e6c9; 
}

.legend-item.grow { 
  background: #fff9c4; 
}

.legend-item.harvest { 
  background: #ffccbc; 
}

/* Container around calendar to enable horizontal scroll on small screens */
.calendar-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
  box-sizing: border-box;
}

/* Calendar Grid */
.calendar {
  display: grid;
  grid-template-columns: 150px repeat(12, minmax(60px, 1fr));
  gap: 0.5rem;
  padding: 1.5rem;
  max-width: 95%;
  margin: auto;
  box-sizing: border-box;
  min-width: 900px;
}

.calendar div {
  padding: 0.75rem;
  text-align: center;
  border-radius: 6px;
  transition: transform 0.3s ease, background 0.3s ease, opacity 0.3s ease;
  font-size: 0.95rem;
}

/* Header months */
.month {
  position: sticky;
  top: 5px;
  z-index: 5;
  font-weight: bold;
  background: var(--light-green, #e8f5e9);
  animation: fadeInUp 0.4s ease forwards;
}

/* Crop name column */
.crop-name {
  font-weight: bold;
  background: #fff8e1;
  color: #333;
}

/* Cell states */
.month-cell.sow {
  background: #c8e6c9;
}

.month-cell.grow {
  background: #fff9c4;
}

.month-cell.harvest {
  background: #ffccbc;
}

/* Emojis and tooltip */
.emoji {
  font-size: 1.2rem;
  display: block;
}

.tooltip {
  visibility: hidden;
  opacity: 0;
  background: #333;
  color: #fff;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-top: 0.3rem;
  position: absolute;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  transition: opacity 0.3s ease;
  z-index: 20;
}

.month-cell:hover .tooltip {
  visibility: visible;
  opacity: 1;
}

/* Loading state */
.calendar-loading {
  text-align: center;
  padding: 2rem;
}

.loading-spinner {
  border: 4px solid #ddd;
  border-top: 4px solid #4caf50;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  margin: auto;
  animation: spin 1s linear infinite;
}

.loading-text {
  margin-top: 1rem;
  font-size: 1rem;
  color: #666;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* Responsive adjustments */

/* Large screens (desktops) */
@media (min-width: 1025px) {
  .calendar {
    grid-template-columns: repeat(13, 1fr);
    max-width: 1200px;
    margin: 1rem auto;
    padding: 1.5rem 2rem;
    overflow-x: visible;
  }
  
  .calendar div {
    font-size: 0.95rem;
    padding: 0.75rem;
  }
  
  .month {
    font-size: 1.1rem;
  }
  
  .crop-name {
    font-size: 1.1rem;
  }
}

@media (max-width: 900px) {
  header {
    padding: 1.2rem 1.5rem;
  }
  
  header h1 {
    font-size: 1.8rem;
  }
  
  .header-actions {
    right: 1.5rem;
    gap: 0.8rem;
  }
  
  .theme-toggle, .back-btn {
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
  }

  .calendar {
    min-width: 700px;
    padding: 1rem;
  }
}

@media (max-width: 800px) {
  header {
    padding: 1rem 1rem 0.5rem;
    min-height: auto;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
  }
  
  header h1 {
    font-size: 1.5rem;
    line-height: 1.2;
    margin: 0;
    order: 1;
    width: 100%;
  }

  .header-actions {
    position: static;
    transform: none;
    right: auto;
    top: auto;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    order: 2;
    margin: 0;
    padding: 0.25rem 0;
  }
  
  .theme-toggle {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    min-width: 45px;
    order: 1;
    flex-shrink: 0;
  }
  
  .theme-toggle i {
    font-size: 0.9rem;
  }

  .back-btn {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    white-space: nowrap;
    order: 2;
    flex-shrink: 0;
    text-decoration: none;
  }
  
  .header-actions > * {
    flex: 0 0 auto;
  }
}

@media (max-width: 600px) {
  .calendar {
    gap: 0.4rem;
    padding: 0.75rem;
    max-width: 100%;
    min-width: 300px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .legend {
    gap: 1rem;
  }

  .legend-item {
    font-size: 0.85rem;
  }
}

@media (max-width: 375px) {
  header {
    padding: 0.8rem 0.8rem 0.4rem;
    gap: 0.4rem;
  }
  
  header h1 {
    font-size: 1.3rem;
  }
  
  .header-actions {
    gap: 0.6rem;
  }
  
  .theme-toggle, .back-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    min-width: 40px;
  }
  
  .theme-toggle i {
    font-size: 0.8rem;
  }
  
  .back-btn {
    min-width: 35px;
    text-align: center;
  }

  .back-btn::before {
    content: "← ";
  }

  .legend {
    gap: 0.5rem;
  }

  .legend-item {
    font-size: 0.8rem;
  }
}

/* Enhanced loading state for better visibility */
.calendar-loading {
  text-align: center;
  padding: 2rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  grid-column: 1 / -1;
  min-height: 200px;
  box-sizing: border-box;
}

@media (max-width: 600px) {
  .calendar-loading {
    padding: 1rem;
    min-height: 150px;
  }
  
  /* Temporarily adjust calendar during loading to fit screen */
  .calendar.loading {
    min-width: auto !important;
    grid-template-columns: 1fr;
    padding: 1rem;
  }
}
