/* ============================================================
   Stoxbay Design Tokens — sb-tokens.css
   Single source of truth for all visual properties.
   Loaded by all 5 layout files before module-specific CSS.
   ============================================================ */

/* --- Self-hosted Fonts --- */
@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/plus-jakarta-sans-400.woff2') format('woff2');
}
@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('../fonts/plus-jakarta-sans-500.woff2') format('woff2');
}
@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/plus-jakarta-sans-600.woff2') format('woff2');
}
@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/plus-jakarta-sans-700.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/inter-400.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('../fonts/inter-500.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/inter-600.woff2') format('woff2');
}

/* --- Design Tokens --- */
:root {
    /* Colors — Primary */
    --sb-teal: #00D4AA;
    --sb-teal-light: #33DDBB;
    --sb-teal-dark: #00B894;
    --sb-teal-soft: #E6FAF5;
    --sb-navy: #1B2A4A;
    --sb-navy-light: #2D3F5E;
    --sb-navy-dark: #0F1A2E;
    --sb-white: #FFFFFF;
    --sb-off-white: #F8FAFB;

    /* Colors — Semantic */
    --sb-success: #22C55E;
    --sb-warning: #F59E0B;
    --sb-error: #EF4444;
    --sb-info: #3B82F6;

    /* Colors — Gray Scale */
    --sb-gray-50: #F8FAFC;
    --sb-gray-100: #F1F5F9;
    --sb-gray-200: #E2E8F0;
    --sb-gray-300: #CBD5E1;
    --sb-gray-400: #94A3B8;
    --sb-gray-500: #64748B;
    --sb-gray-600: #475569;
    --sb-gray-700: #334155;
    --sb-gray-800: #1E293B;
    --sb-gray-900: #111827;

    /* Typography */
    --sb-font-heading: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --sb-font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --sb-fs-h1: clamp(1.75rem, 1.5rem + 0.8vw, 2.25rem);
    --sb-fs-h2: clamp(1.375rem, 1.2rem + 0.6vw, 1.75rem);
    --sb-fs-h3: clamp(1.125rem, 1rem + 0.4vw, 1.375rem);
    --sb-fs-body: 1rem;
    --sb-fs-body-sm: 0.875rem;
    --sb-fs-caption: 0.75rem;

    /* Spacing (8px grid) */
    --sb-space-xs: 4px;
    --sb-space-sm: 8px;
    --sb-space-md: 16px;
    --sb-space-lg: 24px;
    --sb-space-xl: 32px;
    --sb-space-2xl: 48px;
    --sb-space-3xl: 64px;

    /* Border Radius */
    --sb-radius-sm: 4px;
    --sb-radius-md: 8px;
    --sb-radius-lg: 12px;
    --sb-radius-xl: 16px;
    --sb-radius-full: 9999px;

    /* Shadows */
    --sb-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --sb-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --sb-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --sb-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --sb-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Z-Index Layers */
    --sb-z-base: 0;
    --sb-z-dropdown: 100;
    --sb-z-sticky: 200;
    --sb-z-fixed: 300;
    --sb-z-modal-backdrop: 400;
    --sb-z-modal: 500;
    --sb-z-popover: 600;
    --sb-z-tooltip: 700;
    --sb-z-preloader: 9999;
    --sb-z-sidebar: 1000;
    --sb-z-overlay: 999;

    /* Transitions */
    --sb-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Base Typography --- */
body {
    font-family: var(--sb-font-body);
    font-size: var(--sb-fs-body);
    color: var(--sb-gray-800);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--sb-font-heading);
}

h1 { font-size: var(--sb-fs-h1); }
h2 { font-size: var(--sb-fs-h2); }
h3 { font-size: var(--sb-fs-h3); }

/* --- Focus Indicators (Accessibility) --- */
:focus-visible {
    outline: 2px solid var(--sb-teal);
    outline-offset: 2px;
}
:focus:not(:focus-visible) {
    outline: none;
}

/* --- Button System --- */
.sb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sb-space-sm);
    min-height: 44px;
    padding: var(--sb-space-sm) var(--sb-space-md);
    border: 2px solid transparent;
    border-radius: var(--sb-radius-md);
    font-family: var(--sb-font-body);
    font-size: var(--sb-fs-body-sm);
    font-weight: 600;
    line-height: 1.5;
    text-decoration: none;
    cursor: pointer;
    transition: var(--sb-transition);
    white-space: nowrap;
}
.sb-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sb-btn-primary {
    background-color: var(--sb-teal);
    color: var(--sb-white);
    border-color: var(--sb-teal);
}
.sb-btn-primary:hover:not(:disabled) {
    background-color: var(--sb-teal-dark);
    border-color: var(--sb-teal-dark);
    color: var(--sb-white);
    text-decoration: none;
}

.sb-btn-secondary {
    background-color: var(--sb-white);
    color: var(--sb-navy);
    border-color: var(--sb-navy);
}
.sb-btn-secondary:hover:not(:disabled) {
    background-color: var(--sb-gray-50);
    color: var(--sb-navy);
    text-decoration: none;
}

.sb-btn-danger {
    background-color: var(--sb-error);
    color: var(--sb-white);
    border-color: var(--sb-error);
}
.sb-btn-danger:hover:not(:disabled) {
    opacity: 0.9;
    color: var(--sb-white);
    text-decoration: none;
}

.sb-btn-ghost {
    background-color: transparent;
    color: var(--sb-teal);
    border-color: transparent;
}
.sb-btn-ghost:hover:not(:disabled) {
    background-color: var(--sb-teal-soft);
    text-decoration: none;
}

/* ── U4: Skeleton Screen ─────────────────────────────── */
.sb-skeleton {
    background: linear-gradient(90deg, var(--sb-gray-200) 25%, var(--sb-gray-100) 50%, var(--sb-gray-200) 75%);
    background-size: 200% 100%;
    animation: sb-shimmer 1.5s infinite;
    border-radius: var(--sb-radius-md);
    min-height: 1em;
}
.sb-skeleton-text { height: 1em; margin-bottom: 0.5em; }
.sb-skeleton-title { height: 1.5em; width: 60%; margin-bottom: 0.75em; }
.sb-skeleton-card { height: 120px; }
.sb-skeleton-table-row { height: 44px; margin-bottom: 4px; }
@keyframes sb-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.sb-skeleton[aria-hidden] { pointer-events: none; }

/* ── U4: NProgress Color Override ─────────────────────── */
#nprogress .bar { background: var(--sb-teal); }
#nprogress .peg { box-shadow: 0 0 10px var(--sb-teal), 0 0 5px var(--sb-teal); }

/* ── U4: Button Loading State ─────────────────────────── */
.sb-btn-loading { pointer-events: none; opacity: 0.65; }
.sb-btn-loading .spinner-border { width: 1em; height: 1em; border-width: 0.15em; }

/* ── U4: Flash Message Improvements ───────────────────── */
.sb-flash {
    position: relative;
    animation: sb-flash-in 0.3s ease;
}
.sb-flash .sb-flash-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    opacity: 0.5;
    cursor: pointer;
    padding: 0;
    color: inherit;
}
.sb-flash .sb-flash-close:hover { opacity: 1; }
.sb-flash-dismiss {
    animation: sb-flash-in 0.3s ease, sb-flash-out 0.5s ease 4.5s forwards;
}
@keyframes sb-flash-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes sb-flash-out {
    from { opacity: 1; }
    to { opacity: 0; height: 0; margin: 0; padding: 0; overflow: hidden; }
}

/* ── U4: Empty State Component ────────────────────────── */
.sb-empty-state {
    text-align: center;
    padding: var(--sb-space-xl) var(--sb-space-lg);
    color: var(--sb-gray-500);
}
.sb-empty-state i {
    font-size: 3rem;
    margin-bottom: var(--sb-space-md);
    display: block;
    color: var(--sb-gray-300);
}
.sb-empty-state h5 {
    color: var(--sb-gray-600);
    margin-bottom: var(--sb-space-sm);
}
.sb-empty-state p { margin-bottom: var(--sb-space-md); }

/* --- Print Styles --- */
@media print {
    .sidebar, .bottom-nav, .navbar, .no-print,
    nav, aside, .btn, .dropdown, .modal, .toast,
    .preloader, .dataTables_paginate, .dataTables_length,
    .dataTables_filter, .export_csv, #export, #export1,
    .dt-button, .dt-buttons { display: none !important; }
    #nprogress, .toastify, .swal2-container { display: none !important; }

    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    * {
        box-shadow: none !important;
        text-shadow: none !important;
    }

    a[href]::after { content: " (" attr(href) ")"; }
    a[href^="#"]::after,
    a[href^="javascript"]::after { content: ""; }

    h2, h3 { break-after: avoid; }
    table, figure { break-inside: avoid; }
    tr { break-inside: avoid; }

    @page {
        size: A4 portrait;
        margin: 15mm 20mm;
    }
}

/* --- Numeric Data Formatting --- */
.dataTable td, .kpi-value, .stock_no, .invoice_no, .shift_no, .p_number {
    font-variant-numeric: tabular-nums;
}

/* === U3 Touch Targets === */
.form-control, .custom-select { min-height: 44px; }
.page-link { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.nav-link { min-height: 44px; display: inline-flex; align-items: center; }

/* === U3 Sticky Submit Buttons === */
.form-actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: var(--sb-z-sticky);
    background: var(--sb-white);
    padding: var(--sb-space-sm) var(--sb-space-md);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    will-change: transform;
    padding-bottom: calc(var(--sb-space-sm) + env(safe-area-inset-bottom, 0px));
}

/* === U3 Table Scroll Indicator === */
.table-scroll-indicator {
    position: relative;
}
.table-scroll-indicator::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.08));
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s;
}
.table-scroll-indicator.scrolled-end::after {
    opacity: 0;
}

/* === U3 DataTables Mobile Overrides === */
@media (max-width: 767px) {
    .dataTables_filter { width: 100%; float: none; text-align: left; margin-bottom: 8px; }
    .dataTables_filter input { width: 100% !important; max-width: 100%; }
    .dataTables_paginate .paginate_button { min-width: 44px; min-height: 44px; padding: 8px 12px !important; margin: 2px; }
    .dataTables_length { width: 100%; float: none; margin-bottom: 8px; }
}

/* === U3 Sidebar Off-Canvas === */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: var(--sb-z-overlay);
}

@media (max-width: 767px) {
    body.open .sidebar-overlay {
        display: block;
    }
}
