:root {
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  --brand-primary: #C76A1B;
  --brand-secondary: #E38B2C;
  --brand-tint: rgba(227, 139, 44, 0.14);
  --bg-color: #000000;
  --surface: #0B0D11;
  --surface-border: rgba(255, 255, 255, 0.10);
  --text-color: #F2F4F7;
  --muted-color: #A1A6AD;
  --accent-instagram: #e1306c;
  --accent-linkedin: #0072b1;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
}

body {
  background: radial-gradient(circle at top right, rgba(227, 139, 44, 0.14), transparent 30%), var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start; /* Align to top */
  align-items: stretch; /* Stretch to fill width */
  font-family: var(--font-system);
  padding: 0; /* Reset padding from global body */
  text-align: left; /* Ensure text aligns left by default */
  overflow-x: hidden;
}

.light-mode {
  --brand-primary: #DE8E3A;
  --brand-secondary: #F0A955;
  --brand-tint: rgba(240, 169, 85, 0.16);
  --bg-color: #F5F5F7;
  --surface: #FFFFFF;
  --surface-border: rgba(15, 17, 21, 0.08);
  --text-color: #1D1D1F;
  --muted-color: #6E6E73;
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.08);
}

.dark-mode {
  --bg-color: #000000;
  --surface: #0B0D11;
  --surface-border: rgba(255, 255, 255, 0.10);
  --text-color: #F2F4F7;
  --muted-color: #A1A6AD;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--surface-border);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-knob {
  position: absolute;
  inset: 3px;
  width: auto;
  height: auto;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--muted-color);
  transition: all 0.22s ease;
  line-height: 1;
  font-size: 0.95rem;
}

.theme-toggle input:not(:checked) + .theme-knob {
  background: #FFFFFF;
  color: #1D1D1F;
}

/* School Calendar Specific Styles */
.app-shell.school-shell {
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.header-location .kicker {
  font-size: 0.8rem;
  color: var(--muted-color);
  margin: 0;
}

.header-location h1 {
  margin: 4px 0 0;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.2;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.nav-chip {
  display: inline-flex;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--brand-tint);
  color: var(--brand-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.2s ease;
}

.nav-chip:hover {
  background: color-mix(in srgb, var(--brand-tint) 80%, var(--brand-primary));
}

/* New Top Controls Bar */
.top-controls-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  position: sticky;
  top: 78px; /* Height of the header, adjust if header height changes */
  z-index: 9;
  flex-wrap: wrap;
  justify-content: center;
}

.top-controls-bar .control-group {
    flex-grow: 1;
    min-width: 120px;
}

.top-controls-bar select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text-color);
  font-family: var(--font-system);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-appearance: none; /* Remove default arrow */
  -moz-appearance: none;
  appearance: none;
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23F2F4F7%22%20d%3D%22M287%2C197.393L146.2%2C56.593L5.4%2C197.393c-7.8%2C7.8-20.5%2C7.8-28.3%2C0c-7.8-7.8-7.8-20.5%2C0-28.3l142.9-142.9c7.8-7.8%2C20.5-7.8%2C28.3%2C0l142.9%2C142.9C294.8%2C176.893%2C294.8%2C189.593%2C287%2C197.393z%22%2F%3E%3C%2Fsvg%3E'); /* Custom arrow */
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
}

.light-mode .top-controls-bar select {
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%231D1D1F%22%20d%3D%22M287%2C197.393L146.2%2C56.593L5.4%2C197.393c-7.8%2C7.8-20.5%2C7.8-28.3%2C0c-7.8-7.8-7.8-20.5%2C0-28.3l142.9-142.9c7.8-7.8%2C20.5-7.8%2C28.3%2C0l142.9%2C142.9C294.8%2C176.893%2C294.8%2C189.593%2C287%2C197.393z%22%2F%3E%3C%2Fsvg%3E');
}

.top-controls-bar select:hover {
  border-color: var(--brand-primary);
}

.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;
}

.school-shell main {
  flex-grow: 1;
  display: grid;
  gap: 16px;
  padding: 16px;
  grid-template-columns: 1fr; /* Default to single column on mobile */
}

.school-calendar-page .card {
  border: 1px solid var(--surface-border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

body.light-mode.school-calendar-page .card {
  background: var(--surface);
  border-color: var(--surface-border);
}

.calendar-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: stretch;
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.calendar-hero > div:first-child {
  flex-grow: 1;
}

.calendar-hero h2 {
  margin: 4px 0 6px;
  font-size: clamp(1.8rem, 4vw, 3.3rem);
}

.hero-range {
  color: var(--muted-color);
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 8px;
}

/* Reintroduced styles for hero stats as chips */
.hero-stats-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px; /* Space between chips */
  margin-top: 12px; /* Space from hero text */
}

.hero-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  border: 1px solid var(--surface-border);
  border-radius: 14px; /* Slightly smaller border-radius */
  padding: 8px 12px; /* Reduced padding */
  background: rgba(255, 255, 255, 0.05); /* Slight tint for dark mode */
  flex-shrink: 0; /* Prevent chips from shrinking too much */
}

body.light-mode .hero-chip {
  background: rgba(0, 0, 0, 0.03); /* Slight tint for light mode */
}

.hero-chip-label {
  color: var(--muted-color);
  font-size: 0.7rem; /* Smaller font size */
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.hero-chip-value {
  font-weight: 700;
  font-size: 0.9rem; /* Smaller font size */
  color: var(--text-color);
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.calendar-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 100px), 1fr));
  gap: 10px;
  margin-top: 8px;
}

.timeline-item {
  border: 1px solid var(--surface-border);
  border-radius: 18px;
  padding: 12px;
  min-height: 104px;
  background: var(--surface);
  position: relative;
}

.timeline-item.current {
  outline: 3px solid #75d68b;
  background: rgba(39, 174, 96, 0.17);
}

.timeline-item.holiday {
  background: rgba(46, 134, 222, 0.14);
}

.timeline-item strong {
  display: block;
  margin-bottom: 8px;
}

.month-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn.small {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 1px solid var(--surface-border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text-color);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn.small:hover {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

.month-grid {
  display: grid;
  grid-template-columns: 0.5fr repeat(7, 1fr); /* Added 0.5fr for week number column */
  gap: 6px;
  margin-top: 12px;
}

.day-head,
.day-cell {
  padding: 9px;
  border-radius: 12px;
  min-height: 48px;
  border: 1px solid var(--surface-border);
}

.day-head {
  min-height: auto;
  font-weight: 800;
  color: var(--muted-color);
  text-align: center;
}

.week-number-cell { /* New style for week number column */
    padding: 9px;
    border-radius: 12px;
    min-height: 48px;
    border: 1px solid var(--surface-border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--muted-color);
    font-size: 0.85rem;
}

.day-head.week-number-header {
    text-align: center;
}

.day-cell {
  background: var(--surface);
}

.day-cell.outside {
  opacity: 0.35;
}

.day-cell.today {
  outline: 2px solid var(--brand-primary);
}

.day-cell.term {
  background: rgba(39, 174, 96, 0.18);
}

.day-cell.school-holiday {
  background: rgba(46, 134, 222, 0.18);
}

.day-cell.public-holiday {
  box-shadow: inset 0 -4px 0 #f5c542;
}

.day-number {
  font-weight: 800;
}

.day-note {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted-color);
}

.legend {
  margin-top: 12px;
  color: var(--muted-color);
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
}

.term-dot,
.holiday-dot,
.public-dot {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 50%;
}

.term-dot {
  background: #27ae60;
}
.holiday-dot {
  background: #2e86de;
}
.public-dot {
  background: #f5c542;
}

/* Removed max-height from #holidaysSection */
/* #holidaysSection {
    max-height: 400px;
    overflow-y: auto;
} */

#publicHolidayList { /* Make public holidays list scrollable */
    max-height: 400px; /* Adjust as needed */
    overflow-y: auto;
}

.holiday-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.holiday-pill {
  border: 1px solid rgba(245, 197, 66, 0.35);
  border-radius: 16px;
  padding: 12px;
  background: rgba(245, 197, 66, 0.09);
}

.table-wrap { /* Make week numbers table scrollable */
  overflow: auto;
  max-height: 400px; /* Adjust as needed */
}

.week-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.week-table th,
.week-table td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--surface-border);
}

.week-table tr.current {
  background: rgba(117, 214, 139, 0.16);
}

/* Styles for the download section */
.download-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.download-options button,
.download-options a {
  min-width: 140px;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text-color);
  font-family: var(--font-system);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.light-mode .download-options button,
body.light-mode .download-options a {
  background: var(--surface);
  color: var(--text-color);
  border-color: var(--surface-border);
}

.download-options button:hover,
.download-options a:hover {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

.google-export-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
}

.google-export-links a {
  color: inherit;
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  padding: 8px 10px;
  text-decoration: none;
  font-size: 0.85rem;
}

body.light-mode .google-export-links a {
  border-color: var(--surface-border);
}


.global-footer {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface);
  border-top: 1px solid var(--surface-border);
  text-align: center;
}

.footer-nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 12px;
}

.footer-nav a {
  color: var(--muted-color);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s ease;
}

.footer-nav a:hover {
  color: var(--text-color);
}

.attribution-bar p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted-color);
}

/* Media Queries */
@media (min-width: 781px) {
  .school-shell main {
    grid-template-columns: 1fr; /* Ensure main is a single column for overall flow */
  }

  /* Sections that should always span full width */
  .calendar-hero,
  #timelineSection,
  #weeksSection {
    grid-column: 1 / -1; /* Span all columns of the main grid */
  }

  .calendar-details-grid {
    display: grid;
    grid-template-columns: 2fr 1fr; /* Monthly Calendar (2/3) and Public Holidays (1/3) */
    gap: 16px;
    grid-column: 1 / -1; /* Span full width of main grid */
    grid-auto-rows: 1fr; /* Make children (sections) equal height */
  }

  .top-controls-bar {
    justify-content: flex-start;
  }

  .top-controls-bar .control-group {
      flex-grow: 0;
      min-width: 180px; /* Give more space to selectors on desktop */
  }
}

@media (max-width: 780px) {
  .app-header {
    padding: 12px;
  }

  .header-top {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 8px;
  }

  .header-location h1 {
    font-size: 1.5rem;
  }

  .header-controls {
    width: 100%;
    justify-content: flex-end;
  }

  .app-shell.school-shell {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .school-shell main {
    padding: 12px;
  }

  .calendar-hero {
    flex-direction: column;
  }

  /* Adjust hero-stats-chips for mobile */
  .hero-stats-chips {
    flex-direction: column; /* Stack chips vertically on mobile */
    align-items: flex-start;
  }

  .hero-chip {
    width: 100%; /* Make chips full width on mobile */
  }

  .calendar-timeline {
    grid-template-columns: 1fr; /* Stack vertically on small screens */
  }

  .day-cell {
    min-height: 58px;
    padding: 7px;
  }

  .day-note {
    font-size: 0.65rem;
  }

  .top-controls-bar {
    top: 70px; /* Adjust for smaller header height on mobile */
    padding: 10px 12px;
  }

  .month-grid {
    grid-template-columns: 0.5fr repeat(7, 1fr); /* Keep week number column on mobile */
  }
}