:root {
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-danger: #dc2626;
  --color-whatsapp: #25d366;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.pantalla-carga {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
  padding: 2rem;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #eef2ff 0%, #f8fafc 60%);
}

.login-card {
  background: var(--color-surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--color-primary-dark);
}

.login-subtitle {
  margin: -0.5rem 0 0.5rem;
  color: var(--color-text-muted);
}

/* ---------- Layout general ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.app-header-left,
.app-header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--color-primary-dark);
  white-space: nowrap;
}

.view-switch {
  display: flex;
  background: var(--color-bg);
  border-radius: 999px;
  padding: 3px;
  border: 1px solid var(--color-border);
}

.view-switch button {
  border: none;
  background: transparent;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.view-switch button.active {
  background: var(--color-primary);
  color: white;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--color-border);
}

.user-email {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.app-main {
  flex: 1;
  overflow: auto;
  padding: 1rem;
}

/* ---------- Botones ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: #fee2e2;
  color: var(--color-danger);
}

.btn-link {
  background: transparent;
  color: var(--color-primary);
  padding: 0.25rem 0.4rem;
  font-weight: 600;
}

.btn-danger-text {
  color: var(--color-danger);
}

.btn-whatsapp {
  background: var(--color-whatsapp);
  color: white;
}

.btn-whatsapp:hover:not(:disabled) {
  background: #1fb457;
}

/* ---------- Kanban ---------- */
.kanban-board {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  height: 100%;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  position: relative;
}

.drag-ghost {
  position: fixed;
  z-index: 100;
  background: var(--color-primary);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  pointer-events: none;
  box-shadow: var(--shadow);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kanban-column {
  background: #eef1f6;
  border-radius: var(--radius);
  min-width: 270px;
  max-width: 270px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.9rem;
  border-top: 4px solid #94a3b8;
  border-radius: var(--radius) var(--radius) 0 0;
}

.kanban-column-header h2 {
  font-size: 0.9rem;
  margin: 0;
}

.kanban-count {
  background: white;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
}

.kanban-column-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 60px;
  transition: background 0.15s ease;
}

.kanban-column-over {
  background: rgba(79, 70, 229, 0.06);
  border-radius: 8px;
}

.kanban-empty {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 1rem 0;
}

.contact-card {
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.7rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.contact-card-drag {
  cursor: grab;
  touch-action: none;
}

.contact-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.4rem;
}

.contact-card-header strong {
  font-size: 0.92rem;
  line-height: 1.25;
}

.contact-card-sub {
  margin: 0.15rem 0 0;
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

.contact-card-next {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: #b45309;
}

.contact-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--color-border);
  padding-top: 0.45rem;
}

.contact-card-actions-right {
  display: flex;
  gap: 0.4rem;
}

.modal-header-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

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

.tag {
  display: inline-block;
  background: #eef2ff;
  color: var(--color-primary-dark);
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  width: fit-content;
}

.canal-badge {
  font-size: 0.95rem;
}

/* ---------- Lista ---------- */
.list-view {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.list-filters {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.list-search {
  flex: 1;
  min-width: 200px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.list-filters select {
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.contact-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.contact-table th,
.contact-table td {
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.contact-table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 1.5rem;
}

/* ---------- Modales / formularios ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal-card {
  background: var(--color-surface);
  border-radius: 14px;
  padding: 1.25rem;
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.modal-card-lg {
  max-width: 560px;
}

.modal-card h3 {
  margin: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.modal-hint {
  margin: -0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.field input,
.field select,
.field textarea {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.9rem;
}

.field-with-action {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.field-full {
  grid-column: 1 / -1;
}

.form-error {
  color: var(--color-danger);
  font-size: 0.82rem;
  margin: 0;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 40vh;
  overflow-y: auto;
}

.template-item {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}

.template-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.template-preview {
  margin: 0.3rem 0 0;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  white-space: pre-wrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .app-header-left,
  .app-header-right {
    justify-content: space-between;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .kanban-column {
    min-width: 82vw;
    max-width: 82vw;
  }
}
