/**
 * nreg-bs5.css
 * Bootstrap 5 + AdminLTE Compatibility Layer
 * Responsive-first design for PC & Mobile
 */

/* ===== CSS Variables ===== */
:root {
    --sidebar-width: 260px;
    --sidebar-bg: #1a252f;
    --sidebar-bg-gradient: linear-gradient(180deg, #2c3e50 0%, #1a252f 100%);
    --sidebar-text: rgba(255,255,255,0.8);
    --sidebar-active: rgba(255,255,255,0.12);
    --sidebar-border: rgba(255,255,255,0.08);
    --accent-color: #28a745;
    --topbar-height: 56px;
    --body-bg: #f4f6f9;
    --content-padding: 25px;
}

/* ===== Global ===== */
body {
    font-family: 'Sarabun', sans-serif !important;
    font-size: 14px;
    background-color: var(--body-bg);
    overflow-x: hidden;
}
*, *::before, *::after {
    box-sizing: border-box;
}

/* ===== Wrapper Layout ===== */
.wrapper {
    display: flex;
    flex-wrap: wrap;
    min-height: 100vh;
    width: 100%;
}

/* ===== Sidebar ===== */
.main-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg-gradient);
    color: #fff;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease, width 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.main-sidebar::-webkit-scrollbar {
    width: 5px;
}
.main-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.main-sidebar .sidebar-brand {
    padding: 18px 20px;
    text-align: center;
    border-bottom: 1px solid var(--sidebar-border);
}
.main-sidebar .sidebar-brand h4 {
    margin: 0;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
}
.main-sidebar .sidebar-brand small {
    color: rgba(255,255,255,0.6);
    font-size: 11px;
}

/* User Panel in Sidebar */
.user-panel {
    padding: 15px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-panel .image img,
.user-panel .pull-left.image img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
}
.user-panel .info p,
.user-panel .pull-left.info p {
    margin: 0;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}
.user-panel .info a {
    font-size: 12px;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
}

/* Sidebar Menu */
.sidebar-menu {
    list-style: none;
    padding: 10px 0;
    margin: 0;
}
.sidebar-menu .header,
.sidebar-menu .menu-header {
    padding: 12px 20px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255,255,255,0.4);
}
.sidebar-menu > li > a {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.2s;
    font-size: 14px;
}
.sidebar-menu > li > a > i,
.sidebar-menu > li > a > .fa,
.sidebar-menu > li > a > .fas,
.sidebar-menu > li > a > .far {
    width: 22px;
    text-align: center;
    margin-right: 10px;
    font-size: 15px;
}
.sidebar-menu > li > a:hover,
.sidebar-menu > li.active > a {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: var(--accent-color);
}

/* Treeview (submenu) */
.sidebar-menu .treeview > a::after {
    content: '\f105';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: auto;
    transition: transform 0.2s;
}
.sidebar-menu .treeview.menu-open > a::after {
    transform: rotate(90deg);
}
.sidebar-menu .treeview-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
    background: rgba(0,0,0,0.15);
}
.sidebar-menu .treeview.menu-open > .treeview-menu {
    display: block;
}
.sidebar-menu .treeview-menu > li > a {
    display: flex;
    align-items: center;
    padding: 8px 20px 8px 50px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
}
.sidebar-menu .treeview-menu > li > a:hover {
    color: #fff;
    background: rgba(255,255,255,0.05);
}
.sidebar-menu .treeview-menu > li > a > i {
    width: 18px;
    text-align: center;
    margin-right: 8px;
    font-size: 12px;
}

/* ===== Content Wrapper ===== */
.content-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    flex: 1;
    transition: margin-left 0.3s ease;
    background-color: var(--body-bg);
}

/* ===== Top Navbar ===== */
.main-header {
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.main-header .logo {
    display: none; /* Hidden in sidebar layout */
}
.main-header .navbar {
    width: 100%;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent !important;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 20px;
    color: #495057;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}
.sidebar-toggle:hover {
    background: #f0f0f0;
}

.navbar-custom-menu .nav {
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

/* User dropdown in navbar */
.navbar-custom-menu .user-menu > a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 8px;
    color: #495057;
    text-decoration: none;
    transition: background 0.2s;
}
.navbar-custom-menu .user-menu > a:hover {
    background: #f0f0f0;
}
.navbar-custom-menu .user-menu .user-image {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

/* User dropdown menu */
.navbar-custom-menu .dropdown-menu {
    min-width: 280px;
    border: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border-radius: 10px;
    overflow: hidden;
    right: 0;
    left: auto;
}
.navbar-custom-menu .user-header {
    background: var(--accent-color);
    color: #fff;
    padding: 20px;
    text-align: center;
}
.navbar-custom-menu .user-header img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.3);
    margin-bottom: 10px;
}
.navbar-custom-menu .user-header p {
    margin: 0;
    font-weight: 600;
    color: #fff;
}
.navbar-custom-menu .user-header small {
    color: rgba(255,255,255,0.8);
}
.navbar-custom-menu .user-footer {
    padding: 12px 20px;
    display: flex;
    justify-content: flex-end;
}

/* ===== AdminLTE Box → Bootstrap Card ===== */
.box {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e3e6ea;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.box-header {
    padding: 12px 18px;
    border-bottom: 1px solid #e3e6ea;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 8px 8px 0 0;
}
.box-header.with-border {
    border-bottom: 1px solid #e3e6ea;
}
.box-header font {
    font-weight: 600;
}
.box-body {
    padding: 18px;
}
.box-body.table-responsive {
    padding: 0;
}
.box-body.table-responsive > table {
    margin: 0;
}
.box-footer {
    padding: 12px 18px;
    border-top: 1px solid #e3e6ea;
    background: #fafbfc;
    border-radius: 0 0 8px 8px;
}
.box-tools {
    display: flex;
    gap: 4px;
}
.btn-box-tool {
    background: none;
    border: none;
    color: #999;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    transition: all 0.2s;
}
.btn-box-tool:hover {
    background: #f0f0f0;
    color: #333;
}

/* ===== Info Box (Dashboard cards) ===== */
.info-box {
    display: flex;
    align-items: stretch;
    background: #fff;
    border-radius: 10px;
    min-height: 80px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #e3e6ea;
    overflow: hidden;
    margin-bottom: 15px;
}
.info-box-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 75px;
    font-size: 28px;
    color: #fff;
}
.info-box-icon.bg-red { background: #dc3545; }
.info-box-icon.bg-blue { background: #0d6efd; }
.info-box-icon.bg-green { background: #198754; }
.info-box-icon.bg-yellow { background: #ffc107; color: #333; }
.info-box-icon.bg-aqua { background: #0dcaf0; }

.info-box-content {
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
}
.info-box-text {
    font-size: 13px;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.info-box-number {
    font-size: 22px;
    font-weight: 700;
    color: #2c3e50;
}

/* ===== Footer ===== */
.main-footer {
    padding: 15px var(--content-padding);
    border-top: 1px solid #dee2e6;
    background: #fff;
    font-size: 13px;
    color: #6c757d;
    margin-top: auto;
    width: 100%;
    transition: none;
}

/* ===== Bootstrap 3 → 5 Utility Compat ===== */
.pull-left { float: left !important; }
.pull-right { float: right !important; }
.hidden-xs { } /* handled per breakpoint below */
.img-circle { border-radius: 50% !important; }
.btn-flat { border-radius: 4px; }
.btn-default { 
    background: #f8f9fa; 
    border: 1px solid #dee2e6; 
    color: #495057; 
}
.btn-default:hover { 
    background: #e9ecef; 
    color: #333; 
}
.btn-xs {
    padding: 2px 8px;
    font-size: 12px;
    line-height: 1.5;
    border-radius: 4px;
}
.text-red { color: #dc3545 !important; }
.bg-red { background-color: #dc3545 !important; color: #fff; }
.bg-blue { background-color: #0d6efd !important; color: #fff; }
.bg-green { background-color: #198754 !important; color: #fff; }
.bg-yellow { background-color: #ffc107 !important; }
.bg-aqua { background-color: #0dcaf0 !important; }

/* BS3 panel → card compat */
.panel { background: #fff; border: 1px solid #dee2e6; border-radius: 8px; margin-bottom: 20px; }
.panel-default { border-color: #dee2e6; }
.panel-info { border-color: #0dcaf0; }
.panel-heading { padding: 12px 18px; border-bottom: 1px solid #e3e6ea; border-radius: 8px 8px 0 0; background: #fafbfc; }
.panel-info > .panel-heading { background: #e7f6fd; color: #055160; }
.panel-body { padding: 18px; }
.panel-footer { padding: 12px 18px; border-top: 1px solid #e3e6ea; background: #fafbfc; border-radius: 0 0 8px 8px; }

/* BS3 input-group-btn compat */
.input-group-btn { display: flex; }
.input-group-btn .btn { border-radius: 0 6px 6px 0; }

/* BS3 .help-block → .form-text */
.help-block { 
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #6c757d;
}

/* AdminLTE text-color compat */
.text-green { color: #198754 !important; }
.text-red { color: #dc3545 !important; }
.text-blue { color: #0d6efd !important; }
.text-yellow { color: #ffc107 !important; }
.text-aqua { color: #0dcaf0 !important; }

/* AdminLTE h3.box-title compat */
.box-title, h3.box-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.4;
}

/* Normalize <font> tags in box-header */
.box-header font,
.box-header font[size] {
    font-size: 1rem !important;
    font-weight: 600;
}

/* Old .label → badge */
.label { 
    display: inline-block; 
    padding: 3px 8px; 
    font-size: 12px; 
    border-radius: 4px; 
    font-weight: 600; 
}
.label-success { background: #198754; color: #fff; }
.label-danger { background: #dc3545; color: #fff; }
.label-warning { background: #ffc107; color: #333; }
.label-info { background: #0dcaf0; color: #333; }
.label-primary { background: #0d6efd; color: #fff; }
.label-default { background: #6c757d; color: #fff; }

/* ===== DataTables BS5 Overrides ===== */
table.display,
table.dataTable {
    width: 100% !important;
}
.dataTables_wrapper {
    padding: 15px;
}
.dataTables_wrapper .dataTables_length select {
    padding: 4px 24px 4px 8px;
}
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 5px 12px;
}
/* Fix DataTables stacking on mobile */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    text-align: left;
}

/* ===== Make all tables scroll-friendly ===== */
.box-body > table,
.card-body > table,
section.content > table {
    width: 100%;
}
/* Auto-wrap any table in scrollable container */
.box-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== Modal Compatibility ===== */
.modal .modal-header .close,
.modal .modal-header .btn-close-legacy {
    background: none;
    border: none;
    font-size: 20px;
    opacity: 0.7;
    cursor: pointer;
}
.modal .modal-header .close:hover {
    opacity: 1;
}
.modal .modal-header.bg-green {
    background: #198754 !important;
    color: #fff;
}
.modal .modal-header.bg-green .close,
.modal .modal-header.bg-green .modal-title {
    color: #fff;
}

/* ===== Tables ===== */
.table thead th {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

/* ===== Content Header ===== */
.content-header {
    padding: 15px var(--content-padding);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.content-header h1,
.content-header h5,
.content-header font {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    line-height: 1.4;
}
.content-header .breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: 13px;
}
.content-header .breadcrumb li {
    display: inline;
}
.content-header .breadcrumb li + li::before {
    content: '/ ';
    color: #999;
    padding: 0 6px;
}
.content-header .breadcrumb a {
    color: #6c757d;
    text-decoration: none;
}
.content-header .breadcrumb .active {
    color: #333;
}

/* ===== Content Section ===== */
section.content,
.content-section {
    padding: 0 var(--content-padding) var(--content-padding);
    flex: 1;
    min-width: 0; /* prevent flex overflow */
}

/* ========================================================
   RESPONSIVE: MOBILE FIRST
   ======================================================== */

/* ----- XS: 0–575 px (Phone portrait) ----- */
@media (max-width: 575.98px) {
    :root {
        --content-padding: 12px;
        --topbar-height: 50px;
    }
    body { font-size: 13px; }

    /* Sidebar: off-canvas */
    .main-sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    .main-sidebar.sidebar-open {
        transform: translateX(0);
    }
    .content-wrapper { margin-left: 0; }

    /* Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1035;
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active { display: block; }

    /* Header */
    .main-header .navbar { padding: 0 10px; }
    .content-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .content-header h5,
    .content-header font {
        font-size: 15px;
    }
    .content-header .breadcrumb {
        font-size: 12px;
    }

    /* Info box — stack on tiny screens */
    .info-box {
        min-height: 65px;
    }
    .info-box-icon {
        width: 60px;
        font-size: 22px;
    }
    .info-box-number {
        font-size: 18px;
    }
    .info-box-text {
        font-size: 11px;
    }

    /* Tables: smaller text */
    .table { font-size: 12px; }
    .table td, .table th { padding: 6px 8px; }
    .dataTables_wrapper { padding: 10px; }
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: center;
        margin-bottom: 8px;
    }
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: center;
        margin-top: 8px;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 4px 8px !important;
        font-size: 12px !important;
    }

    /* Btn group — wrap on mobile */
    .btn-group .btn { font-size: 12px; }

    /* Box */
    .box-header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
    .box-header font { font-size: 14px !important; }
    .box-body { padding: 12px; }
    .box-footer { padding: 10px 12px; }

    /* Modals: near full-width */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100vw - 20px);
    }
    .modal-lg { max-width: calc(100vw - 20px); }

    /* Form: ID card inputs */
    .input-group input[name^="txtID"] {
        width: auto !important;
        flex: 1;
        min-width: 0;
        text-align: center;
    }

    /* Footer */
    .main-footer .d-flex {
        flex-direction: column;
        text-align: center;
        gap: 4px;
    }

    /* User dropdown */
    .navbar-custom-menu .dropdown-menu {
        min-width: 250px;
        right: -10px;
    }
    .navbar-custom-menu .user-header img {
        width: 50px; height: 50px;
    }

    /* Hidden on xs */
    .hidden-xs { display: none !important; }
}

/* ----- SM: 576–767 px (Phone landscape / small tablet) ----- */
@media (min-width: 576px) and (max-width: 767.98px) {
    :root {
        --content-padding: 15px;
    }

    /* Sidebar: still off-canvas */
    .main-sidebar {
        transform: translateX(-100%);
    }
    .main-sidebar.sidebar-open {
        transform: translateX(0);
    }
    .content-wrapper { margin-left: 0; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1035;
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active { display: block; }

    .content-header h5,
    .content-header font {
        font-size: 16px;
    }

    .modal-dialog {
        margin: 20px auto;
        max-width: 500px;
    }

    .hidden-xs { display: inline-block !important; }
}

/* ----- MD: 768–991 px (Tablet portrait) ----- */
@media (min-width: 768px) and (max-width: 991.98px) {
    :root {
        --content-padding: 20px;
        --sidebar-width: 230px;
    }
    
    .main-sidebar {
        width: var(--sidebar-width);
        transform: translateX(0) !important;
    }
    body.sidebar-collapsed .main-sidebar {
        transform: translateX(-100%) !important;
    }
    body.sidebar-collapsed .content-wrapper {
        margin-left: 0;
    }
    
    .sidebar-overlay { display: none !important; }

    .info-box-number { font-size: 20px; }
    .hidden-xs { display: inline-block !important; }
}

/* ----- LG: 992–1199 px (Tablet landscape / small desktop) ----- */
@media (min-width: 992px) and (max-width: 1199.98px) {
    :root {
        --content-padding: 25px;
        --sidebar-width: 250px;
    }

    .main-sidebar {
        width: var(--sidebar-width);
        transform: translateX(0) !important;
    }
    body.sidebar-collapsed .main-sidebar {
        transform: translateX(-100%) !important;
    }
    body.sidebar-collapsed .content-wrapper,
    body.sidebar-collapsed .main-footer {
        margin-left: 0;
    }

    .sidebar-overlay { display: none !important; }
    .hidden-xs { display: inline-block !important; }
}

/* ----- XL: 1200 px+ (Desktop) ----- */
@media (min-width: 1200px) {
    :root {
        --content-padding: 25px;
        --sidebar-width: 260px;
    }

    .main-sidebar {
        width: var(--sidebar-width);
        transform: translateX(0) !important;
    }
    body.sidebar-collapsed .main-sidebar {
        transform: translateX(-100%) !important;
    }
    body.sidebar-collapsed .content-wrapper,
    body.sidebar-collapsed .main-footer {
        margin-left: 0;
    }

    .sidebar-overlay { display: none !important; }
    .hidden-xs { display: inline-block !important; }
}

/* ===== Stat Card (Dashboard) ===== */
.stat-card {
    border-radius: 10px;
    padding: 20px;
    color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 110px;
}
.stat-card .stat-icon {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 48px;
    opacity: 0.2;
}
.stat-card .stat-number {
    font-size: 28px;
    font-weight: 700;
}
.stat-card .stat-label {
    font-size: 13px;
    opacity: 0.9;
}

/* ===== Form Controls ===== */
.form-group {
    margin-bottom: 1rem;
}
/* Touch-friendly form elements */
@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .input-group .form-control {
        font-size: 16px; /* prevents iOS zoom on focus */
        min-height: 42px;
    }
    .form-check-input {
        width: 1.2em;
        height: 1.2em;
    }
    select.form-control,
    select.form-select {
        padding-right: 32px;
    }
}

/* ===== Select2 Responsive ===== */
.select2-container { width: 100% !important; }
@media (max-width: 575.98px) {
    .select2-container--bootstrap-5 .select2-selection {
        min-height: 42px;
        font-size: 14px;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
::-webkit-scrollbar-track {
    background: transparent;
}

/* ===== Animations ===== */
.sidebar-menu > li > a,
.treeview-menu > li > a,
.card,
.box {
    transition: all 0.2s ease;
}

/* ===== Print ===== */
@media print {
    .main-sidebar,
    .main-header,
    .main-footer,
    .sidebar-overlay,
    .sidebar-toggle,
    .btn-box-tool,
    .box-tools {
        display: none !important;
    }
    .content-wrapper {
        margin-left: 0 !important;
    }
    section.content { padding: 0; }
    .box { box-shadow: none; border: 1px solid #ddd; }
}
