/* ============ Design tokens ============ */
:root {
    --ink: #0f172a;
    --ink-2: #475569;
    --muted: #94a3b8;
    --line: #e2e8f0;
    --surface: #f4f6f8;
    --card: #ffffff;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --accent-soft: #ccfbf1;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
}

html, body {
    font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--surface);
    color: var(--ink);
}

h3 {
    font-weight: 600;
    font-size: 1.35rem;
    letter-spacing: -0.01em;
}

/* ============ App shell ============ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.content {
    flex-grow: 1;
    padding: 28px 32px;
    width: 100%;
    min-width: 0; /* let flex children shrink so tables can scroll instead of overflow */
}

/* Panels, cards and form rows fill the available width instead of being pinned
   to a fixed pixel width (which left dead space on wide / zoomed-out screens). */
.content > .panel,
.content > .card,
.content > .row {
    max-width: 100%;
}

/* Mobile top bar + drawer plumbing (hidden on desktop) */
.nav-toggle { display: none; }
.topbar { display: none; }
.nav-overlay { display: none; }

/* ============ Sidebar ============ */
.sidebar {
    width: 256px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #0c1a17, #10231e);
    color: #e2e8f0;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

/* ============ Responsive: collapse the sidebar into a drawer on phones/tablets ============ */
@media (max-width: 768px) {
    .topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: sticky;
        top: 0;
        z-index: 1030;
        height: 54px;
        padding: 0 14px;
        background: #0c1a17;
        color: #fff;
        box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
    }

    .nav-burger {
        font-size: 1.5rem;
        line-height: 1;
        cursor: pointer;
        padding: 4px 8px;
        margin: 0;
        user-select: none;
    }

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

    /* app-shell becomes a vertical stack: topbar, then content; sidebar floats over */
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }

    .nav-toggle:checked ~ .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, .4);
    }

    .nav-toggle:checked ~ .nav-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1035;
        background: rgba(0, 0, 0, .45);
    }

    .content {
        padding: 16px;
        max-width: 100%;
    }
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 4px 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    margin-bottom: 10px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #134e4a, #0f766e);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: .95rem;
    color: #fff;
    line-height: 1.2;
}

.brand-sub {
    font-size: .68rem;
    color: #5eead4;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.nav-section {
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: #64748b;
    margin: 16px 10px 6px;
}

.side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #cbd5e1;
    text-decoration: none;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: .9rem;
    margin-bottom: 2px;
    border-left: 3px solid transparent;
    transition: background .15s ease, color .15s ease;
}

.side-link:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.side-link.active {
    background: rgba(16, 185, 129, .14);
    color: #fff;
    border-left-color: #10b981;
}

.side-ico {
    width: 22px;
    text-align: center;
}

.logout-form {
    margin-top: auto;
    padding-top: 16px;
}

.btn-logout {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .18);
    color: #cbd5e1;
    border-radius: 10px;
    padding: 8px;
    font-size: .85rem;
    transition: background .15s ease;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

/* ============ Cards & panels ============ */
.card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--card);
}

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.panel-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: .95rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel .table {
    margin-bottom: 0;
}

/* ============ Tables ============ */
.table thead th {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
    padding: .6rem 1.1rem;
}

.table tbody td {
    padding: .65rem 1.1rem;
    vertical-align: middle;
    color: var(--ink-2);
}

.table tbody tr td:first-child {
    color: var(--ink);
    font-weight: 500;
}

/* ============ Buttons & forms ============ */
.btn {
    border-radius: 10px;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background: var(--accent-strong) !important;
    border-color: var(--accent-strong) !important;
}

.btn-outline-primary {
    color: var(--accent);
    border-color: var(--accent);
}

.btn-outline-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.form-control, .form-select {
    border-radius: 10px;
    border-color: var(--line);
}

.form-control:focus, .form-select:focus {
    border-color: #14b8a6;
    box-shadow: 0 0 0 .2rem rgba(20, 184, 166, .15);
}

.form-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: .3rem;
}

.alert {
    border-radius: 10px;
}

/* ============ Soft status badges ============ */
.badge-soft {
    display: inline-block;
    padding: .32em .75em;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-soft-success { background: #d1fae5; color: #065f46; }
.badge-soft-danger  { background: #fee2e2; color: #991b1b; }
.badge-soft-info    { background: #dbeafe; color: #1e40af; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-neutral { background: #e2e8f0; color: #475569; }

/* ============ KPI stat tiles ============ */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 18px 0 26px;
}

.kpi-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    display: flex;
    gap: 14px;
    align-items: center;
}

.kpi-ico {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.kpi-ico-teal  { background: #ccfbf1; }
.kpi-ico-blue  { background: #dbeafe; }
.kpi-ico-amber { background: #fef3c7; }
.kpi-ico-red   { background: #fee2e2; }
.kpi-ico-gray  { background: #e2e8f0; }

.kpi-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.kpi-label {
    font-size: .8rem;
    color: var(--ink-2);
}

.kpi-alert {
    font-size: .72rem;
    color: #b91c1c;
    font-weight: 600;
}

/* ============ Chat ============ */
.chat-box {
    background: #efeae2;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.chat-row {
    display: flex;
    margin-bottom: 8px;
}

.chat-row.chat-right {
    justify-content: flex-end;
}

.chat-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 4px 14px 14px 14px;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
    font-size: .92rem;
}

.chat-row.chat-right .chat-bubble {
    border-radius: 14px 4px 14px 14px;
}

.bubble-customer { background: #ffffff; }
.bubble-ai       { background: #d9fdd3; }
.bubble-agent    { background: #dbeafe; }

/* Per-message direction (WhatsApp-style): Arabic renders RTL, English LTR,
   mixed content aligns to its dominant language via dir="auto" on the element. */
.chat-text { text-align: start; }

.chat-meta {
    font-size: .7rem;
    color: #6c757d;
    margin-bottom: 2px;
}

/* ============ Login ============ */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(1100px 550px at 15% -5%, rgba(19, 78, 74, .45), transparent),
        radial-gradient(900px 500px at 110% 110%, rgba(15, 118, 110, .25), transparent),
        linear-gradient(160deg, #0c1a17, #0f172a);
}

.login-card {
    width: min(410px, 92vw);
    background: #fff;
    border-radius: 18px;
    padding: 38px 34px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}

.login-logo {
    width: 58px;
    height: 58px;
    margin: 0 auto 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, #134e4a, #0f766e);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.login-title {
    text-align: center;
    font-weight: 650;
    margin-bottom: 2px;
}

.login-sub {
    text-align: center;
    color: var(--muted);
    font-size: .85rem;
    margin-bottom: 26px;
}

/* ============ Misc ============ */
.page-sub {
    color: var(--muted);
    font-size: .88rem;
    margin-bottom: 1.2rem;
}

.text-muted {
    color: var(--muted) !important;
}
