/* ===========================
   THE COLLECTIF CRM — Styles
   =========================== */

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

:root {
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --blue-mid: #dbeafe;
  --violet: #7c3aed;
  --violet-light: #f5f3ff;
  --green: #059669;
  --green-light: #ecfdf5;
  --amber: #d97706;
  --amber-light: #fffbeb;
  --red: #dc2626;
  --red-light: #fef2f2;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --sidebar-w: 240px;
  --header-h: 60px;
  --banner-h: 40px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);
}

html, body { height: 100%; overflow: hidden; }
body { font-family: 'Inter', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ======== DEMO BANNER ======== */
.demo-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 999;
  height: var(--banner-h);
  background: linear-gradient(90deg, #0f172a 0%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center; gap: 20px;
  font-size: 13px; color: #e2e8f0; font-weight: 500;
}
.demo-back {
  color: #93c5fd; text-decoration: none; font-weight: 600;
  padding: 4px 12px; border: 1px solid rgba(147,197,253,.3); border-radius: 20px;
  transition: all .2s;
}
.demo-back:hover { background: rgba(147,197,253,.15); }

/* ======== APP SHELL ======== */
.app-shell {
  display: flex;
  height: calc(100vh - var(--banner-h));
  margin-top: var(--banner-h);
  overflow: hidden;
}

/* ======== SIDEBAR ======== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}
.logo-mark {
  width: 36px; height: 36px;
  background: var(--blue); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white; flex-shrink: 0;
}
.logo-mark svg { width: 18px; height: 18px; }
.logo-text strong { display: block; font-size: 15px; font-weight: 700; color: var(--text); }
.logo-text span { font-size: 11px; color: var(--text-3); }

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 2px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; color: var(--text-2);
  background: none; border: none; cursor: pointer;
  text-align: left; width: 100%;
  transition: all .15s;
  position: relative;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--blue-light); color: var(--blue); font-weight: 600; }
.nav-item.active svg { stroke: var(--blue); }

.badge-count {
  margin-left: auto;
  background: var(--blue); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}

.nav-divider {
  height: 1px; background: var(--border);
  margin: 8px 2px;
}

.sidebar-user {
  padding: 14px 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--blue); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-info strong { display: block; font-size: 13px; font-weight: 600; }
.user-info span { font-size: 11px; color: var(--text-3); }
.user-more { margin-left: auto; background: none; border: none; cursor: pointer; color: var(--text-3); padding: 4px; border-radius: 6px; }
.user-more:hover { background: var(--bg); }

/* ======== MAIN CONTENT ======== */
.main-content {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ======== APP HEADER ======== */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  flex-shrink: 0;
}

.hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: 6px; border-radius: 8px;
}
.hamburger:hover { background: var(--bg); }
.hamburger svg { width: 20px; height: 20px; }

.header-search {
  flex: 1; max-width: 420px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px;
}
.header-search svg { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.header-search input {
  flex: 1; background: none; border: none; outline: none;
  font-size: 13.5px; color: var(--text);
}
.header-search input::placeholder { color: var(--text-3); }
.header-search kbd {
  font-size: 11px; color: var(--text-3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px; font-family: inherit;
}

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.header-btn {
  position: relative;
  width: 36px; height: 36px;
  background: none; border: none; cursor: pointer;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}
.header-btn:hover { background: var(--bg); }
.header-btn svg { width: 18px; height: 18px; }
.notif-dot {
  position: absolute; top: 7px; right: 7px;
  width: 8px; height: 8px; background: var(--red);
  border-radius: 50%; border: 2px solid var(--surface);
}
.header-avatar {
  width: 32px; height: 32px;
  background: var(--blue); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  cursor: pointer;
}

/* ======== VIEW CONTAINER ======== */
.view-container {
  flex: 1; overflow-y: auto;
  padding: 28px 32px;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px; gap: 16px;
}
.view-header h1 { font-size: 24px; font-weight: 700; color: var(--text); }
.view-sub { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.view-actions { display: flex; gap: 10px; flex-shrink: 0; align-items: center; }

/* Buttons */
.btn-primary {
  background: var(--blue); color: #fff;
  border: none; border-radius: 8px; cursor: pointer;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600;
  font-family: inherit; transition: background .15s; white-space: nowrap;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  padding: 8px 14px; font-size: 13.5px; font-weight: 500;
  font-family: inherit; display: flex; align-items: center; gap: 6px;
  transition: all .15s; white-space: nowrap;
}
.btn-secondary:hover { border-color: var(--border-hover); background: var(--bg); }
.btn-ghost-sm {
  background: none; border: none; cursor: pointer;
  color: var(--blue); font-size: 13px; font-weight: 600;
  font-family: inherit; padding: 4px 8px; border-radius: 6px;
}
.btn-ghost-sm:hover { background: var(--blue-light); }

/* ======== KPI CARDS ======== */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: flex-start; gap: 16px;
  box-shadow: var(--shadow);
}
.kpi-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 20px; height: 20px; }
.kpi-blue { background: var(--blue-light); color: var(--blue); }
.kpi-violet { background: var(--violet-light); color: var(--violet); }
.kpi-green { background: var(--green-light); color: var(--green); }
.kpi-amber { background: var(--amber-light); color: var(--amber); }
.kpi-data { display: flex; flex-direction: column; gap: 3px; }
.kpi-label { font-size: 12px; color: var(--text-3); font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 800; color: var(--text); letter-spacing: -.5px; }
.kpi-delta { font-size: 12px; font-weight: 500; }
.kpi-delta.positive { color: var(--green); }
.kpi-delta.negative { color: var(--red); }

/* ======== DASHBOARD GRID ======== */
.dashboard-grid {
  display: grid; grid-template-columns: 1fr 380px;
  gap: 20px; margin-bottom: 20px;
}

/* CHART */
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow);
}
.chart-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px;
}
.chart-header h3 { font-size: 15px; font-weight: 700; }
.chart-sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.chart-legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.legend-dot.blue { background: var(--blue); }

.chart-body {
  width: 100%;
  aspect-ratio: 16/6;
  overflow: hidden;
}
.line-chart { width: 100%; height: 100%; }

.chart-months {
  display: flex; justify-content: space-between;
  padding-top: 12px;
  font-size: 11.5px; color: var(--text-3); font-weight: 500;
}
.chart-values {
  display: flex; justify-content: space-between;
  padding-top: 4px;
  font-size: 12px; color: var(--blue); font-weight: 600;
}

/* ACTIVITIES */
.activity-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.activity-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.activity-header h3 { font-size: 15px; font-weight: 700; }
.activity-list { list-style: none; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.activity-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 8px; border-radius: 8px;
  transition: background .12s;
}
.activity-item:hover { background: var(--bg); }

.act-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.act-icon svg { width: 15px; height: 15px; }
.act-deal { background: var(--blue-light); color: var(--blue); }
.act-contact { background: var(--violet-light); color: var(--violet); }
.act-invoice { background: var(--amber-light); color: var(--amber); }
.act-note { background: var(--green-light); color: var(--green); }

.act-content { flex: 1; min-width: 0; }
.act-content strong { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-content span { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.act-time { font-size: 11px; color: var(--text-3); white-space: nowrap; flex-shrink: 0; margin-top: 2px; }

/* QUICK STATS */
.quick-stats {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 28px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.qs-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.qs-label { font-size: 12px; color: var(--text-3); }
.qs-value { font-size: 18px; font-weight: 800; color: var(--text); }
.qs-sep { width: 1px; height: 36px; background: var(--border); }

/* ======== PIPELINE / KANBAN ======== */
.kanban {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; align-items: start;
}
.kanban-col {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.kanban-col-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.col-title { display: flex; align-items: center; gap: 8px; }
.col-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-grey { background: #94a3b8; }
.dot-blue { background: var(--blue); }
.dot-amber { background: var(--amber); }
.dot-green { background: var(--green); }
.col-title strong { font-size: 13.5px; font-weight: 700; }
.col-count {
  background: var(--border); color: var(--text-2);
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px;
}
.col-total { font-size: 12px; font-weight: 700; color: var(--text-2); }

.kanban-cards { display: flex; flex-direction: column; gap: 10px; }

.deal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer; transition: all .15s;
}
.deal-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-hover); transform: translateY(-1px); }
.deal-card.deal-won { border-left: 3px solid var(--green); }
.col-signed { border-top: 2px solid var(--green); }

.deal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.deal-company { font-size: 12px; font-weight: 600; color: var(--text-2); }
.deal-tag {
  font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}
.tag-high { background: #fef2f2; color: var(--red); }
.tag-med { background: var(--amber-light); color: var(--amber); }
.tag-low { background: #f1f5f9; color: var(--text-3); }
.tag-won { background: var(--green-light); color: var(--green); }

.deal-title { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 10px; line-height: 1.3; }
.deal-footer { display: flex; justify-content: space-between; align-items: center; }
.deal-amount { font-size: 15px; font-weight: 800; color: var(--text); }
.avatar-xs {
  width: 24px; height: 24px;
  background: var(--blue); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #fff;
}
.deal-date { font-size: 11px; color: var(--text-3); margin-top: 8px; }

/* ======== CONTACTS TABLE ======== */
.table-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.contacts-table {
  width: 100%; border-collapse: collapse;
}
.contacts-table thead tr {
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.contacts-table th {
  padding: 12px 16px; text-align: left;
  font-size: 11.5px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap;
}
.contacts-table td {
  padding: 13px 16px; border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px; vertical-align: middle;
}
.contacts-table tbody tr:hover { background: #fafbfd; }
.contacts-table tbody tr:last-child td { border-bottom: none; }

.contact-cell { display: flex; align-items: center; gap: 10px; }
.contact-av {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.contact-cell strong { display: block; font-size: 13.5px; font-weight: 600; }
.contact-cell span { font-size: 12px; color: var(--text-3); }
.val-cell { font-weight: 700; color: var(--text); }
.date-cell { color: var(--text-2); }

.status {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
}
.status-hot { background: #fef2f2; color: var(--red); }
.status-prospect { background: #f1f5f9; color: #475569; }
.status-nego { background: var(--amber-light); color: var(--amber); }
.status-client { background: var(--green-light); color: var(--green); }
.status-quote { background: var(--blue-mid); color: var(--blue); }

.cb { accent-color: var(--blue); width: 15px; height: 15px; cursor: pointer; }
.row-btn { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.row-btn:hover { background: var(--bg); color: var(--text); }

/* ======== PLACEHOLDER VIEWS ======== */
.inv-placeholder, .cal-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 80px 40px;
  text-align: center; box-shadow: var(--shadow);
}
.inv-placeholder h3, .cal-placeholder h3 { font-size: 18px; font-weight: 700; }
.inv-placeholder p, .cal-placeholder p { font-size: 14px; color: var(--text-2); max-width: 400px; }

/* ======== SETTINGS ======== */
.settings-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
.settings-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px;
}
.settings-section h3 { font-size: 16px; font-weight: 700; }
.settings-field { display: flex; flex-direction: column; gap: 6px; }
.settings-field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.settings-field input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; outline: none;
  transition: border .15s;
}
.settings-field input:focus { border-color: var(--blue); }

.settings-toggle { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.track {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 999px; transition: .2s;
}
.track::before {
  content: ''; position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: .2s;
}
.toggle input:checked + .track { background: var(--blue); }
.toggle input:checked + .track::before { transform: translateX(18px); }

/* ======== RESPONSIVE ======== */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .kanban { grid-template-columns: repeat(2, 1fr); }
  .view-container { padding: 20px 16px; }
  .quick-stats { flex-wrap: wrap; gap: 16px; }
  .qs-sep { display: none; }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: var(--banner-h); left: 0; bottom: 0; z-index: 100;
    transform: translateX(-100%); transition: transform .25s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: flex; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kanban { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .contacts-table th:nth-child(6),
  .contacts-table td:nth-child(6) { display: none; }
  .chart-values { display: none; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .view-header { flex-direction: column; }
  .view-container { padding: 16px 12px; }
  .demo-banner { font-size: 11px; gap: 10px; }
  .contacts-table th:nth-child(4),
  .contacts-table td:nth-child(4) { display: none; }
}
