:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f7f6;
  color: #202725;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f4f7f6;
}

.app {
  width: min(1100px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 24px 92px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #6f6a5d;
  font-size: 12px;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 42px);
  font-weight: 700;
  line-height: 1.08;
}

.tabs {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  gap: 6px;
  padding: 6px;
  border: 1px solid #cbd8d4;
  border-radius: 999px;
  background: #ffffff;
  overflow-x: auto;
}

.tab-button {
  min-width: 74px;
  padding: 10px 16px;
  color: #4c493f;
  background: transparent;
}

.tab-button.active {
  color: #ffffff;
  background: #275f76;
}

.tab-panel {
  min-height: 0;
}

.tab-panel.active {
  display: grid;
  min-height: 0;
}

#chatPanel.active {
  grid-template-rows: 220px minmax(0, 1fr);
  gap: 18px;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.82fr);
  gap: 18px;
  min-height: 0;
}

.tool-pane {
  min-width: 0;
  padding: 18px;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  background: #ffffff;
}

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

.pane-head h2 {
  margin: 0;
  font-size: 17px;
}

.document-head {
  margin-top: 20px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  color: #275f76;
  background: #dbeaf0;
  font-size: 12px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: #554f43;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c9d6d2;
  border-radius: 8px;
  padding: 10px 11px;
  color: #202725;
  background: #fbfdfc;
  font: inherit;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input[type="range"] {
  padding: 0;
}

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

.slider-grid label {
  min-width: 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.inline-status {
  min-height: 20px;
  margin: 12px 0 0;
  color: #5a6e43;
  font-size: 13px;
}

.result-list,
.document-list,
.settings-readout {
  display: grid;
  gap: 10px;
}

.result-item,
.document-item {
  border: 1px solid #d7e1de;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.result-item h3,
.document-item h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.result-item p,
.document-item p,
.settings-readout p {
  margin: 0;
  color: #665f52;
  font-size: 13px;
  line-height: 1.55;
}

.section-head {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #d7e1de;
}

.field-builder {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #d7e1de;
  border-radius: 8px;
  background: #f8fbfa;
}

.field-list,
.form-preview {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

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

.block-palette button {
  min-width: 0;
  padding: 10px 8px;
  border-radius: 8px;
  color: #204238;
  background: #e8f3ef;
  font-size: 12px;
}

.flow-canvas {
  position: relative;
  display: grid;
  gap: 10px;
  min-height: 280px;
  padding: 14px;
  border: 1px solid #d7e1de;
  border-radius: 8px;
  background:
    linear-gradient(#f8fbfa, #f8fbfa) padding-box,
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(39, 95, 118, 0.08) 24px),
    repeating-linear-gradient(90deg, transparent 0 23px, rgba(39, 95, 118, 0.08) 24px);
}

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

.flow-connector {
  width: 2px;
  height: 100%;
  min-height: 72px;
  justify-self: center;
  background: #b7cac4;
}

.flow-node:first-child .flow-connector {
  background: linear-gradient(to bottom, transparent 0 50%, #b7cac4 50%);
}

.flow-node:last-child .flow-connector {
  background: linear-gradient(to bottom, #b7cac4 0 50%, transparent 50%);
}

.flow-card {
  display: grid;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 12px;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  color: #202725;
  background: #ffffff;
  text-align: left;
}

.flow-node.selected .flow-card {
  border-color: #d81f3a;
  box-shadow: 0 0 0 3px rgba(216, 31, 58, 0.12);
}

.flow-card strong {
  font-size: 14px;
}

.flow-card span,
.flow-card small {
  color: #60706a;
  font-size: 12px;
  line-height: 1.45;
}

.node-type {
  justify-self: start;
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 800;
}

.node-start {
  color: #22523c;
  background: #dcf2e6;
}

.node-message {
  color: #275f76;
  background: #dbeaf0;
}

.node-form {
  color: #69498b;
  background: #eee4f7;
}

.node-condition {
  color: #8a5c13;
  background: #fff1ce;
}

.node-mcp {
  color: #8a2838;
  background: #ffe3e7;
}

.node-end {
  color: #4f5b58;
  background: #edf3f1;
}

.flow-actions {
  display: grid;
  gap: 6px;
}

.flow-actions button {
  min-width: 36px;
  padding: 7px 8px;
  border-radius: 8px;
}

.flow-actions .flow-delete-btn,
button.danger {
  color: #ffffff;
  background: #a33a3a;
}

.flow-actions .flow-delete-btn:hover,
button.danger:hover {
  background: #7f2c2c;
}

.block-inspector {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #d7e1de;
  border-radius: 8px;
  background: #ffffff;
}

.field-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid #d7e1de;
  border-radius: 8px;
  background: #ffffff;
}

.field-item h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.field-item p {
  margin: 0;
  color: #606e69;
  font-size: 13px;
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.mini-actions button,
.field-item button {
  min-width: 46px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
}

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

.field-full {
  grid-column: span 6;
}

.field-half {
  grid-column: span 3;
}

.field-third {
  grid-column: span 2;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 32, 35, 0.38);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(980px, 100%);
  max-height: min(720px, calc(100vh - 48px));
  overflow: auto;
  padding: 18px;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 64px rgba(15, 31, 37, 0.22);
}

.modal-card-small {
  width: min(420px, 100%);
}

.modal-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.5fr) minmax(0, 1fr);
  gap: 14px;
}

.list-button {
  width: 100%;
  min-width: 0;
  border-radius: 8px;
  text-align: left;
  color: #202725;
  background: #eef5f3;
}

.list-button span {
  color: #64736e;
  font-size: 12px;
}

.json-view {
  min-height: 280px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid #d7e1de;
  border-radius: 8px;
  background: #f8fbfa;
  white-space: pre-wrap;
  line-height: 1.55;
}

.document-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.rag-doc {
  grid-template-columns: 70px minmax(0, 1fr) auto;
}

.doc-media {
  width: 58px;
  min-height: 44px;
}

.thumb,
.result-image {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #d7e1de;
  background: #edf3f1;
}

.result-image {
  width: min(240px, 100%);
  margin: 8px 0;
}

.document-item button {
  min-width: 56px;
  padding: 8px 10px;
  background: #8a4b47;
}

audio {
  width: 100%;
  margin-top: 10px;
}

body[data-active-tab="learnPanel"] .controls,
body[data-active-tab="scenarioPanel"] .controls,
body[data-active-tab="formPanel"] .controls,
body[data-active-tab="ttsPanel"] .controls {
  display: none;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 128px;
  justify-content: flex-end;
  color: #6d675a;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #a8a093;
}

.dot.live {
  background: #49d18b;
  box-shadow: 0 0 18px rgba(73, 209, 139, 0.8);
}

.dot.busy {
  background: #f5b84b;
  box-shadow: 0 0 18px rgba(245, 184, 75, 0.8);
}

.dot.vision {
  background: #3c7caa;
  box-shadow: 0 0 18px rgba(60, 124, 170, 0.55);
}

.dot.face {
  background: #4b9b68;
  box-shadow: 0 0 18px rgba(75, 155, 104, 0.55);
}

.dot.stopped {
  background: #9c9588;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px solid #cbd8d4;
  background: #ffffff;
  border-radius: 8px;
  padding: 24px;
}

.stage-toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid #c9d6d2;
  border-radius: 999px;
  color: #52625d;
  background: #f8fbfa;
  font-size: 12px;
}

.toggle-row input {
  width: 16px;
  min-height: 16px;
}

.toggle-row.active {
  color: #0f5733;
  border-color: #75b99a;
  background: #e9f7f0;
}

.pill.mic-on {
  color: #9f1d2d;
  background: #ffe3e7;
}

.pill.mic-off {
  color: #606e69;
  background: #edf3f1;
}

.meter {
  width: min(460px, 82vw);
  height: 14px;
  border-radius: 999px;
  background: #dce8e4;
  overflow: hidden;
}

#meterBar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #4b9b68, #3c7caa);
  transition: width 90ms linear;
}

.agent-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
  font-size: 26px;
  font-weight: 700;
}

.mic-live-icon {
  position: relative;
  width: 18px;
  height: 26px;
  border: 3px solid #d81f3a;
  border-radius: 999px;
}

.mic-live-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 3px;
  height: 8px;
  background: #d81f3a;
  transform: translateX(-50%);
}

.mic-live-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 16px;
  height: 3px;
  border-radius: 999px;
  background: #d81f3a;
  transform: translateX(-50%);
}

.turn-hint {
  min-height: 22px;
  margin-top: 8px;
  color: #4d7d5b;
  font-size: 14px;
}

.partial {
  min-height: 24px;
  margin-top: 12px;
  color: #6d675a;
}

.messages {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 4px 0 120px;
  scroll-behavior: smooth;
}

.bubble {
  max-width: 78%;
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  color: #ffffff;
  background: #3c7caa;
}

.bubble.agent {
  align-self: flex-start;
  color: #202725;
  background: #ffffff;
  border: 1px solid #d7e1de;
}

.bubble.meta {
  align-self: center;
  color: #756f62;
  background: transparent;
  font-size: 12px;
}

.bubble.image {
  align-self: flex-end;
  max-width: min(252px, 52%);
  background: #ffffff;
  border: 1px solid #d7e1de;
  padding: 8px;
}

.bubble.image img {
  display: block;
  width: 100%;
  border-radius: 6px;
}

.bubble.sources {
  align-self: flex-start;
  display: grid;
  gap: 8px;
  width: min(520px, 92%);
  max-width: 92%;
  background: #eef5f3;
  border: 1px solid #d7e1de;
}

.source-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.source-card img {
  width: 92px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
}

.source-card p {
  margin: 4px 0 0;
  color: #51605b;
  font-size: 12px;
  line-height: 1.45;
}

.source-card .source-location {
  color: #6f6254;
  font-size: 11px;
}

button {
  min-width: 88px;
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  color: #ffffff;
  background: #5d5a50;
  font-weight: 700;
  cursor: pointer;
}

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

button.primary {
  background: #2f7e56;
}

.controls {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(222, 211, 187, 0.9);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: 0 14px 34px rgba(44, 39, 29, 0.14);
  backdrop-filter: blur(12px);
}

.controls button {
  min-width: 72px;
  padding: 11px 16px;
}

.vision-panel {
  position: fixed;
  right: 24px;
  top: 132px;
  z-index: 20;
  width: min(380px, calc(100vw - 48px));
  pointer-events: none;
  opacity: 1;
  transition: width 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.vision-panel[hidden] {
  display: none;
}

.vision-card {
  overflow: hidden;
  border: 1px solid rgba(222, 211, 187, 0.95);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.94);
  box-shadow: 0 18px 42px rgba(44, 39, 29, 0.2);
  backdrop-filter: blur(14px);
}

.vision-panel[data-mode="face"],
.vision-panel[data-mode="idle"] {
  width: min(190px, calc(100vw - 48px));
  opacity: 0.36;
}

.vision-panel[data-mode="capture"] {
  width: min(380px, calc(100vw - 48px));
  opacity: 1;
}

.vision-panel[data-mode="face"] .vision-head,
.vision-panel[data-mode="idle"] .vision-head {
  min-height: 32px;
  padding: 7px 9px;
  font-size: 11px;
}

.vision-panel[data-mode="face"] .countdown,
.vision-panel[data-mode="idle"] .countdown {
  min-width: 42px;
  min-height: 18px;
  font-size: 13px;
}

.vision-head {
  min-height: 44px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #514b40;
  font-size: 13px;
  font-weight: 700;
}

.vision-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #e7efec;
}

#cameraPreview,
#capturedPreview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #e7efec;
}

#capturedPreview[src=""],
#capturedPreview:not([src]) {
  display: none;
}

.countdown {
  min-width: 56px;
  min-height: 24px;
  color: #2f7e56;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  text-align: right;
}

@media (max-width: 640px) {
  .app {
    padding: 14px;
    padding-bottom: 96px;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .topbar {
    position: relative;
    display: block;
    padding-right: 72px;
  }

  h1 {
    font-size: 30px;
  }

  .status {
    position: absolute;
    top: 6px;
    right: 0;
    min-width: auto;
    font-size: 12px;
  }

  .bubble {
    max-width: 92%;
  }

  .bubble.image {
    max-width: min(252px, 60%);
  }

  #chatPanel.active {
    grid-template-rows: minmax(190px, auto) minmax(0, 1fr);
  }

  .tool-grid,
  .form-grid,
  .slider-grid,
  .block-palette,
  .preview-grid,
  .modal-grid {
    grid-template-columns: 1fr;
  }

  .stage-toolbar {
    position: static;
    justify-self: stretch;
    justify-content: center;
    margin-bottom: 12px;
  }

  .field-full,
  .field-half,
  .field-third {
    grid-column: auto;
  }

  .rag-doc {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .rag-doc button {
    grid-column: 1 / -1;
  }

  .source-card {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .source-card img {
    width: 72px;
  }

  .tabs {
    width: 100%;
  }

  .tab-button {
    flex: 1;
  }

  .vision-panel {
    right: 12px;
    top: 104px;
    width: min(320px, calc(100vw - 24px));
  }

  .vision-panel[data-mode="face"],
  .vision-panel[data-mode="idle"] {
    width: min(150px, calc(100vw - 24px));
  }

  .vision-panel[data-mode="capture"] {
    width: min(320px, calc(100vw - 24px));
  }

  .controls {
    right: 12px;
    bottom: 12px;
  }
}

@media (max-width: 360px) {
  h1 {
    font-size: 28px;
  }

  #statusText {
    display: none;
  }
}
