/* Modern Medical Theme */
:root {
    --primary-color: #6B46C1;
    --secondary-color: #9F7AEA;
    --accent-color: #E9D8FD;
    --success-color: #26a69a;
    --warning-color: #ef5350;
    --background-color: #f5f5f5;
    --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --disabled-color: #9e9e9e;
    --table-border-color: #e0e0e0; /* ปรับให้เข้มขึ้น */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Prompt', sans-serif;
    background-color: var(--background-color);
    color: #37474f;
    line-height: 1.6;
}

/* Header Styling */
header {
    background: white;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
}

.header-text h1 {
    color: var(--primary-color);
    font-size: 1.8rem;
    text-align: center;
    font-weight: 600;
    position: relative;
    padding-bottom: 1rem;
}

.header-text h1::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 3px;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
}

/* Main Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
    background: white;
    border-radius: 15px;
    box-shadow: var(--card-shadow);
}

/* Date Selection Area */
.date-selection-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 2rem 0;
    padding: 1.5rem;
    background-color: var(--accent-color);
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.date-label {
    font-size: 1.1rem;
    color: var(--primary-color);
    font-weight: 500;
    white-space: nowrap;
}

#bookingDate {
    width: 200px;
    padding: 0.8rem 1rem;
    border: 2px solid var(--secondary-color);
    border-radius: 8px;
    font-size: 1rem;
    background-color: white;
    color: var(--primary-color);
    transition: all 0.3s ease;
    margin: 0;
    display: inline-block;
}

#bookingDate:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0,131,143,0.1);
    outline: none;
}

#selectedDate {
    text-align: center;
    color: var(--primary-color);
    font-size: 1.4rem;
    font-weight: 600;
    margin: 1.5rem 0;
    padding: 1rem;
    background: linear-gradient(to right, transparent, var(--accent-color), transparent);
    border-radius: 8px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

/* Booking Table */
#bookingTable {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--table-border-color); /* เพิ่มเส้นขอบตาราง */
}

#bookingTable th {
    background-color: var(--primary-color);
    color: white;
    padding: 1.2rem;
    font-weight: 500;
    border: none;
    position: relative;
}

#bookingTable th:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background-color: rgba(255, 255, 255, 0.4); /* เพิ่มความชัดของเส้นแบ่งหัวตาราง */
}

#bookingTable td {
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid var(--table-border-color);
    border-right: 1px solid var(--table-border-color);
    transition: all 0.2s ease;
}

#bookingTable tr:last-child td {
    border-bottom: none;
}

#bookingTable td:last-child {
    border-right: none;
}

#bookingTable tr:nth-child(even) td {
    background-color: rgba(0, 131, 143, 0.04); /* เพิ่มความเข้มของพื้นหลังแถวคู่ */
}

#bookingTable tr:hover td {
    background-color: var(--accent-color);
    transition: background-color 0.2s ease;
    cursor: pointer;
}

/* Button Styling */
.button-container {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}

.booking-button {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 25px;
    font-weight: 500;
    min-width: 80px;
    cursor: default;
}

.available {
    background-color: #e8f5e9;
    color: #2e7d32;
}

.full {
    background-color: #e0e0e0;
    color: #757575;
}

.book-button {
    padding: 0.6rem 1.2rem;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: white;
    text-decoration: none;
    border-radius: 25px;
    transition: transform 0.3s, box-shadow 0.3s;
    min-width: 80px;
    display: inline-block;
    text-align: center;
}

.book-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.book-button.disabled {
    background: #e0e0e0;
    color: #757575;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    pointer-events: none;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    margin-top: 1rem;
    color: var(--primary-color);
    font-size: 1.1rem;
}

/* Close Button */
.close-button-container {
    text-align: center;
    margin: 2rem 0;
}

.close-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 2rem;
    background: linear-gradient(45deg, #ef5350, #e53935);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    transition: transform 0.3s;
}

.close-button:hover {
    transform: translateY(-2px);
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Hidden Class */
.hidden {
    display: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Container */
    .container {
        padding: 0.8rem;
        margin: 0.8rem;
        border-radius: 10px;
    }

    /* Header */
    header {
        padding: 1rem;
    }

    .header-text h1 {
        font-size: 1.3rem;
        padding-bottom: 0.8rem;
    }

    .header-text h1::after {
        width: 80px;
    }

    /* Date Selection */
    .date-selection-container {
        flex-direction: column;
        padding: 1rem;
        gap: 0.8rem;
    }

    .date-label {
        text-align: center;
        font-size: 1rem;
    }

    #bookingDate {
        width: 100%;
        max-width: 280px;
        padding: 0.7rem;
        font-size: 0.95rem;
    }

    #selectedDate {
        font-size: 1.1rem;
        padding: 0.8rem;
        margin: 1rem 0;
    }

    /* Table Responsive */
    #bookingTable {
        width: 100%;
        min-width: unset;
        font-size: 0.9rem;
        margin-top: 1rem;
    }

    #bookingTable th {
        padding: 0.8rem 0.5rem;
        font-size: 0.9rem;
        white-space: normal;
    }

    #bookingTable td {
        padding: 0.8rem 0.4rem;
        font-size: 0.9rem;
    }

    #bookingTable td:last-child {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* Buttons in Table */
    .button-container {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.3rem;
    }

    .booking-button,
    .book-button {
        width: 100%;
        min-width: unset;
        padding: 0.8rem;
        margin: 0.2rem 0;
        min-height: 44px;
        font-size: 0.9rem;
    }

    /* Loading */
    .loading-spinner {
        width: 40px;
        height: 40px;
    }

    .loading-text {
        font-size: 1rem;
    }

    /* Close Button */
    .close-button {
        padding: 0.8rem 1.5rem;
        font-size: 0.9rem;
        min-height: 44px;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .container {
        padding: 0.6rem;
        margin: 0.5rem;
    }

    .header-text h1 {
        font-size: 1.1rem;
    }

    #selectedDate {
        font-size: 1rem;
    }

    #bookingTable th,
    #bookingTable td {
        padding: 0.6rem 0.3rem;
        font-size: 0.85rem;
    }

    .booking-button,
    .book-button {
        padding: 0.6rem;
        font-size: 0.85rem;
    }

    .close-button {
        padding: 0.6rem 1.5rem;
        font-size: 0.85rem;
    }
}

/* Safe Area Insets for Modern Phones */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(0.8rem, env(safe-area-inset-left));
        padding-right: max(0.8rem, env(safe-area-inset-right));
        padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
    }
}

/* Touch Device Optimization */
@media (hover: none) {
    .book-button:hover {
        transform: none;
    }

    #bookingTable tr:hover td {
        background-color: inherit;
    }

    .book-button:active {
        transform: scale(0.98);
    }
}

/* Font Optimization for Mobile */
@media (max-width: 768px) {
    body {
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* Hide Elements on Mobile if needed */
@media (max-width: 768px) {
    .hide-on-mobile {
        display: none;
    }
}