:root {
  --black: #050507;
  --surface: #0c0c12;
  --surface-2: #12121b;
  --surface-3: #191927;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --ink: #f5f4f9;
  --ink-dim: #b7b4c4;
  --ink-faint: #767386;
  --violet: #7c6ff0;
  --violet-bright: #a398ff;
  --green: #34c77d;
  --amber: #f6c453;
  --red: #ff6b7a;
  --blue: #67d3ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Bricolage Grotesque", "Inter", sans-serif;
  --ease: cubic-bezier(0.16, 0.84, 0.44, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: var(--black);
}

body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(124, 111, 240, 0.12), transparent 34%),
    radial-gradient(circle at 85% 10%, rgba(103, 211, 255, 0.12), transparent 28%),
    var(--black);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

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

[hidden] {
  display: none !important;
}

::selection {
  background: var(--violet);
  color: white;
}

:focus-visible {
  outline: 2px solid var(--violet-bright);
  outline-offset: 3px;
}

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

.login-card,
.panel,
.stat-card,
.modal-card {
  border: 1px solid var(--line);
  background: rgba(12, 12, 18, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-card {
  width: min(100%, 390px);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
}

.login-card h1,
.section-head h1,
.topbar h2,
.modal-head h2 {
  font-family: var(--font-display);
  letter-spacing: 0;
}

.login-card h1 {
  margin-top: 16px;
  font-size: 30px;
}

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

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #8e7ff5, #4f89f9);
  color: white;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  box-shadow: 0 14px 34px rgba(124, 111, 240, 0.34);
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid var(--line);
  background: rgba(5, 5, 7, 0.86);
  padding: 22px;
  backdrop-filter: blur(20px);
}

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

.brand strong {
  display: block;
  font-family: var(--font-display);
  font-size: 20px;
}

.brand small,
.user-chip small {
  display: block;
  color: var(--ink-faint);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.nav-btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-dim);
  padding: 11px 12px;
  text-align: left;
  transition: background 180ms var(--ease), border-color 180ms var(--ease), color 180ms var(--ease);
}

.nav-btn:hover,
.nav-btn.is-active {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: white;
}

.sidebar-footer {
  display: grid;
  gap: 12px;
  margin-top: auto;
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 5, 7, 0.78);
  padding: 18px clamp(18px, 4vw, 36px);
  backdrop-filter: blur(20px);
}

.topbar h2 {
  font-size: 28px;
}

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

.user-chip {
  display: flex;
  min-width: 220px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
}

.avatar {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--violet-bright);
  font-weight: 700;
}

main {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 36px);
}

.view {
  display: none;
  animation: fade-up 420ms var(--ease) both;
}

.view.is-active {
  display: block;
}

.section-head,
.panel-head,
.toolbar,
.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-head {
  margin-bottom: 22px;
}

.section-head h1 {
  margin-top: 3px;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
}

.eyebrow {
  color: var(--violet-bright);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted {
  color: var(--ink-dim);
}

.small {
  font-size: 12px;
}

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

.stat-card {
  border-radius: var(--radius);
  padding: 18px;
}

.stat-card small {
  display: block;
  color: var(--ink-faint);
  font-size: 12px;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 1;
}

.panel {
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}

.panel-head {
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.panel-head h3 {
  font-family: var(--font-display);
  font-size: 20px;
}

.panel > p,
.panel > .field,
.panel > .btn,
.panel > .code-box {
  margin: 16px 18px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  color: var(--ink-faint);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

td {
  color: var(--ink-dim);
}

td strong {
  color: var(--ink);
}

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

.empty-row {
  color: var(--ink-faint);
  padding: 30px 16px;
  text-align: center;
}

.btn,
.icon-btn,
.text-btn,
.filter-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 180ms var(--ease), border-color 180ms var(--ease), background 180ms var(--ease), color 180ms var(--ease);
}

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  color: white;
  font-weight: 700;
}

.btn:hover,
.icon-btn:hover,
.text-btn:hover,
.filter-btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  border-color: rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, #8e7ff5, #4f89f9);
  box-shadow: 0 16px 34px rgba(124, 111, 240, 0.28);
}

.btn-ghost,
.icon-btn,
.filter-btn {
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  display: inline-grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  font-size: 12px;
}

.icon-btn {
  min-height: 36px;
  padding: 7px 10px;
}

.text-btn {
  border-color: transparent;
  background: transparent;
  color: var(--violet-bright);
  padding: 6px 8px;
}

#mobileNavBtn {
  display: none;
}

.toolbar {
  margin-bottom: 14px;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  padding: 4px;
}

.filter-btn {
  border-color: transparent;
  padding: 8px 11px;
  color: var(--ink-dim);
}

.filter-btn.is-active {
  background: var(--surface-3);
  color: white;
}

.input,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  min-height: 40px;
  padding: 9px 11px;
}

.select {
  min-width: 220px;
}

textarea.input {
  min-height: 120px;
  resize: vertical;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--ink-dim);
  font-size: 12px;
  font-weight: 700;
}

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

.field-full,
.modal-actions {
  grid-column: 1 / -1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.66);
  padding: 20px;
}

.modal-card {
  width: min(100%, 640px);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border-radius: var(--radius-lg);
  padding: 20px;
}

.modal-head {
  margin-bottom: 18px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge-neutral {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink-dim);
}

.badge-new {
  border-color: rgba(124, 111, 240, 0.22);
  background: rgba(124, 111, 240, 0.14);
  color: var(--violet-bright);
}

.badge-contacted {
  border-color: rgba(52, 199, 125, 0.22);
  background: rgba(52, 199, 125, 0.14);
  color: var(--green);
}

.badge-closed {
  border-color: rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-faint);
}

.badge-warn {
  border-color: rgba(246, 196, 83, 0.24);
  background: rgba(246, 196, 83, 0.14);
  color: var(--amber);
}

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

.action-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
}

.action-btn.danger {
  color: var(--red);
}

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

.template-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12, 12, 18, 0.82);
  padding: 16px;
}

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

.template-card h3 {
  font-family: var(--font-display);
  font-size: 20px;
}

.template-card p {
  color: var(--ink-dim);
}

.template-body {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim);
  padding: 11px;
  white-space: pre-wrap;
}

.automation-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.8fr);
  gap: 16px;
}

.automation-layout .panel:first-child {
  grid-row: span 2;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 700;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--violet);
}

.timeline {
  display: grid;
  gap: 0;
  padding: 10px 18px 18px;
}

.timeline article {
  position: relative;
  display: grid;
  gap: 4px;
  border-left: 1px solid var(--line);
  padding: 12px 0 14px 22px;
}

.timeline article:last-child {
  border-left-color: transparent;
}

.timeline-dot {
  position: absolute;
  left: -6px;
  top: 18px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--violet-bright);
  box-shadow: 0 0 0 5px rgba(124, 111, 240, 0.15);
}

.timeline small {
  color: var(--ink-faint);
}

.timeline p {
  color: var(--blue);
  font-size: 13px;
}

.code-box {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #07070b;
  color: var(--ink-dim);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  padding: 12px;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(18, 18, 27, 0.96);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 12px 14px;
}

.toast.is-error {
  border-color: rgba(255, 107, 122, 0.45);
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(82vw, 310px);
    transform: translateX(-104%);
    transition: transform 220ms var(--ease);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  #mobileNavBtn {
    display: inline-flex;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

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

  .automation-layout .panel:first-child {
    grid-row: auto;
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  body {
    font-size: 14px;
  }

  main {
    padding: 18px;
  }

  .topbar,
  .section-head,
  .toolbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .user-chip,
  .select {
    min-width: 0;
    width: 100%;
  }

  .stat-grid,
  .template-grid,
  .automation-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
  }

  .filter-btn {
    flex: 1;
  }

  .modal {
    padding: 12px;
  }
}
