:root {
    --audi-red: #e30613;
    --audi-red-dark: #ba000b;
    --bg-dark: #0f1115;
    --bg-body: #13151a;
    --border: #262a33;
    --text-light: #f3f4f6;
    --text-muted: #9ca3af;
    --panel-bg: #1a1d24;
    --panel-hover: #20242d;
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-body);
    color: var(--text-light);
    min-height: 100vh;
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Typography and generic */
.page-title {
    font-size: clamp(1.4rem, 2vw, 1.8rem);
    font-weight: 700;
}
.tracking-wide { letter-spacing: 0.05em; }

/* Panels and Cards */
.panel, .glass-card, .table-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    padding: 24px;
}
.table-panel { padding: 0; }

.metric-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    height: 100%;
    min-height: 142px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    background: var(--panel-hover);
}

.metric-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--audi-red);
}

.metric-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    color: var(--text-light);
    font-weight: 800;
    font-size: 2.25rem;
    margin-top: 12px;
    line-height: 1;
}

.metric-sub {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 8px;
    font-weight: 500;
}

/* Forms and Buttons */
.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border);
    padding: 0.6rem 1rem;
    background-color: #1f232b;
    color: var(--text-light);
}
.form-control:focus, .form-select:focus {
    background-color: #1f232b;
    border-color: rgba(227, 6, 19, 0.5);
    box-shadow: 0 0 0 0.25rem rgba(227, 6, 19, 0.15);
    color: var(--text-light);
}
.form-select option { color: var(--text-light); background: #1f232b; }
.form-control::placeholder { color: var(--text-muted); }

.btn-audi {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--audi-red);
    --bs-btn-border-color: var(--audi-red);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--audi-red-dark);
    --bs-btn-hover-border-color: var(--audi-red-dark);
    border-radius: 8px;
    font-weight: 500;
    padding: 0.6rem 1.25rem;
    transition: all 0.2s;
}

.btn-soft {
    background: #262a33;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 500;
    padding: 0.6rem 1.25rem;
    transition: all 0.2s;
}
.btn-soft:hover {
    background: #313742;
    color: #fff;
}

/* Navigation */
.app-nav {
    background-color: var(--panel-bg);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.navbar-brand .fw-bold { font-size: 1.1rem; }
.navbar-brand .text-muted { font-size: 0.65rem; letter-spacing: 0.1em; }

.nav-link-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-left: auto !important;
    margin-right: auto !important;
}

.nav-pill {
    min-width: 42px;
    height: 42px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: var(--text-light);
    text-decoration: none;
    border: 1px solid transparent;
    background: transparent;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, transform .18s ease, padding .18s ease;
    flex: 0 0 auto;
    font-size: .92rem;
    font-weight: 700;
    line-height: 1;
    position: relative;
}

.nav-label {
    display: inline-block;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    color: currentColor;
    font-size: .86rem;
    font-weight: 700;
    transition: max-width .22s ease, opacity .18s ease, margin-left .18s ease;
}

.nav-pill:hover .nav-label,
.nav-pill:focus-visible .nav-label {
    max-width: 150px;
    margin-left: 8px;
    opacity: 1;
}

.nav-pill i {
    font-size: 1.15rem;
    line-height: 1;
    color: var(--audi-red);
    transition: color .18s ease, transform .18s ease;
}

.nav-pill:hover,
.nav-pill:focus-visible {
    background: #262a33;
    border-color: rgba(255,255,255,.08);
    color: #fff;
    padding: 0 12px;
    transform: translateY(-1px);
    outline: none;
    text-decoration: none;
}

.nav-pill.active {
    background: var(--audi-red);
    color: #fff;
    box-shadow: 0 10px 20px rgba(227,6,19,.22);
}

.nav-pill.active i { color: #fff; }
.nav-pill:hover i,
.nav-pill:focus-visible i { transform: scale(1.04); }

.avatar {
    width: 36px;
    height: 36px;
    font-size: .9rem;
}
.user-role { font-size: .7rem; }
.nav-logout i { color: #f87171; }

/* Tables */
.table {
    margin-bottom: 0;
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-light);
}
.table thead th {
    background-color: rgba(255,255,255,0.02);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}
.table td {
    padding: 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    color: #e5e7eb;
}
.table tbody tr:hover {
    background-color: rgba(255,255,255,0.02);
}

/* Progress bars & badges */
.progress {
    background: #2a2f3a;
    height: 8px;
    border-radius: 999px;
}
.progress-bar {
    background: var(--audi-red);
}

.badge-soft-success { background: rgba(16, 185, 129, 0.15); color: #34d399; font-weight: 600; border: 1px solid rgba(16, 185, 129, 0.25); }
.badge-soft-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; font-weight: 600; border: 1px solid rgba(239, 68, 68, 0.25); }
.badge-soft-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; font-weight: 600; border: 1px solid rgba(245, 158, 11, 0.25); }
.badge-soft-primary { background: rgba(59, 130, 246, 0.15); color: #60a5fa; font-weight: 600; border: 1px solid rgba(59, 130, 246, 0.25); }
.badge-soft-info { background: rgba(6, 182, 212, 0.15); color: #22d3ee; font-weight: 600; border: 1px solid rgba(6, 182, 212, 0.25); }
.badge-soft-dark { background: rgba(255, 255, 255, 0.05); color: #f3f4f6; font-weight: 600; border: 1px solid rgba(255, 255, 255, 0.1); }
.badge-soft-secondary { background: rgba(107, 114, 128, 0.15); color: #9ca3af; font-weight: 600; border: 1px solid rgba(107, 114, 128, 0.25); }
.badge-soft-purple { background: rgba(139, 92, 246, 0.15); color: #a78bfa; font-weight: 600; border: 1px solid rgba(139, 92, 246, 0.25); }

/* Score ring (used in executive dashboards) */
.score-ring {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(var(--audi-red) calc(var(--score) * 1%), #2a2f3a 0);
    position: relative;
    font-weight: 700;
}
.score-ring::before {
    content: "";
    position: absolute;
    inset: 4px;
    background: var(--panel-bg);
    border-radius: 50%;
}
.score-ring span { position: relative; z-index: 1; font-size: 0.85rem; color: var(--text-light); }

/* Pipeline grids */
.pipeline-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 16px;
}
.pipeline-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.pipeline-card .count {
    color: var(--text-light);
    font-size: 1.75rem;
    font-weight: 800;
    margin-top: 12px;
}


/* Dashboard operations */
.process-panel {
    display: flex;
    flex-direction: column;
    min-height: 620px;
}
.process-score-panel .process-chart-wrap {
    flex: 1 1 auto;
    min-height: 520px;
    position: relative;
}
.process-score-panel .process-chart-wrap canvas {
    display: block;
    height: 100% !important;
    width: 100% !important;
}
.dashboard-chart-panel {
    display: flex;
    flex-direction: column;
}
.dashboard-chart-wrap {
    flex: 1 1 auto;
    min-height: 420px;
    position: relative;
}
.dashboard-chart-wrap canvas {
    display: block;
    height: 100% !important;
    width: 100% !important;
}
.process-gaps-panel {
    min-height: 0;
}
.coaching-queue {
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.coaching-list {
    max-height: 232px;
    overflow-y: auto;
    padding-right: 6px;
}
.coaching-list::-webkit-scrollbar {
    width: 8px;
}
.coaching-list::-webkit-scrollbar-thumb {
    background: #343944;
    border-radius: 999px;
}
.leaderboard-panel .table td,
.leaderboard-panel .table th {
    white-space: nowrap;
}
.leaderboard-panel .table td:last-child {
    min-width: 260px;
    white-space: normal;
}
.process-gap-list {
    display: grid;
    gap: 14px;
}
.process-gap-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.process-gap-row:last-child { border-bottom: 0; }
.coaching-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}
.coaching-row:first-of-type { border-top: 0; }
.compact-pipeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.compact-pipeline .pipeline-card {
    min-height: 92px;
}
.compact-pipeline .pipeline-card .count {
    font-size: 1.45rem;
}
.process-scorecard th,
.process-scorecard td {
    white-space: nowrap;
}
.text-nowrap-md { white-space: normal; }

@media (min-width: 992px) {
    .text-nowrap-md { white-space: nowrap; }
}

@media (max-width: 1199.98px) {
    .process-panel { min-height: 0; }
    .process-score-panel .process-chart-wrap { flex: 0 0 auto; height: 420px; min-height: 0; }
    .dashboard-chart-wrap { flex: 0 0 auto; height: 360px; min-height: 0; }
    .coaching-list { max-height: none; overflow: visible; padding-right: 0; }
}

@media (max-width: 575.98px) {
    .process-score-panel .process-chart-wrap { height: 500px; }
}

/* Login specific wrapper */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 22px;
    background-color: var(--bg-body);
}

.login-wrap .panel {
    max-width: 420px;
    width: 100%;
}
.login-card { width: min(100%, 460px); border-radius: 30px; padding: 32px; }


/* Lead workflow */
.lead-workflow-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
.lead-stage-card {
    min-height: 96px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
}
.lead-stage-count {
    color: var(--text-light);
    font-size: 1.65rem;
    font-weight: 800;
    line-height: 1;
}
.action-queue-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
}
.action-queue-row:last-child { border-bottom: 0; }
.lead-register-table td,
.lead-register-table th {
    vertical-align: middle;
}
.form-section-title {
    color: var(--text-muted);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.form-section-title:first-child {
    border-top: 0;
    padding-top: 0;
}

@media (max-width: 1199px) {
    .lead-workflow-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 576px) {
    .lead-workflow-grid { grid-template-columns: minmax(0, 1fr); }
}

@media print {
    .sidebar, .topbar, form, .btn, .sidebar-backdrop { display: none !important; }
    .app-main { margin-left: 0 !important; width: 100% !important; padding: 0 !important; }
    body { background: #fff !important; color: #111 !important; }
    .panel, .table-panel, .metric-card { box-shadow: none !important; border-color: #ccc !important; background: #fff !important; color: #111 !important; }
}

@media (max-width: 991px) {
    .sidebar { transform: translateX(-100%); width: min(86vw, 310px); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    .app-shell { display: block; }
    .app-main { margin-left: 0; width: 100%; padding: 14px; }
    .topbar { position: static; align-items: flex-start; flex-direction: column; }
    .topbar-actions { width: 100%; justify-content: space-between; }
}

@media (max-width: 576px) {
    .metric-value { font-size: 1.55rem; }
    .panel { padding: 16px; }
    .login-card { padding: 22px; }
}


.table-responsive {
    border-radius: inherit;
}

@media (max-width: 1199px) {
    .metric-card { padding: 18px; min-height: 128px; }
    .metric-value { font-size: 1.85rem; }
    .panel, .glass-card, .table-panel { border-radius: 10px; }
}

@media (max-width: 991px) {
    .app-nav .navbar-collapse {
        margin-top: 16px;
        padding: 14px;
        background: #171a21;
        border: 1px solid var(--border);
        border-radius: 10px;
    }
    .nav-link-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
        width: 100%;
        margin-bottom: 14px !important;
    }
    .nav-link-row .nav-item { width: 100%; }
    .nav-pill { width: 100%; height: 46px; justify-content: flex-start; gap: 10px; padding: 0 14px; }
    .nav-label { max-width: none; margin-left: 0; opacity: 1; overflow: visible; font-size: .92rem; }
    .nav-pill:hover .nav-label,
    .nav-pill:focus-visible .nav-label { max-width: none; margin-left: 0; }
    .nav-user {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch !important;
        width: 100%;
        padding-top: 12px;
        border-top: 1px solid var(--border);
    }
    .nav-user .user-chip {
        width: 100%;
        min-height: 46px;
        padding: 0 14px;
        border-radius: 8px;
        background: #1f232b;
        border: 1px solid rgba(255,255,255,.06);
    }
    .nav-user .d-md-block { display: block !important; }
}

@media (max-width: 768px) {
    main.container-fluid { padding-left: 12px !important; padding-right: 12px !important; }
    header .h3 { font-size: 1.35rem; }
    .metric-card { min-height: 116px; }
    .pipeline-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .pipeline-card { padding: 12px 8px; }
    .pipeline-card .count { font-size: 1.35rem; }
    .table thead th, .table td { padding: 10px 12px; }
    .score-ring { width: 42px; height: 42px; }
}
