:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #617087;
  --line: #dce4ef;
  --blue: #1767c2;
  --blue-dark: #0e4f96;
  --green: #138a5b;
  --yellow: #a76a00;
  --red: #b73535;
  --purple: #6b4bb7;
  --shadow: 0 18px 44px rgba(22, 38, 64, 0.12);
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.danger-action {
  color: var(--red) !important;
  border-color: #e4b1b1 !important;
  background: #fff6f6 !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 32px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.4rem, 3vw, 2rem); letter-spacing: 0; }
h2 { margin-bottom: 4px; font-size: 1.45rem; }
h3 { margin-bottom: 0; font-size: 1rem; }
.eyebrow {
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.header-actions, .toolbar, .modal-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #f9fbfe;
  font-size: 0.82rem;
  font-weight: 800;
}
.status-pill.is-live {
  color: var(--green);
  background: #e8f7ef;
  border-color: #b8e4cd;
}
.app-shell {
  display: grid;
  min-height: calc(100vh - 78px);
}
.sidebar {
  padding: 18px 16px;
  background: #0c2647;
  color: #dbeafe;
}
.brand {
  display: block;
  margin-bottom: 18px;
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}
.brand span {
  display: block;
  margin-top: 2px;
  color: #9fc7ef;
  font-size: 0.78rem;
  font-weight: 700;
}
.nav {
  display: grid;
  gap: 8px;
}
.nav-item {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  color: #dbeafe;
  background: transparent;
  text-align: left;
  font-weight: 800;
}
.nav-item.is-active, .nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.14);
}
.sidebar-note {
  margin-top: 22px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.08);
}
.sidebar-note p { margin: 6px 0 0; color: #b8d7f5; font-size: 0.9rem; }
.workspace {
  min-width: 0;
  padding: clamp(16px, 3vw, 32px);
}
.view { display: none; }
.view.is-active { display: block; }
.view-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.btn, .icon-btn, .text-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}
.btn {
  min-height: 42px;
  padding: 10px 14px;
}
.btn-primary {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}
.btn-primary:hover { background: var(--blue-dark); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  color: var(--blue);
  font-size: 1.15rem;
}
.text-btn {
  border: 0;
  color: var(--blue);
  background: transparent;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric {
  min-height: 74px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(22, 38, 64, 0.05);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.metric:hover, .metric:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 10px 26px rgba(22, 38, 64, 0.11);
  transform: translateY(-1px);
}
.metric span { color: var(--muted); font-size: 0.8rem; font-weight: 800; }
.metric strong { display: block; margin-top: 4px; font-size: 1.35rem; }
.dashboard-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}
.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.list { display: grid; gap: 10px; }
.list-item {
  display: grid;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
}
.list-item small { color: var(--muted); }
.filters {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}
.filters input, .filters select, .form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
}
.lead-filters { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.lead-filters > [data-search] { grid-column: span 2; }
.filter-date {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}
.filter-date input { min-height: 42px; }
.form-section-title {
  display: grid;
  gap: 3px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.form-section-title span { color: var(--muted); font-size: 0.82rem; }
.lead-quality {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid #e8c46a;
  border-left: 4px solid #b7791f;
  background: #fff9e8;
}
.lead-quality.is-spam {
  border-color: #e3a3a3;
  border-left-color: #b42318;
  background: #fff1f1;
}
.lead-quality span, .lead-quality small { color: var(--muted); }
.lead-summary-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #c8d7e8;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 8px 24px rgba(22, 38, 64, 0.06);
}
.lead-summary-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.lead-summary-main strong {
  display: block;
  font-size: 1.08rem;
}
.lead-summary-main span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 800;
}
.lead-summary-grid {
  display: grid;
  gap: 10px;
  margin: 0;
}
.lead-summary-grid div {
  min-width: 0;
}
.lead-summary-grid dt {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}
.lead-summary-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}
.job-panel {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #bcd7f4;
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  background: #f4f9ff;
}
.job-panel strong,
.job-panel span {
  display: block;
}
.job-panel span { margin-top: 3px; color: var(--muted); }
.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.job-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  color: var(--blue-dark);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 800;
  text-decoration: none;
}
.timeline {
  display: grid;
  gap: 8px;
}
.timeline-item {
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
}
.timeline-item span,
.timeline-item small {
  color: var(--muted);
}
.lead-section-title {
  margin-top: 0;
}
.lead-extra {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
}
.lead-extra summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}
.lead-extra summary::marker {
  color: var(--blue);
}
.lead-details-grid {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}
.spam-mark {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  background: #b42318;
  font-size: 0.75rem;
}
.spam-score { color: #b42318; font-size: 0.75rem; font-weight: 800; }
.form-grid textarea { min-height: 96px; resize: vertical; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}
th, td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  background: #f9fbfe;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eaf2ff;
  color: var(--blue-dark);
  font-size: 0.78rem;
  font-weight: 800;
}
.badge.green { background: #e8f7ef; color: var(--green); }
.badge.yellow { background: #fff4db; color: var(--yellow); }
.badge.red { background: #fdeaea; color: var(--red); }
.badge.purple { background: #f0ecff; color: var(--purple); }
.row-actions {
  display: flex;
  gap: 6px;
}
.row-actions button {
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--blue);
  font-weight: 800;
}
.site-actions {
  display: grid;
  gap: 7px;
}
.open-site-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  color: var(--blue);
  background: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}
.revenue-bars { display: grid; gap: 12px; }
.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 800;
}
.bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef7;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--blue);
}
.modal {
  width: min(760px, calc(100% - 28px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal.lead-modal {
  width: min(920px, calc(100% - 28px));
}
.modal::backdrop { background: rgba(12, 38, 71, 0.5); }
.modal-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
  margin: 0;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 0;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.form-grid {
  display: grid;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}
.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}
.modal-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  justify-content: flex-end;
  margin-top: 0;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 -10px 24px rgba(22, 38, 64, 0.08);
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #fff;
  background: #102f55;
  opacity: 0;
  transform: translateY(12px);
  transition: 0.2s ease;
  pointer-events: none;
}
.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: min(440px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.lead-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
.lead-form label, .settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}
.lead-form input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.form-note {
  margin: 0;
  color: var(--red);
  font-size: 0.92rem;
  font-weight: 800;
}
.access-form {
  display: grid;
  gap: 14px;
}
.access-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}
.access-form input,
.access-form select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.access-form fieldset {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.access-sites {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.access-sites label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}
.access-sites input {
  width: 18px;
  min-height: 18px;
}
.feature-settings {
  margin-top: 16px;
}
.feature-matrix {
  display: grid;
  gap: 14px;
}
.feature-site {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
}
.feature-site strong,
.feature-site small {
  display: block;
}
.feature-site small { margin-top: 3px; color: var(--muted); }
.feature-grid {
  display: grid;
  gap: 8px;
}
.feature-toggle {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.feature-toggle input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}
.feature-toggle span {
  min-width: 0;
}
.notification-status {
  margin-bottom: 14px;
  padding: 11px 13px;
  border: 1px solid #e8c46a;
  border-radius: var(--radius);
  color: #744f00;
  background: #fff7df;
  font-weight: 800;
}
.notification-status.is-success {
  border-color: #8bd2aa;
  color: var(--green);
  background: #e8f7ef;
}
[hidden] { display: none !important; }
@media (min-width: 760px) {
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .sidebar { min-height: calc(100vh - 78px); }
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters:not(.lead-filters) { grid-template-columns: minmax(260px, 1fr) 220px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .wide { grid-column: 1 / -1; }
  .lead-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lead-details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lead-details-grid .wide { grid-column: 1 / -1; }
  .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 12px;
  }
  .app-header h1 { font-size: 1.15rem; }
  .app-header .eyebrow { display: none; }
  .app-header, .view-heading { align-items: flex-start; flex-direction: column; }
  .header-actions, .toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .header-actions .status-pill { grid-column: 1 / -1; }
  .header-actions .btn,
  .toolbar .btn { width: 100%; }
  .modal {
    width: calc(100% - 12px);
    max-height: calc(100dvh - 12px);
  }
  .modal-card { max-height: calc(100dvh - 12px); }
  .form-grid {
    padding: 12px 12px calc(96px + env(safe-area-inset-bottom));
  }
  .modal-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px 12px calc(18px + env(safe-area-inset-bottom));
  }
  .modal-actions .btn {
    width: 100%;
    min-height: 48px;
  }
  .modal-actions .btn-primary { order: 2; }
  .job-panel {
    margin: -4px -4px 0;
    border-radius: 6px;
  }
  .job-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .job-action {
    min-width: 0;
    padding-inline: 6px;
    text-align: center;
  }
  .app-shell { display: block; }
  .sidebar {
    position: sticky;
    top: 124px;
    z-index: 15;
    padding: 8px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand, .sidebar-note { display: none; }
  .nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 11px;
    white-space: nowrap;
  }
  .workspace { padding: 12px 8px 28px; }
  .view-heading { gap: 10px; }
  .view-heading h2 { font-size: 1.45rem; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 70px; padding: 11px; }
  .metric strong { font-size: 1.25rem; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .panel { padding: 12px; }
  .filters { grid-template-columns: 1fr; }
  .lead-filters > [data-search] { grid-column: auto; }
  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }
  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  tbody {
    display: grid;
    gap: 10px;
  }
  tbody tr {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 5px 16px rgba(16, 47, 85, 0.06);
  }
  tbody td {
    display: grid;
    grid-template-columns: minmax(88px, 0.38fr) minmax(0, 1fr);
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
  }
  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  tbody td:last-child {
    border-bottom: 0;
  }
  tbody td.mobile-actions-cell {
    display: block;
  }
  tbody td.mobile-actions-cell::before {
    display: none;
  }
  .row-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .row-actions.single { grid-template-columns: 1fr; }
  .row-actions button {
    min-height: 42px;
  }
  .open-site-link {
    width: 100%;
    min-height: 42px;
  }
  .access-form {
    padding: 14px;
  }
  .access-form fieldset {
    padding: 10px;
  }
  .access-sites label {
    min-height: 42px;
    padding: 7px 5px;
    border-bottom: 1px solid var(--line);
  }
  .access-sites label:last-child {
    border-bottom: 0;
  }
  .list-item {
    gap: 6px;
    padding: 11px 0;
  }
  .list-item .text-btn {
    min-height: 40px;
    margin-top: 5px;
    text-align: left;
  }
  .modal {
    width: 100%;
    max-height: calc(100dvh - 4px);
    margin: auto 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .toast {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
  }
}

@media (max-width: 340px) {
  .header-actions {
    grid-template-columns: 1fr;
  }
  .header-actions .status-pill {
    grid-column: auto;
  }
  .metric-grid {
    grid-template-columns: 1fr;
  }
  tbody td {
    grid-template-columns: 82px minmax(0, 1fr);
  }
}
