/* Global Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden; /* Prevent iframe scrolling */
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
}

.app-container {
    max-width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

header {
    background-color: #2c3e50;
    color: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* Prevent header from shrinking */
}

header h1 {
    font-size: 1.8rem;
    margin: 0;
}

.btn-help {
    position: absolute;
    right: 20px;
    background-color: #3498db;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s ease;
}

.btn-help:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(52, 152, 219, 0.3);
}

/* Controls Panel */
.controls-panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0; /* Prevent controls panel from shrinking */
}

.form-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.auto-fill-section {
    border-top: 2px solid #e0e0e0;
    padding-top: 15px;
    margin-top: 5px;
}

.section-label {
    font-weight: bold;
    font-size: 1.1rem;
    color: #2c3e50;
    margin-bottom: 10px;
    flex-basis: 100%;
    padding-bottom: 5px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.9rem;
    color: #2c3e50;
    transition: transform 0.2s ease;
}

.toggle-btn:hover {
    color: #3498db;
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.2s ease;
}

.toggle-btn.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.toggle-btn:not(.collapsed) .toggle-icon {
    transform: rotate(0deg);
}

.auto-fill-content {
    flex-basis: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 1000px;
    opacity: 1;
}

.auto-fill-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0;
}

.control-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
}

.control-group input,
.control-group select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    min-width: 150px;
}

.control-group input:focus,
.control-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.control-group .btn {
    margin-top: 0;
    white-space: nowrap;
}

.schedulable-days-group {
    flex-basis: 100%;
    min-width: 100%;
}

.schedulable-days-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.day-toggle {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    background-color: #f9f9f9;
    color: #666;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    user-select: none;
    min-width: 50px;
    text-align: center;
}

.day-toggle:hover {
    background-color: #e9e9e9;
    border-color: #bbb;
}

.day-toggle.active {
    background-color: #3498db;
    color: white;
    border-color: #2980b9;
}

.day-toggle.active:hover {
    background-color: #2980b9;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 120px;
    min-height: 44px; /* Touch-friendly */
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

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

.btn-success {
    background-color: #27ae60;
    color: white;
}

.btn-success:hover {
    background-color: #229954;
}

.btn-secondary {
    background-color: #017a83;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-info {
    background-color: #17a2b8;
    color: white;
}

.btn-info:hover {
    background-color: #138496;
}

.btn-warning {
    background-color: #ffc107;
    color: #212529;
}

.btn-warning:hover {
    background-color: #e0a800;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    background-color: #d3d3d3;
    color: #808080;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn:disabled:hover {
    background-color: #d3d3d3;
    transform: none;
}

.btn-success:disabled {
    background-color: #d3d3d3;
    color: #808080;
}

.btn-info:disabled {
    background-color: #d3d3d3;
    color: #808080;
}

/* Main Content */
.main-content {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    flex: 1;
    min-height: 0; /* Allow flex item to shrink */
    overflow: hidden; /* Prevent main content from causing scroll */
    align-items: stretch; /* Stretch items to full height */
}

/* Calendar Section */
.calendar-section {
    flex: 1;
    min-width: 300px;
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-self: stretch; /* Stretch to match sibling height */
    min-height: 400px; /* Ensure minimum visible height */
    overflow: hidden; /* Prevent section from causing scroll */
}

.calendar-header {
    flex-shrink: 0; /* Keep header visible when scrolling */
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.calendar-header h2 {
    margin: 0;
    color: #2c3e50;
    flex: 0 1 auto;
}

.calendar-header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.btn-maximize {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-maximize:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(52, 152, 219, 0.3);
}

.btn-maximize:active {
    transform: scale(0.98);
}

/* Maximized state - hide header and controls */
.app-container.maximized {
    padding: 0; /* Remove padding when maximized */
    height: 100vh; /* Full viewport height */
    min-height: 100vh;
}

.app-container.maximized header {
    display: none;
}

.app-container.maximized .controls-panel {
    display: none;
}

/* Maximized state - full height for main content */
.app-container.maximized .main-content {
    height: 100vh;
    min-height: 100vh;
    flex: 1;
    align-items: stretch; /* Ensure children stretch to full height */
}

.app-container.maximized .calendar-section {
    height: 100%;
    min-height: 0;
    border-radius: 0; /* Remove border radius when maximized */
}

.app-container.maximized .summary-sidebar {
    height: 100%;
    min-height: 100%; /* Ensure it stretches to full height */
    align-self: stretch; /* Stretch to match parent height */
    border-radius: 0; /* Remove border radius when maximized */
}

.calendar-utility-links {
    margin-top: 5px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* When inside flex container, remove top margin for proper alignment */
.calendar-header > div .calendar-utility-links {
    margin-top: 0;
}

.calendar-header > div:has(.calendar-utility-links) .calendar-utility-links {
    margin-top: 0;
}

.calendar-utility-links a {
    color: #3498db;
    text-decoration: none;
    cursor: pointer;
}

.calendar-utility-links a:hover {
    text-decoration: underline;
    color: #2980b9;
}

.calendar-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 0; /* Remove any default margins */
    align-items: stretch; /* Ensure children take full width */
    flex: 1 1 0; /* Take remaining space, start from 0 */
    overflow-y: auto;
    overflow-x: visible;
    padding-right: 10px; /* Space for scrollbar */
    min-height: 0; /* Important: allows flex item to shrink below content size */
}

/* Custom scrollbar styling for calendar grid */
.calendar-grid::-webkit-scrollbar {
    width: 8px;
}

.calendar-grid::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.calendar-grid::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.calendar-grid::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.calendar-footer {
    margin-top: 20px;
    padding: 20px 0;
    flex-shrink: 0; /* Keep footer visible when scrolling */
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px; /* Space between button groups */
}

.calendar-footer-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.calendar-footer-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.week-container {
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: visible; /* Allow content to overflow if needed in simple view */
    display: flex;
    flex-direction: column; /* Stack header and days-grid vertically */
    flex-shrink: 0; /* Prevent week containers from being compressed */
    width: 100%; /* Ensure full width */
}

/* Normal view - allow overflow for sticky headers to work */
.calendar-grid:not(.simple-view) .week-container {
    overflow-x: auto; /* Allow horizontal scrolling when content is wider */
    overflow-y: visible; /* Keep vertical overflow visible for sticky headers */
}

.week-header {
    background-color: #34495e;
    color: white;
    padding: 10px 15px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0; /* Don't shrink the header */
    width: 100%; /* Header takes full width of container */
    box-sizing: border-box;
    position: sticky;
    top: 0;
    z-index: 100; /* Ensure headers stack above content when sticky */
}

/* Hide week banner ("Week of" bar) when option is checked */
.calendar-grid.hide-week-banner .week-header {
    display: none;
}

/* Normal view - header width will be synced with days-grid via JavaScript */
.calendar-grid:not(.simple-view) .week-header {
    /* Width synced via JavaScript to match days-grid scroll width */
}

/* Simple view - week header should span all day columns */
.calendar-grid.simple-view .week-header {
    width: 100%; /* Span full width of container (which is determined by days-grid) */
    min-width: 100%; /* Ensure it spans all day columns */
}

.week-title {
    flex: 1;
}

.week-toggle-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.week-toggle-btn:hover {
    opacity: 0.8;
}

.week-container.week-collapsed .days-grid {
    display: none;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background-color: #ddd;
    flex-shrink: 0; /* Prevent days-grid from being compressed */
    width: 100%; /* Ensure full width */
    min-height: 120px; /* Ensure minimum height based on day-cell min-height */
}

/* Day Cell */
.day-cell {
    background: white;
    padding: 10px;
    min-height: 120px;
    position: relative;
    cursor: pointer;
}

.day-cell > * {
    pointer-events: none;
}

.day-cell .match-item {
    pointer-events: auto;
}

.day-cell .day-add-match-btn {
    pointer-events: auto;
}

.day-cell.droppable-hover {
    background-color: #e8f5e9;
    border: 2px dashed #4caf50;
}

.day-cell.conflict-day {
    background-color: #ffebee;
    border: 2px solid #f44336;
}

.day-cell.non-schedulable-day {
    background-color: #f5f5f5;
    opacity: 0.7;
}

.day-header {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 48px; /* Position below sticky week header (approximate height ~44px with padding) */
    z-index: 90; /* Below week header (100) but above content */
    background-color: white; /* Ensure header has solid background */
    padding: 4px 0; /* Add padding for better visibility */
    margin-top: -4px; /* Offset the padding */
    border-bottom: 1px solid #e0e0e0; /* Visual separator */
}

/* When week banner is hidden, move day header up to occupy freed space */
.calendar-grid.hide-week-banner .day-header {
    top: 0;
}

.day-date {
    font-size: 0.75rem;
    color: #000000;
    font-weight: bold;
    flex: 0 0 auto;
    margin-left: 8px; /* Space after day name */
    white-space: nowrap; /* Prevent date from wrapping */
}

/* Ensure day header background matches day-cell background in Simple View */
.calendar-grid.simple-view .day-header {
    background-color: white;
}

/* Ensure date is visible in sticky header */
.calendar-grid.simple-view .day-header .day-date {
    color: #888;
}

/* Ensure day header works in collapsed/non-schedulable days */
.day-cell.non-schedulable-day .day-header {
    background-color: #f5f5f5;
}

.day-cell.conflict-day .day-header {
    background-color: #ffebee;
}

.day-name-date-group {
    display: flex;
    align-items: center;
    flex: 1; /* Take available space on left */
    min-width: 0; /* Allow shrinking */
}

.day-name {
    flex: 0 1 auto; /* Don't grow, but can shrink if needed */
    pointer-events: auto;
    position: relative; /* Ensure proper stacking */
    z-index: 1; /* Keep above background */
    margin-right: 4px; /* Space before date */
}

.clickable-day-name {
    pointer-events: auto !important;
}

.day-add-match-btn {
    width: 24px;
    height: 24px;
    border: none;
    background-color: #3498db;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    opacity: 0.7;
    transition: all 0.2s ease;
    flex-shrink: 0;
    pointer-events: auto;
    z-index: 5;
}

.day-add-match-btn:hover {
    opacity: 1;
    background-color: #2980b9;
    transform: scale(1.1);
}

.day-add-match-btn:active {
    transform: scale(0.95);
}

.day-date {
    font-size: 0.8rem;
    color: #999;
}

/* Match Item */
.match-item {
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 4px;
    padding: 8px;
    padding-right: 60px; /* Space for both delete and switch buttons */
    margin-bottom: 6px;
    cursor: move;
    transition: all 0.2s ease;
    position: relative;
    min-height: 60px;
    touch-action: none;
    pointer-events: auto;
}

/* Simple View - smaller matches */
.match-item.simple-view-match {
    min-height: 40px;
    padding: 4px 8px;
    padding-right: 60px;
    padding-bottom: 8px; /* Extra padding at bottom for buttons */
    margin-bottom: 3px;
    max-width: 100%;
    width: 100%;
}

.match-item.simple-view-match .match-home-away {
    font-size: 0.75rem;
    line-height: 1.3;
    margin: 0;
    font-weight: normal;
    white-space: normal;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    max-width: 100%;
    word-wrap: break-word;
}

/* Hide club, time, and court count in simple view */
.match-item.simple-view-match .simple-view-hidden {
    display: none;
}

/* Show hidden info on hover in simple view (when expansion is enabled) */
.match-item.simple-view-match:hover .simple-view-hidden {
    display: block;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #e0e0e0;
    font-size: 0.85rem;
    animation: fadeIn 0.2s ease;
}

/* Suppress hover expansion when EXPAND_IN_SIMPLE_VIEW is false */
.calendar-grid.simple-view.no-expand .match-item.simple-view-match:hover .simple-view-hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Simple view calendar - weeks in rows and columns with natural wrapping */
.calendar-grid.simple-view {
    display: flex;
    flex-direction: row; /* Explicitly set to row */
    flex-wrap: wrap; /* Allow natural wrapping to next row */
    gap: 15px;
    align-items: flex-start;
    align-content: flex-start;
    width: 100%; /* Ensure full width for proper wrapping */
}

/* Simple view - week container sizes to fit its day columns */
.calendar-grid.simple-view .week-container {
    width: fit-content; /* Size to fit content (day columns) */
    max-width: calc(100% - 15px); /* Prevent containers from exceeding available space (account for gap) */
    box-sizing: border-box;
    flex: 0 0 auto; /* Don't grow or shrink, use content size - allows natural wrapping */
    align-items: stretch; /* Stretch children (header) to match container width */
}

/* Simple view - non-schedulable days are shown if they contain matches (handled in JavaScript) */

/* Simple view - days grid uses flexbox to show schedulable days and non-schedulable days with matches */
.calendar-grid.simple-view .days-grid {
    display: flex;
    width: max-content; /* Size to fit all day cells - this determines container width */
    min-width: fit-content; /* Ensure it sizes to content */
    gap: 1px;
    background-color: #ddd;
    box-sizing: border-box;
    flex-shrink: 0; /* Don't shrink - this is what determines container width */
}

/* Simple view - day cells have fixed width, filling the days-grid */
.calendar-grid.simple-view .day-cell {
    flex: 0 0 200px; /* Fixed width, don't grow or shrink */
    min-width: 200px; /* Minimum width for day of week columns */
    width: 200px; /* Fixed width for consistent sizing */
    overflow: visible; /* Allow expanded matches to overflow */
    position: relative;
    box-sizing: border-box;
}

.calendar-grid.simple-view .match-item.simple-view-match {
    max-width: 100%;
    width: 100%;
    min-height: 40px; /* Increased to accommodate action buttons */
    max-height: 90px; /* Limit to approximately 3 lines when not hovered */
    padding: 4px 6px;
    padding-right: 50px;
    padding-bottom: 8px; /* Extra padding at bottom for buttons */
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    position: relative;
    z-index: 10;
}

/* Expand match on hover in simple view (when expansion is enabled) */
.calendar-grid.simple-view .match-item.simple-view-match:hover {
    max-height: 200px; /* Allow expansion */
    overflow: visible;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transform: translateY(-2px);
    background: white;
}

/* Suppress hover expansion when EXPAND_IN_SIMPLE_VIEW is false */
.calendar-grid.simple-view.no-expand .match-item.simple-view-match:hover {
    max-height: 90px;
    overflow: hidden;
    z-index: auto;
    box-shadow: none;
    transform: none;
}

.match-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.match-item.ui-draggable-dragging {
    opacity: 0.8;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Maintain original width when dragging simple-view matches */
.match-item.simple-view-match.ui-draggable-dragging,
.ui-draggable-helper .match-item.simple-view-match {
    width: 200px !important; /* Match the day-cell width */
    max-width: 200px !important;
    min-width: 200px !important;
    box-sizing: border-box;
}

.ui-draggable-helper {
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    pointer-events: none;
}

/* Ensure the helper container maintains match item width */
.ui-draggable-helper .match-item.simple-view-match {
    width: 200px !important;
    max-width: 200px !important;
}

.match-item.conflict-match {
    border-color: #f44336;
    background-color: #ffebee;
}

.match-item.placeholder-match {
    border-color: #999;
    background-color: #f5f5f5;
    border-style: dashed;
    opacity: 0.8;
}

.match-item.placeholder-match:hover {
    background-color: #e8f5e9;
    opacity: 1;
}

.match-item.placeholder-match .match-home-away {
    font-weight: normal;
}

.calendar-grid.simple-view .match-item.placeholder-match .match-home-away {
    font-size: 0.75rem;
    line-height: 1.3;
    margin: 0;
}

.team-drag-helper {
    z-index: 10002 !important;
    pointer-events: none;
}

.match-delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border: none;
    background-color: #f44336;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    opacity: 0.7;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.match-delete-btn:hover {
    opacity: 1;
    background-color: #d32f2f;
    transform: scale(1.1);
}

.match-delete-btn:active {
    transform: scale(0.95);
}

.match-switch-btn {
    position: absolute;
    top: 4px;
    right: 30px; /* Positioned to the left of delete button */
    width: 22px;
    height: 22px;
    border: none;
    background-color: #2196f3;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    opacity: 0.7;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.match-switch-btn:hover {
    opacity: 1;
    background-color: #1976d2;
    transform: scale(1.1);
}

.match-switch-btn:active {
    transform: scale(0.95);
}

.match-link-btn {
    position: absolute;
    top: 4px;
    right: 56px; /* Positioned to the left of switch button (30px + 26px spacing) */
    width: 22px;
    height: 22px;
    border: none;
    background-color: #9c27b0;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    opacity: 0.7;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.match-link-btn:hover {
    opacity: 1;
    background-color: #7b1fa2;
    transform: scale(1.1);
}

.match-link-btn:active {
    transform: scale(0.95);
}

.match-item.linked-match-highlight {
    background-color: #e1bee7 !important; /* Light purple matching link icon */
    border: 2px solid #9c27b0 !important; /* Purple matching link icon */
    box-shadow: 0 0 10px rgba(156, 39, 176, 0.5) !important;
    animation: linkedMatchPulse 1s ease-in-out;
}

@keyframes linkedMatchPulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(156, 39, 176, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(156, 39, 176, 0.8);
    }
}

.match-home-away {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.match-club {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 4px;
}

.match-time {
    font-size: 0.8rem;
    color: #999;
}

.match-time.editable-time {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
    min-width: 60px;
    display: inline-block;
    color: #2196f3;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.match-time.editable-time:hover {
    background-color: #e3f2fd;
    color: #1976d2;
}

.match-time.editable-time:focus {
    outline: 2px solid #3498db;
    background-color: white;
    color: #2196f3;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.match-court-count {
    font-size: 0.75rem;
    color: #666;
    margin-top: 4px;
    white-space: nowrap;
}

.match-court-count .court-count-label {
    display: inline-block;
    color: #666;
}

.match-court-count .editable-court-count {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
    min-width: 30px;
    display: inline-block;
    color: #2196f3;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.match-court-count .editable-court-count:hover {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    color: #1976d2;
}

.match-court-count .editable-court-count:focus {
    outline: 1px solid #ffc107;
    background-color: #fff;
    border: 1px solid #ffc107;
    color: #2196f3;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.match-court-count .continued-from-label {
    font-size: 0.85em;
    color: #666;
    font-style: italic;
    margin-left: -8px;
    white-space: nowrap;
    display: inline;
}

.match-actions {
    margin-top: 6px;
    display: flex;
    gap: 5px;
}

.btn-switch {
    padding: 4px 8px;
    font-size: 0.75rem;
    background-color: #ff9800;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    min-height: 28px;
    min-width: 80px;
}

.btn-switch:hover {
    background-color: #f57c00;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    width: 20px;
    min-width: 20px;
    background: #ecf0f1;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    gap: 0;
    font-size: 0.7rem;
    color: #7f8c8d;
    align-self: stretch;
    transition: background-color 0.2s;
    flex-shrink: 0;
    user-select: none;
    overflow: hidden;
}

.sidebar-toggle:hover {
    background: #d5dbdb;
    color: #2c3e50;
}

.sidebar-toggle-arrow {
    flex-shrink: 0;
}

.sidebar-toggle-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 0.75rem;
    font-weight: 600;
    color: #2c3e50;
    letter-spacing: 0.5px;
    margin-top: 8px;
    display: none;
}

.sidebar-toggle.collapsed .sidebar-toggle-label {
    display: block;
}

/* Summary Sidebar */
.summary-sidebar {
    width: 280px;
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: 100%; /* Take full height of parent */
    max-height: 100%; /* Don't exceed parent */
    overflow: hidden; /* Prevent sidebar from causing scroll */
    z-index: 10;
    box-sizing: border-box;
    transition: width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.summary-sidebar.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    border: none;
    box-shadow: none;
}

.summary-sidebar h2 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.2rem;
    flex-shrink: 0; /* Keep header visible */
}

.team-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1 1 auto; /* Grow and shrink as needed */
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0; /* Allow flex item to shrink */
    padding-right: 5px; /* Space for scrollbar */
}

/* Custom scrollbar styling for team summary */
.team-summary::-webkit-scrollbar {
    width: 8px;
}

.team-summary::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.team-summary::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.team-summary::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.team-summary-item {
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    transition: all 0.2s ease;
    overflow: hidden; /* Clip content to border radius */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Prevent items from being compressed */
    width: 100%;
    box-sizing: border-box;
}

.team-summary-item.team-hidden {
    opacity: 0.5;
    background-color: #e9e9e9;
}

.team-summary-item.team-visible {
    opacity: 1;
    background-color: #f9f9f9;
}

.team-summary-item.team-selected {
    border: 2px solid #2196f3;
    box-shadow: 0 2px 6px rgba(33, 150, 243, 0.3);
}

.team-summary-item:hover {
    background-color: #e8f5e9;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.team-summary-item.team-selected:hover {
    background-color: #e8f5e9;
    box-shadow: 0 4px 8px rgba(33, 150, 243, 0.4);
    transform: translateY(-2px);
}

.team-summary-actions {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    flex-shrink: 0; /* Keep actions visible */
}

.show-all-link {
    display: inline-block;
    color: #2196f3;
    text-decoration: none;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.show-all-link:hover {
    background-color: #e3f2fd;
    text-decoration: underline;
}

/* Team Summary Row Styles */
.team-name-row {
    padding: 6px 10px;
    font-weight: 600;
    font-size: 0.95rem;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    flex-shrink: 0;
}

.team-club-row {
    padding: 4px 10px;
    font-size: 0.85rem;
    color: #666;
    background-color: white;
    flex-shrink: 0;
    margin-bottom: 0; /* Reduce spacing between rows */
    display: flex;
    align-items: center;
}

.club-name-text {
    flex: 1;
}

.calendar-icon {
    cursor: pointer;
    margin-left: 8px;
    font-size: 0.9em;
    opacity: 0.7;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.calendar-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

.team-courts-row {
    padding: 2px 10px;
    font-size: 0.85rem;
    color: #666;
    background-color: white;
    flex-shrink: 0;
    margin-bottom: 0; /* Reduce spacing between rows */
}

.team-matches-row {
    padding: 2px 10px 4px 10px; /* Reduced top padding to bring closer to previous row */
    font-size: 0.85rem;
    color: #666;
    background-color: white;
    flex-shrink: 0;
}

/* Conflict Legend */
.conflict-legend {
    margin-top: 20px;
    padding: 10px;
    background: white;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* When inside flex container in calendar header, remove top margin for proper alignment */
.calendar-header > div .conflict-legend {
    margin-top: 0;
}

.calendar-header > div:has(.conflict-legend) .conflict-legend {
    margin-top: 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid #ddd;
}

.legend-color.conflict {
    background-color: #ffebee;
    border-color: #f44336;
}

.legend-color.overbooked {
    background-color: #fff9c4;
    border-color: #fbc02d;
}

.match-item.overbooked-match {
    background-color: #fff9c4;
}


/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e0e0e0;
    background-color: #f5f5f5;
    border-radius: 8px 8px 0 0;
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #2c3e50;
}

.modal-body {
    padding: 24px;
    font-size: 1rem;
    color: #333;
    line-height: 1.5;
}

.modal-input {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

.modal-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background-color: #fafafa;
    border-radius: 0 0 8px 8px;
}

.modal-footer .btn {
    min-width: 100px;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.modal-footer .btn-primary {
    background-color: #2196f3;
    color: white;
}

.modal-footer .btn-primary:hover {
    background-color: #1976d2;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(33, 150, 243, 0.3);
}

.modal-footer .btn-primary:active {
    transform: translateY(0);
}

.modal-footer .btn-secondary {
    background-color: #757575;
    color: white;
}

.modal-footer .btn-secondary:hover {
    background-color: #616161;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(117, 117, 117, 0.3);
}

.modal-footer .btn-secondary:active {
    transform: translateY(0);
}

#modal-ok-btn {
    display: none;
}

#modal-cancel-btn {
    display: none;
}

/* Help Modal Overlay */
.help-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 10001;
    align-items: center;
    justify-content: center;
}

.help-modal-overlay.show {
    display: flex;
}

.help-modal-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    max-width: 100%;
    width: calc(100% - 40px);
    height: calc(100% - 40px);
    display: flex;
    flex-direction: column;
    animation: modalFadeIn 0.3s ease-out;
}

.help-modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    background-color: #2c3e50;
    color: white;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.help-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.help-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    line-height: 1;
}

.help-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.help-modal-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#help-iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex: 1;
    min-height: 600px;
}

/* Blackout Dates Modal Overlay */
.blackout-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 10002;
    align-items: center;
    justify-content: center;
}

.blackout-modal-overlay.show {
    display: flex;
}

.blackout-modal-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalFadeIn 0.3s ease-out;
}

.blackout-modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    background-color: #2c3e50;
    color: white;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.blackout-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.blackout-modal-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    line-height: 1;
}

.blackout-modal-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.blackout-modal-body {
    padding: 24px;
    font-size: 1rem;
    color: #333;
    line-height: 1.6;
    overflow-y: auto;
    flex: 1;
}

.blackout-modal-body ul {
    margin: 10px 0;
}

.blackout-modal-body li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.blackout-modal-body li:last-child {
    border-bottom: none;
}

/* Responsive Design */
/* Tablet: 3-day week grid */
@media (max-width: 1024px) {
    .days-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .summary-sidebar {
        width: 100%;
        max-height: 400px;
        position: relative;
        top: 0;
    }

    .main-content {
        flex-direction: column;
    }
}

/* Mobile: 1-day column layout */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
    }

    .days-grid {
        grid-template-columns: 1fr;
    }

    .form-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .action-buttons {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        width: 100%;
    }
    
    .action-buttons .btn {
        width: 100%;
    }

    .control-group input,
    .control-group select {
        width: 100%;
    }

    .btn {
        width: 100%;
        margin-bottom: 10px;
    }

    .summary-sidebar {
        width: 100%;
        max-height: 300px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .day-cell {
        min-height: 100px;
    }

    .match-item {
        min-height: 70px;
        padding: 10px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .match-item {
        min-height: 80px;
        padding: 12px;
    }

    .btn-switch {
        min-height: 44px;
        min-width: 100px;
        font-size: 0.9rem;
    }

    .day-cell {
        min-height: 140px;
    }
}

/* Match Status Overlay */
.match-status-overlay {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background-color: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 18px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    display: none;
    max-width: 400px;
    font-size: 0.9rem;
    line-height: 1.4;
    pointer-events: none;
    animation: fadeIn 0.3s ease-in;
}

.match-status-overlay.show {
    display: block;
}

.match-status-overlay.status-success {
    background-color: #2e7d32;
    color: #ffffff;
}

.match-status-overlay #match-status-message {
    margin: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Day Matches Overlay */
.day-matches-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.day-matches-overlay.show {
    opacity: 1;
    visibility: visible;
}

.day-matches-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.day-matches-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f9fa;
}

.day-matches-header h3 {
    margin: 0;
    font-size: 1.3rem;
    color: #2c3e50;
}

.day-matches-close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: #7f8c8d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.day-matches-close-btn:hover {
    background-color: #e74c3c;
    color: white;
}

.day-matches-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.day-matches-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.day-match-club {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 15px;
    background-color: #f8f9fa;
}

.day-match-club-name {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: #2c3e50;
    padding-bottom: 8px;
    border-bottom: 2px solid #3498db;
}

.day-match-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.day-match-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: white;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

.day-match-division {
    font-weight: 500;
    color: #2c3e50;
}

.day-match-times {
    color: #7f8c8d;
    font-size: 0.95rem;
}

/* Make day name clickable */
.day-name {
    cursor: pointer;
    transition: color 0.2s ease;
}

.day-name:hover {
    color: #3498db;
}

/* Day Add Match Button */
.day-add-match-btn {
    width: 24px;
    height: 24px;
    border: none;
    background-color: #3498db;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    opacity: 0.7;
    transition: all 0.2s ease;
    flex-shrink: 0;
    pointer-events: auto;
    z-index: 5;
}

.day-add-match-btn:hover {
    opacity: 1;
    background-color: #2980b9;
    transform: scale(1.1);
}

.day-add-match-btn:active {
    transform: scale(0.95);
}

/* Add Match Dropdown Menu */
.add-match-dropdown {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 150px;
    z-index: 10000;
    overflow: hidden;
}

.dropdown-option {
    padding: 10px 15px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.9rem;
    color: #333;
    user-select: none;
}

.dropdown-option:hover {
    background-color: #f0f0f0;
}

.dropdown-option:active {
    background-color: #e0e0e0;
}

#load-btn {
    height: 37px;
    min-height: 37px;
}