/* ============================================================
   Lavis ERP — Design System
   Dark navy sidebar | Light gray content | Gradient stat cards
   ============================================================ */

:root {
    --sidebar-bg:       #1a2235;
    --sidebar-hover:    #243050;
    --sidebar-active:   #2d3f66;
    --sidebar-text:     #94a3b8;
    --sidebar-text-act: #ffffff;
    --sidebar-label:    #64748b;
    --sidebar-width:    220px;

    --content-bg:       #f0f2f5;
    --card-bg:          #ffffff;
    --topbar-bg:        #ffffff;
    --topbar-border:    #e2e8f0;

    --primary:          #2563eb;
    --primary-hover:    #1d4ed8;
    --success:          #16a34a;
    --warning:          #d97706;
    --danger:           #dc2626;
    --info:             #0891b2;

    --text-primary:     #1e293b;
    --text-secondary:   #64748b;
    --text-muted:       #94a3b8;
    --border:           #e2e8f0;
    --border-radius:    10px;
    --shadow:           0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:        0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);

    /* Stat card gradients */
    --grad-purple:  linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --grad-green:   linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --grad-pink:    linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --grad-cyan:    linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --grad-orange:  linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    --grad-blue:    linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: .9rem;
    color: var(--text-primary);
    background: var(--content-bg);
}

/* ── RTL Arabic ── */
[dir="rtl"] body { font-family: 'Segoe UI', 'Tahoma', sans-serif; }

/* ── Layout ── */
.erp-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.erp-sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    overflow-y: auto;
    transition: width .25s ease;
}

[dir="rtl"] .erp-sidebar { left: auto; right: 0; }

.erp-sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
    text-decoration: none;
}

.erp-sidebar-brand .brand-icon {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.erp-sidebar-brand .brand-text { line-height: 1.2; }
.erp-sidebar-brand .brand-name {
    font-size: .95rem;
    font-weight: 700;
    color: #fff;
    display: block;
}
.erp-sidebar-brand .brand-sub {
    font-size: .7rem;
    color: var(--sidebar-text);
    display: block;
}

/* Nav sections */
.erp-nav { flex: 1; padding: .75rem 0; }
.erp-nav-section { padding: .75rem 1rem .25rem; }
.erp-nav-label {
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--sidebar-label);
}

.erp-nav-item {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .52rem 1rem;
    margin: .1rem .5rem;
    border-radius: 7px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .85rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    cursor: pointer;
}

.erp-nav-item i { font-size: .95rem; width: 18px; text-align: center; }

.erp-nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-act);
}

.erp-nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-act);
}

/* ── Topbar ── */
.erp-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: 60px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 900;
    box-shadow: var(--shadow);
}

[dir="rtl"] .erp-topbar { left: 0; right: var(--sidebar-width); }

.erp-topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.erp-topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.erp-lang-btn {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .3rem .7rem;
    font-size: .8rem;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s;
}
.erp-lang-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.erp-user-badge {
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
}

.erp-user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem;
    font-weight: 600;
}

.erp-user-info { line-height: 1.3; }
.erp-user-name { font-size: .83rem; font-weight: 600; color: var(--text-primary); }
.erp-user-role { font-size: .7rem; color: var(--text-muted); }

/* ── Main content ── */
.erp-content {
    margin-left: var(--sidebar-width);
    margin-top: 60px;
    min-height: calc(100vh - 60px);
    padding: 1.5rem;
    background: var(--content-bg);
    flex: 1;
}

[dir="rtl"] .erp-content { margin-left: 0; margin-right: var(--sidebar-width); }

/* ── Stat Cards ── */
.stat-card {
    border-radius: var(--border-radius);
    padding: 1.25rem 1.5rem;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    min-height: 100px;
}

.stat-card::before {
    content: '';
    position: absolute;
    right: -20px; top: -20px;
    width: 100px; height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,.12);
}

.stat-card-purple { background: var(--grad-purple); }
.stat-card-green  { background: var(--grad-green); }
.stat-card-pink   { background: var(--grad-pink); }
.stat-card-cyan   { background: var(--grad-cyan); }
.stat-card-orange { background: var(--grad-orange); }
.stat-card-blue   { background: var(--grad-blue); }

.stat-card-label { font-size: .8rem; opacity: .9; margin-bottom: .35rem; }
.stat-card-value { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-card-sub   { font-size: .75rem; opacity: .85; margin-top: .25rem; min-height: 1rem; }
.stat-card-icon  { font-size: 2.5rem; opacity: .35; align-self: center; }
.stat-card > div:first-child { display: flex; flex-direction: column; justify-content: center; }

/* ── Content cards ── */
.erp-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.erp-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.erp-card-title {
    font-size: .93rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: .5rem;
}

.erp-card-body { padding: 1.25rem; }

/* ── Tables ── */
.erp-table { width: 100%; border-collapse: collapse; }
.erp-table th {
    background: #f8fafc;
    padding: .65rem 1rem;
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    text-align: left;
}
[dir="rtl"] .erp-table th { text-align: right; }
.erp-table td {
    padding: .7rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    font-size: .87rem;
    color: var(--text-primary);
    vertical-align: middle;
}
.erp-table tr:hover td { background: #f8fafc; }
.erp-table tr:last-child td { border-bottom: none; }

/* ── Badges ── */
.erp-badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
}
.erp-badge-success { background: #dcfce7; color: #15803d; }
.erp-badge-danger  { background: #fee2e2; color: #dc2626; }
.erp-badge-warning { background: #fef3c7; color: #d97706; }
.erp-badge-info    { background: #e0f2fe; color: #0369a1; }
.erp-badge-gray    { background: #f1f5f9; color: #475569; }
.erp-badge-purple  { background: #f3e8ff; color: #7c3aed; }

/* ── Buttons ── */
.btn-erp {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem 1rem;
    border-radius: 7px;
    font-size: .85rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}
.btn-erp-primary { background: var(--primary); color: #fff; }
.btn-erp-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-erp-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-erp-outline:hover { background: var(--content-bg); }
.btn-erp-danger { background: var(--danger); color: #fff; }
.btn-erp-sm { padding: .3rem .7rem; font-size: .78rem; }

/* ── Forms ── */
.erp-form-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: .35rem;
    display: block;
}

.erp-form-control {
    width: 100%;
    padding: .5rem .85rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: .87rem;
    color: var(--text-primary);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.erp-form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.erp-input-group {
    position: relative;
    display: flex;
    align-items: center;
}
.erp-input-group .erp-input-icon {
    position: absolute;
    left: .75rem;
    color: var(--text-muted);
    font-size: .9rem;
    pointer-events: none;
}
[dir="rtl"] .erp-input-group .erp-input-icon { left: auto; right: .75rem; }
.erp-input-group .erp-form-control { padding-left: 2.25rem; }
[dir="rtl"] .erp-input-group .erp-form-control { padding-left: .85rem; padding-right: 2.25rem; }

/* ── Page header ── */
.erp-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.erp-page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.erp-breadcrumb {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: .15rem;
    display: flex;
    align-items: center;
    gap: .3rem;
    flex-wrap: wrap;
}
.erp-breadcrumb a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color .15s;
}
.erp-breadcrumb a:hover { color: var(--primary-hover); text-decoration: underline; }
.erp-breadcrumb .bc-sep { color: var(--text-muted); font-size: .7rem; }
.erp-breadcrumb .bc-current { color: var(--text-secondary); }

/* ── Alert ── */
.erp-alert {
    padding: .75rem 1rem;
    border-radius: 8px;
    font-size: .86rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.erp-alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.erp-alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.erp-alert-info   { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* ── Pagination ── */
.erp-pagination {
    display: flex;
    align-items: center;
    gap: .25rem;
    justify-content: flex-end;
    margin-top: 1rem;
}
.erp-page-btn {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    font-size: .82rem;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}
.erp-page-btn:hover, .erp-page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ── Sidebar user info ── */
.erp-sidebar-user {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex;
    align-items: center;
    gap: .65rem;
}
.erp-sidebar-user .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .78rem;
    font-weight: 700;
    flex-shrink: 0;
}
.erp-sidebar-user .user-name {
    font-size: .82rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.erp-sidebar-user .user-role {
    font-size: .7rem;
    color: var(--sidebar-text);
}

/* ── erp-label alias ── */
.erp-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: .35rem;
    display: block;
}

/* ── Sidebar overlay (mobile) ── */
.erp-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 999;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity .25s ease;
}
.erp-sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* ── Mobile close button inside sidebar ── */
.erp-sidebar-close {
    display: none;
    position: absolute;
    top: .75rem;
    right: .75rem;
    width: 30px; height: 30px;
    border-radius: 6px;
    background: rgba(255,255,255,.08);
    border: none;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
[dir="rtl"] .erp-sidebar-close { right: auto; left: .75rem; }
.erp-sidebar-close:hover { background: rgba(255,255,255,.15); }

/* ── Mobile responsive ── */
@media (max-width: 768px) {
    .erp-sidebar {
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(.4,0,.2,1);
        z-index: 1000;
    }
    [dir="rtl"] .erp-sidebar { transform: translateX(100%); }
    .erp-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.3);
    }
    [dir="rtl"] .erp-sidebar.open {
        box-shadow: -4px 0 24px rgba(0,0,0,.3);
    }
    .erp-sidebar-close { display: flex; }

    .erp-content {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 1rem;
    }
    .erp-topbar { left: 0 !important; right: 0 !important; }

    /* Stat cards: 2-up on mobile */
    .stat-card-value { font-size: 1.45rem; }
    .stat-card { padding: 1rem 1.1rem; min-height: 88px; }
    .stat-card-icon { font-size: 2rem; }

    /* Page header stack on mobile */
    .erp-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: .75rem;
    }
    .erp-page-header > *:last-child {
        width: 100%;
    }

    /* Table wrapper already overflow-x:auto, make sure cells don't shrink too small */
    .erp-table th, .erp-table td { padding: .55rem .65rem; font-size: .82rem; }

    /* Form groups full width */
    .erp-form-control { font-size: .87rem; }

    /* Button group wrapping */
    .d-flex.gap-2 { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .erp-content { padding: .75rem; }
    .erp-page-title { font-size: 1.05rem; }
    .stat-card-value { font-size: 1.25rem; }
    .erp-topbar { padding: 0 .85rem; }
    .erp-topbar-title { font-size: .95rem; }
}

/* ── Login page ── */
.login-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px rgba(0,0,0,.4);
}

.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-logo .logo-icon {
    width: 52px; height: 52px;
    background: var(--primary);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
    margin-bottom: .75rem;
}

.login-logo h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 .25rem;
}

.login-logo p {
    font-size: .82rem;
    color: var(--text-muted);
    margin: 0;
}

.login-demo {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.login-demo p {
    font-size: .75rem;
    color: var(--text-muted);
    margin-bottom: .5rem;
}

.login-demo table {
    width: 100%;
    font-size: .75rem;
}

.login-demo td { padding: .15rem .5rem; color: var(--text-secondary); }
.login-demo td:first-child { font-weight: 600; color: var(--text-primary); text-align: right; }
