* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    --secondary-color: #ecf0f1;
    --accent-color: #3498db;
    --border-color: #bdc3c7;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: rgba(0, 0, 0, 0.03);
    min-height: 100vh;
    padding: 20px;
    color: var(--secondary-color);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow-lg);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--secondary-color);
    flex-wrap: wrap;
    gap: 20px;
}

.header h1 {
    font-size: 28px;
    color: var(--primary-color);
    flex: 1;
    min-width: 200px;
}

.logo-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 200px;
}

.logo-preview {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 6px;
    background: white;
    border: 1px solid var(--border-color);
    padding: 6px;
}

.logo-upload input[type="file"] {
    font-size: 12px;
}

.title-input {
    font-size: 22px;
    font-weight: 700;
    border: none;
    outline: none;
    background: transparent;
    color: #000; /* Main calendar title text -> black */
}
.controls {
    display: flex;
    flex-direction: row;
    align-items: center; /* vertically center the buttons and date picker */
    gap: 8px; /* consistent spacing between items */
    flex-wrap: wrap; /* keep responsive on narrow screens */
}

.controls > .start-date-section {
    margin-left: auto; /* push the date picker to the far right */
}

.controls > .print-btn {
    display: inline-flex;
    align-items: center; /* ensure icon/text are vertically centered */
    justify-content: center;
}
.print-btn {
    padding: 6px 10px;
    border-radius: 6px;
    border: none;
    background: #2c3e50;
    color: white;
    cursor: pointer;
}
.print-btn:hover { background: #223242; }

.report-wrap { position: relative; display:inline-block; }
.report-menu { position: absolute; top: 110%; left: 0; background: white; border: 1px solid var(--border-color); padding: 6px; border-radius:6px; display:flex; gap:6px; }
.report-menu button { background:#2c3e50; color:white; padding:6px 10px; border-radius:4px; border:none; cursor:pointer }
.report-menu button:hover { background:#223242 }

.start-date-section {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--secondary-color);
    padding: 6px 8px;
    border-radius: 8px;
    width: 140px; /* fixed, compact width */
    justify-content: flex-end; /* align inner elements to the right */
}

.start-date-section label {
    font-weight: 600;
    color: var(--primary-color);
}

.start-date-section input {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    text-align: right; /* align the date text to the right */
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 25px;
    align-items: start;
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Calendar */
.calendar-section {
    overflow-x: auto;
}

.calendar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    min-width: 100%;
}

.day-cell {
    background: white;
    border: 2px solid #cfd8dc; /* darkened border for readability */
    border-radius: 8px;
    padding: 12px;
    min-height: 200px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.day-cell:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.day-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    color: var(--primary-color);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--secondary-color);
}

.day-name {
    color: red;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.day-date {
    color: #000; /* Dates inside calendar cells -> black */
    font-size: 12px;
    margin-top: 0;
}

/* Tasks grid inside a day cell: enforce equal 3x3 sizing even when empty.
   Use flex on the parent day-cell so the header has intrinsic size and the
   tasks-container fills remaining space. Inside, a CSS Grid with
   `grid-auto-rows: 1fr` ensures each row gets equal height and each
   column equal width. `min-height: 0` lets flexbox constrain the grid.
*/
.tasks-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* Use equal row sizing so each subcell tracks column width and keeps
       uniform sizing like the print view. */
    grid-auto-rows: 1fr;
    gap: 6px;
    flex: 1 1 auto;
    min-height: 0;
    justify-items: stretch;
    align-items: stretch;
}

.subcell {
    background: rgba(0,0,0,0.03);
    border-radius: 6px;
    padding: 4px;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Keep subcells uniform in live view using the same ratio logic as print.
   Using a slightly rectangular ratio reduces vertical space while keeping
   consistent sizing whether empty or filled. */
.subcell {
    width: 100%;
    aspect-ratio: 4 / 3;
}

/* Ensure any text placed inside the 3x3 subcells is fully centered
   both horizontally and vertically regardless of length. Use flexbox
   so wrapping and multi-line text remain centered without changing
   the cell sizing. */
.subcell .slot-text {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    height: 100%;
    padding: 6px;
    box-sizing: border-box;
    word-break: break-word;
}

/* Print-only timestamp under the main title. Hidden on-screen, visible in print. */
.print-timestamp {
    display: none;
    font-size: 12px; /* match .day-date */
    color: #000;     /* match calendar dates */
    font-weight: 400; /* same weight as calendar date text */
    margin-top: 6px;
}

.subcell .task {
    padding: 6px 8px;
    font-size: 11px;
}

.task {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    word-wrap: break-word;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Ensure task content does not force subcell expansion */
.task {
    max-height: 100%;
    overflow: hidden;
}

.task:hover {
    opacity: 0.9;
    transform: translateX(2px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.task-text {
    flex: 1;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Legend Section */
.legend-section {
    background: var(--secondary-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 20px;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #d4d9dd;
}

.legend-header h2 {
    font-size: 16px;
    color: var(--primary-color);
}

.add-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e74c3c;
    color: white;
    border: none;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-btn:hover {
    background: #c0392b;
    transform: scale(1.1);
}

.legend-list {
    max-height: 400px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.legend-item:hover {
    background: #f8f9fa;
    transform: translateX(4px);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
    border: 2px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px; /* smaller text if any is placed inside the color box */
    line-height: 1;
}

.legend-color-input {
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: transparent;
}

.legend-label {
    font-size: 11px;
    font-weight: 500;
    color: #000; /* Subcontractor (category) text -> black */
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar {
    background: transparent;
}
.sidebar-tabs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.sidebar-tab { background: #ecf0f1; border: 1px solid var(--border-color); padding: 8px; border-radius: 6px; cursor: pointer; }
.history-panel { background: white; border: 1px solid var(--border-color); border-radius: 6px; padding: 8px; max-height: 72vh; overflow: auto; }
.history-entry { padding: 8px; border-bottom: 1px solid #eef1f2; font-size: 12px; }
.history-entry .meta { color: #666; font-size: 11px; }

/* Critique styling: thick red outline that persists */
.task.critique { border: 3px solid #ff1900 !important; box-shadow: none !important; }
/* When using slot-background approach, apply critique outline to subcell */
.subcell.critique { outline: 3px solid #ff1900; outline-offset: -2px; }

/* Text inside a colored slot */
.slot-text { padding: 6px; font-size: 11px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; text-align: left; color: #fff !important; }

/* Legend inline edit input */
.legend-label-input { font-size: 11px; font-weight: 500; border: none; background: transparent; width: 100%; color: #000; }
.legend-label-input:focus { outline: none; background: rgba(0,0,0,0.03); padding: 2px 4px; border-radius: 4px; }

/* Compact status checkboxes in modal */
.status-row { display: flex; gap: 8px; align-items: center; }
.status-row label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.status-row input[type="checkbox"] { width: 16px; height: 16px; }

/* Smaller modal action buttons for compact UI */
.modal-actions .save-btn, .modal-actions .cancel-btn, .modal-actions .delete-btn { padding: 8px; font-size: 13px; border-radius: 6px; }

.status-badge { margin-left: 8px; font-size: 12px; color: #333; background: rgba(255,255,255,0.2); padding: 2px 6px; border-radius: 4px; }


/* Ensure report button is hidden in print */
@media print {
    #reportBtn { display: none !important; }
}

.day-notes-wrap { margin-top: 8px; }
.day-notes { width: 100%; height: 44px; resize: none; padding: 6px; border: 1px solid #dfe6e9; border-radius: 6px; font-size: 12px; overflow: auto; font-family: inherit; font-weight: 400; color: #000; line-height: 1.2; }
.logo-upload.hidden { display: none; }
/* calendar as vertical list of weeks to ensure selected week is top */
#commentsInput { width: 100%; box-sizing: border-box; font-size: 13px; color: #444; font-family: inherit; }
.calendar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 100%;
}
.week-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

/* Floating Historique button */
.historique-fab { position: fixed; right: 18px; bottom: 18px; z-index: 2000; background:#2c3e50; color:white; border:none; padding:10px 14px; border-radius:8px; box-shadow:var(--shadow); cursor:pointer }
.historique-fab:hover { background:#223242 }

.history-page { position: fixed; inset:0; background:white; z-index:1500; padding:20px; overflow:auto }
.history-header { display:flex; gap:12px; align-items:center; margin-bottom:12px }
.history-content { display:block }

.delete-legend-btn {
    background: #e74c3c;
    color: white;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.legend-item:hover .delete-legend-btn {
    opacity: 1;
}

.delete-legend-btn:hover {
    background: #c0392b;
}

/* Add Category Form */
.add-category-form {
    background: white;
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    border: 2px solid var(--accent-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.add-category-form input {
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
}

.add-category-form button {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

#confirmCategoryBtn {
    background: var(--accent-color);
    color: white;
}

#confirmCategoryBtn:hover {
    background: #2980b9;
}

#cancelCategoryBtn {
    background: #e74c3c;
    color: white;
}

#cancelCategoryBtn:hover {
    background: #c0392b;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    max-width: 720px;
    width: 95%;
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    background: var(--primary-color);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Task modal header override to use red similar to weekday headers */
.modal.task-modal .modal-header { background: #e74c3c !important; }

.modal-header h3 {
    font-size: 16px;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-btn:hover {
    transform: rotate(90deg);
}

.modal-body {
    padding: 20px;
    display: grid;
    grid-template-columns: 50% 50%;
    gap: 16px;
}

#reasonModal .modal-body textarea { width: 100%; box-sizing: border-box; }

#reasonModal .save-btn, #reasonModal .cancel-btn { padding: 6px 8px; font-size: 12px; }

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--primary-color);
    font-size: 13px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
}

/* Critique checkbox positioned top-right of Activité field */
.activite-group { position: relative; }
.critique-top-left { display: inline-flex; gap:6px; align-items:center; justify-content:flex-end; }

/* ensure the Critique control is right-aligned inside the left column */
.activite-row > div:last-child { text-align: right; }

.activite-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.activite-row .activite-label { font-weight: 600; }
.activite-input { margin-top: 8px; }

/* Critique row underneath the Activité input */
.critique-row { margin-top: 8px; display: flex; align-items: center; }
.critique-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; line-height: 1; }
.critique-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    vertical-align: middle;
    appearance: auto;
}

.comments-side { display: flex; flex-direction: column; gap:8px; }
.reason-display { font-size: 13px; color: #444; background:#fafafa; border:1px solid #eee; padding:8px; border-radius:6px; min-height:44px }

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding: 8px; /* white padding around the buttons */
    background: white;
    border-radius: 6px;
}

.save-btn {
    flex: 1;
    padding: 10px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-btn:hover {
    background: #2980b9;
}

.delete-btn {
    padding: 10px 15px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.delete-btn:hover {
    background: #c0392b;
}

.delete-btn.hidden {
    display: none;
}

.cancel-btn {
    flex: 1;
    padding: 10px;
    background: #95a5a6;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn:hover {
    background: #7f8c8d;
}

/* Utilities */
.hidden {
    display: none !important;
}

@media print {
    /* Ensure backgrounds/colors print where supported */
    html, body { background: white !important; color: black !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

    /* Define explicit page size for tabloid (11x17) landscape and tighter margins */
    @page { size: 11in 17in landscape; margin: 0.125in; }

    /* Make the app container use the full printable area with tighter padding */
    .container {
        box-shadow: none !important;
        border-radius: 0 !important;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 4pt !important;
    }

    /* Slightly larger base font for better readability and to reduce white space */
    body, .container { font-size: 11pt; }

     /* Hide interactive controls and UI chrome that should not print */
     #printBtn, .print-btn, .add-btn, .delete-legend-btn, .close-btn,
     .save-btn, .cancel-btn, input[type="file"], .modal,
     .add-category-form { display: none !important; }

      /* Ensure the main calendar title remains visible in print; keep on-screen appearance unchanged. */
        .logo-title .title-input { display: inline-block !important; }

    /* Place the logo at the far left and the title+timestamp to its right.
       The `.title-block` stacks the title above the print timestamp. This
       only affects print; on-screen layout is unchanged. */
    .logo-title { flex-direction: row !important; align-items: flex-start !important; }
    .logo-title .title-block { display: flex !important; flex-direction: column !important; align-items: flex-start !important; margin-left: 12px !important; }

    /* Show the print timestamp under the title in print only and style it
       to match the calendar dates (same font family, size, weight, color). */
    .print-timestamp {
        display: block !important;
        text-align: left !important;
        font-family: inherit !important;
        font-size: 12px !important; /* same as .day-date */
        font-weight: 400 !important; /* match normal date weight */
        color: #000 !important; /* match .day-date color */
        margin-top: 6px !important;
    }

    /* Ensure the main title uses the same style in print and on-screen. */
    .logo-title .title-block .title-input {
        font-family: inherit !important;
        font-size: 22px !important; /* match on-screen */
        font-weight: 700 !important; /* match on-screen */
        color: #000 !important;
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
    }

     /* Make the start-date selector visible in print as requested (top-right).
         Keep the control hidden on-screen only if previously hidden by JS/CSS. */
      .controls .start-date-section { display: flex !important; }

     /* 1) Attempt to hide browser-added headers/footers (file path / page numbers)
         Note: browser UI may still add headers/footers; users should disable headers
         in print dialog if required. We reduce margins and request no header space. */
    @page { margin: 0.25in; }
     /* Hide any in-DOM debug elements that might show file path or page numbers */
     .print-header, .print-footer, .file-path, .page-number { display: none !important; }

    /* Ensure legend is fully visible and uses available width */
    .legend-section { position: static !important; max-height: none !important; overflow: visible !important; }

    /* Layout adjustments to reduce spacing and ensure fit on one page */
    /* Make Sous-traitant (legend) column slightly narrower to give calendar more width */
    .main-content { gap: 6px !important; grid-template-columns: 1fr 280px !important; }
    .legend-list { gap: 6px; }
    .legend-item { padding: 6px; margin-bottom: 6px; }
    .legend-label { font-size: 9pt; }

    /* Compact calendar spacing and cell sizes to avoid cropping */
     /* Restore original column division for print: each week-row uses 5 equal columns */
     .calendar { gap: 6px !important; }
     .week-row { gap: 6px !important; grid-template-columns: repeat(5, 1fr) !important; }

     /* Reduce vertical footprint for print only (keep live view intact).
         Decrease min-height and padding so 4 weeks fit while preserving square subcells. */
    .day-cell { padding: 4px !important; min-height: 56px !important; }
    .day-header { margin-bottom: 8px; padding-bottom: 6px; }
      .tasks-container { gap: 3px !important; grid-auto-rows: 1fr !important; }
    .task, .subcell .task { font-size: 10pt; padding: 4px 6px; }

      /* Ensure subcells stay square and do not collapse in print. They will
          size according to the column width while keeping equal height. */
    .subcell { aspect-ratio: 1 / 1 !important; width: 100% !important; min-height: 0 !important; }

      /* Use full available width for the calendar in print (legend kept wider).
          Remove transform scaling and instead make subcells rectangular to
          reduce vertical space while preserving uniform sizing. */
      .calendar { transform: none !important; width: 100% !important; }

      /* Make subcells rectangular in print to reduce total height. Keep them
          uniform and non-collapsing. Adjust this ratio if you want taller/shorter cells. */
    .subcell { aspect-ratio: 4 / 3 !important; width: 100% !important; min-height: 0 !important; }

     /* Remove any printed timestamp elements; timestamp removed from DOM. */

    /* Prevent week rows and day cells from being split across pages */
    .week-row, .day-cell, .legend-item, .header { page-break-inside: avoid; }
    .week-row { page-break-after: avoid; }

    /* Ensure overflow content is visible instead of clipped */
    html, body { height: auto !important; overflow: visible !important; }

    /* Final safety: hide print button specifically */
    #printBtn { display: none !important; }
    #historiqueBtn { display: none !important; }
}

/* Print-only header compression: reduce vertical space taken by header
   (logo + title + timestamp) without changing calendar cells. Keeps
   fonts/colors/layout but tightens sizes and spacing for print. */
@media print {
    .header {
        padding-bottom: 6px !important;
        margin-bottom: 6px !important;
        gap: 8px !important;
        border-bottom-width: 1px !important;
    }
    .logo-title {
        gap: 8px !important;
        align-items: center !important;
    }
    .logo-preview {
        width: 48px !important;
        height: 48px !important;
        padding: 4px !important;
    }
    .logo-title .title-block .title-input {
        font-size: 18px !important; /* slightly smaller but readable */
        line-height: 1 !important;
    }
    .print-timestamp {
        font-size: 10px !important;
        margin-top: 4px !important;
    }
}

/* 3) Ensure layout consistency inside each calendar day cell on-screen and in print:
   - Use flex on the day cell to reserve header area and give the tasks grid a fixed
     available space so its 3x3 grid rows/columns remain equal even when empty.
   - `grid-auto-rows: 1fr` plus `flex: 1` forces equal-sized sub-cells. */
.day-cell {
    display: flex;
    flex-direction: column;
}
.day-header {
    flex: 0 0 auto;
}
.tasks-container {
    flex: 1 1 auto;
    /* ensure grid has equal rows/cols */
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    grid-auto-rows: 1fr;
    gap: 6px;
    min-height: 0; /* allow proper flexbox sizing */
}
.subcell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0; /* prevent content-driven growth */
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--secondary-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

/* Additional print-fit tweaks: keep live view unchanged, only affects print */
@media print {
    /* Slightly smaller base font for denser layout */
    body, .container { font-size: 9pt !important; }

    /* Narrow gaps and tighter legend column to fit on 11x17 */
    .main-content { gap: 6px !important; grid-template-columns: 1fr 320px !important; }
    .legend-section { padding: 8px !important; }
    .legend-list { max-height: none !important; }

    /* Compact header */
    .header { padding: 6px 8px !important; margin-bottom: 6px !important; }
    .logo-preview { width: 40px !important; height: 40px !important; }
    .logo-title .title-block .title-input { font-size: 16px !important; }

    /* Compact calendar cells and typography */
    .day-cell { padding: 4px !important; min-height: 56px !important; }
    .day-header { font-size: 11px !important; margin-bottom: 6px !important; padding-bottom: 4px !important; }
    .tasks-container { gap: 4px !important; }
    .subcell { aspect-ratio: 4 / 2 !important; }
    .slot-text { font-size: 9pt !important; }

    /* Notes area smaller in print */
    .day-notes {
        height: 36px !important;
        font-size: 9pt !important;
        font-family: inherit !important;
        font-weight: 400 !important;
        color: #000 !important;
        line-height: 1.1 !important;
    }

    /* Reduce legend item padding and font to fit */
    .legend-item { padding: 6px !important; }
    .legend-label, .legend-label-input { font-size: 9pt !important; }

    /* Ensure no unexpected overflows */
    html, body { overflow: visible !important; }
}

/* Consolidated 11x17 print tuning: keep live view intact and
    restore comfortable proportions for the calendar cells. */
@page {
    size: 11in 17in landscape;
    margin: 0.25in;
}

@media print {
    /* Use a slightly larger base font than prior 9pt override
       to improve readability while still fitting on 11x17. */
    body,
    .container {
        font-size: 11pt !important;
    }

    /* Ensure the main app uses the full printable width. */
    .container {
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    /* Keep the calendar/legend layout but give the calendar
       more horizontal space than the Sous-traitant column
       so days are wider on paper. */
    .main-content {
        grid-template-columns: 77% 23% !important;
        gap: 8px !important;
    }

    /* Slightly taller day-cell height to better fill
       bottom space while still fitting on one page. */
    .day-cell {
        min-height: 96px !important;
        padding: 4px !important;
    }

    .day-header {
        font-size: 11pt !important;
        margin-bottom: 6px !important;
        padding-bottom: 4px !important;
    }

    /* Keep the same proportional layout as live view for the
       3x3 subcells: rectangular but not too flat. This also
       cancels older 1/1 and 4/2 ratios defined above. */
    .tasks-container {
        grid-template-rows: repeat(3, 1fr) !important;
        grid-auto-rows: 1fr !important;
        gap: 2px !important;
    }

    .subcell {
        aspect-ratio: 16 / 9 !important;
        width: 100% !important;
        min-height: 0 !important;
    }

    .slot-text {
        font-size: 8pt !important;
        line-height: 1.1 !important;
        padding: 3px !important;
    }

    /* Notes area: keep visible but even more compact so
       more height is reserved for the activity grid. */
    .day-notes {
        height: 40px !important;
        font-size: 7.5pt !important;
        font-family: inherit !important;
        font-weight: 400 !important;
        color: #000 !important;
        line-height: 1.1 !important;
    }

    /* Make sure floating buttons never appear on paper. */
    #historiqueBtn,
    .historique-fab {
        display: none !important;
    }

    /* Avoid splitting a day or week across pages. */
    .week-row,
    .day-cell {
        page-break-inside: avoid;
    }
}
