/* Color System - Premium Light Theme */
:root {
    --bg-color: #F8FAFC;
    --surface-color: #FFFFFF;
    --primary-color: #0EA5E9;
    --primary-glow: rgba(14, 165, 233, 0.15);
    --secondary-color: #D97706;
    --success-color: #16A34A;
    --warning-color: #EA580C;
    --danger-color: #DC2626;
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --border-color: #E2E8F0;
    --card-bg: #FFFFFF;
    --sidebar-width: 260px;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
    background: rgba(14, 165, 233, 0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(14, 165, 233, 0.4);
}

/* Card Styling */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
    border-color: rgba(14, 165, 233, 0.3);
}

/* Button styles */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
    text-decoration: none;
}

.btn-primary {
    background: #0EA5E9;
    color: #FFFFFF;
}

.btn-primary:hover {
    background: #0284C7;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #FFFFFF;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    color: var(--text-primary) !important;
    background: #F1F5F9;
    transform: translateY(-1px);
}

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

.btn-danger:hover {
    background: #B91C1C;
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success-color);
    color: #FFFFFF;
}

.btn-success:hover {
    background: #15803D;
    transform: translateY(-1px);
}

/* Form controls */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select.form-control option {
    background-color: #FFFFFF;
    color: var(--text-primary);
}

/* Layout - Sidebar is overlay drawer, main-content is always full width */
.app-container {
    display: block;
    min-height: 100vh;
    overflow: hidden;
}

.main-content {
    display: block;
    margin-left: 0;
    padding: 30px;
    background: #F8FAFC;
    min-height: 100vh;
}

/* Sidebar Styling - hidden by default, slides in as overlay */
.sidebar {
    width: 260px;
    height: 100vh;
    background-color: #FFFFFF;
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateX(-260px);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.32s ease;
}

/* Sidebar open state (via hamburger) - slides into view */
.sidebar-open {
    transform: translateX(0) !important;
    box-shadow: 4px 0 30px rgba(0,0,0,0.18);
}

/* ── Sidebar Overlay Backdrop ── */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 99;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
}
#sidebarOverlay.overlay-active {
    display: block;
    opacity: 1;
}

/* ── Hamburger Button ── */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 8px;
    background: transparent;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    margin-right: 14px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.hamburger-btn:hover {
    background: #F0F9FF;
    border-color: var(--primary-color);
}
.hamburger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1),
                opacity 0.2s ease,
                width 0.3s ease;
    transform-origin: center;
}
/* Animated to X when active */
.hamburger-btn.is-active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.hamburger-btn.is-active span:nth-child(2) {
    opacity: 0;
    width: 0;
}
.hamburger-btn.is-active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ── Sidebar Close Button (inside sidebar) ── */
.sidebar-close-btn {
    display: none;
    margin-left: auto;
    width: 32px;
    height: 32px;
    border: none;
    background: #FEF2F2;
    color: #B91C1C;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}
.sidebar-close-btn:hover {
    background: #FCA5A5;
    transform: rotate(90deg);
}
/* Show close btn when sidebar is open */
.sidebar-open .sidebar-close-btn {
    display: flex;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: #F0F9FF;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0EA5E9;
    font-size: 1.5rem;
}

.sidebar-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.sidebar-title span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
    font-weight: 400;
}

.sidebar-menu {
    list-style: none;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.sidebar-item a:hover {
    color: var(--primary-color);
    background: #F8FAFC;
}

.sidebar-item.active a {
    color: #0369A1;
    background: #E0F2FE;
    font-weight: 600;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    background: #F8FAFC;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #E0F2FE;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #0369A1;
    border: 2px solid #0EA5E9;
}

.user-info {
    min-width: 0;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

/* Top bar style */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

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

/* Badges */
.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    display: inline-block;
    white-space: nowrap;
}

.badge-pending { background: #F1F5F9; color: #475569; border: 1px solid #CBD5E1; }
.badge-in_progress { background: #FFF7ED; color: #C2410C; border: 1px solid #FDBA74; }
.badge-qc_check { background: #FAF5FF; color: #7E22CE; border: 1px solid #E9D5FF; }
.badge-ready { background: #F0FDF4; color: #15803D; border: 1px solid #BBF7D0; }
.badge-dispatched { background: #F0F9FF; color: #0369A1; border: 1px solid #BAE6FD; }
.badge-delivered { background: #ECFDF5; color: #047857; border: 1px solid #A7F3D0; }
.badge-cancelled { background: #FEF2F2; color: #B91C1C; border: 1px solid #FCA5A5; }
.badge-rejected  { background: #FFF7ED; color: #9A3412; border: 1px solid #FDBA74; }

/* Table styling */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    text-align: left;
}

.table th {
    padding: 14px 16px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.table tbody tr:hover {
    background: #F8FAFC;
}

/* Stat Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-info h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
}

.stat-info .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-icon.cyan { background: #F0F9FF; color: #0284C7; }
.stat-icon.orange { background: #FFF7ED; color: #C2410C; }
.stat-icon.green { background: #F0FDF4; color: #15803D; }
.stat-icon.gold { background: #FEF3C7; color: #B45309; }
.stat-icon.red { background: #FEF2F2; color: #B91C1C; }

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }

/* Alert utility */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-danger {
    background: #FEF2F2;
    border: 1px solid #FCA5A5;
    color: #B91C1C;
}
.alert-success {
    background: #F0FDF4;
    border: 1px solid #BBF7D0;
    color: #15803D;
}

/* Responsive Scrollable Modal Layout */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6) !important;
    z-index: 1000;
    justify-content: center;
    align-items: flex-start !important;
    overflow-y: auto !important;
    padding: 40px 15px !important;
    backdrop-filter: blur(5px);
}

.modal-card {
    background: #FFFFFF !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
    width: 100%;
    position: relative;
    margin: auto !important;
    padding: 30px !important;
}

/* Modal fallback styles to prevent raw HTML display if CDN fails */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1055;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(3px);
}
.modal.show {
    display: flex !important;
    align-items: center;
    justify-content: center;
}
.modal-dialog {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 1.75rem auto;
    pointer-events: none;
}
.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: #ffffff;
    border-radius: 12px;
    outline: 0;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 1.5rem;
}
.modal-footer {
    display: flex;
    wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    gap: 10px;
}
.btn-close {
    background: transparent;
    border: 0;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s linear;
}
.btn-close::before {
    content: "✕";
    font-weight: bold;
    color: var(--text-secondary);
}
.btn-close:hover {
    opacity: 1;
}

/* Global Printing Stylesheet - Hides sidebar, topbar, buttons, footers */
@media print {
    .sidebar,
    .top-bar,
    .no-print,
    .btn,
    button,
    footer,
    .sidebar-menu,
    .top-actions,
    form.no-print {
        display: none !important;
    }
    
    body {
        background: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .main-content,
    .content-wrapper,
    .container-fluid {
        margin-left: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-shadow: none !important;
        border: none !important;
    }
    
    .glass-card,
    .card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}

/* ==========================================
   SUPER RESPONSIVE SYSTEM FOR ALL DEVICES
   (Mobiles, Tablets, Desktops, 4K Projectors)
   ========================================== */

/* Max width wrapper for images/SVGs to prevent overflow */
img, svg {
    max-width: 100%;
    height: auto;
}

/* Prevent CSS Grid items from blowing out and overflowing the viewport */
*[style*="display: grid"] > *, *[style*="display:grid"] > *, .stats-grid > * {
    min-width: 0;
}

/* Base style enhancements */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    width: 100% !important;
    overflow-x: auto !important;
}

/* 1. Large screens, Ultra-wide, Projectors & Cinema (>= 1600px) */
@media (min-width: 1600px) {
    .main-content {
        max-width: 1400px;
        margin-left: auto !important;
        margin-right: auto !important;
        box-shadow: 0 0 50px rgba(15, 23, 42, 0.05);
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        border-radius: 8px;
    }
}
@media (min-width: 2500px) {
    /* 4K and Cinema screens */
    .main-content {
        max-width: 1800px;
    }
    html {
        font-size: 18px; /* Scale up typography for readability from distance */
    }
}

/* 2. Tablets and Medium Devices (<= 992px) */
@media (max-width: 992px) {
    /* Responsive Grid overrides for inline styles (excludes scrollable tooth selection) */
    div[style*="grid-template-columns"]:not([style*="min-width"]) {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    form[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) !important;
        gap: 15px !important;
    }
}

/* 3. Standard Mobile Devices (<= 768px) */
@media (max-width: 768px) {
    .main-content {
        padding: 15px !important;
    }
    
    .glass-card {
        padding: 16px !important;
    }
    
    /* Responsive layout classes */
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }
    
    /* Ensure table-responsive doesn't crop outlines */
    .table-responsive {
        padding: 2px;
    }
}

/* 4. Small Mobiles (<= 576px) */
@media (max-width: 576px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    .top-bar {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }
    
    .top-actions {
        width: 100% !important;
        justify-content: space-between !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .page-title {
        font-size: 1.4rem !important;
    }
    
    /* Force elements display wrap */
    div[style*="display: flex"], div[style*="display:flex"] {
        flex-wrap: wrap !important;
    }
    
    #admin_map {
        height: 250px !important;
    }
    
    #notification-dropdown {
        position: fixed !important;
        top: 75px !important;
        left: 15px !important;
        right: 15px !important;
        width: auto !important;
        max-width: none !important;
        z-index: 10000 !important;
    }
}

/* 5. Extremely Small Mobiles / Keypad Phones (<= 360px) */
@media (max-width: 360px) {
    html {
        font-size: 12px !important;
    }
    
    .main-content {
        padding: 8px !important;
    }
    
    .glass-card {
        padding: 10px !important;
    }
    
    .btn {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
    }
    
    /* Ensure sidebar overlays completely cover the screen on tiny devices */
    .sidebar {
        width: 100% !important;
        max-width: 100% !important;
        transform: translateX(-100%);
    }
    .sidebar-open {
        transform: translateX(0) !important;
    }
}

/* Responsive Flex Groups for Forms/Filters and Inputs */
.responsive-flex-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .responsive-flex-group {
        flex-direction: column !important;
        gap: 15px !important;
        align-items: stretch !important;
    }
    .responsive-flex-group > div {
        flex: 1 1 100% !important;
        width: 100% !important;
        min-width: 100% !important;
    }
    .form-control, input, select, textarea {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}


