/* ============================================
   Korty Tenisowe Duszniki-Zdrój
   System rezerwacji — widok timeline
   ============================================ */

:root {
    --primary: #2e7d32;
    --primary-dark: #1b5e20;
    --primary-bg: #e8f5e9;
    --accent: #ff9800;
    --accent-light: #fff3e0;
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #212121;
    --text-secondary: #666666;
    --text-light: #999999;
    --border: #dee2e6;
    --border-light: #f0f0f0;

    /* booking types */
    --member-bg: #c8e6c9;
    --member-border: #66bb6a;
    --member-text: #1b5e20;
    --guest-bg: #bbdefb;
    --guest-border: #42a5f5;
    --guest-text: #0d47a1;
    --admin-bg: #424242;
    --admin-border: #212121;
    --admin-text: #ffffff;
    --blocked-bg: #e0e0e0;
    --blocked-border: #9e9e9e;
    --blocked-text: #616161;

    --available-bg: #e8f5e9;
    --available-hover: #c8e6c9;
    --selected-bg: #ffb74d;
    --selected-border: #e65100;
    --past-bg: #fafafa;
    --today-bg: #e3f2fd;

    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;

    --row-height: 34px;
    --label-width: 120px;
    --court-label-width: 70px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container { max-width: 900px; margin: 0 auto; padding: 0 16px; width: 100%; }
.container-wide { max-width: 1400px; margin: 0 auto; padding: 0 12px; width: 100%; }

/* ---- Header ---- */
.header {
    background: var(--primary);
    color: #fff;
    padding: 16px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header-content { display: flex; align-items: center; justify-content: center; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 32px; line-height: 1; }
.logo h1 { font-size: 18px; font-weight: 700; line-height: 1.2; }
.header-subtitle { font-size: 13px; opacity: 0.85; }

/* ---- Main ---- */
.main { flex: 1; padding: 16px 0 80px; }

/* ---- Week Navigation ---- */
.week-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
}

.week-nav-btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--primary);
    background: var(--card);
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.week-nav-btn:hover { background: var(--primary); color: #fff; }
.week-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.week-nav-btn:disabled:hover { background: var(--card); color: var(--primary); }

.week-label { font-size: 16px; font-weight: 700; color: var(--text); text-align: center; }

/* ---- Timeline ---- */
.timeline-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 16px;
}

.timeline {
    min-width: 900px;
}

.loading {
    text-align: center;
    padding: 60px 16px;
    color: var(--text-light);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---- Time header ---- */
.tl-time-header {
    display: flex;
    margin-left: calc(var(--label-width) + var(--court-label-width));
    border-bottom: 2px solid var(--border);
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
}

.tl-hour-label {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 8px 0;
    border-left: 1px solid var(--border);
    min-width: 0;
}

.tl-hour-label:first-child { border-left: none; }

.tl-hour-label.now-hour {
    color: var(--primary);
    background: var(--primary-bg);
}

/* ---- Day section ---- */
.tl-day {
    display: flex;
    border-bottom: 2px solid var(--border);
    background: var(--card);
}

.tl-day:last-child {
    border-bottom: none;
    border-radius: 0 0 var(--radius) var(--radius);
}

.tl-day.today {
    background: var(--today-bg);
}

/* Day label column */
.tl-day-label {
    width: var(--label-width);
    min-width: var(--label-width);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    border-right: 1px solid var(--border);
}

.tl-day-name {
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
}

.tl-day-date {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.tl-day.today .tl-day-name { color: var(--primary); }
.tl-day.today .tl-day-date { color: var(--primary); font-weight: 700; }

/* Courts column */
.tl-day-courts {
    flex: 1;
    min-width: 0;
}

/* Court row */
.tl-court-row {
    display: flex;
    height: var(--row-height);
    border-bottom: 1px solid var(--border-light);
}

.tl-court-row:last-child {
    border-bottom: none;
}

.tl-court-name {
    width: var(--court-label-width);
    min-width: var(--court-label-width);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border-right: 1px solid var(--border-light);
    text-align: center;
}

/* Slots grid */
.tl-slots {
    flex: 1;
    display: flex;
    position: relative;
    min-width: 0;
    overflow: hidden;
}

.tl-cell {
    flex: 1;
    height: 100%;
    border-right: 1px solid var(--border-light);
    min-width: 0;
}

/* Hour separators (every 2nd cell) */
.tl-cell.hour-start {
    border-left: 1px solid var(--border);
}

/* Cell states */
.tl-cell.available {
    background: var(--available-bg);
    cursor: pointer;
}

.tl-cell.available:hover {
    background: var(--available-hover);
}

.tl-cell.past {
    background: var(--past-bg);
}

.tl-cell.selected {
    background: var(--selected-bg);
    cursor: pointer;
}

/* Booking overlays (positioned on top of cells) */
.tl-booking {
    position: absolute;
    top: 2px;
    bottom: 2px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    padding: 2px 5px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: default;
    border-left: 3px solid;
}

.tl-booking .bk-name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.tl-booking .bk-time {
    font-weight: 400;
    opacity: 0.7;
    font-size: 9px;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tooltip on hover (desktop) */
.tl-booking[data-tooltip] {
    cursor: pointer;
}

.tl-booking[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 4px;
    background: #333;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: pre-line;
    z-index: 100;
    pointer-events: none;
    min-width: 120px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Tooltip on click (mobile) */
.bk-tooltip {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 4px;
    background: #333;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: pre-line;
    z-index: 100;
    min-width: 120px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Booking types */
.tl-booking.bk-member {
    background: var(--member-bg);
    border-color: var(--member-border);
    color: var(--member-text);
}

.tl-booking.bk-guest {
    background: var(--guest-bg);
    border-color: var(--guest-border);
    color: var(--guest-text);
}

.tl-booking.bk-admin {
    background: var(--admin-bg);
    border-color: var(--admin-border);
    color: var(--admin-text);
}

.tl-booking.bk-blocked {
    background: var(--blocked-bg);
    border-color: var(--blocked-border);
    color: var(--blocked-text);
    font-weight: 500;
}

/* Selection highlight overlay */
.tl-selection {
    position: absolute;
    top: 1px;
    bottom: 1px;
    background: var(--selected-bg);
    border: 2px solid var(--selected-border);
    border-radius: 4px;
    z-index: 3;
    pointer-events: none;
}

/* ---- Legend ---- */
.legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid;
}

.lg-available { background: var(--available-bg); border-color: #66bb6a; }
.lg-member { background: var(--member-bg); border-color: var(--member-border); }
.lg-guest { background: var(--guest-bg); border-color: var(--guest-border); }
.lg-admin { background: var(--admin-bg); border-color: var(--admin-border); }
.lg-blocked { background: var(--blocked-bg); border-color: var(--blocked-border); }

/* ---- Selection Bar ---- */
.selection-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--card);
    border-top: 3px solid var(--selected-border);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 100;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.selection-bar.active { transform: translateY(0); }

.selection-bar-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.selection-info {
    font-size: 15px;
    color: var(--text);
}

.selection-info strong { color: var(--accent); }

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

.btn-cancel-sel {
    padding: 10px 20px;
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.btn-cancel-sel:hover { background: #e0e0e0; }

.btn-book-floating {
    padding: 10px 28px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.btn-book-floating:hover { background: var(--primary-dark); }

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    padding: 16px;
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.3s;
    position: relative;
}

.modal-overlay.active .modal { transform: translateY(0); }

.modal-close {
    position: absolute;
    top: 12px; right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-light);
    cursor: pointer;
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-title { font-size: 22px; font-weight: 700; margin-bottom: 20px; }

.booking-summary {
    background: var(--primary-bg);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 24px;
}

.booking-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 14px;
}

.booking-summary-label { color: var(--text-secondary); }
.booking-summary-value { font-weight: 600; }

/* ---- Form ---- */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(76,175,80,0.15);
}

/* Phone prefix dropdown */
.phone-input-group {
    display: flex;
    gap: 0;
}
.phone-prefix {
    flex-shrink: 0;
    width: 110px;
    padding: 10px 8px;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 22px;
}
.phone-prefix:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(76,175,80,0.15);
}
.phone-input-group input[type="tel"] {
    flex: 1;
    min-width: 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important;
}

.checkbox-group { margin-bottom: 20px; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 15px;
    user-select: none;
}

.checkbox-label input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }

.checkbox-custom {
    width: 22px; height: 22px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.checkbox-label input:checked + .checkbox-custom {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-label input:checked + .checkbox-custom::after {
    content: '\2713';
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}

.price-display {
    background: var(--accent-light);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: center;
    font-size: 16px;
    margin-bottom: 20px;
}

.price-display.free { background: var(--primary-bg); }
.price-display.free strong { color: var(--primary); }

.btn-book {
    width: 100%;
    padding: 14px 24px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-book:hover { background: var(--primary-dark); }
.btn-book:disabled { background: #9e9e9e; cursor: not-allowed; }

.form-error {
    margin-top: 12px;
    padding: 10px 14px;
    background: #ffebee;
    color: #c62828;
    border-radius: var(--radius-sm);
    font-size: 14px;
}

/* ---- Success Modal ---- */
.modal-success { text-align: center; padding: 40px 32px; }

.success-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.modal-success h2 { font-size: 24px; margin-bottom: 8px; }
.modal-success p { color: var(--text-secondary); margin-bottom: 24px; }

/* ---- Rules overlay ---- */
.rules-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.rules-overlay.hidden {
    display: none;
}

.rules-box {
    background: #fff;
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.rules-accept-top {
    position: sticky;
    top: 0;
    background: #fff;
    padding: 28px 28px 20px;
    border-bottom: 1px solid var(--border-light);
    text-align: center;
    z-index: 1;
    border-radius: 16px 16px 0 0;
}

.rules-accept-top h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.rules-accept-top p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.btn-accept {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 16px 48px;
    font-size: 18px;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    width: 100%;
    max-width: 360px;
    transition: background 0.2s;
}

.btn-accept:hover {
    background: var(--primary-dark);
}

.rules-content {
    padding: 24px 28px 28px;
}

.rules-content h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 20px 0 8px;
    color: var(--text);
}

.rules-content h3:first-child {
    margin-top: 0;
}

.rules-content p, .rules-content li {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.rules-placeholder {
    font-style: italic;
    color: var(--text-light);
    padding: 12px 16px;
    background: var(--bg);
    border-radius: 8px;
}

/* ---- Mobile day view ---- */
.mobile-section {
    display: none;
}

.mobile-day-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 8px;
}

.mobile-day-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: var(--card);
    color: var(--primary);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-day-btn:hover { background: var(--primary); color: #fff; }
.mobile-day-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.mobile-day-btn:disabled:hover { background: var(--card); color: var(--primary); }

.mobile-day-label {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    color: var(--text);
}

.mobile-day-label .mob-today {
    color: var(--primary);
}

.mobile-grid {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.mob-header {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    border-bottom: 2px solid var(--border);
}

.mob-header-cell {
    padding: 10px 4px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
}

.mob-header-cell:not(:first-child) {
    border-left: 1px solid var(--border);
}

.mob-row {
    display: grid;
    grid-template-columns: 60px 1fr 1fr;
    border-bottom: 1px solid var(--border-light);
}

.mob-row:last-child { border-bottom: none; }

.mob-row.hour-start {
    border-top: 1px solid var(--border);
}

.mob-time {
    padding: 0 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mob-cell {
    min-height: 40px;
    border-left: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 4px;
    text-align: center;
    cursor: default;
    transition: background 0.15s;
}

.mob-cell.available {
    background: var(--available-bg);
    cursor: pointer;
}

.mob-cell.available:active {
    background: var(--available-hover);
}

.mob-cell.past {
    background: var(--past-bg);
}

.mob-cell.booked.bk-member {
    background: var(--member-bg);
    color: var(--member-text);
}

.mob-cell.booked.bk-guest {
    background: var(--guest-bg);
    color: var(--guest-text);
}

.mob-cell.booked.bk-admin {
    background: var(--admin-bg);
    color: var(--admin-text);
}

.mob-cell.blocked {
    background: var(--blocked-bg);
    color: var(--blocked-text);
}

.mob-cell.selected {
    background: var(--selected-bg);
    border-color: var(--selected-border);
    cursor: pointer;
}

.mob-cell .mob-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* ---- Footer ---- */
.footer {
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 16px 0;
    text-align: center;
    font-size: 13px;
    color: var(--text-light);
}

.footer a { color: var(--primary); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    /* Hide desktop timeline, show mobile day view */
    .timeline-wrapper { display: none; }
    .week-nav { display: none; }
    .mobile-section { display: block; }

    .selection-bar-inner {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
    .selection-info { font-size: 13px; }

    .rules-accept-top { padding: 20px 16px 16px; }
    .rules-accept-top h2 { font-size: 18px; }
    .rules-content { padding: 16px; }
    .btn-accept { font-size: 16px; padding: 14px 24px; }
}

@media (max-width: 480px) {
    .logo h1 { font-size: 16px; }
    .modal { padding: 24px 20px; }
    .form-row { grid-template-columns: 1fr; }
    .mobile-day-label { font-size: 16px; }
    .mob-cell { min-height: 36px; font-size: 10px; }
    .mob-time { font-size: 10px; }
}
