:root {
  --navy: #0f1b2d; --navy-2: #172a44; --navy-3: #22395a;
  --gold: #d6a85c; --gold-soft: #f6ead6;
  --bg: #f4f5f7; --card: #ffffff; --line: #e3e6eb; --text: #1b2433; --muted: #6b7584;
  --hot: #d9453b; --warm: #e39a2d; --cold: #3f7fd6; --ok: #2c9a62; --bad: #8a94a3;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,27,45,.06), 0 4px 16px rgba(16,27,45,.06);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); font-size: 13px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; border-color: var(--gold); }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-3); }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.ghost:hover { border-color: var(--muted); }
.btn.danger { background: #fff; border-color: #f0c9c6; color: var(--hot); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px 8px; }

/* ===== Login ===== */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, var(--navy-3), var(--navy) 60%); padding: 16px; }
.login-card { background: #fff; padding: 28px; border-radius: 16px; width: min(380px, 100%); display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.err { color: var(--hot); margin: 0; min-height: 1em; font-size: 13px; }

/* ===== Layout ===== */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #cdd6e3; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 14px; }
.brand b { color: #fff; font-size: 16px; display: block; }
.brand small { font-size: 12px; display: block; }
.brand.big b { color: var(--navy); font-size: 20px; }
.brand.big small { color: var(--muted); }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--gold); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 9px 8px 8px; background: var(--navy); clip-path: polygon(50% 0, 100% 45%, 100% 100%, 0 100%, 0 45%); }
.live::before { content: "●"; margin-right: 5px; }
.live.on { color: #6fd39b; } .live.off { color: #e9a19b; }
.nav-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-decoration: none; color: #cdd6e3; }
.nav-item:hover { background: var(--navy-2); color: #fff; }
.nav-item.active { background: var(--navy-3); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.count { font-size: 12px; background: var(--navy-3); padding: 1px 8px; border-radius: 99px; color: #fff; }
.count:empty { display: none; }
.count.accent { background: var(--gold); color: var(--navy); }
.count.warn { background: var(--warm); color: #fff; }
.count.hot { background: var(--hot); }
.side-title { margin: 16px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7f8ea5; }
.side-foot { margin-top: auto; display: grid; gap: 6px; padding-top: 16px; }
.side-foot .btn { background: transparent; color: #cdd6e3; border-color: var(--navy-3); }

.main { min-width: 0; }
.topbar { display: flex; gap: 12px; align-items: center; padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .menu { display: none; }
.search { flex: 1; max-width: 520px; }
.view { padding: 22px 24px 40px; }
.view-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; }

/* ===== Dashboard ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; border: 1px solid transparent; }
.kpi:hover { border-color: var(--gold); }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.hot .n { color: var(--hot); } .kpi.warn .n { color: var(--warm); } .kpi.ok .n { color: var(--ok); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 18px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.bar i { display: block; width: 100%; max-width: 34px; background: var(--navy-3); border-radius: 5px 5px 2px 2px; min-height: 2px; }
.bar b { font-size: 11px; color: var(--text); }
.bar span { font-size: 10px; color: var(--muted); white-space: nowrap; }
.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 40%) 1fr 34px; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.hbar .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { background: #eef0f4; border-radius: 99px; height: 8px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--gold); border-radius: 99px; }
.hbar .v { text-align: right; font-weight: 600; }

/* ===== Leads table ===== */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters select { width: auto; min-width: 130px; max-width: 220px; }
.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.leads { width: 100%; border-collapse: collapse; }
.leads th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
.leads td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.leads td.c-fu, .leads td.c-recv { white-space: nowrap; font-size: 13px; }
.leads td.c-lead { min-width: 130px; }
.leads tr { cursor: pointer; }
.leads tbody tr:hover { background: #fbf8f2; }
.leads tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.leads tr.unread .lname { font-weight: 700; }
.lname { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.clip { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone-cell { white-space: nowrap; }
.mini { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; text-decoration: none; margin-left: 4px; font-size: 13px; border: 1px solid var(--line); background: #fff; }
.mini.wa { color: #1f9d55; } .mini.tel { color: var(--navy); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef0f4; color: var(--text); }
.pill.Hot { background: #fde8e6; color: var(--hot); } .pill.Warm { background: #fdf1df; color: #a96a10; } .pill.Cold { background: #e6effb; color: var(--cold); }
.pill.s-New { background: var(--gold-soft); color: #8a6420; }
.pill.s-Contacted, .pill.s-Follow-up { background: #e6effb; color: #2c5fa8; }
.pill.s-Interested, .pill.s-Viewing-Meeting, .pill.s-Negotiation { background: #e5f5ec; color: #23784d; }
.pill.s-Closed-Won { background: var(--ok); color: #fff; }
.pill.s-No-Answer { background: #fdf1df; color: #a96a10; }
.pill.s-Closed-Lost, .pill.s-Not-Interested, .pill.s-Junk { background: #eceef1; color: var(--bad); }
.due { color: var(--hot); font-weight: 600; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); }

/* ===== Drawer ===== */
.scrim { position: fixed; inset: 0; background: rgba(15,27,45,.35); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 21; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
.d-head { background: var(--navy); color: #fff; padding: 18px 20px 16px; position: sticky; top: 0; z-index: 2; }
.d-head h2 { margin: 0; font-size: 20px; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.d-head .sub { color: #b8c4d6; }
.d-head .close { color: #fff; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.quick a, .quick button { text-decoration: none; background: var(--navy-3); color: #fff; border: 0; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; cursor: pointer; }
.quick a.wa { background: #1f9d55; }
.d-body { padding: 16px 20px 40px; display: grid; gap: 14px; }
.d-body .card { padding: 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 10px; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.touch-form { display: grid; grid-template-columns: 120px 1fr; gap: 8px; }
.touch-form textarea { grid-column: 1 / -1; }
.touch-form .btn { grid-column: 1 / -1; justify-self: end; }
.timeline { display: grid; gap: 10px; margin-top: 12px; }
.ev { display: grid; grid-template-columns: 26px 1fr; gap: 10px; }
.ev .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: #eef0f4; }
.ev.touch .dot { background: var(--gold-soft); }
.ev .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.ev .txt { white-space: pre-wrap; word-break: break-word; }
.ev .del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.note-form { display: grid; gap: 8px; }
.note-form .btn { justify-self: end; }

/* ===== Dialog & toasts ===== */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15,27,45,.45); }
.dlg { padding: 20px; display: grid; gap: 12px; }
.dlg h3 { color: var(--text); text-transform: none; font-size: 18px; letter-spacing: 0; margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; cursor: pointer; border-left: 4px solid var(--gold); animation: pop .25s ease-out; }
.toast b { display: block; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 1500px) {
  .leads th.h-ttc, .leads td.c-ttc { display: none; }
}

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.3); }
  .topbar { padding: 10px 16px; }
  .topbar .menu { display: block; }
  .view { padding: 16px 16px 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .filters select { flex: 1 1 140px; max-width: none; }
  .leads thead { display: none; }
  .leads, .leads tbody, .leads tr, .leads td { display: block; width: 100%; }
  .leads tr { padding: 12px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
  .leads td { border: 0; padding: 0; }
  .leads td.c-int, .leads td.c-term, .leads td.c-ttc, .leads td.c-recv { display: none; }
  .leads td.c-lead { grid-column: 1; } .leads td.c-status { grid-column: 2; grid-row: 1; text-align: right; }
  .leads td.c-phone { grid-column: 1; } .leads td.c-prio { grid-column: 2; grid-row: 2; text-align: right; }
  .leads td.c-fu:empty { display: none; }
  .leads tr.unread { box-shadow: inset 3px 0 0 var(--gold); }
  .leads tr.unread td:first-child { box-shadow: none; }
  .row3, .two { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 110px 1fr; }
}
