:root {
  --ink: #17181c;
  --muted: #6c7078;
  --line: #dde0e5;
  --paper: #fbfaf8;
  --surface: #ffffff;
  --nav: #191b22;
  --accent: #ba3f2f;
  --accent-dark: #8f2f24;
  --green: #28735a;
  --blue: #315c96;
  --amber: #9b6a1a;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(30, 31, 35, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--ink);
  background: #f2f0ec;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
}

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

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

button {
  cursor: pointer;
}

.admin-body {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 22px;
  color: #f6f2ea;
  background:
    linear-gradient(180deg, rgba(25, 27, 34, 0.92), rgba(25, 27, 34, 0.98)),
    url("https://images.unsplash.com/photo-1524995997946-a1c2e315a42f?auto=format&fit=crop&w=1200&q=80") center / cover;
}

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

.brand-large {
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 0.8rem;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 38px;
}

.nav a,
.nav-disabled,
.logout-form button {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.72);
}

.nav a:hover,
.nav a.is-active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.nav-disabled {
  opacity: 0.42;
}

.logout-form {
  margin-top: auto;
}

.logout-form button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.admin-main {
  min-width: 0;
  padding: 28px clamp(18px, 4vw, 54px) 54px;
}

.admin-header,
.panel-title,
.public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.admin-header {
  margin-bottom: 26px;
}

.kicker {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.28rem;
}

.header-link,
.text-button,
.ghost-button,
.danger-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  white-space: nowrap;
  font-weight: 800;
}

.header-link,
.text-button,
.ghost-button {
  color: var(--blue);
}

.header-link,
.text-button {
  padding: 0 4px;
}

.primary-button {
  padding: 0 15px;
  border: 0;
  color: #fff;
  background: var(--accent);
}

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

.ghost-button,
.danger-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.9rem;
}

.danger-button {
  color: var(--danger);
}

.flash {
  margin-bottom: 18px;
  padding: 13px 15px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.flash-success {
  color: var(--green);
  border-color: rgba(40, 115, 90, 0.3);
}

.flash-error {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.28);
}

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

.stat-card,
.panel,
.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 124px;
  padding: 20px;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 18px;
  font-size: 2.3rem;
  line-height: 1;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.72fr);
  gap: 18px;
}

.panel {
  padding: 22px;
}

.module-list,
.run-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.module-row,
.run-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 68px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.module-row p,
.run-row small,
td small,
.empty-state {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.run-row {
  justify-content: flex-start;
}

.status-dot {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
}

.status-success {
  background: var(--green);
}

.status-failed {
  background: var(--danger);
}

.status-running,
.status-queued {
  background: var(--amber);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--muted);
  background: #f1f2f4;
  font-size: 0.78rem;
  font-weight: 900;
}

.badge-green,
.badge-active,
.badge-success,
.badge-info,
.badge-qualified,
.badge-converted {
  color: var(--green);
  background: rgba(40, 115, 90, 0.12);
}

.badge-draft,
.badge-queued,
.badge-running,
.badge-warning,
.badge-new,
.badge-to_follow {
  color: var(--amber);
  background: rgba(155, 106, 26, 0.14);
}

.badge-paused,
.badge-muted,
.badge-archived {
  color: var(--muted);
  background: #eff0f2;
}

.badge-contacted {
  color: var(--blue);
  background: rgba(49, 92, 150, 0.12);
}

.badge-failed {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.12);
}

.badge-error {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.12);
}

.badge-ready,
.badge-installed {
  color: var(--green);
  background: rgba(40, 115, 90, 0.12);
}

.badge-planned {
  color: var(--blue);
  background: rgba(49, 92, 150, 0.12);
}

.table-wrap {
  width: 100%;
  margin-top: 18px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 15px 12px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

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

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

label {
  display: grid;
  gap: 8px;
  color: #30323a;
  font-weight: 800;
}

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(49, 92, 150, 0.18);
  border-color: var(--blue);
}

.field-error {
  color: var(--danger);
}

.field-help {
  color: var(--muted);
  font-weight: 600;
  line-height: 1.45;
}

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

.export-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

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

.readonly-grid div {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f6;
}

.readonly-grid strong,
.readonly-grid span {
  display: block;
}

.readonly-grid strong {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.readonly-grid span {
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px 170px 150px auto;
  gap: 14px;
  align-items: end;
  margin-top: 20px;
}

.contacts-filter-bar {
  grid-template-columns: minmax(260px, 1fr) 190px 150px 150px 150px auto;
}

.log-filter-bar {
  grid-template-columns: 220px 220px auto;
}

.table-meta,
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.sort-link {
  display: inline-flex;
  color: var(--muted);
}

.sort-link:hover {
  color: var(--blue);
}

.contact-detail-row td {
  padding: 0 12px 18px;
  background: #fafafa;
}

.contact-detail-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.contact-detail-panel div {
  min-width: 0;
}

.contact-detail-panel strong,
.contact-detail-panel span {
  display: block;
}

.contact-detail-panel strong {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.contact-detail-panel span {
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.contact-detail-wide {
  grid-column: 1 / -1;
}

.pagination {
  justify-content: flex-end;
}

.pagination .is-active {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.pagination .is-disabled {
  pointer-events: none;
  opacity: 0.46;
}

.duplicate-empty {
  margin-top: 18px;
}

.duplicate-list {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

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

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

.duplicate-group-head h3 {
  margin: 10px 0 4px;
}

.duplicate-group-head small {
  color: var(--muted);
  font-weight: 700;
}

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

.duplicate-card {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
}

.duplicate-card.is-recommended {
  border-color: rgba(40, 115, 90, 0.38);
  background: rgba(40, 115, 90, 0.06);
}

.duplicate-card-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 900;
}

.duplicate-card-radio input {
  width: auto;
}

.duplicate-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.duplicate-card dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.duplicate-card dd {
  min-height: 20px;
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.privacy-note {
  margin-top: 18px;
  padding: 13px 15px;
  border: 1px solid rgba(155, 106, 26, 0.24);
  border-radius: 8px;
  color: #6f4d17;
  background: rgba(155, 106, 26, 0.1);
  line-height: 1.5;
}

.import-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.55fr);
  gap: 18px;
  align-items: start;
}

.import-upload,
.import-help {
  display: grid;
  gap: 16px;
}

.import-help {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f6;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-list span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #30323a;
  background: #ffffff;
  border: 1px solid var(--line);
  font-size: 0.84rem;
  font-weight: 800;
}

.mapping-table td {
  min-width: 210px;
}

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

.connector-card {
  display: flex;
  flex-direction: column;
  min-height: 210px;
}

.connector-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.connector-card p,
.help-panel p,
.timeline p,
.tool-list p,
.note-grid p {
  color: var(--muted);
  line-height: 1.55;
}

.connector-card .text-button {
  margin-top: auto;
  justify-content: flex-start;
}

.timeline,
.path-list,
.settings-list,
.tool-list,
.note-grid {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

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

.path-row,
.settings-list div,
.tool-list article,
.note-grid article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.path-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

code {
  display: inline-block;
  max-width: 100%;
  color: #354255;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.settings-list {
  margin-bottom: 0;
}

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

.settings-list dt {
  color: var(--muted);
  font-weight: 800;
}

.settings-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.help-panel pre {
  margin: 18px 0;
  padding: 16px;
  overflow-x: auto;
  border-radius: 8px;
  color: #f7f3ec;
  background: #17181c;
}

.help-panel pre code {
  color: inherit;
}

.note-grid,
.tool-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.endpoint-box {
  display: grid;
  gap: 8px;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid rgba(49, 92, 150, 0.22);
  border-radius: 8px;
  background: rgba(49, 92, 150, 0.08);
}

.endpoint-box span {
  color: var(--muted);
  font-weight: 800;
}

.token-box {
  margin-top: 18px;
}

.connector-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 14px;
  margin-top: 18px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.inline-form label {
  min-width: 170px;
}

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

.brevo-audience-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.brevo-audience-grid > article {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.brevo-audience-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brevo-audience-head h3 {
  margin-bottom: 0;
}

.brevo-sync-help {
  max-width: 900px;
  margin: 12px 0 0;
}

.brevo-list-create-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.brevo-list-create-grid .form-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.token-row input {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.help-steps {
  display: grid;
  gap: 12px;
  margin: 18px 0 0;
  padding-left: 22px;
  color: #30323a;
  line-height: 1.55;
}

.auth-body {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(25, 27, 34, 0.72), rgba(25, 27, 34, 0.12)),
    url("https://images.unsplash.com/photo-1456324504439-367cee3b3c32?auto=format&fit=crop&w=1800&q=80") center / cover;
}

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

.login-panel {
  width: min(100%, 460px);
  padding: 30px;
}

.login-panel h1 {
  margin-bottom: 12px;
}

.login-panel p {
  color: var(--muted);
  line-height: 1.55;
}

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

.public-shell {
  min-height: 100vh;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(20, 22, 28, 0.62), rgba(20, 22, 28, 0.84)),
    url("https://images.unsplash.com/photo-1519389950473-47ba0277781c?auto=format&fit=crop&w=2200&q=80") center / cover;
}

.public-header {
  padding: 22px clamp(18px, 5vw, 70px);
}

.public-header a {
  font-weight: 800;
}

.public-hero {
  width: min(780px, 100%);
  padding: clamp(70px, 13vw, 150px) clamp(18px, 5vw, 70px);
}

.public-hero h1 {
  margin-bottom: 20px;
  font-size: clamp(2.6rem, 7vw, 5.7rem);
}

.public-hero p {
  max-width: 620px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 1.15rem;
  line-height: 1.65;
}

@media (max-width: 960px) {
  .admin-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
  }

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

  .logout-form {
    margin-top: 22px;
  }

  .stats-grid,
  .split-grid,
  .form-grid,
  .filter-bar,
  .contacts-filter-bar,
  .import-grid,
  .readonly-grid,
  .connector-grid,
  .timeline,
  .note-grid,
  .tool-list,
  .brevo-audience-grid,
  .brevo-list-create-grid,
  .contact-detail-panel,
  .duplicate-cards,
  .duplicate-card dl {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .admin-header,
  .panel-title,
  .public-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-grid {
    gap: 10px;
  }

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

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

  .duplicate-group-head {
    flex-direction: column;
  }

  .token-row {
    grid-template-columns: 1fr;
  }

  .connector-actions,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }
}
