/* Ortodoncia San Cugat · CRM
   Dirección: herramienta clínica calmada. Riel-embudo oscuro como columna vertebral,
   #8D9CA2 como firma, estados en dropdowns tintados.
   Tipos: Space Grotesk (display/datos numéricos) + Inter (cuerpo). */

:root {
  --ink: #1B2427;
  --ink-soft: #5E6B70;
  --canvas: #EEEFF1;
  --surface: #FFFFFF;
  --line: #E4E6E7;
  --line-soft: #EDEEF0;
  --brand: #8D9CA2;
  --brand-deep: #5C6C73;
  --rail: #EFF4F6;
  --rail-2: #E0EAEE;
  --rail-line: #D8E3E7;
  --rail-text: #1B2427;
  --rail-muted: #6C7C83;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 30px rgba(20,28,32,.08);
  --shadow-sm: 0 1px 2px rgba(20,28,32,.05), 0 4px 14px rgba(20,28,32,.04);
  --font-display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;

  /* tintes de estado */
  --st-nuevo-bg:#ECEFF0;          --st-nuevo-fg:#465056;
  --st-contactado-bg:#E7EEF4;     --st-contactado-fg:#3A546E;
  --st-no_contesta-bg:#F6EFDD;    --st-no_contesta-fg:#7F6016;
  --st-cita_agendada-bg:#E2F0EF;  --st-cita_agendada-fg:#2F5E5E;
  --st-primera_visita-bg:#E6F1E8; --st-primera_visita-fg:#33623F;
  --st-perdido-bg:#F4E7E7;        --st-perdido-fg:#7C3E3E;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--canvas); color: var(--ink);
  font-family: var(--font-body); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--ink-soft); }
.small { font-size: 12px; }
::selection { background: #D5DCDE; }

/* ============ Estructura app ============ */
.app { display: flex; min-height: 100vh; }

/* ---- Riel lateral (embudo = navegación) ---- */
.rail {
  width: 240px; flex: none; background: var(--rail); color: var(--rail-text);
  border-right: 1px solid var(--rail-line);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 22px 16px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 4px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(150deg, var(--brand), #6E8087);
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; inset: 8px 8px auto 8px; height: 6px;
  border-radius: 6px 6px 2px 2px; background: rgba(255,255,255,.85);
  box-shadow: 0 7px 0 -2px rgba(255,255,255,.45);
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; line-height: 1.12; letter-spacing: -.01em; }

.rail-nav { display: flex; flex-direction: column; gap: 1px; margin: 22px 0 6px; }
.rail-link {
  font-size: 13.5px; color: var(--rail-muted); padding: 9px 12px; border-radius: 9px;
  display: flex; align-items: center; gap: 9px;
}
.rail-link:hover { color: var(--rail-text); background: var(--rail-2); }
.rail-link.on { color: var(--rail-text); background: var(--rail-2); font-weight: 500; }
.rail-spacer { flex: 1; }

.rail-label {
  font-family: var(--font-display); font-size: 10.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--rail-muted);
  padding: 0 12px; margin: 16px 0 8px;
}
.rail-funnel { position: relative; padding-left: 4px; flex: 1; overflow-y: auto; }
/* la "tubería" que conecta las etapas */
.rail-funnel .pipe {
  position: absolute; left: 17px; top: 30px; bottom: 18px; width: 2px;
  background: var(--rail-line); border-radius: 2px;
}
.funnel-row {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; border-radius: 9px; color: var(--rail-muted); font-size: 13px;
}
.funnel-row:hover { background: var(--rail-2); color: var(--rail-text); }
.funnel-row.on { background: var(--rail-2); color: var(--rail-text); font-weight: 500; }
.fdot {
  width: 9px; height: 9px; border-radius: 50%; flex: none; z-index: 1;
  box-shadow: 0 0 0 3px var(--rail);
}
.funnel-row.on .fdot { box-shadow: 0 0 0 3px var(--rail-2); }
.funnel-row .fname { flex: 1; min-width: 0; }
.funnel-n { font-family: var(--font-display); font-weight: 600; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--rail-text); }
.funnel-row.dim .funnel-n { color: var(--rail-muted); }
.funnel-all { margin-bottom: 2px; }
.funnel-all .fdot { background: transparent; box-shadow: inset 0 0 0 2px var(--rail-muted); }

.rail-foot { border-top: 1px solid var(--rail-line); padding-top: 12px; margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.rail-user { font-size: 13px; flex: 1; }
.rail-salir { font-size: 12.5px; color: var(--rail-muted); padding: 6px 11px; border-radius: 8px; }
.rail-salir:hover { color: var(--rail-text); background: var(--rail-2); }

/* ---- Main ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-top {
  position: sticky; top: 0; z-index: 20; background: rgba(238,239,241,.86);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 16px 26px;
}
.page-title { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: -.01em; }
.page-title .count { color: var(--ink-soft); font-weight: 500; font-size: 15px; margin-left: 8px; }
.main-top .search { flex: 1; max-width: 420px; }
.main-body { padding: 22px 26px 70px; flex: 1; }

.flash {
  margin: 14px 26px -4px; padding: 10px 16px; background: #E9F0ED;
  border: 1px solid #D6E4DE; color: #355044; border-radius: var(--radius-sm); font-size: 13px;
}

/* ---- Search + toggle ---- */
.search {
  padding: 10px 16px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; font: inherit; font-size: 14px; width: 100%;
}
.search:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(141,156,162,.18); }
.viewtoggle { display: inline-flex; background: #E2E4E6; border-radius: 999px; padding: 3px; margin-left: auto; flex: none; }
.viewtoggle a { padding: 7px 16px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.viewtoggle a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ============ Estado: dropdown tintado ============ */
.status-select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  font: 500 12.5px var(--font-body);
  padding: 6px 30px 6px 13px; border-radius: 999px; border: 1px solid transparent;
  background-repeat: no-repeat; background-position: right 11px center; background-size: 9px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236B7780' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.status-select:focus { outline: none; box-shadow: 0 0 0 3px rgba(141,156,162,.22); }
.st-nuevo { background-color: var(--st-nuevo-bg); color: var(--st-nuevo-fg); }
.st-contactado { background-color: var(--st-contactado-bg); color: var(--st-contactado-fg); }
.st-no_contesta { background-color: var(--st-no_contesta-bg); color: var(--st-no_contesta-fg); }
.st-cita_agendada { background-color: var(--st-cita_agendada-bg); color: var(--st-cita_agendada-fg); }
.st-primera_visita { background-color: var(--st-primera_visita-bg); color: var(--st-primera_visita-fg); }
.st-perdido { background-color: var(--st-perdido-bg); color: var(--st-perdido-fg); }

/* ============ Tabla ============ */
.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow-x: auto; }
.leads-table { width: 100%; border-collapse: collapse; }
.leads-table.fixed { table-layout: fixed; }
.leads-table.fixed td, .leads-table.fixed th { overflow: hidden; text-overflow: ellipsis; }
.leads-table thead th {
  position: relative;
  text-align: left; font-family: var(--font-display); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft);
  white-space: nowrap; padding: 14px 16px; border-bottom: 1px solid var(--line);
}
/* tirador para redimensionar columnas */
.col-resizer { position: absolute; top: 0; right: -1px; width: 10px; height: 100%; cursor: col-resize; z-index: 2; }
.col-resizer::after {
  content: ''; position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 2px; height: 15px; border-radius: 2px; background: transparent; transition: background .12s;
}
.leads-table thead th:hover .col-resizer::after { background: var(--line); }
.col-resizer:hover::after, body.col-resizing .col-resizer.active::after { background: var(--brand); }
body.col-resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }
.leads-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; white-space: nowrap; }
.leads-table tbody tr:last-child td { border-bottom: none; }
.leads-table tbody tr { cursor: pointer; transition: background .08s; }
.leads-table tbody tr:hover { background: #F7F8F8; }
.t-name { font-weight: 600; }
.t-mono { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 13.5px; }
.t-muted { color: var(--ink-soft); }
.col-campaign, .col-besttime { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.cell-note { color: var(--ink-soft); max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.t-actions { text-align: right; }
.t-actions a { margin-left: 6px; }
.count-note { margin: 14px 4px 0; }

.qa {
  display: inline-flex; align-items: center; justify-content: center; width: 33px; height: 33px;
  border-radius: 50%; background: #EEF0F1; color: var(--ink);
}
.qa svg { width: 15px; height: 15px; }
.qa:hover { background: #E4E7E8; }
.qa-wa { background: #E5F1E9; color: #2F6B45; }
.qa-wa:hover { background: #D9EBDF; }

.empty {
  background: var(--surface); border-radius: var(--radius); padding: 48px; text-align: center;
  box-shadow: var(--shadow-sm); color: var(--ink-soft);
}
.empty p { margin: 4px 0; }

/* ============ Kanban ============ */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.kcol { flex: 0 0 274px; background: #E7E9EB; border-radius: var(--radius); padding: 10px; }
.kcol-head { display: flex; align-items: center; gap: 9px; padding: 6px 8px 12px; font-size: 12.5px; font-weight: 600; }
.kcol-head .fname { font-family: var(--font-display); }
.kcol-count { margin-left: auto; color: var(--ink-soft); font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.kcol-body { min-height: 30px; }
.kcol.drop-hover { outline: 2px dashed var(--brand); outline-offset: -4px; }
.kcard { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-sm); padding: 12px 13px; margin-bottom: 10px; cursor: pointer; }
.kcard:last-child { margin-bottom: 0; }
.kcard.dragging { opacity: .4; }
.kcard-name { font-weight: 600; font-size: 14px; }
.kcard-sub { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.kcard-note { font-size: 12px; color: var(--ink-soft); margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard-actions { display: flex; gap: 6px; margin-top: 10px; }
.kcard-actions .qa { width: 30px; height: 30px; }

/* ============ Drawer / panel ============ */
/* Backdrop transparente: solo captura el click-fuera para cerrar, sin oscurecer la página. */
#backdrop { position: fixed; inset: 0; background: transparent; visibility: hidden; z-index: 60; }
#backdrop.open { visibility: visible; }
#drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw;
  background: var(--surface); box-shadow: -16px 0 50px rgba(20,28,32,.16);
  transform: translateX(100%); transition: transform .22s cubic-bezier(.4,0,.2,1); z-index: 70;
  display: flex; flex-direction: column;
}
#drawer.open { transform: translateX(0); }
.panel-body { padding: 26px 26px 40px; overflow-y: auto; }
.panel-close { position: absolute; top: 16px; right: 16px; width: 34px; height: 34px; border-radius: 50%; border: none; background: #EEF0F1; color: var(--ink); font-size: 16px; cursor: pointer; }
.panel-close:hover { background: #E4E7E8; }
.panel-name { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -.01em; padding-right: 44px; }
.panel-sub { color: var(--ink-soft); font-size: 12.5px; margin: 5px 0 0; }
.panel-actions { display: flex; gap: 9px; margin: 18px 0 4px; flex-wrap: wrap; }
.besttime-box { display: flex; flex-direction: column; gap: 2px; background: #EAEFF0; border-radius: var(--radius-sm); padding: 11px 14px; margin: 16px 0; }
.besttime-box strong { font-size: 14.5px; }
.panel-info { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin: 16px 0; }
.panel-info div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.panel-info dt { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.panel-info dd { margin: 0; font-size: 13.5px; overflow-wrap: anywhere; }
.panel-sec-label { font-family: var(--font-display); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); margin: 22px 0 9px; }
.panel-status .status-select { font-size: 14px; padding: 9px 34px 9px 16px; background-size: 10px; }

/* Seguimiento */
.seg-form input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; background: var(--surface);
}
.seg-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(141,156,162,.18); }
.panel-log { list-style: none; margin: 14px 0 0; padding: 0; }
.panel-log li { padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: 13.5px; display: flex; align-items: flex-start; gap: 12px; }
.panel-log li:first-child { border-top: none; }
.log-date { color: var(--ink-soft); font-family: var(--font-display); font-size: 11.5px; white-space: nowrap; flex: none; width: 78px; padding-top: 1px; font-variant-numeric: tabular-nums; }
.log-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.log-estado { color: var(--brand-deep); font-weight: 500; }
.panel-log .empty-log { color: var(--ink-soft); padding: 8px 0; }
/* editar / borrar nota */
.log-actions { display: flex; gap: 2px; margin-left: 6px; flex: none; opacity: 0; transition: opacity .12s; }
.panel-log li:hover .log-actions, .panel-log li.confirming .log-actions { opacity: 1; }
.log-actions button { width: 25px; height: 25px; border: none; background: transparent; color: var(--ink-soft); border-radius: 7px; cursor: pointer; display: grid; place-items: center; }
.log-actions button:hover { background: #EEF0F1; color: var(--ink); }
.log-actions button svg { width: 13px; height: 13px; }
.log-edit-input { flex: 1; font: inherit; font-size: 13.5px; padding: 4px 9px; border: 1px solid var(--brand); border-radius: 7px; background: var(--surface); }
.log-edit-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(141,156,162,.18); }
.log-yes, .log-no { font: inherit; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 7px; border: none; cursor: pointer; white-space: nowrap; }
.log-yes { background: var(--st-perdido-bg); color: var(--st-perdido-fg); }
.log-no { background: #EEF0F1; color: var(--ink-soft); font-weight: 500; }
.panel-log li.removing { opacity: 0; transform: translateX(10px); transition: opacity .22s, transform .22s; }

/* ============ Toast de estado ============ */
.toast-host { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 11px; background: #fff; border-radius: 13px;
  padding: 11px 17px 11px 12px; box-shadow: 0 16px 46px rgba(20,28,32,.22);
  transform: translateY(16px) scale(.96); opacity: 0;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .2s;
}
.toast.show { transform: translateY(0) scale(1); opacity: 1; }
.toast-check { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.toast-check svg { width: 16px; height: 16px; }
.toast-check svg path { stroke-dasharray: 22; stroke-dashoffset: 22; animation: toastdraw .45s .12s cubic-bezier(.65,0,.35,1) forwards; }
@keyframes toastdraw { to { stroke-dashoffset: 0; } }
.toast-text { font-size: 13.5px; color: var(--ink); white-space: nowrap; display: flex; align-items: center; gap: 9px; }
.toast-pill { padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }

/* ============ Botones ============ */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 18px; border-radius: 999px; font: inherit; font-size: 13.5px; font-weight: 600; background: var(--ink); color: #fff; border: none; cursor: pointer; }
.btn:hover { background: #0E1517; }
.btn-wa { background: #2F6B45; }
.btn-wa:hover { background: #275a3a; }
.btn-ghost { display: inline-flex; align-items: center; padding: 9px 15px; border-radius: 999px; font-size: 13px; color: var(--ink-soft); background: #EEF0F1; border: none; cursor: pointer; }
.btn-ghost:hover { background: #E4E7E8; color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { padding: 9px 15px; border-radius: var(--radius-sm); font: inherit; font-size: 13px; font-weight: 600; background: var(--ink); color: #fff; border: none; cursor: pointer; }

/* ============ Equipo ============ */
.users-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; max-width: 900px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm); }
.card h2 { font-family: var(--font-display); font-size: 15px; margin: 0 0 14px; font-weight: 600; }
.user-list { list-style: none; margin: 0; padding: 0; }
.user-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.user-list li:first-child { border-top: none; }
.user-list li.inactive { opacity: .5; }
.u-name { display: block; font-weight: 500; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12px; color: var(--ink-soft); }
.field input { font: inherit; font-size: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.field input:focus { outline: none; border-color: var(--brand); }
.login-error { background: #F7E9E9; border: 1px solid #ECD3D3; color: #8E4040; padding: 9px 13px; border-radius: var(--radius-sm); font-size: 13px; }

/* ============ Login ============ */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1B2427; }
.login-card { background: var(--surface); width: 100%; max-width: 360px; padding: 34px 30px; border-radius: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 11px; }
.login-brand .brand-name { color: var(--ink); }
.login-sub { margin: 2px 0 8px; color: var(--ink-soft); font-size: 13px; }

/* ============ Responsive ============ */
@media (max-width: 1040px) { .col-campaign, .col-date { display: none; } }
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .rail { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 4px; padding: 12px 16px; }
  .rail-nav { flex-direction: row; margin: 0; }
  .rail-funnel { display: none; }
  .rail-foot { border: none; margin: 0; padding: 0; flex: none; }
  .rail-user { display: none; }
  .col-besttime, .cell-note { display: none; }
  #drawer { width: 100vw; max-width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  #drawer, #backdrop, .toast { transition: none; }
  .toast-check svg path { animation: none; stroke-dashoffset: 0; }
}
