/* ============================================================
   Serranía Sales OS · Design system
   Paleta: teal petróleo + terracota + ink profundo
   ============================================================ */
:root {
  --teal: #2AA79F;
  --teal-dark: #1D7C77;
  --teal-2: #6BC5BE;
  --teal-tint: #E6F4F3;
  --terracota: #C25A2C;
  --terracota-dark: #8F3D1A;
  --terracota-tint: #F7E5DA;
  --ink: #0A0F0E;
  --ink-2: #1A2020;
  --ink-3: #3A4442;
  --text: #2A2E2C;
  --text-2: #6A6E6C;
  --text-3: #9BA09E;
  --bg: #F5F4F0;
  --bg-2: #EDEBE4;
  --card: #FFFFFF;
  --line: #E2DED4;
  --line-2: #D0CBC0;
  --danger: #EF4444;
  --success: #10B981;
  --warning: #F59E0B;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(10,15,14,0.05);
  --shadow: 0 4px 12px rgba(10,15,14,0.08);
  --shadow-lg: 0 20px 40px -12px rgba(10,15,14,0.15);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal-dark); text-decoration: none; }
a:hover { color: var(--terracota); }
h1, h2, h3, h4 { margin: 0 0 12px; color: var(--ink); font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

/* ============ TOPBAR ============ */
.topbar {
  background: var(--ink);
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0; z-index: 100;
  border-bottom: 3px solid var(--teal);
}
.brand-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 15px;
  letter-spacing: 0.02em;
  color: white;
}
.brand-logo .mark {
  width: 26px; height: 26px;
  background: var(--terracota);
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-size: 14px;
}
.brand-logo .brand-txt em { color: var(--teal-2); font-style: normal; }
.topbar nav {
  display: flex; gap: 4px;
  flex: 1;
}
.topbar nav a {
  color: rgba(255,255,255,0.7);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.topbar nav a:hover { color: white; background: rgba(255,255,255,0.06); }
.topbar nav a.active { color: white; background: var(--teal); }
.topbar-user {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px;
}
.topbar-user .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--terracota);
  color: white; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
}
.topbar-user .role-pill {
  padding: 2px 8px; border-radius: 999px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--teal); color: white; font-weight: 700;
}
.topbar-user .role-pill.role-comercial { background: var(--terracota); }
.topbar-user .logout {
  background: transparent; border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8); padding: 6px 12px; border-radius: 6px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.topbar-user .logout:hover { background: rgba(255,255,255,0.08); color: white; }

/* ============ LAYOUT ============ */
.wrap { max-width: 1400px; margin: 0 auto; padding: 24px; }
.wrap-narrow { max-width: 780px; margin: 0 auto; padding: 24px; }

/* ============ STAT BAR ============ */
.stat-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: ""; position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--teal);
}
.stat.accent-terra::before { background: var(--terracota); }
.stat.accent-ink::before { background: var(--ink); }
.stat .n {
  font-size: 26px; font-weight: 800; color: var(--ink);
  line-height: 1; margin-bottom: 4px;
  letter-spacing: -0.02em;
}
.stat .l {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-2); font-weight: 600;
}

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar h1 { margin: 0; }
.toolbar-spacer { flex: 1; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.2;
}
.btn-primary { background: var(--teal); color: white; }
.btn-primary:hover { background: var(--teal-dark); color: white; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-terra { background: var(--terracota); color: white; }
.btn-terra:hover { background: var(--terracota-dark); color: white; transform: translateY(-1px); }
.btn-ghost {
  background: transparent; color: var(--text);
  border-color: var(--line-2);
}
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ============ KANBAN ============ */
.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
  scroll-snap-type: x proximity;
}
.kanban-col {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 240px;
  max-height: calc(100vh - 260px);
  display: flex; flex-direction: column;
  scroll-snap-align: start;
}
.kanban-col-body {
  overflow-y: auto;
  flex: 1;
  min-height: 100px;
  padding-right: 4px;
}
/* Columna histórico visualmente distinta (fondo más apagado) */
.kanban-col[data-stage-code="historico"] {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border: 1px dashed var(--line-2);
}
.kanban-col[data-stage-code="historico"] .lead-card {
  opacity: 0.85;
}
.kanban-col.is-drop-over { background: var(--teal-tint); box-shadow: inset 0 0 0 2px var(--teal); }
.kanban-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 10px;
  margin-bottom: 10px;
  border-bottom: 2px solid var(--line);
}
.kanban-col-head .label {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.kanban-col-head .label .dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.kanban-col-head .count {
  background: var(--card); border-radius: 999px;
  padding: 2px 10px; font-size: 11px; font-weight: 700;
  color: var(--text-2);
}

.lead-card {
  background: var(--card);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  cursor: grab;
  transition: all 0.15s;
  position: relative;
  display: block;
  color: var(--text);
}
.lead-card:hover {
  border-color: var(--teal);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.lead-card.is-dragging { opacity: 0.5; cursor: grabbing; }
.lead-card .name {
  font-weight: 700; font-size: 14px; color: var(--ink); margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lead-card .meta {
  font-size: 12px; color: var(--text-2);
  display: flex; flex-wrap: wrap; gap: 6px 10px;
}
.lead-card .meta .fresh { color: var(--terracota); font-weight: 600; }
.lead-card .interest {
  margin-top: 6px; font-size: 12px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lead-card .tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 600; margin-right: 4px;
  background: var(--teal-tint); color: var(--teal-dark);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.lead-card .tag.src { background: var(--terracota-tint); color: var(--terracota-dark); }
.lead-card .assigned-badge {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--terracota); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
}
.lead-card.unassigned { border-left: 3px solid var(--terracota); }

/* ============ FORMS ============ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.form-row { display: grid; gap: 6px; margin-bottom: 14px; }
.form-row.two { grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-row.two { grid-template-columns: 1fr; } }
label {
  font-size: 12px; font-weight: 600; color: var(--ink);
  text-transform: uppercase; letter-spacing: 0.04em;
}
input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=number], input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--line-2);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: var(--card);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-tint);
}
textarea { min-height: 90px; resize: vertical; font-family: inherit; }
.error-msg {
  background: #FEE2E2; color: #991B1B;
  padding: 10px 14px; border-radius: 8px; border: 1px solid #FCA5A5;
  margin-bottom: 14px; font-size: 13.5px;
}
.info-msg {
  background: var(--teal-tint); color: var(--teal-dark);
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--teal-2);
  margin-bottom: 14px; font-size: 13.5px;
}

/* ============ LOGIN ============ */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--ink) 0%, var(--ink-2) 100%);
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand-logo {
  color: var(--ink);
  font-size: 18px;
  margin-bottom: 8px;
}
.login-card .brand-logo .brand-txt em { color: var(--teal); font-style: normal; }
.login-card .sub {
  color: var(--text-2); font-size: 13px; margin-bottom: 28px;
}
.login-card .btn { width: 100%; justify-content: center; padding: 12px; margin-top: 8px; }

/* ============ LEAD DETAIL ============ */
.lead-header {
  background: linear-gradient(135deg, var(--ink) 0%, var(--ink-2) 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.lead-header::after {
  content: ""; position: absolute; top: -50%; right: -20%;
  width: 400px; height: 400px; border-radius: 50%;
  background: radial-gradient(circle, var(--teal) 0%, transparent 60%);
  opacity: 0.15; pointer-events: none;
}
.lead-header > * { position: relative; z-index: 2; }
.lead-header .crumb { font-size: 12px; opacity: 0.6; margin-bottom: 8px; }
.lead-header h1 { color: white; margin-bottom: 6px; font-size: 30px; }
.lead-header .contact {
  font-size: 14px; color: rgba(255,255,255,0.85);
  display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px;
}
.lead-header .contact a { color: var(--teal-2); }
.lead-header .stage-pill {
  display: inline-block; padding: 6px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.2);
  margin-top: 12px;
}

.two-col {
  display: grid; grid-template-columns: 1fr 380px; gap: 20px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.section-head {
  font-size: 11px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: 12px 14px 12px 40px;
  border-left: 2px solid var(--line);
  margin-left: 12px;
  position: relative;
  font-size: 13.5px;
}
.timeline li::before {
  content: ""; position: absolute;
  left: -7px; top: 16px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--teal);
}
.timeline li.type-cambio_estado::before { border-color: var(--terracota); }
.timeline li.type-visita::before { border-color: var(--warning); }
.timeline li .meta {
  font-size: 11px; color: var(--text-3); text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 600; margin-bottom: 2px;
}
.timeline li .msg { color: var(--text); }

/* Info panel */
.info-panel .row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.info-panel .row:last-child { border: none; }
.info-panel .row .k { color: var(--text-2); }
.info-panel .row .v { color: var(--ink); font-weight: 600; text-align: right; word-break: break-word; }

.stage-selector {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px;
}
.stage-selector button {
  padding: 8px; font-size: 12px; font-weight: 600;
  border: 1.5px solid var(--line-2); border-radius: 6px;
  background: var(--card); color: var(--text); cursor: pointer;
  font-family: inherit; transition: all 0.15s;
}
.stage-selector button:hover { border-color: var(--teal); }
.stage-selector button.active {
  background: var(--ink); color: white; border-color: var(--ink);
}

.wa-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #25D366; color: white; padding: 12px; border-radius: 8px;
  font-weight: 700; text-decoration: none; margin-top: 8px; font-size: 14px;
}
.wa-btn:hover { background: #1FBA5A; color: white; }

/* Tabla admin */
.table {
  width: 100%; border-collapse: collapse;
  background: var(--card); border-radius: var(--radius); overflow: hidden;
}
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.table th { background: var(--bg-2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-ok { background: #DCFCE7; color: #166534; }
.badge-off { background: #FEE2E2; color: #991B1B; }
.badge-admin { background: var(--terracota-tint); color: var(--terracota-dark); }
.badge-comercial { background: var(--teal-tint); color: var(--teal-dark); }

.chart-bar { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.chart-bar .lbl { width: 140px; }
.chart-bar .bar {
  flex: 1; height: 20px; background: var(--bg-2); border-radius: 4px; overflow: hidden;
}
.chart-bar .bar .fill { height: 100%; background: var(--teal); }
.chart-bar .n { font-weight: 700; color: var(--ink); width: 40px; text-align: right; }

/* Empty state */
.empty {
  text-align: center; padding: 60px 24px; color: var(--text-2);
}
.empty h3 { color: var(--text); margin-bottom: 8px; }

/* ============ INBOX / BADGES ============ */
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: var(--terracota); color: white;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  margin-left: 6px;
  box-shadow: 0 0 0 2px var(--ink);
}
.inbox-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; background: var(--terracota);
  box-shadow: 0 0 0 3px var(--terracota-tint);
}

/* Lead card: distintivo cuando aún no fue abierto */
.lead-card.unseen {
  border-left: 3px solid var(--terracota);
  background: linear-gradient(90deg, var(--terracota-tint) 0%, var(--card) 40%);
}
.lead-card.unseen .name::before {
  content: "●";
  color: var(--terracota);
  margin-right: 6px;
  font-size: 10px;
  vertical-align: middle;
}

/* Error page */
.err-page {
  min-height: 60vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 40px 24px;
}
.err-page .code { font-size: 80px; font-weight: 800; color: var(--terracota); line-height: 1; }
