/* ============================================================
   Components
   ============================================================ */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13px;
  transition: 100ms;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-600); }
.btn-success { background: var(--success); border-color: var(--success); color: white; }
.btn-success:hover { filter: brightness(0.95); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-lg { padding: 11px 18px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px; }
.card-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-body { padding: 18px; }

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.kpi-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  margin-left: auto;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -0.01em;
}
.kpi-change {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  margin-top: 6px;
  padding: 2px 7px;
  border-radius: 6px;
}
.kpi-change.up { color: var(--success); background: var(--success-50); }
.kpi-change.down { color: var(--danger); background: var(--danger-50); }
.kpi-change.flat { color: var(--muted); background: var(--bg-soft); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-info { background: var(--info-50); color: var(--info); }
.badge-purple { background: var(--purple-50); color: var(--purple); }
.badge-pink { background: var(--pink-50); color: var(--pink); }
.badge-primary { background: var(--primary-50); color: var(--primary); }
.badge-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; display: inline-block;
}

/* Tables */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--surface-2); }
/* Action cells: a `flex` utility set directly on a <td> cancels the cell's
   vertical-align, so buttons top-align in taller rows. Keep it a normal
   table-cell (inherits vertical-align:middle) and lay buttons out inline. */
.table td.flex { display: table-cell !important; vertical-align: middle; white-space: nowrap; }
.table td.flex > * { display: inline-flex; align-items: center; vertical-align: middle; }
.table td.flex > * + * { margin-left: 8px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-action { color: var(--text-2); font-weight: 500; }
.table-action:hover { color: var(--primary); }

/* Filters bar */
.filters {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filters select, .filters input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
}
.filters input { min-width: 220px; }
.filters select:focus, .filters input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }

/* Standalone styled select (e.g. dashboard date range) — native chevron removed,
   custom one added so it matches buttons/inputs across browsers. */
.select {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 32px 7px 12px;
  height: 34px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: 120ms;
}
.select:hover { border-color: var(--primary); }
.select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }

/* Inputs */
.field {
  display: flex; flex-direction: column; gap: 6px;
}
.field label {
  font-size: 12px; font-weight: 600; color: var(--text-2);
}
.field input, .field select, .field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 80px; font-family: var(--font); }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-50);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid; place-items: center;
  z-index: 80;
  padding: 24px;
  animation: fadeIn 150ms;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 600px;
  max-width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 180ms;
}
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } }
.modal-lg { width: 880px; }
.modal-xl { width: 1100px; }
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 22px; overflow-y: auto; overflow-x: hidden; flex: 1; min-width: 0; }
.modal-body * { max-width: 100%; box-sizing: border-box; }
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Toasts */
#toast-root {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 14px;
  border-radius: 9px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn 180ms;
}
.toast.success { background: var(--success); }
.toast.danger { background: var(--danger); }
.toast.info { background: var(--info); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }

/* Charts wrappers */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
.chart-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
@media (max-width: 1024px) {
  .chart-grid, .chart-grid-3 { grid-template-columns: 1fr; }
}
.chart-box {
  position: relative;
  height: 280px;
}

/* Kanban */
.kanban {
  display: grid;
  grid-template-columns: repeat(10, minmax(260px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.kanban-col {
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 400px;
  display: flex; flex-direction: column; gap: 10px;
}
.kanban-col-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px;
}
.kanban-col-head .count {
  background: white;
  border-radius: 999px;
  padding: 1px 8px;
  font-weight: 600;
}
.kanban-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: grab;
  transition: 120ms;
  box-shadow: var(--shadow-sm);
}
.kanban-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kanban-card.dragging { opacity: 0.5; transform: rotate(2deg); }
.kanban-col.over { background: var(--primary-50); outline: 2px dashed var(--primary); }
.kanban-card-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.kanban-card-meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.kanban-card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.kanban-card-value { font-size: 12.5px; font-weight: 700; color: var(--primary); }

/* Section grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 1024px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* Pipeline summary */
.list {
  display: flex; flex-direction: column; gap: 1px;
}
.list-item {
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.list-item:hover { background: var(--surface-2); }
.list-item:last-child { border-bottom: 0; }
.list-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--primary-50);
  color: var(--primary);
  display: grid; place-items: center;
  flex: 0 0 32px;
}

/* Detail layout */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}
@media (max-width: 1024px) { .detail-grid { grid-template-columns: 1fr; } }

/* Tabs */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border: 0; background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-color: var(--primary); }
.tab:hover { color: var(--text); }

/* Activity timeline */
.timeline {
  position: relative;
  padding-left: 28px;
}
.timeline::before {
  content: ""; position: absolute; left: 11px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item {
  position: relative;
  padding-bottom: 18px;
}
.timeline-item::before {
  content: ""; position: absolute; left: -22px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: white;
  border: 3px solid var(--primary);
}
.timeline-item .meta {
  font-size: 11.5px; color: var(--muted);
}
.timeline-item .body {
  font-size: 13px;
}

/* PDF preview */
.pdf-doc {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 36px 40px;
  font-size: 12px;
  color: #1f2937;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  max-width: 760px;
  margin: 0 auto;
}
.pdf-doc h1 {
  font-size: 24px;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--primary);
}
.pdf-doc table { width: 100%; border-collapse: collapse; font-size: 12px; }
.pdf-doc table th { background: #f1f5f9; padding: 8px; text-align: left; border-bottom: 2px solid #cbd5e1; }
.pdf-doc table td { padding: 8px; border-bottom: 1px solid var(--border); }
.pdf-doc .totals { width: 280px; margin-left: auto; margin-top: 18px; }
.pdf-doc .totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.pdf-doc .totals .grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 14px; }

/* Empty state */
.empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}
.empty .icon {
  font-size: 32px; margin-bottom: 8px; opacity: 0.4;
}

/* Misc helpers */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

.progress {
  height: 6px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 200ms;
}

/* Email preview */
.email-preview {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  font-size: 13px;
}
.email-preview .head {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.email-preview .head .row {
  display: flex; gap: 8px; margin-bottom: 4px;
  font-size: 12.5px;
}
.email-preview .head .row label { color: var(--muted); width: 50px; }

/* Score pill */
.score-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 6px;
  font-weight: 700; font-size: 11.5px;
}
.score-high { background: var(--success-50); color: var(--success); }
.score-med { background: var(--warning-50); color: var(--warning); }
.score-low { background: var(--bg-soft); color: var(--muted); }

/* Two-pane mail layout */
.mail-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  height: calc(100vh - 180px);
}
.mail-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
}
.mail-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.mail-item:hover { background: var(--surface-2); }
.mail-item.active { background: var(--primary-50); border-left: 3px solid var(--primary); padding-left: 11px; }
.mail-item .from { font-weight: 600; font-size: 13px; }
.mail-item .subj { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.mail-item .preview { font-size: 11.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Quote builder line items */
.line-items {
  display: grid;
  grid-template-columns: 3fr 1fr 1.2fr 1fr 1.2fr 40px;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.line-items .head {
  font-size: 11.5px; font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.line-items input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 13px;
  outline: none;
}
.line-items input:focus { border-color: var(--primary); background: white; }

/* Mini stats */
.mini-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.mini-stat {
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.mini-stat .label { font-size: 11.5px; color: var(--muted); }
.mini-stat .val { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* Sortable rows */
.sortable th { cursor: pointer; user-select: none; }
.sortable th:hover { color: var(--text); }

/* ---- Business switcher (sidebar) ---- */
.biz-switcher-wrap {
  padding: 10px 12px 4px;
  position: relative;
}
.biz-current {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 9px;
  color: var(--sidebar-text-strong);
  text-align: left;
  cursor: pointer;
  transition: 100ms;
}
.biz-current:hover { background: rgba(148, 163, 184, 0.14); }
.biz-icon {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white; font-weight: 700;
  display: grid; place-items: center;
  flex: 0 0 30px;
}
.biz-icon-sm {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white; font-weight: 700; font-size: 12px;
  display: grid; place-items: center;
  flex: 0 0 24px;
}
.biz-meta { flex: 1; min-width: 0; line-height: 1.2; overflow: hidden; }
.biz-meta strong {
  display: block; font-size: 13px; color: var(--sidebar-text-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.biz-meta span { display: block; font-size: 11px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.biz-chev { color: #94a3b8; font-size: 11px; }

.biz-menu {
  position: absolute;
  top: 6px;
  left: 100%;
  margin-left: 8px;
  width: 264px;
  background: #0e162a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.5);
  padding: 6px;
  z-index: 60;
  max-height: 70vh;
  overflow-y: auto;
}
.biz-menu-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 8px 10px 4px;
  font-weight: 600;
}
.biz-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  background: transparent; border: 0;
  border-radius: 7px;
  color: var(--sidebar-text);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.biz-menu-item:hover { background: rgba(79, 70, 229, 0.15); color: white; }
.biz-menu-item.active { background: rgba(16, 185, 129, 0.12); color: white; }
.biz-menu-item strong { font-size: 13px; display: block; }
.biz-menu-item span { font-size: 11px; color: #94a3b8; display: block; }
.biz-tick { margin-left: auto; color: var(--success); font-weight: 700; }
.biz-menu-divider { height: 1px; background: #1e293b; margin: 6px 4px; }
