/* ============================================================
   AAuCRM – Modern UI  (dark sidebar + clean white content)
   Brand: #A11D21
   ============================================================ */

:root {
    --sidebar-bg: #1a2236;
    --sidebar-text: rgba(255,255,255,.6);
    --sidebar-active-text: #fff;
    --sidebar-active-bg: rgba(161,29,33,.2);
    --sidebar-hover-bg: rgba(255,255,255,.06);
    --sidebar-border: rgba(255,255,255,.07);
    --brand: #A11D21;
    --brand-hover: #8b1519;
    --brand-light: rgba(161,29,33,.08);
    --bg: #f0f2f7;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e8edf2;
    --border-light: #f1f5f9;
    --sidebar-w: 240px;
    --topbar-h: 58px;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
    --shadow: 0 2px 8px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
    --shadow-md: 0 4px 20px rgba(0,0,0,.10);
    --transition: all .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1,h2,h3,h4,h5,h6 { font-weight: 700; line-height: 1.3; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.crm-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
    scrollbar-width: none;
}

/* ---- Collapsed sidebar (desktop) ---- */
.crm-sidebar.collapsed {
    width: 64px;
}
.crm-sidebar.collapsed .sidebar-brand-name,
.crm-sidebar.collapsed .nav-section-title,
.crm-sidebar.collapsed .nav-text,
.crm-sidebar.collapsed .sidebar-footer .nav-text {
    display: none;
}
.crm-sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 20px 0 16px;
}
.crm-sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 10px;
    margin: 1px 6px;
    border-left-color: transparent;
    border-radius: var(--radius-sm);
}
.crm-sidebar.collapsed .nav-link.active {
    border-left-color: transparent;
    background: var(--sidebar-active-bg);
}
.crm-sidebar.collapsed .nav-link i {
    width: auto;
    font-size: 18px;
}
.crm-sidebar.collapsed .sidebar-footer {
    justify-content: center;
    padding: 14px 0;
}
.crm-sidebar::-webkit-scrollbar { display: none; }

.sidebar-brand {
    padding: 20px 18px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.sidebar-brand img {
    width: 32px; height: 32px;
    border-radius: 8px;
    object-fit: contain;
}
.sidebar-brand-name {
    color: #fff;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -.5px;
}
.sidebar-brand-sub {
    color: rgba(255,255,255,.35);
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 1px;
}

.sidebar-nav { padding: 10px 0; flex: 1; }

.nav-section-title {
    color: rgba(255,255,255,.28);
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    padding: 12px 18px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8.5px 18px;
    color: var(--sidebar-text);
    text-decoration: none !important;
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: var(--transition);
    margin: 1px 8px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-left: 0;
}
.nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: rgba(255,255,255,.9);
}
.nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--brand);
    font-weight: 600;
}
.nav-link.active i { color: var(--brand); }
.nav-link i {
    font-size: 15px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid var(--sidebar-border);
    font-size: 11px;
    color: rgba(255,255,255,.25);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ---- Sidebar overlay ---- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1040;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ============================================================
   MAIN
   ============================================================ */
.crm-main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}
.crm-main.sidebar-collapsed {
    margin-left: 64px;
}

/* ---- Topbar ---- */
.crm-topbar {
    position: sticky; top: 0; z-index: 100;
    height: var(--topbar-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0,0,0,.04);
}
.topbar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 7px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    flex-shrink: 0;
}
.topbar-toggle:hover { background: var(--bg); color: var(--text); }
.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0; flex: 1;
}
.topbar-date { font-size: 12.5px; color: var(--text-muted); }
.topbar-user .btn {
    font-size: 13px; border-color: var(--border);
    color: var(--text); border-radius: 20px;
    padding: 5px 14px;
}

/* ---- Page content ---- */
.crm-page { padding: 24px; flex: 1; }

/* ---- Page header ---- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.page-title i { color: var(--brand); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin: 3px 0 0; }

/* ============================================================
   CARDS
   ============================================================ */
.crm-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: box-shadow .2s ease;
}
.crm-card:hover { box-shadow: var(--shadow-md); }
.crm-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.crm-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.crm-card-body { padding: 20px; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform .18s ease, box-shadow .18s ease;
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0;
    right: 0; height: 3px;
    background: transparent;
    transition: background .2s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card:hover::after { background: var(--brand); }

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.red    { background: rgba(161,29,33,.1); color: #A11D21; }
.stat-icon.blue   { background: rgba(37,99,235,.1);  color: #2563eb; }
.stat-icon.green  { background: rgba(22,163,74,.1);  color: #16a34a; }
.stat-icon.purple { background: rgba(109,40,217,.1); color: #6d28d9; }
.stat-icon.orange { background: rgba(234,88,12,.1);  color: #ea580c; }
.stat-icon.teal   { background: rgba(13,148,136,.1); color: #0d9488; }
.stat-icon.pink   { background: rgba(236,72,153,.1); color: #ec4899; }

.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; letter-spacing: -.5px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

/* ============================================================
   CHART
   ============================================================ */
.chart-wrapper { position: relative; height: 280px; }

/* ============================================================
   AG GRID
   ============================================================ */
.ag-theme-alpine {
    --ag-font-family: 'Segoe UI', system-ui, sans-serif;
    --ag-font-size: 13px;
    --ag-row-hover-color: #fff7f7;
    --ag-selected-row-background-color: #fef2f2;
    --ag-header-background-color: #f8fafc;
    --ag-border-color: var(--border);
    --ag-row-border-color: var(--border-light);
    --ag-header-foreground-color: var(--text-muted);
    --ag-odd-row-background-color: #fff;
    --ag-even-row-background-color: #fdfdfd;
}
.ag-theme-alpine .ag-header-cell-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.ag-theme-alpine .ag-row { cursor: pointer; transition: background .1s; }
.ag-theme-alpine .ag-paging-panel { font-size: 12.5px; }
.ag-theme-alpine .ag-cell { display: flex; align-items: center; }

/* ============================================================
   OFFCANVAS DETAIL
   ============================================================ */
.detail-offcanvas { width: 520px !important; }
.offcanvas-header { padding: 18px 20px; }
.offcanvas-title { font-size: 16px; font-weight: 700; }

.detail-tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    gap: 0;
}
.detail-tab {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
    white-space: nowrap;
}
.detail-tab:hover { color: var(--text); }
.detail-tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ============================================================
   INFO GRID (detail panel)
   ============================================================ */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }
.info-item label {
    font-size: 10.5px;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 3px;
    display: block;
}
.info-item p { margin: 0; font-size: 13.5px; font-weight: 500; color: var(--text); }

/* ============================================================
   MINI TABLE (offcanvas / cards)
   ============================================================ */
.crm-mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.crm-mini-table th {
    padding: 8px 12px;
    background: var(--border-light);
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.crm-mini-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    color: var(--text);
}
.crm-mini-table tr:last-child td { border-bottom: none; }
.crm-mini-table tr:hover td { background: var(--border-light); }

/* ============================================================
   BADGES
   ============================================================ */
.badge-yes  { background: rgba(22,163,74,.1); color: #16a34a; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-no   { background: rgba(100,116,139,.1); color: #64748b; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-warn { background: rgba(234,88,12,.1); color: #ea580c; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-info { background: rgba(37,99,235,.1); color: #2563eb; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 40px;
    opacity: .25;
    display: block;
    margin-bottom: 10px;
}
.empty-state p { margin: 0; font-size: 13.5px; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a2236 0%, #0f1929 100%);
    position: relative;
    overflow: hidden;
}
.login-wrap::before {
    content: '';
    position: absolute;
    width: 600px; height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(161,29,33,.12) 0%, transparent 70%);
    top: -200px; right: -200px;
}
.login-wrap::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37,99,235,.08) 0%, transparent 70%);
    bottom: -100px; left: -100px;
}
.login-card {
    background: rgba(255,255,255,.98);
    border-radius: 20px;
    padding: 44px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 80px rgba(0,0,0,.3);
    position: relative;
    z-index: 1;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo img {
    width: 60px;
    border-radius: 14px;
    box-shadow: 0 4px 16px rgba(161,29,33,.25);
}
.login-logo h4 { font-size: 22px; font-weight: 800; margin: 12px 0 3px; color: var(--text); }
.login-logo p { color: var(--text-muted); font-size: 13px; }
.login-card .form-label { font-weight: 600; font-size: 12.5px; color: var(--text); }
.login-card .input-group-text {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text-muted);
}
.login-card .form-control {
    border-color: var(--border);
    font-size: 14px;
    padding: 10px 14px;
}
.login-card .form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(161,29,33,.12); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-brand {
    background: linear-gradient(135deg, var(--brand) 0%, #c0272c 100%);
    color: #fff;
    border: none;
    font-weight: 600;
    letter-spacing: .2px;
    transition: var(--transition);
    box-shadow: 0 3px 10px rgba(161,29,33,.3);
}
.btn-brand:hover, .btn-brand:focus {
    background: linear-gradient(135deg, var(--brand-hover) 0%, #a11d21 100%);
    color: #fff;
    box-shadow: 0 5px 16px rgba(161,29,33,.4);
    transform: translateY(-1px);
}
.btn-brand:active { transform: translateY(0); }

/* ============================================================
   UTILITY
   ============================================================ */
.text-brand { color: var(--brand) !important; }
.bg-brand { background: var(--brand) !important; }

/* ============================================================
   TOAST
   ============================================================ */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-12px) scale(.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991px) {
    .crm-sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,.15);
    }
    .crm-sidebar.show { transform: translateX(0); }
    .crm-main { margin-left: 0; }
    .topbar-toggle { display: block; }
    .crm-page { padding: 16px; }
    .detail-offcanvas { width: 100vw !important; }
    .info-grid { grid-template-columns: 1fr; }
    .stat-value { font-size: 22px; }
}
@media (max-width: 575px) {
    .crm-page { padding: 12px; }
    .crm-card-header { padding: 12px 16px; }
    .crm-card-body { padding: 16px; }
}
