:root {
  --bg: #f7f2ec;
  --card: #fffaf4;
  --ink: #26201b;
  --muted: #74695f;
  --line: #eadfd3;
  --accent: #8f1d2c;
  --accent-dark: #6f1420;
  --soft: #f2e1d5;
  --success: #246b4a;
  --shadow: 0 18px 50px rgba(72, 37, 22, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(143,29,44,0.12), transparent 35%),
    linear-gradient(180deg, #fff8ef 0%, var(--bg) 100%);
  min-height: 100vh;
}

.phone-shell {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 18px;
  min-height: 100vh;
  display: grid;
  align-items: center;
}

.admin-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px 18px 60px;
}
.admin-shell.narrow { width: min(480px, 100%); min-height: 100vh; display: grid; align-items: center; }

.card {
  background: rgba(255, 250, 244, 0.96);
  border: 1px solid rgba(234, 223, 211, 0.9);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.hero h1, .card h1 { font-size: clamp(2rem, 7vw, 3.5rem); line-height: 0.98; margin: 0 0 16px; letter-spacing: -0.04em; }
h2 { font-size: clamp(1.35rem, 5vw, 2rem); line-height: 1.12; margin: 0 0 16px; letter-spacing: -0.03em; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: 0.13em; font-weight: 800; font-size: 0.76rem; margin: 0 0 10px; }
.muted { color: var(--muted); line-height: 1.55; }
.tiny { color: var(--muted); font-size: 0.78rem; line-height: 1.4; margin-top: 14px; }
.hidden { display: none !important; }
.center { text-align: center; }

button, .link-button {
  border: 0;
  border-radius: 999px;
  padding: 15px 18px;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
button:active, .link-button:active { transform: translateY(1px) scale(0.99); }
.primary { background: var(--accent); color: white; box-shadow: 0 10px 24px rgba(143,29,44,0.24); width: 100%; }
.primary:hover { background: var(--accent-dark); }
.secondary { background: var(--soft); color: var(--accent-dark); width: 100%; margin-top: 10px; }
.compact { width: auto; padding: 12px 16px; font-size: 0.92rem; }

.consent-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 12px;
  align-items: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin: 22px 0;
  color: var(--muted);
  line-height: 1.45;
}
.consent-row input { width: 20px; height: 20px; accent-color: var(--accent); }

.progress-wrap { margin-bottom: 24px; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-weight: 700; font-size: 0.85rem; margin-bottom: 9px; }
.progress { background: var(--soft); height: 10px; border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .25s ease; }

.scale-labels { display: flex; justify-content: space-between; gap: 12px; font-size: 0.78rem; color: var(--muted); margin: 4px 0 14px; }
.button-grid { display: grid; gap: 10px; }
.button-grid.five { grid-template-columns: repeat(5, 1fr); }
.button-grid.nps, .button-grid.ten { grid-template-columns: repeat(5, 1fr); }
.choice {
  background: #fff;
  border: 1.5px solid var(--line);
  color: var(--ink);
  min-height: 56px;
  border-radius: 18px;
  box-shadow: none;
}
.question-step .choice {
  justify-content: flex-start;
  text-align: left;
}
.choice.selected { border-color: var(--accent); background: #fff1f2; color: var(--accent-dark); }
.matrix-scale-legend { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 4px 0 18px; color: var(--muted); font-size: 0.68rem; text-align: center; }
.matrix-scale-legend span { display: grid; gap: 2px; align-content: start; }
.matrix-scale-legend strong { color: var(--accent-dark); font-size: 0.82rem; }
.matrix-question-list { display: grid; gap: 18px; }
.matrix-rating-row { border-top: 1px solid var(--line); padding-top: 14px; }
.matrix-rating-row:first-child { border-top: 0; padding-top: 0; }
.matrix-item-label { margin: 0 0 10px; font-weight: 800; line-height: 1.35; }
.stacked-options { display: grid; gap: 10px; }
.pill { justify-content: flex-start; padding-left: 18px; border-radius: 18px; }
.survey-nav { display: grid; gap: 10px; margin-top: 16px; }
.survey-nav.two-actions { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); }
.survey-nav .secondary { margin-top: 0; }
.survey-back-btn { min-width: 104px; }

textarea, input[type="password"], input[type="date"], input[type="text"], input[type="number"] {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 15px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  outline: none;
}
textarea { min-height: 148px; resize: vertical; margin: 10px 0 16px; }
textarea:focus, input[type="password"]:focus, input[type="date"]:focus, input[type="text"]:focus, input[type="number"]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(143,29,44,0.08); }

.chat-box {
  display: grid;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  max-height: 44vh;
  overflow: auto;
  margin: 14px 0;
}
.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.bubble.assistant { background: var(--soft); color: var(--ink); border-bottom-left-radius: 6px; }
.bubble.user { background: var(--accent); color: #fff; margin-left: auto; border-bottom-right-radius: 6px; }
.phase-banner {
  display: grid;
  gap: 3px;
  margin: 12px 0 8px;
  padding: 12px 14px;
  border: 1px solid rgba(143,29,44,0.22);
  border-radius: 16px;
  background: #fff1f2;
  color: var(--accent-dark);
}
.phase-banner strong { font-size: 0.9rem; letter-spacing: 0.01em; }
.phase-banner span { color: var(--muted); font-size: 0.82rem; line-height: 1.35; }
.phase-divider {
  width: 100%;
  max-width: 100%;
  margin: 8px 0 4px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  background: #fffaf4;
}
.bubble.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  min-width: 70px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .35;
  animation: typingPulse 1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .14s; }
.typing-dot:nth-child(3) { animation-delay: .28s; }
@keyframes typingPulse {
  0%, 60%, 100% { transform: translateY(0); opacity: .28; }
  30% { transform: translateY(-3px); opacity: .9; }
}
.chat-wait-label { color: var(--muted); font-size: .74rem; margin-left: 4px; }
.chat-input-row { display: grid; gap: 10px; }
.chat-input-row textarea { min-height: 104px; margin: 0; }
.checkmark { width: 72px; height: 72px; display: grid; place-items: center; margin: 0 auto 18px; background: #e9f7ef; color: var(--success); border-radius: 50%; font-size: 2.2rem; font-weight: 900; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-weight: 700;
  max-width: calc(100vw - 36px);
}
.error-text { color: #b00020; font-weight: 700; }
.login-form { display: grid; gap: 12px; }
.login-form label { font-weight: 800; }

.admin-filter-card { margin-bottom: 14px; }
.filter-form { display: grid; grid-template-columns: minmax(220px, 1.4fr) repeat(4, minmax(140px, 0.8fr)) auto; gap: 14px; align-items: end; }
.filter-form label { display: grid; gap: 6px; font-weight: 800; color: var(--muted); font-size: 0.86rem; }
.filter-form h2 { margin-bottom: 8px; }
.filter-form .muted { margin: 0; }
code { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 20px; }
.admin-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.admin-actions .secondary { margin-top: 0; width: auto; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.metric { padding: 18px; }
.metric span { color: var(--muted); font-weight: 800; font-size: 0.82rem; }
.metric strong { display: block; font-size: 2.1rem; margin-top: 8px; letter-spacing: -0.04em; }
.section-title-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.bar-list { display: grid; gap: 16px; }
.bar-label { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 7px; font-size: 0.92rem; }
.bar-label strong { color: var(--accent-dark); }
.bar-bg { height: 13px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar-bg span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.summary-box { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 16px; white-space: pre-wrap; font: inherit; color: var(--ink); min-height: 120px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); padding: 10px; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; }
td { max-width: 360px; }

@media (max-width: 720px) {
  .card { padding: 21px; border-radius: 24px; }
  .button-grid.nps, .button-grid.ten { grid-template-columns: repeat(3, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-header, .section-title-row { align-items: stretch; flex-direction: column; }
  .filter-form { grid-template-columns: 1fr; }
  .admin-actions, .admin-actions .secondary, .compact { width: 100%; }
}


.knowledge-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.knowledge-form label { display: grid; gap: 6px; font-weight: 800; color: var(--muted); font-size: 0.86rem; }
.knowledge-form label:nth-child(3) { grid-column: 1 / -1; }
.compact-text { max-height: 7.6em; overflow: auto; margin: 8px 0; }
@media (max-width: 720px) { .knowledge-form { grid-template-columns: 1fr; } .knowledge-form label:nth-child(3) { grid-column: auto; } }

.prompt-form { display: grid; gap: 14px; margin-top: 18px; }
.prompt-form label, .import-form label { display: grid; gap: 6px; font-weight: 800; color: var(--muted); font-size: 0.86rem; }
.prompt-form textarea { min-height: 132px; margin: 6px 0 4px; font-size: 0.92rem; }
.prompt-form label:nth-child(2) textarea { min-height: 280px; }
.import-form { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: end; margin-top: 18px; }
input[type="file"] { width: 100%; border: 1.5px solid var(--line); border-radius: 18px; padding: 13px; font: inherit; color: var(--ink); background: #fff; }
@media (max-width: 720px) { .import-form { grid-template-columns: 1fr; } }
.prompt-form textarea.large-prompt { min-height: 620px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 0.88rem; line-height: 1.55; }

select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  padding: 15px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  outline: none;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(143,29,44,0.08); }
.small-metric { font-size: 1.15rem !important; word-break: break-word; }
.demo-grid { display: grid; grid-template-columns: 1.4fr 0.6fr; gap: 14px; align-items: end; }
.demo-grid label, .full-width-label, .demo-rating-grid label, .demo-inline-controls label { display: grid; gap: 6px; font-weight: 800; color: var(--muted); font-size: 0.86rem; }
.demo-details { margin-top: 12px; border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #fff; }
.demo-details summary { cursor: pointer; font-weight: 900; color: var(--accent-dark); }
.demo-rating-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 14px; }
.demo-inline-controls { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.demo-inline-controls label { max-width: 120px; }
.demo-chat-box { min-height: 180px; max-height: 56vh; }
.demo-results { margin-top: 14px; }
.demo-alerts ul { margin: 8px 0 0; padding-left: 22px; }
.warn-box { background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; border-radius: 18px; padding: 14px; }
.ok-box { background: #ecfdf5; border: 1px solid #bbf7d0; color: #14532d; border-radius: 18px; padding: 14px; }
.ok-text { color: #166534; font-weight: 800; }
.demo-metadata { margin-top: 16px; }
.demo-meta-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 12px 0; }
.demo-meta-grid > div { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.batch-run { border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; background: #fff; margin: 12px 0; }
.batch-run summary { cursor: pointer; font-weight: 900; color: var(--accent-dark); }
.batch-alerts { margin: 10px 0; }
.batch-transcript { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; display: grid; gap: 6px; }
.demo-transcript-line { padding: 8px 10px; border-radius: 12px; background: var(--soft); }
.demo-transcript-line.user { background: #fff1f2; }
.demo-transcript-line.assistant { background: #f8fafc; }
@media (max-width: 720px) {
  .demo-grid, .demo-rating-grid, .demo-meta-grid { grid-template-columns: 1fr; }
  .demo-inline-controls, .demo-inline-controls label { width: 100%; max-width: none; }
}
.notice { border-radius: 18px; padding: 14px 16px; margin: 14px 0; font-weight: 800; }
.notice.success { background: #ecfdf5; border: 1px solid #bbf7d0; color: #14532d; }
.notice.warning { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; }

/* Admin response-level AI/customer conversation viewer */
.conversation-selector { display: grid; grid-template-columns: 1fr minmax(340px, 1.2fr) auto; gap: 14px; align-items: end; }
.conversation-selector label { display: grid; gap: 6px; font-weight: 800; color: var(--muted); font-size: 0.86rem; }
.conversation-selector h2 { margin-bottom: 8px; }
.conversation-selector .muted { margin: 0; }
.conversation-meta-grid { grid-template-columns: 1.6fr 1.2fr 0.8fr 0.6fr; }
.response-id-text, .response-id-cell { overflow-wrap: anywhere; word-break: break-word; }
.response-id-cell { min-width: 180px; }
.table-action-link { display: inline-block; color: var(--accent-dark); font-weight: 900; text-decoration: none; border-bottom: 1px solid currentColor; }
.table-action-link:hover { color: var(--accent); }
.conversation-context-card { margin-bottom: 14px; }
.conversation-context-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; }
.conversation-context-grid p { line-height: 1.55; margin: 7px 0 16px; }
.context-label { display: block; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 900; }
.context-comment { font-size: 1.05rem; }
.context-customer-speech { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 7px; align-items: center; margin-top: 8px; }
.context-speaker-avatar { align-self: center; }
.speech-comment { position: relative; margin: 0 !important; padding: 11px 13px; background: #fff0f2; border: 1px solid #f0d2d7; border-radius: 6px 17px 17px 17px; line-height: 1.55; overflow-wrap: anywhere; box-shadow: 0 4px 12px rgba(72, 37, 22, 0.05); }
.speech-comment::before, .speech-comment::after { content: ""; position: absolute; top: 50%; width: 0; height: 0; border-style: solid; transform: translateY(-50%); }
.speech-comment::before { left: -8px; border-width: 6px 8px 6px 0; border-color: transparent #f0d2d7 transparent transparent; }
.speech-comment::after { left: -6px; border-width: 5px 7px 5px 0; border-color: transparent #fff0f2 transparent transparent; }
.empty-conversation { margin-top: 18px; padding: 18px; background: #fff; border: 1px dashed var(--line); border-radius: 18px; }
.empty-conversation p { margin-bottom: 0; }
@media (max-width: 720px) {
  .conversation-selector, .conversation-context-grid, .conversation-meta-grid { grid-template-columns: 1fr; }
  .context-customer-speech { grid-template-columns: 22px minmax(0, 1fr); gap: 6px; }
}

/* Conversation viewer v1.8.3: extra-compact speech-bubble timeline */
.conversation-timeline-card { overflow: hidden; }
.conversation-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.76rem; font-weight: 900; white-space: nowrap; }

/* Small speaker icons: the bubble tail points directly at the speaker. */
.speaker-avatar { width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; box-shadow: 0 2px 6px rgba(72, 37, 22, 0.08); }
.speaker-avatar svg { width: 15px; height: 15px; overflow: visible; }
.speaker-avatar .icon-line { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.speaker-avatar .icon-fill { fill: currentColor; }
.speaker-avatar .icon-panel { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.speaker-avatar .icon-spark { fill: currentColor; stroke: none; }
.staff-avatar { color: #36566f; background: #e7f1f7; border-color: #c8dce8; }
.customer-avatar { color: var(--accent-dark); background: #fff0f2; border-color: #f0ccd3; }
.mini-avatar { width: 18px; height: 18px; flex-basis: 18px; border-width: 1px; box-shadow: none; }
.mini-avatar svg { width: 11px; height: 11px; }

.conversation-timeline { display: grid; gap: 16px; margin-top: 22px; }
.timeline-message { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 7px; align-items: start; }
.timeline-marker { display: flex; justify-content: center; padding-top: 24px; }
.timeline-content { min-width: 0; max-width: min(78%, 820px); }
.timeline-heading { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 5px; min-height: 20px; }
.timeline-heading strong { font-size: 0.82rem; }
.timeline-message.staff .timeline-heading strong { color: #36566f; }
.timeline-message.customer .timeline-heading strong { color: var(--accent-dark); }
.turn-badge { display: inline-flex; align-items: center; min-height: 20px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); font-size: 0.64rem; font-weight: 900; letter-spacing: 0.04em; }
.timeline-bubble { position: relative; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px 17px 17px 17px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 4px 12px rgba(72, 37, 22, 0.05); }
.timeline-message.staff .timeline-bubble { background: #eef4f8; border-color: #d7e4ec; }
.timeline-message.customer .timeline-bubble { background: #fff0f2; border-color: #f0d2d7; border-radius: 17px 6px 17px 17px; }
.timeline-time { margin-top: 5px; color: var(--muted); font-size: 0.66rem; overflow-wrap: anywhere; }

/* Speech tails make it clear that the nearby icon is saying the text. */
.timeline-message.staff .timeline-bubble::before,
.timeline-message.staff .timeline-bubble::after,
.timeline-message.customer .timeline-bubble::before,
.timeline-message.customer .timeline-bubble::after {
  content: "";
  position: absolute;
  top: 11px;
  width: 0;
  height: 0;
  border-style: solid;
}
.timeline-message.staff .timeline-bubble::before { left: -9px; border-width: 7px 9px 7px 0; border-color: transparent #d7e4ec transparent transparent; }
.timeline-message.staff .timeline-bubble::after { left: -7px; top: 12px; border-width: 6px 8px 6px 0; border-color: transparent #eef4f8 transparent transparent; }

/* Customer messages sit on the right, with the customer icon immediately beside them. */
.timeline-message.customer { grid-template-columns: minmax(0, 1fr) 24px; }
.timeline-message.customer .timeline-marker { grid-column: 2; grid-row: 1; }
.timeline-message.customer .timeline-content { grid-column: 1; grid-row: 1; justify-self: end; width: min(78%, 820px); }
.timeline-message.customer .timeline-heading { justify-content: flex-end; }
.timeline-message.customer .timeline-time { text-align: right; }
.timeline-message.customer .timeline-bubble::before { right: -9px; border-width: 7px 0 7px 9px; border-color: transparent transparent transparent #f0d2d7; }
.timeline-message.customer .timeline-bubble::after { right: -7px; top: 12px; border-width: 6px 0 6px 8px; border-color: transparent transparent transparent #fff0f2; }

@media (max-width: 720px) {
  .conversation-legend { margin-top: 4px; gap: 9px; }
  .speaker-avatar { width: 22px; height: 22px; flex-basis: 22px; }
  .speaker-avatar svg { width: 14px; height: 14px; }
  .mini-avatar { width: 17px; height: 17px; flex-basis: 17px; }
  .mini-avatar svg { width: 10px; height: 10px; }
  .conversation-timeline { gap: 14px; }
  .timeline-message { grid-template-columns: 22px minmax(0, 1fr); gap: 6px; }
  .timeline-message.customer { grid-template-columns: minmax(0, 1fr) 22px; }
  .timeline-marker { padding-top: 24px; }
  .timeline-content, .timeline-message.customer .timeline-content { max-width: none; width: min(86%, 100%); }
  .timeline-bubble { padding: 11px 12px; }
}


.question-helper { margin: -6px 0 14px; }
.multi-options { margin-bottom: 16px; }
.question-continue { margin-top: 16px; }

