:root {
  --bg: #080c18;          /* negro azulado */
  --bg-2: #0d1426;        /* azul marino muy oscuro */
  --panel: #131c33;       /* tarjetas, más claro que el fondo */
  --panel-2: #1b2746;     /* hover / inputs */
  --border: #2a3a60;      /* bordes discretos pero visibles */
  --text: #eef3fe;        /* texto principal casi blanco */
  --muted: #a9b7d6;       /* texto secundario gris claro legible */
  --accent: #3b82f6;      /* azul eléctrico */
  --accent-2: #22d3ee;    /* cian */
  --accent-strong: #2563eb;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 12px;
  --tap: 42px;            /* área táctil mínima */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #10213f 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

#app { display: flex; min-height: 100vh; }

/* ------------------------- Topbar móvil ------------------------- */
.topbar {
  display: none;
  align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--bg-2);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 60;
}
.topbar img { height: 30px; width: auto; }
.hamburger {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  width: var(--tap); height: var(--tap); border-radius: 10px; font-size: 20px; cursor: pointer;
  display: grid; place-items: center;
}

/* ------------------------- Sidebar ------------------------- */
.sidebar {
  width: 248px; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand img { height: 46px; width: auto; max-width: 100%; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  color: var(--muted); padding: 11px 13px; border-radius: 10px;
  font-weight: 600; display: flex; align-items: center; gap: 8px; min-height: var(--tap);
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: linear-gradient(90deg, var(--accent-strong), var(--accent)); color: #fff; }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); }
.sidebar-backdrop { display: none; }

/* ------------------------- Content ------------------------- */
.content { flex: 1; padding: 30px 34px; max-width: 1280px; width: 100%; }
h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -0.3px; }
h2 { font-size: 17px; margin: 0 0 14px; }
h3 { font-size: 14.5px; margin: 16px 0 8px; color: var(--text); }
.page-sub { color: var(--muted); margin: 0 0 22px; }

/* Cards / panels */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.grid { display: grid; gap: 16px; }
.grid > *, .ficha-grid > * { min-width: 0; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.stat .num { font-size: 32px; font-weight: 800; letter-spacing: -0.5px; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 11px 12px; font-size: 15px;
  font-family: inherit; min-height: var(--tap);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
.field { margin-bottom: 15px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }

button, .btn {
  background: linear-gradient(90deg, var(--accent-strong), var(--accent)); color: #fff; border: none;
  border-radius: 10px; padding: 11px 18px; font-size: 14.5px; font-weight: 700; cursor: pointer;
  font-family: inherit; min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--panel-2); filter: none; }
.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }
.btn-danger { background: linear-gradient(90deg, #b91c1c, #ef4444); }

/* Table */
.table-wrap { overflow-x: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--muted); font-weight: 700; cursor: pointer; user-select: none; white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); cursor: pointer; }

/* ------------------------- Badges / estados ------------------------- */
.badge {
  display: inline-block; padding: 5px 11px; border-radius: 999px; font-size: 12px;
  font-weight: 600; white-space: nowrap; color: #fff; border: 1px solid transparent;
}
.badge-muted { background: #334155; color: #e2e8f0; }
.badge-wrap { white-space: normal; max-width: 100%; }
.badge-green { background: #15803d; }
.badge-amber { background: #b45309; }
.badge-red { background: #b91c1c; }
.badge-blue { background: #1d4ed8; }
.badge-cyan { background: #0e7490; }

/* Estados comerciales: texto blanco siempre + color de fondo de alto contraste */
.st { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; border: 1px solid rgba(255,255,255,.12); }
.st-nuevo { background: #0e7490; }                 /* cian oscuro */
.st-revisar { background: #7c5e10; }               /* ámbar oscuro */
.st-aprobado { background: #15803d; }              /* verde oscuro */
.st-contactado { background: #6d28d9; }            /* violeta oscuro */
.st-respondio { background: #1d4ed8; }
.st-interesado { background: #0f766e; }
.st-presupuesto_enviado { background: #1e40af; }
.st-cerrado { background: #334155; }
.st-no_interesado { background: #9f1239; }         /* bordó */
.st-descartado { background: #991b1b; }            /* rojo oscuro */

/* Etiquetas de canal de contacto: texto completo, alto contraste, no solo color */
.ch-badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; line-height: 1.3; white-space: nowrap; border: 1px solid rgba(255,255,255,.14); }
.ch-whatsapp { background: #0b6b3a; }   /* verde oscuro */
.ch-instagram { background: #6b21a8; }  /* violeta oscuro */
.ch-llamada { background: #1e40af; }    /* azul oscuro */

/* Historial de contacto */
.contact-history .contact-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.contact-history .ch-act { flex: 1 1 auto; min-height: 44px; color: #fff; border: 1px solid rgba(255,255,255,.14); }
.contact-history .ch-act.ch-whatsapp { background: #0b6b3a; }
.contact-history .ch-act.ch-instagram { background: #6b21a8; }
.contact-history .ch-act.ch-llamada { background: #1e40af; }
.contact-history .ch-act:disabled { opacity: .55; cursor: not-allowed; }
.ch-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 10px; }
.ch-live { min-height: 1.2em; margin: 10px 0 0; font-size: 13px; color: #6ee7b7; font-weight: 600; }
.ch-live:empty { display: none; }
.ch-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.ch-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 10px; background: var(--bg-2); border-radius: 8px; }
.ch-row-main { flex: 1 1 160px; min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.ch-void { flex: 0 0 auto; }

/* Métricas de contacto en el dashboard */
.contact-metrics { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.cm-chip { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 44px; background: var(--bg-2); border-radius: 10px; text-decoration: none; color: inherit; border: 1px solid rgba(255,255,255,.08); }
.cm-chip:hover { border-color: var(--accent); }
.cm-num { font-weight: 800; font-size: 18px; }
.cm-lbl { font-size: 13px; }

.score-pill { display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; font-weight: 800; font-size: 15px; border: 2px solid transparent; }
.score-alta { background: rgba(52,211,153,.16); color: #6ee7b7; border-color: rgba(52,211,153,.4); }
.score-bueno { background: rgba(59,130,246,.18); color: #93c5fd; border-color: rgba(59,130,246,.45); }
.score-revision { background: rgba(251,191,36,.16); color: #fcd34d; border-color: rgba(251,191,36,.4); }
.score-descartar { background: rgba(248,113,113,.16); color: #fca5a5; border-color: rgba(248,113,113,.4); }

/* Toolbar / filtros */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.toolbar .field { margin: 0; }

/* Toast / aria-live */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 80;
  background: var(--panel); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); padding: 14px 18px; border-radius: 10px;
  max-width: 360px; box-shadow: 0 12px 34px rgba(0,0,0,.5); font-weight: 600;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }

/* Ficha */
.ficha-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.kv dd a, .contact-row a, .contact-main { word-break: break-word; overflow-wrap: anywhere; }
.reason { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); gap: 12px; }
.reason .pts-pos { color: #6ee7b7; font-weight: 800; }
.reason .pts-neg { color: #fca5a5; font-weight: 800; }
.muted { color: var(--muted); }
.chip { display:inline-block; background: var(--panel-2); border:1px solid var(--border); border-radius: 999px; padding: 5px 11px; margin: 2px; font-size: 12.5px; }
.spacer { height: 16px; }
.inline { display:flex; gap:8px; align-items:center; flex-wrap: wrap; }
.back-link { display:inline-block; margin-bottom: 12px; font-weight: 600; }
.empty { text-align:center; color: var(--muted); padding: 44px; }
.loading { color: var(--muted); padding: 20px; }

/* Datos de contacto con acciones */
.contact-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.contact-main { font-weight: 700; font-size: 16px; }
.contact-sub { color: var(--muted); font-size: 12.5px; }
.pill-note { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.pill-wa { background: rgba(52,211,153,.15); color: #6ee7b7; border: 1px solid rgba(52,211,153,.4); }
.pill-nowa { background: rgba(169,183,214,.12); color: var(--muted); border: 1px solid var(--border); }
.pill-pend { background: rgba(251,191,36,.15); color: #fcd34d; border: 1px solid rgba(251,191,36,.4); }

/* Mensaje personalizado a ancho completo */
.message-card textarea {
  width: 100%; min-height: 150px; max-height: 420px; line-height: 1.6; font-size: 15px;
  white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden;
}

.warn-box {
  margin-top: 10px; padding: 9px 13px; border-radius: 10px;
  background: rgba(251,191,36,.1); border: 1px solid rgba(251,191,36,.4);
  color: #fcd34d; font-size: 13px; font-weight: 700;
}

/* Login */
.login-wrap { min-height: 100vh; width: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-logo { display: block; margin: 0 auto 18px; max-width: 230px; width: 80%; height: auto; }
#user-box { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 8px; }

/* ------------------------- Responsive ------------------------- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .ficha-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #app { display: block; }
  .topbar { display: flex; }
  .content { padding: 18px 16px; max-width: 100%; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; width: 260px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 45;
  }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .toast { left: 12px; right: 12px; max-width: none; }
}
