/* ==========================================================================
   Reusable components: buttons, cards, table, badges, modal, forms
   ========================================================================== */

/* ---------------------------------------------------------------- BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--surface-muted); }

.btn-danger { background: var(--danger-text); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 12px; }
.btn-ghost:hover { background: var(--surface-muted); }

.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-block { width: 100%; }

/* ------------------------------------------------------------------ CARD */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
}

.stat-card .stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.stat-card .stat-icon svg { width: 20px; height: 20px; }

.stat-card .stat-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.stat-card .stat-value-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.trend-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.trend-badge.up { background: var(--success-bg); color: var(--success-text); }
.trend-badge.down { background: var(--danger-bg); color: var(--danger-text); }

/* ----------------------------------------------------------------- TABLE */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface-muted);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  color: var(--text-muted);
}
.search-box input {
  border: none; outline: none; background: transparent;
  font-size: 13.5px; width: 100%; color: var(--text-primary);
}
.search-box svg { width: 16px; height: 16px; flex-shrink: 0; }

.select-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  font-size: 13.5px;
  color: var(--text-secondary);
  background: var(--surface);
  outline: none;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.data-table tbody td {
  padding: 14px 20px;
  font-size: 13.8px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #FAFAFE; }
.data-table tbody tr:last-child td { border-bottom: none; }

.row-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* ----------------------------------------------------------------- PILLS */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 13px;
  border-radius: var(--radius-pill);
}
.pill-toggle-group { display: inline-flex; background: var(--surface-muted); border-radius: var(--radius-pill); padding: 4px; gap: 2px; }
.pill-toggle {
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
}
.pill-toggle.active { background: var(--primary); color: #fff; }

.status-active { background: var(--success-bg); color: var(--success-text); }
.status-inactive { background: var(--danger-bg); color: var(--danger-text); }
.status-warning { background: var(--warning-bg); color: var(--warning-text); }
.status-info { background: var(--info-bg); color: var(--info-text); }

.priority-hot { background: var(--danger-bg); color: var(--danger-text); }
.priority-warm { background: var(--warning-bg); color: var(--warning-text); }
.priority-cold { background: var(--info-bg); color: var(--info-text); }

.action-menu-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.action-menu-btn:hover { background: var(--surface-muted); }

/* ----------------------------------------------------------------- MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 19, 64, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 30px;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-box.wide { max-width: 760px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 700; }

.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-muted);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
}

.modal-body {
  padding: 22px 24px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ----------------------------------------------------------------- FORMS */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group .required { color: var(--danger-text); }

.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.8px;
  color: var(--text-primary);
  outline: none;
  background: var(--surface);
  transition: border-color .12s ease;
}
.form-control:focus { border-color: var(--accent); }
textarea.form-control { resize: vertical; min-height: 80px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--primary); }

.perm-module {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.perm-module-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  text-transform: capitalize;
}
.perm-checks { display: flex; flex-wrap: wrap; gap: 14px; }
.perm-check-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.perm-check-item input { width: 15px; height: 15px; accent-color: var(--accent); }

.field-error { color: var(--danger-text); font-size: 12.5px; margin-top: 5px; }

/* ------------------------------------------------------------- EMPTY/404 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 70px 20px;
  color: var(--text-secondary);
}
.empty-state .empty-icon {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
}
.empty-state .empty-icon svg { width: 30px; height: 30px; }
.empty-state h3 { margin: 0 0 6px; font-size: 16px; color: var(--text-primary); }
.empty-state p { margin: 0; font-size: 13.5px; max-width: 360px; }

/* --------------------------------------------------------------- TOASTS */
.toast-stack {
  position: fixed;
  top: 20px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 260px;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 14px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-left: 4px solid var(--accent);
  animation: slideIn .18s ease;
}
.toast.success { border-left-color: var(--success-text); color: var(--success-text); }
.toast.error { border-left-color: var(--danger-text); color: var(--danger-text); }

@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ------------------------------------------------------------- SPINNER */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner.dark { border-color: rgba(36,30,99,0.2); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row { text-align: center; padding: 40px; color: var(--text-muted); }

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------------------------------------------------- SEARCHABLE SELECT */
.searchable-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  z-index: 60;
}
.searchable-select-option {
  padding: 10px 14px;
  font-size: 13.5px;
  cursor: pointer;
}
.searchable-select-option:hover { background: var(--surface-muted); }
.searchable-select-empty {
  padding: 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ------------------------------------------------------- DASHBOARD/CHARTS */
.stat-card.disabled { opacity: 0.55; }

.coming-soon-tag {
  font-size: 10.5px;
  font-weight: 700;
  background: var(--surface-muted);
  color: var(--text-muted);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  display: inline-block;
  margin-top: 8px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.chart-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

.chart-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.chart-card .chart-sub { margin: 0 0 16px; font-size: 12.5px; color: var(--text-muted); }
.chart-canvas-wrap { position: relative; height: 260px; }
.chart-canvas-wrap.small { height: 210px; }

/* ------------------------------------------------------------- PIPELINE */
.pipeline-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  align-items: flex-start;
}

.pipeline-column {
  background: var(--surface-muted);
  border-radius: var(--radius-lg);
  min-width: 268px;
  max-width: 268px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 230px);
  transition: outline .1s ease;
}

.pipeline-column.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }

.pipeline-column-head {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pipeline-column-count {
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

.pipeline-cards {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pipeline-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  border-left: 3px solid var(--accent);
}
.pipeline-card:active { cursor: grabbing; }
.pipeline-card.dragging { opacity: 0.4; }

.pipeline-card-name { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; color: var(--text-primary); }
.pipeline-card-company { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.pipeline-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pipeline-empty-hint { padding: 18px 10px; text-align: center; font-size: 12px; color: var(--text-muted); }

/* ------------------------------------------------------------ FOLLOW-UPS */
.followup-row-overdue td { background: var(--danger-bg) !important; }
