:root {
  color-scheme: light;
  --ink: #20211f;
  --muted: #74756f;
  --paper: #f3f2ed;
  --surface: #fff;
  --surface-soft: #f8f7f3;
  --line: #deddd6;
  --line-strong: #c9c8c0;
  --coral: #ef665b;
  --coral-dark: #d84f46;
  --coral-soft: #fff0ed;
  --green: #3f8f69;
  --green-soft: #e9f4ed;
  --blue-soft: #eaf1fb;
  --blue: #3e6597;
  --shadow: 0 22px 60px rgba(28, 28, 24, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
}

body,
button,
textarea {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
textarea {
  font-size: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

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

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(62, 101, 151, 0.25);
  outline-offset: 2px;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 3px minmax(0, 1fr);
}

.topbar {
  background: var(--ink);
  color: #fff;
  padding: max(12px, env(safe-area-inset-top)) 24px 12px;
}

.topbar-inner {
  width: min(1180px, 100%);
  min-height: 48px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark,
.welcome-mark,
.portrait-mark {
  display: grid;
  place-items: center;
  background: var(--coral);
  color: #fff;
  font-weight: 800;
  line-height: 1;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  font-size: 17px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  margin-top: 1px;
  color: rgba(255, 255, 255, 0.58);
  font-size: 11px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  color: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.topbar-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
}

.topbar-link svg {
  width: 16px;
  height: 16px;
}

.connection-dot,
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e0a74d;
}

.connection.online .connection-dot {
  background: #58be86;
  box-shadow: 0 0 0 3px rgba(88, 190, 134, 0.15);
}

.connection.error .connection-dot,
.status-line.error .status-dot {
  background: var(--coral);
}

.progress-track {
  overflow: hidden;
  background: #d4d3cd;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 350ms ease;
}

.workspace {
  width: min(1180px, 100%);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  background: var(--surface);
  border-inline: 1px solid var(--line);
}

.interview {
  min-width: 0;
  min-height: calc(100dvh - 75px);
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto auto auto;
  background: var(--surface);
}

.interview-head,
.profile-head,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.interview-head {
  padding: 22px 28px 17px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.interview-head h1,
.profile-head h2,
.dialog-head h2 {
  margin: 0;
}

.interview-head h1 {
  font-size: 20px;
  line-height: 1.35;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.voice-toggle.active {
  color: var(--green);
  background: var(--green-soft);
  border-color: #b9d9c6;
}

.transcript {
  min-height: 0;
  overflow-y: auto;
  padding: 28px max(28px, calc((100% - 680px) / 2));
  scroll-behavior: smooth;
}

.welcome {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.welcome-mark,
.portrait-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  font-size: 22px;
}

.welcome h2 {
  margin: 19px 0 9px;
  font-size: 24px;
}

.welcome p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.primary-button,
.secondary-button,
.send-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 700;
}

.primary-button,
.send-button {
  background: var(--coral);
  color: #fff;
  border: 1px solid var(--coral);
}

.primary-button:hover:not(:disabled),
.send-button:hover:not(:disabled) {
  background: var(--coral-dark);
  border-color: var(--coral-dark);
}

.welcome .primary-button {
  margin-top: 25px;
  min-width: 148px;
}

.primary-button.compact {
  min-width: 150px;
}

.secondary-button {
  background: #fff;
  border: 1px solid var(--line-strong);
}

.secondary-button:hover {
  background: var(--surface-soft);
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 18px;
}

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

.message-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.message-bubble {
  max-width: min(82%, 570px);
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  background: var(--coral-soft);
  border-color: #f1c5c0;
}

.message.system .message-bubble {
  max-width: 100%;
  background: var(--blue-soft);
  color: #355475;
  border-color: #c9d9ec;
  font-size: 13px;
}

.message.system.error .message-bubble {
  background: #fff0ee;
  color: #9f3933;
  border-color: #efc2bd;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 18px;
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 140ms;
}

.typing i:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.status-line {
  min-height: 35px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 28px;
  color: var(--muted);
  font-size: 12px;
}

.status-line .status-dot {
  background: var(--green);
}

.composer {
  margin: 0 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.composer:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(63, 143, 105, 0.1);
}

.composer textarea {
  width: 100%;
  max-height: 128px;
  min-height: 40px;
  padding: 9px 6px;
  resize: none;
  overflow-y: auto;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: #9a9a94;
}

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

.mic-button.listening {
  color: #fff;
  background: var(--coral);
  border-color: var(--coral);
  animation: listen 1.4s infinite ease-out;
}

@keyframes listen {
  0% { box-shadow: 0 0 0 0 rgba(239, 102, 91, 0.35); }
  70% { box-shadow: 0 0 0 8px rgba(239, 102, 91, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 102, 91, 0); }
}

.send-button {
  min-width: 92px;
}

.quick-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 13px 28px 18px;
}

.quick-actions button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-size: 12px;
}

.quick-actions button:hover:not(:disabled) {
  color: var(--ink);
  background: var(--surface-soft);
}

.quick-actions svg {
  width: 16px;
  height: 16px;
}

.profile-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 25px 22px;
  background: var(--surface-soft);
  border-left: 1px solid var(--line);
}

.profile-head h2 {
  font-size: 17px;
}

.field-count {
  min-width: 32px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.profile-state {
  margin: 16px 0 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.profile-fields {
  min-height: 120px;
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}

.profile-field {
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.profile-field dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.profile-field dd {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.pending-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  color: var(--blue);
  font-size: 11px;
}

.pending-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  animation: typing 1.1s infinite ease-in-out;
}

.privacy-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.5;
}

.privacy-note svg {
  width: 15px;
  height: 15px;
  color: var(--green);
}

dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: min(820px, calc(100dvh - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(24, 25, 23, 0.58);
  backdrop-filter: blur(3px);
}

.dialog-shell {
  max-height: inherit;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.dialog-head {
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  font-size: 20px;
}

.dialog-body {
  overflow-y: auto;
}

.json-body {
  padding: 18px 22px;
  background: #262724;
}

.json-body pre {
  margin: 0;
  color: #e9eadf;
  font: 12px/1.7 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 15px 22px;
  border-top: 1px solid var(--line);
}

.portrait-dialog {
  width: min(760px, calc(100vw - 32px));
}

.portrait-hero {
  position: relative;
  padding: 28px 32px 25px;
  background: var(--blue-soft);
  border-bottom: 1px solid #cbd9e9;
}

.portrait-hero .close-on-color {
  position: absolute;
  top: 16px;
  right: 16px;
  border-color: rgba(32, 33, 31, 0.16);
}

.portrait-mark {
  margin-bottom: 17px;
}

.portrait-hero .eyebrow {
  color: var(--blue);
}

.portrait-hero h2 {
  max-width: 630px;
  margin: 0;
  padding-right: 40px;
  font-size: 25px;
  line-height: 1.35;
}

.portrait-hero > p:not(.eyebrow) {
  max-width: 650px;
  margin: 12px 0 0;
  color: #4e5f70;
  font-size: 14px;
  line-height: 1.8;
}

.portrait-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 16px;
}

.portrait-tag {
  padding: 5px 9px;
  border: 1px solid #b9cce2;
  border-radius: 5px;
  color: #355474;
  background: rgba(255, 255, 255, 0.52);
  font-size: 11px;
  font-weight: 700;
}

.portrait-body {
  padding: 25px 32px 30px;
}

.portrait-opener {
  margin: 0 0 20px;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.65;
}

.portrait-section {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 20px;
  padding: 19px 0;
  border-top: 1px solid var(--line);
}

.portrait-section h3 {
  margin: 0;
  color: var(--green);
  font-size: 14px;
  line-height: 1.6;
}

.portrait-section p {
  margin: 0;
  font-size: 14px;
  line-height: 1.85;
}

.confidence-note {
  margin: 18px 0 0;
  padding: 12px 14px;
  color: var(--muted);
  background: var(--surface-soft);
  border-left: 3px solid var(--line-strong);
  font-size: 11px;
  line-height: 1.65;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 20;
  padding: 9px 14px;
  border-radius: 5px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 8px 24px rgba(20, 20, 18, 0.2);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    border-inline: 0;
  }

  .profile-panel {
    display: none;
  }

  .interview {
    min-height: calc(100dvh - 75px);
  }
}

@media (max-width: 600px) {
  .topbar {
    padding-inline: 16px;
  }

  .brand small {
    display: none;
  }

  .topbar-actions {
    gap: 10px;
  }

  .topbar-link {
    padding-inline: 8px;
  }

  .topbar-link span {
    font-size: 11px;
  }

  .connection span:last-child {
    display: none;
  }

  .interview-head {
    padding: 17px 16px 14px;
  }

  .interview-head h1 {
    font-size: 17px;
  }

  .transcript {
    padding: 20px 16px;
  }

  .welcome {
    padding-inline: 8px;
  }

  .welcome h2 {
    font-size: 21px;
  }

  .message-bubble {
    max-width: 88%;
    font-size: 14px;
  }

  .status-line {
    padding-inline: 16px;
  }

  .composer {
    margin-inline: 12px;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .quick-actions {
    padding: 10px 10px max(14px, env(safe-area-inset-bottom));
    justify-content: space-between;
  }

  .quick-actions button {
    padding-inline: 7px;
  }

  .dialog-actions {
    padding: 12px 14px;
  }

  .dialog-actions > * {
    flex: 1;
    min-width: 0;
    padding-inline: 10px;
  }

  .portrait-hero,
  .portrait-body {
    padding-inline: 20px;
  }

  .portrait-hero h2 {
    font-size: 21px;
  }

  .portrait-section {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
