/* OMS custom styles – badges and utilities (Tailwind handles layout/buttons/forms) */
:root {
    --color-brand-blue: #2B52A3;
    --color-brand-orange: #F28F2D;
    /* Native form controls follow the APP theme, not the OS, so inputs stay
       readable in light mode even on a dark-mode machine. */
    color-scheme: light;
}
html.dark {
    color-scheme: dark;
}
/* Dark body bg — lifted midnight-blue (not near-black) */
html.dark body { background-color: #13192b; }
/* Sidebar: slightly elevated surface in dark mode */
html.dark #app-sidebar { background-color: #18223c !important; border-color: #29395a !important; }

/* Cards – slightly stronger definition */
.rounded-xl.border.bg-white { box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.05); }
.shadow-sm { box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05), 0 1px 3px -1px rgb(0 0 0 / 0.05); }

/* Focus rings – preserve keyboard accessibility (WCAG 2.4.7).
   We hide the default outline only when the user is using a pointing device
   (no :focus-visible match) and keep a strong outline for keyboard users. */
:focus-visible {
    outline: 2px solid var(--color-brand-blue);
    outline-offset: 2px;
}
.focus-ring-brand:focus { box-shadow: 0 0 0 2px var(--color-brand-blue); }
/* Skip-link helper for keyboard users (revealed when focused) */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--color-brand-blue);
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; outline: 2px solid #fff; outline-offset: 2px; }

/* Status badges – keep semantic colors */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-submitted { background: #dbeafe; color: #1d4ed8; }
.badge-admin_approved { background: #d1fae5; color: #047857; }
.badge-admin_rejected { background: #fee2e2; color: #b91c1c; }
.badge-warehouse_processing { background: #fef3c7; color: #b45309; }
.badge-warehouse_ready { background: #d1fae5; color: #047857; }
.badge-invoice_generated { background: #e0e7ff; color: #4338ca; }
.badge-dispatched { background: #cffafe; color: #0e7490; }
.badge-completed { background: #d1fae5; color: #047857; }
.badge-on_hold { background: #fed7aa; color: #c2410c; }
.badge-cancelled { background: #e2e8f0; color: #64748b; }
.badge-returned { background: #e0e7ff; color: #4338ca; }

/* Toasts – top-right, slide-in, 10s auto-dismiss */
.toast {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 24rem;
    padding: 0;
    border-radius: 0.75rem;
    font-size: 1rem;
    box-shadow: 0 14px 32px -10px rgb(15 23 42 / 0.28), 0 4px 10px -2px rgb(15 23 42 / 0.10);
    border: 1px solid rgb(0 0 0 / 0.06);
    opacity: 0;
    transform: translateX(1.25rem);
    transition: opacity 0.35s ease, transform 0.35s ease;
}
.toast-visible { opacity: 1; transform: translateX(0); }
.toast-success {
    background: #ecfdf5;
    color: #065f46;
    border-left: 4px solid #10b981;
}
.toast-warning {
    background: #fffbeb;
    color: #92400e;
    border-left: 4px solid #f59e0b;
}
.toast-error {
    background: #fef2f2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
}
.toast-inner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    pointer-events: auto;
    padding: 1rem 1rem 1rem 0.875rem;
}
.toast-body { flex: 1; min-width: 0; }
.toast-label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    opacity: 0.85;
}
.toast-message {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 500;
    line-height: 1.45;
    word-wrap: break-word;
}
.toast-close {
    flex-shrink: 0;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.65;
    padding: 0 0.125rem;
    margin-top: -0.125rem;
    color: inherit;
}
.toast-close:hover { opacity: 1; }

/* Searchable select — native select hidden, custom combobox */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.searchable-select-list:not(.hidden) { display: block; }

/* Inline button spinner — used by async form submit (Mail, PDF-heavy actions) */
@keyframes btn-async-spin {
    to { transform: rotate(360deg); }
}
.btn-async-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.375em;
    vertical-align: -0.15em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-async-spin 0.65s linear infinite;
    opacity: 0.9;
}
button[type="submit"]:disabled .btn-async-spinner {
    opacity: 1;
}

/* Toast icon + progress bar */
.toast-icon {
    flex-shrink: 0;
    width: 1.375rem;
    height: 1.375rem;
    margin-top: 0.1rem;
}
.toast-icon svg { width: 100%; height: 100%; }
.toast-success .toast-icon { color: #10b981; }
.toast-warning .toast-icon { color: #f59e0b; }
.toast-error .toast-icon { color: #ef4444; }
.toast-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background: rgb(0 0 0 / 0.06);
}
.toast-progress-bar {
    height: 100%;
    width: 100%;
    transform-origin: left center;
    animation-name: toast-progress-shrink;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}
.toast-success .toast-progress-bar { background: #10b981; }
.toast-warning .toast-progress-bar { background: #f59e0b; }
.toast-error .toast-progress-bar { background: #ef4444; }
@keyframes toast-progress-shrink {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* Dark toast variants */
.dark .toast-success { background: #05281e; color: #a7f3d0; border-color: rgb(16 185 129 / 0.35); }
.dark .toast-warning { background: #2a1c05; color: #fcd34d; border-color: rgb(245 158 11 / 0.35); }
.dark .toast-error { background: #2a0d0d; color: #fca5a5; border-color: rgb(239 68 68 / 0.35); }
.dark .toast-progress { background: rgb(255 255 255 / 0.08); }

/* ── Sidebar nav ─────────────────────────────────────────────────────────── */
.nav-icon { opacity: 0.9; transition: color 0.15s ease; }
.nav-link-active .nav-icon { opacity: 1; }
.nav-active-bar {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 62%;
    width: 3px;
    border-radius: 0 4px 4px 0;
    background: transparent;
    transition: background-color 0.15s ease;
}
.nav-link-active .nav-active-bar { background: var(--color-brand-blue); }
.dark .nav-link-active .nav-active-bar { background: #a5b4fc; }
.nav-group-label {
    margin: 1rem 0 0.25rem;
    padding: 0.5rem 0.75rem 0;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}
.nav-group-first { margin-top: 0.25rem; }

/* ── Collapsible nav group toggles ──────────────────────────────────────── */
.nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-top: 1rem;
    padding: 0.35rem 0.75rem 0.1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.4;
    border-radius: 0.375rem;
    transition: color 0.15s ease, background-color 0.15s ease;
    text-align: left;
}
.nav-group-toggle:hover { color: var(--color-brand-blue); background-color: rgb(43 82 163 / 0.07); }
.dark .nav-group-toggle:hover { color: #a5b4fc; background-color: rgb(99 102 241 / 0.12); }
.nav-group-toggle:focus-visible { outline: 2px solid var(--color-brand-blue); outline-offset: 1px; }
.nav-group-chevron {
    width: 0.875rem;
    height: 0.875rem;
    flex-shrink: 0;
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.nav-group-toggle[aria-expanded="false"] .nav-group-chevron { transform: rotate(-90deg); }
/* Collapsible panel */
.nav-group-items {
    overflow: hidden;
    max-height: 800px;
    opacity: 1;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.22s ease;
}
.nav-group-items.nav-group-closed {
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
}
/* Collapsed icon-only mode: all group panels always visible */
body.sidebar-collapsed .nav-group-items {
    max-height: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    overflow: visible;
}
body.sidebar-collapsed .nav-group-toggle { display: none; }

/* Collapsed sidebar (desktop only) → icon-only with hover tooltips */
@media (min-width: 768px) {
    body.sidebar-collapsed .app-sidebar { width: 4.25rem; }
    body.sidebar-collapsed .nav-label,
    body.sidebar-collapsed .nav-group-label { display: none; }
    body.sidebar-collapsed .app-sidebar .nav-link {
        justify-content: center;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    body.sidebar-collapsed .app-sidebar .nav-link::after {
        content: attr(title);
        position: absolute;
        left: calc(100% + 0.5rem);
        top: 50%;
        transform: translateY(-50%);
        white-space: nowrap;
        background: #0f172a;
        color: #fff;
        padding: 0.3rem 0.55rem;
        border-radius: 0.375rem;
        font-size: 0.75rem;
        font-weight: 500;
        box-shadow: 0 6px 16px -4px rgb(0 0 0 / 0.35);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s ease;
        z-index: 60;
    }
    body.sidebar-collapsed .app-sidebar .nav-link:hover::after { opacity: 1; }
}

/* Mobile off-canvas drawer slide-in */
body.sidebar-open .app-sidebar { transform: translateX(0); }

/* ── Interaction polish ─────────────────────────────────────────────────── */
.card-clickable {
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card-clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px -8px rgb(15 23 42 / 0.18);
}
/* Primary buttons: subtle gradient on hover + tactile press */
a.bg-brand-blue,
button.bg-brand-blue,
.bg-brand-blue[type="submit"] {
    transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
a.bg-brand-blue:hover,
button.bg-brand-blue:hover {
    background-image: linear-gradient(120deg, #2B52A3 0%, #3a55b3 100%);
    box-shadow: 0 8px 20px -8px rgb(43 82 163 / 0.6);
}
.bg-brand-blue:active { transform: scale(0.98); }

/* Table rows: gentle hover tint */
tbody tr { transition: background-color 0.12s ease; }
tbody tr:hover { background-color: rgb(43 82 163 / 0.04); }
.dark tbody tr:hover { background-color: rgb(255 255 255 / 0.04); }

/* ── Dark mode: lifted midnight-blue palette — clear hierarchy, not near-black ── */

/* ─ Backgrounds: 3-level depth (page → card → input) ─ */
.dark .bg-white { background-color: #1c2640 !important; }
.dark .bg-slate-50,
.dark .bg-gray-50 { background-color: #141c2f !important; }
.dark .bg-slate-100,
.dark .bg-gray-100 { background-color: #243050 !important; }
.dark .bg-slate-200,
.dark .bg-gray-200 { background-color: #2d3d5c !important; }

/* ─ Text — crisp contrast hierarchy ─ */
.dark .text-slate-900,
.dark .text-slate-800,
.dark .text-slate-700,
.dark .text-gray-900,
.dark .text-gray-800 { color: #f1f5f9; }
.dark .text-slate-600,
.dark .text-slate-500,
.dark .text-gray-600,
.dark .text-gray-500 { color: #94a3b8; }
.dark .text-slate-400,
.dark .text-gray-400 { color: #64748b; }

/* ─ Borders ─ */
.dark .border-slate-100,
.dark .border-slate-200,
.dark .border-slate-300,
.dark .border-gray-100,
.dark .border-gray-200,
.dark .border-gray-300 { border-color: #2e3d5a; }
.dark .divide-slate-100 > :not([hidden]) ~ :not([hidden]),
.dark .divide-slate-200 > :not([hidden]) ~ :not([hidden]) { border-color: #2e3d5a; }

/* ─ Tinted alert / info boxes ─ */
.dark .bg-blue-50 { background-color: rgb(99 102 241 / 0.14) !important; }
.dark .bg-indigo-50,
.dark .bg-purple-50 { background-color: rgb(99 102 241 / 0.14) !important; }
.dark .bg-emerald-50,
.dark .bg-green-50 { background-color: rgb(16 185 129 / 0.14) !important; }
.dark .bg-amber-50,
.dark .bg-yellow-50 { background-color: rgb(245 158 11 / 0.14) !important; }
.dark .bg-red-50 { background-color: rgb(239 68 68 / 0.14) !important; }
.dark .bg-orange-50 { background-color: rgb(249 115 22 / 0.14) !important; }
.dark .text-blue-700, .dark .text-blue-800, .dark .text-blue-900 { color: #93c5fd; }
.dark .text-indigo-700, .dark .text-indigo-800 { color: #c7d2fe; }
.dark .text-purple-700, .dark .text-purple-800 { color: #d8b4fe; }
.dark .text-emerald-700, .dark .text-emerald-800,
.dark .text-green-700, .dark .text-green-800 { color: #6ee7b7; }
.dark .text-amber-700, .dark .text-amber-800, .dark .text-amber-900,
.dark .text-yellow-800 { color: #fcd34d; }
.dark .text-red-700, .dark .text-red-800, .dark .text-red-900 { color: #fca5a5; }
.dark .text-orange-700, .dark .text-orange-800 { color: #fdba74; }
.dark .text-cyan-700, .dark .text-cyan-800 { color: #67e8f9; }

/* ─ Inputs — lifted bg, branded focus glow ─ */
.dark input,
.dark select,
.dark textarea {
    background-color: #1c2640;
    border-color: #2e3d5a;
    color: #f1f5f9;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.dark input:focus,
.dark select:focus,
.dark textarea:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgb(99 102 241 / 0.18) !important;
    outline: none;
}
.dark input::placeholder,
.dark textarea::placeholder { color: #64748b; }

/* ─ Status badges — tinted dark variants ─ */
.dark .badge-draft { background: rgb(148 163 184 / 0.12); color: #94a3b8; }
.dark .badge-submitted { background: rgb(59 130 246 / 0.18); color: #93c5fd; }
.dark .badge-admin_approved { background: rgb(16 185 129 / 0.18); color: #6ee7b7; }
.dark .badge-admin_rejected { background: rgb(239 68 68 / 0.18); color: #fca5a5; }
.dark .badge-warehouse_processing { background: rgb(245 158 11 / 0.18); color: #fcd34d; }
.dark .badge-warehouse_ready { background: rgb(16 185 129 / 0.18); color: #6ee7b7; }
.dark .badge-invoice_generated { background: rgb(99 102 241 / 0.18); color: #c7d2fe; }
.dark .badge-dispatched { background: rgb(6 182 212 / 0.18); color: #67e8f9; }
.dark .badge-completed { background: rgb(16 185 129 / 0.18); color: #6ee7b7; }
.dark .badge-on_hold { background: rgb(249 115 22 / 0.18); color: #fdba74; }
.dark .badge-cancelled { background: rgb(100 116 139 / 0.12); color: #64748b; }
.dark .badge-returned { background: rgb(99 102 241 / 0.18); color: #c7d2fe; }

/* ─ Card interactive glow in dark mode ─ */
.dark .rounded-xl.border, .dark .rounded-lg.border {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.dark .rounded-xl.border:hover, .dark .rounded-lg.border:hover {
    border-color: #3d5280;
    box-shadow: 0 4px 24px -6px rgb(0 0 0 / 0.4), 0 0 0 1px rgb(99 102 241 / 0.1);
}

/* ── Global search (command palette) ────────────────────────────────────── */
.gsearch-empty {
    padding: 1.75rem 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: #94a3b8;
}
.gsearch-group-label {
    padding: 0.5rem 0.75rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}
.gsearch-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: #1e293b;
    cursor: pointer;
}
.dark .gsearch-item { color: #e2e8f0; }
.gsearch-item-main {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
}
.gsearch-item-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gsearch-item-sub {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gsearch-badge {
    flex-shrink: 0;
    border-radius: 9999px;
    background: #eef2ff;
    color: #4338ca;
    padding: 0.1rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: capitalize;
}
.dark .gsearch-badge { background: rgb(99 102 241 / 0.18); color: #c7d2fe; }
.gsearch-item.gsearch-active {
    background: #eff4ff;
}
.dark .gsearch-item.gsearch-active { background: rgb(99 102 241 / 0.16); }
.gsearch-item.gsearch-active .gsearch-item-title { color: var(--color-brand-blue); }
.dark .gsearch-item.gsearch-active .gsearch-item-title { color: #c7d2fe; }
.gsearch-kbd {
    display: inline-block;
    min-width: 1.1rem;
    padding: 0.05rem 0.3rem;
    border-radius: 0.25rem;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    color: #64748b;
}
.dark .gsearch-kbd { border-color: #2e3d5a; background: #1c2640; color: #94a3b8; }

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .card-clickable:hover { transform: none; }
}

/* ── Print: isolate the customer statement for a clean, shareable PDF ─────── */
@media print {
    body * { visibility: hidden !important; }
    #customer-statement,
    #customer-statement * { visibility: visible !important; }
    #customer-statement {
        position: absolute;
        inset: 0 auto auto 0;
        width: 100%;
        margin: 0;
        padding: 0;
        border: none !important;
        box-shadow: none !important;
        background: #fff !important;
        color: #111827 !important;
    }
    /* Force print-friendly ink on white regardless of light/dark theme. */
    #customer-statement *,
    #customer-statement a { color: #111827 !important; background: transparent !important; }
    #customer-statement thead tr,
    #customer-statement tfoot tr { background: #f3f4f6 !important; }
    #customer-statement .no-print { display: none !important; }
    #customer-statement table { width: 100% !important; min-width: 0 !important; }
    @page { margin: 14mm; }
}
