/* =========================================================
   Royo Dispatch — Modern Sidebar & Topbar
   Replaces UBold layout styles for left-sidebar + topbar
   ========================================================= */

/* =========================================================
   UBOLD OVERRIDES — fix conflicts with existing UBold CSS
   ========================================================= */

/* UBold sets overflow:hidden on .content-page — this breaks
   horizontal table scroll. Override to visible/auto.         */
.content-page {
    overflow: visible !important;
}

/* UBold topbar was 70px; our topbar is 60px.
   Override margin-top so content starts at the right place. */
.content-page,
.content-page.main_outter_box {
    /* margin-top: 60px !important; */
    margin-left: 240px !important;
    width: calc(100% - 240px) !important;
    min-height: calc(100vh - 60px);
}

/* UBold navbar-custom (old topbar) — hide it, we use rd-topbar */
.navbar-custom {
    display: none !important;
}

/* UBold left-side-menu — hide it, we use rd-sidebar */
.left-side-menu {
    display: none !important;
}

/* Fix horizontal scroll for tables inside content */
.content .table-responsive,
.content .dataTables_wrapper,
.content .dataTables_scroll {
    overflow-x: auto !important;
    width: 100% !important;
}
.content table {
    max-width: none !important;
}

/* Fix Bootstrap 4 pagination styling.
   Target ul.pagination only — NOT div.pagination (agent page wrapper div) */
ul.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 16px 0;
    padding: 0;
    list-style: none;
}
ul.pagination .page-item .page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: 6px !important;
    border: 1px solid #e5e7eb;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    background: #ffffff;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}
ul.pagination .page-item .page-link:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
    color: #111827;
}
ul.pagination .page-item.active .page-link {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}
ul.pagination .page-item.disabled .page-link {
    color: #9ca3af;
    background: #f9fafb;
    border-color: #e5e7eb;
    cursor: not-allowed;
}

/* Remove UBold padding on .content — was adding gray strips top+left on dashboard.
   Each page controls its own padding via its container/card classes. */
.content {
    padding: 0 !important;
}

/* Twilio error alert row — ensure it takes no space when hidden */
.displaySettingsError[style*="display:none"],
.displaySettingsError[style*="display: none"] {
    margin: 0 !important;
    padding: 0 !important;
}

/* =========================================================
   DARK MODE — UBold card-box & legacy element overrides
   card-box is UBold's equivalent of .card — not covered by
   the Bootstrap .card rules above.
   ========================================================= */
body.dark .card-box {
    background: #1e2433 !important;
    border-color: #2d3547 !important;
    box-shadow: none !important;
}
body.dark .card-box .header-title,
body.dark .card-box h4,
body.dark .card-box h5,
body.dark .card-box h6 {
    color: #f1f5f9 !important;
}
body.dark .card-box .sub-header,
body.dark .card-box p,
body.dark .card-box label,
body.dark .card-box .primaryCurText,
body.dark .card-box .control-label {
    color: #d1d5db !important;
}
body.dark .card-box .font-weight-normal {
    color: #e2e8f0 !important;
}
body.dark .card-box .form-control,
body.dark .card-box textarea.form-control {
    background: #252d3d !important;
    border-color: #3d4a5e !important;
    color: #e2e8f0 !important;
}
body.dark .card-box .form-control::placeholder,
body.dark .card-box textarea::placeholder {
    color: #6b7280 !important;
}
body.dark .card-box #tags {
    color: #94a3b8 !important;
}
/* UBold thead-light inside card-box */
body.dark .card-box .thead-light th {
    background: #252d3d !important;
    color: #94a3b8 !important;
    border-color: #2d3547 !important;
}
body.dark .card-box .table td,
body.dark .card-box .table th {
    color: #e2e8f0 !important;
    border-color: #2d3547 !important;
}
body.dark .card-box .table tr:hover,
body.dark .card-box .table tr:hover td,
body.dark .card-box .table tr:hover th {
    background: #2a3447 !important;
}
/* UBold page title box */
body.dark .page-title-box .page-title,
body.dark .page-title-box h4 {
    color: #f1f5f9 !important;
}

/* Fix footer — UBold sets position:absolute which places it over table content.
   Make it flow naturally at the bottom of the page. */
footer.footer {
    position: relative !important;
    left: auto !important;
    bottom: auto !important;
    right: auto !important;
    padding: 14px 24px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

/* Fix dashboard map height — was calc(100vh - 70px) for old topbar */
#map_canvas {
    height: calc(100vh - 60px) !important;
}

/* Fix dashboard left panel height */
.coolcheck .left-sidebar {
    height: calc(100vh - 60px) !important;
    overflow-y: auto;
}

/* ── Reset wrapper ── */
#wrapper {
    display: flex;
    min-height: 100vh;
    background: #f3f4f6;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.rd-sidebar {
    width: 240px;
    min-height: 100vh;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transition: width 0.2s ease, transform 0.2s ease;
    overflow: hidden;
}

/* Logo area */
.rd-sidebar .rd-logo {
    display: flex;
    align-items: center;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #f3f4f6;
    min-height: 60px;
    flex-shrink: 0;
}
.rd-sidebar .rd-logo img {
    max-height: 36px;
    max-width: 160px;
    object-fit: contain;
}
.rd-sidebar .rd-logo-text {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.3px;
}

/* Scrollable nav area */
.rd-sidebar .rd-nav-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 0 20px;
}
.rd-sidebar .rd-nav-wrap::-webkit-scrollbar {
    width: 4px;
}
.rd-sidebar .rd-nav-wrap::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 4px;
}

/* Section labels  e.g. ORDERS / SETTINGS */
.rd-sidebar .rd-section-label {
    padding: 14px 20px 4px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9ca3af;
    white-space: nowrap;
}

/* Nav list */
.rd-sidebar ul.rd-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}
.rd-sidebar ul.rd-menu li {
    margin: 1px 8px;
}

/* Nav item link */
.rd-sidebar ul.rd-menu li > a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 7px;
    color: #374151;
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.rd-sidebar ul.rd-menu li > a i {
    font-size: 16px;
    flex-shrink: 0;
    color: #6b7280;
    width: 18px;
    text-align: center;
    transition: color 0.15s;
}
.rd-sidebar ul.rd-menu li > a:hover {
    background: #eff6ff;
    color: #2563eb;
}
.rd-sidebar ul.rd-menu li > a:hover i {
    color: #2563eb;
}

/* Active state */
.rd-sidebar ul.rd-menu li > a.active,
.rd-sidebar ul.rd-menu li.active > a {
    background: #eff6ff;
    color: #2563eb;
    font-weight: 600;
}
.rd-sidebar ul.rd-menu li > a.active i,
.rd-sidebar ul.rd-menu li.active > a i {
    color: #2563eb;
}

/* Sub-menu (collapsed) */
.rd-sidebar ul.rd-menu ul.rd-submenu {
    list-style: none;
    margin: 2px 0 2px 28px;
    padding: 0;
    border-left: 2px solid #e5e7eb;
}
.rd-sidebar ul.rd-menu ul.rd-submenu li {
    margin: 0;
}
.rd-sidebar ul.rd-menu ul.rd-submenu li > a {
    padding: 6px 12px;
    font-size: 13px;
    color: #4b5563;
    border-radius: 0 6px 6px 0;
}
.rd-sidebar ul.rd-menu ul.rd-submenu li > a:hover,
.rd-sidebar ul.rd-menu ul.rd-submenu li > a.active {
    background: #eff6ff;
    color: #2563eb;
}

/* Expand arrow */
.rd-sidebar ul.rd-menu li > a .rd-arrow {
    margin-left: auto;
    font-size: 12px;
    color: #9ca3af;
    transition: transform 0.2s;
}
.rd-sidebar ul.rd-menu li.open > a .rd-arrow {
    transform: rotate(90deg);
}

/* =========================================================
   TOPBAR
   ========================================================= */
.rd-topbar {
    position: fixed;
    top: 0;
    left: 240px;
    right: 0;
    height: 60px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 999;
    transition: left 0.2s ease;
}

/* Left: hamburger + page title */
.rd-topbar .rd-topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}
.rd-topbar .rd-hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: #6b7280;
    display: flex;
    align-items: center;
    transition: background 0.15s;
}
.rd-topbar .rd-hamburger:hover {
    background: #f3f4f6;
    color: #111827;
}
.rd-topbar .rd-hamburger i {
    font-size: 18px;
}
.rd-topbar .rd-page-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

/* Right: action buttons */
.rd-topbar .rd-topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Generic topbar button */
.rd-topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 7px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.rd-topbar-btn:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    color: #111827;
    text-decoration: none;
}
.rd-topbar-btn i {
    font-size: 14px;
    color: #6b7280;
}

/* Primary (Add Route) button */
.rd-topbar-btn.rd-btn-primary {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}
.rd-topbar-btn.rd-btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
}
.rd-topbar-btn.rd-btn-primary i {
    color: #ffffff;
}

/* Dropdown arrow */
.rd-topbar-btn .rd-caret {
    font-size: 11px;
    color: #9ca3af;
    margin-left: 2px;
}

/* User button */
.rd-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 6px;
    border-radius: 7px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}
.rd-user-btn:hover {
    background: #f9fafb;
    text-decoration: none;
    color: #111827;
}
.rd-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Loading spinner in topbar */
.rd-topbar .rd-spinner {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px;          /* prevent flex from squishing */
    flex-shrink: 0;
    box-sizing: border-box;
    border: 2px solid #e2e8f0 !important;
    border-top-color: #2563eb !important;
    border-radius: 50%;
    animation: rd-spin 0.75s linear infinite;
    display: none;
    align-self: center;
}
.rd-topbar .rd-spinner.active,
.rd-topbar .rd-spinner[style*="display: block"],
.rd-topbar .rd-spinner[style*="display:block"] {
    display: inline-block !important;
}
@keyframes rd-spin {
    to { transform: rotate(360deg); }
}

/* =========================================================
   CONTENT AREA  — offset handled in UBOLD OVERRIDES above
   ========================================================= */
.rd-content-wrap {
    transition: margin-left 0.2s ease, width 0.2s ease;
}

/* =========================================================
   COLLAPSED SIDEBAR  (toggle class on body)
   ========================================================= */
body.rd-sidebar-collapsed .rd-sidebar {
    width: 60px;
}
body.rd-sidebar-collapsed .rd-sidebar .rd-logo-text,
body.rd-sidebar-collapsed .rd-sidebar .rd-section-label,
body.rd-sidebar-collapsed .rd-sidebar ul.rd-menu li > a span,
body.rd-sidebar-collapsed .rd-sidebar ul.rd-menu li > a .rd-arrow,
body.rd-sidebar-collapsed .rd-sidebar ul.rd-menu ul.rd-submenu {
    display: none;
}
body.rd-sidebar-collapsed .rd-sidebar ul.rd-menu li {
    margin: 1px 6px;
}
body.rd-sidebar-collapsed .rd-sidebar ul.rd-menu li > a {
    justify-content: center;
    padding: 10px;
}
body.rd-sidebar-collapsed .rd-topbar {
    left: 60px;
}
body.rd-sidebar-collapsed .content-page,
body.rd-sidebar-collapsed .content-page.main_outter_box {
    margin-left: 60px !important;
    width: calc(100% - 60px) !important;
}

/* =========================================================
   DARK MODE
   ========================================================= */
body.dark .rd-sidebar {
    background: #1e2433;
    border-right-color: #2d3547;
}
body.dark .rd-sidebar .rd-logo-text { color: #f9fafb; }
body.dark .rd-sidebar .rd-section-label { color: #6b7280; }
body.dark .rd-sidebar ul.rd-menu li > a { color: #d1d5db; }
body.dark .rd-sidebar ul.rd-menu li > a i { color: #9ca3af; }
body.dark .rd-sidebar ul.rd-menu li > a:hover,
body.dark .rd-sidebar ul.rd-menu li > a.active,
body.dark .rd-sidebar ul.rd-menu li.active > a {
    background: rgba(37,99,235,0.18);
    color: #60a5fa;
}
body.dark .rd-sidebar ul.rd-menu li > a:hover i,
body.dark .rd-sidebar ul.rd-menu li > a.active i,
body.dark .rd-sidebar ul.rd-menu li.active > a i {
    color: #60a5fa;
}
body.dark .rd-topbar {
    background: #1e2433;
    border-bottom-color: #2d3547;
}
body.dark .rd-topbar .rd-page-title { color: #f9fafb; }
body.dark .rd-topbar-btn {
    background: #2d3547;
    border-color: #3d4a5e;
    color: #d1d5db;
}
body.dark .rd-topbar-btn:hover {
    background: #374151;
    color: #f9fafb;
}
body.dark .rd-user-btn {
    background: #2d3547;
    border-color: #3d4a5e;
    color: #d1d5db;
}

/* =========================================================
   DARK MODE — Global content area fixes
   Forces light text on dark backgrounds across all pages
   ========================================================= */

/* Page background */
body.dark #wrapper,
body.dark .content-page {
    background: #111827 !important;
}

/* Cards */
body.dark .card {
    background: #1e2433 !important;
    border-color: #2d3547 !important;
    color: #e2e8f0 !important;
}
body.dark .card-header,
body.dark .card-footer {
    background: #252d3d !important;
    border-color: #2d3547 !important;
    color: #e2e8f0 !important;
}

/* General text inside content */
body.dark .content-page h1,
body.dark .content-page h2,
body.dark .content-page h3,
body.dark .content-page h4,
body.dark .content-page h5,
body.dark .content-page h6 {
    color: #f1f5f9 !important;
}
body.dark .content-page p,
body.dark .content-page label,
body.dark .content-page span:not(.badge):not(.btn):not([class*="label-"]) {
    color: #d1d5db !important;
}
body.dark .content-page .text-muted,
body.dark .content-page small {
    color: #94a3b8 !important;
}
body.dark .content-page .text-dark,
body.dark .content-page .text-body {
    color: #e2e8f0 !important;
}

/* Tables */
body.dark .table,
body.dark .table th,
body.dark .table td {
    color: #e2e8f0 !important;
    border-color: #2d3547 !important;
}
body.dark .table thead th {
    background: #252d3d !important;
    color: #94a3b8 !important;
}
body.dark .table tbody tr {
    background: #1e2433 !important;
    transition: none !important;
}
body.dark .table tbody td,
body.dark .table tbody th {
    background: #1e2433 !important;
    transition: background .12s;
}
body.dark .table-striped tbody tr:nth-of-type(odd) {
    background: #222b3a !important;
}
body.dark .table tbody tr:hover,
body.dark .table tbody tr:hover td,
body.dark .table tbody tr:hover th {
    background: #2a3447 !important;
}
body.dark .thead-light th {
    background: #252d3d !important;
    color: #94a3b8 !important;
    border-color: #2d3547 !important;
}

/* Forms */
body.dark .form-control,
body.dark .form-control:focus {
    background: #252d3d !important;
    border-color: #3d4a5e !important;
    color: #e2e8f0 !important;
}
body.dark .form-control::placeholder {
    color: #6b7280 !important;
}
body.dark select.form-control option {
    background: #1e2433;
    color: #e2e8f0;
}
body.dark .input-group-text {
    background: #2d3547 !important;
    border-color: #3d4a5e !important;
    color: #94a3b8 !important;
}

/* Modals */
body.dark .modal-content {
    background: #1e2433 !important;
    border-color: #2d3547 !important;
    color: #e2e8f0 !important;
}
body.dark .modal-header {
    background: #252d3d !important;
    border-bottom-color: #2d3547 !important;
}
body.dark .modal-header .modal-title,
body.dark .modal-header h4,
body.dark .modal-header h5 {
    color: #f1f5f9 !important;
}
body.dark .modal-footer {
    border-top-color: #2d3547 !important;
    background: #1e2433 !important;
}
body.dark .modal-body label {
    color: #d1d5db !important;
}
body.dark .close {
    color: #94a3b8 !important;
}

/* Tabs */
body.dark .nav-tabs {
    border-color: #2d3547 !important;
}
body.dark .nav-tabs .nav-link {
    color: #94a3b8 !important;
}
body.dark .nav-tabs .nav-link.active {
    background: #1e2433 !important;
    border-color: #2d3547 #2d3547 #1e2433 !important;
    color: #f1f5f9 !important;
}
body.dark .tab-content {
    color: #e2e8f0 !important;
}

/* Dropdowns */
body.dark .dropdown-menu {
    background: #252d3d !important;
    border-color: #3d4a5e !important;
}
body.dark .dropdown-item {
    color: #d1d5db !important;
}
body.dark .dropdown-item:hover {
    background: rgba(255,255,255,0.07) !important;
    color: #f1f5f9 !important;
}
body.dark .dropdown-divider {
    border-color: #3d4a5e !important;
}

/* Pagination */
body.dark ul.pagination .page-item .page-link {
    background: #252d3d !important;
    border-color: #3d4a5e !important;
    color: #d1d5db !important;
}
body.dark ul.pagination .page-item .page-link:hover {
    background: #2d3547 !important;
    color: #f1f5f9 !important;
}
body.dark ul.pagination .page-item.disabled .page-link {
    background: #1e2433 !important;
    color: #6b7280 !important;
}

/* Footer */
body.dark footer.footer {
    background: #1e2433 !important;
    border-top-color: #2d3547 !important;
    color: #6b7280 !important;
}

/* =========================================================
   RESPONSIVE — mobile
   ========================================================= */
@media (max-width: 768px) {
    .rd-sidebar {
        transform: translateX(-100%);
    }
    body.rd-sidebar-open .rd-sidebar {
        transform: translateX(0);
    }
    .rd-topbar {
        left: 0;
    }
    .content-page,
    .content-page.main_outter_box {
        margin-left: 0 !important;
        width: 100% !important;
    }
    /* overlay */
    body.rd-sidebar-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 999;
    }
}
