/* Import Google Font - Prompt */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');

/* --- Variables for Theme Colors (Default: Cool Serenity - Muted Teal/Aqua) --- */
:root {
    /* Primary Colors: เน้นความสดชื่น ความสงบ และความน่าเชื่อถือ */
    --primary-color: #00A693; /* Emerald Green/Teal - เขียวมรกตอมฟ้า สดใสแต่ยังคงความสุภาพ */
    --primary-dark: #007C6B; /* Darker Primary - เขียวอมฟ้าเข้มขึ้น เพื่อสร้างความลึก */
    --primary-light: #E0F5F2; /* Very Light Primary - เขียวอมฟ้าอ่อนมาก ให้ความรู้สึกสะอาด โปร่งสบาย */
    --primary-accent: #34D399; /* Bright Green Accent - สีเขียวสดใสสำหรับปุ่มหรือจุดเด่นที่ต้องการดึงดูดสายตา */

    /* Secondary Colors: เสริมความอบอุ่นและเป็นมิตร */
    --secondary-color: #FFC107; /* Amber - สีเหลืองอำพัน เพื่อเพิ่มความสดใสและความกระปรี้กระเปร่า */
    --secondary-light: #FFF8E1; /* Light Amber - สีเหลืองอ่อนมาก เหมาะสำหรับพื้นหลังส่วนเสริม */

    /* Background Colors: สะอาดตา สบายตา และมีมิติ */
    --bg-light: #F8FCFC; /* Off-White with a hint of Teal - ขาวอมเขียวอ่อนมาก ให้ความรู้สึกสดชื่น ไม่ใช่แค่ขาวนิ่งๆ */
    --bg-white: #FFFFFF; /* Pure White - สีขาวบริสุทธิ์สำหรับส่วนที่ต้องการความคมชัดสูงสุด */

    /* Text Colors: อ่านง่าย เป็นมืออาชีพ และสบายตา */
    --text-dark: #2A363B; /* Deep Charcoal - เทาเข้มเกือบดำ ให้ความคมชัดสูง อ่านง่าย */
    --text-medium: #6B7A8F; /* Slate Grey - เทาอมน้ำเงิน ให้ความรู้สึกสุขุม เป็นมืออาชีพ */
    --text-light: #AAB7BF; /* เทาอ่อนอมน้ำเงิน เหมาะสำหรับข้อความรอง */

    /* Border & Divider: คมชัด เป็นระเบียบ และทันสมัย */
    --border-color: #E2E8F0; /* Light Grey Blue - เทาอมฟ้าอ่อน ทำให้เส้นแบ่งดูนุ่มนวลขึ้น */
    --divider-color: #F0F4F7; /* สีสำหรับเส้นแบ่งที่ละเอียดอ่อน */

    /* Status Colors: สดใส ชัดเจน และเป็นสากล */
    --success-color: #28A745; /* Vibrant Green - เขียวสดใส สำหรับการแจ้งเตือนสำเร็จ */
    --error-color: #DC3545; /* Bold Red - แดงเข้ม สำหรับการแจ้งเตือนข้อผิดพลาด */
    --warning-color: #FFC107; /* Amber (reused secondary) - เหลืองอำพัน สำหรับการแจ้งเตือนเตือน */
    --info-color: #17A2B8; /* Bright Cyan - ฟ้าอมเขียว สำหรับการแจ้งข้อมูลทั่วไป */

    /* Shadows & Borders: ทันสมัย ดูมีมิติ และโปร่งสบาย */
    --box-shadow-light: 0 4px 12px rgba(0, 0, 0, 0.05); /* เพิ่มความลึกอย่างนุ่มนวล */
    --box-shadow-medium: 0 8px 24px rgba(0, 0, 0, 0.1); /* เพิ่มความเข้มขึ้นเล็กน้อย */
    --border-radius: 8px; /* ลดความโค้งมนลงเล็กน้อย ให้ความรู้สึกทันสมัยและเฉียบคม */
    --border-radius-large: 12px; /* สำหรับองค์ประกอบที่ต้องการความโดดเด่น */
}

/* --- Base Styles --- */
body {
    font-family: 'Prompt', sans-serif;
    margin: 0;
    padding-top: 75px; /* ปรับค่าตามความสูงของ Header โดยประมาณ */
    padding-left: 0;
    padding-right: 0;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    font-weight: 300;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-dark);
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 1rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* --- Header (ปรับปรุงให้ Fixed และสวยงามขึ้น) --- */
.header {
    background: linear-gradient(to right, var(--primary-color), var(--primary-dark)); /* ไล่สี */
    color: var(--bg-white);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25),
                0 2px 8px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    box-sizing: border-box;
    transition: all 0.3s ease-in-out;
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(to right, var(--primary-accent), var(--primary-color));
    box-shadow: 0 1px 5px rgba(0,0,0,0.1);
}

.header:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3),
                0 3px 10px rgba(0, 0, 0, 0.15);
}

.header-brand-name {
    display: flex;
    flex-direction: column; /* จัดให้ข้อความใน brand-name เป็นคอลัมน์ */
    align-items: flex-start; /* จัดชิดซ้าย */
    flex-grow: 1;
    line-height: 1.2; /* ลดระยะห่างระหว่างบรรทัด */
}

/* --- ปรับปรุงชื่อระบบ 2 บรรทัด --- */
.system-title {
    color: var(--bg-white);
    font-weight: 600;
    font-size: 1.6rem; /* ขนาดใหญ่สำหรับบรรทัดแรก */
    white-space: nowrap; /* ให้เป็นบรรทัดเดียว */
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.2rem; /* เพิ่มระยะห่างเล็กน้อยจากบรรทัดล่าง */
}

.system-subtitle {
    color: var(--bg-white);
    font-weight: 400;
    font-size: 0.9rem; /* ขนาดเล็กสำหรับบรรทัดที่สอง */
    opacity: 0.8; /* ลดความเข้มลงเล็กน้อย */
    white-space: nowrap; /* ให้เป็นบรรทัดเดียว */
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--bg-white);
    font-size: 0.95rem;
    font-weight: 400;
    white-space: nowrap;
}

/* --- ปรับปรุง .current-date ให้ไม่มีกรอบ --- */
.current-date {
    font-weight: 500;
    font-size: 1rem;
    padding: 0.4rem 0;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
    transition: opacity 0.3s ease;
}
.current-date:hover {
    opacity: 0.8;
}

/* --- ปรับปรุงปุ่ม .add-new-patient-top-btn ให้เด่นขึ้น --- */
.add-new-patient-top-btn {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    background-color: var(--primary-accent);
    color: var(--bg-white);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out, transform 0.2s ease, box-shadow 0.2s ease-in-out;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
}

.add-new-patient-top-btn:hover {
    background-color: #28B47E;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

/* ===== NEW: Logout Button Style (UPDATED) ===== */
.logout-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.7); /* ทำให้เส้นขอบชัดขึ้นเล็กน้อย */
    color: var(--bg-white);
    font-size: 1.2rem; /* ทำให้ไอคอนใหญ่ขึ้นเล็กน้อย */
    width: 44px;       /* กำหนดความกว้าง */
    height: 44px;      /* กำหนดความสูง */
    border-radius: 50%;/* ทำให้เป็นวงกลม */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;        /* ลบ padding เดิมออก */
    line-height: 1;
}
.logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--bg-white);
    transform: scale(1.1) rotate(5deg);
}

/* --- New: Page Container for Sidebar and Main Content (UPDATED) --- */
.page-container {
    display: flex;
    flex-grow: 1;
    gap: 2rem;
    padding: 2rem 3rem;
    width: 100%; /* ทำให้ Container ขยายเต็มความกว้าง */
    /* max-width: 1600px; <-- ลบออกเพื่อให้ขยายเต็มหน้าจอ */
    /* margin-left: auto;  <-- ลบออก */
    /* margin-right: auto; <-- ลบออก */
    box-sizing: border-box; /* สำคัญมากสำหรับ layout */
}

/* --- New: Sidebar --- */
.sidebar {
    flex-shrink: 0;
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- Original Dashboard Overview --- */
.dashboard-overview {
    background-color: var(--bg-white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-medium);
    /* flex-grow: 1; ไม่จำเป็นแล้ว */
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.dashboard-overview h2 {
    color: var(--primary-dark);
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.summary-metrics {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.metric-item {
    background-color: var(--primary-light);
    padding: 1rem;
    border-radius: var(--border-radius);
    flex: 1;
    min-width: unset;
    max-width: 100%;
    text-align: center;
    box-shadow: var(--box-shadow-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.metric-item h3 {
    font-size: 0.9rem;
    color: var(--primary-dark);
    font-weight: 500;
    margin: 0;
}

.metric-item p {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
    color: var(--primary-color);
}

/* --- New: Main Content Wrapper --- */
.main-content-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* --- Today Patients Section --- */
.today-patients-section {
    background-color: var(--bg-white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-medium);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.today-patients-section h2 {
    color: var(--primary-dark);
    font-size: 1.6rem;
    margin-bottom: 1.5rem;
}

/* --- Buttons (General) --- */
.submit-btn,
button:not(.close-button):not(.add-new-patient-top-btn):not(.edit-info-btn):not(.edit-row-btn):not(.logout-btn) {
    background-color: var(--primary-color);
    color: var(--bg-white);
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.submit-btn:hover,
button:not(.close-button):not(.edit-info-btn):not(.edit-row-btn):not(.logout-btn):hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
}
.submit-btn:disabled,
button:disabled {
    background-color: var(--text-light);
    cursor: not-allowed;
    transform: none;
}

/* --- Form Elements --- */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-dark);
    font-size: 0.95rem;
}

input, select, textarea {
    width: calc(100% - 24px);
    padding: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Prompt', sans-serif;
    font-size: 1rem;
    color: var(--text-dark);
    background-color: var(--bg-white);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(77, 182, 172, 0.25);
    outline: none;
}

.read-only {
    background-color: var(--bg-light);
    cursor: not-allowed;
}

.inline-fields {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}
.inline-fields label {
    margin-bottom: 0;
    flex-shrink: 0;
}
.inline-fields input, .inline-fields select {
    margin-bottom: 0;
    flex-grow: 1;
}
.inline-fields select {
    width: auto;
}

/* --- Search Input --- */
.filter-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

#patientSearch {
    flex: 2;
    min-width: 200px;
    margin-bottom: 0;
}

#therapistFilter {
    flex: 1;
    min-width: 150px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Prompt', sans-serif;
    font-size: 1rem;
    color: var(--text-dark);
    background-color: var(--bg-white);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    margin-bottom: 0;
    cursor: pointer;
}

#therapistFilter:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(77, 182, 172, 0.25);
    outline: none;
}

/* --- Table Styles --- */
.table-scroll-container {
    overflow-x: auto;
    flex-grow: 1;
    max-height: unset;
    overflow-y: auto;
}

#todayPatientsTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.95rem;
    min-width: 800px;
}

#todayPatientsTable th,
#todayPatientsTable td {
    border: 1px solid var(--border-color);
    padding: 14px 18px;
    text-align: left;
    white-space: nowrap;
}

#todayPatientsTable th {
    background-color: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
    white-space: nowrap;
}

#todayPatientsTable tbody tr:nth-child(even) {
    background-color: var(--bg-light);
}

#todayPatientsTable tbody tr:hover {
    background-color: #EAF7F6;
}

#todayPatientsTable th:nth-child(6),
#todayPatientsTable td:nth-child(6) {
    white-space: normal;
    word-wrap: break-word;
    max-width: 200px;
}

/* เพิ่ม Style สำหรับคอลัมน์ "หัตถการ" (ลำดับที่ 7) */
#todayPatientsTable th:nth-child(7),
#todayPatientsTable td:nth-child(7) {
    white-space: normal;
    word-wrap: break-word;
    max-width: 150px; /* สามารถปรับความกว้างได้ตามความเหมาะสม */
}


#todayPatientsTable td:last-child,
#todayPatientsTable th:last-child {
    text-align: center; /* จัดปุ่มให้อยู่กลางคอลัมน์ */
}

.edit-row-btn {
    background-color: transparent;
    border: 1px solid var(--text-light);
    color: var(--text-medium);
    
    padding: 5px 12px;
    font-size: 0.8rem;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    
    transition: all 0.2s ease-in-out;
}

.edit-row-btn:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-dark);
    transform: translateY(-1px);
}

/* --- Modal Styles --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--bg-white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    position: relative;
    max-width: 800px; 
    width: 90%;
    box-shadow: var(--box-shadow-medium);
    animation: fadeIn 0.3s ease-out;
    max-height: 95vh;
    overflow-y: auto;
}

.close-button {
    color: var(--text-medium);
    font-size: 2rem;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close-button:hover,
.close-button:focus {
    color: var(--error-color);
}

/* --- Form Grid in Modal --- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem; 
    margin-top: 1.2rem;
}

.modal-content h2 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
}

.form-grid .grid-section h3 {
    margin-bottom: 0.6rem;
    color: var(--primary-dark);
    font-size: 1.05rem;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 0.2rem;
}

/* --- Adjustments for Form Elements inside Modal --- */
.modal-content label {
    font-size: 0.88rem;
    margin-bottom: 0.2rem;
}

.modal-content input, .modal-content select, .modal-content textarea {
    width: calc(100% - 24px);
    padding: 8px;
    margin-bottom: 0.6rem;
    font-size: 0.88rem;
    border-radius: 6px; 
    box-sizing: border-box;
}

.modal-content input:focus, .modal-content select:focus, .modal-content textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(77, 182, 172, 0.25);
    outline: none;
}

.modal-content .inline-fields {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
    align-items: center;
}

.modal-content .inline-fields label {
    margin-bottom: 0; 
}

/* ปุ่มภายในฟอร์ม */
.modal-content .submit-btn {
    padding: 0.6rem 1.1rem;
    font-size: 0.9rem;
    gap: 0.3rem;
    margin-top: 0.6rem;
}


/* --- Message Styles --- */
.message {
    font-size: 0.82rem;
    margin-top: -0.3rem;
    margin-bottom: 0.6rem;
    padding: 0.3rem 0.5rem;
    border-radius: 5px;
    background-color: transparent;
    color: var(--text-medium);
    display: block;
}

.message.error {
    color: var(--error-color);
    background-color: rgba(220, 53, 69, 0.1);
    border: 1px solid var(--error-color);
}

.message.success {
    color: var(--success-color);
    background-color: rgba(40, 167, 69, 0.1);
    border: 1px solid var(--success-color);
}

.message.info {
    color: var(--info-color);
    background-color: rgba(23, 162, 184, 0.1);
    border: 1px solid var(--info-color);
}

.message.warning {
    color: var(--warning-color);
    background-color: rgba(255, 193, 7, 0.1);
    border: 1px solid var(--warning-color);
}

/* --- Custom Notifications --- */
#notificationContainer {
    position: fixed;
    top: 95px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    background-color: var(--bg-white);
    color: var(--text-dark);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-medium);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 250px;
    max-width: 350px;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.notification.success {
    border-left: 5px solid var(--success-color);
    background-color: var(--success-color);
    color: var(--bg-white);
}
.notification.success i { color: var(--bg-white); }

.notification.error {
    border-left: 5px solid var(--error-color);
    background-color: var(--error-color);
    color: var(--bg-white);
}
.notification.error i { color: var(--bg-white); }

.notification.info {
    border-left: 5px solid var(--info-color);
    background-color: var(--info-color);
    color: var(--bg-white);
}
.notification.info i { color: var(--bg-white); }

.notification.warning {
    border-left: 5px solid var(--warning-color);
    background-color: var(--warning-color);
    color: var(--text-dark);
}
.notification.warning i { color: var(--text-dark); }

.notification i {
    font-size: 1.2rem;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* --- Media Queries for Responsiveness --- */

/* For Desktops and larger tablets (min-width: 992px) */
@media (min-width: 992px) {
    .form-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* For Tablets (landscape) and smaller desktops (min-width: 768px and max-width: 991px) */
@media (min-width: 768px) and (max-width: 991px) {
    .header { padding: 1rem 1.5rem; flex-wrap: wrap; justify-content: space-between; }
    .header-brand-name { flex-grow: 1; align-items: flex-start; margin-bottom: 0; }
    .system-title { font-size: 1.4rem; margin-bottom: 0.1rem; }
    .system-subtitle { font-size: 0.8rem; }
    .header-right { width: auto; justify-content: flex-end; margin-top: 0; white-space: nowrap; gap: 1rem; }
    .current-date { padding: 0.3rem 0; font-size: 0.9rem; text-align: right; }
    .add-new-patient-top-btn { padding: 0.7rem 1.2rem; font-size: 0.9rem; max-width: none; }
    body { padding-top: 70px; }
    #notificationContainer { top: 80px; }
    .header::after { height: 2px; }
    .page-container { flex-direction: column; padding: 1.5rem; gap: 1.5rem; }
    .sidebar { width: 100%; order: 1; }
    .dashboard-overview { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 1.5rem; }
    .metric-item { flex: 1 1 calc(33% - 1.5rem); min-width: 150px; max-width: 250px; }
    .main-content-wrapper { order: 2; }
    .today-patients-section { padding: 1.5rem; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .modal-content { padding: 1.5rem; }
    .modal-content h2 { font-size: 1.35rem; margin-bottom: 0.8rem; }
    .form-grid .grid-section h3 { font-size: 1rem; margin-bottom: 0.5rem; padding-bottom: 0.2rem; }
    label { font-size: 0.85rem; margin-bottom: 0.15rem; }
    .modal-content input, .modal-content select, .modal-content textarea { padding: 7px; font-size: 0.85rem; margin-bottom: 0.5rem; }
    .modal-content .inline-fields { gap: 0.5rem; margin-bottom: 0.5rem; }
    .modal-content .submit-btn { padding: 0.55rem 1rem; font-size: 0.88rem; margin-top: 0.5rem; }
    .message { font-size: 0.8rem; margin-top: -0.2rem; margin-bottom: 0.5rem; padding: 0.25rem 0.4rem; }
}

/* For Mobile Devices (max-width: 767px) */
@media (max-width: 767px) {
    .header { flex-direction: row; align-items: center; justify-content: space-between; padding: 0.8rem 1rem; height: auto; padding-bottom: 0.8rem; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15); }
    .header-brand-name { width: auto; text-align: left; margin-bottom: 0; max-width: 60%; }
    .system-title { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.1rem; }
    .system-subtitle { font-size: 0.7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .header-right { flex-direction: column; width: auto; margin-top: 0; gap: 0.3rem; align-items: flex-end; text-align: right; }
    .current-date { font-size: 0.75rem; padding: 0; text-align: right; margin-bottom: 0; }
    .add-new-patient-top-btn { width: auto; font-size: 0.7rem; padding: 0.4rem 0.7rem; border-radius: 6px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); white-space: nowrap; }
    .add-new-patient-top-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2); }
    body { padding-top: 85px; }
    #notificationContainer { top: 95px; right: 10px; left: 10px; align-items: center; }
    .notification { min-width: unset; width: 100%; padding: 0.8rem 1rem; box-sizing: border-box; }
    .header::after { height: 1px; }
    .page-container { flex-direction: column; padding: 1rem; gap: 1rem; }
    .sidebar { width: 100%; order: 1; }
    .dashboard-overview { padding: 1rem; flex-direction: column; gap: 0.8rem; }
    .dashboard-overview h2 { font-size: 1.3rem; margin-bottom: 0.8rem; }
    .metric-item { flex-basis: auto; max-width: 100%; padding: 0.8rem; }
    .metric-item p { font-size: 1.6rem; }
    .main-content-wrapper { order: 2; }
    .today-patients-section { padding: 1rem; }
    .today-patients-section h2 { font-size: 1.4rem; margin-bottom: 1rem; }
    .filter-controls { flex-direction: column; gap: 0.8rem; margin-bottom: 1rem; align-items: stretch; }
    #patientSearch, #therapistFilter { min-width: unset; width: 100%; margin-bottom: 0; }
    #todayPatientsTable { font-size: 0.85rem; min-width: 700px; }
    #todayPatientsTable th, #todayPatientsTable td { padding: 10px 12px; }
    #todayPatientsTable th:nth-child(6), #todayPatientsTable td:nth-child(6) { max-width: 150px; }
    #todayPatientsTable th:nth-child(7), #todayPatientsTable td:nth-child(7) { max-width: 150px; }
    .modal-content { width: 95%; padding: 1.2rem 0.8rem; }
    .close-button { font-size: 1.6rem; top: 8px; right: 12px; }
    .form-grid { grid-template-columns: 1fr; gap: 0.8rem; }
    .form-grid .grid-section h3 { font-size: 1rem; padding-bottom: 0.2rem; margin-bottom: 0.5rem; }
    .modal-content input, .modal-content select, .modal-content textarea { width: calc(100% - 16px); padding: 7px; font-size: 0.85rem; margin-bottom: 0.5rem; }
    .modal-content .inline-fields { flex-direction: column; align-items: flex-start; gap: 0.2rem; }
    .modal-content .inline-fields label { flex-basis: 100%; margin-bottom: 0.2rem; }
    .modal-content .inline-fields input, .modal-content .inline-fields select { width: 100%; min-width: unset; box-sizing: border-box; }
    .modal-content .submit-btn { padding: 0.5rem 0.9rem; font-size: 0.85rem; margin-top: 0.5rem; }
    .message { font-size: 0.78rem; margin-top: -0.15rem; margin-bottom: 0.4rem; padding: 0.2rem 0.3rem; }
    .logout-btn { width: 38px; height: 38px; font-size: 1rem; border-width: 2px; } /* Adjust logout button for mobile */
}

@media (max-width: 375px) {
    .system-title { font-size: 1rem; }
    .system-subtitle { font-size: 0.65rem; }
    .add-new-patient-top-btn { font-size: 0.65rem; padding: 0.3rem 0.5rem; }
    .current-date { font-size: 0.7rem; }
    body { padding-top: 80px; }
    #notificationContainer { top: 90px; }
    .modal-content { padding: 1rem 0.6rem; }
    .modal-content h2 { font-size: 1.2rem; margin-bottom: 0.7rem; }
    .form-grid .grid-section h3 { font-size: 0.95rem; margin-bottom: 0.4rem; }
    label { font-size: 0.82rem; margin-bottom: 0.1rem; }
    .modal-content input, .modal-content select, .modal-content textarea { padding: 6px; font-size: 0.82rem; margin-bottom: 0.4rem; }
    .modal-content .inline-fields { gap: 0.4rem; margin-bottom: 0.4rem; }
    .modal-content .submit-btn { padding: 0.4rem 0.7rem; font-size: 0.8rem; margin-top: 0.4rem; }
    .message { font-size: 0.75rem; margin-top: -0.1rem; margin-bottom: 0.3rem; padding: 0.15rem 0.25rem; }
}

/* --- NEW: Confirmation Modal Styles --- */
#confirmModal { display: none; position: fixed; z-index: 1001; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.7); align-items: center; justify-content: center; }
#confirmModal.show { display: flex; }
#confirmModal .modal-content { max-width: 600px; padding: 2rem; text-align: center; animation: fadeIn 0.3s ease-out; }
#confirmModal h2 { color: var(--primary-dark); font-size: 1.8rem; margin-bottom: 1.5rem; display: flex; align-items: center; justify-content: center; gap: 0.8rem; }
#confirmModal h2 i { color: var(--primary-color); font-size: 2rem; }
.confirm-details { text-align: left; margin-bottom: 2rem; background-color: var(--primary-light); padding: 1.5rem; border-radius: var(--border-radius); box-shadow: var(--box-shadow-light); border: 1px solid var(--border-color); max-height: 50vh; overflow-y: auto; }
.confirm-details h3 { font-size: 1.2rem; color: var(--primary-dark); margin-top: 1rem; margin-bottom: 0.8rem; display: flex; align-items: center; gap: 0.6rem; border-bottom: 1px dashed var(--border-color); padding-bottom: 0.5rem; }
.confirm-details h3:first-of-type { margin-top: 0; }
.confirm-details h3 i { color: var(--text-medium); font-size: 1.1rem; }
.confirm-details p { margin-bottom: 0.5rem; font-size: 0.95rem; color: var(--text-dark); line-height: 1.5; padding-left: 0.5rem; }
.confirm-details p strong { color: var(--primary-dark); min-width: 120px; display: inline-block; }
.modal-actions { display: flex; justify-content: center; gap: 1.5rem; margin-top: 2rem; }
.cancel-btn { background-color: var(--text-medium); color: var(--bg-white); padding: 0.8rem 1.8rem; border: none; border-radius: 8px; cursor: pointer; font-size: 1rem; font-weight: 600; transition: background-color 0.3s ease, transform 0.2s ease; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
.cancel-btn:hover { background-color: #8C9CAE; transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15); }
.confirm-btn { background-color: var(--success-color); color: var(--bg-white); padding: 0.8rem 1.8rem; border: none; border-radius: 8px; cursor: pointer; font-size: 1rem; font-weight: 600; transition: background-color 0.3s ease, transform 0.2s ease; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
.confirm-btn:hover { background-color: #218838; transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15); }

@media (max-width: 767px) {
    #confirmModal .modal-content { max-width: 95%; padding: 1.5rem 1rem; }
    #confirmModal h2 { font-size: 1.5rem; margin-bottom: 1rem; gap: 0.5rem; }
    #confirmModal h2 i { font-size: 1.8rem; }
    .confirm-details { padding: 1rem; margin-bottom: 1.5rem; }
    .confirm-details h3 { font-size: 1.1rem; margin-bottom: 0.6rem; gap: 0.4rem; }
    .confirm-details p { font-size: 0.9rem; margin-bottom: 0.4rem; padding-left: 0.3rem; }
    .modal-actions { flex-direction: column; gap: 0.8rem; margin-top: 1.5rem; }
    .cancel-btn, .confirm-btn { width: 100%; padding: 0.7rem 1rem; font-size: 0.95rem; }
}

@media (max-width: 375px) {
    #confirmModal .modal-content { padding: 1rem 0.8rem; }
    #confirmModal h2 { font-size: 1.3rem; gap: 0.4rem; }
    #confirmModal h2 i { font-size: 1.6rem; }
    .confirm-details h3 { font-size: 1rem; margin-bottom: 0.5rem; }
    .confirm-details p { font-size: 0.85rem; }
    .cancel-btn, .confirm-btn { padding: 0.6rem 0.8rem; font-size: 0.9rem; }
}

/* --- NEW: Login Overlay Styles --- */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(248, 252, 252, 0.95); /* Semi-transparent background */
  backdrop-filter: blur(5px); /* ทำให้พื้นหลังเบลอ */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20000; /* ต้องมีค่าสูงที่สุด */
  padding: 1rem;
  box-sizing: border-box;
}

.login-container {
  background-color: white;
  padding: 2rem 2.5rem;
  border-radius: var(--border-radius-large);
  box-shadow: var(--box-shadow-medium);
  text-align: center;
  max-width: 400px;
  width: 100%;
  border-top: 5px solid var(--primary-color);
  animation: fadeIn 0.4s ease-out;
}

.login-container h2 {
  color: var(--primary-dark);
  margin-bottom: 0.5rem;
  font-size: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.8rem;
}

.login-container p {
  color: #6B7A8F;
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.login-container .input-group {
  position: relative;
  margin-bottom: 1.5rem;
}

.login-container .input-group i {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #AAB7BF;
}

.login-container #passwordInput {
    width: 100%;
    padding: 12px 12px 12px 45px;
    margin: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: 'Prompt', sans-serif;
    font-size: 1rem;
    box-sizing: border-box;
}
.login-container #passwordInput:focus {
   border-color: var(--primary-color);
   box-shadow: 0 0 0 3px rgba(77, 182, 172, 0.25);
   outline: none;
}

.login-container .login-btn {
  width: 100%;
  padding: 0.8rem 1.5rem;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: background-color 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0; /* Override default button margin */
}

.login-container .login-btn:hover {
  background-color: var(--primary-dark);
}

.login-container .login-btn:disabled {
    background-color: #AAB7BF;
    cursor: not-allowed;
}

.login-message {
  color: var(--error-color);
  margin-top: 1rem;
  font-weight: 500;
  min-height: 20px; /* จองพื้นที่ไว้ */
  display: block;
}


/* --- Styles for Section Heading with Action Button --- */
.section-heading-with-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem; /* ระยะห่างเท่ากับ h3 เดิม */
}
.section-heading-with-action h3 {
    margin-bottom: 0; /* ลบ margin จาก h3 เมื่ออยู่ใน flexbox */
}

/* --- Ghost Button Style for Edit Button --- */
.edit-info-btn {
    padding: 4px 10px;
    font-size: 0.75rem; /* ขนาดตัวอักษรเล็กลง */
    font-weight: 500; /* ความหนาตัวอักษร */
    border-radius: 6px; /* ขอบมนเล็กน้อย */
    
    background-color: transparent; /* << ทำให้พื้นหลังโปร่ง */
    border: 1px solid var(--text-light); /* << ใช้สีเทาอ่อน ไม่แย่งสายตา */
    color: var(--text-medium); /* << สีตัวอักษรเป็นสีเทา */
    
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease-in-out;
    margin: 0;
}

/* --- Hover State: เมื่อเอาเมาส์มาวาง --- */
.edit-info-btn:hover {
    background-color: var(--primary-light); /* พื้นหลังเป็นสีเขียวอ่อนๆ */
    border-color: var(--primary-color); /* ขอบเป็นสีเขียวหลัก */
    color: var(--primary-dark); /* ตัวอักษรเป็นสีเขียวเข้ม */
    transform: translateY(-1px); /* ขยับขึ้นเล็กน้อย */
}

/* --- Unlocked State: เมื่อกดปุ่มแล้ว --- */
.edit-info-btn.unlocked {
    background-color: var(--primary-light); /* พื้นหลังเป็นสีเขียวอ่อน */
    border-color: var(--success-color); /* ขอบเป็นสีเขียว success */
    color: var(--success-color); /* ตัวอักษรเป็นสีเขียว success */
}
.edit-info-btn.unlocked:hover {
    transform: none; /* เมื่อปลดล็อคแล้ว ไม่ต้องขยับตอน hover */
}

/* --- Responsive for mobile --- */
@media (max-width: 767px) {
    .edit-info-btn span {
        display: none; /* บนมือถือ ซ่อนข้อความ "แก้ไข" เหลือแต่ไอคอน */
    }
    .edit-info-btn {
        padding: 5px 7px; /* ปรับขนาดให้เป็นสี่เหลี่ยมจัตุรัสมากขึ้น */
    }
}


/* ===== START: NEW STYLES FOR EXPORT TOGGLE ===== */

/* --- 1. Toggle Export Button Style (Sidebar) --- */
.toggle-export-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--primary-dark);
    background-color: transparent;
    border: 1px solid var(--primary-light);
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    transition: all 0.2s ease-in-out;
}

.toggle-export-btn:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

/* --- 2. Export Section Style (Sidebar) & Animation --- */
.export-section {
    background-color: var(--bg-white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-light);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    /* --- Styles for smooth transition --- */
    transition: opacity 0.4s ease, transform 0.4s ease, margin-top 0.4s ease;
    transform-origin: top;
    transform: scaleY(0.95);
}

.export-section h2 {
    color: var(--primary-dark);
    font-size: 1.4rem;
    margin: 0;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
}

.export-controls {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.export-controls label {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 0;
}

.export-controls select {
    width: 100%;
    margin-bottom: 0;
    cursor: pointer;
}

.export-btn {
    margin-top: 0.5rem;
    width: 100%;
    background-color: var(--success-color);
    color: white;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.export-btn:hover {
    background-color: #218838; /* Darker green */
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-light);
}

/* --- Responsive Adjustments --- */
@media (max-width: 767px) {
    .export-section {
      margin-top: 1rem;
    }
}

/* ===== END: NEW STYLES FOR EXPORT TOGGLE ===== */