:root {
    --brand: #1d4ed8;
    --brand-dark: #1e3a8a;
    --ink: #172033;
    --muted: #64748b;
    --canvas: #f4f6fa;
    --line: #e2e8f0;
    --sidebar: #101b2d;
}

* { -webkit-tap-highlight-color: transparent; }
body { background: var(--canvas); color: var(--ink); font-family: Inter, "Segoe UI", Arial, sans-serif; }
h1, h2, h3, h4, h5, h6 { color: #172033; letter-spacing: -.02em; }
a { color: var(--brand); }

.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar {
    width: 258px; flex: 0 0 258px; height: 100vh; position: sticky; top: 0; overflow-y: auto;
    background: var(--sidebar); color: #cbd5e1; border-right: 1px solid #263449;
}
.offcanvas.sidebar { position: fixed; top: 0; bottom: 0; width: 286px; height: auto; max-width: 88vw; }
.offcanvas.sidebar .menu { overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 21px 18px 17px; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 17px; color: #fff;
}
.brand-name { font-weight: 750; color: #fff; font-size: 1.02rem; line-height: 1.1; }
.brand-sub { font-size: .7rem; color: #94a3b8; margin-top: 3px; }
.menu { padding: 4px 10px 14px; }
.menu-title { font-size: .65rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #8290a4; padding: 18px 11px 6px; }
.menu-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 2px 0; border-radius: 9px;
    color: #cbd5e1; text-decoration: none; font-size: .9rem; font-weight: 500; transition: background .15s, color .15s;
}
.menu-link i { font-size: 1rem; width: 20px; text-align: center; color: #93a4ba !important; }
.menu-link:hover { background: #1e2b40; color: #fff; }
.menu-link.active { background: #1e3a66; color: #fff; box-shadow: inset 3px 0 #60a5fa; }
.menu-link.active i { color: #93c5fd !important; }
.side-foot { padding: 14px 16px; border-top: 1px solid #263449; color: #cbd5e1; }
.side-foot .who { font-weight: 650; color: #fff; }
.side-foot .btn-light { border: 0; color: #334155; }
.offcanvas.sidebar .offcanvas-header { padding: 12px 16px 0; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px;
    background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 100;
    min-height: 62px; backdrop-filter: blur(12px);
}
.topbar-title { font-weight: 650; color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar .badge { color: #475569 !important; border: 1px solid var(--line); padding: 7px 10px; font-weight: 550; }
.menu-toggle { background: var(--brand); color: #fff; border: 0; width: 38px; height: 38px; display: grid; place-items: center; }
.menu-toggle:hover { background: var(--brand-dark); color: #fff; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700;
    background: #315a91; font-size: .85rem;
}
.content-area { padding: 24px; width: 100%; max-width: 1680px; margin: 0 auto; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; }
.page-heading h1 { font-size: 1.4rem; font-weight: 700; margin: 0 0 4px; }
.page-heading p { font-size: .9rem; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: #f1f5f9; }
.auth-page { background: none; }
.auth-content { width: 100%; margin: auto; }
.auth-page .card { border: 1px solid var(--line); box-shadow: 0 18px 48px rgba(15,23,42,.1); }
.auth-brand { display: flex; justify-content: center; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 44px; height: 44px; }
.auth-brand .brand-name { color: var(--ink); font-size: 1.2rem; }
.auth-caption { color: var(--muted); font-size: .9rem; }

.card { border: 1px solid #e8edf4; border-radius: 13px; box-shadow: 0 2px 10px rgba(15,23,42,.035); background: #fff; }
.card-body { padding: 1.25rem; }
.rounded-4 { border-radius: 13px !important; }
.stat {
    display: flex; align-items: center; gap: 14px; padding: 17px; border-radius: 12px; color: var(--ink); height: 100%;
    background: #fff; border: 1px solid #e8edf4; box-shadow: 0 2px 10px rgba(15,23,42,.035);
}
.stat-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 1.1rem; background: #eff6ff; color: var(--brand); flex: 0 0 42px; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; line-height: 1.3; }
.stat-value { font-size: 1.25rem; font-weight: 750; line-height: 1.25; word-break: break-word; color: var(--ink); }
.stat > div:last-child { min-width: 0; }
.grad-1, .grad-2, .grad-3, .grad-4, .grad-5 { background: #fff; }
.table thead th { background: #f8fafc; color: #526176; font-size: .73rem; font-weight: 700; text-transform: uppercase; letter-spacing: .045em; border-bottom: 1px solid var(--line); border-top: 0; }
.table td, .table th { vertical-align: middle; padding: .72rem .75rem; }
.table-hover tbody tr:hover { background: #f8fafc; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.action-dialog { border: 0; border-radius: 14px; padding: 0; width: min(460px, calc(100vw - 24px)); max-width: 100%; box-shadow: 0 20px 60px rgba(15,23,42,.28); }
.action-dialog::backdrop { background: rgba(15,23,42,.55); }
.dialog-card { padding: 20px; }
.dialog-card h2 { font-size: 1.15rem; margin: 0 0 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.card-header-grad { background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: .75rem 1rem; font-weight: 650; color: #334155; }
.summary-tile { display: flex; flex-direction: column; gap: 5px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; height: 100%; }
.summary-tile span { color: var(--muted); font-size: .78rem; }
.summary-tile strong { color: var(--ink); font-size: 1.15rem; }

.btn-dark { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-dark:hover, .btn-dark:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-primary { color: var(--brand); border-color: #b7c8e5; }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); }
.btn { border-radius: 8px; font-weight: 550; }
.form-control, .form-select { border-radius: 8px; border-color: #d7dee8; min-height: 40px; color: #1e293b; }
.form-control:focus, .form-select:focus { border-color: #7aa2e8; box-shadow: 0 0 0 .2rem rgba(37,99,235,.12); }
.input-group-text { border-color: #d7dee8; background: #f8fafc; color: #475569; }
.form-label { color: #334155; font-size: .87rem; font-weight: 600; }
.form-text { color: #718096; }
.nav-pills .nav-link { border-radius: 8px; color: #475569; font-weight: 600; }
.nav-pills .nav-link.active { background: var(--brand); color: #fff; }
.badge { font-weight: 600; }
.badge.text-bg-success { background: #dcfce7 !important; color: #166534 !important; }
.badge.text-bg-info { background: #e0f2fe !important; color: #075985 !important; }
.badge.text-bg-warning { background: #fef3c7 !important; color: #92400e !important; }
.badge.text-bg-danger { background: #fee2e2 !important; color: #991b1b !important; }
.badge.text-bg-light { background: #f1f5f9 !important; color: #475569 !important; }
.form-switch.rounded-pill { padding-left: 3.1em; min-height: 36px; display: flex; align-items: center; }
.form-switch.rounded-pill .form-check-input { margin-left: -2.4em; }

.mobile-tabbar { display: none; }
@media (max-width: 991.98px) {
    .content-area { padding: 18px 16px 26px; }
    .topbar { padding: 10px 16px; }
}
@media (max-width: 767.98px) {
    .content-area { padding-bottom: 92px; }
    .topbar { min-height: 58px; }
    .page-heading { align-items: flex-start; }
    .mobile-tabbar {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 1010; display: grid; grid-template-columns: repeat(4,1fr);
        padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.97);
        border-top: 1px solid var(--line); box-shadow: 0 -5px 18px rgba(15,23,42,.06); backdrop-filter: blur(14px);
    }
    .mobile-tabbar a, .mobile-tabbar button { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 3px; padding: 4px 2px; min-height: 48px; color: #718096; font-size: .67rem; text-decoration: none; border: 0; background: transparent; }
    .mobile-tabbar i { font-size: 1.05rem; }
    .mobile-tabbar .active { color: var(--brand); font-weight: 700; }
}
@media (max-width: 576px) {
    .content-area { padding-left: 12px; padding-right: 12px; }
    .card-body { padding: 1rem; }
    .btn { min-height: 40px; }
    .btn-sm { min-height: 34px; }
    .stat { padding: 12px; gap: 9px; }
    .stat-icon { width: 36px; height: 36px; flex-basis: 36px; font-size: 1rem; }
    .stat-value { font-size: 1rem; }
    .page-heading h1 { font-size: 1.2rem; }
    .table td, .table th { padding: .62rem .55rem; }
}

.table td.nowrap, .text-nowrap { white-space: nowrap; }
.table td { word-break: normal; }
@media print {
    .sidebar, .topbar, .mobile-tabbar, .no-print { display: none !important; }
    .content-area { padding: 0; }
    body { background: #fff; }
}

/* ---------- Charts, stat hints ---------- */
.stat-sub { display: block; font-size: .72rem; margin-top: 2px; line-height: 1.3; }
.chart-box { position: relative; height: 270px; }
.chart-box.tall { height: 330px; }
.chart-box.chart-empty::after {
    content: "No data for this selection"; position: absolute; inset: 0; display: grid; place-items: center;
    color: var(--muted); font-size: .85rem; border: 1px dashed var(--line); border-radius: 10px; background: #f8fafc;
}
.card h6 { font-weight: 650; }

/* ---------- CRM ---------- */
.avatar-sm { width: 24px; height: 24px; font-size: .65rem; display: inline-grid; vertical-align: middle; }
.crm-stage { font-weight: 600; }
.crm-dl dt { color: var(--muted); font-weight: 500; }
.crm-dl dd { margin-bottom: .5rem; }
.crm-stepper { display: flex; flex-wrap: wrap; gap: 8px; }
.crm-step-form { margin: 0; }
.crm-step {
    border: 1px solid var(--c); background: #fff; color: var(--c); border-radius: 999px; padding: 6px 14px;
    font-size: .83rem; font-weight: 600; cursor: pointer; transition: background .15s, color .15s;
}
.crm-step:hover:not(:disabled) { background: var(--c); color: #fff; }
.crm-step.active, .crm-step:disabled { background: var(--c); color: #fff; cursor: default; opacity: 1; }
.crm-timeline li { display: flex; gap: 12px; padding: 0 0 14px; position: relative; }
.crm-timeline li:not(:last-child)::before { content: ""; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--line); }
.crm-dot { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: #eff6ff; color: var(--brand); font-size: .9rem; }

.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; -webkit-overflow-scrolling: touch; }
.kcol { flex: 0 0 262px; background: #eef2f7; border-radius: 12px; border-top: 4px solid var(--c); min-height: 120px; }
.kcol > header { padding: 10px 12px 4px; }
.kname { font-weight: 700; color: #334155; }
.kcount { margin-left: 4px; }
.kbody { padding: 8px; min-height: 90px; display: flex; flex-direction: column; gap: 8px; border-radius: 0 0 10px 10px; transition: background .12s; }
.kbody.over { background: rgba(37,99,235,.08); outline: 2px dashed #93c5fd; outline-offset: -4px; }
.kcard { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 12px; cursor: grab; box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.kcard.dragging { opacity: .45; }
.kcard-title { font-weight: 650; color: var(--ink); text-decoration: none; }
.kcard-title:hover { color: var(--brand); }
.kcard .kmove { font-size: .75rem; min-height: 30px; padding-top: 2px; padding-bottom: 2px; color: var(--muted); }
@media (max-width: 576px) { .kcol { flex-basis: 82vw; } .chart-box { height: 240px; } }
@media print { .chart-box { height: 240px; } .card { break-inside: avoid; } }
