/* ============================================
   PropCRM — Components (Responsive, Legible)
   ============================================ */

/* ── Buttons ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s;
  white-space: nowrap;
  line-height: 1;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary i { font-size: 18px; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text-primary); }

.btn-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition);
  font-size: 17px;
}
.btn-icon:hover { background: var(--surface2); color: var(--text-primary); }

/* ── Metrics Grid ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 26px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  display: flex;
  align-items: flex-start;
  gap: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
}
.metric-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.metric-icon {
  width: 54px; height: 54px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}

.metric-body { flex: 1; min-width: 0; }
.metric-label { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: 5px; }
.metric-value { font-size: 30px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.metric-delta { font-size: var(--fs-sm); margin-top: 5px; }
.metric-delta.positive { color: var(--green); }
.metric-delta.negative { color: var(--red); }
.metric-delta.info { color: var(--blue); }

/* ── Dashboard Panels ── */
.dash-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.dash-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px;
}
.panel-title { font-size: var(--fs-md); font-weight: 600; color: var(--text-primary); }
.panel-link {
  font-size: var(--fs-sm); color: var(--brand); background: none; border: none;
  cursor: pointer; font-family: var(--font-sans);
}
.panel-link:hover { text-decoration: underline; }

/* Activity List */
.activity-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 9px; height: 9px; border-radius: 50%;
  margin-top: 6px; flex-shrink: 0;
}

.activity-text { font-size: var(--fs-sm); color: var(--text-primary); line-height: 1.5; }
.activity-time { font-size: var(--fs-xs); color: var(--text-hint); margin-top: 3px; }

/* AI Stats bars */
.ai-stat-row { margin-bottom: 18px; }
.ai-stat-header {
  display: flex; justify-content: space-between;
  font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: 7px;
}
.ai-stat-val { font-weight: 700; color: var(--text-primary); }
.progress-track { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 1s var(--ease); }

/* ── Card Panel ── */
.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ── Table ── */
.table-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-wrap { position: relative; flex: 1; min-width: 220px; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 17px; color: var(--text-hint);
}
.search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  font-family: var(--font-sans);
  background: var(--surface2);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px rgba(26,86,219,0.1); }
.search-input::placeholder { color: var(--text-hint); }

.toolbar-filters { display: flex; gap: 10px; flex-wrap: wrap; }

.filter-select {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  font-family: var(--font-sans);
  background: var(--surface2);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  min-width: 140px;
}
.filter-select:focus { border-color: var(--brand); }

.table-wrap { overflow-x: auto; }

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}

.crm-table thead th {
  padding: 15px 20px;
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-hint);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}

.crm-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  cursor: pointer;
}
.crm-table tbody tr:hover { background: #f0f6ff; }
.crm-table tbody tr:last-child { border-bottom: none; }

.crm-table td {
  padding: 16px 20px;
  color: var(--text-primary);
  vertical-align: middle;
}

.cell-name { display: flex; align-items: center; gap: 11px; font-weight: 500; }

.table-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 700; flex-shrink: 0;
}

.cell-actions { display: flex; gap: 5px; justify-content: flex-end; opacity: 0; transition: opacity var(--transition); }
tr:hover .cell-actions { opacity: 1; }

/* Tags / Badges */
.tag {
  display: inline-flex; align-items: center;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}

.tag-comprador { background: var(--teal-light); color: var(--teal); }
.tag-vendedor  { background: var(--blue-light);  color: var(--blue); }
.tag-inversor  { background: var(--amber-light); color: var(--amber); }
.tag-caliente  { background: var(--red-light);   color: var(--red); }
.tag-nuevo     { background: var(--blue-light);  color: var(--blue); }
.tag-negociacion { background: var(--teal-light); color: var(--teal); }
.tag-proceso   { background: var(--amber-light); color: var(--amber); }
.tag-perdido   { background: #f3f4f6; color: var(--text-secondary); }
.tag-cerrado   { background: var(--green-light); color: var(--green); }

/* ── Kanban ── */
.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
}
.kanban-board::-webkit-scrollbar { height: 7px; }
.kanban-board::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.kanban-col { min-width: 220px; flex-shrink: 0; }

.kanban-col-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 2px 12px;
}
.kanban-col-title {
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.kanban-count {
  background: var(--surface2);
  color: var(--text-secondary);
  font-size: var(--fs-xs); font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}

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

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.kanban-card.closed { border-left: 3px solid var(--green); }

.k-prop { font-size: var(--fs-base); font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.k-client { font-size: var(--fs-sm); color: var(--text-secondary); }
.k-price { font-size: var(--fs-base); font-weight: 700; margin-top: 10px; }
.k-accent { height: 4px; border-radius: 2px; margin-top: 12px; }
.k-price-closed { color: var(--green); }

/* ── Reports ── */
.reports-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.rc-title { font-size: var(--fs-base); font-weight: 600; color: var(--text-secondary); margin-bottom: 16px; }

.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.bar-label { font-size: var(--fs-sm); color: var(--text-secondary); min-width: 100px; }
.bar-track { flex: 1; height: 9px; background: var(--surface2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; transition: width 1.2s var(--ease); }
.bar-val { font-size: var(--fs-sm); color: var(--text-secondary); min-width: 36px; text-align: right; font-weight: 700; }

.funnel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.funnel-bar {
  height: 30px; border-radius: var(--radius-sm);
  display: flex; align-items: center; padding: 0 12px;
  font-size: var(--fs-sm); font-weight: 600; color: #fff;
  transition: width 1s var(--ease);
  white-space: nowrap; overflow: hidden;
}

/* ── Config IA ── */
.config-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.config-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.config-card-title {
  font-size: var(--fs-md); font-weight: 600; color: var(--text-primary);
  margin-bottom: 18px; display: flex; align-items: center; gap: 9px;
}
.config-card-title i { font-size: 20px; color: var(--brand); }

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-control-crm {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  background: var(--surface2);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), background var(--transition);
  line-height: 1.5;
}
.form-control-crm:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px rgba(26,86,219,0.1); }
textarea.form-control-crm { resize: vertical; min-height: 90px; }
.form-hint { font-size: var(--fs-xs); color: var(--text-hint); margin-top: 5px; display: block; line-height: 1.5; }
.form-hint a { color: var(--brand); }

.flow-item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.flow-item:last-child { border-bottom: none; }

.flow-icon {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}

.flow-text { flex: 1; }
.flow-name { font-size: var(--fs-base); font-weight: 600; color: var(--text-primary); }
.flow-desc { font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 2px; line-height: 1.4; }

/* Toggle Switch */
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0;
  background: var(--border-strong);
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}
.switch-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-slider { background: var(--brand); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

/* Toggle Row */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: var(--fs-base); font-weight: 600; color: var(--text-primary); }
.toggle-sub { font-size: var(--fs-sm); color: var(--text-secondary); margin-top: 3px; }

/* Settings */
.settings-section { padding-bottom: 22px; margin-bottom: 22px; border-bottom: 1px solid var(--border); }
.settings-section:last-of-type { border-bottom: none; }
.settings-title { font-size: var(--fs-md); font-weight: 700; margin-bottom: 16px; color: var(--text-primary); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s var(--ease);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: var(--fs-lg); font-weight: 700; color: var(--text-primary); }
.modal-close {
  width: 34px; height: 34px;
  border: none; background: var(--surface2);
  border-radius: var(--radius-sm);
  font-size: 18px; cursor: pointer; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
}

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

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 28px; right: 28px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 10px;
}

.toast {
  background: var(--sidebar-bg);
  color: #fff;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 11px;
  animation: toastIn 0.25s var(--ease);
  max-width: 360px;
}
.toast.success i { color: #4ade80; }
.toast.error   i { color: #f87171; }
.toast.info    i { color: #60a5fa; }

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

/* ── Responsive: Large screens (> 1280px) — 4 columns ── */
@media (min-width: 1280px) {
  .metrics-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Responsive: Tablet landscape (1025–1279px) — 2+2 ── */
@media (max-width: 1279px) and (min-width: 769px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .dash-panels { grid-template-columns: 1fr; }
  .config-layout { grid-template-columns: 1fr; }
  .reports-grid { grid-template-columns: 1fr; }
}

/* ── Responsive: Mobile (≤768px) ── */
@media (max-width: 768px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .metric-card { padding: 14px 16px; gap: 12px; }
  .metric-icon { width: 40px; height: 40px; font-size: 18px; }
  .metric-value { font-size: 22px; }

  .dash-panels { grid-template-columns: 1fr; gap: 14px; }
  .config-layout { grid-template-columns: 1fr; }
  .reports-grid { grid-template-columns: 1fr; }

  .table-toolbar { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: unset; }
  .toolbar-filters { flex-direction: column; }
  .filter-select { min-width: unset; width: 100%; }

  .crm-table { font-size: var(--fs-sm); }
  .crm-table td, .crm-table th { padding: 10px 12px; }

  .kanban-col { min-width: 200px; }

  .toast-container { bottom: 16px; right: 16px; left: 16px; }
  .toast { max-width: 100%; }
}

/* ── Responsive: Small mobile (≤480px) ── */
@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 12px 14px; }
  .metric-value { font-size: 20px; }

  .btn-primary, .btn-ghost { padding: 9px 14px; font-size: var(--fs-sm); }

  .modal-box { border-radius: var(--radius-lg); }
  .modal-header { padding: 16px 18px 14px; }
  .modal-body { padding: 16px 18px; }
  .modal-footer { padding: 12px 18px 16px; }
}
