/* ============================================================
   Pipeline / Automations / Dashboard
   ============================================================ */
.view-scroll { height: 100%; overflow-y: auto; }
.view-pad { padding: 28px 32px 48px; max-width: 1340px; margin: 0 auto; }

/* Empty states (used across inbox, pipeline, automations, dashboard) */
.content > .empty-state { height: 100%; max-width: none; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 48px 24px; max-width: 460px; margin: 0 auto; }
.empty-state > * { max-width: 460px; }
.empty-state .es-icon { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--violet-50); color: var(--violet-600); margin-bottom: 10px; }
.empty-state .es-icon svg { width: 30px; height: 30px; }
.empty-state h3 { font-family: var(--font-display); font-weight: 800; font-size: 20px; color: var(--txt-900); }
.empty-state p { font-size: 14px; line-height: 1.6; color: var(--txt-500); font-weight: 500; margin-bottom: 14px; }

/* ---- Pipeline kanban ---- */
.kanban { display: flex; gap: 16px; padding: 24px; height: 100%; overflow-x: auto; align-items: flex-start; }
.kcol {
  flex: 0 0 300px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; max-height: 100%; min-height: 0; transition: border-color .2s, background .2s;
}
.kcol.drag-over { border-color: var(--violet-400); background: var(--violet-50); box-shadow: 0 0 0 3px var(--violet-50); }
.kcol-head { padding: 15px 16px 12px; display: flex; align-items: center; gap: 9px; }
.kcol-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.kcol-head .title { font-weight: 700; font-size: 13.5px; }
.kcol-head .count { background: var(--surface-2); color: var(--txt-500); font-size: 11.5px; font-weight: 800; padding: 2px 8px; border-radius: 99px; }
.kcol-head .sum { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--txt-500); }
.kcol-body { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }

.lead-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px;
  cursor: grab; transition: box-shadow .2s, transform .12s, border-color .2s; box-shadow: var(--shadow-sm);
}
.lead-card:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.lead-card:active { cursor: grabbing; }
.lead-card.dragging { opacity: .4; transform: rotate(1.5deg) scale(1.02); box-shadow: var(--shadow-lg); }
.flash { animation: flashring 1.4s var(--ease); }
@keyframes flashring { 0%,100% { box-shadow: var(--shadow-sm); } 25%,60% { box-shadow: 0 0 0 3px var(--violet-400), var(--shadow-md); } }
.lead-card .lc-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.lead-card .lc-name { font-weight: 700; font-size: 13.5px; }
.lead-card .lc-co { font-size: 11.5px; color: var(--txt-500); font-weight: 600; }
.lead-card .lc-value { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.lead-stage-select { max-width: 120px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--txt-700); padding: 5px 7px; font-size: 11.5px; font-weight: 700; }
.lead-card .lc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line); }
.lead-card .lc-foot .when { font-size: 11px; color: var(--txt-300); font-weight: 600; }
.kcol-add { margin: 0 10px 12px; padding: 9px; border-radius: 10px; border: 1.5px dashed var(--line-strong); color: var(--txt-300); font-weight: 600; font-size: 12.5px; display: flex; align-items: center; justify-content: center; gap: 6px; transition: all .15s; }
.kcol-add:hover { border-color: var(--violet-400); color: var(--violet-600); background: var(--violet-50); }
.kcol-add svg { width: 15px; height: 15px; }

/* ---- Automations ---- */
.auto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 18px; }
.auto-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; transition: box-shadow .2s, border-color .2s; }
.auto-card:hover { box-shadow: var(--shadow-md); }
.auto-head { padding: 18px 20px 14px; display: flex; align-items: flex-start; gap: 13px; }
.auto-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: 0 0 auto; }
.auto-icon svg { width: 21px; height: 21px; }
.auto-head .meta { flex: 1; min-width: 0; }
.auto-head .name { font-weight: 700; font-size: 15px; font-family: var(--font-display); }
.auto-head .desc { font-size: 12.5px; color: var(--txt-500); margin-top: 2px; line-height: 1.45; }

/* toggle */
.toggle { width: 42px; height: 24px; border-radius: 99px; background: var(--line-strong); position: relative; flex: 0 0 auto; transition: background .25s var(--ease); }
.toggle[aria-disabled="true"] { opacity: .68; }
.toggle::after { content:''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .25s var(--ease); }
.toggle.on { background: var(--violet-500); }
.toggle.on::after { transform: translateX(18px); }

.auto-flow { padding: 4px 20px 18px; }
.flow-trigger { display: flex; align-items: center; gap: 9px; font-size: 12.5px; font-weight: 700; color: var(--violet-600); background: var(--violet-50); border: 1px solid var(--violet-100); border-radius: 10px; padding: 9px 12px; }
.flow-trigger svg { width: 15px; height: 15px; flex: 0 0 auto; }
.flow-connector { width: 2px; height: 14px; background: var(--line-strong); margin-left: 18px; }
.flow-step { display: flex; align-items: flex-start; gap: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; line-height: 1.45; position: relative; }
.flow-step .num { width: 20px; height: 20px; border-radius: 6px; background: var(--ink-800); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; flex: 0 0 auto; margin-top: 1px; }
.flow-step .stext { flex: 1; }
.flow-step .delay { display: inline-block; font-size: 10.5px; font-weight: 700; color: var(--txt-300); margin-top: 4px; }
.flow-step .del { color: var(--txt-300); cursor: pointer; opacity: 0; transition: opacity .15s; }
.flow-step:hover .del { opacity: 1; }
.flow-step .del:hover { color: var(--rose); }
.flow-step .del svg { width: 15px; height: 15px; }
.add-step { display: flex; align-items: center; gap: 7px; margin-top: 12px; margin-left: 18px; font-size: 12.5px; font-weight: 700; color: var(--txt-500); padding: 7px 12px; border-radius: 9px; border: 1.5px dashed var(--line-strong); transition: all .15s; }
.add-step:hover { color: var(--violet-600); border-color: var(--violet-400); background: var(--violet-50); }
.add-step svg { width: 15px; height: 15px; }
.auto-stats { display: flex; gap: 22px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.auto-stat .num { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.auto-stat .lbl { font-size: 11px; color: var(--txt-500); font-weight: 600; }

/* ---- Dashboard ---- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 22px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; position: relative; overflow: hidden; }
.metric .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 14px; }
.metric .ico svg { width: 19px; height: 19px; }
.metric .val { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -.8px; line-height: 1; }
.metric .lbl { font-size: 12.5px; color: var(--txt-500); font-weight: 600; margin-top: 7px; }
.metric .delta { position: absolute; top: 20px; right: 20px; font-size: 11.5px; font-weight: 800; padding: 3px 8px; border-radius: 99px; display: flex; align-items: center; gap: 3px; }
.metric .delta svg { width: 11px; height: 11px; }
.delta.up { background: var(--mint-bg); color: #0e8a6c; }
.delta.down { background: var(--rose-bg); color: #c62a4a; }
.metric .spark { position: absolute; bottom: 0; left: 0; right: 0; height: 36px; opacity: .5; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-head h3 { font-family: var(--font-display); font-size: 16px; font-weight: 700; }
.panel-head .sub { font-size: 12.5px; color: var(--txt-500); }

.dash-2col { display: grid; grid-template-columns: 1.7fr 1fr; gap: 18px; }

.legend { display: flex; gap: 16px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--txt-500); }
.legend-item .sw { width: 10px; height: 10px; border-radius: 3px; }

.chan-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.chan-row:last-child { border-bottom: none; }
.chan-row .avatar svg { width: 14px; height: 14px; }
.chan-row .nm { flex: 1; font-weight: 700; font-size: 13px; }
.chan-row .bar-wrap { flex: 2; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.chan-row .bar { height: 100%; border-radius: 99px; }
.chan-row .pct { font-size: 12.5px; font-weight: 800; width: 42px; text-align: right; }

.lead-feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: center; }
.feed-item:last-child { border-bottom: none; }
.feed-item .avatar svg { width: 15px; height: 15px; }
.feed-item .ftext { flex: 1; font-size: 13px; }
.feed-item .ftext b { font-weight: 700; }
.feed-item .fwhen { font-size: 11px; color: var(--txt-300); font-weight: 600; }

/* chart */
.chart-area { position: relative; height: 260px; }
.chart-area svg { width: 100%; height: 100%; overflow: visible; }
.chart-tooltip { position: absolute; pointer-events: none; background: var(--ink-800); color: #fff; padding: 8px 11px; border-radius: 9px; font-size: 12px; font-weight: 600; opacity: 0; transform: translate(-50%, -120%); transition: opacity .12s; box-shadow: var(--shadow-md); white-space: nowrap; z-index: 5; }
.chart-tooltip b { color: var(--violet-400); }

@media (max-width: 1100px) {
  .dash-2col { grid-template-columns: 1fr; }
}

/* ---- Modal ---- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 16, 31, .42); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 200; animation: fadeIn .2s; padding: 20px; }
@keyframes fadeIn { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 440px; max-height: calc(100vh - 40px); box-shadow: var(--shadow-lg); animation: modalIn .3s var(--ease); overflow: auto; }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.modal-head { padding: 20px 22px 0; }
.modal-head h3 { font-family: var(--font-display); font-size: 18px; font-weight: 700; }
.modal-head p { font-size: 13px; color: var(--txt-500); margin-top: 3px; }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--txt-700); margin-bottom: 6px; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px; font-size: 13.5px; outline: none; transition: border-color .2s, box-shadow .2s; background: var(--surface); color: var(--txt-900); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--violet-400); box-shadow: 0 0 0 3px var(--violet-50); }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); }

@media (max-width: 1024px) {
  .inbox { grid-template-columns: 300px 1fr; }
  .context { display: none; }
}
@media (max-width: 760px) {
  :root { --sidebar-w: 60px; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .convlist { display: none; }
  .inbox.show-list .convlist { display: flex; }
  .inbox.show-list .thread { display: none; }
  .composer-tools { flex-wrap: wrap; }
  .thread-scroll { padding: 18px 16px; }
  .thread-back { display: grid !important; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .sub { display: none; }
  .searchbox { width: auto; flex: 1; min-width: 0; }
  .searchbox kbd { display: none; }
}
.thread-back { display: none; }
