@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #0A4D68;
    --secondary: #088395;
    --accent: #05BFDB;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f1c40f;
    --bg-main: #F1F5F9;
    /* Softer, high-end background */
    --card-white: #ffffff;
    --text-main: #1D2D35;
    --text-muted: #6B7C84;
    --radius-xl: 40px;
    /* For main containers */
    --radius-lg: 32px;
    /* For cards */
    --radius-md: 20px;
    /* For buttons/inputs */
    --shadow-soft: 0 10px 40px rgba(10, 77, 104, 0.05);
    --shadow-float: 0 20px 60px rgba(10, 77, 104, 0.08);
    --bg-secondary: #F8FAFC;
    --border-light: #E2E8F0;
    --bg-hover: #EDF2F7;
    --card-shadow: rgba(10, 77, 104, 0.05);
    --card-shadow-float: rgba(10, 77, 104, 0.08);
}

[data-theme="dark"] {
    --primary: #05BFDB;
    --secondary: #088395;
    --accent: #05BFDB;
    --bg-main: #0F1419;
    --bg-secondary: #1A2332;
    --card-white: #1E2A3A;
    --text-main: #E8EDF2;
    --text-muted: #8899A6;
    --border-light: #2E3D4F;
    --bg-hover: #253040;
    --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.3);
    --shadow-float: 0 20px 60px rgba(0, 0, 0, 0.4);
    --card-shadow: rgba(0, 0, 0, 0.3);
    --card-shadow-float: rgba(0, 0, 0, 0.4);
    --success: #34D399;
    --danger: #F87171;
    --warning: #FBBF24;
}

[data-theme="dark"] body {
    background: var(--bg-main);
    color: var(--text-main);
}

[data-theme="dark"] .card-premium {
    background: var(--card-white);
    box-shadow: var(--shadow-soft);
}

[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--bg-secondary) !important;
    color: var(--text-main) !important;
    border-color: var(--border-light) !important;
}

[data-theme="dark"] .bottom-nav {
    background: rgba(30, 42, 58, 0.85);
}

[data-theme="dark"] .glass {
    background: rgba(30, 42, 58, 0.7);
}

/* Theme toggle button */
.theme-toggle-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.theme-toggle-btn:hover {
    background: var(--bg-hover, rgba(0,0,0,0.05));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Noto Sans Thai', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

a {
    text-decoration: none;
    color: inherit;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Base Layout */
.app-container {
    max-width: 500px;
    /* Mobile focused container */
    margin: 0 auto;
    width: 100%;
    padding: 24px;
    padding-bottom: 120px;
    /* space for floating nav */
}

/* Premium Navigation Refined */
.bottom-nav-container {
    position: fixed;
    bottom: 32px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 460px;
    margin: 0 auto;
    z-index: 1000;
    pointer-events: none;
    /* Let clicks pass through to empty space */
}

.bottom-nav-pill {
    background: rgba(10, 77, 104, 0.5);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    height: 72px;
    border-radius: 36px;
    display: flex;
    padding: 0 12px;
    align-items: center;
    gap: 8px;
    box-shadow: 0 15px 45px rgba(10, 77, 104, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: auto;
    /* Enable clicks on the pill itself */
}

.bottom-nav-action {
    background: var(--card-white);
    width: 72px;
    height: 72px;
    border-radius: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 15px 45px rgba(10, 77, 104, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: var(--primary);
    text-decoration: none;
    font-size: 22px;
    pointer-events: auto;
    transition: all 0.3s ease;
}

.bottom-nav-action:active {
    transform: scale(0.9);
}

.nav-item {
    width: 60px;
    height: 52px;
    border-radius: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-size: 20px;
}

.nav-item span {
    display: none;
}

/* Hide text for this specific style */

.nav-item.active {
    background: var(--card-white);
    color: var(--primary);
    box-shadow: 0 4px 12px var(--card-shadow);
}

/* Header Refined */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.user-profile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.avatar-circle {
    width: 50px; /* Slightly smaller for mobile */
    height: 50px;
    border-radius: 25px;
    background: var(--card-white);
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid var(--card-white);
    flex-shrink: 0; 
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-greeting {
    flex: 1;
    min-width: 0;
    padding-right: 12px;
    overflow: hidden;
}

.header-greeting h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
}

.header-greeting p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-actions {
    flex-shrink: 0; /* Protect the logout button from being squeezed */
}

.noti-btn {
    width: 44px; /* Slightly smaller for mobile */
    height: 44px;
    border-radius: 22px;
    background: var(--card-white);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-soft);
    color: var(--text-main);
}

/* Floating Card style - Enhanced Glassmorphism */
.card-premium {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: block;
}

.card-premium:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-float);
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(10, 77, 104, 0.2);
}

/* Search Bar (like example) - Glass */
.search-container {
    background: var(--bg-secondary);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 24px;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 32px;
    border: 1px solid var(--border-light);
}

.search-container input {
    border: none;
    background: none;
    outline: none;
    width: 100%;
    font-size: 0.95rem;
    color: var(--text-main);
}

/* Category Pill tags */
.category-pills {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 24px;
    scrollbar-width: none;
}

.category-pills::-webkit-scrollbar {
    display: none;
}

.pill {
    padding: 10px 20px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: var(--shadow-soft);
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.pill.active {
    background: var(--primary);
    color: white;
}

/* Buttons and Inputs Overwrite */
input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    color: var(--text-main);
    width: 100%;
    outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    background: var(--card-white);
}

.btn-primary {
    background: var(--primary);
    border-radius: var(--radius-md);
    padding: 16px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(10, 77, 104, 0.2);
    text-decoration: none;
    display: block;
    text-align: center;
}

/* Progress / Steps (Patient Dashboard focus) */
.health-status-card {
    background: var(--primary);
    color: white;
    padding: 32px;
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
}

/* Animations */
.animate-slide-up {
    animation: slideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Desktop Responsiveness */
@media (min-width: 768px) {
    .app-container {
        max-width: 900px;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 77, 104, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--card-white);
    width: 100%;
    max-width: 480px;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-float);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    background: none;
    border: none;
}

.modal-header {
    margin-bottom: 24px;
}

.modal-header h3 {
    color: var(--primary);
    font-size: 1.25rem;
    font-weight: 700;
}

/* PWA Install Banner - Premium Glass */
.install-banner {
    position: fixed;
    bottom: 24px;
    left: 20px;
    right: 20px;
    max-width: 500px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 20px;
    border-radius: 24px;
    box-shadow: 0 10px 40px rgba(10, 77, 104, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.5);
    display: none; /* Controlled by JS */
    align-items: center;
    gap: 16px;
    z-index: 9999;
    animation: slideUpLarge 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUpLarge {
    from { transform: translateY(100px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.install-banner .logo-mini {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.install-banner .content {
    flex: 1;
}

.install-banner .content h4 {
    color: var(--primary);
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0 0 2px 0;
}

.install-banner .content p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.install-banner .actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.install-banner .btn-install {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.install-banner .btn-install:active {
    transform: scale(0.95);
}

.install-banner .btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    text-decoration: underline;
}

/* ============================================
   Department Management - Mobile Responsive
   ============================================ */

/* Form container - ensure overflow visible */
.dept-form-card {
    overflow: visible !important;
    height: auto !important;
}

/* Main form grid */
.dept-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    row-gap: 24px;
    align-items: end;
}

/* Form group spacing */
.dept-form .form-group {
    margin-bottom: 0;
}

/* Ensure all inputs respect container width */
.dept-form input,
.dept-form select {
    max-width: 100%;
    box-sizing: border-box;
}

/* Work days checkboxes - compact layout */
.work-days-group {
    grid-column: span 2;
}

.work-days-checkboxes {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.work-day-label {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-main);
    padding: 4px 8px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-light);
    transition: all 0.2s ease;
}

.work-day-label:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.work-day-label input[type="checkbox"] {
    width: 16px !important;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
}

/* Form submit row */
.form-submit-row {
    grid-column: span 2;
}

.form-submit-row .btn-primary {
    width: 100%;
}

/* Edit Modal Styles */
.dept-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.dept-modal-content {
    width: 90%;
    max-width: 450px;
    background: var(--card-white);
    max-height: 85vh;
    overflow-y: auto;
    margin: auto;
}

.dept-modal-content form.dept-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    row-gap: 24px;
    align-items: end;
}

.dept-modal-content form:not(.dept-form) {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dept-modal-content .form-group {
    margin-bottom: 0;
}

.dept-modal-content input,
.dept-modal-content select {
    max-width: 100%;
    box-sizing: border-box;
}

/* Modal actions - horizontal row layout */
.modal-actions {
    display: flex;
    flex-direction: row;
    gap: 12px;
    margin-top: 10px;
    justify-content: flex-start;
}

.modal-actions .btn-primary {
    flex: 1;
}

.modal-actions .btn-cancel {
    background: var(--bg-secondary);
    color: var(--text-main);
    box-shadow: none;
}

/* Mobile Responsive - iPhone SE and small screens */
@media (max-width: 400px) {
    .dept-form {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .dept-form .form-group {
        grid-column: span 1 !important;
    }
    
    .form-submit-row {
        grid-column: span 1;
    }
    
    .work-days-checkboxes {
        gap: 4px;
    }
    
    .work-day-label {
        font-size: 0.75rem;
        padding: 3px 6px;
    }
    
    .work-day-label input[type="checkbox"] {
        width: 14px !important;
        height: 14px;
    }
    
    .dept-modal-content {
        width: 95%;
        max-height: 80vh;
        padding: 20px;
    }
}

/* Extra small screens */
@media (max-width: 320px) {
    .work-day-label {
        font-size: 0.7rem;
        padding: 2px 5px;
    }
}