/* ═══════════════════════════════════════════════════════════════════════════
   Callan Motors Admin Panel — Custom Styles
   Built on Bootstrap 5.3. All brand colours from main site design system.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Root / Brand Variables ────────────────────────────────────────────────── */
:root {
    --cm-red: #c0392b;
    --cm-red-dark: #962d22;
    --cm-red-light: #fdf2f1;
    --cm-dark: #0d1117;
    --cm-dark2: #161c24;
    --cm-dark3: #1a1f2e;
    --cm-sidebar-bg: #141920;
    --cm-sidebar-w: 240px;
    --cm-topnav-h: 54px;
    --cm-text: #1a1f2e;
    --cm-muted: #6b7280;
    --cm-gray: #f5f6f8;
    --cm-gray2: #e4e7ec;
    --cm-white: #ffffff;
    --cm-green: #16a34a;
    --cm-shadow: 0 2px 8px rgba(0, 0, 0, .08);
    --cm-shadow-lg: 0 8px 32px rgba(0, 0, 0, .14);
    --transition: .18s ease;
}

/* ── Reset / Base ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--cm-gray);
    color: var(--cm-text);
    font-size: .9rem;
    overflow-x: hidden;
}

/* ── Top Navbar ─────────────────────────────────────────────────────────────── */
.cm-topnav {
    height: var(--cm-topnav-h);
    background: var(--cm-dark) !important;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    z-index: 1040;
    padding: 0 1rem;
}

.cm-topnav .navbar-brand img {
    filter: brightness(1.1);
}

/* User avatar circle */
.cm-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--cm-red);
    color: #fff;
    font-weight: 700;
    font-size: .75rem;
}

.cm-user-btn {
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .15);
    color: #fff;
    border-radius: 6px;
    padding: .3rem .65rem;
    transition: var(--transition);
}

.cm-user-btn:hover {
    background: rgba(255, 255, 255, .13);
    color: #fff;
}

.cm-user-btn::after {
    color: rgba(255, 255, 255, .5);
}

/* ── Layout Wrapper ─────────────────────────────────────────────────────────── */
.cm-wrapper {
    display: flex;
    min-height: calc(100vh - var(--cm-topnav-h));
    margin-top: var(--cm-topnav-h);
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.cm-sidebar {
    width: var(--cm-sidebar-w);
    flex-shrink: 0;
    background: var(--cm-sidebar-bg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--cm-topnav-h);
    height: calc(100vh - var(--cm-topnav-h));
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1030;
    border-right: 1px solid rgba(255, 255, 255, .05);
    transition: transform var(--transition);
}

.cm-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1rem 0 0;
}

/* Sidebar nav */
.cm-nav {
    flex: 1;
}

.cm-nav ul {
    padding: 0 .5rem;
}

.cm-nav-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem .9rem;
    border-radius: 8px;
    color: rgba(255, 255, 255, .65);
    text-decoration: none;
    font-size: .855rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
    white-space: nowrap;
}

.cm-nav-link:hover {
    background: rgba(255, 255, 255, .07);
    color: rgba(255, 255, 255, .9);
}

.cm-nav-link.active {
    background: var(--cm-red);
    color: #fff;
}

.cm-nav-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.cm-nav-label {
    flex: 1;
}

/* Sidebar footer */
.cm-sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, .06);
    padding: .5rem 0;
    margin-top: auto;
}

.cm-sidebar-footer .cm-nav-link {
    font-size: .78rem;
    color: rgba(255, 255, 255, .4);
}

.cm-sidebar-footer .cm-nav-link:hover {
    color: rgba(255, 255, 255, .7);
}

/* Sidebar backdrop (mobile) */
.cm-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 1025;
}

.cm-sidebar-backdrop.show {
    display: block;
}

/* Mobile sidebar: off-canvas */
@media (max-width: 1199.98px) {
    .cm-sidebar {
        position: fixed;
        top: var(--cm-topnav-h);
        left: 0;
        transform: translateX(-100%);
        z-index: 1035;
    }

    .cm-sidebar.open {
        transform: translateX(0);
    }

    .cm-main {
        margin-left: 0 !important;
    }
}

/* ── Main Content ───────────────────────────────────────────────────────────── */
.cm-main {
    flex: 1;
    min-width: 0;
    padding: 1.75rem 1.75rem 2rem;
    background: var(--cm-gray);
}

.cm-page-header {
    margin-bottom: 1.5rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--cm-gray2);
}

.cm-page-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--cm-text);
    margin: 0;
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.cm-card {
    background: var(--cm-white);
    border: 1px solid var(--cm-gray2);
    border-radius: 10px;
    box-shadow: var(--cm-shadow);
}

.cm-card-header {
    padding: 1rem 1.25rem .75rem;
    border-bottom: 1px solid var(--cm-gray2);
    font-weight: 600;
    font-size: .9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cm-card-body {
    padding: 1.25rem;
}

/* Stat cards */
.cm-stat {
    background: var(--cm-white);
    border: 1px solid var(--cm-gray2);
    border-radius: 10px;
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--cm-shadow);
    text-decoration: none;
    color: inherit;
    transition: box-shadow var(--transition), border-color var(--transition);
}

.cm-stat:hover {
    box-shadow: var(--cm-shadow-lg);
    border-color: #c9cdd4;
    color: inherit;
}

.cm-stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.cm-stat-icon.red {
    background: var(--cm-red-light);
    color: var(--cm-red);
}

.cm-stat-icon.green {
    background: #f0fdf4;
    color: var(--cm-green);
}

.cm-stat-icon.blue {
    background: #eff6ff;
    color: #2563eb;
}

.cm-stat-icon.orange {
    background: #fff7ed;
    color: #ea580c;
}

.cm-stat-icon.purple {
    background: #faf5ff;
    color: #7c3aed;
}

.cm-stat-icon.gray {
    background: var(--cm-gray);
    color: var(--cm-muted);
}

.cm-stat-num {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
}

.cm-stat-label {
    font-size: .78rem;
    color: var(--cm-muted);
    margin-top: .2rem;
}

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.cm-table-wrap {
    background: var(--cm-white);
    border: 1px solid var(--cm-gray2);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--cm-shadow);
}

.cm-table {
    margin: 0;
    font-size: .855rem;
}

.cm-table thead th {
    background: #f8f9fb;
    border-bottom: 1px solid var(--cm-gray2);
    font-weight: 600;
    color: var(--cm-muted);
    text-transform: uppercase;
    font-size: .72rem;
    letter-spacing: .04em;
    padding: .7rem 1rem;
    white-space: nowrap;
}

.cm-table tbody td {
    padding: .75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f0f2f4;
}

.cm-table tbody tr:last-child td {
    border-bottom: 0;
}

.cm-table tbody tr:hover td {
    background: #fafbfc;
}

.cm-table .cm-vehicle-img {
    width: 60px;
    height: 42px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--cm-gray2);
}

/* ── Filter bars / search ───────────────────────────────────────────────────── */
.cm-filter-bar {
    background: var(--cm-white);
    border: 1px solid var(--cm-gray2);
    border-radius: 10px;
    padding: .85rem 1.1rem;
    box-shadow: var(--cm-shadow);
    margin-bottom: 1.25rem;
}

.cm-search-input {
    border-radius: 6px;
    border: 1px solid var(--cm-gray2);
    padding: .42rem .75rem .42rem 2.2rem !important;
    font-size: .875rem;
    transition: border-color var(--transition);
}

.cm-search-input:focus {
    border-color: var(--cm-red);
    outline: none;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, .12);
}

.cm-search-wrap {
    position: relative;
}

.cm-search-wrap .bi-search {
    position: absolute;
    left: .65rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--cm-muted);
    pointer-events: none;
    font-size: .85rem;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn-cm-red {
    background: var(--cm-red);
    border-color: var(--cm-red);
    color: #fff;
    font-weight: 500;
}

.btn-cm-red:hover {
    background: var(--cm-red-dark);
    border-color: var(--cm-red-dark);
    color: #fff;
}

.btn-cm-sm {
    padding: .22rem .6rem;
    font-size: .78rem;
    border-radius: 5px;
}

/* Toggle switches in tables */
.cm-toggle {
    cursor: pointer;
}

/* ── Form styles ────────────────────────────────────────────────────────────── */
.cm-form-card {
    background: var(--cm-white);
    border: 1px solid var(--cm-gray2);
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: var(--cm-shadow);
}

.cm-form-label {
    font-weight: 600;
    font-size: .8rem;
    color: var(--cm-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .35rem;
}

.cm-input {
    border: 1px solid var(--cm-gray2);
    border-radius: 6px;
    padding: .45rem .75rem;
    font-size: .875rem;
    width: 100%;
    transition: border-color var(--transition);
}

.cm-input:focus {
    border-color: var(--cm-red);
    outline: none;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, .12);
}

/* Section labels within settings page */
.cm-section-title {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--cm-muted);
    padding: .5rem 0 .75rem;
    border-bottom: 1px solid var(--cm-gray2);
    margin-bottom: 1rem;
}

/* ── Modal tweaks ───────────────────────────────────────────────────────────── */
.modal-content {
    border-radius: 12px;
    border: 0;
    box-shadow: var(--cm-shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--cm-gray2);
    padding: 1rem 1.25rem;
}

.modal-footer {
    border-top: 1px solid var(--cm-gray2);
}

/* ── Alert / flash messages ─────────────────────────────────────────────────── */
.cm-flash {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    min-width: 280px;
    max-width: 420px;
}

.cm-flash .alert {
    box-shadow: var(--cm-shadow-lg);
    border-radius: 10px;
    font-size: .875rem;
}

/* ── Login page ─────────────────────────────────────────────────────────────── */
.cm-login-page {
    min-height: 100vh;
    background: var(--cm-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.cm-login-card {
    background: var(--cm-white);
    border-radius: 14px;
    padding: 2.5rem 2rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--cm-shadow-lg);
}

.cm-login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.cm-login-logo img {
    height: 48px;
}

.cm-login-title {
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: .25rem;
}

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

/* ── Charts ─────────────────────────────────────────────────────────────────── */
.cm-chart-wrap {
    position: relative;
    height: 260px;
}

/* ── Misc ───────────────────────────────────────────────────────────────────── */
.text-cm-red {
    color: var(--cm-red) !important;
}

.bg-cm-red {
    background: var(--cm-red) !important;
}

.cm-divider {
    border-top: 1px solid var(--cm-gray2);
    margin: 1rem 0;
}

/* Lead detail modal */
.cm-lead-row {
    display: flex;
    gap: 1rem;
    margin-bottom: .5rem;
    font-size: .85rem;
}

.cm-lead-key {
    width: 130px;
    flex-shrink: 0;
    font-weight: 600;
    color: var(--cm-muted);
}

/* Error log severity rows */
tr.cm-error-fatal td:first-child {
    border-left: 3px solid #dc3545;
}

tr.cm-error-js td:first-child {
    border-left: 3px solid #f59e0b;
}

tr.cm-error-php td:first-child {
    border-left: 3px solid #6366f1;
}

/* Scrollable modals with long content */
.modal-body-scroll {
    max-height: 65vh;
    overflow-y: auto;
}

/* Toast notifications in tables (inline) */
.cm-inline-toast {
    display: inline-block;
    font-size: .72rem;
    padding: .1rem .4rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity .3s;
}

.cm-inline-toast.show {
    opacity: 1;
}

/* Responsive tweaks */
@media (max-width: 767.98px) {
    .cm-main {
        padding: 1rem;
    }

    .cm-stat-num {
        font-size: 1.3rem;
    }
}