:root {
  --bg: #f4f2ec; --panel: #ffffff; --ink: #1c2620; --muted: #6a736d; --line: #e3dfd5; --soft: #f8f7f3;
  --brand: #2d4a3a; --brand-2: #3d6350; --wood: #a77b3d; --ok: #1f7a4d; --ok-bg: #e5f3ea; --warn: #9a5a14; --warn-bg: #fbeedd;
  --bad: #a33a3a; --bad-bg: #fbe7e5; --blue: #1f4f8a; --blue-bg: #e6eef8; --gray-bg: #eeede8;
  --radius: 10px; --shadow: 0 1px 2px rgba(28, 38, 32, .06), 0 4px 16px rgba(28, 38, 32, .05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.top { height: 56px; display: flex; align-items: center; gap: 24px; padding: 0 20px; background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .01em; white-space: nowrap; }
.brand span { font-weight: 400; opacity: .7; margin-left: 4px; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: transparent; border: 0; color: rgba(255,255,255,.75); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.tabs button:hover { color: #fff; background: rgba(255,255,255,.08); }
.tabs button.on { color: #fff; background: rgba(255,255,255,.16); }
.top-r { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.top-link { color: rgba(255,255,255,.75); text-decoration: none; font-size: 13px; }
.top-link:hover { color: #fff; }
.top .btn.primary { background: #fff; color: var(--brand); border-color: #fff; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--soft); border-color: #d3cec2; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-2); }
.btn.wa { background: #1f8f4e; border-color: #1f8f4e; color: #fff; }
.btn.wa:hover { background: #197a42; }
.btn.big { padding: 10px 18px; font-size: 14px; font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--gray-bg); color: var(--ink); }
.btn.danger { color: var(--bad); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

/* ---------- layout ---------- */
main { height: calc(100vh - 56px); }
.view { display: none; height: 100%; }
.view.on { display: flex; }
.view.page.on { display: block; overflow: auto; }
.side { width: 390px; flex: 0 0 390px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.detail { flex: 1; overflow: auto; min-width: 0; }
.search { padding: 14px 14px 8px; }
.search input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--soft); outline: none; }
.search input:focus { border-color: var(--brand-2); background: #fff; box-shadow: 0 0 0 3px rgba(61, 99, 80, .12); }
.chips { display: flex; gap: 6px; padding: 0 14px 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted); }
.chip b { color: var(--ink); font-weight: 600; margin-left: 3px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: rgba(255,255,255,.85); }
.chip.on b { color: #fff; }
.side-tools { display: flex; align-items: center; gap: 10px; padding: 0 14px 10px; border-bottom: 1px solid var(--line); }
.side-tools select { border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; background: #fff; font-size: 13px; }
.side-tools .muted { font-size: 12px; margin-left: auto; }
.list { overflow: auto; flex: 1; }
.item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #efece5; background: #fff; padding: 11px 14px 11px 16px; cursor: pointer; position: relative; }
.item:hover { background: var(--soft); }
.item.sel { background: #edf3ef; }
.item.sel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.item-top { display: flex; align-items: center; gap: 8px; }
.item-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-why { color: #4b554f; font-size: 12.5px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.loading, .empty { padding: 40px 24px; color: var(--muted); text-align: center; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--gray-bg); color: #4d554f; }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.est-por-contactar { background: var(--blue-bg); color: var(--blue); }
.est-en-secuencia { background: #ece9f7; color: #4b3f8f; }
.est-respondio { background: var(--ok-bg); color: var(--ok); }
.est-cotizando { background: #e0f2f1; color: #1f6b66; }
.est-reservo { background: #d9efe0; color: #165a37; }
.est-retenido { background: var(--bad-bg); color: var(--bad); }
.est-no-contactar, .est-no-interesado, .est-dormido { background: var(--gray-bg); color: #6a706b; }

/* ---------- detail ---------- */
.d-wrap { max-width: 880px; margin: 0 auto; padding: 22px 28px 60px; }
.d-head { display: flex; align-items: flex-start; gap: 12px; }
.d-title { flex: 1; min-width: 0; }
.d-title h1 { font-size: 23px; margin: 0; line-height: 1.2; letter-spacing: -.01em; }
.d-title h1 small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.d-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.d-contact { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; color: #3b453f; font-size: 13.5px; }
.d-contact span b { color: var(--muted); font-weight: 500; margin-right: 4px; }
.back { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-top: 14px; }
.card h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.why { font-size: 15px; font-weight: 500; }
.resumen { margin-top: 6px; color: #3d4741; }
.flag { background: var(--warn-bg); border-color: #efd3ad; }
.flag p { margin: 0 0 10px; }
textarea.msg { width: 100%; min-height: 190px; border: 1px solid var(--line); border-radius: 9px; padding: 12px 13px; resize: vertical; line-height: 1.5; background: #fffefb; outline: none; }
textarea.msg:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(61, 99, 80, .12); }
.msg-actions { margin-top: 10px; }
.msg-meta { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.subject { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 8px; }
.states { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.inline-form { margin-top: 12px; padding: 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 9px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; font-weight: 500; }
input[type=text], input[type=date], input[type=number], input[type=email], input:not([type]), select, .newform textarea, .page textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none;
}
input:focus, select:focus, .newform textarea:focus, .page textarea:focus { border-color: var(--brand-2); }
.note-row { display: flex; gap: 8px; margin-bottom: 14px; }
.note-row input { flex: 1; }

/* timeline */
.tl-list { list-style: none; margin: 0; padding: 0; position: relative; }
.tl-list::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl { position: relative; padding: 0 0 16px 28px; }
.tl::before { content: ""; position: absolute; left: 2px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid #b9b4a7; }
.tl-stay::before { border-color: var(--ok); }
.tl-talk::before { border-color: var(--blue); }
.tl-out::before { border-color: var(--brand); background: var(--brand); }
.tl-in::before { border-color: #1f8f4e; background: #1f8f4e; }
.tl-note::before { border-color: var(--wood); }
.tl-review::before { border-color: #c99a2e; }
.tl-head { font-size: 13px; }
.tl-head b { font-weight: 600; }
.tl-date { color: var(--muted); font-size: 12px; font-weight: 500; margin-right: 6px; }
.tl-text { margin-top: 3px; color: #3a443e; white-space: pre-wrap; word-break: break-word; }
.tl-text.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.tl-src { margin-top: 2px; font-size: 11.5px; color: #8b928d; }
.facts { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 13.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.skeleton { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* ---------- pages (actividad, ajustes) ---------- */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 28px 60px; }
.page-wrap h2 { margin: 0 0 4px; font-size: 21px; }
.cols { display: grid; grid-template-columns: 360px 1fr; gap: 18px; margin-top: 16px; align-items: start; }
.feed-day { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 14px 0 6px; }
.feed-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #efece5; cursor: pointer; }
.feed-item:hover { background: var(--soft); }
.feed-item .t { color: var(--muted); font-size: 12px; width: 40px; flex: 0 0 40px; padding-top: 1px; }
.feed-item .b { min-width: 0; }
.feed-item .d { color: #4b554f; font-size: 12.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 620px; }
.up-item { padding: 10px 0; border-bottom: 1px solid #efece5; cursor: pointer; }
.up-item:hover { background: var(--soft); }
.up-item .when { font-weight: 600; color: var(--brand); font-size: 13px; }
.settings-form { max-width: 720px; }
.settings-form .help { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 28, 24, .45); }
.newform { padding: 22px 24px; max-height: calc(100vh - 60px); overflow: auto; }
.newform h2 { margin: 0 0 2px; font-size: 19px; }
.seg3 { display: flex; gap: 8px; flex-wrap: wrap; }
.seg3 label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; margin: 0; color: var(--ink); font-size: 13px; cursor: pointer; }
.only-reserva { display: none; }
.newform.reserva .only-reserva { display: block; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; max-width: min(560px, calc(100vw - 32px)); box-shadow: 0 8px 30px rgba(0,0,0,.2); z-index: 50; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); }
#toast.ok { background: #1d5c3d; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; background: var(--brand); padding: 16px; }
.login { background: #fff; border-radius: 16px; padding: 30px 28px; width: min(360px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-brand { font-size: 24px; font-weight: 700; color: var(--brand); }
.login-sub { color: var(--muted); margin-bottom: 18px; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 14px; }
.login .btn { width: 100%; }
.login-err { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .top { gap: 10px; padding: 0 12px; }
  .brand span { display: none; }
  .tabs button { padding: 7px 8px; font-size: 13px; }
  .top .btn.primary { padding: 6px 9px; font-size: 12px; }
  .top-link { display: none; }
  .side { width: 100%; flex-basis: 100%; border-right: 0; }
  .detail { display: none; }
  #v-clientes.detail-open .side { display: none; }
  #v-clientes.detail-open .detail { display: block; }
  .back { display: inline-flex; margin-bottom: 12px; }
  .d-wrap { padding: 16px 16px 60px; }
  .states { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .page-wrap { padding: 16px; }
  .facts { grid-template-columns: 1fr; gap: 0 0; }
  .facts dt { margin-top: 8px; }
}
@media (max-width: 520px) {
  .grid2 { grid-template-columns: 1fr; }
  .tabs button[data-view="ajustes"] { display: none; }
}
