:root {
  --bg: #f7f9fc;
  --panel: #f4f7fa;
  --line: #dde3ea;
  --text: #17202a;
  --muted: #687382;
  --brand: #1f8a5b;
  --brand-dark: #176846;
  --danger: #b42318;
  --warn: #9a6700;
  --ok: #067647;
  --info: #175cd3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--brand-dark);
}

button.secondary,
button.ghost {
  background: #e8edf2;
  color: var(--text);
}

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

button.small {
  padding: 6px 9px;
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: white;
  color: var(--text);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

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

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f6f8fa;
  padding: 20px;
}

.login-card {
  width: min(390px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(23, 32, 42, 0.08);
}

.login-card h1,
.topbar h1 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

.muted {
  color: var(--muted);
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

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

.brand small {
  display: block;
  color: var(--muted);
}

nav {
  display: grid;
  gap: 5px;
}

.nav-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
}

a.nav-btn {
  display: block;
  text-decoration: none;
}

.nav-btn.active,
.nav-btn:hover {
  background: #e8f5ef;
  color: var(--brand-dark);
}

.sidebar .ghost {
  margin-top: auto;
}

.content {
  min-width: 0;
  padding: 24px;
  background: linear-gradient(180deg, #fbfcfe 0%, #f7f9fc 100%);
}

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

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

.stats {
  grid-template-columns: repeat(5, minmax(130px, 1fr));
}

.onboarding-summary {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  margin-top: 14px;
}

.two-col {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel,
.card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 10px 28px rgba(23, 32, 42, 0.04);
}

.card strong {
  display: block;
  font-size: 26px;
  margin-top: 8px;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
}

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

.meta-row code,
.link-box {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: white;
  overflow-wrap: anywhere;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

th {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 700;
}

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

.badge {
  display: inline-block;
  padding: 4px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.badge.success,
.badge.routed {
  background: #dcfae6;
  color: var(--ok);
}

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

.badge.not_routed,
.badge.unassigned {
  background: #fff4ce;
  color: var(--warn);
}

.badge.pending {
  background: #dbeafe;
  color: var(--info);
}

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

.form-grid.single {
  grid-template-columns: 1fr;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.inbox {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  min-height: 620px;
}

.contact-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.contact-item {
  width: 100%;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.contact-item.active,
.contact-item:hover {
  background: #e8f5ef;
}

.conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.bubbles {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 6px;
}

.bubble {
  max-width: 76%;
  padding: 10px 12px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
}

.bubble.outgoing {
  margin-left: auto;
  background: #e8f5ef;
}

.bubble small {
  display: block;
  color: var(--muted);
  margin-top: 6px;
}

.reply-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

pre {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.table-wrap {
  overflow: auto;
}

.onboarding-hero {
  background: linear-gradient(135deg, #ffffff 0%, #edf8f2 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(23, 32, 42, 0.06);
  padding: 20px;
}

.onboarding-hero h2 {
  font-size: 30px;
  line-height: 1.15;
  margin: 0;
  max-width: 760px;
}

.onboarding-hero .muted {
  max-width: 820px;
}

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

.process-list div {
  align-items: center;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr);
  padding: 12px;
}

.process-list strong {
  background: var(--brand);
  border-radius: 999px;
  color: white;
  display: grid;
  height: 28px;
  place-items: center;
  width: 28px;
}

.process-list span {
  color: var(--muted);
}

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

  .sidebar {
    position: static;
  }

  .stats,
  .onboarding-summary,
  .two-col,
  .meta-row,
  .form-grid,
  .inbox {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
