/* ============================================================
   style.css — ระบบรายงานอุบัติการณ์ Refer
   สไตล์สำหรับทั้งระบบ (sidebar, login, components)
   ============================================================ */

/* ==================== GLOBAL RESET ==================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Sarabun', sans-serif;
    background-color: #f1f5f9;
    color: #1e293b;
    overflow-x: hidden;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: 260px;
    min-height: 100vh;
    background: linear-gradient(180deg, #064e3b 0%, #047857 50%, #059669 100%);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: width 0.3s ease, transform 0.3s ease;
    box-shadow: 2px 0 20px rgba(0,0,0,0.1);
}
.sidebar.collapsed { width: 70px; }

/* Logo area */
.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
}
.sidebar-header .logo-icon {
    width: 38px; height: 38px;
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-header .logo-icon i { font-size: 1.3rem; }
.sidebar-header .logo-text {
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s;
}
.sidebar-header .logo-text .title {
    font-weight: 700;
    font-size: 0.95rem;
}
.sidebar-header .logo-text .sub {
    font-size: 0.7rem;
    opacity: 0.7;
    font-weight: 400;
}
.sidebar.collapsed .logo-text,
.sidebar.collapsed .menu-label,
.sidebar.collapsed .user-details { opacity: 0; width: 0; overflow: hidden; }

/* Menu */
.sidebar-menu {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}
.menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
    border-left: 3px solid transparent;
    position: relative;
}
.menu-item:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}
.menu-item.active {
    background: rgba(255,255,255,0.12);
    color: white;
    border-left-color: #6ee7b7;
}
.menu-item i {
    width: 24px;
    text-align: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.menu-label {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    transition: opacity 0.2s;
}

/* User section at bottom */
.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}
.sidebar-user:hover { background: rgba(255,255,255,0.05); }
.sidebar-user .avatar {
    width: 36px; height: 36px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-user .user-details {
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s;
}
.sidebar-user .user-name { font-weight: 600; font-size: 0.85rem; }
.sidebar-user .user-hosp { font-size: 0.7rem; opacity: 0.7; }

/* ==================== MAIN WRAPPER ==================== */
.main-wrapper {
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}
.sidebar.collapsed + .main-wrapper,
.main-wrapper.sidebar-collapsed { margin-left: 70px; }

/* ==================== HEADER ==================== */
.app-header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.app-header .left-section {
    display: flex;
    align-items: center;
    gap: 16px;
}
.app-header .hamburger {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}
.app-header .hamburger:hover { background: #f1f5f9; color: #1e293b; }
.app-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #1e293b;
}
.app-header .user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    padding: 6px 14px 6px 10px;
    border-radius: 30px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s;
}
.app-header .user-badge:hover { background: #f1f5f9; }
.app-header .user-badge .avatar-sm {
    width: 32px; height: 32px;
    background: #d1fae5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #047857;
    font-weight: 700;
    font-size: 0.8rem;
}

/* ==================== LOGIN PAGE ==================== */
.bg-login-pattern {
    background-color: #f1f5f9;
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
}

/* ==================== LOADER ==================== */
.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #00b09b;
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 1s linear infinite;
    margin: auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-fadeIn { animation: fadeIn 0.3s ease-out; }

/* ==================== COMPONENT STYLES ==================== */
.card {
    background: white;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 10px 10px 0 0;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-body { padding: 20px; }

/* Table styles */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.data-table th {
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.data-table tbody tr:hover { background: #f8fafc; }

/* Status badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-teal { background: #d1fae5; color: #047857; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-purple { background: #f3e8ff; color: #7c3aed; }
.badge-gray { background: #f1f5f9; color: #64748b; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}
.btn-primary { background: #00b09b; color: white; }
.btn-primary:hover { background: #0d9488; transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,176,155,0.3); }
.btn-secondary { background: white; border: 1px solid #e2e8f0; color: #475569; }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 600; font-size: 0.85rem; color: #334155; margin-bottom: 4px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 8px 12px;
    border: 1px solid #cbd5e1; border-radius: 6px;
    font-size: 0.9rem; font-family: 'Sarabun', sans-serif;
    outline: none; transition: border-color 0.2s;
    background: white;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: #00b09b; box-shadow: 0 0 0 3px rgba(0,176,155,0.1); }

/* Stats cards */
.stat-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    display: flex;
    align-items: flex-start;
    gap: 16px;
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.4rem;
}
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.82rem; color: #64748b; margin-top: 4px; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    font-size: 0.85rem;
}
.pagination .page-info { color: #64748b; }
.pagination .page-buttons { display: flex; gap: 6px; }
.pagination .page-btn {
    padding: 6px 14px;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    color: #475569;
    transition: all 0.2s;
}
.pagination .page-btn:hover:not(:disabled) { background: #f1f5f9; border-color: #94a3b8; }
.pagination .page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}
.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 1280px;
    width: 100%;
    margin-top: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    overflow: hidden;
    animation: fadeIn 0.2s ease-out;
}
.modal-header {
    background: linear-gradient(135deg, #0d9488, #00b09b);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.modal-close { background: none; border: none; color: rgba(255,255,255,0.8); font-size: 1.4rem; cursor: pointer; }
.modal-close:hover { color: white; }
.modal-body { padding: 20px 24px; }

/* Empty state */
.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: #94a3b8;
}
.empty-state i { font-size: 3rem; color: #bfdbfe; margin-bottom: 12px; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-260px); }
    .sidebar.open { transform: translateX(0); width: 260px; }
    /* กัน collapsed มาทับตอนเปิดบนมือถือ */
    .sidebar.open .logo-text,
    .sidebar.open .menu-label,
    .sidebar.open .user-details { opacity: 1; width: auto; overflow: visible; }
    .main-wrapper { margin-left: 0 !important; }
    .sidebar-overlay {
        position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99;
        display: none;
    }
    .sidebar-overlay.show { display: block; }

    /* Header: หัวข้อยาวไม่ดันจอ */
    .app-header { padding: 10px 12px; gap: 8px; }
    .app-header .left-section { gap: 8px; min-width: 0; }
    .app-header h1 {
        font-size: 0.95rem;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .app-header .user-badge { padding: 4px 8px; flex-shrink: 0; }
    .app-header .user-badge .avatar-sm { width: 28px; height: 28px; }

    /* Modal เต็มจอมากขึ้น */
    .modal-overlay { padding: 12px 8px; }
    .modal-content { margin-top: 4px; border-radius: 12px; }
    .modal-body { padding: 14px; }
    .modal-header { padding: 12px 16px; }

    /* การ์ดสถิติ + pagination */
    .stat-card { padding: 14px; gap: 12px; }
    .stat-value { font-size: 1.4rem; }
    .pagination { flex-direction: column; gap: 8px; }
}

/* Print */
@media print {
    .sidebar, .app-header, .btn { display: none !important; }
    .main-wrapper { margin-left: 0 !important; }
}
