:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", sans-serif;
  --paper: #f5f5f3;
  --white: #fff;
  --ink: #191a1c;
  --secondary: #62666b;
  --quiet: #92969b;
  --line: #e5e5e2;
  --green: #426a51;
  --red: #8d514b;
  --shadow: 0 18px 50px rgb(22 24 27 / 8%), 0 2px 9px rgb(22 24 27 / 4%);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  background: #e8e8e5;
  color: var(--ink);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

.app-shell {
  position: relative;
  width: min(100vw, 390px);
  height: min(var(--tg-viewport-stable-height, 100dvh), 844px);
  min-height: min(var(--tg-viewport-stable-height, 100dvh), 620px);
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 34px 95px rgb(20 22 24 / 16%);
}

.main-screen,
.history-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

.app-header,
.history-header {
  position: relative;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 10px;
  background: linear-gradient(to bottom, var(--paper) 75%, rgb(245 245 243 / 92%));
}

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

.brand {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.055em;
  line-height: 1;
}

.status-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--quiet);
  font-size: 11px;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: #78947d;
}

.status-dot[data-state="requesting"],
.status-dot[data-state="connecting"] {
  background: #a39a79;
  animation: soft-pulse 1.6s ease-in-out infinite;
}

.status-dot[data-state="speaking"] {
  background: #3d4447;
  animation: soft-pulse 1.2s ease-in-out infinite;
}

.status-dot[data-state="problem"] {
  background: var(--red);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: #51555a;
}

.icon-button:hover {
  background: #eaeae7;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.conversation-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: 28px 21px 22px;
}

.conversation-panel::-webkit-scrollbar,
.history-body::-webkit-scrollbar {
  display: none;
}

.welcome {
  padding-top: clamp(35px, 10vh, 91px);
}

.welcome h1 {
  max-width: 330px;
  margin: 0;
  font-size: 35px;
  line-height: 1.12;
  font-weight: 560;
  letter-spacing: -0.06em;
}

.welcome h1 span {
  display: block;
  color: #85898d;
}

.welcome-rule {
  width: 29px;
  height: 1px;
  margin-top: 29px;
  background: #c9cbc8;
}

.transcript-list {
  padding-top: 9px;
}

.transcript-entry,
.detail-message {
  margin: 0 0 30px;
  animation: arrive 0.28s ease both;
}

.transcript-speaker {
  display: block;
  margin-bottom: 8px;
  color: var(--quiet);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.transcript-text {
  max-width: 335px;
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 480;
  line-height: 1.34;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.transcript-entry[data-role="user"] .transcript-text,
.detail-message[data-role="user"] .transcript-text {
  max-width: 325px;
  color: #65696f;
  font-size: 15px;
  line-height: 1.49;
  letter-spacing: 0;
}

.transcript-entry[data-partial="true"] .transcript-text {
  color: #777b80;
}

.transcript-entry[data-interrupted="true"] .transcript-text::after,
.detail-message[data-interrupted="true"] .transcript-text::after {
  content: " · перебито";
  color: var(--quiet);
  font-size: 11px;
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0;
}

.transcript-empty,
.transcript-warning {
  margin: 10px 0 0;
  color: var(--quiet);
  font-size: 12px;
  line-height: 1.5;
}

.transcript-warning {
  margin-top: 14px;
  color: var(--red);
}

.task-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 29px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fbfbfa;
}

.task-pulse {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: #879889;
  box-shadow: 0 0 0 4px rgb(116 143 121 / 10%);
  animation: soft-pulse 1.6s ease-in-out infinite;
}

.task-title {
  font-size: 12px;
  font-weight: 610;
}

.task-state {
  margin-left: auto;
  color: var(--secondary);
  font-size: 11px;
}

.weather-attribution {
  display: flex;
  flex-wrap: wrap;
  gap: 0 12px;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
}

.weather-attribution a {
  color: inherit;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  text-underline-offset: 3px;
}

.result-card {
  margin: 0 0 29px;
  padding: 18px 17px;
  border: 1px solid #e6e7e3;
  border-radius: 19px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.result-card .transcript-speaker {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}

.result-card .transcript-speaker::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.result-card .transcript-text {
  max-width: none;
  font-size: 14px;
  line-height: 1.58;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.result-card[data-partial="true"] .transcript-text {
  color: var(--ink);
}

.task-error {
  margin: 0 0 27px;
  padding: 16px 17px;
  border: 1px solid #ebd9d6;
  border-radius: 17px;
  background: #fffafa;
  color: #744842;
  font-size: 13px;
  line-height: 1.5;
}

.error {
  margin: 0 0 22px;
  padding: 14px 16px;
  border: 1px solid #ebd9d6;
  border-radius: 17px;
  background: #fffafa;
  color: #744842;
  font-size: 13px;
  line-height: 1.5;
}

.voice-dock {
  position: relative;
  z-index: 2;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  background: linear-gradient(to top, var(--paper) 82%, rgb(245 245 243 / 97%) 91%, rgb(245 245 243 / 0%));
}

.end-button {
  position: absolute;
  top: 20px;
  right: 20px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--secondary);
  font-size: 11px;
}

.end-button:hover {
  background: #e9e9e6;
}

.end-button:disabled {
  opacity: 0.5;
}

.voice-orb-wrap {
  position: relative;
  display: grid;
  width: 78px;
  height: 78px;
  place-items: center;
}

.voice-orb-ring {
  position: absolute;
  inset: 0;
  border: 1px solid rgb(47 50 51 / 15%);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.voice-orb {
  position: relative;
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 26%, #5c5f62, #25272a 60%, #191b1e);
  box-shadow: 0 11px 27px rgb(28 30 33 / 18%), inset 0 1px 1px rgb(255 255 255 / 20%);
  color: #fff;
  transition: transform 0.23s, background 0.23s, box-shadow 0.23s;
}

.voice-orb:active:not(:disabled) {
  transform: scale(0.94);
}

.voice-orb:disabled {
  cursor: default;
}

.voice-orb svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.voice-wave {
  display: none;
  align-items: center;
  gap: 3px;
  height: 24px;
}

.voice-wave i {
  display: block;
  width: 2px;
  height: 5px;
  border-radius: 3px;
  background: #fff;
  animation: wave 0.7s ease-in-out infinite alternate;
}

.voice-wave i:nth-child(2),
.voice-wave i:nth-child(6) {
  animation-delay: 0.2s;
}

.voice-wave i:nth-child(3),
.voice-wave i:nth-child(5) {
  animation-delay: 0.34s;
}

.voice-wave i:nth-child(4) {
  animation-delay: 0.12s;
}

.voice-dock[data-state="listening"] .voice-wave {
  display: flex;
}

.voice-dock[data-state="listening"] .voice-orb svg {
  display: none;
}

.voice-dock[data-state="listening"] .voice-orb-ring {
  opacity: 1;
  animation: ring 1.5s ease-out infinite;
}

.voice-dock[data-state="connecting"] .voice-orb,
.voice-dock[data-state="requesting"] .voice-orb,
.voice-dock[data-state="reconnecting"] .voice-orb {
  background: #d7d8d5;
  box-shadow: none;
  color: #51555a;
}

.voice-dock[data-state="connecting"] .voice-orb-ring,
.voice-dock[data-state="requesting"] .voice-orb-ring,
.voice-dock[data-state="reconnecting"] .voice-orb-ring {
  opacity: 0.8;
  animation: soft-pulse 1.7s ease-in-out infinite;
}

.voice-dock[data-state="speaking"] .voice-orb-ring {
  opacity: 0.7;
  animation: speak 1.2s ease-in-out infinite;
}

.voice-dock[data-state="problem"] .voice-orb-ring {
  opacity: 0.8;
  border-color: var(--red);
}

.voice-state {
  min-height: 17px;
  margin-top: 7px;
  color: #575b60;
  font-size: 12px;
  font-weight: 620;
}

.voice-hint {
  min-height: 15px;
  margin: 3px 0 0;
  color: var(--quiet);
  font-size: 11px;
}

.timer {
  position: absolute;
  top: 28px;
  left: 20px;
  color: var(--quiet);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.audio-button {
  min-height: 40px;
  margin-top: 14px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--white);
  color: var(--secondary);
  font-size: 12px;
}

.history-screen {
  z-index: 10;
}

.history-header {
  justify-content: flex-start;
  gap: 8px;
}

.history-header h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.045em;
}

.history-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 12px 21px calc(env(safe-area-inset-bottom, 0px) + 30px);
}

.history-day,
.section-label {
  color: var(--quiet);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.history-day {
  margin: 24px 0 6px;
}

.history-item {
  display: flex;
  width: 100%;
  min-height: 73px;
  align-items: flex-start;
  gap: 14px;
  padding: 15px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.history-item-main {
  flex: 1;
  min-width: 0;
}

.history-name {
  display: block;
  font-size: 15px;
  font-weight: 550;
  line-height: 1.34;
}

.history-meta,
.history-time {
  color: var(--quiet);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.history-meta {
  display: block;
  margin-top: 6px;
}

.history-time {
  white-space: nowrap;
}

.detail-title {
  margin: 29px 0 10px;
  font-size: 28px;
  font-weight: 590;
  line-height: 1.18;
  letter-spacing: -0.055em;
}

.detail-meta {
  display: flex;
  gap: 12px;
  color: var(--quiet);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.summary-divider {
  height: 1px;
  margin: 29px 0 24px;
  background: var(--line);
}

.summary-text {
  margin: 9px 0 0;
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: -0.025em;
  white-space: pre-wrap;
}

.summary-sub {
  margin: 15px 0 0;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.55;
}

.history-transcript {
  margin-top: 30px;
}

.history-transcript .transcript-entry {
  margin-top: 20px;
  margin-bottom: 22px;
}

.history-transcript .transcript-text {
  font-size: 17px;
}

.history-transcript .transcript-entry[data-role="user"] .transcript-text {
  font-size: 15px;
}

.quiet-button {
  min-height: 44px;
  margin-top: 16px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  font-size: 12px;
  font-weight: 600;
}

.history-message {
  margin: 28px 0;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.5;
}

/* The existing direct link to a conversation keeps using conversation.html. */
.shell.detail-shell {
  width: min(100vw, 390px);
  min-height: min(var(--tg-viewport-stable-height, 100dvh), 844px);
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 21px calc(env(safe-area-inset-bottom, 0px) + 30px);
  background: var(--paper);
  box-shadow: 0 34px 95px rgb(20 22 24 / 16%);
}

.detail-card {
  margin: 0;
  padding: 0;
  background: transparent;
}

.detail-card h1 {
  margin: 0 0 10px;
  font-size: 28px;
  font-weight: 590;
  letter-spacing: -0.055em;
}

.detail-card h2 {
  margin: 0 0 12px;
  color: var(--quiet);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.025em;
}

.detail-card .detail-meta {
  margin: 0;
}

.detail-summary {
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.detail-summary p {
  margin: 0;
  font-size: 17px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.detail-messages {
  margin-top: 20px;
}

.detail-message .transcript-text {
  font-size: 17px;
}

.detail-card section[aria-label="Текст разговора"] {
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes soft-pulse {
  50% { opacity: 0.45; transform: scale(0.83); }
}

@keyframes wave {
  to { height: 20px; }
}

@keyframes ring {
  from { transform: scale(0.82); opacity: 0.65; }
  to { transform: scale(1.16); opacity: 0; }
}

@keyframes speak {
  50% { transform: scale(1.05); opacity: 0.22; }
}

@media (max-width: 430px) {
  body { background: var(--paper); }
  .app-shell {
    width: 100vw;
    height: var(--tg-viewport-stable-height, 100dvh);
    box-shadow: none;
  }
  .shell.detail-shell {
    width: 100vw;
    min-height: var(--tg-viewport-stable-height, 100dvh);
    box-shadow: none;
  }
}

@media (max-height: 690px) {
  .welcome { padding-top: 25px; }
  .conversation-panel { padding-top: 14px; }
  .voice-dock { padding-top: 8px; }
}

@media (max-width: 360px) {
  .end-button { top: -12px; right: 10px; }
  .timer { top: 19px; left: 12px; }
}

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

/* Current Registry results are shared between the voice screen and history. */
.tasks-link { display: flex; justify-content: space-between; width: 100%; padding: 11px 0; margin: -14px 0 24px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--secondary); font-size: 13px; text-align: left; }
.results-heading { margin: 0 0 14px; color: var(--secondary); font-size: 13px; font-weight: 500; }
.task-result-card { padding: 15px 16px; margin: 0 0 12px; background: var(--white); border: 1px solid var(--line); border-radius: 16px; overflow-wrap: anywhere; }
.task-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; }
.task-card-type { color: var(--secondary); }
.task-card-status { color: var(--green); }
.task-result-card[data-status="error"] .task-card-status { color: var(--red); }
.task-result-card[data-status="clarification"] .task-card-status { color: #786338; }
.task-result-card[data-status="running"] .task-card-status { color: var(--secondary); }
.task-card-subject { margin: 9px 0 0; font-size: 15px; font-weight: 600; line-height: 1.4; }
.task-card-fact { font-size: 18px; line-height: 1.45; margin: 10px 0; letter-spacing: -.025em; white-space: pre-wrap; }
.task-card-message { font-size: 14px; line-height: 1.5; margin: 9px 0; color: var(--secondary); }
.task-card-asof, .task-card-sources, .task-card-details { font-size: 11px; line-height: 1.55; color: var(--secondary); margin: 8px 0 0; }
.task-card-sources a { color: #426a51; text-underline-offset: 2px; }
.task-card-details summary { cursor: pointer; color: var(--quiet); }
.task-card-details p { margin: 5px 0; }
.task-history-group { margin-bottom: 26px; }
.detail-results { margin-top: 18px; }
.history-transcript > summary { margin: 24px 0 16px; cursor: pointer; }
