/* 
 * styles.css - Main stylesheet for Year-At-A-Glance Calendar
 *
 * Provides consistent styling for the application with a responsive design
 * that works well on desktops and tablets.
 */

/* ===== Base styles ===== */
:root {
  /* Color variables */
  --primary-color: #4682B4;  /* Steel Blue */
  --primary-light: #e3f2fd;
  --primary-dark: #31708f;
  --accent-color: #ffc107;   /* Amber */
  --accent-light: #ffecb3;
  --neutral-dark: #343a40;
  --neutral-medium: #6c757d;
  --neutral-light: #f8f9fa;
  --error-color: #f44336;
  --success-color: #4CAF50;
  --border-color: #ced4da;
  --text-color: #212529;
  --text-light: #6c757d;
  --background-color: #ffffff;
  --grid-line-color: #e0e0e0;

  /* Spacing variables */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  --font-size-base: 1rem;
}

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

html {
  font-size: 16px;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.4;
  color: var(--text-color);
  background-color: var(--background-color);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Layout ===== */
header {
  background-color: var(--primary-color);
  color: white;
  padding: var(--spacing-sm) var(--spacing-lg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.main-nav {
  max-width: 1400px;
  margin: 0 auto;
  padding-top: var(--spacing-sm);
}

.main-nav ul {
  display: flex;
  list-style: none;
  gap: var(--spacing-md);
}

.main-nav a {
  color: white;
  text-decoration: none;
  font-size: 0.9rem;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: 4px;
  transition: background-color 0.2s;
}

.main-nav a:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.app-header {
  max-width: 1400px;
  margin: 0 auto;
}

h1 {
  margin: 0;
  margin-bottom: var(--spacing-xs);
  font-size: 1.5rem;
  line-height: 1.2;
}

.app-description {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  line-height: 1.2;
  margin: 0;
}

main {
  flex: 1;
  padding: var(--spacing-lg);
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

footer {
  background-color: var(--neutral-light);
  color: var(--text-light);
  padding: var(--spacing-md) var(--spacing-lg);
  text-align: center;
  font-size: 0.875rem;
  border-top: 1px solid var(--border-color);
}

/* ===== Controls ===== */
#app-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  background-color: var(--neutral-light);
  border-radius: 4px;
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: var(--spacing-md);
}

.year-navigation {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.action-buttons {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  flex-wrap: wrap;
}

.import-export-group {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
}

.control-separator {
  width: 1px;
  height: 20px;
  background-color: var(--border-color);
  margin: 0 var(--spacing-md);
}

.btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: white;
  color: var(--text-color);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background-color: var(--neutral-light);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-nav {
  background-color: var(--neutral-light);
}

.btn-danger {
  background-color: var(--error-color);
  color: white;
  border-color: var(--error-color);
}

.btn-danger:hover {
  background-color: #d32f2f;
  border-color: #d32f2f;
}

.btn-manual {
  background-color: var(--neutral-light);
  text-decoration: none;
}

.year-select {
  padding: 0.375rem 1.75rem 0.375rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
  min-width: 100px;
  text-align: center;
  font-weight: 600;
}

/* ===== Legend ===== */
.event-legend {
  display: flex;
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-md);
  flex-wrap: wrap;
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.legend-item {
  display: flex;
  align-items: center;
  font-size: 0.875rem;
}

.legend-color {
  width: 16px;
  height: 16px;
  margin-right: var(--spacing-sm);
  border-radius: 2px;
}

.legend-regular {
  background-color: var(--primary-light);
  border-left: 2px solid var(--primary-color);
}

.legend-holiday {
  background-color: var(--accent-light);
  border-left: 2px solid var(--accent-color);
}

/* ===== Planner Container ===== */
.planner-container {
  border: 1px solid var(--border-color);
  border-radius: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Smoother scrolling on iOS */
  min-height: 600px;
  background-color: white;
  position: relative;
  /* Create a new stacking context */
  isolation: isolate;
  /* Prevent content from disappearing on some mobile browsers */
  transform: translateZ(0);
  will-change: transform; /* Hint to browser to use hardware acceleration */
}

/* Apply minimal width to ensure the grid is visible */
year-planner-grid {
  min-width: 1300px; /* Increased to accommodate the wider 37-column grid */
  display: block;
  /* Help maintain visual hierarchy */
  transform: translateZ(0);
}

/* ===== Notification ===== */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: 4px;
  color: white;
  font-weight: 500;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: none;
  max-width: 300px;
}

/* ===== Event Editor Modal ===== */
/* These styles will complement the web component's shadow DOM styles */
event-editor-modal {
  --modal-width: 500px;
  --modal-padding: var(--spacing-lg);
  --modal-border-radius: 4px;
  --modal-background: white;
  --modal-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ===== Responsive Styles ===== */
@media (max-width: 768px) {
  #app-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .year-navigation, 
  .action-buttons {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--spacing-md);
  }

  .action-buttons {
    margin-top: var(--spacing-md);
  }

  .import-export-group {
    margin-top: var(--spacing-sm);
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--spacing-md);
  }
  
  /* Hide separators on mobile */
  .control-separator {
    display: none;
  }
  
  /* Give more space to reset button */
  .btn-danger {
    margin-top: var(--spacing-sm);
  }

  .planner-container {
    margin-top: var(--spacing-md);
  }
  
  .event-legend {
    justify-content: flex-start;
    gap: var(--spacing-md);
  }
  
  .notification {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
  
  main {
    padding: var(--spacing-md);
  }
}

/* ===== Print Styles ===== */
@media print {
  /* Set up page for landscape A4 with narrow margins */
  @page {
    size: A4 landscape;
    margin: 0.5cm;
  }
  
  /* Hide non-essential elements */
  header,
  footer,
  #app-controls,
  #debug-tools,
  .notification,
  .import-export-group,
  .btn-manual,
  .control-separator {
    display: none !important;
  }
  
  /* Show legend but optimize for print */
  .event-legend {
    display: flex;
    padding: 0.1cm 0.2cm;
    margin-bottom: 0.2cm;
    border: none;
    font-size: 8pt;
    gap: 0.5cm;
  }
  
  .legend-item {
    font-size: 8pt;
  }
  
  .legend-color {
    width: 10px;
    height: 10px;
  }
  
  /* Container styling for print */
  .planner-container {
    border: none;
    overflow: visible;
    width: 100%;
    height: auto;
    page-break-inside: avoid;
    box-shadow: none;
  }
  
  /* Ensure grid fits on the page */
  year-planner-grid {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    transform-origin: top left;
    page-break-inside: avoid;
  }
  
  /* Override shadow DOM styles for print - apply these in the component too */
  ::slotted(.year-grid),
  ::part(year-grid) {
    font-size: 7pt !important;
  }
  
  /* Basic body/document reset */
  html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: white;
    font-size: 10pt;
  }
  
  body {
    display: block;
  }
  
  main {
    padding: 0;
    margin: 0;
    max-width: none;
    width: 100%;
  }
  
  /* Hide any scrollbars */
  ::-webkit-scrollbar {
    display: none;
  }
  
  /* Force background colors to print */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
}

/* ===== Utility Classes ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.hidden {
  display: none !important;
}

/* ===== Loading State ===== */
.loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.loading::after {
  content: '';
  width: 40px;
  height: 40px;
  border: 4px solid var(--neutral-light);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Adjust the grid-template-columns property in the .year-grid class */
.year-grid {
  display: grid;
  grid-template-columns: 3.75em repeat(37, minmax(20px, 1fr));
  grid-template-rows: 40px repeat(12, 80px);
  gap: 1px;
  background-color: var(--grid-line-color);
  border: 1px solid var(--grid-line-color);
  width: 100%;
  box-sizing: border-box;
}
