:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-strong: #eef4f0;
  --ink: #14211d;
  --muted: #64736f;
  --line: #dce6e2;
  --accent: #0f8f7a;
  --accent-dark: #08705f;
  --warn: #b95024;
  --shadow: 0 18px 48px rgba(15, 43, 36, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100svh;
  background:
    linear-gradient(180deg, rgba(15, 143, 122, 0.12), rgba(246, 248, 247, 0) 34%),
    var(--bg);
}

.view {
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
}

.hidden {
  display: none !important;
}

.auth-view {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 34px;
}

.brand-block h1,
.top-bar h1,
.chat-heading h1 {
  margin: 4px 0 0;
  font-size: 30px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

.subtle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.auth-form,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  outline: 0;
  padding: 14px 13px;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 143, 122, 0.16);
}

.primary-button,
.secondary-button,
.icon-text-button,
.ghost-button {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  background: var(--accent);
  color: #fff;
}

.primary-button:active {
  background: var(--accent-dark);
}

.secondary-button,
.icon-text-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.82);
  color: var(--accent-dark);
}

.top-bar,
.floating-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-bar {
  margin-bottom: 22px;
}

.entry-grid {
  display: grid;
  gap: 14px;
}

.entry-card {
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: auto auto;
  gap: 4px 14px;
  align-items: center;
  width: 100%;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 18px;
  text-align: left;
}

.entry-card strong {
  font-size: 18px;
}

.entry-card small {
  color: var(--muted);
  font-size: 13px;
}

.entry-icon {
  display: grid;
  grid-row: 1 / 3;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  font-size: 25px;
}

.capture-view {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: #0a100e;
  color: #fff;
}

.floating-bar {
  position: absolute;
  z-index: 4;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
}

.status-pill {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  padding: 8px 12px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.camera-pane,
.preview-pane {
  position: relative;
  flex: 1;
  min-height: 0;
}

#cameraVideo,
.image-stage,
#previewImage {
  width: 100%;
  height: 100%;
}

#cameraVideo,
#previewImage {
  display: block;
  object-fit: contain;
  background: #050807;
}

.image-stage {
  position: relative;
  overflow: hidden;
}

.bbox-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bbox {
  position: absolute;
  border: 2px solid #28e0b8;
  border-radius: 4px;
  pointer-events: auto;
}

.bbox span {
  position: absolute;
  left: -2px;
  top: -28px;
  max-width: 160px;
  overflow: hidden;
  border-radius: 4px;
  background: #28e0b8;
  color: #02251f;
  padding: 4px 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.camera-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #fff;
  text-align: center;
}

.capture-controls {
  position: absolute;
  z-index: 5;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 1fr 86px 1fr;
  gap: 10px;
  align-items: center;
}

.capture-controls .primary-button,
.capture-controls .secondary-button {
  margin: 0;
}

.round-button {
  min-height: 48px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 800;
}

.shutter-button {
  justify-self: center;
  width: 74px;
  height: 74px;
  border: 5px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 5px rgba(10, 16, 14, 0.12);
}

.preview-pane .result-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 116px;
  max-height: 42svh;
  overflow: auto;
  color: var(--ink);
}

.result-panel h2,
.result-panel h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.result-panel p {
  margin: 8px 0;
  line-height: 1.55;
}

.audio-row,
.item-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.audio-row button,
.item-button {
  min-height: 38px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  padding: 8px 10px;
  text-align: left;
}

.chat-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-heading {
  min-width: 0;
  text-align: center;
}

.chat-heading h1 {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.role-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 0 8px;
}

.role-card {
  flex: 0 0 116px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
  color: var(--ink);
  text-align: center;
}

.role-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 143, 122, 0.14);
}

.role-card img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-strong);
}

.role-card span {
  display: block;
  min-height: 36px;
  margin-top: 8px;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.message {
  max-width: 86%;
  margin-bottom: 12px;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.55;
  word-break: break-word;
}

.message.user {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
}

.message.bot {
  margin-right: auto;
  background: var(--surface-strong);
  color: var(--ink);
}

.message.error {
  background: #fff1e9;
  color: var(--warn);
}

.chat-controls {
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.record-button {
  width: 100%;
  min-height: 58px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
}

.record-button.recording {
  background: #ca3c2f;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 18px;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  border-radius: 8px;
  background: rgba(20, 33, 29, 0.92);
  color: #fff;
  padding: 13px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .view {
    max-width: 560px;
    margin: 0 auto;
  }

  .capture-view {
    max-width: none;
  }

  .capture-view .floating-bar,
  .capture-view .capture-controls,
  .preview-pane .result-panel {
    left: 50%;
    right: auto;
    width: min(540px, calc(100vw - 24px));
    transform: translateX(-50%);
  }
}
