:root {
    --primary: #575dd8;
    --primary-dark: #4147b9;
    --primary-soft: #eef0ff;
    --ink: #162033;
    --muted: #718096;
    --surface: #ffffff;
    --surface-2: #f4f7fb;
    --line: #e6ebf2;
    --success: #15966b;
    --danger: #df4b5f;
    --warning: #e99b20;
    --info: #2784d7;
    --sidebar: #121a2c;
    --shadow: 0 12px 34px rgba(22, 32, 51, .07);
}

:root[data-theme="dark"] {
    --ink: #edf2f8;
    --muted: #9ca9bc;
    --surface: #182235;
    --surface-2: #0f1726;
    --line: #2a374c;
    --primary-soft: #292d62;
    --shadow: 0 12px 34px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-2); }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--surface-2);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }
.btn { border-radius: 10px; font-weight: 700; font-size: 13px; padding: .55rem .9rem; }
.btn-sm { padding: .38rem .65rem; font-size: 12px; border-radius: 8px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-soft { background: var(--primary-soft); color: var(--primary); border: 1px solid transparent; }
.btn-soft:hover { color: var(--primary-dark); background: #e2e5ff; }
.btn-success-soft { color: #08724e; background: #e1f7ee; border: 0; }
.btn-danger-soft { color: #ba3145; background: #ffe8eb; border: 0; }
.btn-warning-soft { color: #9a5a00; background: #fff2d8; border: 0; }
.btn-info-soft { color: #176bb2; background: #e5f3ff; border: 0; }
.form-control, .form-select {
    min-height: 41px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 13px;
}
.form-control:focus, .form-select:focus {
    color: var(--ink);
    background: var(--surface);
    border-color: #989cf0;
    box-shadow: 0 0 0 .2rem rgba(87, 93, 216, .12);
}
.form-label { margin-bottom: .35rem; font-size: 12px; font-weight: 750; color: var(--ink); }
.text-muted { color: var(--muted) !important; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    width: 242px;
    display: flex;
    flex-direction: column;
    color: #dbe4f2;
    background: var(--sidebar);
    border-right: 1px solid rgba(255, 255, 255, .04);
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 76px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(145deg, #6d74ef, #4046b9);
    border-radius: 12px;
    font-size: 19px;
    font-weight: 850;
    box-shadow: 0 8px 20px rgba(77, 83, 204, .34);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.sidebar-brand strong { display: block; max-width: 156px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: #fff; }
.sidebar-brand small, .sidebar-user small { display: block; margin-top: 2px; color: #8391a8; font-size: 10px; }
.sidebar-nav { flex: 1; padding: 14px 11px; overflow-y: auto; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 42px;
    margin-bottom: 4px;
    padding: 9px 11px;
    color: #9ca9bc;
    border-radius: 10px;
    font-size: 12.5px;
    font-weight: 650;
}
.sidebar-nav a:hover { color: #fff; background: rgba(255, 255, 255, .055); }
.sidebar-nav a.active { color: #fff; background: linear-gradient(100deg, rgba(96, 103, 232, .9), rgba(82, 88, 204, .66)); }
.nav-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; font-size: 15px; }
.icon-grid::before { content: "▦"; }
.icon-users::before { content: "♟"; }
.icon-contacts::before { content: "☷"; }
.icon-upload::before { content: "⇧"; }
.icon-message::before { content: "◫"; }
.icon-chart::before { content: "▥"; }
.icon-trophy::before { content: "♛"; }
.icon-shield::before { content: "◇"; }
.icon-settings::before { content: "⚙"; }
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 70px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-user > span:nth-child(2) { flex: 1; min-width: 0; }
.sidebar-user strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: #fff; }
.avatar, .top-avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 11px;
    color: #fff;
    background: #39425a;
    font-weight: 800;
}
.icon-button {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    color: inherit;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.sidebar .icon-button { border-color: rgba(255, 255, 255, .12); }
.app-main { min-height: 100vh; margin-left: 242px; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    min-height: 76px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}
.topbar h1 { margin: 1px 0 0; font-size: 19px; font-weight: 820; letter-spacing: -.02em; }
.eyebrow { display: block; color: var(--muted); font-size: 9.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #21b47e; box-shadow: 0 0 0 4px rgba(33, 180, 126, .13); }
.sidebar-toggle { display: none; }
.content-area { max-width: 1480px; margin: 0 auto; padding: 20px 24px 34px; }
.mobile-nav, .sidebar-backdrop { display: none; }

.page-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.page-actions h2 { margin: 0; font-size: 16px; font-weight: 800; }
.page-actions p { margin: 3px 0 0; color: var(--muted); font-size: 11.5px; }
.action-cluster { display: flex; flex-wrap: wrap; gap: 7px; }
.panel {
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 15px;
    box-shadow: var(--shadow);
}
.panel-header {
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
}
.panel-header h3 { margin: 0; font-size: 13.5px; font-weight: 800; }
.panel-header p { margin: 2px 0 0; color: var(--muted); font-size: 10.5px; }
.panel-body { padding: 14px; }
.panel + .panel { margin-top: 14px; }
.compact-alert { padding: .65rem .8rem; border: 0; border-radius: 11px; font-size: 12.5px; box-shadow: var(--shadow); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; margin-bottom: 14px; }
.metric-card {
    min-height: 102px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}
.metric-icon { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-size: 17px; font-weight: 900; }
.metric-card small { display: block; margin-bottom: 3px; color: var(--muted); font-size: 10.5px; font-weight: 650; }
.metric-card strong { display: block; font-size: 21px; line-height: 1; font-weight: 850; letter-spacing: -.03em; }
.metric-card em { display: block; margin-top: 5px; color: var(--success); font-size: 9.5px; font-style: normal; }
.metric-primary { color: #fff; background: linear-gradient(145deg, #646ae1, #454bbd); border: 0; }
.metric-primary small, .metric-primary em { color: rgba(255,255,255,.75); }
.metric-primary .metric-icon { color: #fff; background: rgba(255,255,255,.15); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 14px; }
.activity-chart { width: 100%; height: 190px; display: block; }
.chart-legend { display: flex; gap: 12px; color: var(--muted); font-size: 10px; }
.chart-legend i { width: 8px; height: 8px; display: inline-block; margin-right: 4px; border-radius: 3px; background: #19a974; }
.chart-legend span:last-child i { background: var(--primary); }

.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); margin: 0; font-size: 11.5px; }
.table > :not(caption) > * > * { padding: .65rem .65rem; border-bottom-color: var(--line); vertical-align: middle; }
.table thead th { color: var(--muted); font-size: 9.5px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-responsive { border-radius: 0 0 15px 15px; }
.person-cell { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.person-cell .avatar { width: 29px; height: 29px; flex-basis: 29px; border-radius: 9px; font-size: 11px; background: var(--primary-soft); color: var(--primary); }
.person-cell strong { display: block; font-size: 11.5px; }
.person-cell small { display: block; margin-top: 1px; color: var(--muted); font-size: 9.5px; }
.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 7px;
    border-radius: 999px;
    font-size: 9.5px;
    font-weight: 800;
    white-space: nowrap;
}
.status-new { color: #526176; background: #edf1f6; }
.status-contacted { color: #176bb2; background: #e5f3ff; }
.status-interested { color: #08724e; background: #dff7ed; }
.status-follow-up { color: #8a5c00; background: #fff0c9; }
.status-registered { color: #4b42b2; background: #eae8ff; }
.status-deposited, .status-completed { color: #08724e; background: #d8f5e8; }
.status-not-interested, .status-invalid { color: #af3547; background: #ffe6ea; }
.status-active { color: #08724e; background: #dff7ed; }
.status-disabled, .status-inactive { color: #af3547; background: #ffe6ea; }
.online-badge { color: var(--success); font-size: 9px; font-weight: 800; }
.filter-bar { display: grid; grid-template-columns: 2fr repeat(4, 1fr) auto; gap: 8px; padding: 12px; }
.filter-bar.compact { grid-template-columns: 2fr 1fr auto; }
.bulk-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 9px 12px; background: var(--primary-soft); border-top: 1px solid var(--line); }
.bulk-bar .form-select { width: auto; min-width: 180px; min-height: 34px; }
.pagination { margin: 12px 0 0; gap: 4px; }
.page-link { color: var(--ink); background: var(--surface); border-color: var(--line); border-radius: 8px !important; font-size: 11px; }
.active > .page-link { background: var(--primary); border-color: var(--primary); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.credential-card { padding: 12px 14px; margin-bottom: 14px; color: #fff; background: linear-gradient(135deg, #15966b, #087a57); border-radius: 14px; box-shadow: var(--shadow); }
.credential-card code { display: inline-block; padding: 5px 8px; margin: 6px 7px 0 0; color: #123; background: #fff; border-radius: 7px; font-weight: 800; }
.import-drop {
    display: grid;
    place-items: center;
    min-height: 160px;
    padding: 24px;
    text-align: center;
    background: var(--surface-2);
    border: 1.5px dashed #b8c0d0;
    border-radius: 13px;
}
.import-drop strong { display: block; margin-bottom: 5px; font-size: 14px; }
.import-drop small { color: var(--muted); }
.import-drop input { max-width: 360px; margin: 13px auto 0; }
.template-preview { white-space: pre-line; color: var(--muted); font-size: 11px; line-height: 1.55; }
.code-hint { display: inline-block; padding: 3px 6px; color: var(--primary); background: var(--primary-soft); border-radius: 6px; font-size: 10px; }

.contact-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.contact-card {
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    transition: opacity .2s, transform .2s;
}
.card-dismissed { opacity: 0; transform: translateX(25px); }
.contact-card-head { display: flex; align-items: center; gap: 9px; padding: 11px 12px 9px; }
.contact-card-head .avatar { color: var(--primary); background: var(--primary-soft); }
.contact-card-head > div { flex: 1; min-width: 0; }
.contact-card-head h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 800; }
.contact-card-head a.phone { display: block; margin-top: 2px; color: var(--muted); font-size: 10.5px; }
.contact-meta { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 8px; }
.contact-meta small { padding: 3px 6px; color: var(--muted); background: var(--surface-2); border-radius: 6px; font-size: 9px; }
.contact-note { min-height: 34px; margin: 0 12px 9px; padding: 7px 8px; color: var(--muted); background: var(--surface-2); border-radius: 8px; font-size: 10px; }
.template-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 8px; }
.template-row .form-select { min-height: 32px; padding-top: .25rem; padding-bottom: .25rem; font-size: 10px; }
.contact-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 9px 12px; border-top: 1px solid var(--line); }
.contact-actions .btn { padding: .45rem .3rem; font-size: 10px; }
.quick-statuses { display: flex; gap: 5px; overflow-x: auto; padding: 8px 12px; border-top: 1px solid var(--line); scrollbar-width: none; }
.quick-statuses form { flex: 0 0 auto; }
.quick-statuses .btn { padding: .33rem .5rem; font-size: 9.5px; white-space: nowrap; }
.contact-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--surface-2); font-size: 9.5px; }
.contact-footer a { color: var(--primary); font-weight: 800; }
.due-over { color: var(--danger); font-weight: 750; }
.followup-list { display: grid; gap: 7px; }
.followup-item { display: flex; align-items: center; gap: 9px; padding: 9px; background: var(--surface-2); border-radius: 10px; }
.followup-item > div { flex: 1; min-width: 0; }
.followup-item strong { display: block; font-size: 11px; }
.followup-item small { display: block; color: var(--muted); font-size: 9.5px; }
.timeline { position: relative; display: grid; gap: 8px; }
.timeline-item { position: relative; padding: 9px 10px 9px 29px; background: var(--surface-2); border-radius: 9px; }
.timeline-item::before { content: ""; position: absolute; left: 11px; top: 14px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.timeline-item strong { display: block; font-size: 10.5px; }
.timeline-item small { color: var(--muted); font-size: 9px; }
.timeline-item p { margin: 4px 0 0; font-size: 10.5px; }
.rank { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-size: 10px; font-weight: 850; }
.rank.top { color: #744c00; background: #ffe8aa; }

.guest-body {
    display: grid;
    place-items: center;
    padding: 22px;
    background:
        radial-gradient(circle at 15% 15%, rgba(91, 97, 220, .18), transparent 30%),
        radial-gradient(circle at 88% 80%, rgba(21, 150, 107, .12), transparent 32%),
        #f3f6fb;
}
.guest-shell { width: min(100%, 430px); }
.guest-brand { display: flex; align-items: center; gap: 10px; margin: 0 0 15px 4px; }
.guest-brand strong { display: block; font-size: 13px; }
.guest-brand span:not(.brand-mark) { color: var(--muted); font-size: 10px; }
.login-card, .error-card {
    padding: 25px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(22, 32, 51, .12);
}
.login-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.login-icon { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; color: #fff; background: var(--primary); border-radius: 13px; font-size: 18px; font-weight: 900; }
.login-heading h1 { margin: 2px 0 5px; font-size: 22px; font-weight: 850; }
.login-heading p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.password-field { position: relative; }
.password-field input { padding-right: 58px; }
.password-field button { position: absolute; top: 5px; right: 5px; height: 31px; padding: 0 9px; color: var(--primary); background: var(--primary-soft); border: 0; border-radius: 7px; font-size: 10px; font-weight: 800; }
.login-button { min-height: 45px; }
.security-note { margin: 15px 0 0; color: var(--muted); font-size: 9.5px; line-height: 1.5; text-align: center; }
.error-card { text-align: center; }
.error-card > span { display: block; color: var(--primary); font-size: 54px; font-weight: 900; letter-spacing: -.06em; }
.error-card h1 { font-size: 20px; font-weight: 850; }
.error-card p { color: var(--muted); font-size: 12px; }
.crm-toast { position: fixed; right: 18px; bottom: 18px; z-index: 2000; max-width: 330px; padding: 11px 14px; opacity: 0; transform: translateY(12px); color: #fff; background: #182235; border-radius: 11px; box-shadow: 0 14px 40px rgba(0,0,0,.24); font-size: 11px; transition: .2s; }
.crm-toast.error { background: #b83449; }
.crm-toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
    body { padding-bottom: 62px; }
    .sidebar { transform: translateX(-102%); box-shadow: 20px 0 50px rgba(0,0,0,.2); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop { position: fixed; inset: 0; z-index: 1030; background: rgba(7, 12, 23, .55); }
    .sidebar-backdrop.show { display: block; }
    .app-main { margin-left: 0; }
    .sidebar-toggle { display: grid; }
    .content-area { padding: 14px 12px 24px; }
    .topbar { min-height: 64px; padding: 9px 12px; }
    .topbar h1 { font-size: 16px; }
    .topbar .eyebrow { font-size: 8px; }
    .mobile-nav { position: fixed; inset: auto 8px 8px; z-index: 1025; min-height: 52px; display: flex; align-items: center; justify-content: space-around; padding: 4px; background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 36px rgba(22,32,51,.18); backdrop-filter: blur(14px); }
    .mobile-nav a { min-width: 52px; display: grid; place-items: center; gap: 1px; padding: 5px 7px; color: var(--muted); border-radius: 11px; }
    .mobile-nav a.active { color: #fff; background: var(--primary); }
    .mobile-nav small { font-size: 7.5px; font-weight: 750; }
    .mobile-nav .nav-icon { height: 15px; font-size: 13px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .contact-card-grid { grid-template-columns: 1fr; }
    .form-grid.three { grid-template-columns: repeat(2, 1fr); }
    .form-grid .span-3 { grid-column: span 2; }
}
@media (max-width: 560px) {
    body { font-size: 13px; }
    .content-area { padding: 10px 9px 18px; }
    .topbar-actions .online-dot, .topbar-actions .icon-button { display: none; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
    .metric-card { min-height: 80px; gap: 8px; padding: 10px; border-radius: 12px; }
    .metric-icon { width: 31px; height: 31px; flex-basis: 31px; border-radius: 9px; font-size: 13px; }
    .metric-card strong { font-size: 17px; }
    .metric-card small { font-size: 8.5px; }
    .metric-card em { margin-top: 3px; font-size: 8px; }
    .page-actions { align-items: flex-start; }
    .page-actions h2 { font-size: 14px; }
    .panel { border-radius: 12px; }
    .panel-body { padding: 10px; }
    .filter-bar, .filter-bar.compact { grid-template-columns: 1fr 1fr; padding: 9px; }
    .filter-bar > :first-child { grid-column: span 2; }
    .filter-bar .btn { min-height: 40px; }
    .form-grid, .form-grid.three { grid-template-columns: 1fr; }
    .form-grid .span-2, .form-grid .span-3 { grid-column: span 1; }
    .contact-card-head { padding: 9px 10px 7px; }
    .contact-meta, .template-row, .contact-actions, .quick-statuses, .contact-footer { padding-left: 10px; padding-right: 10px; }
    .contact-note { margin-left: 10px; margin-right: 10px; }
    .contact-actions { grid-template-columns: repeat(3, 1fr); }
    .table > :not(caption) > * > * { padding: .5rem; }
    .guest-body { padding: 14px; }
    .login-card, .error-card { padding: 20px; border-radius: 17px; }
}
