/* =========================================
   B2B Order Portal Global Stylesheet
   ========================================= */

:root {
    /* Color Palette */
    --primary-color: #0f172a; /* Slate 900 */
    --primary-hover: #1e293b; /* Slate 800 */
    --accent-color: #2563eb;  /* Blue 600 */
    --accent-hover: #1d4ed8;  /* Blue 700 */
    --danger-color: #ef4444;  /* Red 500 */
    --danger-bg: #fee2e2;     /* Red 100 */
    --success-color: #10b981; /* Emerald 500 */
    --success-bg: #d1fae5;    /* Emerald 100 */
    --admin-accent: #6d28d9;  /* Violet 700 */
    --admin-accent-hover: #5b21b6;
    
    /* Backgrounds & Surfaces */
    --bg-main: #f8fafc;       /* Slate 50 */
    --bg-card: #ffffff;
    --border-color: #e2e8f0;  /* Slate 200 */
    
    /* Text */
    --text-main: #0f172a;
    --text-muted: #334155;    /* Slate 700 - Darker for higher contrast */
    
    /* Layout */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --transition-speed: 0.3s;
    
    /* Shadows */
    --shadow-sm: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

html, body {
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    width: 100%;
    overflow-x: hidden; /* Prevent horizontal sliding */
    position: relative;
    -webkit-font-smoothing: antialiased;
}

* {
    -webkit-tap-highlight-color: transparent;
}

/* --- Utility Classes --- */
/* .hidden moved to bottom for highest specificity */

/* --- Mockup Login UI --- */
.login-wrapper {
    width: 100%;
    min-height: 100vh;
    background: url('background.jpg') no-repeat center center fixed;
    background-size: cover;
    display: flex;
    position: relative;
}

.login-bg-overlay {
    flex: 1;
    background: rgba(0,0,0,0.4);
}

.admin-overlay {
    background: linear-gradient(rgba(15, 23, 42, 0.7), rgba(15, 23, 42, 0.9)), url('background.jpg') no-repeat center center;
    background-size: cover;
}

.admin-theme {
    background: rgba(15, 23, 42, 0.95) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

button.btn-admin {
    background: linear-gradient(135deg, #6d28d9 0%, #4c1d95 100%) !important;
    color: white !important;
    border: none !important;
    padding: 14px 28px !important;
    border-radius: 8px !important;
    font-weight: 700 !important;
    font-size: 15px !important;
    cursor: pointer !important;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1) !important;
    transition: all 0.3s !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    appearance: none !important;
    -webkit-appearance: none !important;
}

button.btn-admin:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1) !important;
    filter: brightness(1.1) !important;
}

.login-sidebar {
    width: 380px;
    background: rgba(20, 20, 20, 0.9); /* Dark semi-transparent */
    backdrop-filter: blur(5px);
    padding: 60px 40px;
    display: flex;
    flex-direction: column;
    z-index: 2;
    box-shadow: 10px 0 30px rgba(0,0,0,0.3);
}

.logo-area {
    margin-bottom: 20px; /* Reduced to allow for larger image logo */
    text-align: center;
}

.main-logo {
    max-width: 100%;
    height: auto;
    max-height: 120px;
    object-fit: contain;
}

/* Base button styles to reset defaults */
button {
    font-family: inherit;
    transition: all var(--transition-speed);
}

.login-subtitle {
    color: #94a3b8;
    font-size: 14px;
    margin-bottom: 30px;
}

.input-group {
    margin-bottom: 25px;
}

.input-group label {
    display: block;
    color: var(--primary-color); /* Use dark color by default for white dashboard cards */
    font-size: 14px;
    margin-bottom: 8px;
    font-weight: 600;
}

/* White labels for the dark login sidebar ONLY */
.login-sidebar .input-group label {
    color: #f1f5f9;
}

.input-group input, select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--primary-color);
    font-size: 15px;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-speed);
    appearance: none;
    -webkit-appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 40px;
    cursor: pointer;
}

.input-group input:focus, select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    background-color: #ffffff;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

button.btn-login, button.btn-primary {
    background: linear-gradient(135deg, #eab308 0%, #ca8a04 100%) !important;
    color: #1e293b !important;
    border: none !important;
    padding: 12px 28px !important;
    border-radius: 8px !important;
    font-weight: 700 !important;
    font-size: 15px !important;
    cursor: pointer !important;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1) !important;
    transition: all 0.3s !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    appearance: none !important;
    -webkit-appearance: none !important;
}

.btn-login:hover, .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    filter: brightness(1.1);
}

.btn-login:active, .btn-primary:active {
    transform: translateY(0);
}

.btn-reset {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 12px 28px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.btn-reset:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.sidebar-footer {
    margin-top: auto;
    font-size: 12px;
    color: #3b82f6;
}

.sidebar-footer a {
    color: #3b82f6;
    text-decoration: none;
}

/* Spinner adjustment for new btn */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #000;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-cancel {
    background-color: var(--danger-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-cancel:hover {
    background-color: #dc2626; /* Darker red */
}

/* Premium Secondary Button (Sleek Silver/Slate style) */
.btn-secondary-premium {
    background: #f8fafc !important;
    color: #334155 !important;
    border: 1px solid #cbd5e1 !important;
    padding: 10px 22px !important;
    border-radius: 8px !important;
    font-weight: 700 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    box-shadow: var(--shadow-sm) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    text-decoration: none !important;
}

.btn-secondary-premium:hover {
    background: #fff !important;
    border-color: #94a3b8 !important;
    transform: translateY(-1.5px) !important;
    box-shadow: var(--shadow-md) !important;
    color: #0f172a !important;
}

.btn-secondary-premium:active {
    transform: translateY(0) !important;
}

/* Special High-Contrast Style for Admin Create Order Button in Topbar */
.btn-admin-accent {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
    color: white !important;
    border: none !important;
    padding: 10px 24px !important;
    border-radius: 25px !important; /* Pill style to stand out */
    font-weight: 700 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    transition: all 0.3s ease !important;
}

.btn-admin-accent:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4) !important;
    filter: brightness(1.1) !important;
}

@media (max-width: 600px) {
    .login-sidebar {
        width: 100%;
        background: rgba(20, 20, 20, 0.95);
    }
}

/* --- Tom Select Overrides --- */
.ts-control {
    padding: 14px 18px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--border-radius) !important;
    font-size: 16px !important;
    background-color: #f8fafc !important;
    box-shadow: var(--shadow-sm) !important;
    min-height: 54px;
    display: flex;
    align-items: center;
    transition: all var(--transition-speed) !important;
}

.ts-control.focus {
    border-color: var(--accent-color) !important;
    background-color: #ffffff !important;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1) !important;
}

.ts-wrapper.single .ts-control::after {
    border-color: var(--text-muted) transparent transparent transparent !important;
    border-width: 5px 5px 0 5px !important;
}

.ts-wrapper {
    margin-bottom: 20px;
}

/* =========================================
   Responsive Dashboard & Grid System
   ========================================= */

.dashboard-container {
    width: 100%;
    max-width: 1400px; /* Increased for better desktop experience */
    margin: 0 auto;
    padding: 24px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}

.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); /* Fluid grid */
    gap: 24px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
}

.stat-lbl { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-val { font-size: 26px; font-weight: 700; color: var(--primary-color); }
.stat-val.danger { color: var(--danger-color); }

.form-section, .history-section, .card {
    background: var(--bg-card);
    padding: 25px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.form-section h3, .history-section h3, .card-header h3 {
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 700;
}

/* Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px; /* Base minimum to spark overflow scroll if needed */
}

th, td {
    padding: 16px 18px; /* More spacious for premium feel */
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

th {
    color: var(--text-muted);
    font-weight: 700;
    background-color: #f8fafc;
    text-transform: uppercase;
    font-size: 11px; /* Slightly smaller for tighter uppercase headers */
    letter-spacing: 0.8px;
}

/* Admin Specific */
.topbar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 15px 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    margin-bottom: 30px;
}

.admin-action {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}

.status-pending { background: #fef3c7; color: #d97706; }
.status-completed { background: var(--success-bg); color: var(--success-color); }

/* =========================================
   Perfect Mobile Optimization (@Media)
   ========================================= */

@media (max-width: 768px) {
    .dashboard-container { padding: 15px; }
    
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .stat-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
        align-items: center;
        text-align: center;
    }

    .stat-val { font-size: 24px; }
    
    .form-section, .history-section, .card {
        padding: 20px;
    }

    .topbar {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    /* Prevent text stretching on small screens */
    h2 { font-size: 20px; }
    h1, .stat-val { word-break: break-word; }

    .table-container {
        margin: 0 -20px; /* Negative margin to bleed to edges on mobile if needed */
        padding: 0 20px;
        width: calc(100% + 40px);
    }

    .sync-grid {
        grid-template-columns: 1fr !important;
    }

    .sync-card {
        width: 100% !important;
    }

    /* Fixed Aspect Ratio for Logo */
    .logo-box {
        width: 54px;
        height: 54px;
        font-size: 18px;
        flex-shrink: 0;
    }
    
    /* Ensure action buttons are full width on mobile */
    .quick-actions-btns {
        width: 100%;
    }
    .quick-actions-btns button, .quick-actions-btns a {
        width: 100% !important;
    }
}

/* Ultra Small Devices (e.g. iPhone SE) */
@media (max-width: 380px) {
    .login-card {
        padding: 30px 20px;
    }
    
    .dashboard-container {
        padding: 12px;
        width: 100%;
        max-width: 100vw;
        margin: 0;
        box-sizing: border-box;
    }
    
    .stat-card {
        padding: 15px;
    }
}

/* --- Modal Styles --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: #1e293b; /* Dark slate */
    color: #f1f5f9;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    position: relative;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    border: 1px solid #334155;
    animation: modalFadeIn 0.3s ease-out;
}

.modal-body {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 20px;
    font-size: 14px;
    line-height: 1.6;
    color: #cbd5e1;
}

.modal-body h3 {
    margin: 20px 0 10px;
    font-size: 16px;
    color: #f1f5f9;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #ffffff;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    .modal-content {
        padding: 20px;
    }
}

/* --- Admin Quick Actions Card --- */
.quick-actions-card {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    color: white;
    padding: 30px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%; /* Ensure it takes full width */
}

.quick-actions-info h2 {
    margin: 0 0 5px 0;
    font-size: 22px;
}

.quick-actions-info p {
    margin: 0;
    color: #94a3b8;
    font-size: 14px;
}

.btn-admin-xl {
    background: linear-gradient(135deg, #6d28d9 0%, #4c1d95 100%);
    color: white !important;
    border: none;
    padding: 16px 32px;
    border-radius: var(--border-radius);
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(109, 40, 217, 0.3);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-admin-xl:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 25px rgba(109, 40, 217, 0.4);
    filter: brightness(1.1);
}

@media (max-width: 768px) {
    .top-bar {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        height: 60px !important;
        padding: 0 15px !important;
        width: 100% !important;
    }
    
    .btn-logout {
        width: auto !important;
        padding: 6px 16px !important;
        font-size: 13px !important;
    }

    .quick-actions-card {
        flex-direction: column !important;
        text-align: center !important;
        padding: 20px !important;
        width: 100% !important;
        margin: 0 0 20px 0 !important;
        box-sizing: border-box !important;
    }

    .quick-actions-btns {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 10px !important;
    }

    .btn-admin-xl {
        width: 100% !important;
        justify-content: center !important;
        margin: 0 !important;
        padding: 15px !important;
    }

    .dashboard-container {
        padding: 10px !important;
        width: 100% !important;
    }
}

.sync-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); /* Adaptive grid */
    gap: 24px;
    padding: 20px 0;
}

.sync-card {
    flex: 1;
    min-width: 250px; /* Reduced from 300px to prevent overflow on portrait mobile */
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    background: #1e293b; /* Premium Dark Slate */
    color: white;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s;
}

.sync-card:hover {
    transform: translateY(-2px);
}

.sync-card h4 {
    margin-bottom: 12px;
    font-size: 18px;
    color: #eab308; /* Gold accent */
}

.sync-card p {
    font-size: 13px;
    color: #cbd5e1;
    margin-bottom: 15px;
    line-height: 1.5;
}

.sync-card input[type="file"] {
    margin-bottom: 15px;
    width: 100%;
    font-size: 12px;
    color: #94a3b8;
}

/* =========================================
   MOBILE RESPONSIVE FIX (TABLE SCROLL)
   ========================================= */

@media (max-width: 768px) {
    .dashboard-container {
        padding: 10px !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin: 0 !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    .table-container {
        width: 100% !important;
        overflow-x: auto !important;
        display: block !important;
        -webkit-overflow-scrolling: touch !important;
        border: 1px solid var(--border-color) !important;
        background: white !important;
        margin: 0 0 20px 0 !important;
    }

    table {
        min-width: 850px !important; /* Forces scroll to keep data readable */
        width: 100% !important;
    }

    th, td {
        padding: 12px 10px !important;
        font-size: 13px !important;
        white-space: nowrap !important;
    }

    .top-bar {
        flex-direction: row !important;
        justify-content: space-between !important;
        padding: 10px 15px !important;
        height: 60px !important;
        background: white !important;
        width: 100% !important;
    }

    .btn-logout {
        padding: 6px 12px !important;
        font-size: 12px !important;
        margin: 0 !important;
    }

    .quick-actions-card {
        padding: 20px 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
}

.hidden { display: none !important; }

/* Enhanced Error Banner for high contrast */
.error-banner {
    background-color: #fee2e2;
    color: #b91c1c;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #fecdd3;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Modern Logout Button */
.logout-btn, .btn-logout {
    background: rgba(239, 68, 68, 0.1) !important;
    color: #ef4444 !important;
    border: 1px solid rgba(239, 68, 68, 0.2) !important;
    padding: 8px 20px !important;
    border-radius: 25px !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.05) !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.logout-btn:hover, .btn-logout:hover {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    color: #ffffff !important;
    border-color: transparent !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3) !important;
}
