:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-color: #dee2e6;
    --error-color: #dc3545;
    --card-bg: #ffffff;
    --body-bg: #f1f3f5;
    --spacing: 1rem;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    background-color: var(--body-bg);
    color: var(--dark-color);
    padding: var(--spacing);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--spacing);
}

h1, h2 {
    margin-bottom: var(--spacing);
    color: var(--dark-color);
}

h1 { text-align: center; }

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: calc(var(--spacing) * 1.5);
    margin-bottom: var(--spacing);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.controls .input-group {
    margin-bottom: var(--spacing);
}

.controls label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.controls input[type="date"],
.controls fieldset {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}
.controls input[type="date"] {
    max-width: 200px; /* Limit width on larger screens */
}

.controls fieldset {
    padding-bottom: 0.5rem; /* Adjust padding for legend */
}

.controls legend {
    font-weight: 500;
    padding: 0 0.5rem; /* Give legend some space */
    margin-left: 0.5rem; /* Align with input padding */
}

.controls .options {
    margin-top: var(--spacing);
    margin-bottom: var(--spacing);
}

.controls .options label {
    display: inline-flex;
    align-items: center;
    margin-right: var(--spacing);
    font-weight: normal;
}

.controls .options input[type="checkbox"] {
    margin-right: 0.5rem;
    width: 1.1em;
    height: 1.1em;
    cursor: pointer;
}

.date-format-info {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-top: -0.5rem;
    margin-bottom: var(--spacing);
}

.weekdays {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing);
    padding-top: 0.5rem;
}

.weekdays label {
    display: inline-flex; /* Align checkbox and text */
    align-items: center;
    margin-bottom: 0; /* Reset margin */
    font-weight: normal;
    cursor: pointer;
}

.weekdays input[type="checkbox"] {
    margin-right: 0.5rem;
    width: 1.1em;
    height: 1.1em;
    cursor: pointer;
}

button {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

button:hover {
    background-color: #0056b3;
}

.error {
    color: var(--error-color);
    margin-top: var(--spacing);
    font-weight: 500;
}

.timeline-output-container {
    margin-top: calc(var(--spacing) * 2);
}

#timeline-output {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding-top: var(--spacing); /* Keep some top padding */
    min-height: 60px; /* Reverted min-height */
}

.timeline-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end; /* Align checkbox towards bottom */
    width: 28px;
    height: 55px; /* Reverted height */
    position: relative;
    margin-bottom: 5px;
    --checkbox-height: 20px; /* Define checkbox height variable */
    /* padding: 15px 0 15px 0; REMOVED */
    /* box-sizing: content-box; REMOVED */
}

.timeline-item .week-number {
    position: absolute;
    bottom: calc(var(--checkbox-height) + 3px); /* Calculate bottom based on variable + gap */
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    color: var(--secondary-color);
    font-weight: bold;
    white-space: nowrap;
}

.timeline-item input[type="checkbox"] {
    width: 20px; /* Keep width potentially separate */
    height: var(--checkbox-height); /* Use variable for height */
    margin: 0; /* Remove margin, use positioning */
    cursor: pointer;
    accent-color: var(--primary-color);
    position: relative; /* Needed for z-index */
    z-index: 1; /* Checkbox below day number visually */
}

.timeline-item .day-number {
    position: absolute;
    bottom: 0px; /* Position over the checkbox area (aligned bottom) */
    left: 0;
    width: 100%; /* Take full width of item */
    height: var(--checkbox-height); /* Match checkbox height using variable */
    line-height: var(--checkbox-height); /* Vertically center text using variable */
    text-align: center; /* Horizontally center text */
    font-size: 0.7rem;
    color: #999; /* Adjusted: Made more gray */
    pointer-events: none; /* Allow clicks to pass through to checkbox */
    z-index: 2; /* Ensure number is visually on top */
}

/* Style day number differently when checkbox is checked */
.timeline-item input[type="checkbox"]:checked + .day-number {
    color: white; /* Change color when checked */
    font-weight: bold;
}

#printable-title {
    display: none; /* Hidden by default, shown in print */
    text-align: center;
    font-size: 14pt;
    font-weight: bold;
    margin-bottom: 5mm;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .weekdays {
        gap: 0.8rem;
    }
    .controls input[type="date"] {
        max-width: none; /* Full width on smaller screens */
    }
}

@media (max-width: 480px) {
    body { padding: calc(var(--spacing) / 2); }
    .container { padding: calc(var(--spacing) / 2); }
    .card { padding: var(--spacing); }
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.3rem; }
    .weekdays { flex-direction: column; align-items: flex-start; gap: 0.5rem;}
    button { width: 100%; }
}

/* Print styles */
@media print {
    @page {
        size: A4 landscape;
        margin: 10mm; /* Adjust margins as needed */
    }

    body {
        background-color: #fff;
        color: #000;
        padding: 0;
        margin: 0;
        font-size: 10pt; /* Base print font size */
        -webkit-print-color-adjust: exact; /* Ensure colors print */
        print-color-adjust: exact;
    }

    .container {
        max-width: none;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    .controls, button, h1, .timeline-output-container > h2, .date-format-info, #error-message {
        display: none; /* Hide non-timeline elements */
    }

    #printable-title {
        display: block; /* Show printable title */
    }

    .timeline-output-container {
        border: none;
        box-shadow: none;
        padding: 0;
        margin: 0;
        width: 100%; /* Use full printable width */
        height: 100%; /* Use full printable height */
    }

    #timeline-output {
        display: flex;
        flex-wrap: wrap;
        gap: 2mm; /* Adjust gap for print */
        padding: 0; /* Remove padding */
        margin: 0;
        width: 100%;
        height: 100%;
        align-content: flex-start; /* Start items from top */
        padding-top: 4mm; /* Add padding to the top for week numbers */
    }

    #timeline-output.hide-week-numbers {
        padding-top: 1mm; /* Reduce top padding if no week numbers */
    }

    #timeline-output.hide-week-numbers .timeline-item .week-number {
        display: none;
    }

    .timeline-item {
        width: 10mm;
        height: 16mm; /* Reverted height */
        margin-bottom: 1mm;
        page-break-inside: avoid;
        position: relative;
        justify-content: flex-end; /* Align checkbox towards bottom */
        align-items: center;
        --print-checkbox-height: 7mm; /* Define print checkbox height variable */
        /* padding: 3mm 0 3mm 0; REMOVED */
        /* box-sizing: content-box; REMOVED */
    }

    .timeline-item .week-number {
        font-size: 0.6rem; /* Match web view font size */
        bottom: calc(var(--print-checkbox-height) + 0.8mm); /* Calculate bottom based on variable + gap */
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        color: #000;
        font-weight: bold;
        white-space: nowrap;
    }

    .timeline-item input[type="checkbox"] {
        width: 7mm; /* Keep width potentially separate */
        height: var(--print-checkbox-height); /* Use variable for height */
        border: 1px solid #000;
        appearance: none;
        -webkit-appearance: none;
        background-color: #fff;
        margin: 0; /* Remove margin */
        position: relative; /* Ensure positioning context */
        z-index: 1; /* Checkbox below number */
    }
     /* Basic square for unchecked state */
    .timeline-item input[type="checkbox"]:checked::before {
        content: 'X';
        display: block;
        text-align: center;
        font-size: 10pt;
        line-height: var(--print-checkbox-height); /* Use variable for line-height */
        color: #000;
    }

    .timeline-item .day-number {
        position: absolute;
        bottom: 0mm; /* Position over checkbox area (aligned bottom) */
        left: 0;
        width: 100%;
        height: var(--print-checkbox-height); /* Match checkbox height using variable */
        line-height: var(--print-checkbox-height); /* Vertically center using variable */
        text-align: center;
        font-size: 8pt;
        color: #555; /* Adjusted: Made gray for print */
        margin-top: 0;
        pointer-events: none;
        z-index: 2; /* Number on top */
    }

}
