:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --ink: #17202a;
  --muted: #657386;
  --line: #d9dee7;
  --panel: #ffffff;
  --accent: #176b87;
  --accent-strong: #0f5066;
  --danger: #a53b3b;
  --ok: #27724f;
}

* {
  box-sizing: border-box;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 22px 28px;
  background: #10212b;
  color: white;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 720;
}

h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.topbar p {
  margin-top: 4px;
  color: #c4d0d8;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.session-user {
  color: #d8e3ea;
  font-size: 14px;
  font-weight: 650;
}

main {
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
}

.login,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.login {
  max-width: 440px;
  margin: 48px auto;
}

.hidden {
  display: none;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tabs button,
button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 650;
  cursor: pointer;
}

.tabs button.active {
  background: #dfeff4;
  border-color: #a7cbd7;
  color: var(--accent-strong);
}

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

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

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 16px;
  align-items: start;
}

.grid.flow-mode {
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
}

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

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

.field-block {
  display: grid;
  gap: 6px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
  background: white;
}

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

fieldset.compact-checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 10px;
  max-height: 150px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  margin: 0;
}

.compact-checks legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.compact-checks label.hint {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  line-height: 1.2;
}

.compact-checks input[type="checkbox"] {
  width: 15px;
  min-height: 15px;
  flex: 0 0 15px;
  margin: 0;
  padding: 0;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.license-error {
  color: var(--danger);
  font-weight: 700;
}

.feature-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.feature-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 750;
}

.feature-pill.enabled {
  color: var(--ok);
  border-color: #b7d8c5;
  background: #eef8f2;
}

.feature-pill.disabled {
  color: var(--muted);
  background: #f4f5f7;
}

.metrics .over-limit strong,
.metrics .over-limit span {
  color: var(--danger);
}

.dss-grid {
  display: grid;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.dss-grid-head,
.dss-row {
  display: grid;
  grid-template-columns: 44px 54px minmax(120px, 1fr) minmax(120px, 1fr) minmax(110px, 1fr) 82px 54px 34px;
  gap: 6px;
  align-items: center;
  min-width: 720px;
}

.dss-grid-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.dss-row {
  margin-bottom: 6px;
}

.dss-row input,
.dss-row select {
  min-height: 32px;
  padding: 5px 7px;
  font-size: 12px;
}

.dss-row button {
  min-height: 32px;
  padding: 4px 8px;
}

.dss-grid > button {
  justify-self: start;
  min-height: 32px;
}

.flow-editor {
  display: grid;
  gap: 10px;
}

.flow-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.flow-main {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.flow-debug-panel {
  position: sticky;
  top: 12px;
  min-width: 0;
}

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

.flow-toolbar button,
.flow-node button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.flow-canvas {
  position: relative;
  min-height: 520px;
  min-width: 1200px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#edf1f5 1px, transparent 1px),
    linear-gradient(90deg, #edf1f5 1px, transparent 1px),
    #fbfcfd;
  background-size: 24px 24px;
}

.flow-connectors {
  position: absolute;
  inset: 0;
  width: 2400px;
  height: 1600px;
  pointer-events: auto;
  z-index: 1;
}

.flow-link {
  fill: none;
  stroke: #176b87;
  stroke-width: 2.4;
  opacity: 0.82;
  pointer-events: stroke;
}

.flow-link-hit {
  fill: none;
  stroke: rgba(255, 255, 255, 0.01);
  stroke-width: 18;
  pointer-events: stroke;
  cursor: pointer;
}

.flow-link.selected {
  stroke: #ffb000;
  stroke-width: 4.5;
  opacity: 1;
  filter: drop-shadow(0 0 5px rgba(255, 176, 0, 0.45));
}

.flow-link.draft {
  stroke-dasharray: 8 6;
  opacity: 0.65;
}

.flow-link-handle {
  fill: white;
  stroke: #176b87;
  stroke-width: 2.5;
  cursor: ns-resize;
  pointer-events: all;
}

.flow-link-handle.corner {
  cursor: move;
}

.flow-link-handle:hover,
.flow-editor.routing .flow-link-handle,
.flow-link-handle.selected {
  fill: #d9f2f7;
  stroke-width: 3;
}

.flow-arrow-head {
  fill: #176b87;
}

.flow-arrow-head.selected {
  fill: #ffb000;
}

.flow-link-label {
  fill: #0f5066;
  stroke: white;
  stroke-width: 4px;
  paint-order: stroke;
  font-size: 13px;
  font-weight: 800;
  pointer-events: all;
  cursor: pointer;
}

.flow-link-label.draft {
  opacity: 0.8;
}

.flow-link-label.selected {
  fill: #8a4d00;
  font-size: 14px;
}

.flow-editor.full .flow-canvas {
  min-height: 740px;
}

.flow-editor.full .flow-debug-log {
  max-height: 520px;
}

.flow-editor.full .flow-node {
  width: var(--flow-node-width, 128px);
}

.flow-editor.full .flow-node.expanded {
  width: 260px;
}

.flow-node {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 2px;
  width: var(--flow-node-width, 118px);
  border: 1px solid #b9c5d2;
  border-radius: 8px;
  padding: 6px 8px;
  background: white;
  box-shadow: 0 8px 18px rgba(23, 32, 42, 0.08);
  min-height: var(--flow-node-height, 44px);
}

.flow-node:not(.expanded) {
  height: var(--flow-node-height, 44px);
  padding: 0 14px;
  place-items: center;
  overflow: visible;
}

.flow-node.flow-edge-source {
  border-color: #20824f;
  box-shadow: 0 0 0 3px rgba(111, 211, 154, 0.26), 0 8px 18px rgba(23, 32, 42, 0.08);
}

.flow-node.flow-edge-target {
  border-color: #c89100;
  box-shadow: 0 0 0 3px rgba(255, 212, 90, 0.32), 0 8px 18px rgba(23, 32, 42, 0.08);
}

.flow-node.expanded {
  gap: 6px;
  width: 240px;
  padding: 8px;
  min-height: 0;
  z-index: 5;
}

.flow-entry-port {
  position: absolute;
  box-sizing: border-box;
  left: -10px;
  top: 50%;
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  border-radius: 50%;
  border: 2px solid #c89100;
  background: #ffd45a;
  transform: translateY(-50%);
  box-shadow: none;
}

.flow-node header {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: move;
  user-select: none;
  gap: 6px;
  min-width: 0;
}

.flow-node:not(.expanded) header {
  height: 100%;
  width: 100%;
}

.flow-node header span {
  min-width: 0;
  display: block;
  width: 100%;
}

.flow-node header button {
  display: none;
}

.flow-node.expanded header {
  justify-content: space-between;
}

.flow-node.expanded header span {
  display: grid;
  gap: 1px;
}

.flow-node.expanded header button {
  display: inline-flex;
}

.flow-editor.dragging {
  user-select: none;
}

.flow-editor.connecting {
  cursor: crosshair;
  user-select: none;
}

.flow-node strong {
  color: var(--accent-strong);
  font-size: 12px;
  text-transform: uppercase;
  display: block;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-node em {
  display: none;
  color: var(--ink);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-node.expanded strong {
  text-align: left;
}

.flow-node.expanded em {
  display: block;
}

.flow-node input,
.flow-node select {
  min-height: 30px;
  padding: 5px 7px;
  font-size: 12px;
}

.flow-node label {
  gap: 4px;
  font-size: 11px;
}

.flow-node > label,
.flow-node > textarea,
.flow-node > input,
.flow-node > select {
  display: none;
}

.flow-node.expanded > label,
.flow-node.expanded > textarea,
.flow-node.expanded > input,
.flow-node.expanded > select {
  display: grid;
}

.flow-outputs {
  position: absolute;
  right: -10px;
  top: 50%;
  display: grid;
  gap: 5px;
  border-top: 0;
  padding-top: 0;
  transform: translateY(-50%);
}

.flow-node:not(.expanded) .flow-outputs {
  width: 18px;
  justify-items: center;
}

.flow-node.expanded .flow-outputs {
  position: static;
  right: auto;
  top: auto;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  transform: none;
}

.flow-output-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  font-size: 0;
}

.flow-node:not(.expanded) .flow-output-row {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  overflow: visible;
  color: transparent;
  font-size: 0 !important;
  line-height: 0;
}

.flow-node.expanded .flow-output-row {
  display: grid;
  grid-template-columns: auto 1fr 20px;
  justify-content: stretch;
  gap: 6px;
  font-size: 11px;
}

.flow-output-row select {
  display: none;
}

.flow-node:not(.expanded) .flow-output-row select {
  display: none !important;
}

.flow-node.expanded .flow-output-row select {
  display: block;
}

.flow-inline {
  display: grid;
  grid-template-columns: 18px;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.flow-node:not(.expanded) .flow-inline {
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  overflow: visible;
  color: transparent;
  font-size: 0 !important;
  line-height: 0;
}

.flow-node.expanded .flow-inline {
  grid-template-columns: minmax(54px, 0.32fr) minmax(112px, 1fr) 20px 28px;
  justify-content: stretch;
  gap: 6px;
}

.flow-inline label {
  display: none;
}

.flow-node:not(.expanded) .flow-inline label {
  display: none !important;
}

.flow-node.expanded .flow-inline label {
  display: grid;
  min-width: 0;
}

.flow-outputs > button {
  display: none;
}

.flow-node:not(.expanded) .flow-outputs > button {
  display: none !important;
}

.flow-node.expanded .flow-outputs > button {
  display: inline-flex;
}

.flow-mini-button {
  align-items: center;
  justify-content: center;
  min-width: 26px;
}

.flow-port {
  box-sizing: border-box;
  display: block;
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  border-radius: 50%;
  border: 2px solid #20824f;
  background: #6fd39a;
  padding: 0;
  line-height: 0;
  cursor: crosshair;
}

.flow-node .flow-port {
  flex: 0 0 18px;
  min-height: 18px;
  padding: 0;
  font-size: 0;
}

.flow-port.error {
  border-color: #b3262f;
  background: #ef6b73;
}

.flow-port.success {
  border-color: #20824f;
  background: #6fd39a;
}

.flow-port:hover {
  box-shadow: 0 0 0 4px rgba(111, 211, 154, 0.25);
}

.flow-port.error:hover {
  box-shadow: 0 0 0 4px rgba(239, 107, 115, 0.22);
}

.flow-debug {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.flow-debug summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent-strong);
}

.flow-debug-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

.flow-debug-log {
  max-height: 260px;
  overflow: auto;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

.flow-debug-log table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
}

.flow-debug-log th,
.flow-debug-log td {
  border-bottom: 1px solid var(--line);
  padding: 6px;
  text-align: left;
  vertical-align: top;
}

.flow-debug-log th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

@media (max-width: 1100px) {
  .flow-workspace {
    grid-template-columns: 1fr;
  }

  .flow-debug-panel {
    position: static;
  }
}

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

.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.item h3 {
  margin: 0;
  font-size: 15px;
}

.item p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: white;
}

.status span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px #f5dddd;
}

.status.online {
  color: var(--ok);
  border-color: #b7dac8;
  background: #f0faf5;
}

.status.online span {
  background: var(--ok);
  box-shadow: 0 0 0 2px #d9f1e5;
}

.status.offline {
  color: var(--danger);
  border-color: #e7bcbc;
  background: #fff6f6;
}

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

.button-like {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  text-decoration: none;
  background: white;
  font-size: 13px;
  font-weight: 700;
}

.media-item audio {
  display: block;
  width: min(100%, 520px);
  margin-top: 10px;
}

.recording-call-table {
  width: 100%;
  max-width: 760px;
  border-collapse: collapse;
  margin-top: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  font-size: 12px;
}

.recording-call-table th,
.recording-call-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
}

.recording-call-table tr:last-child th,
.recording-call-table tr:last-child td {
  border-bottom: 0;
}

.recording-call-table th {
  width: 130px;
  color: var(--muted);
  background: #f4f6f8;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.recording-call-table td {
  color: var(--ink);
}

.recording-filter {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 150px 150px auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.recording-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.recording-tabs button.active {
  border-color: var(--accent);
  background: #e9f7fb;
  color: var(--accent-strong);
}

.report-table-wrap {
  width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.report-table {
  width: 100%;
  min-width: 780px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.report-table th,
.report-table td {
  padding: 8px 10px;
  border-right: 1px solid #e5eaf1;
  border-bottom: 1px solid #e5eaf1;
  vertical-align: middle;
}

.report-table th {
  color: var(--ink);
  background: #f4f7fa;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: left;
  white-space: normal;
}

.report-table td {
  line-height: 1.25;
}

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

.report-table th:last-child,
.report-table td:last-child {
  border-right: 0;
}

.report-table tbody tr:nth-child(even) td {
  background: #fbfcfd;
}

.report-table .num,
.report-table .time {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.queue-report-table {
  min-width: 760px;
}

.queue-report-table th:first-child,
.queue-report-table td:first-child {
  width: 140px;
}

.queue-report-table th:not(:first-child),
.queue-report-table td:not(:first-child) {
  width: 78px;
}

.call-report-table {
  min-width: 980px;
}

.call-report-table th:nth-child(1),
.call-report-table td:nth-child(1) {
  width: 135px;
}

.call-report-table th:nth-child(2),
.call-report-table td:nth-child(2) {
  width: 70px;
}

.call-report-table th:nth-child(3),
.call-report-table td:nth-child(3) {
  width: 150px;
}

.call-report-table th:nth-child(4),
.call-report-table td:nth-child(4) {
  width: 90px;
}

.call-report-table th:nth-child(6),
.call-report-table td:nth-child(6),
.call-report-table th:nth-child(7),
.call-report-table td:nth-child(7) {
  width: 70px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.queue-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.queue-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.queue-head h3,
.queue-card h4 {
  margin: 0;
}

.queue-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.queue-card h4 {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

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

.metrics strong {
  display: block;
  font-size: 20px;
}

.metrics span,
.agent-row > span {
  color: var(--muted);
  font-size: 12px;
}

.agent-row strong {
  color: var(--text);
  font-size: 13px;
  margin-right: 4px;
}

.agent-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.agent-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 8px;
}

.agent-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.agent-status span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9ca3af;
}

.agent-status.free span {
  background: #16a34a;
}

.agent-status.busy span {
  background: #dc2626;
}

.agent-status.paused span {
  background: #eab308;
}

.agent-status.logged-out span {
  background: #9ca3af;
}

.log-console {
  display: grid;
  gap: 14px;
}

.log-console-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.log-console-head h3,
.log-section h4 {
  margin: 0;
}

.log-console-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.log-section {
  display: grid;
  gap: 8px;
}

.log-section h4 {
  color: var(--muted);
  font-size: 13px;
}

.log-output {
  max-height: 560px;
  overflow: auto;
  margin: 0;
  border: 1px solid #1f2937;
  border-radius: 6px;
  padding: 12px;
  background: #0d141b;
  color: #d8edf2;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  background: #10212b;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(12px);
  transition: .18s ease;
  pointer-events: none;
}

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

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  main {
    padding: 16px;
  }

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

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