:root {
  --navy: #0d2440; --navy-2: #143559; --ink: #1b2433; --muted: #5f6b7b; --line: #e2e7ee; --bg: #f3f5f9;
  --amber: #f0a23b; --amber-dark: #d98a1f; --ok: #1f8a5b; --err: #c8372d; --warm: #e8692c; --cold: #3b82c4;
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy-2); }
[hidden] { display: none !important; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #cfd8e3; border-top-color: var(--navy); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Top bar */
.top { position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff; padding: calc(var(--safe-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px; }
.top .brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.08rem; color: #fff; text-decoration: none; }
.top .brand svg { width: 30px; height: 30px; }
.top .brand b { color: var(--amber); }
.top .spacer { flex: 1; }
.top .title { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: transparent; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: rgba(255,255,255,.1); }
.icon-btn svg { width: 22px; height: 22px; }
.new-btn { background: var(--amber); color: #1c1407; border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.new-btn:hover { background: #f4b25a; }

.menu { position: absolute; right: 12px; top: calc(var(--safe-top) + 56px); background: #fff; color: var(--ink); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.22); min-width: 240px; padding: 6px; z-index: 30; }
.menu .who { padding: 10px 12px 8px; font-size: .88rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button, .menu a { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 11px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--ink); }
.menu button:hover, .menu a:hover { background: var(--bg); }
.menu .danger { color: var(--err); }

.page { max-width: 1000px; margin: 0 auto; padding: 16px 14px 60px; }

/* Filters */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; cursor: pointer; font-weight: 600; color: var(--muted); display: inline-flex; gap: 7px; align-items: center; }
.tab .n { background: var(--bg); border-radius: 99px; padding: 0 7px; font-size: .82rem; }
.tab.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.tab.on .n { background: rgba(255,255,255,.18); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=search] { flex: 1 1 220px; }
.filters select { flex: 0 1 auto; }
input[type=search], input[type=text], input[type=password], select, textarea {
  border: 1.5px solid #cfd7e1; border-radius: 10px; background: #fff; padding: 10px 12px; min-height: 42px; width: 100%;
}
.filters select { width: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(20,53,89,.12); }
.mine { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1.5px solid #cfd7e1; border-radius: 10px; padding: 0 12px; cursor: pointer; user-select: none; min-height: 42px; }
.summary { color: var(--muted); font-size: .88rem; margin: 0 2px 10px; display: flex; justify-content: space-between; gap: 10px; }

/* Lead cards */
.lead { display: block; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 10px; text-decoration: none; color: inherit; box-shadow: 0 1px 2px rgba(13,36,64,.04); transition: box-shadow .15s, transform .15s; position: relative; }
.lead:hover { box-shadow: 0 6px 18px rgba(13,36,64,.10); }
.lead.is-new { border-left: 4px solid var(--amber); }
.lead .row1 { display: flex; align-items: center; gap: 10px; }
.lead .name { font-weight: 700; font-size: 1.05rem; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead .id { color: var(--muted); font-size: .85rem; }
.lead .age { margin-left: auto; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.lead .meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 6px; align-items: center; }
.lead .sum { color: var(--muted); font-size: .92rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lead .row3 { display: flex; gap: 10px; margin-top: 8px; font-size: .88rem; color: var(--muted); flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 6px; padding: 2px 8px; font-size: .8rem; font-weight: 700; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.warm { background: #fdeee6; color: #b4481a; }
.badge.cold { background: #e7f0fa; color: #2a69a5; }
.badge.com { background: #efe9fb; color: #6243b0; }
.badge.es { background: #e6f5ee; color: #1b7a50; }
.badge.st { background: #eef1f5; color: var(--navy); }
.badge.due { background: #fde8e6; color: var(--err); }
.badge.soon { background: #fff3df; color: #a76510; }
.status { border-radius: 99px; padding: 2px 10px; font-size: .8rem; font-weight: 700; }
.s-new { background: #fff3df; color: #a76510; }
.s-contacted { background: #e7f0fa; color: #2a69a5; }
.s-qualified { background: #efe9fb; color: #6243b0; }
.s-referred { background: #e5f4f6; color: #16707d; }
.s-signed { background: #e6f5ee; color: #1b7a50; }
.s-closed { background: #eceff3; color: #6b7685; }
.dmg { display: inline-flex; align-items: center; gap: 6px; }
.dmg .bar { width: 50px; height: 6px; background: #e3e8ee; border-radius: 9px; overflow: hidden; }
.dmg .bar i { display: block; height: 100%; background: var(--amber); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; background: #fff; border-radius: 14px; border: 1px dashed #cfd7e1; }
.more { display: block; margin: 14px auto; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 700; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-amber { background: var(--amber); color: #1c1407; }
.btn-line { background: #fff; color: var(--navy); border: 1.5px solid #cfd7e1; }
.btn-line:hover { border-color: var(--navy); }
.btn-danger { background: #fff; color: var(--err); border: 1.5px solid #f0c4bf; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .88rem; }
.btn[disabled] { opacity: .6; cursor: default; }
.btn-block { width: 100%; }

/* Detail */
.panel { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 12px; font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.d-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.d-head h2 { margin: 0; font-family: var(--serif); color: var(--navy); font-size: 1.6rem; }
.d-head .sub { color: var(--muted); font-size: .9rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 18px; }
.kv div small { display: block; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; margin-bottom: 2px; }
.kv div span { font-weight: 600; }
.desc { white-space: pre-wrap; margin: 0; }
.ctrl { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.ctrl label { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 7px 16px; border-radius: 8px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--navy); box-shadow: 0 1px 4px rgba(13,36,64,.14); }
.note-box { display: flex; gap: 8px; align-items: flex-end; }
.note-box textarea { min-height: 44px; height: 44px; resize: vertical; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--line); position: relative; margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: #cfd7e1; }
.timeline li.note::before { background: var(--amber); }
.timeline li.status::before { background: var(--navy); }
.timeline .t { color: var(--muted); font-size: .82rem; }
.timeline .x { white-space: pre-wrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(rgba(9,24,43,.82), rgba(9,24,43,.9)), url(/img/hero.jpg) center / cover; }
.login-card { background: #fff; width: min(400px, 100%); border-radius: 18px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.35rem; color: var(--navy); margin-bottom: 6px; }
.login-card .brand svg { width: 38px; height: 38px; }
.login-card .brand b { color: var(--amber-dark); }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.fld { margin-bottom: 14px; }
.fld label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 6px; color: var(--navy); }
.err { color: var(--err); font-size: .9rem; margin: 4px 0 10px; }
.err:empty { display: none; }
.ok { color: var(--ok); }

/* Admin tables */
.list-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 160px; }
.list-row .grow b { color: var(--navy); }
.list-row .grow small { display: block; color: var(--muted); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 150px; }
.form-row .btn { flex: 0 0 auto; }

/* Modal + toast */
.modal { position: fixed; inset: 0; background: rgba(9,24,43,.55); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card { background: #fff; border-radius: 16px; padding: 24px; width: min(440px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card h3 { margin: 0 0 8px; color: var(--navy); font-family: var(--serif); font-size: 1.3rem; }
.modal-card .pw { font-family: Consolas, "SF Mono", monospace; font-size: 1.35rem; background: var(--bg); border-radius: 10px; padding: 14px; text-align: center; letter-spacing: .05em; margin: 14px 0; user-select: all; }
.modal-card .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 60; max-width: 90vw; }
.toast.bad { background: var(--err); }

@media (max-width: 600px) {
  .page { padding: 12px 10px 60px; }
  .new-btn span { display: none; }
  .d-head h2 { font-size: 1.35rem; }
}
