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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    min-height: 100vh;
}

header {
    background: #1a1a2e;
    color: #fff;
    padding: 1rem 1.5rem;
}

#header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

header h1 {
    font-size: 1.3rem;
}

#header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-btn {
    padding: 0.4rem 0.85rem;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.header-btn:hover {
    background: rgba(255,255,255,0.25);
}

#reserve-btn {
    padding: 0.5rem 1.25rem;
    background: #e94560;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

#reserve-btn:hover {
    background: #d63350;
}

#reserve-btn:active {
    transform: scale(0.97);
}

#reserve-btn.hidden {
    display: none;
}

#controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
}

#city-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#city-picker.hidden {
    display: none;
}

#city-select {
    padding: 0.4rem 0.75rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 1.75rem;
}

#city-select option {
    background: #1a1a2e;
    color: #fff;
}

#location-tabs {
    display: flex;
    gap: 0.5rem;
}

.loc-tab {
    padding: 0.4rem 1rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.loc-tab:hover {
    background: rgba(255,255,255,0.1);
}

.loc-tab.active {
    background: #e94560;
    border-color: #e94560;
}

#duration-filters {
    display: flex;
    gap: 0.35rem;
}

.dur-btn {
    padding: 0.35rem 0.75rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s;
}

.dur-btn:hover {
    background: rgba(255,255,255,0.1);
}

.dur-btn.active {
    background: #0f3460;
    border-color: #0f3460;
}

/* Day navigation */
#day-nav {
    display: flex;
    overflow-x: auto;
    gap: 0.25rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #ddd;
    -webkit-overflow-scrolling: touch;
}

.day-btn {
    flex-shrink: 0;
    padding: 0.4rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.8rem;
    text-align: center;
    line-height: 1.3;
    transition: background 0.15s;
}

.day-btn:hover {
    background: #f0f0f0;
}

.day-btn.active {
    background: #1a1a2e;
    color: #fff;
    border-color: #1a1a2e;
}

.day-btn .day-name {
    display: block;
    font-weight: 600;
    font-size: 0.75rem;
}

.day-btn .day-date {
    display: block;
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Error banner */
#error-banner {
    background: #ffe0e0;
    color: #c00;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#error-banner.hidden {
    display: none;
}

#error-retry {
    padding: 0.3rem 0.75rem;
    background: #c00;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Loading */
#loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem;
    color: #888;
}

#loading.hidden {
    display: none;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #ddd;
    border-top-color: #1a1a2e;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Availability grid */
#grid-container {
    padding: 1rem 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.availability-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 600px;
    font-size: 0.8rem;
}

.availability-table th,
.availability-table td {
    border: 1px solid #ddd;
    text-align: center;
    padding: 0.3rem 0.2rem;
    white-space: nowrap;
}

.availability-table thead th {
    background: #1a1a2e;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: 500;
    font-size: 0.75rem;
}

.availability-table tbody th {
    background: #f8f8f8;
    font-weight: 600;
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 100px;
    text-align: left;
    padding-left: 0.5rem;
}

.slot {
    min-width: 55px;
    font-size: 0.7rem;
    transition: opacity 0.15s;
}

.slot.available {
    background: #d4edda;
    color: #155724;
    font-weight: 500;
    cursor: pointer;
}

.slot.available:hover {
    background: #b8e6c8;
}

.slot.selected {
    background: #e94560;
    color: #fff;
    outline: 2px solid #e94560;
    outline-offset: -1px;
}

.slot.selected .price {
    color: rgba(255,255,255,0.85);
}

.slot.booked {
    background: #e9e9e9;
    color: #999;
}

.slot.dim {
    opacity: 0.15;
}

.slot .price {
    display: block;
    font-size: 0.65rem;
}

/* Stacked slot entries (All duration filter) */
.slot-entry {
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s;
}

.slot-entry + .slot-entry {
    margin-top: 2px;
    border-top: 1px solid rgba(21, 87, 36, 0.15);
}

.slot-entry:hover {
    background: #b8e6c8;
}

.slot-entry.selected {
    background: #e94560;
    color: #fff;
}

.slot-entry.selected .price {
    color: rgba(255,255,255,0.85);
}

.court-short {
    display: none;
}

.mobile-table {
    display: none;
}

/* Responsive – Tablet */
@media (max-width: 768px) {
    header {
        padding: 0.75rem 1rem;
    }

    header h1 {
        font-size: 1.15rem;
    }

    #controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    #location-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        padding-bottom: 0.25rem;
    }

    .loc-tab {
        flex-shrink: 0;
    }

    #day-nav {
        padding: 0.5rem 1rem;
    }

    #grid-container {
        padding: 0.75rem;
    }
}

/* Responsive – Phone */
@media (max-width: 480px) {
    header {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1rem;
    }

    #header-top {
        margin-bottom: 0.5rem;
    }

    #reserve-btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    /* Location tabs – horizontal scroll */
    #location-tabs {
        display: flex;
        gap: 0.4rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        scrollbar-width: none;
    }

    #location-tabs::-webkit-scrollbar {
        display: none;
    }

    .loc-tab {
        flex-shrink: 0;
        padding: 0.5rem 0.85rem;
        font-size: 0.8rem;
        min-height: 36px;
    }

    /* Duration filters – bigger touch targets */
    #duration-filters {
        gap: 0.4rem;
    }

    .dur-btn {
        padding: 0.45rem 0.7rem;
        font-size: 0.8rem;
        min-height: 36px;
    }

    /* Day nav – bigger touch targets, hide scrollbar */
    #day-nav {
        padding: 0.5rem 0.75rem;
        gap: 0.35rem;
        scrollbar-width: none;
    }

    #day-nav::-webkit-scrollbar {
        display: none;
    }

    .day-btn {
        padding: 0.5rem 0.6rem;
        font-size: 0.8rem;
        min-height: 44px;
        min-width: 52px;
    }

    .day-btn .day-name {
        font-size: 0.75rem;
    }

    .day-btn .day-date {
        font-size: 0.7rem;
    }

    /* Error banner */
    #error-banner {
        padding: 0.6rem 0.75rem;
        font-size: 0.85rem;
        gap: 0.5rem;
    }

    #error-retry {
        padding: 0.4rem 0.75rem;
        min-height: 36px;
    }

    /* Grid – edge-to-edge */
    #grid-container {
        padding: 0.5rem 0.25rem;
    }

    .desktop-table { display: none; }
    .mobile-table { display: table; }

    .availability-table {
        font-size: 0.8rem;
    }

    .availability-table th,
    .availability-table td {
        padding: 0.4rem 0.25rem;
    }

    .availability-table thead th {
        font-size: 0.7rem;
        padding: 0.4rem 0.2rem;
    }

    .availability-table tbody th {
        min-width: 50px;
        font-size: 0.75rem;
        padding-left: 0.35rem;
    }

    .slot {
        min-width: 52px;
        font-size: 0.75rem;
        padding: 0.35rem 0.15rem;
    }

    .slot .price {
        font-size: 0.6rem;
    }
}

/* Auth Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    position: relative;
    background: #fff;
    border-radius: 8px;
    padding: 2rem;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-content h2 {
    margin-bottom: 1.25rem;
    font-size: 1.2rem;
    color: #1a1a2e;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #888;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

#auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#auth-form input {
    padding: 0.6rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

#auth-form input:focus {
    outline: none;
    border-color: #1a1a2e;
}

#auth-submit {
    padding: 0.65rem;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

#auth-submit:hover {
    background: #2a2a4e;
}

#auth-error {
    font-size: 0.8rem;
    min-height: 1.2rem;
    margin: 0;
}

#auth-toggle {
    background: none;
    border: none;
    color: #0f3460;
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

#auth-toggle:hover {
    color: #1a1a2e;
}
