/* ===========================================
   Booking Calendar - Terminbuchung
   Matches R. Tiews design language
   =========================================== */

/* Section */
.booking-section {
    padding: var(--spacing-24) 0;
    background: var(--color-gray-100);
}

/* Calendar Container */
#booking-calendar {
    position: relative;
    background: var(--color-white);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--color-gray-200);
    padding: var(--spacing-6);
    overflow: hidden;
}

/* ---- Calendar Header ---- */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-3);
    margin-bottom: var(--spacing-6);
    flex-wrap: wrap;
}

.calendar-header h3 {
    font-family: var(--font-display);
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--color-gray-900);
    letter-spacing: -0.01em;
    min-width: 220px;
    text-align: center;
}

.cal-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius);
    background: var(--color-white);
    color: var(--color-gray-700);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition-fast);
    font-family: var(--font-body);
}

.cal-nav-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-frost);
}

.cal-nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: var(--color-gray-200);
    color: var(--color-gray-400);
    background: var(--color-gray-100);
}

.cal-nav-btn:disabled:hover {
    border-color: var(--color-gray-200);
    color: var(--color-gray-400);
    background: var(--color-gray-100);
}

.cal-today-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius);
    background: var(--color-white);
    color: var(--color-gray-700);
    font-family: var(--font-body);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.cal-today-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-frost);
}

/* ---- Calendar Grid ---- */
.calendar-grid {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    gap: 0;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--border-radius);
    overflow: hidden;
    min-height: 480px;
}

/* Day header row */
.cal-day-header {
    padding: var(--spacing-3) var(--spacing-2);
    text-align: center;
    font-family: var(--font-body);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-gray-700);
    background: var(--color-gray-100);
    border-bottom: 1px solid var(--color-gray-200);
    line-height: 1.3;
}

.cal-day-header .cal-day-name {
    display: block;
    font-weight: 600;
    color: var(--color-gray-700);
}

.cal-day-header .cal-day-date {
    display: block;
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--color-gray-400);
    margin-top: 2px;
}

.cal-day-header.cal-today {
    background: var(--color-primary);
    color: var(--color-white);
}

.cal-day-header.cal-today .cal-day-name,
.cal-day-header.cal-today .cal-day-date {
    color: var(--color-white);
}

.cal-day-header.cal-closed {
    background: var(--color-gray-200);
    color: var(--color-gray-400);
}

.cal-day-header.cal-closed .cal-day-name,
.cal-day-header.cal-closed .cal-day-date {
    color: var(--color-gray-400);
}

/* Time axis header (top-left corner) */
.cal-time-header {
    background: var(--color-gray-100);
    border-bottom: 1px solid var(--color-gray-200);
    border-right: 1px solid var(--color-gray-200);
}

/* Time labels column */
.cal-time-col {
    border-right: 1px solid var(--color-gray-200);
    background: var(--color-gray-100);
}

.cal-time-label {
    height: 48px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 2px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--color-gray-400);
    border-bottom: 1px solid var(--color-gray-200);
    font-family: var(--font-body);
}

/* Day columns */
.cal-day-col {
    position: relative;
    border-right: 1px solid var(--color-gray-200);
    min-height: 480px;
}

.cal-day-col:last-child {
    border-right: none;
}

/* Time row lines inside each day column */
.cal-time-row {
    height: 48px;
    border-bottom: 1px solid var(--color-gray-200);
}

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

/* ---- Slot blocks (positioned absolute within day columns) ---- */
.cal-slot {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: var(--transition-fast);
    z-index: 2;
    text-align: center;
    line-height: 1.2;
    padding: 2px 4px;
}

/* Available slot */
.cal-slot-available {
    background: rgba(26, 54, 93, 0.08);
    border: 1px solid rgba(26, 54, 93, 0.15);
    color: var(--color-primary);
    cursor: pointer;
}

.cal-slot-available:hover {
    background: rgba(26, 54, 93, 0.15);
    border-color: var(--color-primary);
    box-shadow: 0 2px 8px rgba(26, 54, 93, 0.12);
    z-index: 3;
}

.cal-slot-available:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.cal-slot-available .cal-slot-time {
    display: block;
    font-size: 0.65rem;
    opacity: 0.7;
}

/* Busy / Booked slot */
.cal-slot-busy {
    background: var(--color-gray-200);
    border: 1px solid var(--color-gray-300);
    color: var(--color-gray-500);
    cursor: default;
}

/* Past slot */
.cal-slot-past {
    background: var(--color-gray-100);
    border: 1px solid var(--color-gray-200);
    color: var(--color-gray-400);
    cursor: default;
    opacity: 0.6;
}

/* Closed day overlay */
.cal-closed-overlay {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        135deg,
        transparent,
        transparent 8px,
        rgba(0, 0, 0, 0.02) 8px,
        rgba(0, 0, 0, 0.02) 16px
    );
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.cal-closed-label {
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--color-gray-400);
    background: var(--color-white);
    padding: var(--spacing-2) var(--spacing-3);
    border-radius: var(--border-radius);
    border: 1px solid var(--color-gray-200);
}

/* Past day column dimming */
.cal-day-col.cal-past-day {
    background: var(--color-gray-100);
    opacity: 0.5;
}

/* ---- Loading State ---- */
.cal-loading {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-3);
    z-index: 10;
    border-radius: var(--border-radius-xl);
}

.cal-loading span {
    font-size: var(--font-size-sm);
    color: var(--color-gray-500);
    font-family: var(--font-body);
}

.cal-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-gray-200);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: cal-spin 0.8s linear infinite;
}

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

/* ---- Error State ---- */
.cal-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-12) var(--spacing-6);
    text-align: center;
    gap: var(--spacing-3);
}

.cal-error-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--color-gray-400);
}

.cal-error p {
    font-size: var(--font-size-sm);
    color: var(--color-gray-500);
    max-width: 360px;
}

.cal-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: 0.5rem 1.25rem;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius);
    background: var(--color-white);
    color: var(--color-gray-700);
    font-family: var(--font-body);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.cal-retry-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ===========================================
   Booking Modal
   =========================================== */
.booking-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-6);
    animation: modal-fade-in 0.2s ease;
}

.booking-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.booking-modal-content {
    position: relative;
    background: var(--color-white);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-xl);
    padding: var(--spacing-8);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1;
    animation: modal-slide-up 0.25s ease;
}

.booking-modal-content h3 {
    font-family: var(--font-display);
    font-size: var(--font-size-2xl);
    font-weight: 600;
    color: var(--color-gray-900);
    margin-bottom: var(--spacing-2);
    letter-spacing: -0.02em;
}

.booking-modal-close {
    position: absolute;
    top: var(--spacing-4);
    right: var(--spacing-4);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--color-gray-100);
    border-radius: 50%;
    font-size: 1.25rem;
    color: var(--color-gray-500);
    cursor: pointer;
    transition: var(--transition-fast);
    line-height: 1;
}

.booking-modal-close:hover {
    background: var(--color-gray-200);
    color: var(--color-gray-700);
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slot info display */
.booking-slot-info {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-4);
    background: var(--color-frost);
    border: 1px solid var(--color-ice);
    border-radius: var(--border-radius);
    color: var(--color-primary);
    font-weight: 500;
    font-size: var(--font-size-sm);
    margin-bottom: var(--spacing-6);
}

.booking-slot-info svg {
    flex-shrink: 0;
}

/* ---- Form inside modal ---- */
#booking-form .form-group {
    margin-bottom: var(--spacing-5);
}

#booking-form .form-label {
    display: block;
    font-weight: 500;
    font-size: var(--font-size-sm);
    color: var(--color-gray-700);
    margin-bottom: var(--spacing-2);
    letter-spacing: 0;
}

#booking-form .form-input,
#booking-form .form-textarea,
#booking-form .form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: var(--font-size-base);
    font-family: var(--font-body);
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius);
    transition: var(--transition-fast);
    background: var(--color-white);
    color: var(--color-gray-900);
    -webkit-appearance: none;
    appearance: none;
}

#booking-form .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

#booking-form .form-input:hover,
#booking-form .form-textarea:hover,
#booking-form .form-select:hover {
    border-color: var(--color-gray-400);
}

#booking-form .form-input:focus,
#booking-form .form-textarea:focus,
#booking-form .form-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.08);
}

#booking-form .form-input::placeholder,
#booking-form .form-textarea::placeholder {
    color: var(--color-gray-400);
}

#booking-form .form-textarea {
    min-height: 80px;
    resize: vertical;
    line-height: 1.6;
}

#booking-form .form-input.error,
#booking-form .form-textarea.error,
#booking-form .form-select.error {
    border-color: #ef4444;
}

#booking-form .form-input.error:focus,
#booking-form .form-textarea.error:focus,
#booking-form .form-select.error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error-text {
    font-size: 0.75rem;
    color: #ef4444;
    margin-top: var(--spacing-1);
}

/* Form row (two fields side by side) */
.booking-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-4);
}

/* Anhang-Grid: 4 Slots in 2x2-Layout */
.booking-attachments-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-3);
}

.booking-attachment-slot {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
    padding: var(--spacing-3);
    background: var(--color-gray-50, #f9f9f9);
    border: 1px dashed var(--color-gray-200, #d4d4d4);
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.booking-attachment-slot.has-file {
    background: var(--color-white);
    border: 1px solid var(--color-primary);
    border-style: solid;
}

.booking-attachment-slot.has-error {
    border-color: #c0392b;
    background: #fdecea;
}

.booking-attachment-label {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
    line-height: 1.3;
    cursor: pointer;
}

/* Native file input visuell verstecken — bleibt aber per Tab/Click via Label erreichbar */
.booking-attachment-input.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* "Datei wählen"-Button (Label-as-Button) */
.booking-attachment-button {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-2);
    align-self: flex-start;
    padding: 0.45rem 0.85rem;
    background: var(--color-white);
    border: 1px solid var(--color-gray-300, #d4d4d4);
    border-radius: var(--border-radius);
    color: var(--color-primary);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.booking-attachment-button:hover {
    border-color: var(--color-primary);
    background: rgba(26, 54, 93, 0.04);
}

.booking-attachment-button svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* Tastatur-Fokus: Input ist hidden, also Fokus-Ring auf Button visualisieren */
.booking-attachment-input:focus-visible + .booking-attachment-button {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.booking-attachment-slot.has-file .booking-attachment-button {
    border-color: var(--color-primary);
    background: rgba(26, 54, 93, 0.06);
}

.booking-attachment-preview {
    font-size: 0.78rem;
    color: var(--color-gray-500, #666);
    display: flex;
    justify-content: space-between;
    gap: var(--spacing-2);
    min-height: 1em;
    line-height: 1.4;
    word-break: break-all;
}

.booking-attachment-preview.is-error {
    color: #c0392b;
}

.booking-attachment-preview .preview-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.booking-attachment-preview .preview-size {
    color: var(--color-gray-400, #888);
    flex-shrink: 0;
}

@media (max-width: 540px) {
    .booking-attachments-grid {
        grid-template-columns: 1fr;
    }
}

/* Submit button */
.booking-submit-btn {
    width: 100%;
    padding: 0.875rem 1.5rem;
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    font-weight: 500;
    letter-spacing: 0;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-2);
    margin-top: var(--spacing-2);
}

.booking-submit-btn:hover {
    background: var(--color-primary-light);
}

.booking-submit-btn:active {
    transform: translateY(1px);
}

.booking-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.booking-submit-btn .btn-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--color-white);
    border-radius: 50%;
    animation: cal-spin 0.8s linear infinite;
}

/* ---- Success State ---- */
.booking-success {
    text-align: center;
    padding: var(--spacing-6) 0;
}

.booking-success .success-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #065f46;
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--spacing-4);
}

.booking-success h4 {
    font-family: var(--font-display);
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--color-gray-900);
    margin-bottom: var(--spacing-3);
}

.booking-success p {
    font-size: var(--font-size-sm);
    color: var(--color-gray-500);
    line-height: 1.6;
    max-width: 360px;
    margin: 0 auto;
}

/* ---- Booking Error Message ---- */
.booking-error-msg {
    padding: var(--spacing-3) var(--spacing-4);
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
    border: 1px solid #fca5a5;
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    font-weight: 500;
    text-align: center;
    margin-bottom: var(--spacing-4);
}

/* ===========================================
   Responsive: Tablet
   =========================================== */
@media (max-width: 1024px) {
    .calendar-grid {
        grid-template-columns: 48px repeat(7, 1fr);
    }

    .cal-time-label {
        font-size: 0.65rem;
    }

    .cal-slot {
        font-size: 0.65rem;
    }
}

/* ===========================================
   Responsive: Mobile
   =========================================== */
@media (max-width: 768px) {
    .booking-section {
        padding: var(--spacing-16) 0;
    }

    #booking-calendar {
        padding: var(--spacing-4);
    }

    .calendar-header {
        gap: var(--spacing-2);
        margin-bottom: var(--spacing-4);
    }

    .calendar-header h3 {
        font-size: var(--font-size-base);
        min-width: 0;
        order: -1;
        width: 100%;
    }

    /* Switch to 3-day view on mobile */
    .calendar-grid {
        grid-template-columns: 48px repeat(3, 1fr);
    }

    .calendar-grid .cal-day-header.cal-mobile-hidden,
    .calendar-grid .cal-day-col.cal-mobile-hidden {
        display: none;
    }

    .cal-day-header {
        padding: var(--spacing-2);
    }

    .cal-slot {
        font-size: 0.6rem;
        left: 1px;
        right: 1px;
    }

    /* Modal adjustments */
    .booking-modal {
        padding: var(--spacing-3);
        align-items: flex-end;
    }

    .booking-modal-content {
        padding: var(--spacing-6);
        max-height: 85vh;
        border-radius: var(--border-radius-xl) var(--border-radius-xl) 0 0;
    }

    .booking-form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .calendar-grid {
        grid-template-columns: 40px repeat(3, 1fr);
    }

    .cal-time-label {
        font-size: 0.6rem;
        height: 40px;
    }

    .cal-time-row {
        height: 40px;
    }

    .booking-modal-content {
        padding: var(--spacing-5);
    }
}
