:root {
    --crm-ink: #172033;
    --crm-muted: #667085;
    --crm-line: #d9dee8;
    --crm-soft-line: #e8ecf3;
    --crm-bg: #f3f5f8;
    --crm-panel: #ffffff;
    --crm-sidebar: #192233;
    --crm-sidebar-2: #202c42;
    --crm-accent: #b08d57;
    --crm-accent-dark: #8f7040;
    --crm-blue: #385f9f;
    --crm-blue-dark: #2d4d80;
    --crm-danger: #b42318;
    --crm-success: #027a48;
    --crm-radius: 8px;
    --crm-shadow: 0 12px 30px rgba(23, 32, 51, .08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    background: var(--crm-bg);
    color: var(--crm-ink);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}
a { color: var(--crm-blue); text-decoration: none; }
a:hover { color: var(--crm-blue-dark); text-decoration: underline; }

/* Local Bootstrap-like essentials, so the UI remains designed without CDN. */
.d-flex { display: flex; }
.d-inline { display: inline; }
.align-items-center { align-items: center; }
.align-items-start { align-items: flex-start; }
.justify-content-between { justify-content: space-between; }
.justify-content-center { justify-content: center; }
.text-end { text-align: end; }
.text-center { text-align: center; }
.text-muted { color: var(--crm-muted) !important; }
.fw-semibold { font-weight: 650; }
.small, small { font-size: .84rem; }
.h3, h1 { font-size: 1.55rem; line-height: 1.2; font-weight: 700; }
.h4 { font-size: 1.25rem; }
.h5, h2 { font-size: 1.05rem; line-height: 1.3; font-weight: 700; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: .25rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-2 { margin-top: .5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.px-0 { padding-left: 0 !important; padding-right: 0 !important; }
.py-2 { padding-top: .5rem !important; padding-bottom: .5rem !important; }
.p-3 { padding: 1rem !important; }
.w-100 { width: 100%; }
.min-vh-100 { min-height: 100vh; }
.container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.row > [class*="col-"] {
    width: auto;
    max-width: none;
    min-width: 0;
}
.g-2 { gap: .5rem; }
.g-3 { gap: 1rem; }
.col-6 { grid-column: span 6; }
.col-12 { grid-column: span 12; }
.col-md-2, .col-md-3, .col-md-4, .col-md-6, .col-lg-5, .col-lg-7 { grid-column: span 12; }
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .85rem 1rem; border-bottom: 1px solid var(--crm-soft-line); vertical-align: middle; }
.table th { color: var(--crm-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; background: #f8fafc; }
.table-hover tbody tr:hover { background: #f8fafc; }
.mb-0.table { margin-bottom: 0; }
.form-label { display: block; color: #344054; font-size: .86rem; font-weight: 650; margin-bottom: .35rem; }
.form-control, .form-select {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cfd6e2;
    border-radius: 7px;
    background: #fff;
    color: var(--crm-ink);
    padding: .55rem .7rem;
    font: inherit;
}
textarea.form-control { min-height: 96px; resize: vertical; }
.form-control:focus, .form-select:focus {
    outline: 3px solid rgba(56, 95, 159, .16);
    border-color: var(--crm-blue);
}
.input-group { display: flex; gap: .5rem; }
.input-group .form-control { flex: 1; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: .48rem .85rem;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    background: #fff;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--crm-blue); color: #fff; border-color: var(--crm-blue); }
.btn-primary:hover { background: var(--crm-blue-dark); color: #fff; }
.btn-outline-secondary { color: #344054; border-color: #cfd6e2; background: #fff; }
.btn-outline-secondary:hover { background: #f2f4f7; color: #1d2939; }
.btn-outline-danger { color: var(--crm-danger); border-color: #f3b8b2; background: #fff; }
.btn-outline-success { color: var(--crm-success); border-color: #a6e4c4; background: #fff; }
.btn-sm { min-height: 32px; padding: .35rem .6rem; font-size: .84rem; }
.btn-link { border: 0; color: var(--crm-blue); background: transparent; }
.alert { border-radius: 7px; padding: .8rem 1rem; margin-bottom: 1rem; }
.alert-danger { background: #fff1f0; border: 1px solid #f3b8b2; color: #912018; }
.list-group { display: grid; }
.list-group-item { padding: .75rem 1rem; border-bottom: 1px solid var(--crm-soft-line); background: #fff; }
.list-group-flush .list-group-item:first-child { border-top: 0; }
.border-top { border-top: 1px solid var(--crm-soft-line); }
.badge, .badge-soft {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .2rem .55rem;
    font-size: .76rem;
    font-weight: 700;
}
.badge-soft { background: #eef4ff; color: #2d4d80; }
.display-6 { font-size: 2rem; font-weight: 750; line-height: 1; }
dl.row { row-gap: .55rem; }
dt { color: var(--crm-muted); font-weight: 700; }
dd { margin: 0; }

/* App shell */
.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--crm-bg);
}
.sidebar {
    position: sticky;
    top: 0;
    width: 282px;
    flex: 0 0 282px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.1rem;
    color: #fff;
    background: linear-gradient(180deg, var(--crm-sidebar), var(--crm-sidebar-2));
    box-shadow: 8px 0 24px rgba(17, 24, 39, .12);
}
.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 52px;
    margin-bottom: 1.25rem;
    color: #fff;
    font-weight: 760;
    font-size: 1.15rem;
}
.brand-mark {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--crm-accent);
    color: #111827;
    font-weight: 800;
}
.sidebar-nav {
    display: grid;
    gap: .35rem;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 44px;
    padding: .7rem .8rem;
    color: rgba(255, 255, 255, .78);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 650;
}
.sidebar-nav a span {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, .7);
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: #fff;
    background: rgba(255, 255, 255, .11);
}
.sidebar-nav a.active {
    box-shadow: inset 3px 0 0 var(--crm-accent);
}
[dir="rtl"] .sidebar-nav a.active {
    box-shadow: inset -3px 0 0 var(--crm-accent);
}
.sidebar-footer {
    margin-top: auto;
    padding: .9rem;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 8px;
    background: rgba(255,255,255,.06);
    color: #fff;
}
.sidebar-footer small { color: rgba(255,255,255,.64); }
.content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.topbar {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.6rem;
    background: rgba(255,255,255,.92);
    border-bottom: 1px solid var(--crm-soft-line);
    backdrop-filter: blur(8px);
}
.topbar-title { font-weight: 750; }
.topbar-subtitle { color: var(--crm-muted); font-size: .84rem; }
.topbar-actions {
    display: flex;
    align-items: center;
    gap: .45rem;
    flex-wrap: wrap;
}
.lang-link,
.logout-link {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    padding: .35rem .65rem;
    border: 1px solid var(--crm-soft-line);
    border-radius: 7px;
    background: #fff;
    color: #344054;
    font-size: .84rem;
    font-weight: 700;
}
.logout-link { color: var(--crm-danger); }
.main-content {
    width: min(1320px, 100%);
    padding: 1.6rem;
}
.card, .table-wrap {
    background: var(--crm-panel);
    border: 1px solid var(--crm-soft-line);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
}
.card h2:first-child,
.card .h5:first-child { margin-top: 0; }
.stat {
    min-height: 118px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-left: 4px solid var(--crm-accent);
}
[dir="rtl"] .stat {
    border-left: 1px solid var(--crm-soft-line);
    border-right: 4px solid var(--crm-accent);
}

/* Login */
.login-page {
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(25,34,51,.86), rgba(56,95,159,.62)),
        linear-gradient(45deg, #eef2f6, #ffffff);
}
.login-card {
    width: min(430px, 100%);
    background: #fff;
    border: 1px solid rgba(255,255,255,.65);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 24px 70px rgba(17, 24, 39, .24);
}
.login-card h1 { margin-top: 0; }

@media (min-width: 768px) {
    .col-md-2 { grid-column: span 2; }
    .col-md-3 { grid-column: span 3; }
    .col-md-4 { grid-column: span 4; }
    .col-md-6 { grid-column: span 6; }
    .col-sm-4 { grid-column: span 4; }
    .col-sm-8 { grid-column: span 8; }
}
@media (min-width: 992px) {
    .col-lg-5 { grid-column: span 5; }
    .col-lg-7 { grid-column: span 7; }
    .p-lg-4 { padding: 1.5rem !important; }
}
@media (min-width: 1200px) {
    .col-xl-3 { grid-column: span 3; }
}
@media (max-width: 991px) {
    .app-shell { display: block; }
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        min-height: auto;
        box-shadow: none;
    }
    .brand { margin-bottom: .75rem; }
    .sidebar-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sidebar-footer { display: none; }
    .topbar { padding: .8rem 1rem; align-items: flex-start; }
    .main-content { padding: 1rem; }
}
@media (max-width: 575px) {
    .sidebar-nav { grid-template-columns: 1fr; }
    .topbar { display: grid; }
    .input-group { display: grid; }
    .col-6 { grid-column: span 12; }
    .table th, .table td { padding: .7rem; }
}
