:root {
  --primary: #b64211;
  --primary-strong: #df3314;
  --primary-soft: rgba(251, 123, 21, 0.08);
  --on-primary: #ffffff;
  --danger: #b11e1b;
  --danger-soft: rgba(177, 30, 27, 0.1);
  --ok: #3f6b28;
  --ok-soft: rgba(95, 141, 62, 0.12);
  --accent: #df3314;
  --accent-soft: rgba(223, 51, 20, 0.12);
  --warning: #92400e;
  --warning-soft: rgba(146, 64, 14, 0.12);
  --primary-ring: rgba(182, 66, 17, 0.18);
  --primary-shadow: rgba(182, 66, 17, 0.28);

  --bg: #f8f4e9;
  --surface: #ffffff;
  --surface-soft: #faf1e7;
  --border: #ecdfd0;
  --text: #2a1c10;
  --text-muted: #8a7565;

  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 8px 24px rgba(178, 94, 42, 0.08);
  --shadow-hover: 0 12px 28px rgba(178, 94, 42, 0.14);

  --font-heading: 'Montserrat', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --primary: #fb7b15;
  --primary-strong: #ff9a4d;
  --primary-soft: rgba(251, 123, 21, 0.18);
  --on-primary: #241608;
  --danger: #ff7168;
  --danger-soft: rgba(226, 69, 63, 0.16);
  --ok: #7cab5a;
  --ok-soft: rgba(124, 171, 90, 0.16);
  --accent: #ff9a4d;
  --accent-soft: rgba(255, 154, 77, 0.18);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.18);
  --primary-ring: rgba(251, 123, 21, 0.28);
  --primary-shadow: rgba(251, 123, 21, 0.35);

  --bg: #1b140f;
  --surface: #241b14;
  --surface-soft: #2c2118;
  --border: #3a2c20;
  --text: #f8f4e9;
  --text-muted: #b5a08c;

  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.45);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: var(--font-heading);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  transition: background-color 0.2s var(--ease), transform 0.15s var(--ease), box-shadow 0.2s var(--ease);
}

button:active {
  transform: scale(0.97);
}

input, select, textarea {
  font-family: inherit;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.2s var(--ease), color 0.2s var(--ease);
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

textarea {
  resize: vertical;
  font-family: inherit;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  animation: fade-in 0.4s var(--ease) both;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark svg {
  width: 26px;
  height: 26px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.theme-toggle svg { width: 18px; height: 18px; }

.theme-toggle:hover { border-color: var(--primary); transform: translateY(-1px); }
.theme-toggle:active { transform: translateY(0) scale(0.92); }

.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.topbar h1 {
  font-size: 17px;
  margin: 0;
  color: var(--primary);
}

.topbar .subtitle-tag {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

.btn-secondary {
  background: var(--surface-soft);
  color: var(--text);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
}

.btn-secondary:hover {
  background: var(--primary-soft);
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--primary-strong);
  box-shadow: 0 6px 16px var(--primary-shadow);
}

.btn-icon-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

/* ---------- Layout ---------- */
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  animation: fade-in 0.5s var(--ease) both;
}

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

.panel + .panel {
  margin-top: 20px;
}

.section-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.hidden {
  display: none !important;
}

/* ---------- Stat cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fade-up 0.35s var(--ease) both;
}

.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-card.total { border-color: var(--primary-soft); }
.stat-card.total .stat-value { color: var(--primary); }

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.count-badge {
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.search-input-wrap {
  position: relative;
  min-width: 220px;
  flex: 1;
  max-width: 320px;
}

.search-input-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap input {
  width: 100%;
  padding-left: 36px;
}

.view-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.view-toggle button {
  background: transparent;
  color: var(--text-muted);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
}

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

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

/* ---------- Kanban ---------- */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(200px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.kanban-column {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.kanban-column.drag-over {
  background: var(--primary-soft);
  border-color: var(--accent);
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 6px;
  border-bottom: 2px solid;
}

.kanban-column-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 40px;
}

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: grab;
  animation: fade-up 0.3s var(--ease) both;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}

.kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px var(--primary-shadow);
  border-color: var(--primary-soft);
}

.kanban-card.dragging {
  opacity: 0.4;
}

.kanban-card h4 {
  margin: 0 0 3px;
  font-size: 14px;
  color: var(--text);
}

.kanban-card .card-company {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.kanban-card .card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

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

/* ---------- Table ---------- */
.contacts-table-wrap {
  overflow-x: auto;
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.contacts-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.contacts-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.contacts-table tr:last-child td {
  border-bottom: none;
}

.contacts-table tr {
  animation: fade-up 0.3s var(--ease) both;
}

.cell-name {
  font-weight: 600;
  color: var(--text);
}

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

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-soft);
}

.icon-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

.empty-text {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 30px 0;
}

/* ---------- Modales ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade-in 0.2s var(--ease) both;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  padding: 28px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.3);
  animation: pop-in 0.25s var(--ease) both;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-content h2 {
  margin: 0;
  font-size: 18px;
  color: var(--primary);
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.modal-content form {
  display: flex;
  flex-direction: column;
}

.modal-content label {
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  margin-bottom: 4px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-row label {
  margin-top: 12px;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .kanban-board {
    grid-template-columns: repeat(7, 220px);
  }
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-filters {
    flex-direction: column;
  }

  .search-input-wrap {
    max-width: none;
  }

  .view-toggle {
    align-self: flex-start;
  }

  .toolbar-actions button {
    flex: 1;
    justify-content: center;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-hover);
  font-size: 13px;
  font-weight: 600;
  max-width: 320px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}
