/* Base Styles */
body {
    font-family: Arial, sans-serif;
    margin: 20px;
    transition: background-color 0.3s, color 0.3s;
  --public-holiday-accent: #ffd400;
  --school-holiday-accent: #ff3b30;
  --hohes-friedensfest-accent: #7c4dff;
  }

  /* Calendar */
  .calendar {
    display: grid;
    grid-template-columns: repeat(auto-fill, 360px);
    gap: 10px;
    margin-bottom: 20px;
    justify-content: start;
  }

  .month {
    border: 1px solid;
    padding: 10px;
    text-align: center;
    transition: background-color 0.3s, border-color 0.3s;
    overflow-x: hidden;
  }

  .month h3 {
    text-align: center;
  }

  .days-header,
  .days {
    justify-content: center;
  }

  .month h3 {
    margin: 0;
  }

  /* Days Header */
  .days-header {
    display: grid;
    grid-template-columns: 40px repeat(7, 36px);
    gap: 5px;
    text-align: center;
    font-weight: bold;
    margin-top: 10px;
    grid-auto-rows: 32px;
  }

  .days-header div {
    padding: 5px;
    border: 1px solid;
    transition: background-color 0.3s, border-color 0.3s;
    box-sizing: border-box;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .days-header .kw-header {
    font-size: 0.9em;
  }

  /* Days */
  .days {
    display: grid;
    grid-template-columns: 40px repeat(7, 36px);
    gap: 5px;
    margin-top: 5px;
    grid-auto-rows: 32px;
  }

  .week-number {
    font-size: 0.9em;
    font-weight: bold;
    text-align: center;
    user-select: none;
    transition: background-color 0.3s, color 0.3s;
    box-sizing: border-box;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid;
    padding: 5px;
  }

  .day,
  .empty-day,
  .days-header div {
    box-sizing: border-box;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid;
    padding: 5px;
  }

  .day {
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.3s, border-color 0.3s;
  }

  .day.selected {
    background-color: #66bb6a;
  }

  /* Ensure selected days are visible in both themes */
  body.dark .day.selected,
  body.light .day.selected {
    background-color: #66bb6a !important;
  }

  .day.selected:hover {
    background-color: #66bb6a;
  }

  .day:hover {
    background-color: #e0e0e0;
  }

  /* Weekend styling */
  .day.weekend {
    /* Additional weekend styling will be applied in the theme sections */
  }

  /* ICS (Schulferien) and Public Holiday styling */
  .day.event-day {
    outline: 2px solid var(--school-holiday-accent) !important;
    outline-offset: -2px;
  }
  .day.public-holiday {
    outline: 2px solid var(--public-holiday-accent) !important;
    outline-offset: -2px;
  }
  .day.public-holiday.event-day {
    outline: 2px solid var(--school-holiday-accent) !important;
    outline-offset: -2px;
    box-shadow: inset 0 0 0 2px var(--public-holiday-accent);
  }

  /* Day hover tooltip */
  #day-hover-tooltip {
    position: absolute;
    z-index: 3000;
    display: none;
    max-width: 280px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    font-size: 0.95em;
    line-height: 1.25;
    pointer-events: none;
    backdrop-filter: blur(2px);
  }
  #day-hover-tooltip .tip-date {
    font-size: 0.85em;
    opacity: 0.85;
    margin-bottom: 6px;
  }
  #day-hover-tooltip .tip-section + .tip-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed;
  }
  #day-hover-tooltip .tip-title {
    font-size: 0.8em;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.9;
    margin-bottom: 4px;
  }
  #day-hover-tooltip .tip-line {
    margin: 2px 0;
  }

  /* Bavaria school holidays toggle label */
  .school-holidays-label {
    color: var(--school-holiday-accent);
  }

  .public-holidays-label {
    color: var(--public-holiday-accent);
  }

  .hohes-friedensfest-label {
    color: var(--public-holiday-accent);
  }

  /* Controls */
  .controls {
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  .controls label,
  .controls button {
    margin-left: 0;
  }

  .year-selector,
  .holiday-selector {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid;
    border-radius: 999px;
    transition: background-color 0.3s, border-color 0.3s, box-shadow 0.2s;
  }

  .year-selector label,
  .holiday-selector label {
    margin: 0;
    font-size: 0.9em;
    font-weight: 600;
    letter-spacing: 0.02em;
    opacity: 0.9;
  }

  #year-input,
  #holiday-count {
    width: 92px;
    border: 1px solid;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.95em;
    font-weight: 600;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.3s, color 0.3s;
    appearance: auto;
    -webkit-appearance: auto;
    -moz-appearance: auto;
  }

  #year-input:focus {
    outline: none;
  }

  #holiday-count:focus {
    outline: none;
  }

  #year-input:focus-visible,
  #holiday-count:focus-visible {
    box-shadow: 0 0 0 2px #66bb6a;
  }

  #year-input::-webkit-outer-spin-button,
  #holiday-count::-webkit-outer-spin-button,
  #year-input::-webkit-inner-spin-button {
    margin: 0;
    opacity: 1;
    height: 1.5em;
    width: 1.1em;
  }

  #holiday-count::-webkit-inner-spin-button {
    margin: 0;
    opacity: 1;
    height: 1.5em;
    width: 1.1em;
  }

  .checkbox-row {
    display: block;
    flex-basis: 100%;
    margin-top: 10px;
  }

  .checkbox-row .checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 0;
    margin-right: 10px;
    white-space: nowrap;
    --toggle-accent: currentColor;
  }

  .checkbox-row .checkbox-label input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
  }

  .checkbox-row .checkbox-text {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid currentColor;
    background-color: transparent;
    font-size: 0.92em;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
    user-select: none;
  }

  .checkbox-row .checkbox-text::before {
    content: "";
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid currentColor;
    background-color: transparent;
    flex: 0 0 16px;
    box-sizing: border-box;
    transition: background-color 0.2s, border-color 0.2s;
  }

  .checkbox-row .checkbox-text::after {
    content: "✓";
    position: absolute;
    left: 14px;
    font-size: 0.82em;
    font-weight: 800;
    color: #111;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.2s, transform 0.2s, color 0.2s;
  }

  .checkbox-row .checkbox-label input:focus-visible ~ .checkbox-text {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }

  .checkbox-row .checkbox-label input:checked ~ .checkbox-text {
    background-color: color-mix(in srgb, var(--toggle-accent) 25%, transparent);
    color: var(--toggle-accent);
    border-color: var(--toggle-accent);
    box-shadow: 0 0 0 2px var(--toggle-accent), 0 6px 14px rgba(0, 0, 0, 0.25);
    transform: translateY(-1px);
  }

  .checkbox-row .checkbox-label input:checked ~ .checkbox-text::before {
    background-color: var(--toggle-accent);
    border-color: var(--toggle-accent);
  }

  .checkbox-row .checkbox-label input:checked ~ .checkbox-text::after {
    opacity: 1;
    transform: scale(1);
    color: #111;
  }

  body.light .checkbox-row .checkbox-label input:checked ~ .checkbox-text::after {
    color: #fff;
  }

  .checkbox-row .checkbox-label:has(input:checked) .checkbox-text {
    background-color: color-mix(in srgb, var(--toggle-accent) 25%, transparent);
    color: var(--toggle-accent);
    border-color: var(--toggle-accent);
    box-shadow: 0 0 0 2px var(--toggle-accent), 0 6px 14px rgba(0, 0, 0, 0.25);
    transform: translateY(-1px);
  }

  .checkbox-row .checkbox-label:has(input:checked) .checkbox-text::before {
    background-color: var(--toggle-accent);
    border-color: var(--toggle-accent);
  }

  .checkbox-row .checkbox-label:has(input:checked) .checkbox-text::after {
    opacity: 1;
    transform: scale(1);
    color: #111;
  }

  body.light .checkbox-row .checkbox-label:has(input:checked) .checkbox-text::after {
    color: #fff;
  }

  .checkbox-row .checkbox-label input:not(:checked) ~ .checkbox-text:hover {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.12);
  }
  .ics-input {
    width: 100%;
    height: 100px;
    margin-top: 10px;
  }

  /* Lists */
  .events-list,
  .public-holidays-list,
  .selected-holidays-list {
    margin-top: 20px;
  }
  .events-list ul,
  .public-holidays-list ul,
  .selected-holidays-list ul {
    list-style-type: none;
    padding: 0;
  }
  .events-list li,
  .public-holidays-list li,
  .selected-holidays-list li {
    margin-bottom: 10px;
  }
  #selected-display {
    font-size: 1.1em;
    margin-top: 8px;
    margin-bottom: 10px;
  }

  #clear-selected-button,
  #export-cal-button,
  #import-cal-button {
    border: 1px solid #bfc5cc;
    color: #1f2328;
    background-color: #f3f5f7;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.92em;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(31, 35, 40, 0.04);
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.06s;
  }

  #clear-selected-button:hover,
  #export-cal-button:hover,
  #import-cal-button:hover {
    background-color: #ffffff;
    border-color: #aeb5bd;
  }

  #clear-selected-button:focus-visible,
  #export-cal-button:focus-visible,
  #import-cal-button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px #9aa6b2;
  }

  #clear-selected-button:active,
  #export-cal-button:active,
  #import-cal-button:active {
    transform: translateY(1px);
    box-shadow: inset 0 1px 2px rgba(31, 35, 40, 0.12);
  }

  body.dark #clear-selected-button,
  body.dark #export-cal-button,
  body.dark #import-cal-button {
    background-color: #eceff2;
    color: #1b1f23;
    border-color: #c7cdd4;
  }

  body.dark #clear-selected-button:hover,
  body.dark #export-cal-button:hover,
  body.dark #import-cal-button:hover {
    background-color: #ffffff;
    border-color: #b7bec6;
  }

  /* Toggle buttons */
  #themeToggle {
    position: fixed;
    top: 10px;
    right: 120px; /* leave space for the configurator button */
    padding: 5px 10px;
    cursor: pointer;
    z-index: 1000;
  }
  #themeConfigButton {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 5px 10px;
    cursor: pointer;
    z-index: 1000;
  }

  /* Theme Configurator Overlay */
  #themeConfigurator {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
  }

  #clearSelectedConfirmOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 2100;
    align-items: center;
    justify-content: center;
  }

  #clearSelectedConfirmOverlay .dialog {
    background-color: #fff;
    color: #111;
    padding: 18px;
    border-radius: 8px;
    min-width: 320px;
    max-width: 420px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  }

  #clearSelectedConfirmOverlay .dialog h2 {
    margin: 0 0 8px;
    font-size: 1.1em;
  }

  #clearSelectedConfirmOverlay .dialog p {
    margin: 0 0 14px;
    line-height: 1.35;
  }

  #clearSelectedConfirmOverlay .dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  #confirm-clear-selected-button {
    border: 1px solid #c26a6a;
    background-color: #fff4f4;
    color: #7f1d1d;
  }

  body.dark #clearSelectedConfirmOverlay .dialog {
    background-color: #333;
    color: #e0e0e0;
  }

  body.dark #confirm-clear-selected-button {
    border-color: #d18a8a;
    background-color: #4a2a2a;
    color: #ffd9d9;
  }

  #themeConfigurator .dialog {
    background-color: #fff;
    padding: 20px;
    border-radius: 5px;
    min-width: 300px;
  }
  body.dark #themeConfigurator .dialog {
    background-color: #333;
    color: #e0e0e0;
  }

  /* Dark Theme (default) */
  body.dark {
    background-color: #121212;
    color: #e0e0e0;
  }
  body.dark .month {
    background-color: #1e1e1e;
    border-color: #444;
  }
  body.dark .days-header div {
    background-color: #333;
    border-color: #555;
    color: #e0e0e0;
  }
  body.dark .day {
    background-color: #2a2a2a;
    border-color: #555;
    color: #e0e0e0;
  }
  body.dark .empty-day {
    background-color: #2a2a2a;
    border-color: #555;
  }
  body.dark .day:hover {
    background-color: #3a3a3a;
  }
  body.dark .day.weekend {
    background-color: #353535;
  }
  body.dark .week-number {
    color: #888;
    border-color: #555;
  }

  body.dark .year-selector,
  body.dark .holiday-selector {
    background-color: #1e1e1e;
    border-color: #555;
  }

  body.dark #year-input,
  body.dark #holiday-count {
    background-color: #2a2a2a;
    color: #e0e0e0;
    border-color: #666;
  }

  body.dark #year-input:hover,
  body.dark #holiday-count:hover {
    background-color: #303030;
  }

  body.dark #day-hover-tooltip {
    background-color: rgba(30, 30, 30, 0.98);
    color: #e0e0e0;
    border-color: #555;
  }
  body.dark #day-hover-tooltip .tip-section + .tip-section {
    border-top-color: rgba(255, 255, 255, 0.18);
  }

  /* Light Theme */
  body.light {
    background-color: #ffffff;
    color: #000000;
  }
  body.light .month {
    background-color: #f9f9f9;
    border-color: #ccc;
  }
  body.light .days-header div {
    background-color: #eee;
    border-color: #ccc;
    color: #000;
  }
  body.light .day {
    background-color: #fff;
    border-color: #ccc;
    color: #000;
  }
  body.light #day-hover-tooltip {
    background-color: rgba(255, 255, 255, 0.98);
    color: #111;
    border-color: #ccc;
  }
  body.light #day-hover-tooltip .tip-section + .tip-section {
    border-top-color: rgba(0, 0, 0, 0.2);
  }
  body.light .empty-day {
    background-color: #fff;
    border-color: #ccc;
  }
  body.light .day:hover {
    background-color: #f0f0f0;
  }
  body.light .day.weekend {
    background-color: #f5f5f5;
  }
  body.light .week-number {
    color: #666;
    border-color: #ccc;
  }

  body.light .year-selector,
  body.light .holiday-selector {
    background-color: #f7f7f7;
    border-color: #ccc;
  }

  body.light #year-input,
  body.light #holiday-count {
    background-color: #fff;
    color: #000;
    border-color: #bbb;
  }

  body.light #year-input:hover,
  body.light #holiday-count:hover {
    background-color: #fafafa;
  }
