/* History (Historial) - Final Layout Fix v2 */

#history-section {
  padding-top: 20px;
  padding-bottom: 20px;
  /* margin, width, and ad padding handled by global.css */
}

@media (max-width: 768px) {
  #history-section {
    padding-top: var(--header-height-condensed); /* Clear sticky header */
  }
}

#history-section.hidden {
  display: none !important;
}

.history-page-wrapper {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center; /* Center children like .history-card */
}

.history-card {
  margin: 0 auto; /* Ensure centering as a block */
  background: var(--bg-card);
  border-radius: 16px;
  /* Fluid padding: scales from 12px to 24px */
  padding: clamp(12px, 4vw, 24px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--glass-border);
  display: flex !important;
  flex-direction: column !important;
  align-items: center;
  min-height: auto;
  /* Sync with home panels margins */
  width: 95%;
  max-width: 600px;
  box-sizing: border-box;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 600px; /* Keep it tight */
  margin-bottom: 8px;
}

.history-header h2 {
  margin: 0;
  /* Fluid title: scales from 1.15rem to 1.5rem */
  font-size: clamp(1.15rem, 5vw, 1.5rem);
  color: var(--text-main);
  text-transform: capitalize;
}

.history-subtitle {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

/* THE GRID - Fluid sizes using clamp */
#history-grid-container {
  /* Fits 7 columns + gaps in ~300px at minimum scaling */
  --cell-size: clamp(34px, 12vw, 60px);
  --gap-size: clamp(4px, 1.5vw, 8px);
  display: grid !important;
  grid-template-columns: repeat(7, var(--cell-size)) !important;
  gap: var(--gap-size);
  justify-content: center;
  margin: 0 auto;
  max-width: 100%; /* Safety */
}

#history-grid-container .calendar-day {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

body.dark-mode #history-grid-container .calendar-day {
  background: rgba(255, 255, 255, 0.08); /* Slightly more visible */
}

#history-grid-container .calendar-day:hover {
  transform: translateY(-2px);
  background: rgba(0, 0, 0, 0.1);
  border-color: var(--brand-color);
}

body.dark-mode #history-grid-container .calendar-day:hover {
  background: rgba(255, 255, 255, 0.15);
}

#history-grid-container .calendar-day.header-day {
  background: transparent !important;
  cursor: default;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  border: none !important;
  height: 30px; /* Shorter header */
}

#history-grid-container .calendar-day.empty {
  background: transparent !important;
  cursor: default;
  border: none !important;
}

#history-grid-container .calendar-day.win {
  background: #22c55e !important;
  color: white !important;
}

#history-grid-container .calendar-day.loss {
  background: #eab308 !important;
  color: white !important;
}

/* Markers */
#history-grid-container .completed-dot {
  position: absolute;
  bottom: calc(var(--cell-size) * 0.05);
  right: calc(var(--cell-size) * 0.03);
  font-size: calc(var(--cell-size) * 0.3);
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2));
}

/* Nav Buttons */
.icon-btn-medium {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-main);
}

.icon-btn-medium:hover {
  background: var(--brand-color);
  color: white;
  border-color: var(--brand-color);
}

.icon-btn-medium.disabled {
  opacity: 0.4;
  filter: grayscale(1);
  pointer-events: none;
  cursor: default;
}

/* Responsive refinements handled by fluid layouts above */
@media (max-width: 360px) {
  .history-header h2 {
    font-size: 1.1rem; /* Extra safety for ultra small */
  }
}
