:root {
  color-scheme: dark;
  --bg: #090d17;
  --bg-elevated: #11182a;
  --bg-panel: #0f1526;
  --border: rgba(94, 125, 255, 0.22);
  --border-strong: rgba(122, 149, 255, 0.42);
  --text: #eef2ff;
  --muted: #8b95b4;
  --primary: #6c7cff;
  --primary-2: #9c5bff;
  --success: #32d583;
  --warning: #ffb020;
  --danger: #ff5c7c;
  --teal: #11cdef;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(108, 124, 255, 0.16), transparent 22%),
    radial-gradient(circle at top right, rgba(17, 205, 239, 0.12), transparent 22%),
    var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(9, 13, 23, 0.92);
  border-bottom: 1px solid rgba(122, 149, 255, 0.18);
  backdrop-filter: blur(18px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-actions .icon-button {
  padding: 0.55rem 0.8rem;
  font-size: 0.86rem;
  border-radius: 12px;
  white-space: nowrap;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-mark {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #8a7dff;
}

.top-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-link,
.icon-button,
.primary-button,
.secondary-button,
.card-action,
.stage-action,
.close-button {
  border: 1px solid transparent;
  border-radius: 14px;
  transition: 0.2s ease;
}

.nav-link {
  background: transparent;
  color: var(--muted);
  padding: 0.75rem 1rem;
  text-decoration: none;
  display: inline-block;
}

.nav-link:hover,
.nav-link.is-active {
  color: var(--text);
  background: rgba(108, 124, 255, 0.14);
  border-color: rgba(108, 124, 255, 0.26);
}

.icon-button,
.primary-button,
.secondary-button,
.stage-action,
.card-action {
  padding: 0.8rem 1.1rem;
}

.icon-button,
.secondary-button,
.card-action,
.stage-action {
  color: var(--text);
  background: rgba(17, 24, 42, 0.9);
  border-color: rgba(122, 149, 255, 0.18);
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  border: none;
  box-shadow: 0 12px 28px rgba(108, 124, 255, 0.3);
}

.content {
  padding: 1.5rem;
}

.view-panel {
  display: none;
}

.view-panel.is-visible {
  display: block;
}

.hero-row,
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3vw, 2.6rem);
  margin-top: 0.35rem;
}

h2 {
  font-size: 1.3rem;
}

.eyebrow,
.field-label,
label span,
th {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: #7f89ab;
}

.muted {
  color: var(--muted);
}

.kpi-grid,
.dashboard-grid,
.board {
  display: grid;
  gap: 1rem;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 1rem;
}

.kpi-card,
.panel-card,
.column,
.modal-shell {
  background: linear-gradient(180deg, rgba(17, 24, 42, 0.98), rgba(13, 19, 34, 0.98));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi-card {
  padding: 1.2rem;
}

.kpi-card__value {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
}

.dashboard-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel-card {
  padding: 1.1rem;
}

.panel-card--wide {
  grid-column: 1 / -1;
}

.panel-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.stack-list,
.audit-list {
  display: grid;
  gap: 0.8rem;
}

.metric-item,
.audit-item,
.lead-card {
  border: 1px solid rgba(122, 149, 255, 0.14);
  border-radius: 18px;
  background: rgba(20, 29, 50, 0.92);
}

.metric-item,
.audit-item {
  padding: 0.95rem 1rem;
}

.metric-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.board {
  grid-template-columns: repeat(3, minmax(280px, 1fr));
  align-items: start;
}

.column {
  padding: 1rem;
  min-height: 280px;
}

.column__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.column__count {
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: rgba(108, 124, 255, 0.14);
  color: #cfd6ff;
}

.column__cards {
  display: grid;
  gap: 0.85rem;
}

.lead-card {
  padding: 1rem;
  display: grid;
  gap: 0.7rem;
}

.lead-card__header,
.lead-card__meta,
.lead-card__actions,
.audit-item__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.lead-card__meta,
.audit-item__meta {
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.badge,
.stage-pill,
.status-pill,
.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(122, 149, 255, 0.18);
  background: rgba(108, 124, 255, 0.12);
  color: #d8ddff;
  font-size: 0.8rem;
}

.stage-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.55rem;
}

.stage-pill {
  background: rgba(18, 25, 44, 0.96);
}

.stage-pill.is-selected {
  border-color: rgba(156, 91, 255, 0.7);
  background: rgba(156, 91, 255, 0.18);
}

.lead-card__actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.search-input,
label input,
label select,
textarea {
  width: 100%;
  background: rgba(19, 26, 45, 0.98);
  color: var(--text);
  border: 1px solid rgba(122, 149, 255, 0.15);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  outline: none;
}

textarea {
  resize: vertical;
}

.search-input:focus,
label input:focus,
label select:focus,
textarea:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(108, 124, 255, 0.15);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(5, 8, 14, 0.7);
  backdrop-filter: blur(10px);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-shell {
  width: min(100%, 560px);
  padding: 1.4rem;
  margin: auto 0;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-shell--large {
  width: min(100%, 900px);
  max-height: calc(100vh - 1.2rem);
}

.modal-header,
.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 1rem;
}

.close-button {
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  border: none;
}

.modal-form {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  padding-bottom: 0.25rem;
}

.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 0.4rem;
}

.followup-card {
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid rgba(122, 149, 255, 0.15);
  background: rgba(17, 24, 42, 0.85);
}

.table-shell {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.9rem 0.6rem;
  border-bottom: 1px solid rgba(122, 149, 255, 0.12);
}

td {
  color: #d7dcf4;
}

.empty-state {
  padding: 1.2rem;
  border-radius: 18px;
  border: 1px dashed rgba(122, 149, 255, 0.18);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1024px) {
  .dashboard-grid,
  .board {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .hero-row,
  .section-header,
  .modal-header,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .form-grid--two {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 1rem;
  }
}

/* ─── Utility ────────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ─── Login page ─────────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-shell {
  width: 100%;
  max-width: 440px;
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-brand {
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 1.5rem;
}

.login-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
}

.login-sub {
  margin: 0 0 2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-submit {
  width: 100%;
  margin-top: 0.5rem;
  justify-content: center;
}

.login-error {
  color: var(--danger);
  font-size: 0.875rem;
  background: rgba(255, 92, 124, 0.1);
  border: 1px solid rgba(255, 92, 124, 0.3);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
}

.login-hint {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  text-align: center;
  color: var(--muted);
}

/* ─── Topbar user pill ───────────────────────────────────────────────────────── */
.user-pill {
  font-size: 0.78rem;
  font-weight: 600;
  color: #ddd7ff;
  padding: 0.35rem 0.8rem;
  border: 1px solid rgba(156, 91, 255, 0.35);
  border-radius: 2rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

.user-pill--button {
  background: linear-gradient(135deg, rgba(108, 124, 255, 0.24), rgba(156, 91, 255, 0.26));
  color: #f2efff;
  gap: 0.45rem;
  box-shadow: 0 10px 24px rgba(108, 124, 255, 0.2);
}

.user-pill--button:hover {
  border-color: rgba(156, 91, 255, 0.6);
  background: linear-gradient(135deg, rgba(108, 124, 255, 0.35), rgba(156, 91, 255, 0.42));
  transform: translateY(-1px);
}

.user-pill__caret {
  font-size: 0.7rem;
  opacity: 0.95;
  color: #eadbff;
}

.user-menu {
  position: relative;
}

.user-menu__dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  min-width: 160px;
  border-radius: 12px;
  border: 1px solid rgba(156, 91, 255, 0.35);
  background: linear-gradient(180deg, rgba(30, 20, 56, 0.98), rgba(20, 15, 38, 0.98));
  box-shadow: 0 20px 40px rgba(80, 34, 143, 0.35);
  overflow: hidden;
  z-index: 20;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #f2efff;
  border: 0;
  padding: 0.75rem 0.9rem;
}

.menu-item:hover {
  background: linear-gradient(135deg, rgba(108, 124, 255, 0.28), rgba(156, 91, 255, 0.35));
  color: #ffffff;
}

/* ─── Danger card action ─────────────────────────────────────────────────────── */
.card-action--danger {
  color: var(--danger) !important;
}

.card-action--danger:hover {
  background: rgba(255, 92, 124, 0.12) !important;
  color: var(--danger) !important;
}

@media (max-width: 920px) {
  .brand-block,
  .topbar-actions {
    width: 100%;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .top-nav {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.2rem;
  }

  .top-nav .nav-link {
    white-space: nowrap;
  }
}

@media (max-width: 560px) {
  .topbar-actions .icon-button {
    width: 100%;
    text-align: center;
  }

  .icon-button {
    width: 100%;
    text-align: center;
  }

  .user-menu {
    width: 100%;
  }

  .user-pill--button {
    width: 100%;
    justify-content: space-between;
  }

  .user-menu__dropdown {
    left: 0;
    right: auto;
    width: 100%;
  }
}
