:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --pendiente: #f59e0b;
  --preparacion: #3b82f6;
  --despachado: #8b5cf6;
  --entregado: #10b981;
  --facturas: #06b6d4;
  --error: #ef4444;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.screen {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Login */
.login-card {
  width: 100%;
  max-width: 380px;
  margin: auto;
  padding: 2.5rem 2rem;
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
  font-size: 1.5rem;
  text-align: center;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, textarea {
  padding: 0.65rem 0.75rem;
  border: 1px solid #2d3a4f;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

textarea {
  resize: vertical;
}

button {
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #2d3a4f;
}

.btn-secondary:hover {
  background: #3d4f66;
}

.btn-primary {
  background: #10b981;
}

.btn-primary:hover {
  background: #059669;
}

.btn-danger {
  background: var(--error);
}

.btn-danger:hover {
  background: #dc2626;
}

.error {
  color: var(--error);
  font-size: 0.85rem;
}

/* Dashboard Layout */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid #2d3a4f;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.meta {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.layout {
  display: flex;
  min-height: calc(100vh - 80px - 40px);
}

/* Sidebar */
.sidebar {
  width: 260px;
  border-right: 1px solid #2d3a4f;
  padding: 1rem 0;
  flex-shrink: 0;
}

.sidebar ul {
  list-style: none;
}

.nav-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.nav-item:hover {
  background: #2d3a4f;
  color: var(--text);
}

.nav-item.active {
  background: #2563eb;
  color: white;
}

.nav-icon {
  font-size: 1.1rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  max-width: calc(100vw - 260px);
}

.view.active {
  display: block;
}

.section-panel {
  background: rgba(26, 35, 50, 0.5);
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #2d3a4f;
}

/* Dashboard Stats */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  border-left: 4px solid var(--accent, #8b9cb3);
}

.stat-card h3 {
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card .value {
  font-size: 2.8rem;
  font-weight: 800;
  margin-top: 0.5rem;
  color: var(--accent, #8b9cb3);
  line-height: 1;
}

.stat-card .value.value-sm {
  font-size: 1.75rem;
}

.btn-secondary.btn-sm,
.btn-primary.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* Kanban Pipeline */
.kanban-board {
  display: flex;
  gap: 0.85rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  min-height: 420px;
  align-items: flex-start;
}

.kanban-column {
  flex: 0 0 250px;
  background: rgba(26, 35, 50, 0.55);
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  max-height: calc(100vh - 220px);
  display: flex;
  flex-direction: column;
}

.kanban-column-header {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid #2d3a4f;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.kanban-column-header h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kanban-column-count {
  background: #2d3a4f;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.kanban-cards {
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
}

.kanban-cards.drag-over {
  background: rgba(37, 99, 235, 0.08);
  outline: 2px dashed rgba(59, 130, 246, 0.45);
  outline-offset: -4px;
  border-radius: 0 0 var(--radius) var(--radius);
}

.crm-dialog-actions-split {
  justify-content: space-between;
  align-items: center;
}

.crm-dialog-actions-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.crm-dialog-actions-right {
  display: flex;
  gap: 0.65rem;
}

.tag-manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface);
  border: 1px solid #2d3a4f;
  border-radius: 8px;
}

.tag-manage-item .btn-danger-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.kanban-card {
  background: var(--surface);
  border: 1px solid #2d3a4f;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  cursor: grab;
  transition: box-shadow 0.15s, opacity 0.15s;
}

.kanban-card .link-btn {
  cursor: pointer;
}

.kanban-card:hover {
  border-color: #3b82f6;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.kanban-card.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.pipeline-actions-right {
  display: flex;
  gap: 0.5rem;
}

.pipeline-export-hint {
  white-space: nowrap;
  margin-left: 1rem;
}

.kanban-card-actions {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.quick-btn {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.quick-btn:hover {
  transform: scale(1.1);
}

.quick-btn.quick-ganado {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
}

.quick-btn.quick-perdido {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.quick-btn.quick-eliminar {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.kanban-card-titulo {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.kanban-card-cliente {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.kanban-card-valor {
  font-size: 0.85rem;
  color: #34d399;
  font-weight: 600;
}

.kanban-card-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.kanban-card-notas {
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-top: 0.35rem;
  line-height: 1.35;
  font-style: italic;
}

/* Tags */
.tags-lista {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.tag-chip .tag-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.tag-chip .tag-remove:hover {
  opacity: 1;
}

.tag-color-input {
  width: 2.5rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid #2d3a4f;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}

.detalle-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.detalle-tags-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.detalle-tags-actions select {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #2d3a4f;
  background: #0f1419;
  color: var(--text);
}

/* Actividad reciente */
.actividad-lista {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.actividad-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid #2d3a4f;
  align-items: flex-start;
}

.actividad-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  background: rgba(59, 130, 246, 0.15);
}

.actividad-body {
  flex: 1;
  min-width: 0;
}

.actividad-body strong {
  font-size: 0.9rem;
}

.actividad-body p {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.actividad-fecha {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.cliente-buscar-lista {
  position: absolute;
  z-index: 10;
  background: #1a2332;
  border: 1px solid #2d3a4f;
  border-radius: 8px;
  max-height: 160px;
  overflow-y: auto;
  width: 100%;
  margin-top: 0.25rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.cliente-buscar-lista button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.cliente-buscar-lista button:hover {
  background: rgba(37, 99, 235, 0.15);
}

.config-label {
  position: relative;
}

/* Pipeline States */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.pipeline-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.pipeline-item h3 {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.pipeline-item .value {
  font-size: 2rem;
  font-weight: 800;
}

/* Clientes por segmento */
.segmentos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.seg-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.seg-item h3 {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.seg-item .value {
  font-size: 2.2rem;
  font-weight: 800;
}

/* Interactions list */
.interaction-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.interaction-card .info {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.interaction-type {
  font-size: 1.25rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #2d3a4f;
}

.interaction-info h4 {
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
}

.interaction-info p {
  font-size: 0.8rem;
  color: var(--muted);
}

.interaction-date {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.toolbar input, .toolbar select {
  width: 300px;
}

/* Panel de filtros (Clientes, Pipeline, Incentivos, Historial) */
.filters-panel {
  background: var(--surface);
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  padding: 1rem 1.25rem 0.85rem;
  margin-bottom: 1.25rem;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.25rem;
  align-items: flex-end;
}

.filters-row--secondary {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(45, 58, 79, 0.55);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.filter-group label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.filter-group input,
.filter-group select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
}

.filter-group--search {
  flex: 1 1 260px;
  max-width: 440px;
}

.filter-group--sm {
  flex: 0 0 120px;
}

.filter-group--md {
  flex: 0 0 160px;
}

.filter-group--lg {
  flex: 0 0 220px;
}

.filter-inline {
  display: flex;
  gap: 0.5rem;
}

.filter-inline input {
  flex: 1;
  min-width: 0;
}

.filter-inline button {
  flex-shrink: 0;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding-bottom: 0.1rem;
}

.filter-actions--end {
  margin-left: auto;
}

.filters-info-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(45, 58, 79, 0.35);
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.filters-info-bar > span:empty {
  display: none;
}

.filters-info-bar > span:not(:first-child):not(:empty)::before {
  content: '·';
  margin-right: 1rem;
  opacity: 0.45;
}

.filters-info-resumen {
  color: var(--text);
  font-weight: 500;
}

@media (max-width: 900px) {
  .filter-group--search {
    flex: 1 1 100%;
    max-width: none;
  }

  .filter-group--sm,
  .filter-group--md,
  .filter-group--lg {
    flex: 1 1 calc(50% - 0.75rem);
  }

  .filter-actions--end {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }
}

/* Tables */
.crm-table {
  width: 100%;
  border-collapse: collapse;
}

.crm-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #2d3a4f;
}

.crm-table td {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(45, 58, 79, 0.4);
}

.crm-table tr:hover td {
  background: rgba(37, 99, 235, 0.08);
}

.crm-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.crm-table th.sortable:hover {
  color: var(--text, #e2e8f0);
}

.crm-table th.sortable .sort-icon::after {
  content: '⇅';
  margin-left: 0.35rem;
  font-size: 0.75rem;
  opacity: 0.35;
}

.crm-table th.sortable.sorted-asc .sort-icon::after {
  content: '↑';
  opacity: 1;
}

.crm-table th.sortable.sorted-desc .sort-icon::after {
  content: '↓';
  opacity: 1;
}

.crm-table tr.row-clickable {
  cursor: pointer;
}

.crm-table tr.row-clickable:hover td {
  background: rgba(37, 99, 235, 0.12);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tabla clientes — layout compacto para que entren las acciones */
#clientes-table {
  table-layout: fixed;
  min-width: 980px;
}

#clientes-table col.col-codigo { width: 4.25rem; }
#clientes-table col.col-fecha { width: 4.5rem; }
#clientes-table col.col-email { width: 8.5rem; }
#clientes-table col.col-locali { width: 6rem; }
#clientes-table col.col-vendedor { width: 5.5rem; }
#clientes-table col.col-monto { width: 5rem; }
#clientes-table col.col-acciones { width: 10.75rem; }

#clientes-table th {
  padding: 0.45rem 0.4rem;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  line-height: 1.25;
}

#clientes-table th.col-resizable {
  position: relative;
  overflow: visible;
}

#clientes-table .col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 3;
  touch-action: none;
}

#clientes-table .col-resizer:hover,
body.col-resizing #clientes-table .col-resizer {
  background: rgba(96, 165, 250, 0.4);
}

body.col-resizing {
  cursor: col-resize;
  user-select: none;
}

body.col-resizing * {
  cursor: col-resize !important;
}

#clientes-table td {
  padding: 0.4rem 0.4rem;
  font-size: 0.78rem;
  line-height: 1.3;
  vertical-align: middle;
}

#clientes-table .cell-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
}

#clientes-table .cell-num {
  white-space: nowrap;
  font-size: 0.74rem;
}

#clientes-table .table-actions {
  flex-wrap: nowrap;
  white-space: nowrap;
}

#clientes-table .table-btn {
  padding: 0.22rem 0.42rem;
  font-size: 0.7rem;
  flex-shrink: 0;
}

#clientes-table th:last-child,
#clientes-table td.table-actions {
  position: sticky;
  right: 0;
  z-index: 1;
  background: #151c28;
  box-shadow: -6px 0 10px rgba(0, 0, 0, 0.25);
}

#clientes-table tr:hover td.table-actions {
  background: #1a2436;
}

.dialog-wide {
  width: min(900px, 95vw);
  max-height: 90vh;
  border: none;
  border-radius: 12px;
  padding: 0;
  background: #1a2332;
  color: inherit;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  overflow: auto;
}

.dialog-wide::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

/* Diálogos CRM (alert / confirm / prompt / formularios) */
.crm-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-height: 90vh;
  overflow: auto;
  width: min(440px, 92vw);
  border: none;
  border-radius: 12px;
  padding: 0;
  background: #1a2332;
  color: inherit;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.crm-dialog-form {
  width: min(480px, 92vw);
}

.incentivo-dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  padding-bottom: 0;
}

.incentivo-dialog-body {
  overflow-y: auto;
  flex: 1;
  padding-right: 0.15rem;
}

.incentivo-dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 1rem 0 0;
  border-top: 1px solid #2d3a4f;
  background: #1a2332;
  position: sticky;
  bottom: 0;
}

.incentivo-dialog-actions-main {
  display: flex;
  gap: 0.65rem;
  margin-left: auto;
  flex-wrap: wrap;
}

#inc-guardar {
  min-width: 8.5rem;
}

.crm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.crm-dialog-inner {
  padding: 1.5rem 1.5rem 1.25rem;
}

.crm-dialog-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  margin-bottom: 0.85rem;
}

.crm-dialog-icon.icon-info { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.crm-dialog-icon.icon-success { background: rgba(52, 211, 153, 0.2); color: #34d399; }
.crm-dialog-icon.icon-warning { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.crm-dialog-icon.icon-error { background: rgba(248, 113, 113, 0.2); color: #f87171; }
.crm-dialog-icon.icon-question { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }
.crm-dialog-icon.icon-mail { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }

.crm-dialog-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  line-height: 1.3;
}

.crm-dialog-lead {
  margin: 0 0 1rem;
  line-height: 1.45;
}

.crm-dialog-message {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 0.25rem;
}

.crm-dialog-message .codigo-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
}

.crm-dialog-field {
  margin-top: 1rem;
}

.crm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.35rem;
  padding-top: 1rem;
  border-top: 1px solid #2d3a4f;
}

.crm-dialog-actions .btn-primary,
.crm-dialog-actions .btn-secondary {
  min-width: 6.5rem;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #2d3a4f;
}

.cliente-detalle-body {
  padding: 1rem 1.25rem 1.25rem;
  overflow: auto;
  max-height: calc(90vh - 4rem);
}

.detalle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
}

.detalle-grid dt {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detalle-grid dd {
  margin: 0.15rem 0 0;
  font-size: 0.95rem;
}

.detalle-section h3 {
  margin: 1rem 0 0.5rem;
  font-size: 0.95rem;
}

.detalle-historial {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.detalle-historial th,
.detalle-historial td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid rgba(45, 58, 79, 0.5);
  text-align: left;
}

.estado-ok { color: #34d399; }
.estado-error { color: #f87171; }
.estado-muted { color: var(--muted); }

.toolbar .hidden {
  display: none;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#clientes-page-info {
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 12rem;
}

#clientes-page-size {
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #2d3a4f;
  background: #1a2332;
  color: inherit;
}

.table-btn.link-btn {
  background: transparent;
  color: #60a5fa;
  padding: 0;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

.table-actions {
  display: flex;
  gap: 0.4rem;
}

.table-btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 6px;
  background: #2d3a4f;
  cursor: pointer;
}

.table-btn:hover {
  background: #3d4f66;
}

.table-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.table-btn:disabled:hover {
  background: #2d3a4f;
}

.table-btn.btn-danger-sm {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

.table-btn.btn-danger-sm:hover {
  background: rgba(239, 68, 68, 0.3);
}

/* Form Rows */
.form-row {
  display: flex;
  gap: 1rem;
}

.form-row > label {
  flex: 1;
}

/* Dialogs */
dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem;
  max-width: 600px;
  width: 90%;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

dialog h2 {
  font-size: 1.25rem;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, 0.82);
  backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
  display: none !important;
}

.loading-box {
  text-align: center;
  padding: 2rem 2.5rem;
  background: var(--surface);
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  max-width: 320px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 1.25rem;
  border: 4px solid #2d3a4f;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-message {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.loading-hint {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

body.is-loading {
  overflow: hidden;
}

/* Footer */
.footer {
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
}

#status-text.error {
  color: var(--error);
}

/* Responsive */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #2d3a4f;
  }

  .main-content {
    max-width: 100vw;
  }

  .form-row {
    flex-direction: column;
  }

  .toolbar input, .toolbar select {
    width: 100%;
  }

  .crm-table th:nth-child(4),
  .crm-table td:nth-child(4) {
    display: none;
  }
}

/* Configuración — plantillas email */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.config-grid--plantillas {
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
}

.config-grid--passwords .config-card .btn-primary {
  margin-top: 0.5rem;
}

.tpl-preview-details {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(45, 58, 79, 0.55);
}

.tpl-preview-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.5rem;
}

.tpl-preview-hint {
  margin: 0.35rem 0 0.65rem;
  font-size: 0.8rem;
}

.tpl-preview-frame {
  display: block;
  width: 100%;
  height: 380px;
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  background: #ffffff;
}

.tpl-preview-html {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  color: #a8b8cc;
  resize: vertical;
  min-height: 140px;
}

.config-card--layout {
  margin-bottom: 1.5rem;
}

.config-layout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.25rem;
}

.config-label--full {
  grid-column: 1 / -1;
}

@media (max-width: 720px) {
  .config-layout-grid {
    grid-template-columns: 1fr;
  }
}

.config-card {
  background: var(--surface);
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  padding: 1.25rem;
}

.config-card h3 {
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}

.config-vars code {
  background: rgba(0, 0, 0, 0.25);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.config-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.config-input,
.config-textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #2d3a4f;
  border-radius: var(--radius);
  background: #0f1419;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.config-textarea {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 180px;
}

.config-inline {
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
}

.config-input-sm {
  max-width: 5rem;
}

#masivo-pct-wrap.hidden {
  display: none;
}

.config-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}


.codigo-badge {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9em;
  letter-spacing: 0.05em;
}
