:root {
  color-scheme: dark;
  --bg: #090b0f;
  --panel: #12161d;
  --panel-2: #171d26;
  --line: #27313e;
  --text: #f3f7fb;
  --muted: #9aa7b8;
  --green: #14e59a;
  --yellow: #f6c453;
  --red: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #0d1016;
  min-width: 0;
  padding: 24px;
}

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

.brand.compact {
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: #04110c;
  font-weight: 900;
}

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

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

.sidebar nav {
  display: grid;
  gap: 8px;
  margin-top: 36px;
}

.sidebar a {
  border-radius: 8px;
  color: var(--muted);
  padding: 12px 14px;
}

.sidebar a.active,
.sidebar a:hover {
  background: var(--panel);
  color: var(--text);
}

.content {
  min-width: 0;
  padding: 32px;
}

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

.page-header h1 {
  font-size: 34px;
  line-height: 1.1;
  margin: 6px 0 0;
}

.page-subtitle {
  color: var(--muted);
  margin: 8px 0 0;
}

.eyebrow {
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  margin: 0;
  text-transform: uppercase;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.filters,
.control-bar {
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
}

.filters {
  grid-template-columns: 1fr 220px 220px 120px;
}

.task-filter {
  grid-template-columns: 220px 120px;
}

.control-bar {
  grid-template-columns: repeat(5, max-content);
}

.metrics article,
.table-wrap,
.details,
.crm-form,
.login-card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics article {
  padding: 18px;
}

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

.metrics strong {
  display: block;
  font-size: 30px;
  margin-top: 8px;
}

.report-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.report-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.report-card .section-title {
  margin-bottom: 18px;
}

.bar-row {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-row-meta {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.bar-row-meta span,
.muted {
  color: var(--muted);
}

.bar-track {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.bar-track span {
  background: var(--green);
  display: block;
  height: 100%;
}

.compact-table th,
.compact-table td {
  padding: 12px 0;
}

.compact-table th {
  background: transparent;
}

.table-wrap {
  overflow: visible;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 16px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

td small {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}

.contact-cell,
.lead-title {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 220px;
}

.lead-title {
  min-width: 0;
}

.lead-title small {
  color: var(--muted);
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.contact-avatar {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--green);
  display: inline-flex;
  flex: 0 0 auto;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  object-fit: cover;
  width: 42px;
}

.lead-title .contact-avatar {
  height: 56px;
  width: 56px;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
}

.badge.bot_active {
  background: rgba(20, 229, 154, .12);
  color: var(--green);
}

.badge.waiting_human,
.badge.human_active {
  background: rgba(246, 196, 83, .14);
  color: var(--yellow);
}

.badge.automation_disabled {
  background: rgba(255, 107, 107, .14);
  color: var(--red);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.row-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  white-space: nowrap;
}

.icon-action {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 11px;
}

.action-menu {
  position: relative;
}

.action-menu summary {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  height: 36px;
  justify-content: center;
  list-style: none;
  width: 40px;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.action-menu > div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .35);
  display: grid;
  gap: 6px;
  min-width: 150px;
  padding: 8px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
}

.menu-action {
  background: transparent;
  border: 0;
  color: var(--text);
  justify-content: flex-start;
  padding: 9px 10px;
  width: 100%;
}

.menu-action:hover {
  background: var(--panel);
}

.actions a,
.ghost-button,
.primary-button,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  padding: 10px 14px;
}

.ghost-button,
.actions a {
  background: var(--panel-2);
}

.primary-button,
button {
  background: var(--green);
  border-color: var(--green);
  color: #03120c;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.header-actions form {
  margin: 0;
}

.header-actions button {
  margin: 0;
  width: auto;
}

.details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
}

.timeline {
  margin-top: 24px;
}

.chat-panel {
  background: #0d1218;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 24px;
  overflow: hidden;
}

.chat-header {
  align-items: center;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
}

.chat-header small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.chat-messages {
  background:
    linear-gradient(rgba(9, 11, 15, .93), rgba(9, 11, 15, .93)),
    radial-gradient(circle at 18px 18px, rgba(154, 167, 184, .12) 1px, transparent 1px);
  background-size: auto, 36px 36px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 560px;
  min-height: 320px;
  overflow-y: auto;
  padding: 20px;
}

.chat-bubble {
  background: #1b232d;
  border-radius: 8px;
  max-width: min(72%, 720px);
  padding: 11px 13px;
}

.chat-bubble.bot,
.chat-bubble.human {
  align-self: flex-end;
  background: #075e48;
}

.chat-bubble.lead {
  align-self: flex-start;
}

.chat-bubble p {
  line-height: 1.45;
  margin: 7px 0 0;
  white-space: pre-wrap;
}

.chat-bubble .timeline-meta {
  font-size: 12px;
}

.chat-empty {
  align-self: center;
  color: var(--muted);
  margin: auto;
}

.chat-composer {
  align-items: end;
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 14px;
}

.chat-composer textarea {
  min-height: 48px;
  resize: vertical;
}

.chat-composer button {
  min-height: 48px;
}

.chat-help {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  margin: 0;
  padding: 0 14px 14px;
}

.conversations-content {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.conversations-page-header {
  flex: 0 0 auto;
}

.conversation-workspace {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  flex: 1;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 0;
  min-height: 0;
  overflow: hidden;
}

.conversation-list {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.conversation-search {
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.conversation-search input {
  width: 100%;
}

.conversation-list-scroll {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  align-items: center;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  display: flex;
  gap: 12px;
  min-height: 78px;
  padding: 13px 14px;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--panel-2);
}

.conversation-item.active {
  box-shadow: inset 3px 0 var(--green);
}

.conversation-item-body {
  min-width: 0;
  width: 100%;
}

.conversation-item-body > div {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.conversation-item-body strong,
.conversation-item-body p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item-body time {
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 11px;
}

.conversation-item-body p {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 0;
}

.conversation-list-empty {
  color: var(--muted);
  padding: 24px 16px;
  text-align: center;
}

.conversation-chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.conversation-chat .chat-header {
  flex: 0 0 auto;
}

.conversation-chat-messages {
  max-height: none;
  min-height: 0;
}

.conversation-placeholder {
  align-self: center;
  color: var(--muted);
  margin: auto;
  padding: 24px;
  text-align: center;
}

.conversation-placeholder strong {
  color: var(--text);
  font-size: 20px;
}

.pipeline-content {
  overflow: hidden;
}

.pipeline-search {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(260px, 560px) auto;
  margin-bottom: 20px;
}

.pipeline-search button {
  margin: 0;
  width: auto;
}

.kanban-board {
  display: grid;
  gap: 14px;
  grid-auto-columns: minmax(280px, 1fr);
  grid-auto-flow: column;
  overflow-x: auto;
  padding-bottom: 16px;
}

.kanban-column {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 520px;
  overflow: hidden;
}

.kanban-column > header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px;
}

.kanban-column h2 {
  font-size: 15px;
  margin: 0;
}

.kanban-column > header span {
  background: var(--panel-2);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
}

.kanban-cards {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.kanban-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.kanban-card-link {
  display: block;
}

.kanban-card p {
  font-size: 14px;
  margin: 12px 0 6px;
}

.kanban-card small {
  color: var(--muted);
}

.kanban-card form {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 10px;
}

.kanban-card select {
  font-size: 13px;
  padding: 9px 10px;
  width: 100%;
}

.kanban-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.sr-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0, 0, 0, 0);
}

.section-title {
  margin-bottom: 16px;
}

.section-title h2 {
  font-size: 24px;
  margin: 4px 0 0;
}

.timeline-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  max-width: 760px;
  padding: 16px;
}

.timeline-item.lead {
  background: #18202b;
}

.timeline-item.bot {
  background: rgba(20, 229, 154, .09);
  margin-left: auto;
}

.timeline-item.human {
  background: rgba(246, 196, 83, .11);
  margin-left: auto;
}

.timeline-item.admin {
  background: rgba(154, 167, 184, .1);
}

.timeline-meta {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.timeline-meta span,
.timeline-item small {
  color: var(--muted);
}

.timeline-item p {
  line-height: 1.5;
  margin: 12px 0;
  white-space: pre-wrap;
}

.detail-row {
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.detail-row:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.detail-row span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.detail-row strong {
  overflow-wrap: anywhere;
}

.login {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  margin: 0 auto;
  max-width: 420px;
  padding: 28px;
  width: 100%;
}

label {
  color: var(--muted);
  display: grid;
  gap: 8px;
}

input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 13px 14px;
}

select,
textarea {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 13px 14px;
}

textarea {
  line-height: 1.5;
  resize: vertical;
}

.crm-form {
  margin-bottom: 24px;
  padding: 18px;
}

.crm-form form {
  display: grid;
  gap: 14px;
}

.task-form {
  grid-template-columns: 1fr 240px 140px;
  margin-bottom: 18px;
}

button {
  font: inherit;
  margin-top: 18px;
  width: 100%;
}

.filters button,
.task-form button,
.control-bar button,
.actions button {
  margin-top: 0;
  width: auto;
}

.actions form {
  margin: 0;
}

.small-button {
  padding: 10px 12px;
}

.secondary {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

.danger {
  background: rgba(255, 107, 107, .14);
  border-color: rgba(255, 107, 107, .4);
  color: #ffb3b3;
}

.error {
  color: var(--red);
  font-weight: 700;
}

.notice {
  background: rgba(20, 229, 154, .12);
  border: 1px solid rgba(20, 229, 154, .35);
  border-radius: 8px;
  color: var(--green);
  font-weight: 700;
  margin: 0 0 18px;
  padding: 12px 14px;
}

.empty-state {
  padding: 28px;
}

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

  .sidebar {
    border-bottom: 1px solid var(--line);
    border-right: 0;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .metrics,
  .details,
  .report-grid,
  .filters,
  .task-form,
  .control-bar {
    grid-template-columns: 1fr;
  }

  .detail-row:nth-child(odd) {
    border-right: 0;
  }

  .table-wrap {
    overflow-x: auto;
  }

  .chat-header {
    align-items: flex-start;
    gap: 12px;
  }

  .chat-bubble {
    max-width: 88%;
  }

  .chat-composer {
    grid-template-columns: 1fr;
  }

  .pipeline-content {
    overflow: visible;
  }

  .pipeline-search {
    grid-template-columns: 1fr;
  }

  .conversations-content {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .conversation-workspace {
    flex: none;
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .conversation-list {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    max-height: 320px;
  }

  .conversation-chat {
    min-height: 600px;
  }
}
