:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #ec4899;
    --bg-main: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.8);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --glass: rgba(255, 255, 255, 0.2);
    --glass-border: rgba(255, 255, 255, 0.3);
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Sarabun', sans-serif;
}

body {
    background: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 100%);
    min-height: 100vh;
    color: var(--text-main);
    overflow-x: hidden;
}

.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.btn {
    padding: 12px 24px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: scale(1.02);
}

.container {
    max-width: 98%;
    margin: 0 auto;
    padding: 1rem 2rem;
}

.navbar {
    display: none;
    /* Hide top navbar as we are switching to sidebar */
}

.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid var(--glass-border);
    position: fixed;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile browsers */
    padding: 2rem 1.5rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    /* iOS safe area */
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    /* sidebar itself doesn't scroll */
}

.main-content {
    flex: 1;
    margin-left: 280px;
    min-height: 100vh;
}

.sidebar-logo {
    margin-bottom: 2.5rem;
    padding: 0 0.5rem;
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    overflow-y: auto;
    /* เลื่อนเมนูได้เมื่อล้น */
    overflow-x: hidden;
    min-height: 0;
    /* จำเป็นสำหรับ flex child ที่มี overflow */
    margin-right: -0.5rem;
    /* ซ่อน scrollbar เล็กน้อย */
    padding-right: 0.5rem;
    -webkit-overflow-scrolling: touch;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background: rgba(99, 102, 241, 0.05);
    color: var(--primary);
}

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

.sidebar-footer {
    margin-top: 0;
    /* ไม่ใช้ auto เพราะ sidebar-menu ขึ้น flex:1 แล้ว */
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
    /* ป้องกัน footer ถูกบีบ */
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.5rem;
    padding: 0 0.5rem;
}

.sidebar-user-info {
    flex: 1;
}

.sidebar-user-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

h1,
h2,
h3 {
    color: var(--text-main);
    font-weight: 800;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.animate-fade-in {
    animation: fadeIn 0.6s ease-out forwards;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: white;
    outline: none;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--primary);
}

/* Password Visibility Toggle */
.password-wrapper {
    position: relative;
}

.password-toggle {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #94a3b8;
    transition: color 0.3s;
    font-size: 0.9rem;
    z-index: 10;
}

/* Mobile Top Bar Styles */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 1060;
    /* Above sidebar */
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}

.mobile-toggle-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 10px;
    display: flex;
    align-items: center;
}

.mobile-brand {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.sidebar-close-btn {
    display: none;
    /* Hidden by default, shown in mobile media query */
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
}

.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Tablet & Mobile Breakpoints */
@media (max-width: 1024px) {
    .mobile-header {
        display: flex;
    }

    .sidebar-close-btn {
        display: block !important;
    }

    .sidebar {
        transform: translateX(-100%) !important;
        transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
        z-index: 1070;
        width: 300px;
        background: white !important;
        box-shadow: none;
        border-right: none;
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        height: 100dvh;
    }

    .sidebar.active {
        transform: translateX(0) !important;
        box-shadow: 15px 0 30px rgba(0, 0, 0, 0.15);
    }

    /* ล็อค body เมื่อ sidebar เปิด ป้องกันเลื่อนพื้นหลัง */
    body.sidebar-open {
        overflow: hidden !important;
        touch-action: none;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 75px !important;
    }

    .container {
        padding: 1rem !important;
        max-width: 100% !important;
    }

    /* Grid single column for mobile */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
    }

    /* Responsive tables */
    .glass-card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 650px;
    }

    /* Input zoom fix */
    input,
    select,
    textarea,
    button {
        font-size: 16px !important;
    }
}