/**
 * Appointment Booking Widget - Production Styling
 *
 * @package     Phoca_Premiere
 * @subpackage  CSS/Components
 * @since       6.0.6
 * @copyright   Copyright (C) 2026 Dariusz Mysliwiec. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 *
 * BEM convention: .ph-booking-* (Block), .ph-*-* (Element), .ph--*-* (Modifier)
 * Dark mode support via [data-bs-theme="dark"] and .dark-mode selectors
 * WCAG 2.1 AA compliant: 4.5:1 contrast minimum, focus indicators, reduced motion support
 */

/* ==========================================================================
   1. CSS Custom Properties (Design Tokens)
   ========================================================================== */

:root {

    /* Primary palette */
    --ph-book-primary: #3b82f6;
    --ph-book-primary-hover: #2563eb;
    --ph-book-primary-light: rgb(59 130 246 / 10%);
    --ph-book-primary-ring: rgb(59 130 246 / 25%);

    /* Surfaces */
    --ph-book-bg: #fff;
    --ph-book-surface: #f9fafb;
    --ph-book-surface-hover: #f3f4f6;

    /* Borders */
    --ph-book-border: #e5e7eb;
    --ph-book-border-focus: #3b82f6;

    /* Text */
    --ph-book-text: #1f2937;
    --ph-book-text-muted: #6b7280;
    --ph-book-text-error: #dc2626;

    /* Feedback */
    --ph-book-success: #10b981;
    --ph-book-success-bg: rgb(16 185 129 / 10%);
    --ph-book-error: #ef4444;
    --ph-book-error-bg: rgb(239 68 68 / 8%);
    --ph-book-warning: #f59e0b;
    --ph-book-warning-bg: rgb(245 158 11 / 8%);

    /* Elevation */
    --ph-book-shadow: 0 4px 6px -1px rgb(0 0 0 / 10%), 0 2px 4px -2px rgb(0 0 0 / 10%);
    --ph-book-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 10%), 0 4px 6px -4px rgb(0 0 0 / 10%);

    /* Spacing (rhythm scale) */
    --ph-book-radius: 12px;
    --ph-book-radius-sm: 8px;
    --ph-book-radius-full: 9999px;

    /* Transitions */
    --ph-book-transition: 0.2s ease;
    --ph-book-transition-slow: 0.3s ease;
}

/* Dark Mode Overrides */
[data-bs-theme="dark"],
.dark-mode {
    --ph-book-primary: #60a5fa;
    --ph-book-primary-hover: #93bbfd;
    --ph-book-primary-light: rgb(96 165 250 / 12%);
    --ph-book-primary-ring: rgb(96 165 250 / 30%);
    --ph-book-bg: #111827;
    --ph-book-surface: #1f2937;
    --ph-book-surface-hover: #374151;
    --ph-book-border: #374151;
    --ph-book-border-focus: #60a5fa;
    --ph-book-text: #f9fafb;
    --ph-book-text-muted: #9ca3af;
    --ph-book-text-error: #fca5a5;
    --ph-book-success: #34d399;
    --ph-book-success-bg: rgb(52 211 153 / 12%);
    --ph-book-error: #f87171;
    --ph-book-error-bg: rgb(248 113 113 / 10%);
    --ph-book-warning: #fbbf24;
    --ph-book-warning-bg: rgb(251 191 36 / 10%);
    --ph-book-shadow: 0 4px 6px -1px rgb(0 0 0 / 40%), 0 2px 4px -2px rgb(0 0 0 / 30%);
    --ph-book-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 50%), 0 4px 6px -4px rgb(0 0 0 / 40%);
}

/* ==========================================================================
   2. Reduced Motion (Accessibility)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .ph-booking-wrapper *,
    .ph-booking-wrapper *::before,
    .ph-booking-wrapper *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================================================
   3. Wrapper & Layout
   ========================================================================== */

.ph-booking-wrapper {
    max-width: 900px;
    margin: 2rem auto;
    background: var(--ph-book-bg);
    border-radius: var(--ph-book-radius);
    box-shadow: var(--ph-book-shadow-lg);
    display: flex;
    overflow: hidden;
    color: var(--ph-book-text);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (width <= 768px) {
    .ph-booking-wrapper {
        flex-direction: column;
        margin: 1rem;
        border-radius: var(--ph-book-radius-sm);
    }
}

/* ==========================================================================
   4. Sidebar
   ========================================================================== */

.ph-booking-sidebar {
    background: var(--ph-book-surface);
    padding: 2rem;
    width: 320px;
    border-right: 1px solid var(--ph-book-border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

@media (width <= 768px) {
    .ph-booking-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--ph-book-border);
        padding: 1.5rem;
    }
}

.ph-booking-title {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    margin: 0;
    color: var(--ph-book-text);
}

.ph-booking-duration {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ph-book-primary);
    font-weight: 600;
    font-size: 0.875rem;
    background: var(--ph-book-primary-light);
    padding: 0.375rem 0.75rem;
    border-radius: var(--ph-book-radius-full);
    width: fit-content;
}

.ph-booking-duration__icon {
    font-size: 1rem;
}

.ph-booking-description {
    color: var(--ph-book-text-muted);
    font-size: 0.9375rem;
    line-height: 1.6;
    margin: 0;
}

/* Timezone Selector */
.ph-timezone-selector {
    margin-top: auto;
    padding-top: 1.25rem;
    border-top: 1px solid var(--ph-book-border);
}

.ph-timezone-selector__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ph-book-text-muted);
    margin-bottom: 0.5rem;
}

.ph-timezone-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--ph-book-border);
    border-radius: var(--ph-book-radius-sm);
    background: var(--ph-book-bg);
    color: var(--ph-book-text);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: border-color var(--ph-book-transition);
    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='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.ph-timezone-select:focus {
    outline: none;
    border-color: var(--ph-book-border-focus);
    box-shadow: 0 0 0 3px var(--ph-book-primary-ring);
}

.ph-timezone-info {
    font-size: 0.8rem;
    color: var(--ph-book-text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* ==========================================================================
   5. Main Content Area
   ========================================================================== */

.ph-booking-main {
    flex-grow: 1;
    padding: 2rem;
    position: relative;
    min-height: 480px;
    overflow: hidden;
}

@media (width <= 768px) {
    .ph-booking-main {
        padding: 1.5rem;
        min-height: 400px;
    }
}

/* ==========================================================================
   6. Calendar Grid View
   ========================================================================== */

.ph-booking-calendar-view {

    /* Visible by default */
}

.ph-calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.ph-calendar-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--ph-book-text);
    margin: 0;
}

.ph-calendar-nav {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.ph-btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--ph-book-border);
    background: transparent;
    color: var(--ph-book-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--ph-book-transition);
    font-size: 0.875rem;
}

.ph-btn-icon:hover:not(:disabled) {
    background: var(--ph-book-surface);
    border-color: var(--ph-book-text-muted);
}

.ph-btn-icon:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

.ph-btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Calendar Grid */
.ph-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem;
    text-align: center;
}

.ph-calendar-day-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ph-book-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    padding-bottom: 0.75rem;
}

.ph-calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--ph-book-transition);
    border: 2px solid transparent;
    position: relative;
}

.ph-calendar-day:not(.ph-disabled, .ph-empty):hover {
    background: var(--ph-book-primary-light);
    color: var(--ph-book-primary);
    border-color: var(--ph-book-primary);
}

.ph-calendar-day:not(.ph-disabled, .ph-empty):focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

.ph-calendar-day.ph-selected {
    background: var(--ph-book-primary);
    color: #fff;
    border-color: var(--ph-book-primary);
    font-weight: 600;
}

.ph-calendar-day.ph-today:not(.ph-selected) {
    font-weight: 700;
    color: var(--ph-book-primary);
}

.ph-calendar-day.ph-today:not(.ph-selected)::after {
    content: '';
    position: absolute;
    bottom: 2px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--ph-book-primary);
}

.ph-calendar-day.ph-disabled {
    color: var(--ph-book-text-muted);
    opacity: 0.3;
    cursor: not-allowed;
}

.ph-calendar-day.ph-empty {
    cursor: default;
}

/* ==========================================================================
   7. Time Slots
   ========================================================================== */

.ph-time-slots-container {
    margin-top: 2rem;
    display: none;
    animation: phFadeInUp 0.3s ease;
}

.ph-time-slots-container.ph-active {
    display: block;
}

.ph-time-slots-header {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ph-book-text);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ph-time-slots-header__icon {
    color: var(--ph-book-primary);
}

.ph-time-slots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
}

.ph-time-slot {
    padding: 0.75rem 0.5rem;
    border: 1px solid var(--ph-book-border);
    border-radius: var(--ph-book-radius-sm);
    text-align: center;
    font-weight: 500;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all var(--ph-book-transition);
    background: transparent;
    color: var(--ph-book-primary);
}

.ph-time-slot:hover {
    border-color: var(--ph-book-primary);
    background: var(--ph-book-primary-light);
    transform: translateY(-1px);
}

.ph-time-slot:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

.ph-time-slot.ph-selected {
    background: var(--ph-book-primary);
    color: #fff;
    border-color: var(--ph-book-primary);
    font-weight: 600;
    transform: scale(1.03);
}

.ph-time-slots-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem 1rem;
    color: var(--ph-book-text-muted);
    font-size: 0.9375rem;
}

.ph-time-slots-empty__icon {
    display: block;
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

/* ==========================================================================
   8. Booking Form View
   ========================================================================== */

.ph-booking-form-view {
    display: none;
    animation: phFadeInRight 0.3s ease;
}

.ph-booking-form-view.ph-active {
    display: block;
}

.ph-btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: none;
    color: var(--ph-book-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-bottom: 1.25rem;
    transition: color var(--ph-book-transition);
}

.ph-btn-back:hover {
    color: var(--ph-book-primary);
}

.ph-btn-back:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

.ph-form-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ph-book-text);
    margin: 0 0 0.25rem;
}

.ph-form-subtitle {
    font-size: 0.875rem;
    color: var(--ph-book-text-muted);
    margin: 0 0 1.5rem;
}

.ph-booking-form {

    /* No extra styling needed, groups handle spacing */
}

.ph-form-group {
    margin-bottom: 1.25rem;
}

.ph-form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--ph-book-text);
}

.ph-form-label__required {
    color: var(--ph-book-error);
    margin-left: 0.125rem;
}

.ph-form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--ph-book-border);
    border-radius: var(--ph-book-radius-sm);
    background: var(--ph-book-bg);
    color: var(--ph-book-text);
    font-size: 0.9375rem;
    font-family: inherit;
    transition: border-color var(--ph-book-transition), box-shadow var(--ph-book-transition);
}

.ph-form-input::placeholder {
    color: var(--ph-book-text-muted);
    opacity: 0.7;
}

.ph-form-input:hover {
    border-color: var(--ph-book-text-muted);
}

.ph-form-input:focus {
    outline: none;
    border-color: var(--ph-book-border-focus);
    box-shadow: 0 0 0 3px var(--ph-book-primary-ring);
}

.ph-form-input.ph-input-error {
    border-color: var(--ph-book-error);
}

.ph-form-input.ph-input-error:focus {
    box-shadow: 0 0 0 3px rgb(239 68 68 / 20%);
}

.ph-form-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--ph-book-surface);
}

textarea.ph-form-input {
    resize: vertical;
    min-height: 80px;
}

/* Phone input specific */
.ph-phone-input-wrapper {
    position: relative;
}

/* Form Messages */
.ph-form-msg {
    font-size: 0.8125rem;
    margin-top: 0.375rem;
    min-height: 1.25rem;
    transition: all var(--ph-book-transition);
}

.ph-form-msg--error {
    color: var(--ph-book-text-error);
    font-weight: 500;
}

.ph-form-msg--success {
    color: var(--ph-book-success);
    font-weight: 500;
}

.ph-form-msg--info {
    color: var(--ph-book-text-muted);
}

/* ==========================================================================
   9. Form Actions & Buttons
   ========================================================================== */

.ph-booking-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

.ph-btn-primary {
    background: var(--ph-book-primary);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--ph-book-radius-sm);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    flex-grow: 1;
    transition: background var(--ph-book-transition), transform var(--ph-book-transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 140px;
}

.ph-btn-primary:hover:not(:disabled) {
    background: var(--ph-book-primary-hover);
}

.ph-btn-primary:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

.ph-btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.ph-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ph-btn-outline {
    background: transparent;
    border: 1px solid var(--ph-book-border);
    color: var(--ph-book-text);
    padding: 0.75rem 1.5rem;
    border-radius: var(--ph-book-radius-sm);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: all var(--ph-book-transition);
}

.ph-btn-outline:hover {
    background: var(--ph-book-surface-hover);
    border-color: var(--ph-book-text-muted);
}

.ph-btn-outline:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

/* Success action buttons */
.ph-btn-add-calendar {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--ph-book-primary);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--ph-book-radius-sm);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--ph-book-transition);
}

.ph-btn-add-calendar:hover {
    background: var(--ph-book-primary-hover);
    text-decoration: none;
    color: #fff;
}

.ph-btn-add-calendar:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

.ph-btn-download-ics {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: 1px solid var(--ph-book-border);
    color: var(--ph-book-text);
    padding: 0.75rem 1.5rem;
    border-radius: var(--ph-book-radius-sm);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--ph-book-transition);
}

.ph-btn-download-ics:hover {
    background: var(--ph-book-surface-hover);
    border-color: var(--ph-book-text-muted);
    text-decoration: none;
    color: var(--ph-book-text);
}

.ph-btn-download-ics:focus-visible {
    outline: 2px solid var(--ph-book-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   10. Success View (Confirmation)
   ========================================================================== */

.ph-booking-success {
    display: none;
    text-align: center;
    padding: 2rem 1rem;
    animation: phFadeInScale 0.5s ease;
}

.ph-booking-success.ph-active {
    display: block;
}

.ph-success-icon-wrapper {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--ph-book-success-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    animation: phSuccessPop 0.5s ease 0.15s both;
}

.ph-success-icon {
    font-size: 2.5rem;
    color: var(--ph-book-success);
    line-height: 1;
}

.ph-success-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ph-book-text);
    margin: 0 0 0.75rem;
}

.ph-success-message {
    color: var(--ph-book-text-muted);
    font-size: 0.9375rem;
    line-height: 1.6;
    margin: 0 0 1.5rem;
}

.ph-success-details {
    background: var(--ph-book-surface);
    border-radius: var(--ph-book-radius-sm);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    text-align: left;
    font-size: 0.875rem;
    color: var(--ph-book-text);
}

.ph-success-details__item {
    display: flex;
    justify-content: space-between;
    padding: 0.375rem 0;
}

.ph-success-details__item + .ph-success-details__item {
    border-top: 1px solid var(--ph-book-border);
}

.ph-success-details__label {
    color: var(--ph-book-text-muted);
    font-weight: 500;
}

.ph-success-details__value {
    font-weight: 600;
}

.ph-success-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ==========================================================================
   11. Loading State
   ========================================================================== */

.ph-booking-loading {
    position: absolute;
    inset: 0;
    background: var(--ph-book-bg);
    opacity: 0.85;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
    z-index: 10;
    border-radius: inherit;
}

.ph-booking-loading.ph-active {
    display: flex;
}

.ph-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--ph-book-border);
    border-top-color: var(--ph-book-primary);
    border-radius: 50%;
    animation: phSpin 0.8s linear infinite;
}

.ph-loading-text {
    font-size: 0.875rem;
    color: var(--ph-book-text-muted);
    font-weight: 500;
}

/* ==========================================================================
   12. Error / Alert Banner
   ========================================================================== */

.ph-booking-alert {
    padding: 0.75rem 1rem;
    border-radius: var(--ph-book-radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
    display: none;
}

.ph-booking-alert.ph-active {
    display: block;
}

.ph-booking-alert--error {
    background: var(--ph-book-error-bg);
    color: var(--ph-book-error);
    border: 1px solid rgb(239 68 68 / 20%);
}

.ph-booking-alert--warning {
    background: var(--ph-book-warning-bg);
    color: var(--ph-book-warning);
    border: 1px solid rgb(245 158 11 / 20%);
}

.ph-booking-alert--info {
    background: var(--ph-book-primary-light);
    color: var(--ph-book-primary);
    border: 1px solid rgb(59 130 246 / 20%);
}

/* ==========================================================================
   13. Animations
   ========================================================================== */

@keyframes phFadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes phFadeInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes phFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes phFadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes phSuccessPop {
    0% {
        transform: scale(0);
    }

    60% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes phSpin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes phShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.ph-shake {
    animation: phShake 0.4s ease;
}

/* ==========================================================================
   14. Screen Reader Only
   ========================================================================== */

.ph-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   15. Print Styles
   ========================================================================== */

@media print {
    .ph-booking-wrapper {
        box-shadow: none;
        border: 1px solid #ddd;
    }

    .ph-calendar-nav,
    .ph-btn-icon,
    .ph-booking-actions {
        display: none;
    }

    .ph-time-slot {
        break-inside: avoid;
    }
}