:root {
    --sidebar-width: 250px;
    --brand: #128c7e;
    --brand-dark: #075e54;
    --brand-light: #25d366;
}

body {
    font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", sans-serif;
    font-size: 0.925rem;
    background-color: var(--bs-body-bg);
}

/* ── هيكل اللوحة ─────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--brand-dark);
    color: #e9f5f2;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
    font-weight: 700;
}

.brand-mark {
    background: var(--brand-light);
    color: #06382f;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-weight: 800;
}

.sidebar-nav {
    padding: .6rem .5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav .nav-link {
    color: #cfe7e1;
    border-radius: 8px;
    padding: .5rem .75rem;
    display: flex;
    align-items: center;
    gap: .55rem;
    font-size: .9rem;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
}

.nav-ico {
    width: 1.25rem;
    text-align: center;
    opacity: .9;
}

.nav-section {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .55;
    padding: .9rem .75rem .3rem;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem 1rem;
    background: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title {
    font-weight: 600;
    font-size: 1.02rem;
}

.topbar-actions {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: .4rem;
}

.balance-chip {
    background: rgba(37, 211, 102, .14);
    color: #128c7e;
    border-radius: 999px;
    padding: .25rem .8rem;
    font-weight: 700;
    font-size: .85rem;
}

.app-content {
    padding: 1.1rem;
    flex: 1 1 auto;
}

/* ── البطاقات والإحصاءات ─────────────────────────────────── */
.stat-card {
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    padding: .9rem 1rem;
    background: var(--bs-body-bg);
    height: 100%;
}

.stat-label {
    font-size: .78rem;
    color: var(--bs-secondary-color);
    margin-bottom: .3rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.15;
}

.stat-hint {
    font-size: .75rem;
    color: var(--bs-secondary-color);
}

.card {
    border-radius: 12px;
}

.table > :not(caption) > * > * {
    padding: .55rem .6rem;
}

.table thead th {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--bs-secondary-color);
    font-weight: 600;
}

code, .mono {
    font-family: Consolas, "Courier New", monospace;
    direction: ltr;
    unicode-bidi: embed;
}

.num {
    direction: ltr;
    unicode-bidi: embed;
    display: inline-block;
}

/* ── شاشات الدخول ────────────────────────────────────────── */
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #075e54, #128c7e 55%, #25d366);
}

.auth-shell {
    width: min(460px, 94vw);
    padding: 1rem;
}

.auth-card {
    background: var(--bs-body-bg);
    border-radius: 16px;
    padding: 1.8rem;
    box-shadow: 0 20px 45px rgba(0, 0, 0, .25);
}

/* ── ربط واتساب ──────────────────────────────────────────── */
.qr-box {
    display: grid;
    place-items: center;
    padding: 1.2rem;
    border: 2px dashed var(--bs-border-color);
    border-radius: 14px;
    min-height: 280px;
}

.qr-box img {
    width: 260px;
    height: 260px;
    image-rendering: pixelated;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin-inline-end: .35rem;
}

.status-dot.on { background: #25d366; box-shadow: 0 0 0 3px rgba(37, 211, 102, .2); }
.status-dot.off { background: #dc3545; }
.status-dot.wait { background: #ffc107; }

/* ── المحادثات ───────────────────────────────────────────── */
.chat-wrap {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 0;
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    overflow: hidden;
    height: calc(100vh - 190px);
}

.chat-list {
    border-inline-end: 1px solid var(--bs-border-color);
    overflow-y: auto;
}

.chat-list a {
    display: block;
    padding: .7rem .8rem;
    border-bottom: 1px solid var(--bs-border-color);
    color: inherit;
    text-decoration: none;
}

.chat-list a:hover, .chat-list a.active {
    background: var(--bs-tertiary-bg);
}

.chat-body {
    display: flex;
    flex-direction: column;
    background: var(--bs-tertiary-bg);
}

.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.bubble {
    max-width: 70%;
    padding: .5rem .75rem;
    border-radius: 12px;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    font-size: .9rem;
}

.bubble.out {
    align-self: flex-end;
    background: #d9fdd3;
    color: #08321f;
    border-color: #bdf0b3;
}

.bubble .meta {
    font-size: .68rem;
    opacity: .65;
    margin-top: .25rem;
}

/* ── المخطط البياني البسيط ───────────────────────────────── */
.spark {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 90px;
}

.spark span {
    flex: 1 1 auto;
    background: var(--brand);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    opacity: .85;
}

.spark span:hover { opacity: 1; }

/* ── الاستجابة ───────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        inset-inline-start: 0;
        top: 0;
        z-index: 1040;
        transform: translateX(-105%);
        transition: transform .2s ease;
    }

    [dir="rtl"] .app-sidebar { transform: translateX(105%); }

    .app-sidebar.open { transform: translateX(0) !important; }

    .chat-wrap {
        grid-template-columns: 1fr;
        height: auto;
    }
}

@media print {
    .app-sidebar, .app-topbar, .btn, form.d-inline { display: none !important; }
    .app-content { padding: 0; }
}
