:root {
  --ink: #1e2526;
  --muted: #657174;
  --line: #d7dfdf;
  --surface: #ffffff;
  --surface-soft: #f3f7f5;
  --brand: #0f766e;
  --brand-dark: #0b4f4a;
  --accent: #d97706;
  --shadow: 0 18px 40px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 24%),
    linear-gradient(180deg, #f8fbf9 0%, var(--surface-soft) 100%);
  font-family: "Segoe UI", "Trebuchet MS", Verdana, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button svg {
  width: 18px;
  height: 18px;
}

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

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

label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 750;
  color: #374245;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.6rem;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.25rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.primary {
  background: var(--brand);
  color: #fff;
  padding: 0 16px;
}

.primary:hover {
  background: var(--brand-dark);
}

.secondary {
  background: #edf2f1;
  color: var(--brand-dark);
  padding: 0 14px;
}

.secondary:hover {
  background: #dce8e4;
}

.big-action {
  min-height: 50px;
}

.full-width {
  width: 100%;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--brand-dark);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #eef2f1;
  color: #344043;
  font-size: 0.76rem;
  font-weight: 900;
  padding: 7px 10px;
}

.status-pill.good {
  background: #ddf3ee;
  color: var(--brand-dark);
}

.status-pill.warn {
  background: #fff1db;
  color: #8a5706;
}

.status-pill.bad {
  background: #fde7e5;
  color: #b42318;
}

.brand-logo {
  display: block;
  height: auto;
}

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.auth-logo {
  width: min(220px, 62%);
  margin: 0 auto 14px;
}

.auth-copy,
.auth-status,
.inline-status,
.helper-text,
.stack-item span,
.stack-item small,
.section-heading p,
.card-title span,
.message-meta {
  color: var(--muted);
}

.auth-form,
.settings-form,
.detail-form,
.wizard-form {
  display: grid;
  gap: 14px;
}

.auth-status,
.inline-status {
  margin: 0;
  font-weight: 700;
}

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

.sidebar {
  background: #183533;
  color: #eff7f4;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar .eyebrow,
.sidebar h1 {
  color: #eff7f4;
}

.sidebar-head {
  display: grid;
  gap: 10px;
}

.sidebar-logo {
  width: 150px;
  margin-bottom: 2px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  justify-content: flex-start;
  background: transparent;
  color: #d8ebe5;
  min-height: 46px;
  padding: 0 12px;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(255, 255, 255, 0.1);
}

.workspace {
  padding: 26px 24px 32px;
}

.workspace-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding: 6px 0 14px;
  background: linear-gradient(180deg, rgba(243, 247, 245, 0.96) 0%, rgba(243, 247, 245, 0.92) 78%, rgba(243, 247, 245, 0) 100%);
  backdrop-filter: blur(10px);
}

.topbar-title {
  margin-bottom: 0;
}

.topbar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-button {
  position: relative;
  width: 42px;
  min-width: 42px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand-dark);
}

.notification-count {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 999px;
  background: #b42318;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.notification-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(520px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 30;
}

.notification-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.notification-list {
  display: grid;
  gap: 12px;
  max-height: min(62vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.notification-group {
  display: grid;
  gap: 8px;
}

.notification-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: 2px;
}

.notification-group-head strong {
  font-size: 0.88rem;
}

.notification-group-head span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.notification-item {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    padding: 12px;
    border: 1px solid var(--line);
    background: #fbfcfd;
    display: grid;
    gap: 6px;
    align-content: start;
    overflow: hidden;
  }

.notification-item strong,
.notification-item span,
.notification-item small {
    display: block;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.35;
  }

.notification-item strong {
    font-size: 0.98rem;
    color: var(--text);
  }

.notification-item span {
    color: var(--text);
  }

.notification-item small {
    color: var(--muted);
  }

.view-panel {
  display: grid;
  gap: 18px;
}

.view-head,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stat-card-button {
  width: 100%;
  text-align: left;
}

.stat-card-button:hover {
  border-color: rgba(15, 118, 110, 0.35);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.08);
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-card strong {
  font-size: 1.8rem;
}

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

.pipeline-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.pipeline-item span {
  color: var(--muted);
  font-weight: 700;
}

.pipeline-item strong {
  font-size: 1.2rem;
}

.pipeline-item.is-hot {
  border-color: #f0c98a;
  background: #fff8ee;
}

.pipeline-item.is-followup {
  border-color: #bed9d3;
  background: #f3faf8;
}

.pipeline-item.is-won {
  border-color: #9ad6c9;
  background: #edf9f5;
}

.pipeline-item.is-lost {
  border-color: #f1c2bc;
  background: #fff5f4;
}

.dashboard-grid,
.database-grid,
.chat-grid,
.settings-grid-main {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.database-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.95fr);
  align-items: start;
}

.database-list-panel,
.detail-panel {
  max-height: calc(100vh - 132px);
  overflow: auto;
}

.stack-list,
.contact-list,
.thread-messages {
  display: grid;
  gap: 10px;
}

.chat-thread-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.stack-item,
.contact-card,
.message-bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.stack-item strong {
  display: block;
  margin-bottom: 4px;
}

.stack-item small {
  display: block;
  margin-top: 4px;
}

.database-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.selection-toolbar {
  display: grid;
  gap: 14px;
}

.selection-toolbar-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.selection-status-field {
  min-width: 220px;
}

.toolbar-panel {
  align-items: end;
}

.toolbar-panel label {
  display: grid;
  gap: 8px;
}

.chat-toolbar {
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, 0.9fr) auto;
}

.toolbar-actions {
  display: flex;
  justify-content: flex-end;
  align-items: end;
  gap: 10px;
  min-height: 100%;
}

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

.compact-stats .stat-card {
  min-height: 100px;
}

.chat-crm-form {
  display: grid;
  grid-template-columns: 160px 190px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.chat-side-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chat-note-card,
.chat-attachments-card,
.detail-attachments {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.attachment-upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.attachment-list {
  display: grid;
  gap: 8px;
}

.attachment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.attachment-item strong,
.attachment-item small {
  display: block;
}

.attachment-item small {
  color: var(--muted);
}

.chat-note-actions {
  display: flex;
  justify-content: flex-end;
}

.chat-next-action {
  min-width: 0;
}

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

.crm-shortcut {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.detail-panel {
  align-content: start;
}

.tight-heading {
  margin-top: 6px;
}

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

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

.detail-panel {
  position: sticky;
  top: 86px;
}

.list-hint {
  padding: 12px 14px 4px;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

.contact-card {
  display: grid;
  gap: 10px;
  border-left: 4px solid var(--brand);
  transition: border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
  align-content: start;
  padding: 14px;
}

.contact-card:hover {
  transform: translateY(-1px);
}

.selectable-card {
  width: 100%;
  text-align: left;
}

.selectable-card.active {
  border-color: var(--brand);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.12);
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.card-select-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card-select-main {
  display: flex;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.card-checkbox {
  width: 18px;
  min-width: 18px;
  min-height: 18px;
  margin-top: 4px;
}

.card-main {
  min-width: 0;
  display: grid;
  gap: 10px;
  flex: 1;
}

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

.card-inline-edit {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fbfa;
}

.card-meta-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
}

.card-meta-line {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.card-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.card-title strong {
  display: block;
  overflow-wrap: anywhere;
}

.lead-jump,
.lead-link-button {
  color: inherit;
  font: inherit;
  font-weight: 900;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.lead-jump:hover,
.lead-link-button:hover {
  color: var(--brand-dark);
}

.contact-preview {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  min-height: 2.6em;
}

.contact-card-meta {
  display: grid;
  gap: 4px;
}

.contact-card-meta span:nth-child(2) {
  font-size: 1rem;
}

.contact-card-meta span:nth-child(3) {
  color: var(--muted);
}

.contact-group-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.contact-group-heading small {
  font-size: 0.8rem;
  color: var(--muted);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  border-radius: 999px;
  background: #eef2f1;
  color: #344043;
  font-size: 0.74rem;
  font-weight: 900;
  padding: 4px 8px;
}

.badge.stop {
  background: #ddf3ee;
  color: var(--brand-dark);
}

.badge.bad {
  background: #fde7e5;
  color: #b42318;
}

.reply-badge {
  background: #fff1db;
  color: #8a5706;
}

.badge.fail {
  background: #fde7e5;
  color: #b42318;
}

.badge.action {
  background: #eef6ff;
  color: #1d4ed8;
}

.thread-messages {
  max-height: 700px;
  overflow: auto;
  padding-right: 4px;
  align-content: start;
  padding-top: 6px;
}

.chat-summary-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.reply-form {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #ffffff 22%);
}

.reply-form textarea {
  min-height: 160px;
  white-space: pre-wrap;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-reply {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.84rem;
}

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

.message-bubble {
  display: grid;
  gap: 8px;
  max-width: 88%;
  padding: 14px;
  box-shadow: 0 10px 22px rgba(17, 24, 39, 0.04);
}

.message-bubble.outgoing {
  justify-self: end;
  background: #eef8f6;
  border-color: #cfe9e4;
}

.message-bubble.incoming {
  justify-self: start;
  background: #fbfcfd;
}

.message-bubble.bounce {
  background: #fff5f4;
  border-color: #f1c2bc;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8rem;
}

.message-bubble p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.55;
}

.message-body {
  display: grid;
  gap: 10px;
}

.message-quote {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.message-quote summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}

.message-quote-content {
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.03);
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.5;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.small-form {
  max-width: 440px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
}

.secure-row {
  align-self: end;
  min-height: 42px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.wizard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 29, 37, 0.46);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 20;
}

.wizard-modal {
  width: min(720px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border: 1px solid rgba(32, 35, 38, 0.08);
  border-radius: 8px;
  box-shadow: 0 28px 60px rgba(18, 25, 38, 0.24);
  padding: 22px;
}

.wizard-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.wizard-step-label {
  margin-bottom: 0;
  color: var(--brand-dark);
  font-weight: 900;
}

.wizard-progress {
  height: 8px;
  border-radius: 999px;
  background: #ebefee;
  overflow: hidden;
}

.wizard-progress-bar {
  height: 100%;
  width: 20%;
  background: linear-gradient(90deg, var(--brand), #5ab4a0);
  transition: width 180ms ease;
}

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

.review-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fafcfb;
}

.review-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.bulk-modal {
  width: min(620px, 100%);
}

.bulk-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.bulk-summary div,
.bulk-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fafcfb;
}

.bulk-summary span,
.bulk-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.bulk-summary strong {
  font-size: 1.4rem;
}

.bulk-card {
  display: grid;
  gap: 6px;
}

.bulk-countdown {
  margin: 0;
  color: var(--brand-dark);
  font-weight: 700;
}

.draft-body-label textarea {
  min-height: 260px;
  white-space: pre-wrap;
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    padding-bottom: 16px;
  }

  .dashboard-grid,
  .database-grid,
  .chat-grid,
  .settings-grid-main,
  .stats-grid,
  .compact-stats,
  .database-toolbar,
  .detail-grid,
  .settings-grid,
  .pipeline-overview,
  .chat-crm-form,
  .card-inline-edit,
  .chat-side-tools {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions > * {
    width: 100%;
  }

  .detail-panel {
    position: static;
  }

  .database-list-panel,
  .detail-panel {
    max-height: none;
    overflow: visible;
  }

  .selection-toolbar-main,
  .selection-toolbar-actions,
  .attachment-upload-row,
  .card-select-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 700px) {
  .workspace {
    padding: 18px 16px 24px;
  }

  .view-head,
  .section-heading,
  .wizard-header,
  .workspace-topbar,
  .notification-panel-head,
  .chat-summary-card {
      flex-direction: column;
    }

    .notification-panel {
      right: 0;
      left: auto;
      width: min(420px, calc(100vw - 24px));
      max-width: calc(100vw - 24px);
    }

  .message-bubble {
    max-width: 100%;
  }

  .quick-replies,
  .reply-actions,
  .crm-shortcuts {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-actions button,
  .wizard-actions button,
  .full-width {
    width: 100%;
  }
}
