:root {
  --bg: #f4f5f7;
  --card: #fff;
  --border: #e5e7eb;
  --text: #14161a;
  --muted: #767b87;
  --primary: #84cc16;
  --primary-dark: #65a30d;
  --primary-ink: #1a1f0a;
  --sidebar-bg: #fff;
  --sidebar-active: #14161a;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary-dark); text-decoration: none; }

.muted { color: var(--muted); font-size: 0.9em; }
.hidden { display: none !important; }
.error { color: var(--danger); }

/* ── Shell: sidebar + main ─────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex: none;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.sidebar-logo {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.85em;
  flex: none;
}
.sidebar-title { font-weight: 700; font-size: 0.95em; }
.sidebar-subtitle { font-size: 0.75em; color: var(--muted); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  font-size: 0.92em;
}
.sidebar-nav a:hover { background: var(--bg); }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-group-title {
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 12px 4px;
}
.sidebar-group-title:first-child { padding-top: 2px; }
.nav-icon { width: 18px; height: 18px; flex: none; display: inline-flex; }
.nav-icon svg { width: 100%; height: 100%; }

.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user-info { text-align: right; }
.topbar-user-name { font-weight: 600; font-size: 0.9em; }
.topbar-user-email { font-size: 0.78em; color: var(--muted); }
.avatar {
  width: 34px; height: 34px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8em;
  flex: none;
}
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; display: flex; align-items: center; }
.link-btn:hover { color: var(--text); }

.container { max-width: 1400px; margin: 0 auto; padding: 24px 28px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h2 { margin: 0; }
.badge { background: var(--primary); color: var(--primary-ink); border-radius: 999px; padding: 2px 10px; font-size: 0.85em; font-weight: 700; }
.badge-pendiente { background: #fef3c7; color: #92400e; border-radius: 999px; padding: 3px 10px; font-size: 0.78em; font-weight: 700; }

/* ── Stat cards (estilo referencia) ────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-clickable { cursor: pointer; transition: border-color 0.15s, transform 0.1s; }
.stat-clickable:hover { border-color: var(--primary); transform: translateY(-1px); }
.stat-label { font-size: 0.72em; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); text-transform: uppercase; }
.stat-value { font-size: 1.8em; font-weight: 800; margin: 6px 0 2px; }
.stat-sub { font-size: 0.8em; color: var(--muted); }
.stat-warn { color: #d97706; }
.stat-ok { color: #16a34a; }
.stat-info { color: #2563eb; }
.stat-neutral { color: var(--text); }

.filters { display: flex; gap: 8px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95em;
  margin-bottom: 10px;
  font-family: inherit;
}

.list { display: flex; flex-direction: column; gap: 6px; }
.list.small { max-height: 220px; overflow-y: auto; }

.crear-cliente-inline {
  border: 1px dashed var(--primary-dark);
  border-radius: var(--radius);
  padding: 10px;
  background: #f7fbee;
}
.crear-cliente-inline p { margin: 0 0 6px; }
.crear-cliente-inline input { margin-bottom: 6px; }
.crear-cliente-inline button { width: 100%; }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
}
.row:hover { background: #f7fbee; }
.ticket-badge { font-size: 0.78em; font-weight: 600; color: var(--muted); margin-left: 6px; }
.cliente-dominio { display: block; font-size: 0.85em; color: var(--muted); }

/* ── Tablas de datos (Historial, Clientes) ─────────────────── */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.data-table thead th {
  text-align: left;
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table tr[data-href] { cursor: pointer; }
.data-table .cell-strong { font-weight: 600; }
.data-table .col-fecha { white-space: nowrap; color: var(--muted); font-size: 0.9em; }
.data-table .col-acciones { text-align: right; white-space: nowrap; }

/* ── Estadísticas ───────────────────────────────────────────── */
.panels-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.panel h3 { margin: 0 0 14px; font-size: 0.95em; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
}
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar { width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-label { font-size: 0.62em; color: var(--muted); margin-top: 4px; }

.hbar-list { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: 110px 1fr 34px; align-items: center; gap: 10px; font-size: 0.88em; }
.hbar-label { text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.hbar-value { text-align: right; font-weight: 700; color: var(--muted); }

.tipo { text-transform: capitalize; font-weight: 700; font-size: 0.78em; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.tipo-llamada { color: #15803d; background: #dcfce7; }
.tipo-chat { color: #1d4ed8; background: #dbeafe; }
.tipo-ticket { color: #7e22ce; background: #f3e8ff; }
.tipo-correo { color: #b45309; background: #fef3c7; }

.board { display: flex; flex-direction: column; gap: 28px; }
.board-row h3 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.board-columns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.board-column {
  background: #eef0f4;
  border-radius: var(--radius);
  padding: 10px;
  min-height: 60px;
}
.board-column h4 { margin: 0 0 8px; font-size: 0.85em; color: var(--muted); display: flex; gap: 6px; }
.board-column-body { display: flex; flex-direction: column; gap: 8px; min-height: 40px; transition: background 0.15s; border-radius: 6px; }
.board-column-body.drag-over { background: #eaf6cf; }
.board-empty { margin: 0; text-align: center; padding: 8px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  font-size: 0.9em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card.dragging { opacity: 0.4; }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.card-cliente { font-weight: 600; color: var(--text); }
.card-cliente-wrap { display: inline-flex; align-items: center; gap: 4px; }
.copy-btn {
  background: none; border: none; padding: 4px; margin: 0;
  color: var(--muted); cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center;
  width: 24px; height: 24px;
  border-radius: 5px;
}
.copy-btn svg { width: 15px; height: 15px; }
.copy-btn:hover { color: var(--primary-dark); background: var(--bg); }
.copy-btn.copied { color: #16a34a; }
.card-problema { margin: 4px 0; color: var(--text); }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.card-actions { display: flex; gap: 10px; align-items: center; }
.mover-btn { font-weight: 600; color: var(--primary-dark); }
.mover-btn-volver { font-weight: 400; color: var(--muted); opacity: 0.7; }
.mover-btn-volver:hover { opacity: 1; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
}
button:hover { background: var(--primary-dark); color: #fff; }
button.secondary { background: var(--border); color: var(--text); }
button.secondary:hover { background: #d3d6dc; }

.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}
.login-card h1 { margin: 0 0 4px; }
.login-card button { width: 100%; margin-top: 8px; }
label { display: block; font-size: 0.85em; margin-bottom: 4px; color: var(--muted); }

#quickLogFab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  border-radius: 999px;
  padding: 14px 22px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 26px 30px;
  width: 560px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h3 { margin-top: 0; }
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-row > div { display: flex; flex-direction: column; }
.modal-actions { display: flex; gap: 8px; justify-content: space-between; margin-top: 8px; }
.modal-actions-right { display: flex; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 0.9em; color: var(--text); margin-bottom: 10px; }
.checkbox-label input { width: auto; margin: 0; }
.warning-box {
  background: #fef3c7; border: 1px solid #f59e0b; color: #92400e;
  border-radius: var(--radius); padding: 8px 10px; font-size: 0.82em;
  line-height: 1.5; margin: 4px 0 10px;
}
