/* ═══════════════════════════════════════════════════════════════
   ERP PRO — Global Design System
   Pure CSS (no @apply — compatible with pre-built Tailwind)
   ═══════════════════════════════════════════════════════════════ */

/* ── TOKENS ──────────────────────────────────────────────────── */
:root {
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-light: #eef2ff;
    --color-primary-ring: rgba(79,70,229,0.2);
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-surface: #ffffff;
    --color-surface-rgb: 255, 255, 255;
    --color-surface-alt: #f8fafc;
    --color-border: #e2e8f0;
    --color-text: #334155;
    --color-text-muted: #94a3b8;
    --color-text-heading: #0f172a;
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 3.5rem;
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --z-sidebar: 100;
    --z-topbar: 90;
    --z-modal: 200;
    --z-tooltip: 300;
}
.dark {
    --color-surface: #0f172a;
    --color-surface-rgb: 15, 23, 42;
    --color-surface-alt: #1e293b;
    --color-border: #1e293b;
    --color-text: #cbd5e1;
    --color-text-muted: #64748b;
    --color-text-heading: #f1f5f9;
    --color-primary-light: rgba(79,70,229,0.15);
}

/* ── RESET & BASE ────────────────────────────────────────────── */
[x-cloak] { display: none !important; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--color-text);
    background: var(--color-surface-alt);
}

/* ── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 10px; }
.dark ::-webkit-scrollbar-thumb { background: #334155; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ── APP SHELL ───────────────────────────────────────────────── */
.app-shell {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--color-surface-alt);
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: var(--sidebar-width);
    box-shadow: var(--shadow-sm);
}

.app-sidebar.collapsed,
.sidebar-is-collapsed .app-sidebar {
    width: var(--sidebar-collapsed);
}

/* Sidebar Sections */
.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    gap: 0.75rem;
    overflow: hidden;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Scrollbar fine pour la nav */
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 10px; }

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    flex-shrink: 0;
}

/* Sidebar Text & Transitions */
.sidebar-text {
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s ease, visibility 0.2s;
}

.sidebar-is-collapsed .sidebar-text {
    display: none !important;
}

.app-sidebar.collapsed .sidebar-text {
    opacity: 0;
    visibility: hidden;
    width: 0;
}

/* ── MAIN CONTENT ────────────────────────────────────────────── */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-main.sidebar-collapsed,
.sidebar-is-collapsed .app-main {
    margin-left: var(--sidebar-collapsed);
}

.app-topbar {
    height: var(--topbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    flex-shrink: 0;
    z-index: var(--z-topbar);
    backdrop-filter: blur(8px);
    background: rgba(var(--color-surface-rgb), 0.8);
}

.app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    background: var(--color-surface-alt);
    position: relative;
    scrollbar-gutter: stable;
}

.app-content-inner {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Backdrop mobile */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: calc(var(--z-sidebar) - 1);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* ── CARDS ────────────────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card:hover {
    box-shadow: var(--shadow-md);
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 1.25rem; }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    line-height: 1.5;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    box-shadow: 0 2px 4px var(--color-primary-ring);
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-secondary {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: #e2e8f0; }
.dark .btn-secondary:hover { background: #334155; }

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}
.btn-ghost:hover { background: var(--color-surface-alt); color: var(--color-text); }

.btn-icon {
    padding: 0.5rem;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text-muted);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-icon:hover { background: var(--color-surface-alt); color: var(--color-text); }

/* ── FORM INPUTS ─────────────────────────────────────────────── */
.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-ring);
}
.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
}
.form-group { margin-bottom: 1rem; }

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}
textarea.form-input { resize: vertical; min-height: 4rem; }

/* ── SIDEBAR NAV ─────────────────────────────────────────────── */
.nav-group-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1rem 0.25rem 1rem;
    font-size: 0.625rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    cursor: pointer;
    border: none;
    background: none;
    transition: color 0.2s;
}
.nav-group-label:hover { color: var(--color-text); }
.nav-group-label svg {
    width: 0.75rem !important;
    height: 0.75rem !important;
    color: var(--color-text-muted);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    margin: 0 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    color: var(--color-text);
    transition: all 0.2s;
    text-decoration: none;
}
.nav-link svg {
    width: 1.25rem !important;
    height: 1.25rem !important;
    flex-shrink: 0;
    color: var(--color-text-muted);
}
.nav-link:hover {
    background: var(--color-surface-alt);
}
.nav-link.active {
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 700;
}
.nav-link.active svg {
    color: var(--color-primary);
}

.nav-link-pos {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 900;
    border-radius: var(--radius-lg);
    background: var(--color-success);
    color: #fff;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(16,185,129,0.2);
}
.nav-link-pos:hover { background: #059669; transform: translateY(-1px); }
.nav-link-pos svg {
    width: 1.25rem !important;
    height: 1.25rem !important;
}

/* ── TABLES ──────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

/* ── PRODUCT SEARCH AUTOCOMPLETE ─────────────────────────────── */
.search-product-wrapper {
    position: relative;
}
.product-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 9999;
    max-height: 300px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    margin-top: 2px;
}
.dropdown-visible-table {
    min-height: 280px;
}
@media (min-width: 1025px) {
    .dropdown-visible-table {
        overflow: visible !important;
        min-height: auto;
    }
}
.table {
    width: 100%;
    text-align: left;
    font-size: 0.875rem;
    border-collapse: collapse;
}
.table thead th {
    padding: 0.625rem 1.25rem;
    font-size: 0.5625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    background: var(--color-surface-alt);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 1;
}
.table tbody td {
    padding: 0.625rem 1.25rem;
}
.table tbody tr {
    border-bottom: 1px solid var(--color-border);
    transition: background 0.15s;
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover {
    background: rgba(248,250,252,0.5);
}
.dark .table tbody tr:hover {
    background: rgba(30,41,59,0.3);
}

/* ── BADGES ──────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    font-size: 0.625rem;
    font-weight: 700;
    border-radius: 9999px;
}
.badge-success { background: #d1fae5; color: #059669; }
.badge-danger  { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-info    { background: #e0e7ff; color: #4f46e5; }
.badge-neutral { background: #f1f5f9; color: #64748b; }
.dark .badge-success { background: rgba(16,185,129,0.15); }
.dark .badge-danger  { background: rgba(239,68,68,0.15); }
.dark .badge-warning { background: rgba(245,158,11,0.15); }
.dark .badge-info    { background: rgba(79,70,229,0.15); }
.dark .badge-neutral { background: rgba(100,116,139,0.15); }

/* ── STATUS DOT ──────────────────────────────────────────────── */
.status-dot {
    display: inline-block;
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
}

/* ── ALERTS ──────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
}
.alert-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}
.dark .alert-success {
    background: rgba(16,185,129,0.1);
    border-color: rgba(16,185,129,0.2);
    color: #6ee7b7;
}

/* ── KPI CARD ────────────────────────────────────────────────── */
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}
.kpi-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}
.kpi-value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--color-text-heading);
    margin-top: 0.75rem;
    line-height: 1;
}
.kpi-label {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

/* ── EMPTY STATE ─────────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3rem 1rem;
    text-align: center;
}
.empty-state svg { color: #cbd5e1; margin-bottom: 1rem; }
.empty-state h5 { font-weight: 700; color: var(--color-text-muted); }
.empty-state a { font-size: 0.75rem; font-weight: 700; color: var(--color-primary); margin-top: 0.5rem; }
.empty-state a:hover { text-decoration: underline; }

/* ── MODAL ────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-box {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 32rem;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 700;
}
.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ── POS LAYOUT ──────────────────────────────────────────────── */
.pos-shell {
    display: grid;
    grid-template-columns: 1fr 420px;
    height: 100vh;
    overflow: hidden;
}
.pos-products {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.pos-products-header {
    padding: 1rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}
.pos-products-grid {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    align-content: start;
}
.pos-cart {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    overflow: hidden;
}
.pos-cart-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.pos-cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}
.pos-cart-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}
.pos-product-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}
.pos-product-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.pos-cart-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
}

@media (max-width: 1024px) {
    .pos-shell { grid-template-columns: 1fr; }
    .pos-cart { display: none; }
}

/* ── RESPONSIVE ──────────────────────────────────────────────── */
/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .app-main {
        margin-left: var(--sidebar-collapsed);
    }
    .app-sidebar:not(.open) {
        width: var(--sidebar-collapsed);
    }
    .app-sidebar:not(.open) .sidebar-text,
    .app-sidebar:not(.open) .nav-group-label span,
    .app-sidebar:not(.open) .nav-group-label svg {
        display: none;
    }
}

@media (max-width: 768px) {
    .app-main {
        margin-left: 0 !important;
    }
    .app-sidebar {
        transform: translateX(-100%);
        width: 280px !important;
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-sidebar .sidebar-text {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        width: auto !important;
    }
    .app-topbar {
        padding: 0 1rem;
    }
}

/* ── UTILITIES ───────────────────────────────────────────────── */
.truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.animate-fade-in {
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-slide-up {
    animation: slideUp 0.4s ease;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-pulse-soft {
    animation: pulseSoft 2s ease-in-out infinite;
}
@keyframes pulseSoft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
