:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ece8df;
  --ink: #222421;
  --muted: #6d716a;
  --line: #ded8cd;
  --brand: #156f6c;
  --brand-2: #0f5754;
  --accent: #b5532a;
  --good: #21784d;
  --warn: #9d6b12;
  --danger: #aa3434;
  --shadow: 0 16px 40px rgba(44, 39, 31, 0.09);
}

* {
  box-sizing: border-box;
}

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

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(246, 244, 239, 0.96);
}

.access-gate[hidden] {
  display: none;
}

.access-box {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.access-brand {
  color: var(--ink);
}

.access-brand span {
  color: var(--muted);
}

.access-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: #2f3431;
  color: #f6f4ef;
}

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

.brand strong {
  display: block;
  font-size: 17px;
}

.brand span {
  color: #bbc4ba;
  font-size: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f4c458;
  color: #1d211f;
  font-weight: 800;
}

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

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  padding: 10px;
  background: transparent;
  color: #e9eee7;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 700;
  font-size: 12px;
}

.safety-strip {
  margin-top: auto;
  padding: 12px;
  border-radius: 8px;
  background: rgba(244, 196, 88, 0.16);
  border: 1px solid rgba(244, 196, 88, 0.28);
}

.safety-strip strong,
.safety-strip span {
  display: block;
}

.safety-strip span {
  margin-top: 4px;
  color: #d9ded6;
  font-size: 12px;
  line-height: 1.35;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button,
.icon-button,
.segment,
.chip-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-2);
}

.secondary-button,
.chip-button {
  border-color: var(--line);
}

.icon-button {
  width: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-color: var(--line);
  font-weight: 800;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 82px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 27px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-2);
}

.segment {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(41, 37, 29, 0.08);
}

.compact .segment {
  padding: 0 10px;
}

.search,
input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label textarea,
label select {
  color: var(--ink);
  font-size: 14px;
}

.checkbox-label {
  display: flex;
  grid-template-columns: none;
  align-items: flex-start;
  gap: 9px;
  line-height: 1.35;
}

.checkbox-label input {
  width: 18px;
  min-width: 18px;
  height: 18px;
  margin-top: 1px;
}

.lead-layout {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.lead-list,
.connector-list,
.outbox-list,
.logs-list {
  display: grid;
  gap: 10px;
}

.lead-card,
.connector-card,
.outbox-card,
.log-row,
.panel,
.detail-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lead-card {
  padding: 13px;
  display: grid;
  gap: 10px;
}

.lead-card.active {
  border-color: var(--brand);
}

.lead-card h3,
.detail-pane h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.lead-meta,
.card-actions,
.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.badge.good {
  color: #fff;
  background: var(--good);
}

.badge.warn {
  color: #fff;
  background: var(--warn);
}

.badge.danger {
  color: #fff;
  background: var(--danger);
}

.lead-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.detail-pane,
.panel {
  padding: 16px;
}

.detail-pane {
  min-height: 390px;
}

.detail-grid {
  display: grid;
  gap: 14px;
}

.detail-section {
  display: grid;
  gap: 6px;
}

.detail-section p {
  color: var(--muted);
  line-height: 1.5;
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.source-layout,
.profile-grid,
.agent-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 14px;
  align-items: start;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.connector-card,
.outbox-card,
.log-row {
  padding: 13px;
}

.connector-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.connector-card p,
.outbox-card p,
.log-row p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.connector-foot {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.outbox-card {
  display: grid;
  gap: 10px;
}

.draft-body {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfaf7;
  white-space: pre-wrap;
  line-height: 1.48;
}

.rule-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.rule {
  padding: 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.rule.ok {
  border-left: 4px solid var(--good);
}

.rule.warn {
  border-left: 4px solid var(--warn);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #2f3431;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

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

  .nav-item {
    justify-content: center;
    padding: 9px 6px;
  }

  .nav-item span:last-child,
  .safety-strip {
    display: none;
  }

  .workspace {
    padding: 14px;
  }

  .metrics,
  .lead-layout,
  .source-layout,
  .profile-grid,
  .agent-layout {
    grid-template-columns: 1fr;
  }

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

  .top-actions {
    width: 100%;
  }

  .top-actions .primary-button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .segment {
    min-width: 0;
  }

  .connector-card {
    grid-template-columns: 1fr;
  }
}
