:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #637083;
  --line: #d9e1ea;
  --green: #0f8f62;
  --green-soft: #e5f6ee;
  --blue: #1769aa;
  --blue-soft: #e8f2fb;
  --amber: #ad6800;
  --amber-soft: #fff7e6;
  --purple: #5b3bb2;
  --purple-soft: #f4f0ff;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
  border-radius: 7px;
  background: var(--green);
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

button.secondary {
  background: #edf1f5;
  color: var(--text);
}

button.link {
  background: transparent;
  color: var(--danger);
  min-height: 0;
  padding: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  min-height: 0;
  padding: 16px;
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 58px;
}

.eyebrow {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  margin: 0 0 3px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.status {
  align-items: center;
  background: #eef2f6;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  min-height: 34px;
  padding: 0 13px;
}

.status.online {
  background: var(--green-soft);
  border-color: #b8e4cf;
  color: var(--green);
}

.status.error {
  background: #fff1f0;
  border-color: #ffccc7;
  color: var(--danger);
}

.workspace {
  flex: 1;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(290px, 360px) minmax(360px, 1fr) minmax(290px, 390px);
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls,
.event-panel {
  padding: 14px;
}

.controls {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.field-group {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

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

input,
select,
textarea {
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  min-height: 40px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  min-height: 84px;
  resize: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.grid-two {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.button-row,
.composer-actions,
.event-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.lead-picker {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin: 4px 0 12px;
  padding: 10px;
}

.lead-picker-toolbar {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

#leadSelector {
  min-height: 40px;
}

.lead-status {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.settings-row {
  border-top: 1px solid var(--line);
  margin-top: auto;
  padding-top: 12px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 0;
  overflow: hidden;
}

.journey-panel {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding: 14px 16px;
}

.journey-summary {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.panel-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.journey-status-strip,
.action-rail {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.state-chip,
.action-chip {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  min-height: 28px;
  padding: 0 9px;
  white-space: nowrap;
}

.state-chip {
  background: #eef2f6;
  color: var(--muted);
}

.state-chip.online,
.state-chip.secure,
.action-chip.safe {
  background: var(--green-soft);
  border-color: #b8e4cf;
  color: var(--green);
}

.state-chip.pending,
.action-chip.pending {
  background: var(--amber-soft);
  border-color: #ffd591;
  color: var(--amber);
}

.action-chip.transfer {
  background: var(--purple-soft);
  border-color: #d8c8ff;
  color: var(--purple);
}

.journey-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
}

.journey-card {
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 4px;
  min-height: 58px;
  min-width: 0;
  padding: 8px 9px;
}

.journey-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.journey-card strong {
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}

.journey-timeline {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.journey-timeline li {
  background: #eef2f6;
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  min-height: 24px;
  padding: 5px 8px;
  text-align: center;
  overflow-wrap: anywhere;
}

.journey-timeline li.is-active {
  background: var(--blue-soft);
  color: var(--blue);
}

.journey-timeline li.is-done {
  background: var(--green-soft);
  color: var(--green);
}

.action-rail {
  justify-content: flex-start;
  min-height: 28px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 16px;
}

.bubble {
  border-radius: 8px;
  max-width: min(78%, 720px);
  padding: 11px 13px;
}

.bubble-content {
  white-space: pre-wrap;
}

.bubble-footer {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin-top: 6px;
  text-align: right;
}

.bubble.user {
  align-self: flex-end;
  background: var(--green);
  color: white;
}

.bubble.bot {
  align-self: flex-start;
  background: #eef3f7;
}

.bubble.bot .bubble-footer {
  color: #59677a;
}

.bubble.user .bubble-footer {
  color: rgba(255, 255, 255, 0.75);
}

.bubble.system {
  align-self: center;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 13px;
}

.bubble.pending {
  opacity: 0.78;
}

.composer {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding: 12px 14px;
}

.composer textarea {
  min-height: 56px;
}

.checkline {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: 8px;
  text-transform: none;
}

.checkline input {
  min-height: auto;
  width: auto;
}

.media-composer {
  display: grid;
  gap: 8px;
}

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

.file-button {
  align-items: center;
  background: #edf6f1;
  border-radius: 7px;
  color: #116b4b;
  cursor: pointer;
  display: inline-flex;
  min-height: 36px;
  padding: 0 12px;
  text-transform: none;
}

#mediaInput {
  height: 1px;
  min-height: 1px;
  opacity: 0;
  padding: 0;
  position: absolute;
  width: 1px;
}

.media-list {
  display: grid;
  gap: 6px;
}

.media-item {
  align-items: center;
  background: #f6f8fa;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 36px;
  padding: 7px 9px;
}

.media-name {
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.samples {
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 88px;
  overflow: auto;
  padding: 12px 14px 14px;
}

.samples button {
  background: #edf6f1;
  color: #116b4b;
  font-size: 13px;
  min-height: 32px;
}

.event-panel {
  display: grid;
  gap: 12px;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.department-panel {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
}

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

.department-manual-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(116px, 0.8fr) auto;
}

.department-toolbar-actions {
  display: inline-flex;
  gap: 8px;
}

#departmentSelector {
  min-height: 40px;
}

.department-list {
  display: grid;
  gap: 8px;
  max-height: 150px;
  overflow: auto;
}

.department-item {
  align-items: center;
  background: #f7fafc;
  border: 1px solid var(--line);
  color: var(--text);
  display: grid;
  gap: 9px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  justify-items: start;
  min-height: 48px;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}

.department-item.has-priority {
  border-color: #f5bd5b;
  box-shadow: inset 3px 0 0 #d97706;
}

.department-item.is-virtual {
  background: #f8fafc;
  border-style: dashed;
}

.department-item.is-single-queue {
  box-shadow: inset 3px 0 0 #64748b;
}

.department-swatch {
  border-radius: 999px;
  display: inline-block;
  height: 12px;
  width: 12px;
}

.department-details {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.department-details strong,
.department-details span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.department-details span,
.department-empty {
  color: var(--muted);
  font-size: 12px;
}

.department-badge {
  align-items: center;
  background: var(--green-soft);
  border: 1px solid #b8e4cf;
  border-radius: 999px;
  color: var(--green);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  justify-content: center;
  min-height: 26px;
  min-width: 30px;
  padding: 0 8px;
}

.department-queue {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
  padding-right: 2px;
}

.queue-group {
  display: grid;
  gap: 6px;
}

.queue-group h3 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 4px 0 0;
}

.queue-item {
  align-items: center;
  background: #f7fafc;
  border: 1px solid var(--line);
  color: var(--text);
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  justify-items: stretch;
  min-height: 54px;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}

.queue-item.is-priority {
  background: #fff8eb;
  border-color: #f5bd5b;
}

.queue-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.queue-main strong,
.queue-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-main span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.queue-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

.queue-chip {
  align-items: center;
  background: #eef2f6;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  min-height: 24px;
  padding: 0 8px;
}

.queue-chip.priority {
  background: #fff3d6;
  border-color: #f5bd5b;
  color: #9a5800;
}

.queue-chip.temperature.hot {
  background: #fff1f0;
  border-color: #ffccc7;
  color: #b42318;
}

.queue-chip.temperature.warm {
  background: #fff7e6;
  border-color: #ffd591;
  color: #ad6800;
}

.queue-chip.temperature.cold {
  background: #e8f2fb;
  border-color: #bfd7ee;
  color: #1769aa;
}

.queue-chip.manager-alert {
  background: #f4f0ff;
  border-color: #d8c8ff;
  color: #5b3bb2;
}

pre {
  background: #101723;
  border-radius: 7px;
  color: #d6e2f0;
  font-size: 12px;
  line-height: 1.45;
  margin: 12px 0 0;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.modal-backdrop {
  align-items: center;
  background: rgba(16, 23, 35, 0.52);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(16, 23, 35, 0.28);
  display: grid;
  gap: 12px;
  max-height: min(720px, calc(100vh - 40px));
  max-width: min(1040px, calc(100vw - 40px));
  min-height: 360px;
  overflow: hidden;
  padding: 16px;
  width: 100%;
}

.modal-header,
.modal-toolbar {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.modal-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 0;
  overflow: auto;
}

table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 920px;
  width: 100%;
}

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

th {
  background: #f0f4f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  position: sticky;
  text-transform: uppercase;
  top: 0;
}

td {
  color: var(--text);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .chat-panel,
  .event-panel {
    min-height: 520px;
    overflow: hidden;
  }

  .department-actions,
  .department-manual-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 760px) {
  .journey-panel {
    gap: 8px;
    max-height: 42vh;
    overflow: auto;
    padding: 10px 12px;
  }

  .journey-card {
    min-height: 48px;
    padding: 6px 8px;
  }

  .journey-timeline {
    display: none;
  }

  .action-rail {
    max-height: 60px;
    overflow: auto;
  }
}

@media (max-width: 620px) {
  .shell {
    padding: 12px;
  }

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

  .grid-two {
    grid-template-columns: 1fr;
  }

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

  .journey-status-strip {
    justify-content: flex-start;
  }

  .journey-grid {
    grid-template-columns: 1fr 1fr;
  }

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