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

html, body {
    height: 100%;
    overflow: hidden; /* only the sidebar and main content scroll internally — the page itself never grows/jumps */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: bold;
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.full-width {
    width: 100%;
}

/* ---------- App shell: fixed sidebar + independently scrolling content ---------- */

.app-shell {
    display: flex;
    height: 100vh;
    width: 100%;
}

.sidebar {
    flex: 0 0 300px;
    width: 300px;
    height: 100vh;
    overflow-y: auto;
    background: white;
    box-shadow: 3px 0 15px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 14px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    padding-bottom: 14px;
    border-bottom: 1px solid #e5e7eb;
}

.sidebar-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
    flex: 1;
    min-height: 0; /* let the watch list's own scroll take over instead of growing the sidebar */
}

.brand {
    gap: 4px;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.brand h1 {
    font-size: 1.15em;
    color: #667eea;
    margin: 0;
}

/* Mobile-only "☰ Filtry a sledování" toggle for #sidebarPanels — hidden on
   desktop, where the panels are simply always visible (see media query
   below for the collapsed/expanded behavior). */
.sidebar-toggle {
    display: none;
    align-items: center;
    gap: 4px;
    background: #eef0fd;
    color: #4c51bf;
    font-size: 0.78em;
    padding: 6px 10px;
}

.sidebar-toggle:hover {
    transform: none;
    box-shadow: none;
    background: #e0e4fc;
}

.sidebar-toggle-icon {
    font-size: 1.1em;
}

.sidebar-panels {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    min-height: 0;
}

/* Hidden on narrow screens until the schedule itself is what people came
   for — see the mobile hint text and touch drag-select support instead. */
.mobile-hint {
    display: none;
}

.section-label {
    font-size: 0.75em;
    color: #6b7280;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Secondary explanatory text under a control (email hint, watch status). */
.hint {
    font-size: 0.75em;
    color: #6b7280;
    line-height: 1.4;
}

.hint:empty {
    display: none;
}

/* Server-side misconfiguration the user must know about (no mail key). */
.system-warning {
    margin-top: 6px;
    padding: 8px 10px;
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #dc2626;
    border-radius: 6px;
    font-size: 0.78em;
    line-height: 1.4;
}

.system-warning[hidden] {
    display: none;
}

/* ---------- Email dialog (replaces alert() when no email is set yet) ---------- */

.email-dialog {
    border: none;
    border-radius: 12px;
    padding: 20px;
    max-width: 22rem;
    width: calc(100% - 2.5rem);
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
    /* The browser centers <dialog> itself (UA stylesheet: `dialog { margin:
       auto }`) — but this file's own `* { margin: 0 }` reset is author CSS,
       which always wins over UA CSS regardless of specificity, so without
       this the dialog collapses to the top-left corner. */
    margin: auto;
}

.email-dialog::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.email-dialog h2 {
    color: #667eea;
    font-size: 1.1em;
    margin-bottom: 6px;
}

.email-dialog .hint {
    margin-bottom: 14px;
}

.email-dialog .text-input {
    margin-bottom: 16px;
}

.email-dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.email-dialog-actions .watch-btn {
    flex: none;
}

.system-warning code {
    font-size: 0.95em;
}

.data-status {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 1.4em;
    font-size: 0.78em;
    color: #6b7280;
}

.spinner {
    width: 14px;
    height: 14px;
    flex: none;
    border: 2px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner[hidden] {
    display: none;
}

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

.text-input {
    padding: 7px 10px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 0.85em;
    color: #333;
    background: white;
    transition: border-color 0.2s;
}

.text-input:hover {
    border-color: #667eea;
}

.text-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.venue-filter {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.venue-filter label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
    color: #333;
    background: #f7fafc;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    user-select: none;
}

.venue-filter label:has(input:checked) {
    border-color: #667eea;
    background: #eef0fd;
}

.watch-actions {
    display: flex;
    gap: 8px;
}

.watch-btn {
    flex: 1;
    background: #f59e0b;
    color: white;
    border: none;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
}

.watch-btn:hover {
    background: #d97706;
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(245, 158, 11, 0.4);
}

.watch-btn.secondary {
    background: #6b7280;
}

.watch-btn.secondary:hover {
    background: #4b5563;
    box-shadow: 0 3px 10px rgba(107, 114, 128, 0.4);
}

.watch-section {
    overflow: hidden; /* the list below scrolls; header, status and buttons stay put */
}

.watch-list {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.watch-list-empty {
    color: #9ca3af;
    text-align: center;
    font-size: 0.8em;
    line-height: 1.4;
    padding: 14px 6px;
    border: 1px dashed #e5e7eb;
    border-radius: 6px;
}

.watch-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-left: 3px solid #cbd5e1;
    background: #f7fafc;
    border-radius: 3px;
    font-size: 0.78em;
    cursor: pointer;
    transition: background 0.15s;
}

.watch-item:hover {
    background: #eef2ff;
}

.watch-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.watch-item-when {
    font-weight: 600;
    color: #333;
}

.watch-item-where {
    color: #4b5563;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.watch-item-status {
    color: #6b7280;
    font-size: 0.9em;
}

/* A watched slot that is free right now — the whole point of watching. */
.watch-item.freed {
    border-left-color: #10b981;
    background: #d1fae5;
}

.watch-item.freed:hover {
    background: #a7f3d0;
}

.watch-item.freed .watch-item-status {
    color: #047857;
    font-weight: 700;
}

.watch-item.booked {
    border-left-color: #e63946;
}

.watch-item.past,
.watch-item.unknown {
    opacity: 0.6;
}

.watch-item-remove {
    flex: none;
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 1em;
    padding: 2px 5px;
    border-radius: 4px;
}

.watch-item-remove:hover {
    color: #dc2626;
    background: #fee2e2;
}

/* ---------- Main content ---------- */

.main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 18px 22px;
}

.error-slot:empty {
    display: none;
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 16px;
    border-left: 4px solid #dc2626;
}

.venue-warning {
    background: #fef3c7;
    color: #92400e;
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 16px;
    border-left: 4px solid #d97706;
}

.venue-warning ul {
    margin: 6px 0 0;
    padding-left: 20px;
}

.day-section {
    background: white;
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    overflow-x: auto;
}

.day-header {
    margin-bottom: 6px;
    padding-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.day-title {
    font-size: 1.05em;
    color: #667eea;
    font-weight: bold;
    margin: 0;
}

.day-summary {
    display: flex;
    gap: 10px;
    font-size: 0.9em;
    flex-wrap: wrap;
    align-items: center;
}

.summary-badge {
    padding: 4px 10px;
    border-radius: 5px;
    font-weight: bold;
    font-size: 0.95em;
}

.summary-badge.available {
    background: #d1fae5;
    color: #065f46;
}

/* ---------- Schedule table ---------- */

.schedule-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.72em;
    min-width: 800px;
    user-select: none; /* avoid text-selection ghosting while drag-selecting slots */
    -webkit-touch-callout: none; /* suppress iOS's long-press callout/magnifier — long-press starts a drag-select instead (see dragSelect.ts) */
}

.schedule-table th {
    background: #2d3748;
    color: white;
    padding: 2px 3px;
    text-align: center;
    font-weight: bold;
    border: 1px solid #1a202c;
    white-space: nowrap;
    font-size: 0.85em;
}

.schedule-table td {
    padding: 0;
    border: 1px solid #e5e7eb;
    height: 13px;
    min-width: 13px;
    text-align: center;
}

.schedule-table .court-name {
    background: #f7fafc;
    padding: 1px 5px;
    font-weight: bold;
    text-align: left;
    color: #667eea;
    position: sticky;
    left: 0;
    z-index: 10;
    min-width: 64px;
    white-space: nowrap;
}

.schedule-table .court-name-header {
    min-width: 64px;
    position: sticky;
    left: 0;
    z-index: 11;
}

.schedule-table .price-row {
    background: #edf0f5;
    color: #6b7280;
    font-weight: 600;
    font-size: 0.85em;
}

.schedule-table .venue-row .venue-name {
    background: #eef0fd;
    color: #4c51bf;
    text-align: left;
    padding: 3px 6px;
    font-weight: 700;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    position: sticky;
    left: 0;
}

.schedule-table .venue-row .venue-count {
    text-transform: none;
    font-weight: 500;
    color: #6b7280;
    letter-spacing: normal;
}

.slot-cell {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s, opacity 0.15s;
}

/* Only cells with real slot data (inside a .slot-td) are interactive —
   the plain "no data at all here" fallback cells stay non-interactive. */
.slot-td .slot-cell {
    cursor: pointer;
}

.slot-cell.available {
    background-color: #fff;
}

.slot-cell.booked {
    background-color: #e63946;
}

.slot-cell.closed {
    background-color: #cbd5e0;
}

/* "Past" is an overlay independent of status (available/booked/closed),
   drawn on top of whatever color that status already set — not a
   replacement for it, so a past-booked slot still reads as booked, just
   also visibly past. Only `background-image` is set here (never the
   `background` shorthand, which would reset the color underneath); this
   rule must stay AFTER the status rules above so its background-image wins
   the cascade while background-color still comes from .available/.booked/
   .closed. Applies uniformly to every status so it's always drawn on every
   elapsed cell, with no exceptions.
   Opacity/spacing tuned for visibility against WHITE specifically (the
   .available case) at this cell's tiny ~13px size — a lighter overlay here
   read clearly on red/gray but was nearly invisible on white, making
   past-but-still-available cells look like nothing had changed at all. */
.slot-cell.past {
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        rgba(15, 23, 42, 0.55) 2px,
        rgba(15, 23, 42, 0.55) 4px
    );
}

/* Hover feedback on every status, not just available, so hovering always
   confirms "this cell is interactive" regardless of what it shows. Uses
   background-color (not the `background` shorthand) so a .past overlay's
   background-image survives hover instead of being wiped out by it. */
.slot-td:hover .slot-cell.available {
    background-color: #d1fae5;
    transform: scale(1.15);
}

.slot-td:hover .slot-cell.booked {
    background-color: #ff5b6b;
    transform: scale(1.15);
}

.slot-td:hover .slot-cell.closed {
    background-color: #b0bcd0;
    transform: scale(1.15);
}

.slot-cell.watched {
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
    position: relative;
}

.slot-cell.watched::after {
    content: '🔔';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    line-height: 1;
    text-shadow: 0 0 1px white, 0 0 2px white;
}

/* Live rectangle preview while a drag-select gesture is in progress, before
   the selection is committed to watched/unwatched on mouseup. */
.slot-cell.selecting {
    outline: 2px dashed #2563eb;
    outline-offset: -2px;
    background: rgba(37, 99, 235, 0.25);
}

/* Brief pulse on the cell a watch-list row was clicked for (see focusSlot). */
@keyframes focus-flash {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); transform: scale(1); }
    20%, 60% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.9); transform: scale(1.5); }
}

.slot-cell.focus-flash {
    animation: focus-flash 2s ease-out;
    position: relative;
    z-index: 2;
}

/* ---------- Mobile: stacked layout, page-level scroll, touch-sized targets ---------- */

@media (max-width: 760px) {
    html, body {
        overflow: auto; /* whole page scrolls now, instead of two nested viewport-height panels */
    }

    .app-shell {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        flex-basis: auto;
        height: auto;
        overflow: visible;
        padding: 0; /* .brand bleeds edge-to-edge for its sticky bar; other sections manage their own padding below */
        gap: 0;
    }

    /* Pinned to the top of the (now page-level) scroll, so the ☰ toggle is
       always reachable without scrolling back up — the whole point of a
       toggle instead of always showing the panels. */
    .sidebar-section.brand {
        position: sticky;
        top: 0;
        z-index: 20;
        background: white;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        padding: 8px 12px;
        gap: 2px;
        border-bottom: none;
    }

    .brand h1 {
        font-size: 1.02em;
    }

    .data-status {
        min-height: 1.2em;
        font-size: 0.72em;
    }

    #systemWarning {
        margin: 8px 12px 0;
    }

    .main-content {
        height: auto;
        padding: 8px 6px 24px;
    }

    .mobile-hint {
        display: block;
        font-size: 0.75em;
        color: #4b5563;
        background: #eef0fd;
        border-radius: 8px;
        padding: 6px 10px;
        margin-bottom: 8px;
    }

    /* Icon-only on mobile — the full label would wrap the header onto two
       lines on narrow phones. aria-label on the button keeps it accessible. */
    .sidebar-toggle-label {
        display: none;
    }

    /* Filters/email/watch list collapse behind the toggle by default so the
       schedule — what people actually came for — is visible immediately. */
    .sidebar-toggle {
        display: inline-flex;
        padding: 7px 9px;
    }

    .sidebar-panels {
        display: none;
        flex: none; /* no viewport-height flex-fill needed once the page itself scrolls */
        padding: 10px 12px 12px;
        gap: 10px;
    }

    .sidebar.expanded .sidebar-panels {
        display: flex;
    }

    .sidebar-section {
        gap: 6px;
        padding-bottom: 10px;
    }

    .sidebar-section.watch-section {
        flex: none;
        overflow: visible;
    }

    .watch-list {
        flex: none;
        overflow: visible;
    }

    /* ~30px touch targets instead of the 13px desktop grid — the table gets
       wider and needs more horizontal swiping, which is the expected
       trade-off for a dense multi-court schedule on a small screen. */
    .schedule-table {
        font-size: 0.8em;
    }

    .schedule-table td {
        height: 30px;
        min-width: 30px;
    }

    .schedule-table th {
        padding: 4px 3px;
    }

    .schedule-table .court-name,
    .schedule-table .court-name-header {
        min-width: 76px;
    }

    .slot-cell.watched::after {
        font-size: 11px;
    }

    .day-section {
        padding: 6px 5px;
        margin-bottom: 8px;
    }

    /* Bigger tap targets throughout the (now full-width) sidebar controls. */
    .venue-filter label {
        padding: 9px 12px;
        font-size: 0.9em;
    }

    .text-input {
        padding: 10px 12px;
        font-size: 0.95em;
    }

    .watch-btn {
        padding: 11px 10px;
    }

    .watch-item {
        padding: 9px 10px;
    }

    .watch-item-remove {
        padding: 6px 8px;
        font-size: 1.2em;
    }
}
