/* The review page. Colours are custom properties; dark mode follows the system. */

:root {
  color-scheme: light dark;
  --page: #e6e9ee;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #e8ecf1;
  --text: #1b1f24;
  --text-soft: #5b6572;
  --line: #dfe3e9;
  --line-strong: #c3cad3;
  --accent: #2b6cb0;
  --accent-strong: #1f5a99;
  --accent-soft: #e2edf9;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --focus: #2b6cb0;
  --overlay: rgba(15, 20, 28, 0.45);
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0b0d10;
    --bg: #121519;
    --surface: #1b1f25;
    --surface-soft: #272c34;
    --text: #e8eaed;
    --text-soft: #a0a8b3;
    --line: #2a3038;
    --line-strong: #454d59;
    --accent: #3672b6;
    --accent-strong: #a3c8ef;
    --accent-soft: #1f3247;
    --on-accent: #ffffff;
    --danger: #f2a199;
    --focus: #8ab8ea;
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--page);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

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

:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- the column ---------- */

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  height: 100vh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
}

@supports (height: 100dvh) {
  .app {
    height: 100dvh;
  }
}

/* Set by the script to the height that is really visible, so the composer stays above the keyboard. */
html.fit .app {
  height: var(--app-height);
}

@media (min-width: 721px) {
  .app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

.view {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

/* ---------- buttons, links, fields ---------- */

.btn {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin: 0;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-appearance: none;
  appearance: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-tonal {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.btn-quiet {
  background: transparent;
  color: var(--text-soft);
}

.btn-block {
  width: 100%;
  min-height: 46px;
  font-size: 16px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.link {
  min-height: 40px;
  margin: -12px -6px;
  padding: 12px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 16px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  touch-action: manipulation;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
}

.field {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-appearance: none;
  appearance: none;
}

.field:focus {
  border-color: var(--accent);
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.field::placeholder,
.composer-text::placeholder {
  color: var(--text-soft);
  opacity: 0.75;
}

.field-area {
  min-height: 104px;
  resize: vertical;
}

.form-error {
  margin-top: 10px;
  color: var(--danger);
  font-size: 14px;
}

/* ---------- start and sign-in ---------- */

.view-notice {
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

.notice-text {
  max-width: 28em;
  color: var(--text-soft);
  font-size: 15px;
}

.view-notice .link {
  margin: 0;
  font-size: 13px;
}

.view-signin {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.signin-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 360px;
  margin: auto;
}

.signin-avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
}

.brand-name {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 15px;
  text-align: center;
  overflow-wrap: anywhere;
}

.signin-form {
  margin-top: 28px;
}

#signin-code {
  letter-spacing: 0.04em;
}

.signin-form .btn-block {
  margin-top: 16px;
}

.brand-notice {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
}

/* ---------- the bar at the top of the chat and of the rating ---------- */

.bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.bar-title {
  flex: 1 1 auto;
  min-width: 0;
}

.bar-name {
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  line-height: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
}

.bar-label {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar .link {
  flex: none;
}

@media (max-width: 359px) {
  .bar {
    gap: 6px;
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
  }

  .bar .btn {
    padding: 0 10px;
    font-size: 14px;
  }

  .bar .avatar {
    width: 32px;
    height: 32px;
  }
}

/* ---------- messages ---------- */

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
}

.messages:focus-visible {
  outline-offset: -2px;
}

.intro {
  margin: 8px auto 16px;
  max-width: 30em;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}

.turn {
  margin-top: 10px;
}

.row {
  display: flex;
  align-items: flex-end;
  margin-top: 4px;
}

.row-user {
  justify-content: flex-end;
}

.row-bot {
  gap: 8px;
  justify-content: flex-start;
}

.avatar-small {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

/* Only the first bubble of a reply shows the face; the others keep its space. */
.row-follow .avatar-small {
  visibility: hidden;
}

.bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: rise 0.18s ease-out;
}

.bubble-user {
  border-bottom-right-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
}

.bubble-bot {
  border-bottom-left-radius: 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 39px;
  padding: 8px 14px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-soft);
  opacity: 0.35;
  animation: blink 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }

  30% {
    opacity: 0.95;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.cut-note {
  margin: 4px 0 0 38px;
  color: var(--text-soft);
  font-size: 12px;
}

.system-line {
  margin: 14px auto 6px;
  max-width: 26em;
  padding: 0 8px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.system-line.is-error {
  color: var(--danger);
}

/* ---------- marks under a reply ---------- */

.feedback {
  margin: 0 0 0 30px;
}

.feedback-buttons {
  display: flex;
  align-items: center;
  gap: 2px;
}

.thumb {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: transparent;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  filter: grayscale(1);
  opacity: 0.6;
}

.thumb[aria-pressed="true"] {
  background: var(--accent-soft);
  filter: none;
  opacity: 1;
}

.thumb:disabled,
.chip:disabled {
  cursor: default;
}

.thumb:disabled:not([aria-pressed="true"]) {
  opacity: 0.3;
}

.feedback-status {
  margin-left: 6px;
  color: var(--danger);
  font-size: 12px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 8px 8px;
}

.chip {
  min-height: 40px;
  margin: 0;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 500;
}

.chip:disabled:not([aria-pressed="true"]) {
  opacity: 0.45;
}

/* ---------- composer ---------- */

.composer {
  flex: none;
  padding: 8px 12px 4px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-box {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--bg);
}

.composer-box:focus-within {
  border-color: var(--accent);
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.composer-text {
  display: block;
  width: 100%;
  height: 38px;
  min-height: 38px;
  max-height: 126px;
  margin: 0;
  padding: 8px 14px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 22px;
  resize: none;
  overflow-y: auto;
  -webkit-appearance: none;
  appearance: none;
}

/* The box around it shows the focus. */
.composer-text:focus,
.composer-text:focus-visible {
  outline: none;
}

.composer .btn {
  min-width: 64px;
  border-radius: 20px;
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-height: 18px;
  margin-top: 2px;
  padding: 0 4px;
  color: var(--text-soft);
  font-size: 11px;
  line-height: 18px;
}

.composer-hint {
  display: none;
  margin-right: auto;
}

@media (hover: hover) and (pointer: fine) {
  .composer-hint {
    display: inline;
  }
}

.composer-count {
  font-variant-numeric: tabular-nums;
}

.composer-count.is-over {
  color: var(--danger);
  font-weight: 600;
}

.closed-bar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  font-size: 14px;
}

/* ---------- rating ---------- */

.rating-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
}

.rating-form,
.rating-done {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.rating-intro {
  margin: 0 4px 14px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.6;
}

.card {
  min-width: 0;
  margin: 0 0 12px;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.scale-label {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.scale-hint {
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
}

.scale-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.score {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.score[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.flags-title {
  float: left;
  width: 100%;
  margin: 0 0 4px;
  padding: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.flags-title + * {
  clear: both;
}

.flag {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 0;
  font-size: 15px;
  line-height: 1.45;
  cursor: pointer;
}

.flag input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.rating-form .btn-block {
  margin-top: 14px;
}

.rating-done {
  padding-top: 15vh;
  text-align: center;
}

.thanks {
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 600;
}

.thanks:focus,
.bar-name:focus {
  outline: none;
}

.rating-done .btn-block {
  margin-top: 12px;
}

/* ---------- the question before leaving an unrated conversation ---------- */

.sheet-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--overlay);
}

.sheet {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 16px 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border-radius: 18px 18px 0 0;
  background: var(--surface);
}

.sheet-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

.sheet-text {
  margin: 6px 0 10px;
  color: var(--text-soft);
  font-size: 14px;
}

.sheet .btn-block {
  margin-top: 10px;
}

@media (min-width: 560px) {
  .sheet-backdrop {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    border-radius: 18px;
    padding-bottom: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* History remains available after starting or rating another conversation. */
.conversation-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
}
.conversation-nav label { flex: none; color: var(--text-soft); }
.conversation-nav select {
  min-width: 0;
  flex: 1;
  min-height: 36px;
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background-color: var(--bg);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-soft) 50%), linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  appearance: none;
  font: inherit;
}
.chat-error { flex: none; margin: 0; padding: 10px 16px; color: var(--danger); background: var(--surface); font-size: 14px; }
.welcome { max-width: 360px; margin: 15vh auto 24px; padding: 0 16px; text-align: center; }
.welcome-title { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.welcome-copy { margin: 14px 0 24px; color: var(--text-soft); font-size: 16px; line-height: 1.75; }
.thumb { min-width: 56px; padding: 0 8px; font-size: 14px; }
.feedback-status { color: var(--text-soft); font-size: 14px; line-height: 1.5; }
.pending { opacity: .7; }
.link, .view-notice .link, .bar-sub, .brand-notice, .intro, .cut-note,
.system-line, .composer-meta, .scale-hint { font-size: 14px; line-height: 1.5; }
.composer-meta { min-height: 24px; }
.bar .btn { min-height: 44px; }
.conversation-nav select:disabled { opacity: .65; }
@media (max-width: 480px) {
  .view-chat > .bar { flex-wrap: wrap; padding: 10px 12px; }
  .view-chat > .bar .bar-title { flex-basis: calc(100% - 60px); }
  .view-chat > .bar > .btn { flex: 1; }
  .composer-hint { display: none; }
  .welcome { margin-top: 10vh; }
}
