/* ============================================================
   SmartCore CRM — Design System
   Supports dark (default) and light themes via [data-theme]
   ============================================================ */

/* ── Tokens ──────────────────────────────────────────────── */
:root, [data-theme="dark"] {
  --bg:        #05081a;
  --bg2:       #07163b;
  --bg3:       #0a0f2e;
  --sidebar:   #060c22;
  --card:      rgba(10,15,40,0.85);
  --card2:     rgba(14,20,50,0.6);
  --line:      rgba(255,255,255,0.08);
  --line2:     rgba(255,255,255,0.05);
  --text:      #e9f0ff;
  --text2:     rgba(233,240,255,0.72);
  --text3:     rgba(233,240,255,0.45);
  --text-dim:  rgba(233,240,255,0.45);
  --blue:      #1e5cff;
  --blue2:     #0ea5ff;
  --blue-dim:  rgba(30,92,255,0.15);
  --blue-glow: 0 0 0 3px rgba(30,92,255,0.18);
  --good:      #10b981;
  --good-dim:  rgba(16,185,129,0.15);
  --warn:      #f59e0b;
  --warn-dim:  rgba(245,158,11,0.15);
  --bad:       #ef4444;
  --bad-dim:   rgba(239,68,68,0.15);
  --purple:    #8b5cf6;
  --purple-dim:rgba(139,92,246,0.15);
  --pink:      #ec4899;
  --r:         12px;
  --r2:        8px;
  --shadow:    0 8px 32px rgba(0,0,0,0.5);
  --shadow2:   0 2px 8px rgba(0,0,0,0.3);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial;
  --mono: ui-monospace, 'SF Mono', 'Fira Code', Menlo, Consolas, monospace;
  --nav-w: 240px;
  --top-h: 56px;
  /* Sidebar-specific tokens (dark sidebar stays dark even in light mode) */
  --sb-text:       rgba(233,240,255,0.60);
  --sb-text-hi:    #e9f0ff;
  --sb-label:      rgba(233,240,255,0.28);
  --sb-hover:      rgba(255,255,255,0.06);
  --sb-active-bg:  rgba(30,92,255,0.25);
  /* Shared select tokens */
  --sel-bg:        #0d1535;
  --sel-bg-hover:  #111a3d;
  --sel-text:      rgba(233,240,255,0.75);
  --sel-text-hi:   #e9f0ff;
  --sel-border:    rgba(255,255,255,0.10);
  --sel-divider:   rgba(255,255,255,0.05);
}

[data-theme="light"] {
  --bg:        #ffffff;
  --bg2:       #f7f9fc;
  --bg3:       #ffffff;
  --sidebar:   #ffffff;
  --card:      #ffffff;
  --card2:     #f7f9fc;
  --line:      rgba(0,0,0,0.10);
  --line2:     rgba(0,0,0,0.06);
  --text:      #0a0f1e;
  --text2:     #374151;
  --text3:     #6b7280;
  --text-dim:  #6b7280;
  --blue:      #1e5cff;
  --blue2:     #0ea5ff;
  --blue-dim:  rgba(30,92,255,0.08);
  --blue-glow: 0 0 0 3px rgba(30,92,255,0.15);
  --good:      #059669;
  --good-dim:  rgba(5,150,105,0.10);
  --warn:      #d97706;
  --warn-dim:  rgba(217,119,6,0.10);
  --bad:       #dc2626;
  --bad-dim:   rgba(220,38,38,0.10);
  --purple:    #7c3aed;
  --purple-dim:rgba(124,58,237,0.10);
  --pink:      #db2777;
  --shadow:    0 4px 24px rgba(0,0,0,0.08);
  --shadow2:   0 1px 4px rgba(0,0,0,0.05);
  /* Sidebar light mode — dark text on white background */
  --sb-text:       #374151;
  --sb-text-hi:    #0a0f1e;
  --sb-label:      #9ca3af;
  --sb-hover:      rgba(0,0,0,0.05);
  --sb-active-bg:  rgba(30,92,255,0.08);
  /* Select tokens for light mode */
  --sel-bg:        #ffffff;
  --sel-bg-hover:  #f0f4ff;
  --sel-text:      #374151;
  --sel-text-hi:   #0a0f1e;
  --sel-border:    rgba(0,0,0,0.12);
  --sel-divider:   rgba(0,0,0,0.06);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
img { display: block; }

/* ── App Shell ───────────────────────────────────────────── */
.crm-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.crm-sidebar {
  width: var(--nav-w);
  min-width: var(--nav-w);
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.sidebar-logo .logo-dot {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.sidebar-logo .logo-text { line-height: 1.2; }
.sidebar-logo .logo-text strong {
  display: block; font-size: 13px; font-weight: 700;
  color: var(--sb-text-hi); letter-spacing: .2px;
}
.sidebar-logo .logo-text span {
  display: block; font-size: 10px; color: var(--sb-label);
  text-transform: uppercase; letter-spacing: .8px;
}

.sidebar-section { padding: 8px 10px 4px; }
.sidebar-section-label {
  font-size: 10px; font-weight: 600; color: var(--sb-label);
  text-transform: uppercase; letter-spacing: .8px;
  padding: 4px 8px 6px;
}

.sidebar-nav { padding: 6px 10px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--r2);
  color: var(--sb-text);
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left;
  transition: color .15s, background .15s;
  position: relative;
}
.nav-link:hover { color: var(--sb-text-hi); background: var(--sb-hover); }
.nav-link.active {
  color: var(--sb-text-hi);
  background: var(--sb-active-bg);
}
.nav-link.active::before {
  content: '';
  position: absolute; left: 0; top: 4px; bottom: 4px;
  width: 3px; border-radius: 0 2px 2px 0;
  background: var(--blue2);
}
.nav-link .nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-link .nav-badge {
  margin-left: auto;
  background: var(--bad);
  color: #fff;
  font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 99px;
}
.nav-link .nav-badge.blue { background: var(--blue); }
.nav-link .nav-badge.warn { background: var(--warn); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: var(--r2);
  cursor: pointer;
  transition: background .15s;
}
.sidebar-user:hover { background: var(--sb-hover); }
.sidebar-user .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name {
  font-size: 12px; font-weight: 600; color: var(--sb-text-hi);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user .user-role { font-size: 10px; color: var(--sb-label); }
.sidebar-user .user-chevron { font-size: 10px; color: var(--sb-label); }

/* ── Main area ───────────────────────────────────────────── */
.crm-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* ── Topbar ──────────────────────────────────────────────── */
.crm-topbar {
  height: var(--top-h); min-height: var(--top-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  backdrop-filter: blur(12px);
  z-index: 50;
}
.topbar-back-btn {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--text);
  text-decoration: none; flex-shrink: 0;
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 13px;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
  letter-spacing: .01em;
}
.topbar-back-btn:hover { color: var(--blue2); border-color: rgba(30,92,255,.5); background: var(--blue-dim); }

.topbar-title { font-size: 16px; font-weight: 700; flex: 1; }
.topbar-title span { color: var(--text3); font-weight: 400; font-size: 13px; }

.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 99px; padding: 7px 14px;
  width: 260px; max-width: 100%;
}
.topbar-search input {
  background: none; border: none; outline: none;
  color: var(--text); font-size: 13px; width: 100%;
}
.topbar-search input::placeholder { color: var(--text3); }
.topbar-search .search-icon { color: var(--text3); font-size: 14px; flex-shrink: 0; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; cursor: pointer;
  transition: border-color .15s, color .15s;
  position: relative;
}
.topbar-btn:hover { border-color: var(--blue); color: var(--blue2); }
.topbar-btn .notif-dot {
  position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--bad); border: 1px solid var(--bg);
}

/* ── Content area ────────────────────────────────────────── */
.crm-content {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 20px;
  background: var(--bg);
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header-left h1 { font-size: 22px; font-weight: 700; }
.page-header-left p { color: var(--text2); font-size: 13px; margin-top: 3px; }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Stats grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
  position: relative; overflow: hidden;
  transition: border-color .2s, transform .2s;
}
.stat-card:hover { border-color: rgba(30,92,255,.3); transform: translateY(-1px); }
.stat-card::before {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--stat-color, var(--blue));
  border-radius: var(--r) var(--r) 0 0;
}
.stat-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--stat-dim, var(--blue-dim));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; margin-bottom: 10px;
}
.stat-value { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }
.stat-change {
  font-size: 11px; margin-top: 6px;
  display: flex; align-items: center; gap: 4px;
}
.stat-change.up { color: var(--good); }
.stat-change.down { color: var(--bad); }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line2);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-header h2 { font-size: 14px; font-weight: 600; }
.card-header .card-actions { display: flex; align-items: center; gap: 8px; }
.card-body { padding: 16px 18px; }

/* ── Grid layouts ────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-3-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-3-1 { grid-template-columns: 1fr; }
}

/* ── Table ───────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
.tbl {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.tbl th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600;
  color: var(--text3); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.tbl th:hover { color: var(--text); }
.tbl td {
  padding: 11px 14px; border-bottom: 1px solid var(--line2);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--blue-dim); }
.tbl .tbl-link { color: var(--blue2); font-weight: 600; cursor: pointer; }
.tbl .tbl-link:hover { text-decoration: underline; }
.tbl .tbl-muted { color: var(--text3); font-size: 12px; }
.tbl .tbl-actions { display: flex; gap: 6px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-blue   { background: var(--blue-dim);   color: var(--blue2);  border: 1px solid rgba(30,92,255,.2); }
.badge-green  { background: var(--good-dim);   color: var(--good);   border: 1px solid rgba(16,185,129,.2); }
.badge-yellow { background: var(--warn-dim);   color: var(--warn);   border: 1px solid rgba(245,158,11,.2); }
.badge-red    { background: var(--bad-dim);    color: var(--bad);    border: 1px solid rgba(239,68,68,.2); }
.badge-purple { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(139,92,246,.2); }
.badge-pink   { background: rgba(236,72,153,.12); color: var(--pink); border: 1px solid rgba(236,72,153,.2); }
.badge-grey   { background: rgba(148,163,184,.1); color: var(--text3); border: 1px solid var(--line); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 99px;
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card2); color: var(--text);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: rgba(30,92,255,.4); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--blue), rgba(14,165,255,.8));
  border-color: rgba(30,92,255,.5); color: #fff;
}
.btn-primary:hover { box-shadow: 0 4px 20px rgba(30,92,255,.4); }

.btn-ghost {
  background: transparent; border-color: transparent;
  color: var(--text2); padding: 8px 12px;
}
.btn-ghost:hover { background: var(--blue-dim); color: var(--blue2); border-color: transparent; transform: none; }

.btn-danger {
  background: var(--bad-dim); border-color: rgba(239,68,68,.3); color: var(--bad);
}
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 14px;
}

/* ── Form controls ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text2); margin-bottom: 6px;
}
.form-control {
  width: 100%; padding: 9px 12px;
  background: var(--card2); border: 1px solid var(--line);
  border-radius: var(--r2); color: var(--text);
  font-size: 13px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  border-color: var(--blue); box-shadow: var(--blue-glow);
}
.form-control::placeholder { color: var(--text3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(6px);
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  width: 100%; max-width: 560px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  animation: slideUp .2s ease;
}
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 960px; }
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 10px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 20px; text-align: center;
  color: var(--text3);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 14px; opacity: .4; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 320px; }

/* ── Search & filter bar ─────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.search-input-wrap {
  position: relative; flex: 1; min-width: 200px;
}
.search-input-wrap .search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text3); font-size: 14px; pointer-events: none;
}
.search-input {
  width: 100%; padding: 8px 12px 8px 34px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 99px; color: var(--text);
  font-size: 13px; outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--blue); }
.search-input::placeholder { color: var(--text3); }

.filter-select {
  padding: 7px 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 99px; color: var(--text);
  font-size: 12px; outline: none; cursor: pointer;
}

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-md { width: 32px; height: 32px; font-size: 13px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

/* ── Toast ───────────────────────────────────────────────── */
#toastwrap {
  position: fixed; right: 16px; bottom: 16px;
  z-index: 9999; display: flex; flex-direction: column;
  gap: 8px; max-width: 360px;
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex; gap: 10px; align-items: flex-start;
  animation: slideUp .2s ease;
  font-size: 13px;
}
.toast-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.toast-dot.ok   { background: var(--good); }
.toast-dot.warn { background: var(--warn); }
.toast-dot.bad  { background: var(--bad); }
.toast-dot.info { background: var(--blue2); }
.toast b { display: block; font-size: 13px; }
.toast p { color: var(--text2); font-size: 12px; margin-top: 2px; }

/* ── Timeline ────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: ''; position: absolute;
  left: 9px; top: 8px; bottom: 0;
  width: 1px; background: var(--line);
}
.timeline-item { position: relative; margin-bottom: 18px; }
.timeline-dot {
  position: absolute; left: -23px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--blue); border: 2px solid var(--bg);
  flex-shrink: 0;
}
.timeline-dot.green  { background: var(--good); }
.timeline-dot.yellow { background: var(--warn); }
.timeline-dot.red    { background: var(--bad); }
.timeline-dot.purple { background: var(--purple); }
.timeline-dot.grey   { background: var(--text3); }
.timeline-header {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px;
}
.timeline-title { font-size: 13px; font-weight: 600; }
.timeline-time  { font-size: 11px; color: var(--text3); }
.timeline-body  { font-size: 12px; color: var(--text2); }

/* ── Pipeline / Kanban ───────────────────────────────────── */
.kanban-board {
  display: flex; gap: 14px;
  overflow-x: auto; padding-bottom: 16px;
  align-items: flex-start;
  min-height: calc(100vh - 160px);
}
.kanban-col {
  flex-shrink: 0; width: 270px;
  background: var(--card2); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden;
}
.kanban-col-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.kanban-col-header .col-title { font-size: 13px; font-weight: 700; }
.kanban-col-header .col-count {
  font-size: 11px; font-weight: 600; padding: 2px 7px;
  background: var(--blue-dim); color: var(--blue2);
  border-radius: 99px;
}
.kanban-col-body {
  padding: 10px; min-height: 120px;
  display: flex; flex-direction: column; gap: 8px;
}
.kanban-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r2); padding: 12px;
  cursor: grab; transition: all .15s;
}
.kanban-card:hover { border-color: rgba(30,92,255,.35); transform: translateY(-2px); box-shadow: var(--shadow2); }
.kanban-card.dragging { opacity: .4; cursor: grabbing; }
.kanban-card .kcard-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.kanban-card .kcard-company { font-size: 11px; color: var(--text2); margin-bottom: 8px; }
.kanban-card .kcard-footer { display: flex; align-items: center; justify-content: space-between; }
.kanban-card .kcard-value { font-size: 13px; font-weight: 700; color: var(--good); }
.kanban-card .kcard-date { font-size: 11px; color: var(--text3); }
.kanban-drop-zone {
  min-height: 60px; border: 2px dashed transparent;
  border-radius: var(--r2); transition: border-color .15s;
}
.kanban-drop-zone.over { border-color: var(--blue); background: var(--blue-dim); }

/* ── Calendar ────────────────────────────────────────────── */
.cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
}
.cal-day-label {
  padding: 8px; text-align: center;
  font-size: 11px; font-weight: 600; color: var(--text3);
  background: var(--card2); text-transform: uppercase;
}
.cal-day {
  background: var(--card);
  padding: 8px; min-height: 90px;
  position: relative; cursor: pointer;
  transition: background .12s;
}
.cal-day:hover { background: var(--blue-dim); }
.cal-day.other-month { opacity: .35; }
.cal-day.today { background: var(--blue-dim); }
.cal-day.today .cal-date { color: var(--blue2); font-weight: 700; }
.cal-date { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.cal-events { display: flex; flex-direction: column; gap: 2px; }
.cal-event {
  font-size: 10px; padding: 2px 5px; border-radius: 3px;
  background: var(--blue-dim); color: var(--blue2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.cal-event.green  { background: var(--good-dim); color: var(--good); }
.cal-event.yellow { background: var(--warn-dim); color: var(--warn); }
.cal-event.red    { background: var(--bad-dim); color: var(--bad); }

/* ── Loading ─────────────────────────────────────────────── */
.loading-spinner {
  display: flex; align-items: center; justify-content: center;
  padding: 48px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress bar ────────────────────────────────────────── */
.progress-bar {
  height: 4px; background: var(--line); border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--blue), var(--blue2));
  transition: width .4s ease;
}
.progress-fill.green { background: var(--good); }
.progress-fill.warn  { background: var(--warn); }
.progress-fill.red   { background: var(--bad); }

/* ── Tags ────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11px; background: var(--blue-dim);
  color: var(--blue2); border: 1px solid rgba(30,92,255,.15);
}
.tag .tag-remove { cursor: pointer; opacity: .6; }
.tag .tag-remove:hover { opacity: 1; }

/* ── Dropdown ────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 200;
  min-width: 160px;
  background: var(--bg3); border: 1px solid var(--line);
  border-radius: var(--r2); box-shadow: var(--shadow);
  overflow: hidden; display: none;
}
.dropdown-menu.open { display: block; animation: slideUp .12s ease; }
.dropdown-item {
  padding: 9px 14px; font-size: 13px; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  color: var(--text); transition: background .12s;
}
.dropdown-item:hover { background: var(--blue-dim); }
.dropdown-item.danger { color: var(--bad); }
.dropdown-item.danger:hover { background: var(--bad-dim); }
.dropdown-divider { height: 1px; background: var(--line); margin: 4px 0; }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs-bar {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.tab {
  padding: 9px 16px; font-size: 13px; font-weight: 500;
  color: var(--text2); cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue2); border-bottom-color: var(--blue2); }

/* ── Section divider ─────────────────────────────────────── */
.section-divider {
  height: 1px; background: var(--line); margin: 20px 0;
}
.section-title {
  font-size: 12px; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: .6px;
  margin-bottom: 12px;
}

/* ── Charts ──────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 220px; }
.chart-wrap canvas { border-radius: var(--r2); }

/* ── Mobile ──────────────────────────────────────────────── */
.mobile-only { display: none; }
.hamburger {
  display: none; background: none; border: none;
  color: var(--text); font-size: 20px; cursor: pointer; padding: 4px;
}

@media (max-width: 768px) {
  .hamburger { display: flex; align-items: center; }
  .mobile-only { display: block; }
  .crm-sidebar {
    position: fixed; inset: 0 auto 0 0;
    transform: translateX(-100%);
    box-shadow: 8px 0 32px rgba(0,0,0,.4);
    z-index: 300;
  }
  .crm-sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 299;
    background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  }
  .sidebar-overlay.open { display: block; }
  .topbar-search { display: none; }
  .crm-content { padding: 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* Kanban — horizontal scroll on mobile (keeps columns usable) */
  .kanban-board { flex-direction: row; }
  .kanban-col { width: 84vw; flex-shrink: 0; }

  /* Modals → bottom sheet */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal, .modal-lg, .modal-xl {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    animation: slideUpSheet .25s ease;
  }

  /* Tabs — horizontal scroll */
  .tabs-bar {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    gap: 0; padding-bottom: 0;
    scrollbar-width: none;
  }
  .tabs-bar::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; font-size: 12px; padding: 8px 12px; }

  /* Filter bar — search full width */
  .filter-bar { flex-wrap: wrap; }
  .search-input-wrap { min-width: 100%; }

  /* Detail grid (used in company-detail.html) */
  .detail-grid { grid-template-columns: 1fr !important; gap: 12px !important; }

  /* Page header */
  .page-header-left h1 { font-size: 18px; }
  .page-header-actions { gap: 6px; }
  .page-header-actions .btn { padding: 7px 12px; font-size: 12px; }

  /* Card padding */
  .card-body { padding: 12px; }
  .card-header { padding: 11px 14px; }

  /* Calendar — horizontal scroll */
  .cal-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-grid { min-width: 520px; }
  .cal-day { min-height: 64px; padding: 4px; }
  .cal-day-label { padding: 6px 2px; font-size: 10px; letter-spacing: 0; }
  .cal-date { font-size: 11px; }

  /* Toast — full-width at bottom */
  #toastwrap { left: 10px; right: 10px; max-width: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal, .modal-lg, .modal-xl { max-height: 96vh; }
}

@keyframes slideUpSheet {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Tier gate overlay ───────────────────────────────────── */
.tier-gate {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px; text-align: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r);
}
.tier-gate-icon { font-size: 48px; margin-bottom: 16px; }
.tier-gate h2 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.tier-gate p { color: var(--text2); max-width: 360px; font-size: 14px; line-height: 1.6; }
.tier-gate .upgrade-btn { margin-top: 20px; }

/* ── Utility classes ─────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text2); }
.text-dim { color: var(--text3); }
.text-good  { color: var(--good); }
.text-warn  { color: var(--warn); }
.text-bad   { color: var(--bad); }
.text-blue  { color: var(--blue2); }
.font-bold  { font-weight: 700; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ── Custom select dropdown ─────────────────────────────────── */
.custom-select {
  position: relative;
  user-select: none;
}
.custom-select-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--sel-bg);
  border: 1px solid var(--sel-border);
  border-radius: 8px;
  color: var(--sel-text-hi);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  min-width: 140px;
  justify-content: space-between;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.custom-select-btn:hover {
  border-color: rgba(30,92,255,0.5);
  background: var(--sel-bg-hover);
}
.custom-select-btn.active {
  border-color: var(--blue);
  background: var(--sel-bg-hover);
  box-shadow: var(--blue-glow);
}
.custom-select-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.2s ease, opacity 0.15s;
}
.custom-select-btn.active .custom-select-chevron {
  transform: rotate(180deg);
  opacity: 1;
}
.custom-select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  z-index: 9999;
  background: var(--sel-bg);
  border: 1px solid rgba(30,92,255,0.3);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.custom-select-menu.open {
  display: block;
  animation: dropIn 0.18s cubic-bezier(0.4,0,0.2,1) forwards;
}
.custom-select-menu.closing {
  display: block;
  animation: dropOut 0.14s cubic-bezier(0.4,0,0.2,1) forwards;
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
@keyframes dropOut {
  from { opacity: 1; transform: translateY(0)   scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.96); }
}
.custom-select-option {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--sel-text);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.custom-select-option + .custom-select-option {
  border-top: 1px solid var(--sel-divider);
}
.custom-select-option:hover {
  background: var(--sel-bg-hover);
  color: var(--sel-text-hi);
}
.custom-select-option.selected {
  color: #1e5cff;
  font-weight: 600;
  background: rgba(30,92,255,0.1);
}
.custom-select-option.selected::after {
  content: '✓';
  margin-left: auto;
  font-size: 12px;
}

/* ── Searchable combobox ─────────────────────────────────── */
.combo-dropdown {
  font-family: inherit;
  scrollbar-width: thin;
  scrollbar-color: var(--line1) transparent;
}
.combo-option { transition: background .1s; }
.combo-option.combo-active { background: var(--card2) !important; }
