:root {
  --accent: #e8622a;
  --accent-light: #fff0e8;
  --accent-dark: #c44d18;
  --green: #2e9e6b;
  --green-light: #ebf8f2;
  --yellow: #f59e0b;
  --yellow-light: #fffbeb;
  --red: #dc2626;
  --red-light: #fef2f2;
  --blue: #4338ca;
  --blue-light: #eef2ff;
  --purple: #7c3aed;
  --purple-light: #f5f3ff;
  --text: #1a1a1a;
  --text-2: #555;
  --text-3: #888;
  --bg: #f7f6f4;
  --surface: #fff;
  --sidebar-bg: #fafaf9;
  --border: #e5e5e5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  --focus: 0 0 0 3px rgba(232, 98, 42, 0.18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  min-width: 320px;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

button,
select {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--surface);
  transform: translateY(-160%);
  transition: transform 0.15s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

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

h1 {
  margin-bottom: 4px;
  font-size: clamp(26px, 5vw, 32px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
  font-weight: 800;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.supporting-copy {
  margin-bottom: 0;
  color: var(--text-3);
  font-size: 14px;
}

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

.brand-lockup > span:last-child {
  display: grid;
  line-height: 1.2;
}

.brand-lockup strong {
  font-size: 15px;
  font-weight: 800;
}

.brand-lockup small {
  color: var(--text-3);
  font-size: 11px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent);
  color: var(--surface);
  font-weight: 900;
}

.login-page {
  display: grid;
  min-height: 100svh;
  padding: 24px;
  place-items: center;
}

.login-panel {
  display: grid;
  width: min(420px, 100%);
  gap: 24px;
  padding: 28px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.field {
  display: grid;
  min-width: 0;
  gap: 5px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.field small {
  color: var(--text-3);
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field textarea {
  min-height: 94px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.button,
.icon-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease;
}

.button:active,
.icon-button:active {
  transform: scale(0.98);
}

.button:disabled {
  opacity: 0.48;
  transform: none;
}

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.button--primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.button--secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button--secondary:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.button--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--accent-dark);
}

.button--ghost:hover {
  background: var(--accent-light);
}

.button--wide {
  width: 100%;
}

.button--compact {
  min-height: 40px;
  padding: 7px 12px;
}

.icon-button {
  width: 44px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
  font-size: 25px;
}

.icon-button:hover {
  background: var(--bg);
}

.security-note {
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12px;
}

.crm-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.account-menu {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
}

.account-name {
  max-width: 116px;
  overflow: hidden;
  color: var(--text-3);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 24px 18px 56px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(2, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.field--search {
  grid-column: span 1;
}

.filter-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.alert {
  margin: 0 0 18px;
  padding: 12px 16px;
  border-left: 3px solid var(--yellow);
  border-radius: var(--radius-sm);
  background: var(--yellow-light);
  color: #78350f;
  font-size: 14px;
}

.alert--danger {
  border-left-color: var(--red);
  background: var(--red-light);
  color: #991b1b;
}

.alert--success {
  border-left-color: var(--green);
  background: var(--green-light);
  color: #065f46;
}

.loading-list,
.loading-detail {
  display: grid;
  gap: 10px;
}

.loading-list span,
.loading-detail span {
  min-height: 72px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #ece8de, #f7f4ed, #ece8de);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.loading-detail span {
  min-height: 140px;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.empty-state {
  padding: 44px 20px;
  border-block: 1px solid var(--border);
  text-align: center;
}

.empty-state p {
  margin: 6px auto 0;
  color: var(--text-3);
  font-size: 14px;
}

.lead-table-head {
  display: none;
}

.leads-list {
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
  list-style: none;
}

.lead-item {
  position: relative;
  border-bottom: 1px solid var(--border);
}

.lead-item--new::before {
  position: absolute;
  top: 22px;
  left: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.lead-row {
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 88px;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  padding: 16px 8px 16px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 0.12s ease;
}

.lead-row:hover,
.lead-row:focus-visible {
  background: var(--surface);
}

.lead-contact,
.lead-cell {
  min-width: 0;
}

.lead-contact {
  display: grid;
  align-content: center;
  gap: 3px;
}

.lead-phone {
  overflow: hidden;
  font-size: 15px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-time,
.lead-secondary,
.lead-source,
.lead-conversion-copy {
  overflow: hidden;
  color: var(--text-3);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-stage {
  align-self: start;
  justify-self: end;
}

.lead-secondary {
  grid-column: 1 / -1;
}

.lead-source,
.lead-conversion-copy {
  display: none;
}

.badge {
  display: inline-flex;
  max-width: 100%;
  min-height: 24px;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}

.badge--neutral {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-2);
}

.badge--orange {
  background: var(--accent-light);
  color: var(--accent-dark);
}

.badge--green {
  background: var(--green-light);
  color: #065f46;
}

.badge--yellow {
  background: var(--yellow-light);
  color: #92400e;
}

.badge--red {
  background: var(--red-light);
  color: #991b1b;
}

.badge--blue {
  background: var(--blue-light);
  color: var(--blue);
}

.badge--purple {
  background: var(--purple-light);
  color: var(--purple);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 18px;
}

.pagination span {
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
}

.detail-view {
  animation: detail-enter 0.22s ease both;
}

@keyframes detail-enter {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.detail-header {
  margin-bottom: 18px;
}

.detail-back {
  margin: 0 0 12px -10px;
}

.detail-identity {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.detail-stage-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--text-3);
  font-size: 12px;
}

.detail-content {
  border-top: 1px solid var(--border);
}

.detail-columns {
  display: grid;
  gap: 0;
}

.detail-section {
  min-width: 0;
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}

.detail-section--actions {
  position: sticky;
  top: 66px;
  z-index: 10;
  padding-top: 18px;
  background: var(--bg);
}

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

.section-heading p {
  margin: 3px 0 0;
  color: var(--text-3);
  font-size: 12px;
}

.stage-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 3px 6px;
  scrollbar-width: thin;
}

.stage-actions .button {
  flex: 0 0 auto;
}

.data-list {
  margin: 0;
}

.data-row {
  display: grid;
  grid-template-columns: minmax(112px, 0.8fr) minmax(0, 1.3fr);
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}

.data-row:first-child {
  border-top: 0;
}

.data-row dt {
  color: var(--text-3);
  font-size: 12px;
}

.data-row dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 600;
}

.conversion-state {
  display: grid;
  gap: 8px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.conversion-state:first-child {
  padding-top: 0;
  border-top: 0;
}

.conversion-state p {
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.conversion-state__heading,
.conversion-attempt__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conversion-target {
  font-size: 13px;
}

.conversion-facts {
  margin: 0;
}

.conversion-fact {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(0, 1fr);
  gap: 10px;
  padding: 4px 0;
  font-size: 12px;
}

.conversion-fact dt {
  color: var(--text-3);
}

.conversion-fact dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.conversion-attempts {
  display: grid;
  gap: 7px;
  margin: 2px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
}

.conversion-attempt {
  display: grid;
  gap: 3px;
}

.conversion-attempt__title {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
}

.conversion-attempt__meta {
  color: var(--text-3);
  font-size: 11px;
}

.conversion-review {
  padding: 9px 11px;
  border-left: 3px solid var(--purple);
  border-radius: var(--radius-sm);
  background: var(--purple-light);
  color: var(--purple) !important;
  font-weight: 700;
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-item {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 0 0 20px 22px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  position: absolute;
  top: 6px;
  bottom: -6px;
  left: 5px;
  width: 1px;
  background: var(--border);
  content: "";
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-item::after {
  position: absolute;
  top: 5px;
  left: 1px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  content: "";
}

.timeline-stage {
  font-size: 13px;
  font-weight: 800;
}

.timeline-meta,
.timeline-comment {
  color: var(--text-3);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.stage-dialog {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100svh - 32px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
}

.stage-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.stage-dialog__panel {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.stage-dialog__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.stage-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (min-width: 720px) {
  .topbar {
    padding-inline: 28px;
  }

  .workspace {
    padding: 28px 28px 64px;
  }

  .filters {
    grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(140px, 1fr));
  }

  .filter-actions {
    grid-column: span 2;
  }

  .lead-table-head,
  .lead-row {
    grid-template-columns: minmax(190px, 1.25fr) minmax(130px, 0.85fr) minmax(140px, 1fr)
      minmax(130px, 1fr) minmax(110px, 0.75fr);
  }

  .lead-table-head {
    display: grid;
    gap: 16px;
    padding: 10px 14px;
    border-block: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-3);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .lead-item--new::before {
    left: 2px;
  }

  .lead-row {
    min-height: 68px;
    align-items: center;
    gap: 16px;
    padding: 11px 14px;
  }

  .lead-stage {
    align-self: center;
    justify-self: start;
  }

  .lead-secondary {
    grid-column: 3;
  }

  .lead-source,
  .lead-conversion-copy {
    display: block;
  }

  .detail-columns {
    grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr);
    gap: 36px;
  }

  .detail-section--actions {
    position: static;
  }
}

@media (min-width: 1040px) {
  .filters {
    grid-template-columns: minmax(230px, 2fr) repeat(5, minmax(120px, 1fr)) auto;
    align-items: end;
  }

  .filter-actions {
    grid-column: auto;
  }
}

@media (max-width: 719px) {
  .brand-lockup--compact small,
  .account-name {
    display: none;
  }

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

  .field--search,
  .filters .field:nth-child(2),
  .filters .field:nth-child(3),
  .filters .field:nth-child(4),
  .filter-actions {
    grid-column: 1 / -1;
  }

  .filter-actions .button {
    flex: 1;
  }

  .detail-identity {
    align-items: start;
  }
}

@media (max-width: 480px) {
  .login-page {
    padding: 0;
    background: var(--surface);
  }

  .login-panel {
    min-height: 100svh;
    align-content: center;
    padding: 28px 20px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .page-header {
    align-items: start;
  }

  .page-header .button {
    min-width: 44px;
    width: 44px;
    overflow: hidden;
    padding-inline: 0;
    color: transparent;
  }

  .page-header .button::before {
    color: var(--accent-dark);
    content: "↻";
    font-size: 19px;
  }

  .filters {
    padding: 14px;
  }

  .detail-identity {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-identity .button {
    width: 100%;
  }

  .data-row {
    grid-template-columns: minmax(96px, 0.75fr) minmax(0, 1.25fr);
  }

  .stage-dialog {
    width: 100%;
    max-height: calc(100svh - 24px);
    margin: auto 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .stage-dialog__panel {
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  }

  .stage-dialog__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
