/* VPT-857 §1.1: the shipped widget styles — a verbatim port of the example
   widget of VPT-250 (example/widget.css) so the shipped component and the
   hand-written /free page look the same (user decision 2026-10-13).

   Token values are a copy of the editor palette (editor/src/styles.css,
   ТЗ №113/№115: OKLCH, hue 286.98). Tokens live on the .ht-widget root and
   never on :root, so loading this file never repaints the host page; every
   class carries the ht- prefix for the same reason. Dark by default, light
   under prefers-color-scheme: light — the editor's own behaviour. */
.ht-widget {
  --bg: oklch(0.145 0.004 286.98);
  --bg-panel: oklch(0.205 0.006 286.98);
  --bg-elev: oklch(0.269 0.008 286.98);
  --bg-input: oklch(0.145 0.004 286.98);
  --border: oklch(1 0.004 286.98 / 0.1);
  --border-strong: oklch(1 0.005 286.98 / 0.22);
  --text: oklch(0.985 0 0);
  --text-dim: oklch(0.82 0.008 286.98);
  --accent: oklch(0.82 0.065 286.98);
  --accent-soft: oklch(0.82 0.065 286.98 / 0.14);
  --accent-contrast: oklch(0.21 0.01 286.98);
  --ring: oklch(0.7 0.045 286.98);
  --green: oklch(0.85 0.168 155);
  --green-soft: oklch(0.85 0.168 155 / 0.13);
  --amber: oklch(0.85 0.103 75);
  --amber-soft: oklch(0.85 0.103 75 / 0.15);
  --red: oklch(0.85 0.065 25);
  --shadow-panel: oklch(0.1 0.005 286.98 / 0.62);
  --radius: 14px;
  --radius-sm: 10px;
  --dur-1: 120ms;
  --dur-2: 180ms;
  --dur-3: 260ms;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --font-sans: 'Geist Variable', 'Geist', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  .ht-widget {
    --bg: oklch(0.965 0.002 286.98);
    --bg-panel: oklch(1 0 0);
    --bg-elev: oklch(0.97 0.002 286.98);
    --bg-input: oklch(1 0 0);
    --border: oklch(0.92 0.003 286.98);
    --border-strong: oklch(0.85 0.005 286.98);
    --text: oklch(0.145 0.006 286.98);
    --text-dim: oklch(0.5 0.012 286.98);
    --accent: oklch(0.248 0.086 286.98);
    --accent-soft: oklch(0.248 0.086 286.98 / 0.08);
    --accent-contrast: oklch(0.985 0 0);
    --ring: oklch(0.42 0.06 286.98);
    --green: oklch(0.52 0.103 155);
    --green-soft: oklch(0.52 0.103 155 / 0.1);
    --amber: oklch(0.52 0.088 75);
    --amber-soft: oklch(0.52 0.088 75 / 0.12);
    --red: oklch(0.55 0.178 25);
    --shadow-panel: oklch(0.25 0.01 286.98 / 0.22);
    color-scheme: light;
  }
}

/* --- the widget ---------------------------------------------------------- */

.ht-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.ht-widget * {
  box-sizing: border-box;
}
/* The UA rule for [hidden] is `display: none` at zero specificity, so any class
   rule that sets display (.ht-panel, .ht-launcher) silently wins and the
   collapsed state renders anyway. Restate it for the whole widget. */
.ht-widget [hidden] {
  display: none !important;
}
.ht-widget :focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* launcher: the collapsed state */
.ht-widget .ht-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-left: auto;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  box-shadow: 0 6px 20px var(--accent-soft);
  transition:
    filter var(--dur-1) var(--ease-out),
    transform var(--dur-1) var(--ease-out);
}
.ht-widget .ht-launcher:hover {
  filter: brightness(1.08);
}
.ht-widget .ht-launcher:active {
  transform: scale(0.97);
}
/* an active call must stay visible while the panel is collapsed (§4.3) */
.ht-widget .ht-live-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

/* panel: the expanded state */
.ht-widget .ht-panel {
  display: flex;
  flex-direction: column;
  width: 360px;
  /* taller than the log alone would need: the panel also holds the call
     details form, and a squeezed log reads as broken */
  height: min(600px, 100dvh - 32px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px var(--shadow-panel);
  overflow: hidden;
  animation: ht-rise var(--dur-3) var(--ease-out);
}
@keyframes ht-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.ht-widget .ht-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.ht-widget .ht-title {
  font-weight: 600;
  margin-right: auto;
}

/* agent state pill — the editor's .voice-state */
.ht-widget .ht-pill {
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.ht-widget .ht-pill.listening {
  color: var(--green);
  border-color: var(--green);
}
.ht-widget .ht-pill.speaking {
  color: var(--accent);
  border-color: var(--accent);
}
.ht-widget .ht-pill.thinking {
  color: var(--text);
}
.ht-widget .ht-timer {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

/* icon buttons — the base button of the editor */
.ht-widget .ht-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  font: inherit;
  color: inherit;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-out),
    transform var(--dur-1) var(--ease-out);
}
.ht-widget .ht-icon:hover {
  border-color: var(--accent);
}
.ht-widget .ht-icon:active:not(:disabled) {
  transform: scale(0.97);
}
.ht-widget .ht-icon:disabled {
  opacity: 0.45;
  cursor: default;
}

/* transcript — the editor's .chat with .msg-agent / .msg-user / .msg-system */
.ht-widget .ht-log {
  flex: 1;
  min-height: 96px;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ht-widget .ht-msg {
  max-width: 85%;
  padding: 7px 11px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
}
.ht-widget .ht-msg.agent {
  background: var(--bg-elev);
  align-self: flex-start;
}
.ht-widget .ht-msg.user {
  background: var(--accent-soft);
  align-self: flex-end;
}
.ht-widget .ht-msg.interim {
  opacity: 0.6;
  font-style: italic;
}
.ht-widget .ht-msg.system {
  max-width: 100%;
  align-self: center;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}
.ht-widget .ht-empty {
  color: var(--text-dim);
  font-size: 12px;
  margin: auto;
}

/* raw SDK state: the page is also a debugging tool for the integration */
.ht-widget .ht-debug {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  max-height: 5.5em;
  overflow-y: auto;
}

/* composer — the editor's .chat-input-row on a .test-input strip */
.ht-widget .ht-composer {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
}
.ht-widget .ht-composer input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  transition: border-color var(--dur-1) var(--ease-out);
}
.ht-widget .ht-composer input:focus {
  border-color: var(--accent);
  outline: none;
}
.ht-widget .ht-composer input:disabled {
  opacity: 0.45;
}

/* call controls — the editor's .run-btn and .run-btn.danger */
.ht-widget .ht-actions {
  display: flex;
  gap: 8px;
  padding: 0 10px 12px;
}
.ht-widget .ht-btn {
  flex: 1;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  color: var(--accent-contrast);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 1px 8px var(--accent-soft);
  transition:
    filter var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out);
}
.ht-widget .ht-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}
.ht-widget .ht-btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}
.ht-widget .ht-btn-danger {
  background: var(--red);
  border-color: var(--red);
  box-shadow: none;
}

@media (max-width: 480px) {
  .ht-widget {
    right: 8px;
    left: 8px;
    bottom: 8px;
  }
  .ht-widget .ht-panel {
    width: 100%;
    height: min(560px, 100dvh - 16px);
  }
}

/* --- dynamic-variable form: shared by the widget and the call page ------- */

/* Native <details> instead of a scripted toggle — the browser already owns
   the open state, the keyboard and the semantics. */
.ht-widget .ht-details {
  border-bottom: 1px solid var(--border);
  /* shrinkable, so however many fields are declared the panel still ends
     where it should — the block scrolls instead of pushing the composer out.
     During a call it is hidden altogether and the log takes the room back. */
  flex: 0 1 auto;
  max-height: 58%;
  overflow-y: auto;
}
.ht-widget .ht-details > summary {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  cursor: pointer;
  list-style: none;
}
.ht-widget .ht-details > summary::marker,
.ht-widget .ht-details > summary::-webkit-details-marker {
  display: none;
}
.ht-widget .ht-details > summary::before {
  content: '▸';
  display: inline-block;
  width: 1em;
  transition: transform var(--dur-1) var(--ease-out);
}
.ht-widget .ht-details[open] > summary::before {
  transform: rotate(90deg);
}
.ht-widget .ht-details > summary:hover {
  color: var(--text);
}
.ht-widget .ht-details .ht-fields {
  padding: 0 14px 12px;
}
.ht-widget .ht-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.ht-widget .ht-field {
  display: flex;
  flex: 1 1 100%;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.ht-widget .ht-field.half {
  flex-basis: calc(50% - 5px);
}
.ht-widget .ht-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.ht-widget .ht-field input {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  transition: border-color var(--dur-1) var(--ease-out);
}
.ht-widget .ht-field input:hover:not(:read-only) {
  border-color: var(--ring);
}
.ht-widget .ht-field input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.ht-widget .ht-field input:read-only {
  color: var(--text-dim);
  background: var(--bg-elev);
  cursor: default;
}
/* free-form page: a variable is a key/value row the visitor types */
.ht-widget .ht-pair {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
.ht-widget .ht-pair input {
  flex: 1 1 0;
}
.ht-widget .ht-pair .ht-icon {
  flex: none;
}
.ht-widget .ht-details .ht-add-var {
  margin: 0 14px 12px;
}

.ht-widget .ht-field-note {
  flex: 1 1 100%;
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* the secondary action next to Call: chat-only, no microphone, no audio */
.ht-widget .ht-btn-ghost {
  color: var(--text);
  background: none;
  border-color: var(--border-strong);
  box-shadow: none;
}
.ht-widget .ht-btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  filter: none;
}

/* --- avatar mode: the inline card (VPT-935 §1) ---------------------------- */

/* the card lives inside the integrator's container, not in a fixed corner */
.ht-widget[data-mode='avatar'] {
  position: static;
  right: auto;
  bottom: auto;
  z-index: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: var(--ht-card-max-width, 560px);
  /* §1.1 (D2): everything around the square that the viewport must also fit —
     header, captions, controls, card padding; the stage side is
     100dvh minus this. Calibrated on the shipped layout; override in CSS. */
  --ht-stage-reserve: 330px;
  --ht-caption-height: 110px;
}
.ht-widget .ht-avatar-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 1px 2px var(--shadow-panel);
}
.ht-widget .ht-avatar-card-head {
  padding: 0 4px;
}
.ht-widget .ht-avatar-card-name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.ht-widget .ht-avatar-card-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* the square stage — adapts to viewport width AND height, never to content */
.ht-widget .ht-stage {
  position: relative;
  width: min(100%, max(240px, calc(100dvh - var(--ht-stage-reserve))));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 20%, var(--bg-elev), var(--bg));
  outline: 2px solid transparent;
  transition:
    outline-color var(--dur-2) var(--ease-out),
    opacity var(--dur-3) var(--ease-out),
    filter var(--dur-3) var(--ease-out);
}
.ht-widget .ht-stage.ended {
  opacity: 0.55;
  filter: grayscale(0.6);
}
.ht-widget .ht-stage-poster,
.ht-widget .ht-avatar-video,
.ht-widget .ht-avatar-live,
.ht-widget .video-js,
.ht-widget .vjs-tech {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
}
.ht-widget .ht-avatar-video {
  display: block;
}
.ht-widget .ht-avatar-live {
  background: var(--bg-elev);
}
.ht-widget .ht-stage[data-state='listening'] {
  outline-color: var(--green);
}
.ht-widget .ht-stage[data-state='speaking'] {
  outline-color: var(--accent);
}

/* chips on the stage: status top-left, timer top-right, AI label bottom-left */
.ht-widget .ht-chip {
  position: absolute;
  top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 2px var(--shadow-panel);
}
.ht-widget .ht-chip-status {
  left: 10px;
}
.ht-widget .ht-chip-timer {
  right: 10px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.ht-widget .ht-avatar-ai {
  top: auto;
  bottom: 10px;
  left: 10px;
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}
.ht-widget .ht-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--text-dim);
}
.ht-widget .ht-dot.live {
  background: var(--green);
}
.ht-widget .ht-dot.warn {
  background: var(--amber);
}
.ht-widget .ht-dot.err {
  background: var(--red);
}
.ht-widget .ht-dot.pulse {
  animation: ht-pulse 1.2s infinite;
}
@keyframes ht-pulse {
  50% {
    opacity: 0.35;
  }
}
.ht-widget .ht-bars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 12px;
}
.ht-widget .ht-bars i {
  width: 2px;
  height: 3px;
  border-radius: 1px;
  background: var(--green);
  animation: ht-level 0.9s ease-in-out infinite;
}
.ht-widget .ht-bars i:nth-child(2) {
  animation-delay: 0.15s;
}
.ht-widget .ht-bars i:nth-child(3) {
  animation-delay: 0.3s;
}
.ht-widget .ht-bars i:nth-child(4) {
  animation-delay: 0.45s;
}
@keyframes ht-level {
  50% {
    height: 12px;
  }
}

/* captions: a reserved height — the stage above never moves (§1.3) */
.ht-widget .ht-captions {
  height: var(--ht-caption-height);
  padding: 0 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  font-size: 15px;
  line-height: 22px;
  mask-image: linear-gradient(to bottom, transparent, #000 24px);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 24px);
}
.ht-widget .ht-captions.hint {
  justify-content: flex-start;
  color: var(--text-dim);
  font-size: 13.5px;
  mask-image: none;
  -webkit-mask-image: none;
}
.ht-widget .ht-caption {
  margin: 0;
}
.ht-widget .ht-caption-who {
  font-weight: 600;
}

/* controls by phase */
.ht-widget .ht-avatar-card-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ht-widget .ht-avatar-card-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ht-widget .ht-avatar-card .ht-btn {
  height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 14.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.ht-widget .ht-btn-primary {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}
.ht-widget .ht-btn-block {
  flex: 1;
  width: 100%;
}
.ht-widget .ht-icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
}
.ht-widget .ht-icon-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.ht-widget .ht-mic-slash {
  display: none;
}
.ht-widget .ht-muted {
  background: var(--bg-elev);
  color: var(--text-dim);
}
.ht-widget .ht-muted .ht-mic-slash {
  display: block;
}
.ht-widget .ht-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}
.ht-widget .ht-status-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.ht-widget .ht-status-duration {
  font-weight: 400;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--text-dim);
}
.ht-widget .ht-status-sub {
  margin: 2px 0 0;
  font-size: 13.5px;
  color: var(--text-dim);
}
.ht-widget .ht-link {
  align-self: center;
  padding: 0;
  border: 0;
  background: none;
  font: 500 13.5px var(--font-sans);
  color: var(--text-dim);
  cursor: pointer;
}
.ht-widget .ht-link:hover {
  color: var(--text);
}
.ht-widget .ht-transcript {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  overflow: auto;
  font-size: 13.5px;
  line-height: 19px;
}
.ht-widget .ht-transcript p {
  margin: 0;
}
.ht-widget .ht-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
}
.ht-widget .ht-notice svg {
  flex: none;
  margin-top: 1px;
  color: var(--red);
}
.ht-widget[data-mode='avatar'] .ht-details {
  padding: 0 4px;
}
@media (max-width: 420px) {
  .ht-widget .ht-avatar-card {
    padding: 12px;
  }
  .ht-widget .ht-avatar-card .ht-btn {
    padding: 0 14px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .ht-widget .ht-dot.pulse,
  .ht-widget .ht-bars i {
    animation: none;
  }
  .ht-widget .ht-stage {
    transition: none;
  }
}
