:root {
  --crm-bg: #f4f7fb;
  --crm-surface: #ffffff;
  --crm-primary: #4f46e5;
  --crm-primary-soft: #e0e7ff;
  --crm-text: #0f172a;
  --crm-muted: #64748b;
  --crm-border: #e2e8f0;
  --crm-success: #16a34a;
  --crm-warning: #f59e0b;
  --crm-danger: #dc2626;
  --crm-shadow: 0 10px 30px rgba(15, 23, 42, .08);
  --crm-radius: 1rem;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--crm-bg);
  color: var(--crm-text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

.app-shell {
  min-height: 100vh;
  background: var(--crm-bg);
}

.sidebar {
  width: 270px;
  background: linear-gradient(180deg, #0b1220 0%, #121d35 100%);
  color: #fff;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  box-shadow: var(--crm-shadow);
  transition: all .25s ease;
  z-index: 1040;
  display: flex;
  flex-direction: column;
}

.sidebar .text-secondary {
  color: #94a3b8 !important;
}

.sidebar-brand {
  margin: 0;
  padding: 0;
  margin-top: -60px;
  margin-bottom: -60px ;
  margin-left: -60px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-brand img {
  height: 100%;
  width: auto;
  display: block;
  margin: 0;
  padding: 0;
}

.sidebar .nav-link {
  color: #cbd5e1;
  border-radius: .75rem;
  margin-bottom: .35rem;
  padding: .6rem .8rem;
  font-weight: 500;
  transition: all .2s ease;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background: rgba(99, 102, 241, .2);
  color: #fff;
  transform: translateX(2px);
}

.content-wrap {
  flex: 1;
  min-width: 0;
}

.topbar {
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid var(--crm-border);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 1050;
}

.notification-dropdown {
  min-width: 300px;
  max-height: 380px;
  overflow-y: auto;
  z-index: 1055;
}

.navbar-brand {
  font-weight: 700;
  color: var(--crm-text);
}

.card {
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  box-shadow: var(--crm-shadow);
}

.card .card-header {
  border-bottom: 1px solid var(--crm-border);
  background: transparent;
  font-weight: 600;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--crm-border);
}

.table thead th {
  color: var(--crm-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: .78rem;
  letter-spacing: .04em;
}

.table-hover > tbody > tr:hover > * {
  background-color: #f8fbff;
}

.form-control,
.form-select,
textarea {
  border-radius: .75rem;
  border-color: var(--crm-border);
}

.form-control:focus,
.form-select:focus,
textarea:focus {
  border-color: var(--crm-primary);
  box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .18);
}

.btn {
  border-radius: .75rem;
  font-weight: 600;
}

.btn-primary {
  background: var(--crm-primary);
  border-color: var(--crm-primary);
}

.btn-primary:hover {
  background: #4338ca;
  border-color: #4338ca;
}

.crm-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.crm-page-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.crm-page-subtitle {
  margin: 0;
  color: var(--crm-muted);
  font-size: .95rem;
}

.crm-stat-card {
  border: 1px solid var(--crm-border);
  border-radius: 1rem;
  background: var(--crm-surface);
  padding: 1rem;
  height: 100%;
}

.crm-stat-label {
  color: var(--crm-muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.crm-stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.crm-empty {
  border: 1px dashed #cbd5e1;
  border-radius: 1rem;
  background: #f8fafc;
  color: var(--crm-muted);
  padding: 1.25rem;
  text-align: center;
}

.crm-chart-wrap {
  position: relative;
  min-height: 280px;
}

.communication-timeline-card .card-header {
  background: #f8fafc;
}

.communication-timeline-filters .form-select,
.communication-timeline-filters .form-control {
  border-radius: .5rem;
}

.communication-timeline-list {
  position: relative;
  margin-top: .25rem;
}

.communication-timeline-item {
  position: relative;
  padding-left: 1.5rem;
  padding-bottom: 1rem;
  border-left: 2px solid var(--crm-border);
  margin-left: .5rem;
}

.communication-timeline-item:last-child {
  padding-bottom: 0;
}

.communication-timeline-item .timeline-dot {
  position: absolute;
  left: -7px;
  top: .4rem;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--crm-primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--crm-border);
}

.communication-timeline-item .timeline-content {
  background: #fff;
  border: 1px solid var(--crm-border);
  border-radius: .75rem;
  padding: .75rem;
}

.timeline-body {
  white-space: normal;
  word-break: break-word;
}

.timeline-channel-badge,
.timeline-status-badge {
  font-weight: 600;
}

.timeline-channel-badge[data-variant="email"] {
  background: #dbeafe;
  color: #1d4ed8;
}

.timeline-channel-badge[data-variant="whatsapp"] {
  background: #dcfce7;
  color: #15803d;
}

.timeline-channel-badge[data-variant="interaction"] {
  background: #f1f5f9;
  color: #334155;
}

.timeline-status-badge[data-variant="sent"] {
  background: #dcfce7;
  color: #166534;
}

.timeline-status-badge[data-variant="failed"] {
  background: #fee2e2;
  color: #991b1b;
}

.timeline-status-badge[data-variant="pending"] {
  background: #fef3c7;
  color: #92400e;
}

.timeline-status-badge[data-variant="logged"] {
  background: #e2e8f0;
  color: #334155;
}

.kanban-pipeline-total {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: #fff;
  border: 1px solid var(--crm-border);
  border-radius: .75rem;
  padding: .6rem .9rem;
  box-shadow: var(--crm-shadow);
}

.kanban-pipeline-total .label {
  color: var(--crm-muted);
  font-weight: 600;
}

.kanban-pipeline-total .value {
  font-weight: 800;
  color: var(--crm-primary);
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(240px, 1fr));
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: .5rem;
}

.kanban-column {
  background: #f8fafc;
  border: 1px solid var(--crm-border);
  border-radius: 1rem;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  transition: box-shadow .25s ease, transform .25s ease;
}

.kanban-column:hover {
  box-shadow: var(--crm-shadow);
  transform: translateY(-2px);
}

.kanban-column-header {
  padding: .75rem;
  border-bottom: 1px solid var(--crm-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
}

.kanban-column-header h6 {
  margin: 0;
  font-weight: 700;
}

.kanban-dropzone {
  padding: .75rem;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  transition: background-color .2s ease, border-color .2s ease;
}

.kanban-dropzone.drop-hover {
  background: #eef2ff;
  border: 1px dashed var(--crm-primary);
  border-radius: .75rem;
}

.kanban-card {
  border: 1px solid var(--crm-border);
  border-radius: .85rem;
  background: #fff;
  padding: .7rem .75rem;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .06);
  cursor: grab;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, .1);
}

.kanban-card.dragging {
  opacity: .6;
  transform: scale(.98);
}

.kanban-card-title {
  font-weight: 700;
  margin-bottom: .4rem;
}

.kanban-card-line {
  font-size: .84rem;
  color: var(--crm-muted);
  margin-bottom: .25rem;
}

.kanban-card-actions {
  margin-top: .45rem;
  display: flex;
  justify-content: flex-end;
}

.kanban-stage-prospecting .kanban-column-header { border-top: 3px solid #60a5fa; }
.kanban-stage-qualification .kanban-column-header { border-top: 3px solid #a78bfa; }
.kanban-stage-proposal .kanban-column-header { border-top: 3px solid #f59e0b; }
.kanban-stage-negotiation .kanban-column-header { border-top: 3px solid #fb7185; }
.kanban-stage-won .kanban-column-header { border-top: 3px solid #22c55e; }
.kanban-stage-lost .kanban-column-header { border-top: 3px solid #ef4444; }

.kanban-board--4col { grid-template-columns: repeat(4, minmax(240px, 1fr)); }
.kanban-status-pending .kanban-column-header    { border-top: 3px solid #60a5fa; }
.kanban-status-inprogress .kanban-column-header { border-top: 3px solid #f59e0b; }
.kanban-status-completed .kanban-column-header  { border-top: 3px solid #22c55e; }
.kanban-status-cancelled .kanban-column-header  { border-top: 3px solid #94a3b8; }
.kanban-status-todo .kanban-column-header       { border-top: 3px solid #60a5fa; }
.kanban-status-inreview .kanban-column-header   { border-top: 3px solid #a78bfa; }
.kanban-status-done .kanban-column-header       { border-top: 3px solid #22c55e; }

@media (max-width: 1200px) {
  .kanban-board {
    grid-template-columns: repeat(3, minmax(240px, 1fr));
  }
}

@media (max-width: 768px) {
  .kanban-board {
    grid-template-columns: repeat(1, minmax(250px, 1fr));
  }
}

@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    width: 260px;
  }

  .sidebar.show {
    left: 0;
  }

  .content-wrap {
    width: 100%;
  }
}

.codexa-list-page {
  background: #fff;
  border-radius: 16px;
  border: 1px solid #d9e7f5;
  box-shadow: 0 14px 34px rgba(10, 46, 94, 0.08);
  padding: 1.25rem;
}

.codexa-list-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.codexa-list-title {
  color: #0a3d82;
  margin: 0;
  font-weight: 800;
  letter-spacing: .02em;
}

.codexa-list-subtitle {
  margin: .35rem 0 0;
  color: #4e6279;
}

.codexa-list-card {
  background: #fff;
  border: 1px solid #dce8f5;
  border-radius: 14px;
  overflow: hidden;
}

.codexa-list-table thead th {
  background: #0a3d82;
  color: #fff;
  border-bottom: 0;
  font-size: .78rem;
}

.codexa-list-table tbody tr td {
  border-color: #e5edf6;
}

.codexa-status-badge {
  display: inline-flex;
  align-items: center;
  padding: .35rem .7rem;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  line-height: 1;
}

.codexa-status-success {
  background: #dcfce7;
  color: #166534;
}

.codexa-status-warning {
  background: #fef3c7;
  color: #92400e;
}

.codexa-status-danger {
  background: #fee2e2;
  color: #991b1b;
}

.codexa-status-secondary {
  background: #e2e8f0;
  color: #334155;
}

.codexa-btn-primary {
  background: #0a3d82;
  border-color: #0a3d82;
  color: #fff;
}

.codexa-btn-primary:hover {
  background: #082f63;
  border-color: #082f63;
  color: #fff;
}

.codexa-btn-outline-primary {
  border: 1px solid #0a3d82;
  color: #0a3d82;
  background: #fff;
}

.codexa-btn-outline-primary:hover {
  background: #0a3d82;
  color: #fff;
}

.codexa-btn-outline-warning {
  border: 1px solid #d97706;
  color: #b45309;
  background: #fff;
}

.codexa-btn-outline-warning:hover {
  background: #d97706;
  color: #fff;
}

.codexa-btn-outline-success {
  border: 1px solid #0891b2;
  color: #0e7490;
  background: #fff;
}

.codexa-btn-outline-success:hover {
  background: #0891b2;
  color: #fff;
}

.codexa-btn-outline-danger {
  border: 1px solid #dc2626;
  color: #b91c1c;
  background: #fff;
}

.codexa-btn-outline-danger:hover {
  background: #dc2626;
  color: #fff;
}

.codexa-document-page {
  display: grid;
  gap: 1rem;
}

.codexa-document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
}

.codexa-document-sheet {
  background: #fff;
  max-width: 960px;
  margin: 0 auto;
  border: 1px solid #d8e7f6;
  box-shadow: 0 18px 44px rgba(8, 35, 74, 0.1);
  border-radius: 12px;
  padding: 2rem 2rem 1.25rem;
}

.codexa-letterhead-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.6rem;
}

.codexa-letterhead-logo {
  width: 150px;
  max-width: 100%;
  height: auto;
}

.codexa-document-title-wrap {
  text-align: right;
  flex: 1;
}

.codexa-document-title {
  color: #0a3d82;
  margin: 0 0 .5rem;
  font-size: 1.7rem;
  letter-spacing: .14em;
  font-weight: 800;
}

.codexa-document-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(170px, 1fr));
  gap: .45rem .9rem;
  justify-items: end;
}

.codexa-document-meta div {
  display: flex;
  gap: .45rem;
  font-size: .9rem;
}

.codexa-document-meta span {
  color: #4e6279;
}

.codexa-party-section,
.codexa-items-section,
.codexa-totals-wrap,
.codexa-notes-section,
.codexa-payment-section {
  margin-bottom: 1.3rem;
}

.codexa-party-section h2,
.codexa-notes-section h2,
.codexa-payment-section h4 {
  color: #0a3d82;
  font-size: 1rem;
  margin-bottom: .7rem;
  font-weight: 700;
}

.codexa-party-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: .8rem;
  border: 1px solid #dce8f5;
  background: #fafdff;
  border-radius: 10px;
  padding: .8rem;
}

.codexa-party-name {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.codexa-link {
  color: #0891b2;
  font-weight: 600;
  text-decoration: none;
}

.codexa-link:hover {
  text-decoration: underline;
}

.codexa-doc-table thead th {
  background: #0a3d82;
  color: #fff;
  border-color: #0a3d82;
  font-weight: 700;
  text-transform: none;
  font-size: .86rem;
}

.codexa-doc-table td,
.codexa-doc-table th {
  border-color: #dce7f3;
}

.codexa-totals-wrap {
  display: flex;
  justify-content: flex-end;
}

.codexa-totals-card {
  width: 100%;
  max-width: 360px;
  border: 1px solid #d6e4f3;
  border-radius: 10px;
  background: #fafdff;
  padding: .8rem .95rem;
}

.codexa-totals-card > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: .25rem 0;
  gap: .5rem;
}

.codexa-grand-total {
  border-top: 1px solid #b7d2ee;
  padding-top: .45rem;
  margin-top: .35rem;
  color: #0a3d82;
  font-size: 1rem;
}

.codexa-notes-section p {
  margin: 0;
  border: 1px solid #dce8f5;
  border-radius: 10px;
  padding: .8rem;
  background: #fcfeff;
}

.codexa-payment-summary {
  border: 1px solid #d6e4f3;
  border-radius: 10px;
  padding: .8rem;
  background: #fafdff;
  margin-bottom: .9rem;
}

.codexa-letterhead-footer {
  margin-top: 1.5rem;
}

.codexa-footer-line {
  height: 4px;
  width: 100%;
  background: #0a3d82;
  border-radius: 999px;
  margin-bottom: .55rem;
}

.codexa-footer-contact {
  display: flex;
  flex-wrap: wrap;
  gap: .9rem 1.25rem;
  align-items: center;
  font-size: .88rem;
  color: #111827;
}

.codexa-footer-phone {
  color: #06b6d4;
  font-weight: 700;
}

@media (max-width: 768px) {
  .codexa-party-grid {
    grid-template-columns: 1fr;
  }

  .codexa-document-meta {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .codexa-document-title-wrap {
    text-align: left;
  }

  .codexa-letterhead-header {
    flex-direction: column;
  }
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  body {
    background: #fff !important;
  }

  .sidebar,
  .topbar,
  .no-print,
  .btn,
  .modal,
  .navbar,
  .app-shell > .d-flex > .sidebar,
  .crm-page-header {
    display: none !important;
    visibility: hidden !important;
  }

  .content-wrap,
  .container-fluid,
  main {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .codexa-document-page {
    display: block !important;
  }

  .codexa-document-sheet {
    border: 0 !important;
    box-shadow: none !important;
    margin: 0 auto !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    break-inside: avoid;
  }

  .codexa-doc-table,
  .codexa-doc-table thead,
  .codexa-doc-table tbody,
  .codexa-doc-table tr,
  .codexa-doc-table td,
  .codexa-doc-table th {
    page-break-inside: avoid !important;
  }

  .codexa-letterhead-footer {
    position: fixed;
    bottom: 10mm;
    left: 10mm;
    right: 10mm;
  }

  .codexa-payment-section .codexa-payment-summary {
    display: none !important;
  }

  .codexa-list-page {
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
}

/* ── Team Chat ──────────────────────────────────────────────────────────────── */
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--crm-primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-avatar-me {
  background: #6366f1;
}
.chat-bubble {
  padding: .45rem .75rem;
  border-radius: 1rem;
  font-size: .9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble-other {
  background: var(--crm-surface);
  border: 1px solid #e2e8f0;
  border-top-left-radius: 0;
}
.chat-bubble-me {
  background: var(--crm-primary);
  color: #fff;
  border-top-right-radius: 0;
}
.chat-bubble-me .text-primary {
  color: #c7d2fe !important;
}
