:root {
  --green: #22c55e;
  --green-dark: #16a34a;
  --green-light: #dcfce7;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f4f6f8;
  --card: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn-bg: #fffbeb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.04);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.brand {
  font-weight: 800; font-size: 1.1rem; margin: 2px 8px 22px; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px; color: var(--ink);
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  display: flex; align-items: center; justify-content: center; font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
}
.hamburger {
  display: none; background: none; border: 1px solid var(--border); border-radius: 8px;
  font-size: 1.1rem; padding: 6px 10px; cursor: pointer; margin-bottom: 14px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.sidebar nav a {
  color: #334155;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.89rem;
  font-weight: 500;
  display: flex; align-items: center; gap: 9px;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s;
}
.sidebar nav a .nav-ic { font-size: 0.95rem; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar nav a:hover { background: #f8fafc; text-decoration: none; }
.sidebar nav a.active {
  background: var(--green-light); color: var(--green-dark); font-weight: 700;
  border-left-color: var(--green-dark);
}
.nav-divider { height: 1px; background: var(--border); margin: 10px 6px; }
.nav-section-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 14px 10px 4px; opacity: 0.8;
}
.nav-section-label:first-of-type { margin-top: 10px; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.me { display: flex; flex-direction: column; font-size: 0.82rem; line-height: 1.3; }
.me span { color: var(--muted); }

.content { flex: 1; padding: 28px 34px; max-width: 1240px; }

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; letter-spacing: -0.005em; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat .num { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }
.stat .label { color: var(--muted); font-size: 0.84rem; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--green); color: #fff; border: none;
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 0.9rem; font-weight: 600;
  cursor: pointer; text-decoration: none; box-shadow: 0 1px 2px rgba(22, 163, 74, 0.25);
  transition: background .12s, transform .05s, box-shadow .12s;
}
.btn:hover { background: var(--green-dark); text-decoration: none; box-shadow: 0 2px 6px rgba(22, 163, 74, 0.3); }
.btn:active { transform: translateY(1px); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: #f8fafc; box-shadow: var(--shadow-sm); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); box-shadow: none; }
.btn-ghost:hover { box-shadow: none; }
.btn-danger { background: var(--danger); box-shadow: 0 1px 2px rgba(220, 38, 38, 0.25); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 13px 26px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

form.inline { display: inline; }

label { display: block; font-size: 0.85rem; font-weight: 600; margin: 12px 0 5px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=color],
select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.92rem; font-family: inherit; background: #fff; color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}
textarea { resize: vertical; min-height: 110px; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fafafa; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: #f3f4f6; color: var(--ink);
}
.tag-chip {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 0.72rem;
  font-weight: 600; color: #fff; margin: 0 3px 3px 0;
}

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 0.88rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--green-dark); border: 1px solid #bbf7d0; }
.alert-warn { background: var(--warn-bg); color: #92400e; border: 1px solid #fde68a; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: end; }
.filters .field { display: flex; flex-direction: column; gap: 4px; }
.filters label { margin: 0; font-size: 0.75rem; }

.pagination { display: flex; gap: 6px; margin-top: 16px; align-items: center; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #dcfce7, transparent 55%),
              radial-gradient(circle at 80% 85%, #d1fae5, transparent 50%),
              var(--bg);
}
.login-card { background: #fff; padding: 36px; border-radius: 18px; box-shadow: var(--shadow), 0 20px 40px rgba(15,23,42,0.06); width: 350px; border: 1px solid var(--border); }
.login-card h1 { text-align: center; letter-spacing: -0.01em; }
.login-card .brand-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
  box-shadow: 0 6px 16px rgba(22, 163, 74, 0.3);
}

.runner { max-width: 640px; margin: 0 auto; }
.runner-progress { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; color: var(--muted); font-size: 0.85rem; }
.runner-progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 22px; }
.runner-progress-bar > div { height: 100%; background: var(--green); transition: width .2s; }
.contact-card { text-align: center; padding: 26px 20px; }
.contact-card .avatar {
  width: 62px; height: 62px; border-radius: 50%; background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 700;
  margin: 0 auto 12px;
}
.contact-card h2 { margin-bottom: 2px; }
.contact-card .phone { color: var(--muted); margin-bottom: 16px; }
.message-preview {
  background: #ecfdf5; border: 1px solid #bbf7d0; border-radius: 10px; padding: 16px;
  text-align: left; white-space: pre-wrap; font-size: 0.92rem; margin-bottom: 16px;
}
.attachment-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.attachment-row img { max-height: 130px; border-radius: 8px; border: 1px solid var(--border); }
.runner-actions { display: flex; flex-direction: column; gap: 10px; }
.runner-actions .row { display: flex; gap: 10px; }
.runner-actions .row .btn { flex: 1; }
.copy-feedback { font-size: 0.78rem; color: var(--green-dark); min-height: 16px; margin-top: 4px; }

.done-card { text-align: center; padding: 60px 20px; }
.done-card .big-check { font-size: 3rem; margin-bottom: 10px; }

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

.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.tag-toggle {
  --chip-color: #6b7280;
  border: 1.5px solid var(--chip-color);
  background: #fff; color: var(--chip-color);
  padding: 4px 12px; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
}
.tag-toggle.on { background: var(--chip-color); color: #fff; }
.tag-picker-add { display: flex; gap: 8px; margin-top: 4px; }
.tag-picker-add input { flex: 1; }

.emoji-picker { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: #fafafa; margin: 6px 0 4px; max-height: 140px; overflow-y: auto; }
.emoji-btn { border: none; background: transparent; font-size: 1.25rem; padding: 4px 6px; border-radius: 6px; cursor: pointer; line-height: 1; }
.emoji-btn:hover { background: #e5e7eb; }
.emoji-toggle-row { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 0; }

.pipeline-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.pipeline-col { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); width: 260px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 150px); }
.pipeline-col-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 0.9rem; }
.pipeline-col-body { padding: 10px; overflow-y: auto; flex: 1; min-height: 60px; }
.pipeline-col-body.drag-over { background: #f0fdf4; }
.pipeline-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  margin-bottom: 8px; cursor: grab; font-size: 0.85rem;
}
.pipeline-card.dragging { opacity: 0.4; }
.pipeline-card-name { display: block; font-weight: 600; margin-bottom: 2px; }
.pipeline-card-phone { color: var(--muted); font-size: 0.78rem; }
.pipeline-card-date { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }
.pipeline-card-move { width: 100%; margin-top: 8px; font-size: 0.75rem; padding: 4px 6px; }

/* --- WhatsApp: shell de dos paneles tipo WhatsApp Web --- */
.wa-shell {
  display: flex; height: calc(100vh - 56px); margin: -28px -34px; background: #fff;
  border-top: 1px solid var(--border);
}
.wa-list-pane {
  width: 340px; flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; background: #fff;
}
.wa-list-header { padding: 16px 16px 10px; }
.wa-list-header h1 { margin-bottom: 10px; }
.wa-search {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 20px;
  font-size: 0.88rem; background: var(--bg);
}
.wa-list { flex: 1; overflow-y: auto; }
.wa-item {
  width: 100%; display: flex; gap: 10px; align-items: center; text-align: left;
  padding: 10px 14px; border: none; background: none; border-bottom: 1px solid #f3f4f6; cursor: pointer;
}
.wa-item:hover { background: #f7f8fa; }
.wa-item.active { background: #ecfdf5; }
.wa-avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-size: 1rem;
}
.wa-item-body { min-width: 0; flex: 1; }
.wa-item-row { display: flex; justify-content: space-between; gap: 6px; }
.wa-item-name { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-item-time { color: var(--muted); font-size: 0.72rem; flex-shrink: 0; }
.wa-item-preview { color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.wa-thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #e9edf1; }
.wa-thread-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.wa-thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.wa-thread[hidden], .wa-thread-empty[hidden] { display: none; }
.wa-detail-pane[hidden] { display: none; }
.wa-thread-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: #fff;
  border-bottom: 1px solid var(--border);
}
.wa-back { display: none; background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }
.wa-thread-name { font-weight: 700; }
.wa-thread-phone { margin: 0; }
.wa-info-toggle {
  margin-left: auto; background: none; border: 1px solid var(--border); border-radius: 50%;
  width: 32px; height: 32px; cursor: pointer; font-size: 1rem; color: var(--muted);
}
.wa-info-toggle:hover { background: #f3f4f6; }

.wa-detail-pane {
  width: 280px; flex-shrink: 0; border-left: 1px solid var(--border); background: #fff;
  display: flex; flex-direction: column;
}
.wa-detail-header {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.wa-detail-close { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 0.95rem; }
.wa-detail-body { flex: 1; overflow-y: auto; padding: 18px 16px; }
.wa-detail-contact { text-align: center; padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.wa-avatar-lg { width: 56px; height: 56px; font-size: 1.3rem; margin: 0 auto 8px; }
.wa-detail-name { font-weight: 700; }
.wa-detail-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-size: 0.88rem; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.wa-detail-section { margin-bottom: 18px; }
.wa-detail-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 8px; }

.wa-switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.wa-switch input { opacity: 0; width: 0; height: 0; }
.wa-switch-track {
  position: absolute; inset: 0; background: #d1d5db; border-radius: 999px; cursor: pointer; transition: background .15s;
}
.wa-switch-track::before {
  content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s;
}
.wa-switch input:checked + .wa-switch-track { background: var(--green); }
.wa-switch input:checked + .wa-switch-track::before { transform: translateX(16px); }

.wa-status-opt { display: flex; align-items: center; gap: 8px; padding: 6px 2px; font-size: 0.88rem; cursor: pointer; }
.wa-status-opt input { width: auto; margin: 0; }

.wa-note { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-top: 8px; }
.wa-note-text { font-size: 0.85rem; white-space: pre-wrap; }
.wa-note-meta { color: var(--muted); font-size: 0.7rem; margin-top: 4px; }
.wa-orders { background: #fffbeb; border-bottom: 1px solid #fde68a; padding: 8px 18px; font-size: 0.82rem; }
.wa-order { padding: 2px 0; }

.wa-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.wa-bubble { max-width: 68%; padding: 7px 10px; border-radius: 9px; font-size: 0.9rem; box-shadow: 0 1px 1px rgba(0,0,0,0.06); }
.wa-bubble-in { align-self: flex-start; background: #fff; border-top-left-radius: 2px; }
.wa-bubble-out { align-self: flex-end; background: #dcf8c6; border-top-right-radius: 2px; }
.wa-bubble-text { white-space: pre-wrap; word-break: break-word; }
.wa-bubble-meta { color: var(--muted); font-size: 0.68rem; margin-top: 3px; text-align: right; }

.wa-compose { display: flex; gap: 10px; padding: 12px 18px; background: #fff; border-top: 1px solid var(--border); align-items: flex-end; }
.wa-compose textarea { flex: 1; min-height: 40px; max-height: 120px; resize: none; border-radius: 20px; padding: 9px 14px; }
.wa-compose .btn { border-radius: 20px; }

@media (max-width: 860px) {
  .wa-shell { margin: -16px; height: calc(100vh - 56px); }
  .wa-list-pane { width: 100%; }
  .wa-thread-pane { display: none; }
  .wa-shell.thread-open .wa-list-pane { display: none; }
  .wa-shell.thread-open .wa-thread-pane { display: flex; }
  .wa-back { display: inline-block; }
  /* El panel de detalles tapa toda la pantalla en celular en vez de ir al
     lado, porque ahí no hay espacio para un tercer panel fijo. */
  .wa-detail-pane:not([hidden]) {
    position: fixed; inset: 0; z-index: 30; width: 100%;
  }
}

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    padding: 12px 14px; box-shadow: 0 1px 0 var(--border);
  }
  .sidebar-top { margin-bottom: 0; }
  .brand { margin: 0; }
  .hamburger { display: block; margin-bottom: 0; }
  /* Colapsado por defecto: solo se ve la barra con la marca + el botón.
     Al tocar el botón, JS agrega .open y esto se despliega como un menú
     desplegable encima del contenido, sin empujarlo hacia abajo. */
  .sidebar nav, .sidebar-footer { display: none; }
  .sidebar.open nav, .sidebar.open .sidebar-footer {
    display: flex; flex-direction: column;
  }
  .sidebar.open nav { margin-top: 10px; }
  .sidebar.open .sidebar-footer { margin-top: 10px; }
  .sidebar nav a { padding: 12px 10px; font-size: 1rem; }
  .content { padding: 16px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .actions { flex-wrap: wrap; }
  .page-header .actions .btn { flex: 1; min-width: 120px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .field { width: 100%; }
  table { font-size: 0.82rem; }
  th, td { padding: 8px 6px; }

  /* Objetivos táctiles más grandes (mínimo ~44px) para botones pequeños
     que en escritorio funcionan bien con mouse pero son difíciles de
     tocar con el dedo con precisión. */
  .emoji-btn { min-width: 44px; min-height: 44px; font-size: 1.4rem; }
  .tag-toggle { padding: 8px 14px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  .btn-sm { padding: 8px 12px; min-height: 38px; }
  .pipeline-card-move { min-height: 40px; }
  select, input[type=date] { min-height: 44px; }
}
