:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --nav: #17211f;
  --nav-muted: #a8b4b0;
  --surface: #ffffff;
  --surface-soft: #f0f4f2;
  --ink: #17211f;
  --muted: #697772;
  --line: #d9e1dd;
  --line-strong: #c3cec9;
  --accent: #127c66;
  --accent-soft: #dff3ec;
  --blue: #2c638f;
  --blue-soft: #e2edf5;
  --amber: #a86614;
  --amber-soft: #faecd8;
  --danger: #a33a38;
  --danger-soft: #f7e2e1;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(23, 33, 31, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
textarea,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  touch-action: manipulation;
}

button:hover {
  border-color: var(--line-strong);
  background: #f9fbfa;
}

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

button.primary:hover {
  background: #0d6654;
}

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

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

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  text-decoration: none;
  white-space: nowrap;
}

.button-link:hover {
  border-color: var(--line-strong);
  background: #f9fbfa;
}

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

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 13px;
}

a {
  color: var(--blue);
}

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

.nav {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 18px 14px;
  background: var(--nav);
  color: #fff;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 4px 6px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand strong {
  font-size: 18px;
}

.brand span,
.nav-footer span {
  color: var(--nav-muted);
  font-size: 12px;
}

.nav-tabs {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav-tab,
.ghost-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: transparent;
  color: #edf4f1;
  border-color: transparent;
  text-align: left;
}

.nav-tab:hover,
.ghost-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

.nav-tab.active {
  background: #edf4f1;
  color: var(--nav);
}

.nav-tab span {
  color: inherit;
  font-size: 12px;
}

.nav-footer {
  display: grid;
  gap: 8px;
}

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

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

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

.mode-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.status-pill,
.kind {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #e7ece9;
  color: #30423e;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.live {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill.test {
  background: var(--amber-soft);
  color: var(--amber);
}

.kind.respond {
  background: var(--blue-soft);
  color: var(--blue);
}

.kind.verify {
  background: var(--amber-soft);
  color: var(--amber);
}

.kind.approve {
  background: var(--accent-soft);
  color: var(--accent);
}

.kind.incoming {
  background: #e8e6f3;
  color: #4c4a78;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

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

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

.metric strong {
  font-size: 25px;
  line-height: 1;
}

.metric.accent {
  border-color: #bddbd2;
}

.metric.blue {
  border-color: #bfd0df;
}

.metric.amber {
  border-color: #e5ceb0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.toolbar p,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.workbench-layout {
  display: grid;
  grid-template-columns: minmax(340px, 42%) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.queue-pane,
.detail-pane,
.insight-panel,
.agent-table,
.event-list,
.conversation-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pane-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.queue-list {
  display: grid;
  max-height: calc(100vh - 242px);
  overflow: auto;
}

.queue-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "kind title"
    "kind subtitle"
    "kind meta";
  gap: 3px 10px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
}

.queue-row.selected {
  background: #edf5f2;
  box-shadow: inset 3px 0 0 var(--accent);
}

.queue-row .kind {
  grid-area: kind;
  align-self: start;
}

.queue-title {
  grid-area: title;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.queue-subtitle {
  grid-area: subtitle;
  color: #384843;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta {
  grid-area: meta;
  color: var(--muted);
  font-size: 12px;
}

.detail-pane {
  min-height: 520px;
  padding: 16px;
}

.detail-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 5px;
}

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

.detail-section {
  display: grid;
  gap: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}

.detail-section.compact {
  background: transparent;
}

.link-button {
  width: fit-content;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface);
  text-decoration: none;
}

.account-callout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: fit-content;
  min-width: 260px;
  border: 1px solid #bddbd2;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 9px 10px;
}

.account-callout span {
  font-size: 12px;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.copy-row code {
  min-width: 0;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  padding: 9px 10px;
  color: #30423e;
}

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

.facts div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.facts span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.options {
  display: grid;
  gap: 10px;
}

.feedback-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  padding: 10px;
  margin-bottom: 12px;
}

.feedback-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.feedback-head select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 9px;
}

.feedback-text {
  min-height: 76px;
  margin: 0;
}

.option-block {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.option-head,
.option-actions,
.detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.option-head span {
  color: var(--muted);
  font-size: 12px;
}

textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  margin: 8px 0;
  line-height: 1.45;
  color: var(--ink);
  background: #fbfcfc;
}

.detail-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.detail-empty,
.empty-state {
  padding: 22px;
  color: var(--muted);
}

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

.message-line {
  border-left: 2px solid var(--line-strong);
  padding-left: 10px;
}

.message-line span {
  color: var(--muted);
  font-size: 12px;
}

.manual-reply {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.conversation-list {
  display: grid;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

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

.conversation-row p {
  color: #384843;
  margin: 6px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

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

.insight-panel {
  padding: 14px;
}

.insight-panel h3 {
  margin-bottom: 12px;
}

.breakdown {
  display: grid;
  gap: 10px;
}

.break-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}

.bar {
  height: 8px;
  background: #e8eeeb;
  border-radius: 999px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.table {
  display: grid;
}

.table-head,
.table-row {
  display: grid;
  grid-template-columns: 1.3fr 1.1fr 0.8fr 0.9fr 0.7fr;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.table-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-soft);
}

.event-row {
  display: grid;
  grid-template-columns: 160px 155px minmax(0, 1fr) 120px;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.event-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  transform: translateY(140%);
  transition: transform 160ms ease;
  z-index: 10;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  padding: 10px 12px;
}

.toast.show {
  transform: translateY(0);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-panel form {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.login-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.error-text {
  color: var(--danger);
  margin-top: 10px;
  min-height: 20px;
}

@media (max-width: 1120px) {
  .status-strip {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .workbench-layout {
    grid-template-columns: 1fr;
  }

  .queue-list {
    max-height: 430px;
  }
}

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

  .nav {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    grid-template-rows: auto auto auto;
    gap: 9px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  }

  .brand {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 0 2px 8px;
  }

  .brand strong {
    font-size: 16px;
  }

  .nav-tabs {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .nav-tab {
    width: auto;
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 10px;
    white-space: nowrap;
  }

  .nav-footer {
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
  }

  .ghost-button {
    width: auto;
    min-height: 38px;
    padding: 7px 9px;
  }

  .nav-footer span {
    min-width: 0;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main {
    padding: 14px 12px calc(22px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 15px;
  }

  .topbar,
  .toolbar,
  .conversation-row,
  .event-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .mode-badges {
    justify-content: start;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
  }

  .metric {
    min-height: 62px;
    padding: 10px;
  }

  .metric strong {
    font-size: 22px;
  }

  .segmented {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: none;
  }

  .segmented::-webkit-scrollbar {
    display: none;
  }

  .segmented button {
    flex: 0 0 auto;
    min-height: 40px;
    white-space: nowrap;
  }

  .workbench-layout {
    gap: 10px;
  }

  .pane-head {
    padding: 11px 12px;
  }

  .queue-list {
    max-height: 46vh;
  }

  .queue-row {
    grid-template-columns: 1fr;
    grid-template-areas:
      "kind"
      "title"
      "subtitle"
      "meta";
    gap: 5px;
    padding: 12px;
  }

  .queue-row .kind {
    width: fit-content;
  }

  .queue-subtitle {
    overflow: visible;
    white-space: normal;
  }

  .detail-pane {
    min-height: 0;
    padding: 12px;
  }

  .detail-header {
    padding-bottom: 12px;
    margin-bottom: 12px;
  }

  .detail-section {
    padding: 10px;
  }

  .account-callout {
    width: 100%;
    min-width: 0;
  }

  .facts,
  .insight-grid,
  .copy-row {
    grid-template-columns: 1fr;
  }

  .copy-row .button-link,
  .copy-row button {
    justify-content: center;
    width: 100%;
  }

  .feedback-head,
  .option-head,
  .option-actions,
  .detail-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .feedback-head select {
    width: 100%;
  }

  .detail-actions button,
  .detail-actions .button-link,
  .option-actions button,
  .button-link {
    min-height: 44px;
  }

  .detail-actions button,
  .option-actions button {
    flex: 1 1 145px;
  }

  textarea,
  select,
  button,
  .button-link {
    font-size: 16px;
  }

  textarea {
    min-height: 116px;
  }

  .feedback-text {
    min-height: 86px;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions button {
    flex: 1 1 0;
    min-height: 40px;
  }

  .conversation-row p {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .event-row span {
    overflow: visible;
    white-space: normal;
  }

  .table-head {
    display: none;
  }

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

  .toast {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: 12px;
    max-width: none;
  }
}

@media (max-width: 430px) {
  .metric span {
    min-height: 28px;
    margin-bottom: 6px;
  }

  .topbar {
    margin-bottom: 12px;
  }

  .mode-badges {
    gap: 6px;
  }

  .status-pill,
  .kind {
    font-size: 11px;
    padding-inline: 7px;
  }
}
