/* ===== DESIGN SYSTEM ===== */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Inter:wght@300;400;500;600&display=swap');

:root {
  --primary: #FF3B3B;
  --primary-hover: #e62e2e;
  --secondary: #FFD600;
  --bg: #0F0F0F;
  --card: #1A1A1A;
  --card-hover: #222222;
  --border: #2a2a2a;
  --text: #FFFFFF;
  --text-gray: #A0A0A0;
  --success: #00C853;
  --warning: #FFAB00;
  --danger: #FF3B3B;
  --sidebar-w: 240px;
  --navbar-h: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: all 0.3s cubic-bezier(.4,0,.2,1);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4 { font-family: 'Poppins', sans-serif; font-weight: 700; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
small, .text-sm { font-size: 12px; }

a { color: inherit; text-decoration: none; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif; font-weight: 600; font-size: 14px;
  cursor: pointer; border: none; transition: var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(255,59,59,0.4); }
.btn-secondary { background: transparent; color: var(--secondary); border: 1.5px solid var(--secondary); }
.btn-secondary:hover { background: rgba(255,214,0,0.1); transform: translateY(-2px); }
.btn-ghost { background: rgba(255,255,255,0.05); color: var(--text-gray); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-icon { width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; }

/* ===== INPUTS ===== */
.input, .select, textarea {
  width: 100%; padding: 10px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: 'Inter', sans-serif; font-size: 14px;
  transition: var(--transition); outline: none;
}
.input:focus, .select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(255,59,59,0.15); }
.input::placeholder { color: var(--text-gray); }

/* ===== LAYOUT ===== */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; transition: var(--transition);
}
.sidebar-brand {
  padding: 20px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo {
  width: 36px; height: 36px; background: var(--primary); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.sidebar-brand span { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 18px; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 20px;
  color: var(--text-gray); cursor: pointer; transition: var(--transition);
  position: relative; font-size: 14px; font-weight: 500;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.04); }
.nav-item.active {
  color: #fff; background: rgba(255,59,59,0.08);
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: var(--primary); border-radius: 0 4px 4px 0;
}
.nav-item .icon { width: 20px; text-align: center; font-size: 16px; }
.nav-item .badge {
  margin-left: auto; background: var(--primary); color: #fff;
  padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-footer .nav-item { padding: 8px 0; }

/* Main Area */
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

/* Navbar */
.navbar {
  height: var(--navbar-h); background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.search-box {
  flex: 1; max-width: 400px; position: relative;
}
.search-box .input { padding-left: 38px; background: rgba(255,255,255,0.04); border-color: transparent; }
.search-box .input:focus { border-color: var(--primary); background: var(--card); }
.search-box .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-gray); }

.navbar-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.notif-btn {
  position: relative; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.05); border: none; color: var(--text-gray);
  cursor: pointer; font-size: 18px; transition: var(--transition);
}
.notif-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.notif-btn .dot {
  position: absolute; top: 8px; right: 10px; width: 8px; height: 8px;
  background: var(--primary); border-radius: 50%; animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(1.3); } }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; cursor: pointer;
}

/* Content */
.content { padding: 24px; flex: 1; }
.page { display: none; animation: fadeIn .35s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ===== CARDS ===== */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; transition: var(--transition);
}
.card:hover { border-color: #333; box-shadow: var(--shadow); }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; transition: var(--transition); position: relative; overflow: hidden;
}
.stat-card::after {
  content: ''; position: absolute; top: 0; right: 0; width: 80px; height: 80px;
  border-radius: 50%; opacity: 0.06; transform: translate(20px, -20px);
}
.stat-card:nth-child(1)::after { background: var(--primary); }
.stat-card:nth-child(2)::after { background: var(--secondary); }
.stat-card:nth-child(3)::after { background: var(--success); }
.stat-card:nth-child(4)::after { background: var(--warning); }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: #333; }
.stat-card .stat-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 20px; margin-bottom: 14px;
}
.stat-card:nth-child(1) .stat-icon { background: rgba(255,59,59,0.12); color: var(--primary); }
.stat-card:nth-child(2) .stat-icon { background: rgba(255,214,0,0.12); color: var(--secondary); }
.stat-card:nth-child(3) .stat-icon { background: rgba(0,200,83,0.12); color: var(--success); }
.stat-card:nth-child(4) .stat-icon { background: rgba(255,171,0,0.12); color: var(--warning); }
.stat-card .stat-value { font-family: 'Poppins', sans-serif; font-size: 28px; font-weight: 700; }
.stat-card .stat-label { color: var(--text-gray); font-size: 13px; margin-top: 4px; }
.stat-card .stat-change { font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-card .stat-change.up { color: var(--success); }
.stat-card .stat-change.down { color: var(--danger); }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.grid-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 16px; color: var(--text-gray); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr { transition: var(--transition); }
tbody tr:hover { background: rgba(255,255,255,0.02); }

.status {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
  border-radius: 20px; font-size: 12px; font-weight: 600;
}
.status-new { background: rgba(255,59,59,0.12); color: var(--primary); }
.status-active { background: rgba(0,200,83,0.12); color: var(--success); }
.status-pending { background: rgba(255,171,0,0.12); color: var(--warning); }
.status-converted { background: rgba(0,200,83,0.12); color: var(--success); }
.status-cold { background: rgba(160,160,160,0.12); color: var(--text-gray); }

/* ===== CHAT UI ===== */
.chat-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - var(--navbar-h) - 48px); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.chat-list { background: var(--card); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.chat-list-header { padding: 16px; border-bottom: 1px solid var(--border); }
.chat-list-items { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  cursor: pointer; transition: var(--transition); border-bottom: 1px solid rgba(255,255,255,0.03);
}
.chat-item:hover { background: rgba(255,255,255,0.04); }
.chat-item.active { background: rgba(255,59,59,0.08); }
.chat-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 14px; }
.chat-item-msg { color: var(--text-gray); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { color: var(--text-gray); font-size: 11px; flex-shrink: 0; }
.chat-item .unread { background: var(--primary); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 10px; }

.chat-window { display: flex; flex-direction: column; background: var(--bg); }
.chat-window-header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; background: var(--card); }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg {
  max-width: 65%; padding: 12px 16px; border-radius: 16px; font-size: 14px; line-height: 1.5;
  animation: msgIn .3s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } }
.msg-in { background: var(--card); border-bottom-left-radius: 4px; align-self: flex-start; }
.msg-out { background: rgba(255,59,59,0.15); border-bottom-right-radius: 4px; align-self: flex-end; }
.msg-time { font-size: 11px; color: var(--text-gray); margin-top: 4px; }
.chat-input-area {
  padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 12px; align-items: center; background: var(--card);
}
.chat-input-area .input { flex: 1; border-radius: 24px; padding: 12px 20px; }

/* ===== DRAWER ===== */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200;
  opacity: 0; visibility: hidden; transition: var(--transition);
}
.drawer-overlay.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; right: -480px; width: 480px; height: 100vh;
  background: var(--card); z-index: 201; transition: var(--transition);
  overflow-y: auto; border-left: 1px solid var(--border);
}
.drawer.open { right: 0; }
.drawer-header {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.drawer-body { padding: 20px; }
.drawer-close { background: none; border: none; color: var(--text-gray); font-size: 24px; cursor: pointer; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 20px; color: var(--text-gray); cursor: pointer; font-size: 14px;
  font-weight: 500; border-bottom: 2px solid transparent; transition: var(--transition);
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--primary); }

/* ===== FILTER BAR ===== */
.filter-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.filter-bar .select { width: auto; min-width: 150px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 300;
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  animation: modalIn .3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } }
.modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; }

/* Form groups */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-gray); margin-bottom: 6px; font-weight: 500; }

/* ===== CHART PLACEHOLDER ===== */
.chart-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.chart-box h3 { margin-bottom: 16px; }
.chart-area { height: 260px; position: relative; display: flex; align-items: flex-end; gap: 8px; padding-top: 20px; }
.chart-bar {
  flex: 1; border-radius: 6px 6px 0 0; transition: var(--transition); cursor: pointer; position: relative;
  min-width: 20px;
}
.chart-bar:hover { opacity: 0.8; transform: scaleY(1.03); transform-origin: bottom; }
.chart-bar .chart-tooltip {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--bg); padding: 4px 10px; border-radius: 6px; font-size: 12px;
  white-space: nowrap; opacity: 0; transition: var(--transition); pointer-events: none;
}
.chart-bar:hover .chart-tooltip { opacity: 1; }

/* Mini pie chart via conic-gradient */
.pie-chart {
  width: 180px; height: 180px; border-radius: 50%; margin: 0 auto;
}
.pie-legend { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.pie-legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pie-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ===== ACTIVITY LIST ===== */
.activity-list { display: flex; flex-direction: column; gap: 0; }
.activity-item {
  display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.activity-content { flex: 1; }
.activity-content p { font-size: 14px; }
.activity-content small { color: var(--text-gray); }

/* ===== TIMELINE ===== */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item::before {
  content: ''; position: absolute; left: -21px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid var(--card);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .grid-2, .grid-equal { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
  .drawer { width: 100%; right: -100%; }
}
