/* ============================================================
   WhatsApp CRM — Main Stylesheet
   ============================================================ */

:root {
  --sidebar-width: 260px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active-bg: rgba(255,255,255,.08);
  --sidebar-active-text: #ffffff;
  --top-bar-height: 60px;
  --primary: #25D366;
  --primary-dark: #128C7E;
  --accent: #075E54;
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

/* ── Reset / Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body.crm-body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  color: var(--text-dark);
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.brand-logo {
  width: 38px; height: 38px;
  background: rgba(37,211,102,.15);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; color: #fff; font-size: 14px; display: block; line-height: 1.2; }
.brand-sub { font-size: 10px; color: #94a3b8; text-transform: uppercase; letter-spacing: .6px; }

.wa-status-strip { flex-shrink: 0; }

.sidebar-nav {
  flex: 1;
  padding: 8px 10px;
  overflow-y: auto;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #475569;
  padding: 6px 8px 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
  white-space: nowrap;
}
.nav-link i { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.nav-link.active i { color: var(--primary); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-footer .text-muted { color: #94a3b8 !important; }

/* ── Main Wrapper ─────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .25s ease;
}

/* ── Top Navbar ───────────────────────────────────────────── */
.top-navbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  height: var(--top-bar-height);
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: var(--shadow);
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--card-bg);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  font-weight: 600;
}

/* Stat Cards */
.stat-card {
  border-radius: var(--radius);
  padding: 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-dark);
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.stat-card .stat-icon {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 40px;
  opacity: .08;
  color: var(--text-dark);
}
.stat-card .stat-change { font-size: 12px; margin-top: 8px; }
.stat-card-green  { border-left: 4px solid #10b981; }
.stat-card-blue   { border-left: 4px solid #3b82f6; }
.stat-card-yellow { border-left: 4px solid #f59e0b; }
.stat-card-red    { border-left: 4px solid #ef4444; }
.stat-card-purple { border-left: 4px solid #8b5cf6; }
.stat-card-teal   { border-left: 4px solid #14b8a6; }

/* ── Avatars ──────────────────────────────────────────────── */
.avatar-circle-sm {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.avatar-circle {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.avatar-circle img, .avatar-circle-sm img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ── Tables ───────────────────────────────────────────────── */
.table-hover > tbody > tr:hover > td { background-color: #f8fafc; }
.table th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); border-bottom-width: 1px; }
.table td { vertical-align: middle; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-icon {
  padding: 6px 8px;
  line-height: 1;
  border: none;
  background: transparent;
  color: inherit;
}
.btn-icon:hover { background: rgba(0,0,0,.05); border-radius: 6px; }
.btn-wa {
  background: #25D366;
  color: #fff;
  border: none;
}
.btn-wa:hover { background: #22c55e; color: #fff; }

/* ── Badges ───────────────────────────────────────────────── */
.notification-badge {
  position: absolute;
  top: 2px; right: 2px;
  font-size: 9px;
  padding: 2px 4px;
  border-radius: 10px;
  min-width: 16px;
}

/* ── Notification Dropdown ────────────────────────────────── */
.notification-dropdown { width: 320px; max-height: 400px; overflow-y: auto; }
.dropdown-header { font-size: 13px; font-weight: 600; }

/* ── User Menu Button ─────────────────────────────────────── */
.user-menu-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
  color: var(--text-dark);
}
.user-menu-btn:hover { background: var(--body-bg); }

/* ── Forms ────────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border);
  font-size: 14px;
  transition: border-color .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(18,140,126,.1);
}

/* ── Search Bar ───────────────────────────────────────────── */
.search-bar { position: relative; }
.search-bar input { padding-left: 38px; border-radius: 8px; }
.search-bar i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* ── Tags ─────────────────────────────────────────────────── */
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}

/* ── Chat / Conversation ──────────────────────────────────── */
.chat-container { display: flex; height: calc(100vh - 120px); gap: 16px; }
.chat-list { width: 320px; flex-shrink: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; background: #e5ddd5 url("data:image/svg+xml,..."); border-radius: var(--radius); }
.message-bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}
.message-bubble.outbound {
  background: #d9fdd3;
  margin-left: auto;
  border-bottom-right-radius: 2px;
}
.message-bubble.inbound {
  background: #fff;
  border-bottom-left-radius: 2px;
}
.message-bubble .msg-time {
  font-size: 10px;
  color: #888;
  text-align: right;
  margin-top: 4px;
}
.message-bubble .msg-status { margin-left: 4px; font-size: 12px; }
.internal-note-bubble {
  background: #fef9c3;
  border-left: 3px solid #f59e0b;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin: 8px 0;
  font-style: italic;
}
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 0 0;
}
.chat-input-area .form-control { border-radius: 24px; }

/* ── Pipeline / Kanban ────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
  min-height: 500px;
}
.kanban-column {
  min-width: 260px;
  width: 260px;
  flex-shrink: 0;
  background: #f8fafc;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.kanban-column-header {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kanban-cards { padding: 10px; min-height: 100px; }
.kanban-card {
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .1s;
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card.sortable-ghost { opacity: .4; background: #e0f2fe; }
.kanban-card .card-name { font-weight: 600; font-size: 13px; }
.kanban-card .card-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Activity Timeline ────────────────────────────────────── */
.activity-timeline { list-style: none; padding: 0; margin: 0; }
.activity-timeline li {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}
.activity-timeline li::before {
  content: '';
  position: absolute;
  left: 15px; top: 28px; bottom: 0;
  width: 2px;
  background: var(--border);
}
.activity-timeline li:last-child::before { display: none; }
.timeline-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.timeline-body { flex: 1; }
.timeline-body .tl-action { font-weight: 500; font-size: 13px; }
.timeline-body .tl-time { font-size: 11px; color: var(--text-muted); }

/* ── Mobile Sidebar Overlay ───────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1025;
}
.sidebar-overlay.show { display: block; }

/* ── Login Page ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-dark) 40%, var(--primary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo i { font-size: 48px; color: var(--primary); }

/* ── Page Header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; margin: 0; }

/* ── Filter Bar ───────────────────────────────────────────── */
.filter-bar {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}

/* ── Contact Card (list) ─────────────────────────────────── */
.contact-row { cursor: pointer; transition: background .1s; }
.contact-row:hover td { background: #f0fdf4; }

/* ── Follow-up Card ───────────────────────────────────────── */
.followup-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.followup-card.overdue { border-left: 4px solid #ef4444; }
.followup-card.due-today { border-left: 4px solid #f59e0b; }
.followup-card.completed { opacity: .6; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .main-content { padding: 16px; }
  .chat-container { flex-direction: column; height: auto; }
  .chat-list { width: 100%; }
  .kanban-board { flex-wrap: nowrap; }
}

/* ── Utilities ────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.text-green { color: #10b981; }
.text-wa { color: #25D366; }
.bg-wa { background-color: #25D366; }
.border-start-success { border-left: 4px solid #10b981 !important; }
.border-start-warning { border-left: 4px solid #f59e0b !important; }
.border-start-danger  { border-left: 4px solid #ef4444 !important; }
