:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-strong: #edf3f1;
  --text: #17211d;
  --muted: #64736d;
  --line: #d9e2de;
  --green: #16745d;
  --teal: #0f8b8d;
  --yellow: #b98309;
  --red: #ba3b46;
  --blue: #335c81;
  --shadow: 0 12px 28px rgba(23, 33, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: #17211d;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: #9ce0ce;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aebbb6;
  font-size: 13px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #c9d3cf;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  color: #c9d3cf;
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--yellow);
}

.status-dot.live {
  background: #35c487;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

h3 {
  font-size: 14px;
  letter-spacing: 0;
}

.actions {
  display: flex;
  gap: 10px;
  width: min(560px, 55vw);
}

.actions input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
}

.actions button,
.panel-head select,
.section-head button,
.auth-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.metric.urgent strong {
  color: var(--red);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.list-panel,
.detail-panel {
  min-height: calc(100vh - 188px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.section-head h3 {
  margin: 0;
}

.lead-list {
  display: grid;
  max-height: calc(100vh - 252px);
  overflow: auto;
}

.lead-item {
  display: grid;
  gap: 8px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.lead-item:hover,
.lead-item.active {
  background: var(--panel-strong);
}

.lead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lead-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-phone,
.lead-summary {
  color: var(--muted);
  font-size: 13px;
}

.lead-summary {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.4;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: #e7eef4;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.badge.quente {
  background: #f8e8ea;
  color: var(--red);
}

.badge.morno {
  background: #fbf0d7;
  color: var(--yellow);
}

.badge.frio {
  background: #e4f2ef;
  color: var(--green);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #e7eef4;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill.aberto {
  background: #f8e8ea;
  color: var(--red);
}

.status-pill.em_atendimento {
  background: #fbf0d7;
  color: var(--yellow);
}

.status-pill.resolvido {
  background: #e4f2ef;
  color: var(--green);
}

.status-pill.cancelado {
  background: #eef1f0;
  color: var(--muted);
}

.value-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #e4f2ef;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.lock-message {
  margin: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 18px;
  background: #fbf0d7;
  color: #664904;
  font-size: 13px;
  font-weight: 700;
}

.reopen-form {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(0, 1fr);
  gap: 10px;
  align-items: end;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  background: #fff9e8;
}

.handoff-body .reopen-form {
  border: 1px solid var(--line);
  border-radius: 8px;
}

.reopen-form label {
  display: grid;
  gap: 6px;
}

.reopen-form label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.reopen-form select,
.reopen-form input,
.reopen-form textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--text);
}

.reopen-form textarea {
  min-height: 72px;
  padding-top: 10px;
  resize: vertical;
}

.reopen-note {
  grid-column: 1 / -1;
}

.reopen-form button {
  grid-column: 1 / -1;
  width: fit-content;
  min-height: 40px;
  border: 1px solid var(--yellow);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--yellow);
  color: #ffffff;
}

.reopen-form button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.empty-state {
  display: grid;
  min-height: calc(100vh - 188px);
  place-content: center;
  padding: 32px;
  text-align: center;
}

.empty-state p {
  color: var(--muted);
}

.hidden {
  display: none;
}

.contact-detail {
  padding-bottom: 16px;
}

.detail-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-head h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.detail-grid div {
  min-height: 76px;
  padding: 14px;
  background: #ffffff;
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.text-block {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.text-block h3,
.timeline-section h3 {
  margin-bottom: 8px;
}

.text-block p {
  margin-bottom: 0;
  color: #35433e;
  line-height: 1.5;
  white-space: pre-wrap;
}

.source-panel {
  border-bottom: 1px solid var(--line);
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.source-grid div {
  min-height: 70px;
  padding: 14px;
  background: #ffffff;
}

.source-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.source-grid strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.source-wide {
  grid-column: span 3;
}

.source-panel.empty-source .value-pill {
  background: #eef3f1;
  color: var(--muted);
}

.handoff-panel {
  border-bottom: 1px solid var(--line);
}

.events-section {
  border-bottom: 1px solid var(--line);
}

.event-list {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
}

.event-empty {
  margin: 0;
  color: var(--muted);
}

.event-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.event-item.crm_handoff_updated,
.event-item.crm_handoff_reopened {
  border-left-color: var(--yellow);
}

.event-item.crm_lead_reopened,
.event-item.crm_pipeline_updated {
  border-left-color: var(--green);
}

.event-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.event-head strong {
  font-size: 14px;
}

.event-head span,
.event-details {
  color: var(--muted);
  font-size: 12px;
}

.event-item p {
  margin: 8px 0 0;
  color: #35433e;
  line-height: 1.45;
}

.event-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.event-details span {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef3f1;
}

.pipeline-panel {
  border-bottom: 1px solid var(--line);
}

.pipeline-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  padding: 16px 18px;
}

.pipeline-form label {
  display: grid;
  gap: 6px;
}

.pipeline-form label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.pipeline-form select,
.pipeline-form input,
.pipeline-form textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--text);
}

.pipeline-form textarea {
  min-height: 72px;
  padding-top: 10px;
  resize: vertical;
}

.pipeline-wide {
  grid-column: 1 / -1;
}

.pipeline-form button {
  width: fit-content;
  min-height: 40px;
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--green);
  color: #ffffff;
}

.pipeline-form button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.handoff-body {
  display: grid;
  gap: 14px;
  padding: 16px 18px;
}

.handoff-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 12px;
}

.handoff-meta div {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.handoff-meta span,
.handoff-form label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.handoff-meta strong {
  display: block;
  margin-top: 6px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.handoff-form {
  display: grid;
  grid-template-columns: 170px minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.handoff-form label {
  display: grid;
  gap: 6px;
}

.handoff-form select,
.handoff-form input,
.handoff-form textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--text);
}

.handoff-form textarea {
  min-height: 76px;
  padding-top: 10px;
  resize: vertical;
}

.handoff-note {
  grid-column: 1 / -1;
}

.handoff-form button {
  min-height: 40px;
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--green);
  color: #ffffff;
}

.handoff-form button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.pipeline-form input:disabled,
.pipeline-form select:disabled,
.pipeline-form textarea:disabled,
.handoff-form input:disabled,
.handoff-form select:disabled,
.handoff-form textarea:disabled {
  background: #f4f6f5;
  color: var(--muted);
  cursor: not-allowed;
}

.timeline {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
}

.message {
  border-left: 3px solid var(--teal);
  padding: 0 0 0 12px;
}

.message.handoff {
  border-left-color: var(--red);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.message p {
  margin: 7px 0;
  line-height: 1.45;
}

.message strong {
  color: var(--text);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--text);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 33, 29, 0.48);
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.auth-card h2 {
  margin-bottom: 8px;
  font-size: 24px;
}

.auth-card p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.45;
}

.auth-card input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.auth-actions button[type="submit"] {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    gap: 16px;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .topbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .metrics,
  .workspace {
    grid-template-columns: 1fr;
  }

  .handoff-form,
  .handoff-meta,
  .reopen-form,
  .source-grid,
  .pipeline-form {
    grid-template-columns: 1fr;
  }

  .source-wide {
    grid-column: span 1;
  }

  .list-panel,
  .detail-panel,
  .empty-state {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 16px;
  }

  .metrics,
  .detail-grid,
  .source-grid,
  .nav {
    grid-template-columns: 1fr;
  }

  .source-wide {
    grid-column: span 1;
  }

  .lead-list {
    max-height: none;
  }
}
