:root {
  --ink: #161616;
  --muted: #666966;
  --paper: #f6f4ee;
  --panel: #ffffff;
  --line: #d9d4c7;
  --charcoal: #191a16;
  --mint: #69e6a6;
  --mint-dark: #14824b;
  --coral: #ff6b4a;
  --amber: #f7b733;
  --cyan: #4cc9d8;
  --violet: #5a3ca0;
  --danger: #be2f2f;
  --radius: 8px;
  --shadow: 0 20px 60px rgba(22, 22, 22, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

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

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

.admin-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100svh;
  padding: 24px;
  background: var(--charcoal);
  color: #fff;
}

.admin-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 900;
}

.admin-brand span {
  display: grid;
  place-items: center;
  width: 40px;
  aspect-ratio: 1;
  background: var(--mint);
  color: #111;
  border-radius: 8px;
}

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

.admin-nav a {
  padding: 12px 14px;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 800;
  border-radius: 7px;
}

.admin-nav a:hover,
.admin-nav a:focus-visible,
.admin-nav a.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  border-radius: var(--radius);
}

.sidebar-note strong,
.sidebar-note span {
  display: block;
}

.sidebar-note span {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.68);
  line-height: 1.5;
}

.admin-main {
  display: grid;
  gap: 20px;
  align-content: start;
  padding: 28px;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.admin-eyebrow {
  margin: 0 0 8px;
  color: var(--mint-dark);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

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

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  line-height: 1.1;
}

.topbar-actions,
.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.connection-pill,
.status-dot,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.connection-pill.is-connected,
.status-dot.is-connected {
  background: #eff9ed;
  color: var(--mint-dark);
  border-color: #cde9cc;
}

.ghost-button,
.primary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 7px;
  font-weight: 900;
  cursor: pointer;
}

.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.primary-button {
  padding: 0 16px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
}

.icon-button {
  width: 48px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
}

.wide-icon-button {
  width: auto;
  padding: 0 12px;
}

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 900;
  cursor: pointer;
  border-radius: 6px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

.metric-grid article,
.admin-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

.metric-grid article {
  min-height: 134px;
  padding: 20px;
}

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

.metric-grid span {
  color: var(--muted);
  font-weight: 800;
}

.metric-grid strong {
  margin-top: 18px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.9;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.65fr);
  gap: 20px;
}

.secondary-grid {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
}

.admin-panel {
  min-width: 0;
  padding: 20px;
}

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

.lead-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 190px;
  gap: 10px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

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

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 110px;
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(105, 230, 166, 0.32);
  border-color: var(--mint-dark);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

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

th {
  background: #faf8f2;
  color: #323330;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  color: var(--muted);
  line-height: 1.45;
}

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

.lead-name {
  display: grid;
  gap: 4px;
  color: var(--ink);
  font-weight: 900;
}

.lead-name small {
  color: var(--muted);
  font-weight: 700;
}

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

.row-actions button,
.row-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 900;
  cursor: pointer;
  border-radius: 6px;
}

.row-actions a {
  border-color: #cde9cc;
  background: #eff9ed;
  color: var(--mint-dark);
}

.empty-state {
  margin-top: 14px;
  padding: 18px;
  background: #faf8f2;
  color: var(--muted);
  font-weight: 800;
  border-radius: var(--radius);
}

.lead-form,
.whatsapp-form {
  display: grid;
  gap: 14px;
}

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

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

.meta-config > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  background: #faf8f2;
  border-radius: 7px;
}

.meta-config span,
.meta-config strong {
  display: block;
}

.meta-config span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.meta-config strong {
  margin-top: 7px;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.35;
}

.meta-config .meta-warning {
  border-color: #f3cf8b;
  background: #fff7df;
}

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

.api-side-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.api-status-card,
.test-card,
.payload-card {
  padding: 16px;
  background: #faf8f2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.api-status-card strong,
.test-card h3,
.payload-card strong {
  display: block;
  margin-bottom: 10px;
  font-size: 1rem;
}

.api-status-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.test-card {
  display: grid;
  gap: 12px;
}

.payload-card > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.payload-card pre {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  background: #111;
  color: var(--mint);
  font-size: 0.72rem;
  line-height: 1.55;
  white-space: pre-wrap;
  border-radius: 7px;
}

.qr-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  background: #faf8f2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.qr-panel strong {
  font-size: 1rem;
}

.qr-panel p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.qr-mock {
  position: relative;
  width: 150px;
  aspect-ratio: 1;
  background:
    linear-gradient(90deg, #111 12px, transparent 12px) 0 0 / 30px 30px,
    linear-gradient(#111 12px, transparent 12px) 0 0 / 30px 30px,
    #fff;
  border: 10px solid #fff;
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: 7px;
}

.qr-mock span {
  position: absolute;
  width: 34px;
  aspect-ratio: 1;
  background: #fff;
  border: 7px solid #111;
}

.qr-mock span:nth-child(1) {
  top: 10px;
  left: 10px;
}

.qr-mock span:nth-child(2) {
  top: 10px;
  right: 10px;
}

.qr-mock span:nth-child(3) {
  left: 10px;
  bottom: 10px;
}

.pipeline-list {
  display: grid;
  gap: 10px;
}

.pipeline-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  background: #faf8f2;
  border-radius: 7px;
}

.pipeline-item strong,
.pipeline-item span {
  display: block;
}

.pipeline-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.pipeline-count {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  background: var(--ink);
  color: var(--mint);
  font-weight: 900;
  border-radius: 7px;
}

.message-panel {
  margin-bottom: 28px;
}

.message-log {
  display: grid;
  gap: 10px;
}

.log-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #faf8f2;
  border-radius: 7px;
}

.log-entry b {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 8px;
  background: #eff9ed;
  color: var(--mint-dark);
  font-size: 0.72rem;
  border-radius: 6px;
}

.log-entry.is-error b {
  background: #fff0ed;
  color: var(--danger);
}

.log-entry.is-simulated b {
  background: #fff7df;
  color: #8a5d00;
}

.log-entry.is-inbound b {
  background: #e9f8ff;
  color: #08708a;
}

.log-entry strong,
.log-entry span {
  display: block;
}

.log-entry span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.log-entry time {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 80;
  max-width: min(360px, calc(100% - 28px));
  padding: 14px 16px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
  line-height: 1.45;
  border-radius: var(--radius);
}

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

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

  .admin-nav {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 940px) {
  .admin-main {
    padding: 18px;
  }

  .admin-topbar,
  .admin-grid,
  .secondary-grid,
  .meta-config,
  .whatsapp-layout {
    grid-template-columns: 1fr;
  }

  .admin-topbar {
    display: grid;
  }

  .metric-grid,
  .lead-tools {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .admin-main,
  .admin-sidebar {
    padding: 14px;
  }

  .admin-nav,
  .metric-grid,
  .lead-tools,
  .api-grid,
  .log-entry {
    grid-template-columns: 1fr;
  }

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

  .ghost-button,
  .primary-button,
  .connection-pill,
  .status-dot {
    width: 100%;
  }

  .toast {
    right: 14px;
    bottom: 14px;
  }
}
