/* ── Global ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: #111827;
  background: #f9fafb;
  margin: 0;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #111827;
}
.brand-mark {
  background: #7c3aed;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 6px;
  border-radius: 4px;
}
.brand-mark--lg {
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 6px;
}
.brand-name {
  font-size: 15px;
  font-weight: 600;
  color: #111827;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-name {
  font-size: 12px;
  color: #6b7280;
}
.nav-link {
  font-size: 12px;
  color: #6b7280;
  text-decoration: none;
}
.nav-link:hover { color: #111827; }
.nav-link--logout { color: #9ca3af; }

/* ── Main content ────────────────────────────────────────────────────────── */
.app-main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px 40px;
}
.flash-messages { padding: 12px 0 0; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: calc(100vh - 48px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.login-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}
.login-logo { margin-bottom: 16px; }
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 8px;
}
.login-sub {
  color: #6b7280;
  font-size: 14px;
  margin: 0 0 28px;
  line-height: 1.5;
}
.login-btn {
  background: #7c3aed;
  border-color: #7c3aed;
  width: 100%;
  font-size: 15px;
  padding: 10px;
  border-radius: 8px;
}
.login-btn:hover { background: #6d28d9; border-color: #6d28d9; }
.login-hint {
  font-size: 11px;
  color: #9ca3af;
  margin: 16px 0 0;
  line-height: 1.6;
}

/* ── Board header / summary cards ────────────────────────────────────────── */
.board-header {
  padding: 16px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.board-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.summary-cards {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.summary-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 16px;
  min-width: 130px;
}
.summary-card__label {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.summary-card__value {
  font-size: 18px;
  font-weight: 700;
  color: #111827;
  line-height: 1.2;
}
.summary-card__sub {
  font-size: 11px;
  color: #6b7280;
  margin-top: 1px;
}

/* ── Filters bar ─────────────────────────────────────────────────────────── */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 12px;
  flex-wrap: wrap;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-label {
  font-size: 11px;
  color: #6b7280;
  font-weight: 500;
  white-space: nowrap;
}
.filter-select {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  cursor: pointer;
  appearance: auto;
}
.filter-select:focus { outline: 2px solid #7c3aed; outline-offset: 1px; }
.filter-search {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  width: 200px;
}
.filter-search:focus { outline: 2px solid #7c3aed; outline-offset: 1px; }

/* Forecast category chips */
.fcat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.fcat-chip {
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  background: #f9fafb;
  color: #6b7280;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.fcat-chip:hover { border-color: #9ca3af; color: #374151; }
.filter-clear-btn {
  font-size: 11px;
  color: #9ca3af;
  text-decoration: none;
  padding: 3px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  white-space: nowrap;
}
.filter-clear-btn:hover { color: #374151; border-color: #9ca3af; }
.fcat-chip--active {
  background: #ede9fe;
  border-color: #7c3aed;
  color: #5b21b6;
  font-weight: 600;
}

/* Loading overlay */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 9999;
  backdrop-filter: blur(2px);
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e5e7eb;
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.loading-text {
  font-size: 13px;
  color: #6b7280;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* View selector */
.view-selector {
  display: flex;
  align-items: center;
  gap: 6px;
}
.view-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 100px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.1s;
}
.view-btn:hover { border-color: #7c3aed; color: #7c3aed; }
.view-btn--active {
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
}
.view-btn--active:hover { background: #6d28d9; border-color: #6d28d9; color: #fff; }

/* ── Deal table ──────────────────────────────────────────────────────────── */
.deals-table-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  /*
   * overflow: auto makes the table its own scroll container (both axes).
   * Sticky headers use top: 0 and are sticky within THIS container — which
   * actually scrolls vertically — so they always work correctly.
   * max-height keeps the table from growing taller than the viewport.
   */
  overflow: auto;
  max-height: calc(100vh - 210px);
}
.deals-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  min-width: 900px;
}
.deals-table thead th {
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
  background: #f9fafb;
  position: sticky;
  top: 0; /* sticky within the table's own scroll container, not the viewport */
  z-index: 10;
}
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: #374151; }
.sort-indicator { font-size: 9px; opacity: 0.7; }
.deals-table tbody tr {
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  transition: background 0.1s;
}
.deals-table tbody tr:hover { background: #f5f3ff; }
.deals-table tbody tr:last-child { border-bottom: none; }
.deals-table td {
  padding: 8px 10px;
  vertical-align: middle;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Name column (always first, wider) */
.col-name { min-width: 200px; max-width: 280px; }
.deal-account { font-size: 11px; color: #6b7280; }
.deal-name { font-size: 13px; font-weight: 500; color: #111827; }

/* Close date */
.close-date--past { color: #dc2626; font-weight: 500; }

/* Contacts count */
.contact-count { text-align: center; }

/* Boolean (Rep Commit, etc.) */
.bool-true  { color: #16a34a; font-weight: 600; }
.bool-false { color: #9ca3af; }

/* Currency */
.currency { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Next step — truncated but wider */
.col-nextstep { max-width: 200px; }

/* Empty state */
.deals-empty {
  text-align: center;
  padding: 60px 20px;
  color: #9ca3af;
}
.deals-empty-title { font-size: 16px; font-weight: 500; margin-bottom: 6px; }

/* ── Activity timeline ───────────────────────────────────────────────────── */
/* SVG row: dots are circles centered on (or straddling) a horizontal line.   */
/* Size radii: 1.5 / 3 / 5.5 / 7.5 px (sizes 0–3).                          */
/* Colors: purple = outbound, pink = inbound, gray = meeting, light = empty.  */
.timeline-svg {
  display: block;
  overflow: visible;  /* large dots on edge slots can bleed slightly */
}
/* The td default (max-width: 220px; overflow: hidden) would clip the SVG.    */
.deals-table td[data-col="_timeline"] {
  max-width: none;
  overflow: visible;
  white-space: normal;
  padding: 6px 10px;
}

/* Timeline column header: label + ruler SVG stacked */
.col-timeline-header {
  vertical-align: bottom;
  padding-bottom: 4px;
}
.timeline-header-label {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.timeline-ruler-svg {
  display: block;
  overflow: visible;
}

/* ── Warning badges ──────────────────────────────────────────────────────── */
.warning-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #d97706;
  cursor: default;
  white-space: nowrap;
}
.warning-icon { font-size: 12px; }
.no-warning { color: #d1d5db; }

/* ── Side panel ──────────────────────────────────────────────────────────── */
.side-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
.side-panel-overlay.open {
  opacity: 1;
  visibility: visible;
}
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 90vw;
  background: #fff;
  border-left: 1px solid #e5e7eb;
  z-index: 201;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}
.side-panel.open { transform: translateX(0); }

.side-panel-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.side-panel-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  color: #9ca3af;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.side-panel-close:hover { color: #374151; }
.side-panel-deal-name {
  font-size: 15px;
  font-weight: 700;
  color: #111827;
  margin: 0 0 2px;
  padding-right: 28px;
}
.side-panel-account {
  font-size: 12px;
  color: #6b7280;
  margin: 0 0 6px;
}
.side-panel-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #374151;
}
.side-panel-meta span {
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 100px;
}
.sf-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #7c3aed;
  text-decoration: none;
  margin-top: 6px;
}
.sf-link:hover { text-decoration: underline; }

.side-panel-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.side-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.side-tab:hover { color: #374151; }
.side-tab.active { color: #7c3aed; border-bottom-color: #7c3aed; }

.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.side-tab-content { display: none; }
.side-tab-content.active { display: block; }

/* ── Chat-style activity thread ─────────────────────────────────────────── */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

/* Bubble wrapper — flex row; inbound left, outbound right */
.chat-bubble-wrap {
  display: flex;
  max-width: 100%;
}
.chat-bubble-wrap--inbound  { justify-content: flex-start; }
.chat-bubble-wrap--outbound { justify-content: flex-end; }

/* The bubble itself */
.chat-bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.5;
}
.chat-bubble--inbound {
  background: #ede9fe;
  border-bottom-left-radius: 3px;
}
.chat-bubble--outbound {
  background: #f3f4f6;
  border-bottom-right-radius: 3px;
}

.chat-bubble-subject {
  font-weight: 600;
  font-size: 12px;
  color: #111827;
  margin-bottom: 3px;
}
.chat-bubble-meta {
  font-size: 10px;
  color: #9ca3af;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-bubble-from { color: #7c3aed; font-weight: 500; }
.chat-bubble-to   { color: #6b7280; font-weight: 500; }
.chat-bubble-body {
  font-size: 12px;
  color: #374151;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 4px;
  line-height: 1.5;
  /* Default: truncated to 3 visual lines */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-bubble-body--expanded {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
}
.chat-bubble-expand {
  display: inline-block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 500;
  color: #7c3aed;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-bubble-expand:hover { color: #5b21b6; }

/* Full-width meeting/event card */
.chat-event {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 12px;
}
.chat-event-icon { font-size: 14px; flex-shrink: 0; line-height: 1.4; }
.chat-event-subject { font-weight: 600; color: #111827; }
.chat-event-meta { font-size: 10px; color: #9ca3af; margin-top: 2px; }

/* Contact list in side panel */
.contact-list { display: flex; flex-direction: column; gap: 10px; }
.contact-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.contact-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ede9fe;
  color: #7c3aed;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.contact-name { font-size: 13px; font-weight: 500; color: #111827; }
.contact-title { font-size: 11px; color: #6b7280; margin-top: 1px; }
.contact-role {
  font-size: 11px;
  color: #7c3aed;
  background: #ede9fe;
  padding: 1px 6px;
  border-radius: 100px;
  margin-top: 3px;
  display: inline-block;
}
.contact-primary { font-size: 10px; color: #16a34a; font-weight: 600; }

/* Details tab */
.detail-field { margin-bottom: 14px; }
.detail-field__label {
  font-size: 11px;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.detail-field__value {
  font-size: 13px;
  color: #111827;
  line-height: 1.5;
}
.detail-field__value--empty { color: #d1d5db; font-style: italic; }

/* Loading state */
.panel-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #9ca3af;
  font-size: 13px;
}

/* ── Settings page ───────────────────────────────────────────────────────── */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  padding: 20px 0;
}
.settings-sidebar { }
.settings-sidebar-title {
  font-size: 11px;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
  padding: 0 8px;
}
.view-list { list-style: none; padding: 0; margin: 0 0 12px; }
.view-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #374151;
  gap: 6px;
}
.view-list-item:hover { background: #f3f4f6; }
.view-list-item.active { background: #ede9fe; color: #7c3aed; font-weight: 500; }
.view-list-item__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-list-item__default { font-size: 10px; color: #9ca3af; }
.view-delete-btn {
  background: none;
  border: none;
  padding: 1px 4px;
  font-size: 14px;
  color: #d1d5db;
  cursor: pointer;
  line-height: 1;
}
.view-delete-btn:hover { color: #dc2626; }
.add-view-btn {
  width: 100%;
  background: #f9fafb;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
  text-align: left;
}
.add-view-btn:hover { border-color: #7c3aed; color: #7c3aed; background: #faf5ff; }

.settings-main {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
}
.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 4px;
}
.settings-section-sub {
  font-size: 12px;
  color: #6b7280;
  margin: 0 0 16px;
}
.settings-divider {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 20px 0;
}

/* Filter defaults in settings */
.filter-default-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.filter-default-label {
  font-size: 12px;
  color: #374151;
  font-weight: 500;
  width: 140px;
  flex-shrink: 0;
}
.fd-fcat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #374151;
  padding: 3px 8px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
}
.fd-fcat-chip:has(.fd-fcat-check:checked) {
  background: #ede9fe;
  border-color: #7c3aed;
  color: #5b21b6;
  font-weight: 600;
}
.fd-fcat-chip input[type="checkbox"] { display: none; }

/* Column editor */
.column-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.column-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 13px;
}
.column-item__handle {
  color: #d1d5db;
  cursor: ns-resize;
  user-select: none;
  font-size: 14px;
}
.column-item__name { flex: 1; font-weight: 500; }
.column-item__key { font-size: 11px; color: #9ca3af; font-family: monospace; }
.column-item__type {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 100px;
  font-weight: 500;
}
.column-item__type--computed { background: #dbeafe; color: #1d4ed8; }
.column-item__type--sf_field { background: #f3f4f6; color: #6b7280; }
.column-remove-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  font-size: 14px;
  color: #d1d5db;
  cursor: pointer;
}
.column-remove-btn:hover { color: #dc2626; }
.column-move-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  font-size: 12px;
  color: #9ca3af;
  cursor: pointer;
  line-height: 1;
}
.column-move-btn:hover { color: #374151; }

/* Field browser */
.field-browser-search {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 10px;
}
.field-browser-search:focus { outline: 2px solid #7c3aed; outline-offset: 1px; }
.field-browser-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}
.field-browser-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 12px;
  gap: 8px;
}
.field-browser-item:last-child { border-bottom: none; }
.field-browser-item:hover { background: #f9fafb; }
.field-browser-item__label { font-weight: 500; color: #111827; }
.field-browser-item__key { font-size: 11px; color: #9ca3af; font-family: monospace; }
.field-browser-item__type { font-size: 10px; color: #6b7280; }
.field-add-btn {
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.field-add-btn:hover { border-color: #7c3aed; color: #7c3aed; }
.field-browser-section {
  padding: 6px 10px 2px;
  font-size: 10px;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #f9fafb;
}
