/* ================================================================
   Quality System — Design System CSS
   อ้างอิงจาก NEXT_PROJECT_DESIGN_SYSTEM.md
   ================================================================ */

/* --- CSS VARIABLES (§4 Design System) --- */
:root {
    /* 🔵 Brand Colors */
    --primary: #1367c8;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --secondary: #1367c8;

    /* 🔵 Accent Colors (Blue Premium) */
    --accent: #1367c8;
    --accent-light: #eff6ff;
    --accent-dark: #1d4ed8;

    /* 🔴 Semantic Colors */
    --success: #15803d;
    --warning: #b45309;
    --danger: #b91c1c;
    --info: #0ea5e9;

    /* ⚪ Background Colors */
    --bg-main: #f4f7fb;
    --bg-sidebar: var(--primary); /* สีพื้นหลังไซด์บาร์ (น้ำเงินแบรนด์หลัก) */
    --bg-surface: #ffffff;
    --bg-surface-2: #f8fafc;

    /* 🖤 Typography & Lines */
    --text-heading: #0f172a;
    --text-body: #334155;
    --text-muted: #64748b;
    --line: #e8edf3;
    --line-strong: #dbe3ec;

    /* 📐 Layout */
    --sidebar-width: 275px;
    --sidebar-collapsed-width: 72px;

    /* 👤 Shadows */
    --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --card-shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.08);
}

/* --- GLOBAL RESET --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

/* --- BEAUTIFUL SCROLLBARS --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Custom scrollbar for modals/tables */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* --- BODY --- */
body {
    font-family: 'Inter', 'Sarabun', sans-serif !important;
    background: var(--bg-main);
    color: var(--text-body);
    font-size: 14px;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Mono numbers for high-density readable data (§2 กฎข้อ 4) */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

/* ================================================================
   MAIN LAYOUT (§5.3 / SocialWork structure)
   ================================================================ */
.wrapper {
    display: flex;
    min-height: 100vh;
}

#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --- TOP NAVBAR --- */
.top-navbar {
    height: 68px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.top-navbar-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-heading);
}

.top-navbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- MAIN BODY (§5.3 condensed) --- */
.main-body {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
}

/* ================================================================
   SIDEBAR (§5.1 Premium Sidebar)
   ================================================================ */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #ffffff;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    transition: width 0.3s ease;
    display: flex;
    flex-direction: column;
    z-index: 100;
    flex-shrink: 0;
    overflow: hidden;
}

#sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Header */
.sidebar-header {
    height: 68px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    box-sizing: border-box;
}

.sidebar-header i {
    color: #ffffff !important;
    font-size: 22px;
    flex-shrink: 0;
}

.logo-text {
    font-weight: 800;
    font-size: 16px;
    color: #ffffff !important;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s;
    letter-spacing: 0.5px;
}

.logo-subtitle {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.65) !important;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    white-space: nowrap;
}

.collapsed .logo-text,
.collapsed .logo-subtitle {
    display: none;
}

/* Sidebar Menu */
.sidebar-menu {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sidebar-section-header {
    padding: 20px 20px 8px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5) !important;
    letter-spacing: 1.2px;
    font-weight: 700;
    text-transform: uppercase;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 8px;
}

.sidebar-menu .sidebar-section-header:first-of-type {
    border-top: none;
    margin-top: 0;
}

.collapsed .sidebar-section-header {
    display: block !important;
    padding: 16px 0 0 0 !important;
    text-indent: -9999px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin: 8px 12px 0;
    height: 1px;
    overflow: hidden;
}

/* Menu Items (§5.1) */
.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px 12px 20px;
    color: rgba(255, 255, 255, 0.8) !important;
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

.menu-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.7) !important;
    flex-shrink: 0;
}

/* เอฟเฟกต์ชี้โฮเวอร์ */
.menu-item:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
}
.menu-item:hover i {
    color: #ffffff !important;
}

/* เมื่อหน้าเมนูนั้นเปิดใช้งานอยู่ */
.menu-item.active {
    background: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
    border-left-color: #ffffff;
}
.menu-item.active i {
    color: #ffffff !important;
}

.menu-text {
    white-space: nowrap;
}

.collapsed .menu-text {
    display: none;
}

/* Sidebar Badge */
.menu-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 9999px;
    line-height: 1;
}

.collapsed .menu-badge {
    display: none;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: var(--bg-surface-2);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-footer-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.sidebar-footer-info {
    overflow: hidden;
}

.sidebar-footer-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-heading);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer-role {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 500;
}

.collapsed .sidebar-footer-info {
    display: none;
}

/* Toggle Sidebar Button (§5.1) */
.toggle-sidebar {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--accent) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-sidebar:hover {
    background: var(--bg-surface-2);
}

/* ================================================================
   PAGE HEADER (§5.2)
   ================================================================ */
.page-header {
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header-title h1 {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-heading);
    margin: 0;
}

.page-header-title p {
    color: var(--accent);
    margin-top: 2px;
    font-size: 13px;
    font-weight: 500;
}

/* ================================================================
   CARDS (§5.3)
   ================================================================ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    transition: box-shadow 0.2s ease-in-out;
    margin-bottom: 12px;
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

/* Fix icon glitch during card hover (SocialWork pattern) */
.card i {
    transform: translateZ(0) !important;
    backface-visibility: hidden !important;
    perspective: 1000px !important;
    display: inline-block !important;
}

/* ================================================================
   TABLES (SocialWork .standard-table pattern)
   ================================================================ */
.table-card {
    padding: 0 !important;
    overflow: hidden;
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--line);
    margin-bottom: 12px;
}

.table-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface-2);
}

.table-card-header h2,
.table-card-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-heading);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.standard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.standard-table thead tr {
    background: var(--bg-surface-2);
}

.standard-table th {
    padding: 12px 20px;
    text-align: left;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 2px solid var(--line-strong);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-surface-2);
}

.standard-table td {
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    color: var(--text-body);
    font-size: 13px;
}

.standard-table tr:last-child td {
    border-bottom: none;
}

.standard-table tr:hover td {
    background: var(--bg-surface-2);
}

/* ================================================================
   BUTTONS (§5 consistent button set)
   ================================================================ */
.btn-std {
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    outline: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(19, 103, 200, 0.2);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 8px rgba(19, 103, 200, 0.25);
}

.btn-success {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(19, 103, 200, 0.2);
}

.btn-success:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 8px rgba(19, 103, 200, 0.25);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #991b1b;
}

.btn-outline {
    background: var(--bg-surface);
    color: var(--text-body);
    border: 1px solid var(--line-strong);
}

.btn-outline:hover {
    background: var(--bg-surface-2);
    border-color: var(--text-muted);
}

.btn-ghost {
    background: none;
    color: var(--text-muted);
    padding: 6px 10px;
}

.btn-ghost:hover {
    background: var(--bg-surface-2);
    color: var(--text-heading);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-surface-2);
    color: var(--text-heading);
    border-color: var(--line-strong);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 8px;
}

/* ================================================================
   FORMS (§5.3 condensed)
   ================================================================ */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-body);
    background: var(--bg-surface-2);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    background: var(--bg-surface);
}

.form-input::placeholder {
    color: #94a3b8;
}

textarea.form-input {
    resize: vertical;
    min-height: 60px;
}

select.form-input {
    cursor: pointer;
}

/* ================================================================
   SEVERITY BADGES
   ================================================================ */
.severity-badge {
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.sev-low {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.sev-mid {
    background-color: #fffbeb;
    color: #92400e;
    border: 1px solid #fef3c7;
}

.sev-high {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.badge-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.badge-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.badge-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.badge-secondary {
    background: #e2e8f0;
    color: #334155;
    border: 1px solid #94a3b8;
}

.badge-pending-custom {
    background: #DBEAFE;
    color: #1E3A8A;
    border: 1px solid #BFDBFE;
}

.badge-reviewed-custom {
    background: #F4F4F5;
    color: #52525B;
    border: 1px solid #E4E4E7;
}

/* Custom Action Buttons in Incidents Table */
.btn-pending-action {
    background: #DBEAFE !important;
    color: #1E3A8A !important;
    border: 1px solid #BFDBFE !important;
    font-size: 11px !important;
    transition: all 0.2s ease-in-out !important;
}
.btn-pending-action:hover {
    background: #1E3A8A !important;
    color: #FFFFFF !important;
    border-color: #1E3A8A !important;
    box-shadow: 0 4px 6px -1px rgba(30, 58, 138, 0.2), 0 2px 4px -2px rgba(30, 58, 138, 0.2) !important;
}

.btn-reviewed-action {
    background: #F4F4F5 !important;
    color: #52525B !important;
    border: 1px solid #E4E4E7 !important;
    font-size: 11px !important;
    transition: all 0.2s ease-in-out !important;
}
.btn-reviewed-action:hover {
    background: #52525B !important;
    color: #FFFFFF !important;
    border-color: #52525B !important;
    box-shadow: 0 4px 6px -1px rgba(82, 82, 91, 0.2), 0 2px 4px -2px rgba(82, 82, 91, 0.2) !important;
}


/* ================================================================
   PULSE ALERT ANIMATION
   ================================================================ */
.pulse-alert {
    box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.7);
    animation: pulse 1.5s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes pulse {
    to {
        box-shadow: 0 0 0 8px rgba(185, 28, 28, 0);
    }
}

/* ================================================================
   MODAL OVERLAY
   ================================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
    max-width: 480px;
    width: 100%;
    border: 1px solid var(--line);
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-heading);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ================================================================
   STAT CARDS (Dashboard)
   ================================================================ */
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    transition: box-shadow 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card:hover {
    box-shadow: var(--card-shadow-hover);
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.stat-card-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-heading);
    font-variant-numeric: tabular-nums;
}

.stat-card-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ================================================================
   ACCESSIBILITY (§3)
   ================================================================ */

/* Focus ring — visible on keyboard navigation */
.btn-std:focus-visible,
.form-input:focus-visible,
.menu-item:focus-visible,
.btn-icon:focus-visible,
.toggle-sidebar:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

/* Reduced motion (§3) */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ================================================================
   UTILITY HELPERS
   ================================================================ */
.text-heading {
    color: var(--text-heading);
}

.text-body {
    color: var(--text-body);
}

.text-muted {
    color: var(--text-muted);
}

.text-accent {
    color: var(--accent);
}

.text-success {
    color: var(--success);
}

.text-warning {
    color: var(--warning);
}

.text-danger {
    color: var(--danger);
}

.text-primary {
    color: var(--primary);
}

.bg-surface {
    background: var(--bg-surface);
}

.bg-surface-2 {
    background: var(--bg-surface-2);
}

.font-bold {
    font-weight: 700;
}

.font-extrabold {
    font-weight: 800;
}

.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Fallback Toast container at the top-right corner */
#fallback-toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.fallback-toast {
    animation: slideInRight 0.3s ease-out forwards;
    background: #1e293b;
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    border-left: 4px solid var(--accent);
    pointer-events: auto;
    transition: opacity 0.3s, transform 0.3s;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* ================================================================
   PRINT MEDIA STYLES (Clean PDF/Print output)
   ================================================================ */
@media print {

    #sidebar,
    .top-navbar,
    .top-navbar-actions,
    .btn-std,
    form,
    #form-add-incident,
    .modal-overlay,
    .form-group,
    input,
    select,
    button,
    .page-header div[style*="display: flex; gap: 6px;"],
    .swal2-container,
    .swal2-popup,
    .swal2-toast,
    #fallback-toast-container,
    .fallback-toast,
    .no-print,
    .no-print *,
    .page-header > div:last-child,
    .page-header > div:last-child *,
    i,
    .stat-card-icon,
    div[style*="background: #f1f5f9"],
    div[style*="background: var(--bg-surface-2)"] {
        display: none !important;
    }

    .wrapper,
    #content,
    .main-body {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background: transparent !important;
    }

    .card,
    .table-card,
    .stat-card {
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        margin-bottom: 15px !important;
        page-break-inside: avoid !important;
        border-radius: 0 !important;
        padding: 0 !important;
    }

    .grid, .flex {
        display: block !important;
    }

    .badge,
    .badge-pill,
    .badge-success,
    .badge-danger,
    .badge-warning,
    .badge-info,
    .badge-secondary,
    .severity-badge,
    .sev-low,
    .sev-mid,
    .sev-high,
    [class*="badge-"],
    [class*="sev-"] {
        background: transparent !important;
        border: none !important;
        color: #000 !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        text-shadow: none !important;
        border-radius: 0 !important;
        font-weight: normal !important;
        display: inline !important;
    }

    .standard-table {
        border-collapse: collapse !important;
        width: 100% !important;
    }
    .standard-table th, .standard-table td {
        border: none !important;
        border-bottom: 1px solid #cbd5e1 !important;
        padding: 6px 8px !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 11pt !important;
        font-family: 'Sarabun', sans-serif !important;
    }
}

/* Responsive Table Columns (Desktop defaults) */
.col-date {
    width: 120px;
    white-space: nowrap;
}
.col-clinic {
    width: 200px;
    font-weight: 700;
    color: var(--text-heading);
    white-space: nowrap;
}
.col-desc {
    /* No truncation on desktop, wraps naturally */
}
.col-severity {
    width: 120px;
    text-align: center;
    white-space: nowrap;
}
.col-status {
    width: 130px;
    text-align: center;
    white-space: nowrap;
}
.col-action {
    width: 110px;
    text-align: center;
    white-space: nowrap;
}

/* ================================================================
   RESPONSIVE DESIGN Overrides (Phone, iPad, Tablet)
   ================================================================ */

/* 📱 Responsive Mobile Viewport (< 768px) */
@media (max-width: 767.98px) {
    /* Layout adjustments */
    .wrapper {
        position: relative;
        overflow-x: hidden;
    }

    #content {
        width: 100%;
        min-width: 0;
    }

    /* Fixed mobile off-canvas sidebar drawer */
    #sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
        width: var(--sidebar-width) !important;
    }

    #sidebar.active {
        transform: translateX(0);
    }

    /* Sidebar backdrop blur overlay */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(15, 23, 42, 0.4);
        backdrop-filter: blur(4px);
        z-index: 1040;
        transition: opacity 0.3s ease;
        opacity: 0;
        pointer-events: none;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    /* Top navbar adjustments */
    .top-navbar {
        padding: 0 16px;
        height: 60px;
    }

    .top-navbar-actions {
        gap: 6px;
    }

    /* Main body padding */
    .main-body {
        padding: 12px;
    }

    /* Page Header wrap layout */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        margin-bottom: 12px !important;
    }

    .page-header > div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .page-header > div:last-child button,
    .page-header > div:last-child a {
        width: 100% !important;
        margin: 0 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }

    .page-header-title h1 {
        font-size: 18px;
    }

    .page-header-title p {
        font-size: 12px;
    }

    /* Table card header responsive stacking */
    .table-card-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 12px 16px !important;
    }

    .table-card-header h3 {
        font-size: 14px !important;
        line-height: 1.4 !important;
    }

    .table-card-header .flex {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        gap: 8px !important;
    }

    .table-card-header .flex > * {
        flex: 1 !important;
        min-width: 0 !important;
    }

    /* Flex forms stacking (e.g. statistics filter form) */
    form[style*="display: flex"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    form[style*="display: flex"] > div {
        width: 100% !important;
        flex: 1 1 auto !important;
        margin: 0 !important;
    }

    /* Reset timer badge margin on mobile */
    .top-navbar-actions #sessionTimer {
        margin-right: 0 !important;
    }

    /* Filters wrap row */
    .card .flex-wrap {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .card .flex-wrap > div,
    .card .flex-wrap > .flex {
        width: 100% !important;
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .card .flex-wrap select, 
    .card .flex-wrap input {
        width: 100% !important;
    }

    .card .ml-auto {
        margin-left: 0 !important;
        justify-content: flex-start;
    }

    /* Modal box mobile fit */
    .modal-box {
        max-width: 100%;
        border-radius: 12px;
    }

    /* Mobile-specific table column constraints */
    .col-date {
        width: 90px !important;
        min-width: 90px !important;
    }
    .col-clinic {
        width: 140px !important;
        min-width: 140px !important;
    }
    .col-desc {
        max-width: 150px !important;
        min-width: 120px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    .col-severity {
        width: 80px !important;
        min-width: 80px !important;
    }
    .col-status {
        width: 90px !important;
        min-width: 90px !important;
    }
    .col-action {
        width: 90px !important;
        min-width: 90px !important;
    }
}

/* 🩺 iPad & Tablet Responsive Viewport (768px to 1023.98px) */
@media (min-width: 768px) and (max-width: 1023.98px) {
    /* Force collapsed sidebar to avoid cramped screens */
    #sidebar:not(.collapsed) {
        width: var(--sidebar-width);
    }
    
    #sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
    }

    .main-body {
        padding: 16px;
    }

    /* Header styling adjustments */
    .page-header {
        margin-bottom: 16px;
    }
}

/* 📊 General Responsive Utility Classes */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 16px 16px;
}

.table-responsive .standard-table {
    min-width: 600px; /* Force scrollable on extra narrow containers */
}

/* ================================================================
   FINAL PRINT OVERRIDES (Placed at the end to ensure they win over screen styles)
   ================================================================ */
@media print {
    .no-print,
    .no-print *,
    .page-header > div:last-child,
    .page-header > div:last-child * {
        display: none !important;
    }
}