/* =========================================================
   TP CRM — protótipo v0.1 (refinamento visual)
   Paleta: #1F4E79 (marinho) · #2E75B6 (azul) · #D9E1F2 (azul-claro)
   ========================================================= */
:root {
  --navy: #1F4E79;
  --navy-deep: #173c5e;
  --blue: #2E75B6;
  --blue-soft: #e8f0fa;
  --light: #D9E1F2;
  --light-2: #EDF2FA;
  --ink: #1c2733;
  --muted: #66788d;
  --line: #dde5f2;
  --bg: #f5f7fc;
  --card: #ffffff;
  --wa: #1faa53;
  --ig: #C13584;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(23, 43, 77, .06);
  --shadow-md: 0 1px 2px rgba(23, 43, 77, .06), 0 4px 12px rgba(23, 43, 77, .08);
  --shadow-lg: 0 8px 28px rgba(23, 43, 77, .16);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--light); }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 22px 20px 18px;
}
.brand-mark {
  background: #fff;
  color: var(--navy);
  font-weight: 800;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 15px;
  letter-spacing: .5px;
  box-shadow: var(--shadow-sm);
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: .3px; }

.nav { display: flex; flex-direction: column; gap: 3px; padding: 8px 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  background: none;
  border: none;
  color: #c9dcf3;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 650; }
.nav-item:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: #fff;
}
.nav-icon { width: 21px; text-align: center; font-size: 15px; opacity: .92; }
.nav-badge {
  margin-left: auto;
  background: #ff5a5a;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
  line-height: 1.4;
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 20px;
  font-size: 11px;
  color: #8ba6c9;
  line-height: 1.6;
}

/* ---------- Conteúdo ---------- */
.content { flex: 1; padding: 30px 34px; max-width: 1320px; min-width: 0; }
.view { display: none; }
.view.active { display: block; animation: viewIn .22s var(--ease-out); }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 23px; color: var(--navy); letter-spacing: -.2px; font-weight: 750; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { font-size: 15px; color: var(--navy); margin-bottom: 16px; font-weight: 700; letter-spacing: -.1px; }

/* ---------- Dashboard ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--blue);
  opacity: .85;
}
.kpi-label {
  display: block;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 31px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Barras de origem (CSS puro) */
.bars { padding-top: 4px; }
.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.bar-row:last-child { margin-bottom: 2px; }
.bar-label { width: 92px; font-size: 13px; font-weight: 600; color: var(--ink); flex-shrink: 0; }
.bar-track {
  flex: 1;
  background: var(--light-2);
  border-radius: 999px;
  height: 20px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 999px; transition: width .45s var(--ease-out); }
.bar-fill.wa { background: linear-gradient(90deg, #27c468, var(--wa)); }
.bar-fill.ig { background: linear-gradient(90deg, #d64a97, var(--ig)); }
.bar-count {
  width: 30px;
  text-align: right;
  font-weight: 750;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.recent-list { list-style: none; }
.recent-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 6px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  border-radius: 8px;
  transition: background .12s;
}
.recent-list li:last-child { border-bottom: none; }
.recent-list li:hover { background: var(--light-2); }
.recent-name { font-weight: 650; font-size: 13.5px; }
.recent-list li:hover .recent-name { color: var(--blue); }
.recent-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- Kanban ---------- */
.kanban {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  align-items: start;
}
.kanban-col {
  background: var(--light-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 340px;
  transition: background .15s, border-color .15s;
}
.kanban-col.dragover {
  background: var(--blue-soft);
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}
.col-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 2px 4px 0;
  font-weight: 750;
  color: var(--navy);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.col-count {
  background: var(--navy);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  font-variant-numeric: tabular-nums;
}
.kcard {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 10px;
  padding: 13px 14px;
  margin-bottom: 10px;
  cursor: grab;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s var(--ease-out), transform .18s var(--ease-out), opacity .18s var(--ease-out);
}
.kcard:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kcard:active { cursor: grabbing; transform: scale(.99); }
.kcard.dragging { opacity: .45; transform: rotate(1.5deg); }
.kcard.temp-frio { border-left-color: #7fb3e0; }
.kcard.temp-morno { border-left-color: #f0ad4e; }
.kcard.temp-quente { border-left-color: #d9534f; }
.kcard.temp-comprou { border-left-color: #3d9a3d; }
.kcard-name { font-weight: 700; font-size: 14px; margin-bottom: 3px; letter-spacing: -.1px; }
.kcard-interest { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; line-height: 1.45; }
.kcard-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}
.chan { font-weight: 700; display: inline-flex; align-items: center; gap: 5px; }
.chan::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}
.chan.whatsapp { color: var(--wa); }
.chan.instagram { color: var(--ig); }

/* ---------- Caixa de entrada ---------- */
.inbox {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  height: calc(100vh - 170px);
  min-height: 500px;
  box-shadow: var(--shadow-sm);
}
.inbox-list { border-right: 1px solid var(--line); overflow-y: auto; background: #fbfcfe; }
.conv {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  gap: 12px;
  transition: background .12s;
  border-left: 3px solid transparent;
}
.conv:hover { background: var(--light-2); }
.conv.active { background: var(--blue-soft); border-left-color: var(--blue); }
.conv:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.conv-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-name { font-weight: 700; font-size: 13.5px; letter-spacing: -.1px; }
.conv-time { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.conv-preview {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}
.conv-unread {
  background: var(--blue);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 6px;
  line-height: 1.5;
}
.inbox-thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head {
  padding: 15px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  font-size: 14.5px;
}
.thread-empty-hint { color: var(--muted); font-weight: 400; font-size: 13px; }
.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 20% 30%, rgba(46,117,182,.045) 0, transparent 45%),
    var(--bg);
}
.msg {
  max-width: 72%;
  padding: 10px 14px 8px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
}
.msg .msg-time { display: block; font-size: 10.5px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg.lead { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.ia { background: #dbe7f7; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.human { background: #d9ecd9; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .msg-from { display: block; font-size: 10.5px; font-weight: 700; color: var(--navy); margin-bottom: 2px; }
.thread-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}
.thread-actions .btn.on { background: #fff6e0; border-color: #f0ad4e; color: #8a6d00; }
.thread-composer {
  display: flex;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.thread-composer input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 13.5px;
  background: var(--bg);
}
.thread-composer input:focus { outline: 2px solid var(--blue); border-color: var(--blue); background: #fff; }

/* ---------- Botões ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  transition: background .15s var(--ease-out), border-color .15s var(--ease-out), box-shadow .15s var(--ease-out), transform .12s var(--ease-out);
  white-space: nowrap;
}
.btn:hover { background: var(--light-2); border-color: #c3d0e6; }
.btn:active { transform: scale(.97); transition-duration: .1s; }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--navy); border-color: var(--navy); }
.btn-ghost { background: #fff; }

/* ---------- Leads ---------- */
.leads-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.leads-toolbar input,
.leads-toolbar select {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.leads-toolbar input:focus,
.leads-toolbar select:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.leads-toolbar input { flex: 1; }
.leads-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.leads-table thead th {
  text-align: left;
  padding: 11px 14px;
  color: var(--navy);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 2px solid var(--line);
  background: #fbfcfe;
  position: sticky;
  top: 0;
}
.leads-table thead th:first-child { border-radius: 10px 0 0 0; }
.leads-table thead th:last-child { border-radius: 0 10px 0 0; }
.leads-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.leads-table tbody tr { cursor: pointer; transition: background .12s; }
.leads-table tbody tr:hover { background: var(--blue-soft); }
.leads-table tbody tr:last-child td { border-bottom: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 11px;
  text-transform: capitalize;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.frio { background: #e3effb; color: #2b5f8f; }
.pill.morno { background: #fdf0dc; color: #a86a00; }
.pill.quente { background: #fbe3e1; color: #b02a25; }
.pill.comprou { background: #ddf0dd; color: #2c7a2c; }

.tag {
  display: inline-block;
  background: var(--light-2);
  border: 1px solid var(--line);
  color: var(--navy);
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 10px;
  margin: 1px 4px 1px 0;
  white-space: nowrap;
}

/* ---------- Drawer do lead ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 43, 77, .45);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fadeIn .18s var(--ease-out);
}
/* O display definido no CSS anula o atributo hidden: regra global para esconder */
[hidden] { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: 430px;
  max-width: 94vw;
  height: 100vh;
  height: 100dvh;
  background: #fff;
  z-index: 50;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slideIn .28s var(--ease-drawer);
}
@keyframes slideIn { from { transform: translateX(48px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--navy), var(--navy-deep));
  color: #fff;
}
.drawer-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.1px; }
.drawer-head .btn-ghost {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  border-radius: 8px;
  padding: 7px 12px;
}
.drawer-head .btn-ghost:hover { background: rgba(255,255,255,.22); }
.drawer-body { padding: 22px; overflow-y: auto; flex: 1; }
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 4px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 750;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 6px;
}
.field .field-value { font-size: 14px; }
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  min-height: 76px;
  line-height: 1.5;
}
.field textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.tag-input-row { display: flex; gap: 8px; margin-top: 8px; }
.tag-input-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
}
.tag-input-row input:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.tag .tag-x { cursor: pointer; margin-left: 6px; color: var(--blue); font-weight: 700; }
.hist-item {
  border-left: 3px solid var(--light);
  padding: 7px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
  background: #fbfcfe;
  border-radius: 0 8px 8px 0;
}
.hist-item .hist-from { font-weight: 700; color: var(--navy); font-size: 11.5px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1000px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: repeat(2, 1fr); }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox-list { max-height: 320px; border-right: none; border-bottom: 1px solid var(--line); }
}

/* ---------- Celular: barra inferior, tabela vira cartões ---------- */
@media (max-width: 640px) {
  body { padding-bottom: 82px; }
  .content { padding: 16px 14px; }
  .page-head h1 { font-size: 20px; }

  /* Sidebar vira barra de abas fixa embaixo */
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0; top: auto;
    width: 100%; height: auto;
    flex-direction: row;
    z-index: 60;
    background: var(--navy-deep);
    border-top: 1px solid rgba(255,255,255,.14);
    box-shadow: 0 -4px 16px rgba(23, 43, 77, .18);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .brand, .sidebar-footer { display: none; }
  .nav { flex-direction: row; padding: 6px 4px; width: 100%; gap: 2px; }
  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 600;
    padding: 9px 2px 7px;
    text-align: center;
    align-items: center;
  }
  .nav-item.active::before { display: none; }
  .nav-item.active { background: rgba(255,255,255,.16); }
  .nav-icon { width: auto; font-size: 18px; }
  .nav-badge { margin: 0; position: absolute; top: 3px; right: calc(50% - 24px); }

  /* Kanban em 1 coluna */
  .kanban { grid-template-columns: 1fr; }

  /* Tabela de leads vira cartões */
  .leads-toolbar { flex-wrap: wrap; }
  .leads-toolbar input { min-width: 180px; }
  .leads-table thead { display: none; }
  .leads-table, .leads-table tbody { display: block; width: 100%; }
  .leads-table tbody tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 16px;
    box-shadow: var(--shadow-sm);
  }
  .leads-table tbody tr:hover { background: var(--card); }
  .leads-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--line);
    text-align: right;
  }
  .leads-table td:last-child { border-bottom: none; }
  .leads-table td::before {
    content: attr(data-label);
    font-size: 10.5px;
    font-weight: 750;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    text-align: left;
    flex-shrink: 0;
  }

  /* Cartão do lead ocupa a tela toda */
  .drawer { width: 100vw; max-width: 100vw; }

  .inbox { min-height: 0; }
  .msg { max-width: 85%; }
}

/* ---------- Movimento reduzido: respeita a preferência do usuário ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
