/* ═══════════════════════════════════════════════════════════════
   DMSC Maintenance System — Global Styles
   Loaded on every page for consistent web-app experience
   ═══════════════════════════════════════════════════════════════ */

/* ── Smooth page load ──────────────────────────────────────────── */
body { opacity: 1; transition: opacity .15s ease; }
body.page-loading { opacity: 0; }

/* ── Toast Notifications ───────────────────────────────────────── */
#dmsc-toast-container {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: calc(100vw - 36px);
}
.dmsc-toast {
    min-width: 280px;
    max-width: 400px;
    background: #1e293b;
    color: #fff;
    border-radius: 10px;
    padding: 13px 16px 13px 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,.28);
    pointer-events: all;
    animation: toastSlideIn .3s cubic-bezier(.22,1,.36,1) forwards;
    border-left: 4px solid #3b82f6;
    font-family: 'Segoe UI', sans-serif;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}
.dmsc-toast.toast-success { border-left-color: #10b981; }
.dmsc-toast.toast-error   { border-left-color: #ef4444; }
.dmsc-toast.toast-warning { border-left-color: #f59e0b; }
.dmsc-toast.toast-info    { border-left-color: #3b82f6; }
.dmsc-toast.toast-hiding  { animation: toastSlideOut .25s ease forwards; }

.dmsc-toast-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.toast-success .dmsc-toast-icon { color: #10b981; }
.toast-error   .dmsc-toast-icon { color: #ef4444; }
.toast-warning .dmsc-toast-icon { color: #f59e0b; }
.toast-info    .dmsc-toast-icon { color: #60a5fa; }

.dmsc-toast-body { flex: 1; }
.dmsc-toast-title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.dmsc-toast-msg   { font-size: 12px; color: #cbd5e1; }

.dmsc-toast-close {
    background: none; border: none; color: #94a3b8; cursor: pointer;
    font-size: 14px; padding: 0; line-height: 1; flex-shrink: 0;
    transition: color .15s;
}
.dmsc-toast-close:hover { color: #fff; }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(40px) scale(.95); }
    to   { opacity: 1; transform: translateX(0)   scale(1);   }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0)   scale(1);   }
    to   { opacity: 0; transform: translateX(40px) scale(.95); max-height: 0; margin: 0; padding: 0; }
}

/* ── Confirm Modal ─────────────────────────────────────────────── */
#dmsc-confirm-overlay {
    position: fixed; inset: 0; z-index: 99998;
    background: rgba(15,23,42,.55);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn .18s ease;
}
#dmsc-confirm-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

#dmsc-confirm-box {
    background: #fff;
    border-radius: 14px;
    padding: 28px 28px 22px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    animation: scaleIn .2s cubic-bezier(.22,1,.36,1);
    font-family: 'Segoe UI', sans-serif;
}
@keyframes scaleIn { from { transform:scale(.9); opacity:0; } to { transform:scale(1); opacity:1; } }

#dmsc-confirm-icon {
    width: 48px; height: 48px; border-radius: 50%;
    background: #fee2e2; display: flex; align-items: center; justify-content: center;
    margin-bottom: 14px;
}
#dmsc-confirm-icon i { color: #dc2626; font-size: 20px; }
#dmsc-confirm-icon.warn-icon { background: #fef3c7; }
#dmsc-confirm-icon.warn-icon i { color: #d97706; }

#dmsc-confirm-title {
    font-size: 16px; font-weight: 700; color: #0f172a; margin-bottom: 8px;
}
#dmsc-confirm-msg {
    font-size: 13px; color: #475569; line-height: 1.55; margin-bottom: 22px;
}
.dmsc-confirm-btns {
    display: flex; gap: 10px; justify-content: flex-end;
}
.dmsc-confirm-btns button {
    padding: 9px 20px; border-radius: 8px; font-size: 13px; font-weight: 600;
    cursor: pointer; border: none; transition: .15s;
}
#dmsc-confirm-cancel {
    background: #f1f5f9; color: #475569;
}
#dmsc-confirm-cancel:hover { background: #e2e8f0; }
#dmsc-confirm-ok {
    background: #dc2626; color: #fff;
}
#dmsc-confirm-ok:hover { background: #b91c1c; }
#dmsc-confirm-ok.ok-primary { background: #1e3a5f; }
#dmsc-confirm-ok.ok-primary:hover { background: #2d4f80; }

/* ── Page Loading Overlay ──────────────────────────────────────── */
#dmsc-page-loader {
    position: fixed; inset: 0; z-index: 99997;
    background: rgba(255,255,255,.8);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center; justify-content: center;
    flex-direction: column; gap: 12px;
}
#dmsc-page-loader.visible { display: flex; }
.dmsc-spinner {
    width: 40px; height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #1e3a5f;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
.dmsc-spinner-label { font-size: 13px; color: #64748b; font-family: 'Segoe UI',sans-serif; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile: responsive table wrapper ─────────────────────────── */
.tbl-wrap, .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tbl-wrap table, .table-responsive table {
    min-width: 600px;
}

/* ── Mobile: sidebar overlay ───────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1001;
}
.sidebar-overlay.visible { display: block !important; }

/* ── Mobile Top Bar (dark navy, always visible on mobile) ───────── */
#dmsc-mobile-topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    background: linear-gradient(90deg, #001b5e 0%, #000d3a 100%);
    z-index: 1003;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
#dmsc-mobile-topbar-logo {
    width: 32px; height: 32px; border-radius: 6px;
    background: rgba(255,255,255,.15);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
#dmsc-mobile-topbar-logo i { color: #fff; font-size: 14px; }
#dmsc-mobile-topbar-title {
    flex: 1;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Montserrat', 'Segoe UI', sans-serif;
    letter-spacing: .3px;
}
#dmsc-mobile-topbar-subtitle {
    font-size: 10px;
    color: rgba(255,255,255,.6);
    font-weight: 500;
    line-height: 1.2;
}
/* Hamburger button — lives inside #dmsc-mobile-topbar */
.mobile-menu-btn {
    display: none;
    align-items: center; justify-content: center;
    width: 42px; height: 42px;
    background: rgba(251,191,36,.15);
    border: 2px solid #fbbf24;
    border-radius: 8px;
    color: #fbbf24; font-size: 20px;
    cursor: pointer; flex-shrink: 0;
    transition: background .15s, border-color .15s;
    -webkit-tap-highlight-color: transparent;
}
.mobile-menu-btn:hover,
.mobile-menu-btn:active {
    background: rgba(251,191,36,.28);
    border-color: #f59e0b;
    color: #f59e0b;
}

/* ── Core mobile layout ─────────────────────────────────────────── */
@media (max-width: 768px) {

    /* Show mobile top bar and hamburger */
    #dmsc-mobile-topbar { display: flex !important; }
    .mobile-menu-btn    { display: flex !important; }

    /* Prevent horizontal scroll on the whole page */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* Push content down below fixed top bar */
    body.dmsc-mobile .main-content,
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding-top: 54px !important;
        overflow-x: hidden !important;
    }

    /* Slide dashboard sidebar off-screen by default */
    .sidebar:not(.layout .sidebar) {
        position: fixed !important;
        left: 0 !important; top: 0 !important;
        height: 100vh !important;
        width: 260px !important;
        z-index: 1002 !important;
        transform: translateX(-100%) !important;
        transition: transform .28s cubic-bezier(.4,0,.2,1) !important;
        box-shadow: none !important;
    }
    .sidebar.mobile-open:not(.layout .sidebar) {
        transform: translateX(0) !important;
        box-shadow: 6px 0 28px rgba(0,0,0,.4) !important;
    }

    /* Content header */
    .content-header {
        padding: 14px 16px !important;
        flex-wrap: wrap !important;
        gap: 10px !important;
    }
    .content-header .header-title h1 { font-size: 18px !important; }
    .content-header .header-title p  { font-size: 12px !important; }

    /* Page body padding */
    .page-body,
    .main-content > .page-body {
        padding-left: 14px !important;
        padding-right: 14px !important;
    }

    /* Filters row */
    .filters {
        padding: 12px 14px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* Summary/stat cards 2-column */
    .summary-grid, .sum-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Stack form rows */
    .row { flex-direction: column !important; }
    .form-group { width: 100% !important; }

    /* Bus report header */
    .bus-result-header {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    .bus-result-header .stats { flex-wrap: wrap; gap: 12px; }

    /* Full-width modals */
    .modal-content, .modal-box {
        max-width: 100% !important;
        margin: 10px !important;
        border-radius: 12px !important;
        width: calc(100vw - 20px) !important;
    }

    /* Search bar full width */
    .search-bar { width: 100% !important; max-width: 100% !important; }

    /* Action buttons wrap */
    .header-actions { flex-wrap: wrap !important; gap: 8px !important; }

    /* Sidebar footer toggle */
    .sidebar-footer .toggle-btn span { display: none; }
}

/* ════════════════════════════════════════════════════════════════
   COMPREHENSIVE MOBILE LAYOUT FIXES — all page types
   ════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── TYPE A: Pages with .topbar (admin_workers, admin_users,
                 admin_transactions, admin_reports) ────────────── */
    .topbar {
        padding: 8px 12px !important;
        height: auto !important;
        min-height: 54px !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .topbar-brand h1 { font-size: 13px !important; }
    .topbar-actions  { flex-wrap: wrap !important; gap: 6px !important; }
    .tbtn            { font-size: 11px !important; padding: 6px 10px !important; }

    /* ── TYPE A: .layout wrapper — stack vertically ─────────────── */
    .layout {
        flex-direction: column !important;
        min-height: unset !important;
    }

    /* ── TYPE A: Filter sidebar (.sidebar inside .layout)
                 admin_workers, admin_users — becomes horizontal pill bar */
    .layout > aside.sidebar,
    .layout > .sidebar {
        position: static !important;
        transform: none !important;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        padding: 8px 10px !important;
        border-right: none !important;
        border-bottom: 1px solid #e5e7eb !important;
        box-shadow: none !important;
        -webkit-overflow-scrolling: touch;
    }
    .layout > aside.sidebar .sb-section-title,
    .layout > .sidebar .sb-section-title,
    .layout > aside.sidebar .sb-divider,
    .layout > .sidebar .sb-divider,
    .layout > aside.sidebar .sb-title,
    .layout > .sidebar .sb-title       { display: none !important; }
    .layout > aside.sidebar .sb-btn,
    .layout > .sidebar .sb-btn {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 6px 12px !important;
        border-radius: 20px !important;
        font-size: 11px !important;
        min-height: 32px !important;
    }

    /* ── TYPE A: Location sidebar (.loc-sidebar inside .layout)
                 admin_transactions — also becomes horizontal pill bar ── */
    .loc-sidebar {
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        position: static !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        border-right: none !important;
        border-bottom: 1px solid #e5e7eb !important;
        padding: 8px 10px !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 4px !important;
        -webkit-overflow-scrolling: touch;
    }
    .loc-sidebar-title { display: none !important; }
    .loc-btns-row {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        padding: 0 !important;
    }
    .loc-btn {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 6px 12px !important;
        border-radius: 20px !important;
        font-size: 11px !important;
        min-height: 32px !important;
        width: auto !important;
    }

    /* ── TYPE A: Main content area — full width, sensible padding ── */
    .main {
        padding: 14px 12px !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    .view-heading h2    { font-size: 16px !important; }
    .table-head-row h3  { font-size: 12px !important; }

    /* ── TYPE B: Pages with .wrap (leadman_requests) ────────────── */
    .wrap {
        max-width: 100% !important;
        padding: 12px !important;
    }
    .page-header {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 10px 12px !important;
    }
    .page-title { font-size: 15px !important; }

    /* ── TYPE C: Pages with .container (job_order, job_request,
                 view_transaction, approval_requests,
                 admin_drivers_buses) ──────────────────────────── */
    .container {
        padding: 16px 12px !important;
        border-radius: 10px !important;
        margin: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }

    /* ── TYPE C: Form grids — single column on mobile ────────────── */
    .form-grid,
    .grid-4col,
    .form-row,
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        display: block !important;
    }

    /* ── General table improvements ─────────────────────────────── */
    .table-card { border-radius: 10px !important; }
    th, td      { padding: 8px 10px !important; font-size: 12px !important; }

    /* ── Headings scale down ─────────────────────────────────────── */
    h1 { font-size: 20px !important; }
    h2 { font-size: 17px !important; }
    h3 { font-size: 15px !important; }
}

/* ── Small phones (< 480px) ────────────────────────────────────── */
@media (max-width: 480px) {
    .summary-grid, .sum-grid {
        grid-template-columns: 1fr !important;
    }
    .dmsc-toast { min-width: calc(100vw - 36px); }
    #dmsc-toast-container { right: 18px; left: 18px; }

    /* Tables: reduce font size on tiny screens */
    .tbl-wrap table, .table-responsive table {
        font-size: 12px !important;
    }
    .tbl-wrap table th,
    .tbl-wrap table td {
        padding: 8px 6px !important;
    }
}

/* ── Better scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Better focus rings ────────────────────────────────────────── */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ── Smooth links ──────────────────────────────────────────────── */
a { transition: opacity .15s; }

/* ── Touch-friendly tap targets ────────────────────────────────── */
@media (max-width: 768px) {
    button, .nav-item, .btn, a.btn-submit, a.btn-cancel {
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }
}

/* ── Print: always hide toast, loader, confirm, mobile bar ────── */
@media print {
    #dmsc-toast-container,
    #dmsc-confirm-overlay,
    #dmsc-page-loader,
    #dmsc-mobile-topbar,
    .sidebar-overlay,
    .mobile-menu-btn { display: none !important; }

    /* Restore normal layout for print */
    .main-content {
        margin-left: 0 !important;
        padding-top: 0 !important;
    }
}
