/* ============================================================
   INVENTORY OMS — Application Stylesheet v1.6.0
   Full mobile responsiveness as standard
   ============================================================ */

/* --- Variables --- */
:root {
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --sidebar-bg: #0f1923;
    --sidebar-text: #a8b5c3;
    --sidebar-active-bg: #1e3a5f;
    --sidebar-active-text: #ffffff;
    --sidebar-hover-bg: rgba(255,255,255,0.06);
    --sidebar-section-color: #4a6080;
    --brand-color: #2563eb;
    --brand-light: #dbeafe;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --info: #0284c7;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow: 0 4px 12px rgba(0,0,0,.10);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--surface-alt);
    -webkit-font-smoothing: antialiased;
}

/* --- App Shell --- */
.app-wrapper {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease, transform 0.25s ease;
    z-index: 100;
    scrollbar-width: thin;
    scrollbar-color: #2a3f55 transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #2a3f55; border-radius: 4px; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}
.brand-icon {
    width: 36px; height: 36px;
    background: var(--brand-color);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0;
}
.brand-name {
    font-weight: 700;
    color: white;
    font-size: 14px;
    display: block;
    line-height: 1.2;
}
.brand-version {
    font-size: 10px;
    color: var(--sidebar-section-color);
}

.sidebar-nav { padding: 12px 0 20px; flex: 1; }

.nav-section {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--sidebar-section-color);
    padding: 16px 16px 4px;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 400;
    transition: background 0.15s, color 0.15s;
    margin: 1px 8px;
    border-radius: 6px;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 500; }
.nav-item i { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }

/* --- App Body --- */
.app-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
}

/* --- Topbar --- */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex; align-items: center;
    transition: color 0.15s;
    flex-shrink: 0;
}
.sidebar-toggle:hover { color: var(--text-primary); }

.page-heading {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu-btn {
    display: flex; align-items: center; gap: 8px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 10px 4px 4px;
    color: var(--text-primary);
    font-size: 13px;
    white-space: nowrap;
}
.user-menu-btn:hover { background: var(--surface-alt); }

.user-avatar {
    width: 28px; height: 28px;
    background: var(--brand-color);
    color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

/* --- Content Area --- */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.main-content {}

/* --- Cards --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin: 0; }
.card-body { padding: 16px; }

/* --- Stats / KPI Cards --- */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    height: 100%;
}
.stat-icon {
    width: 42px; height: 42px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green  { background: #dcfce7; color: #15803d; }
.stat-icon.orange { background: #ffedd5; color: #c2410c; }
.stat-icon.red    { background: #fee2e2; color: #b91c1c; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.teal   { background: #ccfbf1; color: #0f766e; }

.stat-value { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-label { font-size: 11px; color: var(--text-secondary); font-weight: 500; }

/* --- Tables (Desktop) --- */
.table { font-size: 13px; }
.table thead th {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    padding: 9px 12px;
    background: var(--surface-alt);
    white-space: nowrap;
}
.table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text-primary);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-alt); }
.table-responsive {
    border-radius: var(--radius);
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* ============================================================
   MOBILE CARD TABLE — replaces tables on small screens
   Use .mobile-card-list to show stacked cards on mobile
   ============================================================ */
.mobile-card-list { display: none !important; }

@media (max-width: 767px) {
    .mobile-card-list { display: block !important; }
    .desktop-table-wrap { display: none !important; }

    .mobile-card-item {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 14px 16px;
        margin-bottom: 10px;
    }
    .mobile-card-item .mcl-row {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 6px;
        font-size: 13px;
    }
    .mobile-card-item .mcl-row:last-child { margin-bottom: 0; }
    .mobile-card-item .mcl-label {
        color: var(--text-muted);
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex-shrink: 0;
        min-width: 80px;
    }
    .mobile-card-item .mcl-value { text-align: right; word-break: break-word; }
    .mobile-card-item .mcl-title {
        font-weight: 600;
        font-size: 14px;
        color: var(--text-primary);
        margin-bottom: 8px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border);
    }
    .mobile-card-item .mcl-actions {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid var(--border);
    }
}

/* --- Badges --- */
.badge { font-weight: 500; font-size: 11px; padding: 3px 8px; }

/* --- Buttons --- */
.btn { font-size: 13px; font-weight: 500; border-radius: 6px; }
.btn-primary { background: var(--brand-color); border-color: var(--brand-color); }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 5px; }

/* --- Forms --- */
.form-label { font-weight: 500; font-size: 13px; color: var(--text-primary); }
.form-control, .form-select {
    font-size: 13.5px;
    border-color: var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text-primary);
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.form-text { font-size: 12px; }

/* --- Alerts --- */
.alert {
    border-radius: 6px;
    font-size: 13.5px;
    border: none;
    padding: 12px 16px;
}
.alert-success { background: #f0fdf4; color: #15803d; }
.alert-danger   { background: #fff1f2; color: #b91c1c; }
.alert-warning  { background: #fffbeb; color: #92400e; }
.alert-info     { background: #eff6ff; color: #1e40af; }

/* --- Page Header Row --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.page-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* --- Filter Bar --- */
.filter-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 14px;
}
.filter-bar .form-control,
.filter-bar .form-select { max-width: 200px; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 36px; margin-bottom: 10px; display: block; opacity: 0.4; }
.empty-state p { font-size: 13px; margin-bottom: 0; }

/* --- Stock quantity colors --- */
.stock-low  { color: var(--danger); font-weight: 600; }
.stock-ok   { color: var(--success); font-weight: 600; }
.stock-zero { color: var(--danger); font-weight: 700; }

/* --- Breadcrumb --- */
.breadcrumb { font-size: 13px; }
.breadcrumb-item.active { color: var(--text-secondary); }

/* --- Product image thumbnail --- */
.product-thumb {
    width: 38px; height: 38px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border);
}
.product-thumb-placeholder {
    width: 38px; height: 38px;
    border-radius: 6px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 16px;
}

/* --- Modal --- */
.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 600; }

/* --- Login Page --- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f1923 0%, #1e3a5f 100%);
    padding: 20px;
}
.login-card {
    background: white;
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .logo-icon {
    width: 52px; height: 52px;
    background: var(--brand-color);
    border-radius: 14px;
    display: inline-flex;
    align-items: center; justify-content: center;
    color: white;
    font-size: 26px;
    margin-bottom: 10px;
}
.login-logo h1 { font-size: 19px; font-weight: 700; color: var(--text-primary); }
.login-logo p  { font-size: 12px; color: var(--text-secondary); }

/* --- Pagination --- */
.pagination .page-link { font-size: 13px; color: var(--brand-color); }
.pagination .page-item.active .page-link {
    background: var(--brand-color);
    border-color: var(--brand-color);
}

/* --- Dropdown --- */
.dropdown-item { font-size: 13px; }
.dropdown-header { font-size: 13px; padding: 8px 16px; }

/* --- Permission grid --- */
.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}
.permission-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-alt);
    cursor: pointer;
    transition: border-color 0.15s;
}
.permission-item:hover { border-color: var(--brand-color); }
.permission-item input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; flex-shrink: 0; }
.permission-item label { font-size: 12.5px; cursor: pointer; margin: 0; }
.permission-item input:checked ~ label { color: var(--brand-color); font-weight: 500; }

/* --- Mobile Product Cards (Order Create) --- */
.mobile-product-card {
    background: var(--surface-alt);
}
.mobile-product-card:last-child { border-bottom: none !important; }

/* ============================================================
   MOBILE RESPONSIVE — Global Rules
   ============================================================ */
@media (max-width: 767px) {

    /* Sidebar hidden off-canvas on mobile */
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        z-index: 200;
        width: 240px;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.4); }
    .app-body { width: 100%; }

    /* Content padding tighter on mobile */
    .content-area { padding: 12px; }

    /* Page header stacks on mobile */
    .page-header { margin-bottom: 12px; }
    .page-header h2 { font-size: 16px; }

    /* Filter bar full-width inputs */
    .filter-bar { gap: 6px; }
    .filter-bar .form-control,
    .filter-bar .form-select { max-width: 100%; flex: 1 1 140px; }

    /* Topbar */
    .page-heading { font-size: 13px; }

    /* Stat cards smaller text on mobile */
    .stat-value { font-size: 18px; }
    .stat-label { font-size: 10px; }
    .stat-icon  { width: 36px; height: 36px; font-size: 17px; }

    /* Card body padding */
    .card-body { padding: 12px; }
    .card-header { padding: 10px 12px; }

    /* Table scrollable on mobile — prevent layout break */
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Make sure tables don't cause page overflow */
    .table { min-width: 600px; }

    /* Form rows stack on mobile */
    .row > [class*="col-md"] { margin-bottom: 0; }

    /* Modals full-screen on mobile */
    .modal-dialog { margin: 8px; }

    /* Stat cards 2-column grid on mobile */
    .row.g-3 > .col-6 { padding: 4px; }
}

@media (max-width: 575px) {
    .content-area { padding: 10px; }
    .btn-xs { padding: 3px 6px; font-size: 11px; }

    /* Single column stat cards on very small screens */
    .stat-card { padding: 10px 12px; }
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   RESPONSIVE TABLE HELPERS
   Wrap <table> in .rtable-wrap to get scrollable on mobile
   while keeping desktop behaviour
   ============================================================ */
.rtable-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
}
.rtable-wrap .table { min-width: 500px; }

/* ============================================================
   ORDER DETAIL — Timeline
   ============================================================ */
.timeline .timeline-item { position: relative; }

/* ============================================================
   DASHBOARD — Recent orders table mobile scroll
   ============================================================ */
/* desktop tables: always visible on desktop, scrollable, hidden on mobile via media query above */
.desktop-table-wrap {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
