/* Calendar View Styles */

* {
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f5f5f5;
    overflow: auto;
}

.calendar-view-container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: 100%;
    box-sizing: border-box;
}

/* When inside an iframe with hideControls, allow full width */
body:has(.hide-controls) .calendar-view-container,
.calendar-view-container.full-width {
    max-width: 100%;
}

.calendar-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #2c3e50;
}

.header-title-section {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    text-align: center;
    align-items: center;
}

.calendar-view-header h1 {
    margin: 0;
    color: #2c3e50;
    font-size: 2rem;
    text-align: center;
}

.division-name-header {
    margin: 0;
    color: #555;
    font-size: 1.3rem;
    font-weight: 500;
    text-align: center;
}

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

/* Hamburger Menu Button */
.btn-menu {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
    z-index: 101;
}

.btn-menu span {
    width: 100%;
    height: 3px;
    background-color: #2c3e50;
    border-radius: 3px;
    transition: all 0.3s ease;
}

.btn-menu:hover span {
    background-color: #3498db;
}

.btn-print {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
}

.btn-print:hover {
    background-color: #2980b9;
}

/* Team Menu Overlay */
.team-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.team-menu-overlay.show {
    opacity: 1;
    visibility: visible;
}

.team-menu-container {
    background: white;
    width: 300px;
    max-width: 90vw;
    height: 100vh;
    overflow-y: auto;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.team-menu-overlay.show .team-menu-container {
    transform: translateX(0);
}

.team-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #2c3e50;
    background-color: #2c3e50;
    color: white;
}

.team-menu-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.btn-close-menu {
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.btn-close-menu:hover {
    color: #ecf0f1;
}

.team-menu-content {
    padding: 15px 0;
    flex: 1;
    overflow-y: auto;
}

.team-menu-item {
    display: block;
    width: 100%;
    padding: 12px 20px;
    text-align: left;
    background: white;
    border: none;
    border-bottom: 1px solid #ecf0f1;
    cursor: pointer;
    font-size: 1rem;
    color: #2c3e50;
    transition: background-color 0.2s ease;
}

.team-menu-item:hover {
    background-color: #ecf0f1;
}

.team-menu-item.active {
    background-color: #3498db;
    color: white;
    font-weight: bold;
}

.team-menu-item.active:hover {
    background-color: #2980b9;
}

.team-menu-item strong {
    font-weight: bold;
}

.team-list {
    display: flex;
    flex-direction: column;
}

.calendar-content {
    min-height: 400px;
}

.calendar-content-mobile {
    display: none;
}

/* Month Container */
.month-container {
    margin-bottom: 40px;
    page-break-inside: avoid;
}

.month-header-cell {
    background-color: #ecf0f1;
    padding: 10px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: #2c3e50;
}


/* Calendar Table */
.calendar-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.calendar-table thead {
    background-color: #34495e;
    color: white;
}

.calendar-table th {
    padding: 12px;
    text-align: center;
    font-weight: bold;
    border: 1px solid #2c3e50;
}

.day-names-row th {
    background-color: #34495e;
    color: white;
}

.calendar-table td {
    border: 1px solid #ddd;
    padding: 8px;
    vertical-align: top;
    height: 120px;
    width: 14.28%;
}

.calendar-day {
    background-color: white;
}

.empty-day {
    background-color: #f9f9f9;
}

.day-number {
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

/* Match Display */
.calendar-match {
    background-color: #e8f5e9;
    border-left: 3px solid #4caf50;
    padding: 4px 6px;
    margin-bottom: 4px;
    font-size: 0.75rem;
    border-radius: 3px;
}

.calendar-match.placeholder {
    background-color: #fff3e0;
    border-left-color: #ff9800;
}

.match-title {
    font-weight: bold;
    color: #333;
}

.match-teams {
    font-weight: bold;
    color: #333;
    margin-bottom: 2px;
}

.match-time {
    color: #666;
    font-size: 0.7rem;
    margin-top: 2px;
}

.match-club {
    color: #888;
    font-size: 0.7rem;
    margin-top: 2px;
    font-style: italic;
}

.match-courts {
    color: #555;
    font-size: 0.7rem;
    margin-top: 2px;
    font-weight: 500;
}

/* Print Styles */
@media print {
    body {
        background-color: white;
        padding: 0;
        margin: 0;
    }

    .calendar-view-container {
        box-shadow: none;
        padding: 0;
        max-width: 100%;
    }

    .calendar-view-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 10px;
        border-bottom: 2px solid #2c3e50;
        z-index: 1000;
        page-break-after: avoid;
    }

    .btn-print,
    .btn-menu,
    .header-actions {
        display: none;
    }

    /* Force desktop calendar to show when printing (override mobile styles) */
    .calendar-content {
        display: block !important;
    }

    /* Hide mobile calendar when printing */
    .calendar-content-mobile {
        display: none !important;
    }

    /* Hide team menu when printing */
    .team-menu-overlay {
        display: none !important;
    }

    /* Ensure desktop table layout is used for printing */
    .calendar-table {
        display: table !important;
        width: 100% !important;
    }

    .calendar-table thead {
        display: table-header-group !important;
    }

    .calendar-table tbody {
        display: table-row-group !important;
    }

    .calendar-table tr {
        display: table-row !important;
    }

    .calendar-table td,
    .calendar-table th {
        display: table-cell !important;
    }

    /* Reset mobile-specific header styles for print */
    .calendar-view-header {
        position: relative !important;
        flex-direction: row !important;
    }

    .calendar-view-header h1 {
        font-size: 2rem !important;
    }

    /* Division name and month/year at top of each page - Format: "Division Name - Month/Year" */
    /* Print header elements - inserted via JavaScript */
    .print-page-header-element {
        display: none; /* Hidden in screen view */
        width: 100%;
        text-align: center;
        font-size: 1.2rem;
        font-weight: bold;
        color: #2c3e50;
        padding: 0.5cm 0;
        border-bottom: 1px solid #ccc;
        background: white;
        margin: 0;
        page-break-after: avoid;
        page-break-inside: avoid;
    }
    
    @media print {
        /* Ensure headers are visible when printing */
        .print-page-header-element {
            display: block !important;
            visibility: visible !important;
            width: 100%;
            text-align: center;
            font-size: 1.2rem;
            font-weight: bold;
            color: #2c3e50;
            padding: 0.5cm 0;
            border-bottom: 1px solid #ccc;
            background: white !important;
            margin: 0;
            page-break-after: avoid;
            page-break-inside: avoid;
            position: relative;
            z-index: 999;
        }
        
        /* Ensure first header appears at very top of page */
        .month-container > .print-page-header-element:first-child {
            margin-top: 0;
            padding-top: 0.3cm;
        }
        
        /* Position header in the top margin area */
        body {
            margin-top: 0;
            padding-top: 0;
        }
    }
    
    @page {
        margin-top: 2.5cm;
        margin-bottom: 1cm;
        margin-left: 1cm;
        margin-right: 1cm;
        size: letter;
    }

    .month-container {
        margin-bottom: 0;
        page-break-after: always;
    }

    .month-container:first-child {
        page-break-before: auto;
        margin-top: 0;
    }

    .month-container:not(:first-child) {
        page-break-before: always;
    }

    /* Month header in table header - will repeat on page breaks */
    .month-table-header {
        display: table-header-group;
    }

    .month-header-cell {
        background-color: #ecf0f1;
        padding: 10px;
        text-align: center;
    }

    .calendar-table {
        page-break-after: always;
        border-collapse: collapse;
    }

    /* Month header will repeat on each page when table breaks */
    /* The page header (top-center) will show "Division Name - Month/Year" format */

    .calendar-day {
        page-break-inside: avoid;
        vertical-align: top;
    }

    .calendar-match {
        page-break-inside: avoid;
    }
}

/* Fallback: Show continued header in tbody when page breaks */
@media print {
    /* When thead repeats (browser behavior), show continued version */
    .calendar-table thead tr:first-child th {
        position: relative;
    }
}

/* Responsive - Mobile Layout */
@media (max-width: 768px) {
    html, body {
        padding: 0;
        margin: 0;
        height: 100%;
        overflow: hidden;
    }

    .calendar-view-container {
        padding: 0;
        max-width: 100%;
        height: 100vh;
        position: relative;
        overflow: hidden;
        padding-top: 0; /* No padding - header handles positioning */
    }
    
    .calendar-view-header {
        padding-top: 3px;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 3px;
        margin-bottom: 0;
        flex-direction: column;
        align-items: center;
        position: fixed;
        top: 0px; /* At the top of viewport */
        left: 0;
        right: 0;
        background: white;
        z-index: 100;
        border-bottom: 2px solid #2c3e50;
        flex-shrink: 0;
        min-height: auto;
        height: auto;
    }
    
    /* Content area should scroll, accounting for fixed header */
    .calendar-content {
        margin-top: 0;
        padding-top: 0;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 20px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        position: absolute;
        top: 0px;
        left: 0;
        right: 0;
        bottom: 0;
        box-sizing: border-box;
    }
    
    /* First month container needs spacing to start below fixed header */
    .calendar-content > .month-container:first-child {
        margin-top: 80px; /* Space for fixed header */
    }
    
    .header-title-section {
        align-items: center;
        text-align: center;
        width: 100%;
    }
    
    .calendar-view-header h1 {
        text-align: center;
        font-size: 1rem;
        margin: 0;
        line-height: 1.2;
    }
    
    .division-name-header {
        text-align: center;
        font-size: 0.85rem;
        line-height: 1.2;
    }
    
    .header-actions {
        margin-top: 4px;
        width: 100%;
        align-items: center;
        justify-content: center;
        display: flex;
    }
    
    .btn-print {
        font-size: 0.8rem;
        padding: 4px 12px;
    }
    
    .header-title-section {
        gap: 2px;
    }

    .btn-menu {
        width: 28px;
        height: 28px;
    }

    .btn-print {
        font-size: 0.85rem;
        padding: 8px 12px;
    }

    .team-menu-container {
        width: 280px;
        max-width: 85vw;
    }

    .team-menu-header {
        padding: 15px;
    }

    .team-menu-header h2 {
        font-size: 1.1rem;
    }

    .team-menu-item {
        padding: 10px 15px;
        font-size: 0.9rem;
    }

    /* Hide desktop calendar on mobile */
    .calendar-content {
        display: none;
    }

    /* Show mobile calendar - make it scrollable */
    .calendar-content-mobile {
        display: block;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        position: absolute;
        top: 0px;
        left: 0;
        right: 0;
        bottom: 0;
        padding-left: 0;
        padding-right: 0;
        padding-top: 0;
        padding-bottom: 70px; /* 20px original + 50px extra for iPhone scroll cutoff */
        box-sizing: border-box;
    }
    
    /* Month container for mobile */
    .month-container-mobile {
        margin-bottom: 0;
        width: 100%;
        min-height: 0;
    }
    
    /* First month container needs space for fixed header */
    .calendar-content-mobile > .month-container-mobile:first-child {
        margin-top: 80px; /* Space for fixed header */
    }

    /* Sticky month header - stick at top of scrollable content, replacing fixed header when scrolling */
    .month-header-mobile {
        background-color: #2c3e50;
        color: white;
        padding: 12px 15px;
        font-size: 1.2rem;
        font-weight: bold;
        text-align: center;
        position: sticky;
        top: 0px; /* Stick at top of scrollable area */
        z-index: 90; /* Below fixed header (z-index: 100) but above day headers and content */
        margin: 0;
        box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
    
    /* Fix sticky table headers on mobile - stick at top of scrollable content area */
    .calendar-table thead {
        position: sticky;
        top: 0px;
        z-index: 50;
    }
    
    .month-header-cell {
        position: sticky;
        top: 0px;
        z-index: 50;
    }

    /* Mobile days list */
    .mobile-days-list {
        display: flex;
        flex-direction: column;
        gap: 0;
        width: 100%;
        min-height: 0;
    }

    /* Mobile day cell */
    .mobile-day-cell {
        border-bottom: 1px solid #e0e0e0;
        padding: 12px 15px;
        background: white;
    }

    .mobile-day-cell:last-child {
        border-bottom: none;
    }

    /* Mobile day header (Day of Week + Date) */
    .mobile-day-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
        padding-bottom: 6px;
        border-bottom: 1px solid #f0f0f0;
        position: relative;
        z-index: 1; /* Below sticky month header */
    }

    .mobile-day-of-week {
        font-weight: bold;
        color: #2c3e50;
        font-size: 0.9rem;
    }

    .mobile-day-date {
        color: #666;
        font-size: 0.85rem;
    }

    /* Mobile day matches */
    .mobile-day-matches {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    /* Match styling for mobile */
    .mobile-day-cell .calendar-match {
        background-color: #e8f5e9;
        border-left: 3px solid #4caf50;
        padding: 10px;
        border-radius: 4px;
        font-size: 0.9rem;
    }

    .mobile-day-cell .calendar-match.placeholder {
        background-color: #fff3e0;
        border-left-color: #ff9800;
    }

    .mobile-day-cell .match-teams {
        font-weight: bold;
        color: #333;
        margin-bottom: 4px;
        font-size: 0.95rem;
    }

    .mobile-day-cell .match-title {
        font-weight: bold;
        color: #333;
        margin-bottom: 4px;
        font-size: 0.95rem;
    }

    .mobile-day-cell .match-time {
        color: #666;
        font-size: 0.85rem;
        margin-top: 2px;
    }

    .mobile-day-cell .match-club {
        color: #888;
        font-size: 0.85rem;
        margin-top: 2px;
        font-style: italic;
    }

    .mobile-day-cell .match-courts {
        color: #555;
        font-size: 0.85rem;
        margin-top: 2px;
        font-weight: 500;
    }
}

/* Desktop - Hide mobile calendar */
@media (min-width: 769px) {
    .calendar-content-mobile {
        display: none;
    }

    .calendar-content {
        display: block;
    }
}
