:root {
  --bg: #f3f6f4;
  --panel: #ffffff;
  --ink: #07130f;
  --muted: #64746d;
  --line: #dbe4df;
  --deep: #06231c;
  --green: #00a967;
  --green-soft: #e3f7ee;
  --warn: #9a5b00;
  --danger: #a9281f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select {
  font: inherit;
}

.hidden { display: none !important; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #06231c 0%, #071923 48%, var(--bg) 48%);
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(2, 32, 23, .14);
}

.brand-logo {
  display: block;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: 0 8px 22px rgba(2, 32, 23, .18);
}

.login-logo {
  width: 42px;
  height: 42px;
  margin-bottom: 18px;
}

.login h1 {
  margin: 0;
  font-size: 24px;
}

.login p {
  margin: 8px 0 22px;
  color: var(--muted);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 14px;
}

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  min-height: 40px;
  padding: 9px 14px;
  font-weight: 900;
  cursor: pointer;
}

.ghost {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  color: #fff;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.error {
  display: block;
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

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

.app.sidebar-collapsed {
  grid-template-columns: 76px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  background: #071923;
  color: #fff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.1);
}

.app.sidebar-collapsed .sidebar {
  overflow: hidden;
}

.side-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.side-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
}

.side-title {
  min-width: 0;
  flex: 1;
}

.app.sidebar-collapsed .side-header {
  justify-content: center;
  padding: 16px;
}

.app.sidebar-collapsed .side-logo,
.app.sidebar-collapsed .side-title,
.app.sidebar-collapsed .filters,
.app.sidebar-collapsed .side-footer,
.app.sidebar-collapsed .logout-button {
  display: none;
}

.side-header strong,
.side-header span {
  display: block;
}

.side-header span {
  color: rgba(255,255,255,.58);
  margin-top: 3px;
  font-size: 12px;
}

.filters {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.side-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.logout-button {
  width: 100%;
}

.filters input,
.filters select {
  border-color: rgba(255,255,255,.14);
  background: rgba(255,255,255,.08);
  color: #fff;
}

.filters option {
  color: var(--ink);
}

.refresh-button {
  width: 100%;
  background: var(--green);
}

.refresh-note {
  color: rgba(255,255,255,.54);
  font-size: 12px;
  line-height: 1.35;
}

.row-meta,
.row-last {
  color: rgba(255,255,255,.62);
  font-size: 12px;
  margin-top: 5px;
  line-height: 1.35;
}

.messages-panel .row-meta {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 900;
  color: #063b2a;
  background: var(--green-soft);
}

.badge.transferred { color: #704000; background: #fff1d5; }
.badge.disqualified { color: #7f2018; background: #ffe9e6; }
.badge.qualified { color: #063b2a; background: #dff7ed; }

.workspace {
  min-width: 0;
  min-height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lead-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.lead-header h2 {
  margin: 0;
  font-size: 20px;
}

.lead-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.lead-table-section {
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.lead-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faf8;
  color: var(--muted);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.lead-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.lead-table td strong,
.lead-table td span {
  display: block;
}

.lead-table td span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.lead-table-row {
  cursor: pointer;
}

.lead-table-row:hover,
.lead-table-row.active {
  background: #edf8f2;
}

.last-message {
  max-width: 520px;
  color: #263831;
  line-height: 1.35;
}

.empty-table {
  color: var(--muted);
  text-align: center;
  padding: 22px;
}

.lead-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.secondary-button {
  background: #fff;
  color: var(--deep);
  border: 1px solid var(--line);
}

.lead-actions a {
  color: var(--deep);
  background: var(--green-soft);
  text-decoration: none;
  font-weight: 900;
  border-radius: 6px;
  padding: 10px 12px;
}

.content-grid {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.messages-panel {
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

.messages {
  max-width: 920px;
  display: grid;
  gap: 12px;
}

.message {
  max-width: 76%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(2,32,23,.06);
}

.message.outbound {
  margin-left: auto;
  background: var(--green-soft);
  border-color: #bfead8;
}

.message.internal {
  max-width: 100%;
  background: #fff8e8;
}

.message-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 14px;
}

.details {
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #fff;
  padding: 18px;
}

.details section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.details section:last-child {
  border-bottom: 0;
}

.details h3 {
  margin: 0 0 12px;
  font-size: 14px;
}

dl {
  margin: 0;
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 8px 10px;
  font-size: 13px;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
  min-width: 0;
}

pre {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  background: #f7faf8;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
  white-space: pre-wrap;
}

.kv {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.event {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

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

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

  .app.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .app.sidebar-collapsed .sidebar {
    min-height: 64px;
  }

  .app.sidebar-collapsed .side-header {
    justify-content: flex-end;
  }


  .details {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
