:root {
  --bg: #07111c;
  --bg-alt: #0d1b2a;
  --panel: rgba(16, 33, 50, 0.86);
  --panel-strong: rgba(22, 45, 67, 0.94);
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9f2ff;
  --muted: #97aec6;
  --accent: #5ee9c4;
  --accent-2: #88c8ff;
  --danger: #ff8da1;
  --warning: #ffcc7a;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 32px;
  display: grid;
  gap: 24px;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 12%, rgba(94, 233, 196, 0.12), transparent 28%),
    radial-gradient(circle at 82% 2%, rgba(136, 200, 255, 0.16), transparent 34%),
    linear-gradient(180deg, #061019 0%, #08121f 100%);
}

.home-banner {
  background: linear-gradient(135deg, rgba(94, 233, 196, 0.18), rgba(136, 200, 255, 0.22));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
}

.home-banner a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.home-banner a:hover {
  text-decoration: underline;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.03em;
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.refresh-notice,
.live-tray {
  display: grid;
  gap: 14px;
}

.refresh-notice {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.live-tray {
  position: sticky;
  top: 24px;
  z-index: 5;
}

.live-tray.minimized {
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  padding: 8px;
  justify-self: start;
}

.live-tray.minimized .section-head {
  margin: 0;
}

.live-tray.minimized .section-head > div:first-child,
.live-tray.minimized #liveTrayCount {
  display: none;
}

.live-tray.minimized .live-tray-actions {
  justify-content: flex-start;
}

.live-tray-actions {
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.live-tray-toggle {
  min-width: 96px;
}

.live-tray.minimized .live-tray-toggle {
  min-width: 0;
  white-space: nowrap;
}

.live-tray.minimized .live-tray-toggle.attention {
  background: linear-gradient(90deg, #f4c95d 0%, #f0ad2e 100%);
  color: #2f2000;
  border: 1px solid rgba(244, 201, 93, 0.58);
  box-shadow: 0 0 0 2px rgba(244, 201, 93, 0.26), 0 10px 24px rgba(240, 173, 46, 0.24);
}

.live-calls-list {
  display: grid;
  gap: 12px;
}

.live-call-card {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(94, 233, 196, 0.18);
  box-shadow: none;
  cursor: pointer;
}

.live-call-card:focus {
  outline: 2px solid rgba(94, 233, 196, 0.55);
  outline-offset: 2px;
}

.live-call-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.live-call-title {
  font-size: 18px;
  font-weight: 700;
}

.live-call-meta,
.live-call-duration {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.live-call-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.live-call-finish {
  border-color: rgba(255, 141, 161, 0.35);
  color: #ffd7de;
}

.crm-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.crm-layout.list-collapsed {
  grid-template-columns: 1fr;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(12px);
}

.contacts-card,
.detail-card {
  min-height: 720px;
}

.contacts-card {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.detail-card {
  min-height: 0;
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.detail-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.panel-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head.compact {
  margin: 0;
}

.section-copy {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.flex {
  display: flex;
  align-items: center;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(94, 233, 196, 0.35);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(94, 233, 196, 0.35); }
  70% { box-shadow: 0 0 0 14px rgba(94, 233, 196, 0); }
  100% { box-shadow: 0 0 0 0 rgba(94, 233, 196, 0); }
}

.stat-value {
  font-size: 34px;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
  font-size: 14px;
}

.text-input,
input,
select,
textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 16, 25, 0.55);
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

button,
.link-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border-radius: 12px;
  border: none;
  padding: 10px 14px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #08111b;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 10px 26px rgba(94, 233, 196, 0.2);
  transition: transform 0.12s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

button.secondary,
.link-button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: none;
}

button:hover,
.link-button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: default;
  opacity: 0.65;
  transform: none;
}

.contacts-list {
  display: grid;
  gap: 12px;
}

.archived-contacts-block {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 12px;
}

.archived-contacts-block .section-toggle {
  border: 1px solid rgba(255, 141, 161, 0.26);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 141, 161, 0.08);
}

.archived-contacts-block .panel-title {
  color: var(--danger);
}

.archived-contacts-block .section-copy {
  color: rgba(255, 188, 199, 0.86);
}

.section-toggle {
  width: 100%;
  padding: 0;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  box-shadow: none;
}

.section-toggle:hover {
  transform: none;
}

.section-toggle:focus-visible {
  outline: 2px solid rgba(136, 200, 255, 0.55);
  outline-offset: 6px;
}

.section-toggle-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}

.archived-contacts-block .section-toggle-icon {
  border-color: rgba(255, 141, 161, 0.24);
  background: rgba(255, 141, 161, 0.14);
  color: var(--danger);
}

.contact-item {
  width: 100%;
  text-align: left;
  display: grid;
  justify-content: start;
  align-content: start;
  justify-items: stretch;
  gap: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.contact-item.active {
  background: rgba(94, 233, 196, 0.11);
  border-color: rgba(94, 233, 196, 0.34);
}

.contact-item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.contact-item-title,
.detail-title,
.event-title {
  font-size: 18px;
  font-weight: 700;
}

.contact-item-subtitle,
.detail-meta,
.event-meta,
.phone-meta,
.inline-message,
.empty {
  color: var(--muted);
  font-size: 14px;
}

.contact-item-time {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.contact-item-meta,
.contact-item-summary {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.contact-item-summary {
  color: var(--text);
}

.contact-detail {
  display: grid;
  gap: 18px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.detail-empty {
  flex: 1 1 auto;
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
}

.detail-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.badge.call {
  background: rgba(136, 200, 255, 0.1);
  border-color: rgba(136, 200, 255, 0.35);
  color: var(--accent-2);
}

.badge.alert {
  background: rgba(255, 141, 161, 0.12);
  border-color: rgba(255, 141, 161, 0.36);
  color: var(--danger);
}

.badge.muted {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.09);
  color: var(--muted);
}

.profile-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.profile-form > * {
  min-width: 0;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span,
.subcard-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.follow-up-field {
  cursor: pointer;
}

.date-picker-shell {
  width: 100%;
  min-width: 0;
  border-radius: 12px;
}

input[type="datetime-local"] {
  min-width: 0;
  max-width: 100%;
}

.profile-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.merge-results,
.merge-summary-grid {
  display: grid;
  gap: 12px;
}

.merge-result-button {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  align-items: flex-start;
  display: grid;
  gap: 6px;
}

.merge-result-button.active {
  background: rgba(94, 233, 196, 0.11);
  border-color: rgba(94, 233, 196, 0.34);
}

.merge-result-title,
.merge-summary-name {
  font-weight: 700;
  color: var(--text);
}

.merge-result-meta,
.merge-summary-meta,
.merge-warning {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.merge-summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.merge-summary-card {
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 12px;
  background: rgba(8, 18, 29, 0.55);
  display: grid;
  gap: 8px;
}

.merge-summary-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.merge-selection {
  display: grid;
  gap: 12px;
}

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

.subcard {
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.phone-list,
.mailing-matches-list,
.timeline-list {
  display: grid;
  gap: 12px;
}

.phone-item {
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 12px;
  background: rgba(8, 18, 29, 0.55);
}

.phone-value {
  font-weight: 700;
}

.mailing-match-item {
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 12px;
  background: rgba(8, 18, 29, 0.55);
  display: grid;
  gap: 10px;
}

.mailing-match-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.mailing-match-identity {
  display: grid;
  gap: 4px;
}

.mailing-match-name {
  font-weight: 700;
}

.mailing-match-email,
.mailing-match-meta,
.mailing-match-notes-text {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.mailing-match-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mailing-match-notes {
  display: grid;
  gap: 6px;
}

.timeline-section {
  display: grid;
  gap: 12px;
}

.timeline-node {
  display: grid;
  gap: 12px;
}

.timeline-children {
  display: grid;
  gap: 12px;
  margin-left: 24px;
  padding-left: 18px;
  border-left: 2px solid rgba(136, 200, 255, 0.22);
}

.archived-timeline-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.timeline-item {
  display: grid;
  gap: 10px;
  border-radius: 16px;
  padding: 16px;
  background: var(--panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.timeline-item.nested {
  background: rgba(18, 38, 57, 0.88);
}

.timeline-item.link-source {
  border-color: rgba(244, 201, 93, 0.56);
  box-shadow: 0 0 0 2px rgba(244, 201, 93, 0.16);
}

.timeline-item.dragging {
  opacity: 0.55;
}

.timeline-item.drop-target {
  border-color: rgba(94, 233, 196, 0.6);
  box-shadow: 0 0 0 2px rgba(94, 233, 196, 0.26);
}

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

.call-purpose-editor {
  display: grid;
  gap: 6px;
}

.call-purpose-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.call-purpose-select {
  max-width: 360px;
}

.summary-text {
  line-height: 1.6;
  color: var(--text);
}

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

.subtle {
  font-size: 13px;
}

.notes-section {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: grid;
  gap: 10px;
}

.notes-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow-y: auto;
}

.note-item {
  background: rgba(94, 233, 196, 0.08);
  border-left: 2px solid rgba(94, 233, 196, 0.36);
  border-radius: 8px;
  padding: 10px 12px;
}

.note-item-text {
  margin-bottom: 5px;
  word-break: break-word;
}

.note-section {
  margin-bottom: 8px;
}

.note-section:last-child {
  margin-bottom: 0;
}

.note-section-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.note-section-body {
  white-space: pre-wrap;
  line-height: 1.5;
}

.note-item-time {
  color: var(--muted);
  font-size: 12px;
}

.note-input-group {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.note-input-group.stacked {
  display: grid;
}

.note-employee-select {
  min-width: 180px;
}

.conversation-thread {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.transcript-line {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.transcript-line:last-child {
  border-bottom: none;
}

.transcript-role {
  min-width: 88px;
  color: var(--accent-2);
  font-weight: 700;
  text-transform: capitalize;
}

.transcript-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  .crm-layout {
    grid-template-columns: 1fr;
  }

  .contacts-card {
    position: static;
    top: auto;
    max-height: none;
    overflow: visible;
  }

  .live-tray {
    position: static;
    top: auto;
  }

  .detail-card {
    position: static;
    top: auto;
    height: auto;
    max-height: none;
    overflow: visible;
    display: block;
  }
}

@media (max-width: 860px) {
  body {
    padding: 18px;
  }

  .refresh-notice {
    grid-template-columns: 1fr;
  }

  .page-header,
  .detail-top,
  .event-head {
    grid-template-columns: 1fr;
    display: grid;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .merge-summary-grid {
    grid-template-columns: 1fr;
  }

  .profile-form {
    grid-template-columns: 1fr;
  }

  .note-input-group {
    display: grid;
  }
}
