:root{
  --bg:#FBFAF7; --surface:#FFFFFF; --surface-2:#F4F1EA;
  --line:rgba(24,20,12,0.11); --line-soft:rgba(24,20,12,0.06);
  --ink:#201E19; --muted:#736F68; --muted-2:#A6A199;
  --gold:#B5893C; --gold-ink:#FFFFFF; --gold-dim:rgba(181,137,60,0.12); --gold-line:rgba(181,137,60,0.45);
  --ok:#4C8067; --ok-dim:rgba(76,128,103,0.12);
  --pending:#B5893C;
  --process:#4C6A96; --process-dim:rgba(76,106,150,0.12);
  --missed:#AC5B47; --missed-dim:rgba(172,91,71,0.12);
  --serif:'Fraunces',Georgia,serif; --sans:'Inter',-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  --radius:12px; --radius-sm:8px;
  --shadow-card:0 1px 2px rgba(32,28,20,.04), 0 10px 24px -18px rgba(32,28,20,.18);
  --ease:cubic-bezier(.4,0,.2,1);
  color-scheme:light;
}
:root[data-theme="dark"]{
  color-scheme:dark;
  --bg:#0A0A0C; --surface:#131316; --surface-2:#1B1B1F;
  --line:rgba(255,255,255,0.08); --line-soft:rgba(255,255,255,0.045);
  --ink:#F5F3EE; --muted:#98979F; --muted-2:#5C5B63;
  --gold:#C9A86A; --gold-ink:#0A0A0C; --gold-dim:rgba(201,168,106,0.13); --gold-line:rgba(201,168,106,0.35);
  --ok:#83A892; --ok-dim:rgba(131,168,146,0.14);
  --pending:#C9A86A;
  --process:#7E93BE; --process-dim:rgba(126,147,190,0.14);
  --missed:#B97B70; --missed-dim:rgba(185,123,112,0.14);
  --shadow-card:0 1px 1px rgba(0,0,0,.2), 0 10px 26px -18px rgba(0,0,0,.6);
}

*{box-sizing:border-box;}
html{-webkit-tap-highlight-color:transparent;-webkit-text-size-adjust:100%;}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--sans);-webkit-font-smoothing:antialiased;font-size:14px;}
a{color:inherit;}
:focus-visible{outline:2px solid var(--gold);outline-offset:2px;border-radius:3px;}
@media (prefers-reduced-motion: reduce){ *{animation-duration:0.001ms !important;transition-duration:0.001ms !important;} }

/* ---------- shell ---------- */
.app-shell{display:flex;min-height:100vh;}
.sidebar{
  width:232px;flex-shrink:0;border-right:1px solid var(--line);
  padding:26px 18px;display:flex;flex-direction:column;gap:34px;
  position:sticky;top:0;height:100vh;
}
.brand{display:flex;align-items:center;gap:11px;padding:0 6px;}
.brand-mark{
  width:32px;height:32px;border-radius:9px;flex-shrink:0;
  background:linear-gradient(155deg,var(--gold) 0%,#9C7B3E 100%);
  color:#181410;font-family:var(--serif);font-weight:600;font-size:16px;
  display:flex;align-items:center;justify-content:center;letter-spacing:-0.02em;
}
.sidebar h1{font-family:var(--serif);font-weight:500;font-size:18px;margin:0;letter-spacing:-0.01em;line-height:1.15;}
.sidebar .tag{color:var(--muted);font-size:11.5px;margin-top:1px;}
.sidebar-nav{display:flex;flex-direction:column;gap:2px;}
.nav-link{
  display:flex;align-items:center;gap:10px;padding:9px 10px;border-radius:8px;
  color:var(--muted);text-decoration:none;font-size:13.5px;font-weight:500;
  border-left:2px solid transparent;transition:background .15s var(--ease),color .15s var(--ease);
}
.nav-link svg{width:16px;height:16px;flex-shrink:0;opacity:.85;}
.nav-link.active{color:var(--ink);background:var(--gold-dim);border-left-color:var(--gold);}
.nav-link.active svg{opacity:1;color:var(--gold);}
.nav-link:hover:not(.active){color:var(--ink);background:var(--line-soft);}
.sidebar-foot{margin-top:auto;padding:12px 10px 0;border-top:1px solid var(--line);color:var(--muted-2);font-size:11px;line-height:1.6;}

.main{flex:1;min-width:0;padding:38px 44px 90px;max-width:1180px;}
.page-head{margin-bottom:30px;display:flex;align-items:flex-end;justify-content:space-between;gap:20px;flex-wrap:wrap;}
.page-head h2{font-family:var(--serif);font-weight:500;font-size:27px;margin:0 0 6px;letter-spacing:-0.015em;}
.page-head p{color:var(--muted);font-size:13.5px;margin:0;max-width:46ch;}

@media (max-width:880px){
  .app-shell{flex-direction:column;}
  .sidebar{width:auto;border-right:none;border-bottom:1px solid var(--line);flex-direction:row;align-items:center;padding:14px 18px;gap:18px;overflow-x:auto;position:sticky;height:auto;top:0;z-index:20;background:var(--bg);}
  .sidebar-nav{flex-direction:row;gap:2px;}
  .sidebar-foot{display:none;}
  .main{padding:26px 20px 60px;}
}

/* ---------- tabs / toolbar ---------- */
.tabs{display:flex;gap:22px;border-bottom:1px solid var(--line);margin-bottom:22px;flex-wrap:wrap;}
.tab{background:none;border:none;color:var(--muted-2);font-size:13px;font-weight:500;cursor:pointer;padding:0 0 10px;border-bottom:2px solid transparent;margin-bottom:-1px;transition:color .15s var(--ease);}
.tab.active{color:var(--gold);border-bottom-color:var(--gold);}
.tab:hover:not(.active){color:var(--ink);}
.toolbar{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:22px;}
.toolbar input[type=text],.toolbar input[type=date],.toolbar input[type=month],.toolbar select{
  background:var(--surface);border:1px solid var(--line);color:var(--ink);
  padding:8.5px 12px;border-radius:var(--radius-sm);font-size:13px;font-family:var(--sans);
  transition:border-color .15s var(--ease);
}
.toolbar input:focus,.toolbar select:focus{border-color:var(--gold-line);}
.toolbar input[type=text]{flex:1;min-width:200px;}
.hidden{display:none !important;}

/* ---------- KPI cards ---------- */
.cards-grid{display:grid;grid-template-columns:repeat(6,1fr);gap:12px;margin-bottom:40px;}
.card{
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  padding:18px 18px 16px;box-shadow:var(--shadow-card);position:relative;overflow:hidden;
}
.card::before{content:"";position:absolute;left:0;top:0;bottom:0;width:3px;background:var(--accent,var(--gold));opacity:.85;}
.card .num{font-family:var(--serif);font-size:28px;font-weight:500;font-variant-numeric:tabular-nums;line-height:1.1;}
.card .lbl{font-size:11.5px;color:var(--muted);margin-top:6px;letter-spacing:.01em;}
@media (max-width:980px){.cards-grid{grid-template-columns:repeat(3,1fr);}}
@media (max-width:520px){.cards-grid{grid-template-columns:repeat(2,1fr);gap:10px;}}

/* ---------- panels / charts ---------- */
.panel{margin-bottom:36px;}
.panel-title{font-family:var(--serif);font-weight:500;font-size:16px;margin:0 0 16px;letter-spacing:-0.005em;}
.chart-panel{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:24px 26px 18px;box-shadow:var(--shadow-card);}
.chart-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;flex-wrap:wrap;gap:10px;}
.legend{display:flex;gap:16px;flex-wrap:wrap;font-size:12px;color:var(--muted);}
.legend span{display:inline-flex;align-items:center;gap:6px;}
.legend i{width:7px;height:7px;border-radius:2px;display:inline-block;}
.chart-box{position:relative;width:100%;height:280px;}
.chart-box canvas{position:absolute;left:0;top:0;width:100%!important;height:100%!important;}
@media (max-width:760px){.chart-box{height:240px;}}
.chart-row{display:grid;grid-template-columns:1fr 1fr;gap:18px;}
@media (max-width:760px){.chart-row{grid-template-columns:1fr;}}

/* ---------- operations rows ---------- */
.op-row{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;border-top:none;}
.op-item{
  display:flex;flex-direction:column;gap:10px;padding:18px 18px 16px;
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow-card);
}
.op-item-top{display:flex;align-items:center;gap:8px;}
.op-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0;}
.op-label{font-size:12.5px;color:var(--muted);font-weight:500;}
.op-count{font-family:var(--serif);font-size:26px;font-weight:500;font-variant-numeric:tabular-nums;}
@media (max-width:760px){.op-row{grid-template-columns:repeat(2,1fr);}}

/* ---------- source / path rows ---------- */
.path-row{display:flex;flex-direction:column;gap:10px;}
.path-item{
  display:flex;align-items:center;gap:16px;padding:16px 18px;flex-wrap:wrap;
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow-card);
}
.path-icon{width:34px;height:34px;border-radius:9px;background:var(--gold-dim);color:var(--gold);display:flex;align-items:center;justify-content:center;flex-shrink:0;}
.path-icon svg{width:17px;height:17px;}
.path-main{display:flex;flex-direction:column;gap:2px;min-width:110px;}
.path-name{font-size:14px;font-weight:600;}
.path-status{font-size:12px;color:var(--muted-2);display:flex;align-items:center;gap:6px;}
.path-status .sdot{width:6px;height:6px;border-radius:50%;background:var(--muted-2);}
.path-status.live{color:var(--ok);}
.path-status.live .sdot{background:var(--ok);}
.path-count{font-family:var(--serif);font-size:21px;font-weight:500;margin-left:auto;font-variant-numeric:tabular-nums;}
.path-action{
  background:var(--gold-dim);border:1px solid var(--gold-line);color:var(--gold);
  font-size:12px;font-weight:600;cursor:pointer;padding:8px 14px;border-radius:999px;
  transition:background .15s var(--ease),transform .1s var(--ease);white-space:nowrap;
}
.path-action:hover{background:var(--gold);color:var(--gold-ink);}
.path-action:active{transform:scale(0.97);}
.path-action:disabled{background:transparent;border-color:var(--line);color:var(--muted-2);cursor:default;}
.path-action:disabled:hover{background:transparent;color:var(--muted-2);}
@media (max-width:600px){ .path-item{gap:12px;} .path-count{margin-left:0;} .path-action{margin-left:auto;} }

/* ---------- table ---------- */
.table-wrap{border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;overflow-x:auto;box-shadow:var(--shadow-card);}
table{width:100%;border-collapse:collapse;font-size:13.5px;white-space:nowrap;}
th{text-align:left;font-weight:600;color:var(--muted);font-size:11px;letter-spacing:.02em;padding:11px 16px;border-bottom:1px solid var(--line);background:var(--surface-2);}
td{padding:11px 16px;border-bottom:1px solid var(--line-soft);}
tbody tr:last-child td{border-bottom:none;}
tbody tr{cursor:pointer;transition:background .12s var(--ease);}
tbody tr:hover td{background:var(--gold-dim);}
.lead-cell{display:flex;align-items:center;gap:10px;}
.avatar{
  width:26px;height:26px;border-radius:50%;background:var(--surface-2);border:1px solid var(--line);
  display:flex;align-items:center;justify-content:center;font-size:10.5px;font-weight:600;color:var(--muted);flex-shrink:0;
}
.status-badge{display:inline-flex;align-items:center;gap:6px;font-size:12px;padding:4px 9px;border-radius:999px;font-weight:500;}
.status-badge .sdot{width:6px;height:6px;border-radius:50%;}
.row-link{color:var(--gold);text-decoration:none;font-size:12.5px;font-weight:600;}
.row-link:hover{text-decoration:underline;}
.empty-note{font-size:12.5px;color:var(--muted-2);margin-top:16px;line-height:1.6;max-width:520px;}
.empty-state{display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px;padding:52px 20px;color:var(--muted-2);}
.empty-state svg{width:28px;height:28px;opacity:.5;margin-bottom:4px;}

/* ---------- lead details ---------- */
.detail-card{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:30px;margin-bottom:32px;box-shadow:var(--shadow-card);}
.detail-top{display:flex;align-items:center;gap:16px;margin-bottom:24px;}
.detail-avatar{
  width:52px;height:52px;border-radius:50%;background:var(--gold-dim);color:var(--gold);
  display:flex;align-items:center;justify-content:center;font-family:var(--serif);font-size:19px;font-weight:600;flex-shrink:0;
}
.detail-name{font-family:var(--serif);font-size:23px;font-weight:500;margin:0 0 4px;letter-spacing:-0.01em;}
.detail-meta{color:var(--muted);font-size:13px;}
.detail-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:22px;}
.detail-field .lbl{font-size:11px;color:var(--muted-2);margin-bottom:5px;letter-spacing:.02em;}
.detail-field .val{font-size:14px;}
@media (max-width:640px){.detail-grid{grid-template-columns:1fr 1fr;}}
.back-link{display:inline-flex;align-items:center;gap:6px;margin-bottom:22px;color:var(--muted);text-decoration:none;font-size:13px;transition:color .15s var(--ease);}
.back-link:hover{color:var(--ink);}
.back-link svg{width:14px;height:14px;}

.flow{display:flex;align-items:stretch;gap:0;margin:0 0 6px;}
.flow-step{flex:1;text-align:center;padding:14px 8px 0;border-top:2px solid var(--line);font-size:12px;color:var(--muted-2);position:relative;}
.flow-step::before{content:"";position:absolute;top:-4px;left:50%;transform:translateX(-50%);width:6px;height:6px;border-radius:50%;background:var(--line);}
.flow-step.done{border-top-color:var(--gold);color:var(--ink);}
.flow-step.done::before{background:var(--gold);}
.flow-step.missed{border-top-color:var(--missed);color:var(--missed);}
.flow-step.missed::before{background:var(--missed);}

/* ---------- phones ---------- */
@media (max-width:600px){
  .sidebar{padding:12px 14px;gap:14px;}
  .sidebar h1{font-size:17px;}
  .brand-mark{width:28px;height:28px;font-size:14px;}
  .sidebar-nav{gap:2px;}
  .nav-link{padding:7px 9px;font-size:12.5px;white-space:nowrap;}
  .nav-link span{display:none;}
  .main{padding:20px 14px 50px;}
  .page-head h2{font-size:21px;}
  .cards-grid{grid-template-columns:repeat(2,1fr);}
  .card{padding:14px 14px 12px;}
  .card .num{font-size:22px;}
  .chart-panel{padding:16px 14px 12px;}
  .toolbar{gap:8px;}
  .toolbar input[type=text],.toolbar input[type=date],.toolbar input[type=month],.toolbar select{flex:1 1 100%;min-width:0;}
  .detail-card{padding:20px;}
  .detail-name{font-size:19px;}
  .detail-grid{grid-template-columns:1fr 1fr;gap:14px;}
  .flow-step{font-size:10px;padding:10px 3px 0;}
  .path-item{gap:10px;}
  .path-main{min-width:0;}
  table{font-size:12.5px;}
  th,td{padding:9px 10px;}
}

/* ---------- buttons / export ---------- */
.btn{
  display:inline-flex;align-items:center;gap:8px;cursor:pointer;
  font-family:var(--sans);font-size:13px;font-weight:500;
  padding:9px 14px;border-radius:var(--radius-sm);
  border:1px solid var(--line);background:var(--surface);color:var(--ink);
  transition:background .15s var(--ease),border-color .15s var(--ease),opacity .15s var(--ease);
}
.btn svg{width:15px;height:15px;flex-shrink:0;}
.btn:hover{background:var(--surface-2);}
.btn:disabled{opacity:.6;cursor:progress;}
.btn-gold{background:var(--gold);border-color:var(--gold);color:var(--gold-ink);}
.btn-gold:hover{background:#9C7B3E;border-color:#9C7B3E;}
.btn .caret{width:13px;height:13px;opacity:.8;transition:transform .15s var(--ease);}
.btn[aria-expanded="true"] .caret{transform:rotate(180deg);}
.btn.is-busy svg:first-child{animation:ex-spin 1s linear infinite;}
@keyframes ex-spin{to{transform:rotate(360deg);}}

.export-wrap{position:relative;flex-shrink:0;}
.export-menu{
  position:absolute;right:0;top:calc(100% + 8px);z-index:40;width:290px;
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:0 4px 8px rgba(32,28,20,.06),0 18px 40px -20px rgba(32,28,20,.35);
  padding:6px;overflow:hidden;
}
.export-menu-head{
  font-size:11px;color:var(--muted-2);padding:8px 10px 9px;margin-bottom:2px;
  border-bottom:1px solid var(--line-soft);letter-spacing:.02em;
}
.export-item{
  display:flex;align-items:center;gap:11px;width:100%;text-align:left;
  background:none;border:none;cursor:pointer;padding:10px;border-radius:var(--radius-sm);
  color:var(--ink);font-family:var(--sans);transition:background .13s var(--ease);
}
.export-item:hover{background:var(--surface-2);}
.export-item strong{display:block;font-size:13px;font-weight:500;}
.export-item em{display:block;font-style:normal;font-size:11.5px;color:var(--muted);margin-top:2px;line-height:1.35;}
.ex-ico{
  width:34px;height:34px;flex-shrink:0;border-radius:8px;
  display:flex;align-items:center;justify-content:center;
  font-size:9.5px;font-weight:600;letter-spacing:.03em;
}
.ex-pdf{background:var(--missed-dim);color:var(--missed);}
.ex-xls{background:var(--ok-dim);color:var(--ok);}

.toast{
  position:fixed;left:50%;bottom:26px;transform:translate(-50%,14px);z-index:200;
  background:var(--ink);color:var(--bg);font-size:12.5px;font-weight:500;
  padding:11px 18px;border-radius:999px;box-shadow:0 12px 30px -12px rgba(0,0,0,.5);
  opacity:0;transition:opacity .22s var(--ease),transform .22s var(--ease);pointer-events:none;max-width:88vw;
}
.toast.show{opacity:1;transform:translate(-50%,0);}
.toast-error{background:var(--missed);color:#fff;}

@media (max-width:560px){
  .export-wrap{width:100%;}
  .export-wrap .btn{width:100%;justify-content:center;}
  .export-menu{width:100%;}
}
