:root{
  --bg: #F3F4F8;
  --surface: #FFFFFF;
  --sidebar: #10131F;
  --sidebar-hi: #191E30;
  --ink: #171923;
  --muted: #6B7280;
  --border: #E6E7EE;

  --accent: #0F9B8E;       /* teal — primary */
  --accent-ink: #0B6F65;
  --accent-soft: #E3F5F2;

  --gold: #E8A33D;         /* amber — secondary / warning */
  --gold-soft: #FBF0DD;

  --coral: #E15554;        /* danger / lost */
  --coral-soft: #FBE7E6;

  --blue: #4C6FFF;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16,19,31,0.04), 0 8px 24px -12px rgba(16,19,31,0.10);
}

*{ box-sizing: border-box; }

body{
  margin:0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app-shell{
  display:flex;
  min-height:100vh;
}

/* ============ SIDEBAR ============ */
.sidebar{
  width: 240px;
  flex-shrink:0;
  background: var(--sidebar);
  background-image:
    radial-gradient(circle at 20% 0%, rgba(15,155,142,0.20), transparent 55%),
    radial-gradient(circle at 90% 90%, rgba(232,163,61,0.10), transparent 45%);
  color:#EDEFF7;
  display:flex;
  flex-direction:column;
  padding: 22px 16px;
  position: sticky;
  top:0;
  height:100vh;
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 4px 6px 26px;
}
.brand-mark{
  width:28px; height:28px;
  color: var(--accent);
  flex-shrink:0;
}
.brand-name{
  font-family: var(--font-display);
  font-weight:700;
  font-size: 15px;
  letter-spacing: 0.06em;
}
.brand-sub{
  font-size: 11px;
  color: #8B90A6;
  margin-top:1px;
}

.side-nav{
  display:flex;
  flex-direction:column;
  gap: 2px;
  margin-top: 8px;
}
.side-link{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color:#B7BBD0;
  text-decoration:none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.side-link .dot{
  width:6px; height:6px;
  border-radius:50%;
  background:#4A4F66;
  flex-shrink:0;
  transition: background .15s ease;
}
.side-link:hover{
  background: var(--sidebar-hi);
  color:#fff;
}
.side-link.active{
  background: var(--sidebar-hi);
  color:#fff;
}
.side-link.active .dot{
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(15,155,142,0.25);
}

.sidebar-footer{
  margin-top:auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.conn-status{
  display:flex; align-items:center; gap:8px;
  font-size: 12px;
  color:#9297AB;
}
.conn-dot{
  width:7px; height:7px; border-radius:50%;
  background:#6b7280;
}
.conn-dot.ok{ background: var(--accent); box-shadow:0 0 0 3px rgba(15,155,142,0.25); }
.conn-dot.err{ background: var(--coral); box-shadow:0 0 0 3px rgba(225,85,84,0.25); }

/* ============ MAIN ============ */
.main{
  flex:1;
  min-width:0;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
  padding: 22px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top:0;
  z-index: 5;
  flex-wrap: wrap;
}
.topbar-title h1{
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin:0;
}
.topbar-title p{
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}
.topbar-controls{
  display:flex;
  align-items:center;
  gap:10px;
}
.control-select{
  font-size: 13px;
  padding: 8px 30px 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background-color: #fff;
  color: var(--ink);
  min-width: 140px;
}
.control-select:focus{
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-color: var(--accent);
}
.btn-refresh{
  display:flex; align-items:center; justify-content:center;
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background:#fff;
  color: var(--accent-ink);
}
.btn-refresh:hover{ background: var(--accent-soft); }
.btn-refresh.spinning svg{ animation: spin .7s linear infinite; }
@keyframes spin{ to{ transform: rotate(360deg); } }

.content{
  padding: 24px 32px 48px;
}

/* ============ KPI CARDS ============ */
.kpi-row{
  display:grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label{
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.kpi-value{
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  margin: 6px 0 4px;
  color: var(--ink);
}
.kpi-foot{
  font-size: 11.5px;
  color: var(--muted);
}
.kpi-foot span{
  color: var(--accent-ink);
  font-weight:600;
}

/* ============ PANELS / CHARTS ============ */
.chart-row{
  display:grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.chart-row-3{
  grid-template-columns: repeat(3, 1fr);
}
.panel{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width:0;
}
.panel-head{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  margin-bottom: 14px;
}
.panel-head h2{
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  margin:0;
}
.panel-tag{
  font-size: 11px;
  color: var(--muted);
  font-family: var(--font-mono);
}
.legend-list{
  list-style:none;
  padding:0; margin: 14px 0 0;
  display:flex; flex-wrap:wrap; gap: 8px 14px;
}
.legend-list li{
  font-size: 11.5px;
  color: var(--muted);
  display:flex; align-items:center; gap:6px;
}
.legend-list .sw{
  width:8px; height:8px; border-radius:2px;
}

/* ============ TABLE ============ */
.table-panel{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 8px;
  box-shadow: var(--shadow);
}
.table-filters{
  display:flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filter-input{
  flex: 1 1 240px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  padding: 8px 14px;
}
.filter-select{
  max-width: 160px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  padding: 8px 12px;
}
.filter-input:focus, .filter-select:focus{
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-color: var(--accent);
}
.btn-clear{
  border-radius: 999px;
  border: 1px solid var(--border);
  background:#fff;
  font-size: 12.5px;
  color: var(--muted);
  padding: 8px 16px;
}
.btn-clear:hover{ background: var(--bg); }

.table-scroll{
  overflow-x:auto;
}
.leads-table{
  width:100%;
  border-collapse: collapse;
  font-size: 13px;
}
.leads-table thead th{
  text-align:left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.leads-table tbody td{
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.leads-table tbody tr{
  cursor:pointer;
  transition: background .12s ease;
}
.leads-table tbody tr:hover{
  background: var(--bg);
}
.lead-name{
  font-weight: 600;
  color: var(--ink);
}
.lead-sub{
  font-size: 11.5px;
  color: var(--muted);
  margin-top:1px;
}
.badge-status{
  display:inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  background: #EEF0F6;
  color: #4B5065;
}
.badge-status.st-new{ background: #E7ECFF; color:#3B4FCF; }
.badge-status.st-contacted, .badge-status.st-qualified{ background: var(--gold-soft); color:#9B6A16; }
.badge-status.st-won, .badge-status.st-converted, .badge-status.st-closed_won{ background: var(--accent-soft); color: var(--accent-ink); }
.badge-status.st-lost, .badge-status.st-closed_lost{ background: var(--coral-soft); color: #B23A39; }

.intent-cell{
  display:flex; align-items:center; gap:8px;
}
.intent-bar{
  width: 54px; height: 6px;
  border-radius: 4px;
  background: #EDEEF3;
  overflow:hidden;
}
.intent-bar-fill{
  height:100%;
  border-radius: 4px;
}
.intent-num{
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight:600;
  width: 22px;
}

.empty-state{
  text-align:center;
  padding: 32px 12px;
  color: var(--muted);
  font-size: 13px;
}

.table-footer{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 4px 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.pg-controls{
  display:flex; align-items:center; gap:10px;
}
.btn-page{
  border-radius: 999px;
  border: 1px solid var(--border);
  background:#fff;
  font-size: 12px;
  padding: 6px 14px;
}
.btn-page:hover{ background: var(--bg); }
.btn-page:disabled{ opacity:.4; cursor:not-allowed; }
#pgCurrent{ font-family: var(--font-mono); font-weight:600; color: var(--ink); }

/* ============ DRAWER ============ */
.drawer-backdrop{
  position:fixed; inset:0;
  background: rgba(16,19,31,0.35);
  opacity:0; pointer-events:none;
  transition: opacity .18s ease;
  z-index: 40;
}
.drawer-backdrop.show{ opacity:1; pointer-events:auto; }

.drawer{
  position:fixed;
  top:0; right:0;
  height:100vh;
  width: 380px;
  max-width: 90vw;
  background:#fff;
  box-shadow: -12px 0 32px rgba(16,19,31,0.14);
  transform: translateX(100%);
  transition: transform .2s ease;
  z-index: 41;
  display:flex;
  flex-direction:column;
}
.drawer.show{ transform: translateX(0); }
.drawer-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h3{
  font-family: var(--font-display);
  font-size: 16px; margin:0;
}
.drawer-close{
  border:none; background:none; font-size: 22px; line-height:1;
  color: var(--muted); cursor:pointer;
}
.drawer-body{
  padding: 18px 20px;
  overflow-y:auto;
  flex:1;
}
.dr-row{
  display:flex; justify-content:space-between; gap: 12px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.dr-row .k{ color: var(--muted); }
.dr-row .v{ font-weight:500; text-align:right; }

/* ============ NOTIFICATIONS ============ */
.notif-wrap{
  position: relative;
}
.notif-badge{
  position:absolute;
  top: -4px; right: -4px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--coral);
  color:#fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align:center;
  font-family: var(--font-mono);
}
.notif-panel{
  position:absolute;
  top: 44px; right:0;
  width: 340px;
  max-height: 420px;
  background:#fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px -8px rgba(16,19,31,0.22);
  display:flex;
  flex-direction:column;
  opacity:0; visibility:hidden; transform: translateY(-6px);
  transition: opacity .14s ease, transform .14s ease, visibility .14s;
  z-index: 30;
}
.notif-panel.show{
  opacity:1; visibility:visible; transform: translateY(0);
}
.notif-panel-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
}
.notif-mark-read{
  border:none; background:none;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-ink);
  cursor:pointer;
}
.notif-list{
  overflow-y:auto;
  flex:1;
}
.notif-empty{
  padding: 26px 14px;
  text-align:center;
  color: var(--muted);
  font-size: 12.5px;
}
.notif-item{
  display:flex;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor:pointer;
}
.notif-item:hover{ background: var(--bg); }
.notif-item:last-child{ border-bottom:none; }
.notif-item.unread{ background: var(--accent-soft); }
.notif-item.unread:hover{ background: var(--accent-soft); }
.notif-icon{
  width: 26px; height: 26px;
  border-radius: 999px;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
  font-size: 12px;
  color:#fff;
  font-weight:700;
}
.notif-icon.new{ background: var(--blue); }
.notif-icon.update{ background: var(--gold); }
.notif-body{ min-width:0; }
.notif-title{
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.notif-sub{
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 1px;
}
.notif-time{
  font-size: 10.5px;
  color: #A6ABC0;
  margin-top: 2px;
  font-family: var(--font-mono);
}

/* Toasts */
.toast-stack{
  position: fixed;
  top: 20px; right: 20px;
  display:flex;
  flex-direction:column;
  gap: 10px;
  z-index: 60;
  width: 300px;
  max-width: calc(100vw - 40px);
}
.toast-item{
  background: #fff;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display:flex;
  gap: 10px;
  align-items:flex-start;
  animation: toastIn .18s ease;
}
.toast-item.update{ border-left-color: var(--gold); }
.toast-item .t-icon{
  font-size: 15px;
  line-height:1;
  margin-top: 1px;
}
.toast-item .t-body{ flex:1; min-width:0; }
.toast-item .t-title{ font-size: 12.5px; font-weight:600; color: var(--ink); }
.toast-item .t-sub{ font-size: 11.5px; color: var(--muted); margin-top:2px; }
.toast-item .t-close{
  border:none; background:none; color:#B7BBD0; font-size:16px; line-height:1; cursor:pointer;
}
.toast-item.leaving{ animation: toastOut .18s ease forwards; }
@keyframes toastIn{ from{ opacity:0; transform: translateX(16px);} to{ opacity:1; transform: translateX(0);} }
@keyframes toastOut{ from{ opacity:1; } to{ opacity:0; transform: translateX(16px);} }

/* ============ RESPONSIVE ============ */
@media (max-width: 1180px){
  .kpi-row{ grid-template-columns: repeat(3, 1fr); }
  .chart-row, .chart-row-3{ grid-template-columns: 1fr; }
}
@media (max-width: 860px){
  .sidebar{ display:none; }
  .kpi-row{ grid-template-columns: repeat(2, 1fr); }
  .content{ padding: 18px; }
  .topbar{ padding: 16px 18px; }
  .notif-panel{ width: 90vw; right: -60px; }
  .toast-stack{ right: 10px; left: 10px; width:auto; top: 10px; }
}
