/* ============================================================
   OmniCRM — Design System & Core Styles
   ============================================================ */

/* ── CSS Variables ── */
:root {
    --bg:            #0a0e17;
    --bg-surface:    #111827;
    --bg-card:       #1a2236;
    --bg-card-hover: #1e2a42;
    --bg-elevated:   #243050;

    --border:        #1e293b;
    --border-light:  #334155;

    --text:          #e2e8f0;
    --text-muted:    #94a3b8;
    --text-faint:    #64748b;
    --text-heading:  #f1f5f9;

    --primary:       #6366f1;
    --primary-hover: #818cf8;
    --primary-glow:  rgba(99,102,241,.25);

    --success:       #10b981;
    --success-bg:    rgba(16,185,129,.12);
    --warning:       #f59e0b;
    --warning-bg:    rgba(245,158,11,.12);
    --danger:        #ef4444;
    --danger-bg:     rgba(239,68,68,.12);
    --info:          #3b82f6;
    --info-bg:       rgba(59,130,246,.12);

    --accent-purple: #8b5cf6;
    --accent-pink:   #ec4899;
    --accent-cyan:   #06b6d4;
    --accent-orange: #f97316;

    --sidebar-w:     260px;
    --sidebar-w-sm:  70px;
    --topbar-h:      60px;
    --radius:        10px;
    --radius-sm:     6px;
    --radius-lg:     16px;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
    --transition: .2s cubic-bezier(.4,0,.2,1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }
ul { list-style: none; }

/* ── App Layout ── */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: width var(--transition), transform var(--transition);
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-heading);
}
.sidebar-logo i { font-size: 1.6rem; color: var(--primary); }
.sidebar-toggle {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 1.2rem; padding: 4px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.sidebar-toggle:hover { background: var(--bg-elevated); color: var(--text); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-muted);
    border-radius: var(--radius);
    transition: all var(--transition);
    margin-bottom: 2px;
    position: relative;
    font-weight: 500;
}
.nav-item i { font-size: 1.25rem; width: 22px; text-align: center; }
.nav-item:hover { background: var(--bg-elevated); color: var(--text); transform: translateX(2px); }
.nav-item.active {
    background: linear-gradient(135deg, var(--primary-glow), transparent);
    color: var(--primary-hover);
    font-weight: 600;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 24px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}
.nav-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: .7rem;
    padding: 2px 8px;
    border-radius: 50px;
    font-weight: 700;
}
.nav-divider { height: 1px; background: var(--border); margin: 12px 14px; }
.nav-section-label {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-faint);
    padding: 8px 14px 4px;
    font-weight: 700;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 12px 14px;
}
.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
}
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .9rem;
    color: #fff;
    flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-weight: 600; font-size: .85rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: .7rem; color: var(--text-faint); }

/* ── Main Content ── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition);
}

.topbar {
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 50;
}
.page-title { font-size: 1.1rem; font-weight: 700; color: var(--text-heading); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.sidebar-open-btn { display: none; background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; }

.page-content { flex: 1; padding: 24px; }

/* ── Alerts ── */
.alert {
    padding: 12px 18px;
    border-radius: var(--radius);
    margin: 12px 24px 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: .9rem;
    animation: alertSlide .3s ease;
}
.alert i { font-size: 1.2rem; flex-shrink: 0; margin-top: 2px; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16,185,129,.2); }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,.2); }
@keyframes alertSlide { from { transform: translateY(-10px); opacity: 0; } }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: .85rem;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px var(--primary-glow); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 16px var(--primary-glow); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--text-faint); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 6px; border-radius: var(--radius-sm); font-size: 1.1rem; transition: all var(--transition); }
.btn-icon:hover { background: var(--bg-elevated); color: var(--text); }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition);
}
.card:hover { border-color: var(--border-light); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 700; color: var(--text-heading); }

/* ── Stat Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: all var(--transition);
}
.stat-card:hover { border-color: var(--border-light); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}
.stat-icon.purple { background: rgba(139,92,246,.15); color: var(--accent-purple); }
.stat-icon.blue   { background: rgba(59,130,246,.15); color: var(--info); }
.stat-icon.green  { background: rgba(16,185,129,.15); color: var(--success); }
.stat-icon.orange { background: rgba(249,115,22,.15); color: var(--accent-orange); }
.stat-icon.pink   { background: rgba(236,72,153,.15); color: var(--accent-pink); }
.stat-icon.cyan   { background: rgba(6,182,212,.15); color: var(--accent-cyan); }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text-heading); line-height: 1.2; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.stat-trend { font-size: .75rem; margin-top: 4px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
thead th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-faint);
    font-weight: 600;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--bg-card-hover); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 600; font-size: .85rem; color: var(--text); margin-bottom: 6px; }
.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    transition: all var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.form-control::placeholder { color: var(--text-faint); }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { padding-right: 36px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8'%3E%3Cpath d='M6 9L1 4h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.form-hint { font-size: .78rem; color: var(--text-faint); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: 4px; }

/* ── Badges ── */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: capitalize;
}
.status-badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.status-badge.new_lead, .status-badge.new, .status-badge.draft { background: var(--info-bg); color: var(--info); }
.status-badge.engaged, .status-badge.open, .status-badge.unread { background: rgba(139,92,246,.12); color: var(--accent-purple); }
.status-badge.qualified, .status-badge.assigned { background: rgba(249,115,22,.12); color: var(--accent-orange); }
.status-badge.customer, .status-badge.won, .status-badge.paid, .status-badge.active, .status-badge.resolved, .status-badge.success { background: var(--success-bg); color: var(--success); }
.status-badge.inactive, .status-badge.pending, .status-badge.partial { background: var(--warning-bg); color: var(--warning); }
.status-badge.blacklisted, .status-badge.lost, .status-badge.overdue, .status-badge.failed, .status-badge.suspended, .status-badge.cancelled { background: var(--danger-bg); color: var(--danger); }
.status-badge.closed, .status-badge.archived { background: rgba(100,116,139,.12); color: var(--text-faint); }
.status-badge.trial { background: rgba(6,182,212,.12); color: var(--accent-cyan); }
.status-badge.sent { background: rgba(59,130,246,.12); color: var(--info); }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 4px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span {
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    font-weight: 500;
    transition: all var(--transition);
}
.pagination a { color: var(--text-muted); background: var(--bg-card); border: 1px solid var(--border); }
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .active span { background: var(--primary); color: #fff; }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state i { font-size: 3rem; color: var(--text-faint); margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 8px; }
.empty-state p { color: var(--text-faint); font-size: .9rem; }

/* ── Search ── */
.search-box {
    position: relative;
    max-width: 320px;
}
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-box input { padding-left: 38px; }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn .2s ease;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlide .3s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--text-heading); }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalSlide { from { transform: translateY(-20px); opacity: 0; } }

/* ── Auth Pages ── */
.auth-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrapper { width: 100%; max-width: 420px; padding: 20px; }
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo i { font-size: 3rem; color: var(--primary); margin-bottom: 8px; display: block; }
.auth-logo h1 { font-size: 1.6rem; font-weight: 800; color: var(--text-heading); margin-bottom: 4px; }
.auth-logo p { font-size: .85rem; color: var(--text-muted); }
.auth-card .form-group { margin-bottom: 18px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: .9rem; }
.auth-link { display: block; text-align: center; margin-top: 16px; font-size: .85rem; color: var(--text-muted); }
.auth-link a { color: var(--primary); font-weight: 600; }
.auth-footer { text-align: center; margin-top: 20px; }
.auth-footer p { font-size: .78rem; color: var(--text-faint); }

/* ── Inbox Layout ── */
.inbox-layout { display: grid; grid-template-columns: 340px 1fr; gap: 0; height: calc(100vh - var(--topbar-h) - 48px); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.inbox-sidebar { background: var(--bg-card); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.inbox-sidebar-header { padding: 14px; border-bottom: 1px solid var(--border); }
.inbox-list { flex: 1; overflow-y: auto; }
.inbox-item {
    display: flex;
    gap: 12px;
    padding: 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}
.inbox-item:hover, .inbox-item.active { background: var(--bg-card-hover); }
.inbox-item.unread { border-left: 3px solid var(--primary); }
.inbox-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-purple), var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .85rem;
    color: #fff;
    flex-shrink: 0;
}
.inbox-preview { flex: 1; min-width: 0; }
.inbox-contact-name { font-weight: 600; font-size: .9rem; color: var(--text-heading); }
.inbox-last-msg { font-size: .8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.inbox-time { font-size: .7rem; color: var(--text-faint); white-space: nowrap; }
.inbox-main { display: flex; flex-direction: column; background: var(--bg-surface); }
.inbox-chat-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.inbox-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg-bubble { max-width: 70%; padding: 10px 14px; border-radius: 16px; font-size: .9rem; line-height: 1.5; animation: msgIn .3s ease; }
.msg-bubble.inbound { background: var(--bg-card); color: var(--text); border-bottom-left-radius: 4px; align-self: flex-start; }
.msg-bubble.outbound { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.msg-meta { font-size: .7rem; color: var(--text-faint); margin-top: 4px; }
.msg-bubble.outbound .msg-meta { color: rgba(255,255,255,.6); }
@keyframes msgIn { from { transform: translateY(8px); opacity: 0; } }
.inbox-composer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.inbox-composer input { flex: 1; }
.inbox-empty { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--text-faint); }

/* ── Pipeline / Kanban ── */
.pipeline-board { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 16px; }
.pipeline-column {
    min-width: 280px;
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 160px);
}
.pipeline-col-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: .9rem;
}
.pipeline-col-header .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.pipeline-col-header .count { margin-left: auto; background: var(--bg-elevated); padding: 2px 8px; border-radius: 50px; font-size: .75rem; color: var(--text-muted); }
.pipeline-col-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.deal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    cursor: grab;
    transition: all var(--transition);
}
.deal-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.deal-title { font-weight: 600; font-size: .88rem; color: var(--text-heading); margin-bottom: 6px; }
.deal-amount { font-weight: 700; font-size: .95rem; color: var(--primary-hover); }
.deal-contact { font-size: .78rem; color: var(--text-muted); margin-top: 6px; }

/* ── Utility ── */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .85rem; }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-open-btn { display: block; }
    .inbox-layout { grid-template-columns: 1fr; }
    .inbox-sidebar { max-height: 40vh; }
}
