:root {
  --bg: #f6f8f7;
  --panel: #ffffff;
  --panel-soft: #f9fbfa;
  --text: #1f2a2b;
  --muted: #637173;
  --border: #dce4e2;
  --teal: #177d72;
  --teal-dark: #0e5e56;
  --duck: #f2c14e;
  --amber: #b7791f;
  --red: #b7323c;
  --green: #247a45;
  --blue: #2563a7;
  --shadow: 0 18px 45px rgba(23, 42, 46, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

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

button {
  border: 0;
  border-radius: 7px;
  background: var(--teal);
  color: #fff;
  font-weight: 750;
  padding: 10px 14px;
  cursor: pointer;
}

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

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.secondary-button {
  background: #edf4f3;
  color: var(--teal-dark);
}

.secondary-button:hover {
  background: #dfecea;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 125, 114, 0.12);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--border);
  background: #111b1d;
  color: #f7fbfa;
  padding: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 850;
}

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

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

.nav a {
  border-radius: 7px;
  color: #dce7e5;
  padding: 10px 11px;
  font-weight: 700;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.tenant-card {
  margin-top: auto;
  display: grid;
  gap: 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  padding: 14px;
}

.tenant-card p {
  margin: 0;
  color: #f6d0d3;
  font-size: 13px;
}

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

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

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
}

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

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

.topbar-actions form {
  margin: 0;
}

.route-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 10px;
}

.message-stack {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.notice {
  border-left: 4px solid var(--teal);
  border-radius: 7px;
  background: #edf8f5;
  padding: 10px 12px;
  font-weight: 700;
}

.notice.error {
  border-color: var(--red);
  background: #fff0f1;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric-row div,
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-row div {
  padding: 13px 15px;
}

.metric-row strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.metric-row span,
.muted,
table span,
.hint {
  color: var(--muted);
  font-size: 13px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(255px, 330px) minmax(380px, 1fr) minmax(260px, 340px);
  gap: 12px;
  align-items: start;
}

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

.conversation-rail,
.thread-panel,
.detail-panel {
  height: calc(100vh - 136px);
  min-height: 620px;
}

.conversation-rail,
.detail-panel {
  overflow: auto;
}

.thread-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.search-form,
.stack-form {
  display: grid;
  gap: 9px;
}

.search-form.horizontal {
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 12px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.checkline input {
  width: auto;
}

.conversation-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.conversation-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
  padding: 11px;
}

.conversation-item.active {
  border-color: var(--teal);
  background: #edf8f5;
}

.item-top,
.badge-row,
.thread-header,
.section-head,
.inline-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-top em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  white-space: nowrap;
}

.preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status-badge,
.count-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
  padding: 4px 8px;
  text-transform: uppercase;
}

.status-active,
.status-replaced,
.status-trialing,
.status-online,
.status-open,
.status-replied,
.status-queued,
.status-claimed,
.status-paired,
.status-opted_in {
  background: #e2f5e8;
  color: var(--green);
}

.status-past_due,
.status-paused,
.status-pending,
.status-delayed,
.status-new {
  background: #fff3d5;
  color: var(--amber);
}

.status-cancelled,
.status-expired,
.status-disabled,
.status-retired,
.status-stale,
.status-revoked,
.status-failed,
.status-undelivered,
.status-rejected,
.status-blocked,
.status-offline,
.status-opt_out,
.status-opted_out {
  background: #ffe4e8;
  color: var(--red);
}

.count-badge {
  background: var(--duck);
  color: #151515;
}

.thread-header {
  border-bottom: 1px solid var(--border);
  padding: 16px;
}

.thread-header h2,
.detail-panel h2,
.panel h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.thread-header p,
.section-head p {
  margin: 0;
  color: var(--muted);
}

.sms-thread {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #f8fbfa, #eef5f3);
  padding: 18px;
}

.bubble {
  max-width: min(78%, 620px);
  border-radius: 14px;
  padding: 11px 13px;
  box-shadow: 0 6px 18px rgba(31, 42, 43, 0.08);
}

.bubble.inbound {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
}

.bubble.outbound {
  align-self: flex-end;
  background: #dff3ef;
  border: 1px solid #b9ddd8;
}

.bubble-body {
  overflow-wrap: anywhere;
  white-space: normal;
}

.bubble footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.error-text {
  color: var(--red);
}

.composer {
  display: grid;
  gap: 9px;
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 13px;
}

.composer-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.composer-tools span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.composer-tools .warn {
  color: var(--amber);
}

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

.start-card,
.info-card {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.info-card:last-child {
  border-bottom: 0;
}

dl {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 10px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.audit-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.audit-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.audit-list strong {
  color: var(--text);
}

.empty,
.empty-state {
  color: var(--muted);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  text-align: center;
}

.two-panel,
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  gap: 12px;
}

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

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

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

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 9px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

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

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

.settings-list {
  grid-template-columns: 170px 1fr;
}

.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 12px;
}

.settings-list.compact {
  grid-template-columns: 110px 1fr;
}

.auth-panel {
  max-width: 460px;
}

code {
  overflow-wrap: anywhere;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  padding: 10px 12px;
}

.button-link:hover {
  background: var(--teal-dark);
}

.qr-grid {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(190px, 240px) minmax(280px, 1fr);
  gap: 14px;
  align-items: start;
}

.qr-card,
.pairing-details {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.qr-card h3,
.pairing-details h3 {
  margin: 0;
  font-size: 16px;
}

.qr-card img {
  display: block;
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.qr-placeholder {
  display: grid;
  place-items: center;
  gap: 8px;
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: #f7faf9;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.qr-placeholder strong {
  color: var(--text);
  text-transform: uppercase;
}

.qr-card code {
  display: block;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #f7faf9;
  color: var(--text);
  font-size: 12px;
  padding: 8px;
}

@media (max-width: 1180px) {
  .workspace-grid {
    grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
    height: auto;
    min-height: 0;
  }
}

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

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

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

  .main-shell {
    padding: 14px;
  }

  .topbar,
  .item-top,
  .thread-header,
  .section-head,
  .inline-action {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-row,
  .workspace-grid,
  .two-panel,
  .settings-grid,
  .setup-grid,
  .qr-grid {
    grid-template-columns: 1fr;
  }

  .conversation-rail,
  .thread-panel {
    height: auto;
    min-height: 0;
  }

  .sms-thread {
    max-height: 520px;
  }

  .bubble {
    max-width: 92%;
  }
}
