@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap");

:root {
  color-scheme: light;
  --bg: #f8edf4;
  --bg-top: #fff4f9;
  --bg-accent: #f2cddd;
  --ink: #1b1b22;
  --muted: #6e6b74;
  --accent: #ff7aa6;
  --accent-dark: #d14579;
  --line: rgba(224, 224, 224, 1);
  --call: #35cf74;
  --hangup: #dd2f58;
  --confirm: #f35f86;
  --message-disabled: #d1c8ce;
  --message-active: #f3d5e3;
  --app-height: 100dvh;
  --app-offset-top: 0px;
  --center-shift-connected: clamp(112px, 22vh, 220px);
  --action-size: clamp(66px, 9.6vh, 78px);
  --action-radius: clamp(18px, 2.8vh, 22px);
}

:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #0f1014;
  --bg-top: #18191f;
  --bg-accent: #2c2029;
  --ink: #f4f2f6;
  --muted: #aaa3af;
  --accent: #ff7aa6;
  --accent-dark: #f35f96;
  --line: rgba(255, 255, 255, 0.13);
  --message-disabled: #4a424c;
  --message-active: #3a2632;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #ffe6f1 0%, transparent 42%),
    radial-gradient(circle at 88% 18%, #f6d7e7 0%, transparent 46%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 55%, #efe6ee 100%);
}

:root[data-theme="night"] body {
  background:
    radial-gradient(circle at 12% 8%, rgba(113, 51, 76, 0.42) 0%, transparent 38%),
    radial-gradient(circle at 88% 18%, rgba(209, 69, 121, 0.18) 0%, transparent 42%),
    linear-gradient(180deg, #18191f 0%, #0f1014 55%, #08090c 100%);
}

.page {
  display: flex;
  justify-content: center;
}

.theme-toggle {
  position: relative;
  flex: 0 0 auto;
  width: 72px;
  height: 36px;
  padding: 0 9px;
  border: 1px solid rgba(209, 177, 194, 0.58);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: #8a6476;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(103, 63, 84, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.theme-toggle__icon {
  position: relative;
  z-index: 2;
  width: 17px;
  height: 17px;
}

.theme-toggle__thumb {
  position: absolute;
  z-index: 1;
  left: 4px;
  top: 4px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(76, 45, 62, 0.22);
  transition: transform 0.22s ease, background 0.22s ease;
}

.theme-toggle[aria-pressed="true"] {
  background: rgba(21, 22, 27, 0.82);
  border-color: rgba(255, 255, 255, 0.16);
  color: #f1d7e3;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

.theme-toggle[aria-pressed="true"] .theme-toggle__thumb {
  transform: translateX(36px);
  background: #f35f96;
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(255, 122, 166, 0.3),
    0 14px 36px rgba(103, 63, 84, 0.18);
}

:root.theme-transitioning,
:root.theme-transitioning *,
:root.theme-transitioning *::before,
:root.theme-transitioning *::after {
  transition:
    background-color 200ms ease,
    background 200ms ease,
    border-color 200ms ease,
    box-shadow 200ms ease,
    opacity 200ms ease !important;
}

@media (prefers-reduced-motion: reduce) {
  :root.theme-transitioning,
  :root.theme-transitioning *,
  :root.theme-transitioning *::before,
  :root.theme-transitioning *::after {
    transition: none !important;
  }
}

.page--splash {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.phonebook {
  width: min(540px, 94vw);
  margin: 24px auto 30px;
  flex: 1;
}

.phonebook__header {
  padding: 8px 10px 14px;
  background: rgba(255, 255, 255, 0.48);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(18px);
  display: grid;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

:root[data-theme="night"] .phonebook__header {
  background: rgba(23, 24, 30, 0.72);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.phonebook__title {
  margin: 0;
  font-size: 1.8rem;
  padding-left: 10px;
}

.phonebook__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  position: relative;
}

.phonebook__title-row .theme-toggle {
  margin-left: auto;
}

:root[data-theme="night"] .phonebook__title,
:root[data-theme="night"] .phonebook__name {
  color: #f4f2f6;
}

.phonebook__header-mark {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-right: 8px;
  flex: 0 0 auto;
  pointer-events: none;
}

.phonebook__header-mark-icon {
  display: block;
  width: auto;
  height: 34px;
}

.phonebook__header-mark-text {
  display: block;
  width: auto;
  height: 18px;
}

.phonebook__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.phonebook__brand-icon-shell {
  display: block;
  width: 76px;
  height: 54px;
  overflow: hidden;
  flex: 0 0 auto;
}

.phonebook__brand-icon {
  display: block;
  height: 100%;
  width: auto;
}

.phonebook__brand-wordmark {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.phonebook__brand-wordmark-image {
  display: block;
  height: 31px;
  width: auto;
}

.phonebook__search {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
}

:root[data-theme="night"] .phonebook__search {
  background: rgba(12, 13, 17, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #f4f2f6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

:root[data-theme="night"] .phonebook__search::placeholder {
  color: rgba(222, 214, 224, 0.56);
}

.phonebook__search:focus {
  outline: 2px solid rgba(255, 122, 166, 0.4);
  outline-offset: 2px;
}

.debug-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding-left: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  user-select: none;
}

.debug-toggle input {
  accent-color: var(--accent);
}

.phonebook__list {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.phonebook__loading {
  color: var(--muted);
  padding: 16px 8px;
}

:root[data-theme="night"] .phonebook__loading {
  color: rgba(222, 214, 224, 0.72);
}

.phonebook__letter {
  display: inline-flex;
  position: relative;
  top: 5px;
  left: 16px;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent);
  font-size: 1.2rem;
  font-weight: 600;
  color: #fff;
}

.phonebook__items {
  display: grid;
  margin-top: 7px;
}

.phonebook__item {
  display: grid;
  gap: 2px;
  margin: 2px 8px 2px 22px;
  padding: 11px 10px 11px 14px;
  text-decoration: none;
  color: var(--ink);
  position: relative;
  border-radius: 15px;
  transition: background 0.15s ease;
}

:root[data-theme="night"] .phonebook__item {
  color: #f4f2f6;
}

.phonebook__item:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 10px;
  bottom: -2px;
  height: 2px;
  background: rgba(0, 0, 0, 0.06);
}

:root[data-theme="night"] .phonebook__item:not(:last-child)::after {
  background: rgba(255, 255, 255, 0.08);
}

.phonebook__item:hover {
  background: rgba(255, 122, 166, 0.08);
}

:root[data-theme="night"] .phonebook__item:hover {
  background: rgba(255, 122, 166, 0.12);
}

.phonebook__name {
  font-size: 1.05rem;
  font-weight: 600;
}

.phonebook__address {
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(27, 27, 34, 0.5);
  line-height: 1.35;
}

:root[data-theme="night"] .phonebook__address {
  color: rgba(220, 214, 224, 0.62);
}

.legal-footer {
  width: min(540px, 94vw);
  margin: -8px auto 22px;
  padding: 0 10px calc(14px + env(safe-area-inset-bottom));
  text-align: center;
  color: rgba(104, 88, 101, 0.82);
}

.legal-footer__notice {
  margin: 0 auto 8px;
  max-width: 520px;
  font-size: 0.76rem;
  line-height: 1.4;
}

.legal-footer__info {
  width: 20px;
  height: 20px;
  margin: 0 0 0 -4px;
  border: 1px solid rgba(209, 69, 121, 0.42);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  color: var(--accent-dark);
  display: inline-grid;
  place-items: center;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(103, 63, 84, 0.1);
}

.legal-footer__info:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(255, 122, 166, 0.25),
    0 10px 26px rgba(103, 63, 84, 0.12);
}

.legal-footer__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  font-size: 0.76rem;
  line-height: 1.25;
}

.legal-footer__links a,
.legal-page a,
.legal-page__back {
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
}

.legal-footer__links a:hover,
.legal-page a:hover,
.legal-page__back:hover {
  text-decoration: underline;
}

:root[data-theme="night"] .legal-footer {
  color: rgba(222, 216, 226, 0.66);
}

:root[data-theme="night"] .legal-footer__info {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 140, 180, 0.42);
  color: #ff8cb4;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.26);
}

:root[data-theme="night"] .legal-footer__links a,
:root[data-theme="night"] .legal-page a,
:root[data-theme="night"] .legal-page__back {
  color: #ff8cb4;
}

.legal-footer--client {
  width: 100%;
  margin: 0;
  padding: 0 8px calc(2px + env(safe-area-inset-bottom));
  align-self: end;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.18s ease, visibility 0.18s ease, transform 0.18s ease;
}

.legal-footer--client .legal-footer__notice {
  margin-bottom: 5px;
  font-size: clamp(0.65rem, 1.8vh, 0.72rem);
}

.legal-footer--client .legal-footer__info {
  width: 18px;
  height: 18px;
  margin-left: -3px;
  font-size: 0.62rem;
}

.legal-footer--client .legal-footer__links {
  font-size: clamp(0.65rem, 1.8vh, 0.72rem);
  gap: 4px 10px;
}

.disclosure-popover {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 120;
  width: min(360px, calc(100vw - 28px));
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.disclosure-popover.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.disclosure-popover__card {
  position: relative;
  padding: 16px 42px 16px 16px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 22px 70px rgba(108, 66, 88, 0.22);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: rgba(27, 27, 34, 0.82);
}

:root[data-theme="night"] .disclosure-popover__card {
  background: rgba(23, 24, 30, 0.94);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
  color: rgba(244, 242, 246, 0.82);
}

.disclosure-popover__card p {
  margin: 0 0 10px;
  font-size: 0.86rem;
  line-height: 1.45;
}

.disclosure-popover__card a {
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
}

.disclosure-popover__card a:hover {
  text-decoration: underline;
}

:root[data-theme="night"] .disclosure-popover__card a {
  color: #ff8cb4;
}

.disclosure-popover__close {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: rgba(209, 69, 121, 0.1);
  color: var(--accent-dark);
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

:root[data-theme="night"] .disclosure-popover__close {
  background: rgba(255, 255, 255, 0.08);
  color: #ff8cb4;
}

.page--client {
  min-height: 100svh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
}

.call-screen {
  width: min(560px, 94vw);
  min-height: var(--app-height, 100dvh);
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100dvh);
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto auto auto auto;
  gap: clamp(10px, 2vh, 20px);
  position: fixed;
  top: var(--app-offset-top, 0px);
  left: 0;
  right: 0;
  margin: 0 auto;
  overflow: hidden;
}

.call-screen__header {
  position: relative;
  z-index: 70;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  padding-right: 84px;
}

.call-screen__theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
}

.call-screen__back,
.call-screen__debug-link {
  text-decoration: none;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 17px;
}

:root[data-theme="night"] .call-screen__back,
:root[data-theme="night"] .call-screen__debug-link {
  color: #ff8cb4;
}

.call-screen__debug-link {
  display: none;
}

.call-screen__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.call-screen__chat-client {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  max-width: min(76vw, 420px);
}

.call-screen__chat-client-name {
  margin: 0;
  font-size: clamp(1rem, 2.6vw, 1.12rem);
  font-weight: 600;
  line-height: 1.12;
  color: var(--ink);
}

.call-screen__chat-client-address {
  margin: 0;
  font-size: clamp(0.888rem, 2.28vw, 1.008rem);
  font-weight: 500;
  line-height: 1.28;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.call-screen__back-icon {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
}

.call-screen__center {
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  min-height: 0;
  transform: translateY(0);
  transition: transform 0.38s cubic-bezier(0.2, 0.75, 0.2, 1), padding-top 0.3s ease;
  will-change: transform;
}

.call-screen--connected .call-screen__center {
  place-content: start center;
  padding-top: 0;
  transform: translateY(0);
}

.call-screen--chat-open .call-screen__center {
  display: none;
}

.call-screen--chat-open .call-screen__header {
  justify-content: flex-start;
  align-items: flex-start;
}

.call-screen--chat-open .call-screen__back {
  display: none;
}

.call-screen--chat-open .call-screen__chat-client {
  display: flex;
  padding-right: 86px;
}

.call-screen--chat-open .call-screen__actions,
.call-screen--chat-open .call-screen__status {
  display: none;
}

.call-screen--connected .legal-footer--client,
.call-screen--chat-open .legal-footer--client {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px);
}

.call-screen--connected + .disclosure-popover,
.call-screen--chat-open + .disclosure-popover {
  display: none;
}

.call-screen__name {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 600;
}

:root[data-theme="night"] .call-screen__name,
:root[data-theme="night"] .call-screen__chat-client-name {
  color: #f6f4f7;
}

.call-screen--connected .call-screen__name {
  font-size: clamp(1.1rem, 3vw, 1.35rem);
}

.call-screen--chat-open .call-screen__name {
  font-size: clamp(1.06rem, 2.8vw, 1.2rem);
  font-weight: 600;
}

.call-screen__address {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.9922rem, 2.6015vw, 1.1132rem);
  font-weight: 500;
  line-height: 1.32;
  max-width: min(420px, 90vw);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

:root[data-theme="night"] .call-screen__address,
:root[data-theme="night"] .call-screen__chat-client-address,
:root[data-theme="night"] .call-screen__status {
  color: rgba(222, 216, 226, 0.7);
}

.orb-indicator {
  position: fixed;
  left: 50%;
  top: 50%;
  width: clamp(220px, 43vmin, 370px);
  aspect-ratio: 1 / 1;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-50% + 22px)) scale(0.92);
  transition: opacity 0.34s ease, transform 0.45s cubic-bezier(0.16, 0.84, 0.2, 1);
  display: grid;
  place-items: center;
}

.call-screen--connected .orb-indicator {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.orb-indicator__core {
  position: relative;
  width: 72%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: none;
  background: transparent;
  background-image: none;
  box-shadow: none;
  transform: scale(0.97);
}

.call-visualizer__mount {
  position: absolute;
  inset: -10%;
  z-index: 2;
  pointer-events: none;
  border-radius: 50%;
  overflow: hidden;
  background: transparent;
  box-shadow: none;
}

@keyframes orb-breathe {
  0% {
    transform: scale(0.97);
  }
  50% {
    transform: scale(1.03);
  }
  100% {
    transform: scale(0.97);
  }
}

.call-screen--connected .orb-indicator__core {
  animation: orb-breathe 7.8s ease-in-out infinite;
}

.orb-indicator--webgl .orb-indicator__core {
  animation: none;
}

.call-screen__actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 28px;
}

.action-slot {
  position: relative;
  width: var(--action-size);
  height: var(--action-size);
}

.action {
  border: none;
  width: var(--action-size);
  height: var(--action-size);
  border-radius: var(--action-radius);
  display: grid;
  place-items: center;
  gap: 4px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.action-slot .action {
  position: absolute;
  inset: 0;
}

.action svg {
  width: clamp(24px, 3.2vh, 28px);
  height: clamp(24px, 3.2vh, 28px);
}

.action:active {
  transform: scale(0.97);
}

.action--call {
  background: var(--call);
  box-shadow: 0 16px 30px rgba(53, 207, 116, 0.35);
}

.action--hangup {
  background: var(--hangup);
  box-shadow: 0 16px 30px rgba(221, 47, 88, 0.3);
}

.action--message {
  background: var(--accent-dark);
  color: #fff;
  box-shadow: 0 16px 30px rgba(209, 69, 121, 0.34);
  cursor: pointer;
}

.action--message:disabled {
  background: var(--message-disabled);
  color: rgba(255, 255, 255, 0.9);
  box-shadow: none;
  cursor: not-allowed;
}

.action--call[disabled] {
  opacity: 0.55;
  cursor: default;
}

.action--hidden {
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}

.call-screen__status {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal-open .call-screen {
  filter: blur(8px);
  transform: scale(0.995);
  transition: filter 0.2s ease, transform 0.2s ease;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(20, 14, 19, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(420px, 92vw);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 20px 55px rgba(30, 15, 27, 0.28);
  padding: 20px 20px 16px;
  transform: translateY(10px) scale(0.97);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

:root[data-theme="night"] .modal-card {
  background: rgba(24, 25, 31, 0.96);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

.modal-backdrop.is-visible .modal-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-card__title {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--ink);
}

.modal-card__text {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

:root[data-theme="night"] .modal-card__title {
  color: #f6f4f7;
}

.modal-card__actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  border: none;
  border-radius: 12px;
  min-width: 96px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.modal-btn:active {
  transform: scale(0.98);
}

.modal-btn--ghost {
  background: rgba(241, 232, 238, 0.9);
  color: #4a4550;
}

:root[data-theme="night"] .modal-btn--ghost {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(246, 244, 247, 0.88);
}

.modal-btn--danger {
  background: linear-gradient(180deg, var(--confirm) 0%, #dd2f58 100%);
  color: #fff;
  box-shadow: 0 12px 24px rgba(221, 47, 88, 0.32);
}

.chat-panel {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 73px);
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: min(560px, calc(100vw - 14px));
  transform: translate(-50%, 14px) scale(0.995);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.66);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 22px 60px rgba(24, 16, 24, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overscroll-behavior: contain;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

:root[data-theme="night"] .chat-panel {
  background: rgba(18, 19, 24, 0.94);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

.chat-panel.is-open {
  transform: translate(-50%, 0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.chat-panel__header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(230, 220, 227, 0.92);
}

:root[data-theme="night"] .chat-panel__header,
:root[data-theme="night"] .chat-panel__composer {
  border-color: rgba(255, 255, 255, 0.1);
}

.chat-panel__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-width: 0;
  pointer-events: none;
}

.chat-panel__brand-icon-shell {
  display: block;
  width: 50px;
  height: 36px;
  overflow: hidden;
  flex: 0 0 auto;
}

.chat-panel__brand-icon {
  display: block;
  height: 100%;
  width: auto;
}

.chat-panel__brand-wordmark {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  pointer-events: none;
}

.chat-panel__brand-wordmark-image {
  display: block;
  height: 22px;
  width: auto;
}

.chat-panel__state {
  margin: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8a7884;
  white-space: nowrap;
  pointer-events: none;
}

:root[data-theme="night"] .chat-panel__state {
  color: rgba(222, 216, 226, 0.68);
}

.chat-panel__state[data-state="connecting"] {
  color: #8d6b34;
}

.chat-panel__state[data-state="connected"] {
  color: #258051;
}

.chat-panel__state[data-state="error"] {
  color: #bf4063;
}

.chat-panel__close {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: rgba(243, 95, 134, 0.16);
  color: var(--accent-dark);
  display: grid;
  place-items: center;
  cursor: pointer;
}

:root[data-theme="night"] .chat-panel__close {
  background: rgba(255, 122, 166, 0.14);
  color: #ff8cb4;
}

.chat-panel__close svg {
  width: 20px;
  height: 20px;
}

.chat-panel__log {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chat-entry {
  max-width: 86%;
  height: fit-content;
  align-self: start;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.93rem;
  font-weight: 600;
  line-height: 1.34;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-entry--assistant {
  justify-self: start;
  background: rgba(255, 235, 244, 0.98);
  color: #2d2530;
}

:root[data-theme="night"] .chat-entry--assistant {
  background: rgba(255, 255, 255, 0.08);
  color: #f4f2f6;
}

.chat-entry--user {
  justify-self: end;
  background: rgba(243, 95, 134, 0.95);
  color: #fff;
}

.chat-entry--system {
  justify-self: center;
  max-width: 96%;
  background: transparent;
  color: #6c6470;
  font-size: 0.82rem;
  text-align: center;
  padding: 2px 0;
}

:root[data-theme="night"] .chat-entry--system {
  color: rgba(222, 216, 226, 0.66);
}

.chat-panel__composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(230, 220, 227, 0.92);
}

.chat-panel__input {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid #f1eff3;
  background: #f1eff3;
  padding: 0 12px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.2;
  color: #2f2a31;
}

:root[data-theme="night"] .chat-panel__input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #f6f4f7;
}

.chat-panel__input::placeholder {
  color: #5f5963;
  opacity: 1;
}

:root[data-theme="night"] .chat-panel__input::placeholder {
  color: rgba(222, 216, 226, 0.52);
}

.chat-panel__input:focus {
  outline: none;
  border-color: #f1eff3;
  box-shadow: 0 0 0 3px rgba(95, 89, 99, 0.18);
}

:root[data-theme="night"] .chat-panel__input:focus {
  border-color: rgba(255, 122, 166, 0.32);
  box-shadow: 0 0 0 3px rgba(255, 122, 166, 0.16);
}

.chat-panel__send {
  min-width: 78px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--confirm) 0%, #dd2f58 100%);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.chat-panel__input:disabled,
.chat-panel__send:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

#remoteAudio {
  display: none;
}

.page--legal {
  min-height: 100vh;
  padding: 28px 16px calc(34px + env(safe-area-inset-bottom));
  align-items: flex-start;
}

.legal-page {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 42px);
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.66);
  box-shadow: 0 24px 70px rgba(108, 66, 88, 0.13);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

:root[data-theme="night"] .legal-page {
  background: rgba(23, 24, 30, 0.78);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.legal-page__back {
  display: inline-flex;
  margin-bottom: 22px;
  font-size: 0.95rem;
}

.legal-page h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.legal-page__updated {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.legal-page h2 {
  margin: 28px 0 8px;
  font-size: 1.08rem;
  letter-spacing: -0.015em;
}

.legal-page p {
  margin: 0 0 14px;
  color: rgba(27, 27, 34, 0.78);
  font-size: 1rem;
  line-height: 1.62;
}

:root[data-theme="night"] .legal-page p {
  color: rgba(244, 242, 246, 0.78);
}

:root[data-theme="night"] .legal-page__updated {
  color: rgba(222, 216, 226, 0.62);
}

.debug-ghost {
  position: fixed;
  top: calc(84px + env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  left: auto;
  bottom: auto;
  z-index: 72;
  width: min(380px, 34vw);
  max-width: calc(100vw - 24px);
  display: block;
}

.debug-ghost__hidden-controls {
  display: none;
}

.debug-panel {
  min-width: 0;
}

.debug-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.debug-panel__head h2 {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4b4550;
}

.debug-panel__actions {
  display: inline-flex;
  gap: 6px;
}

.debug-panel__head button {
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #2f2a31;
  background: rgba(241, 236, 243, 0.92);
  cursor: pointer;
}

.debug-panel__head button:hover {
  background: rgba(233, 225, 236, 0.98);
}

.debug-panel__log {
  margin: 8px 0 0;
  border: 1px solid rgba(219, 210, 222, 0.95);
  border-radius: 10px;
  min-height: 260px;
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
  background: rgba(251, 249, 252, 0.96);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
  color: #2f2a31;
}

.debug-panel #log .entry {
  margin-bottom: 10px;
  line-height: 1.4;
}

.debug-panel #log .role {
  display: inline-block;
  margin-right: 8px;
  font-weight: 700;
}

.debug-panel #log .role-user {
  color: #144e9e;
}

.debug-panel #log .role-assistant {
  color: #0f7b46;
}

.debug-panel #log .role-system {
  color: #875d08;
}

@media (max-width: 640px) {
  .phonebook {
    width: min(94vw, 520px);
  }

  .legal-footer {
    width: min(94vw, 520px);
    margin-top: -4px;
  }

  .legal-footer__notice {
    font-size: 0.7rem;
  }

  .legal-footer__links {
    font-size: 0.7rem;
    gap: 5px 9px;
  }

  .phonebook__title {
    font-size: 1.5rem;
  }

  .phonebook__title-row {
    min-height: 47px;
  }

  .phonebook__brand {
    gap: 10px;
  }

  .phonebook__brand-icon-shell {
    width: 62px;
    height: 45px;
  }

  .phonebook__brand-wordmark {
    display: inline-flex;
  }

  .phonebook__brand-wordmark-image {
    height: 26px;
  }

  .phonebook__header-mark-icon {
    height: 28px;
  }

  .call-screen {
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    gap: 10px;
  }

  .call-screen__header {
    padding-right: calc(76px + env(safe-area-inset-right));
  }

  .call-screen__theme-toggle {
    right: max(14px, calc(env(safe-area-inset-right) + 6px));
    width: 64px;
    height: 32px;
    padding: 0 8px;
  }

  .call-screen__theme-toggle .theme-toggle__icon {
    width: 15px;
    height: 15px;
  }

  .call-screen__theme-toggle .theme-toggle__thumb {
    width: 24px;
    height: 24px;
  }

  .call-screen__theme-toggle[aria-pressed="true"] .theme-toggle__thumb {
    transform: translateX(32px);
  }

  .call-screen__name {
    font-size: clamp(1.4rem, 7vw, 2rem);
  }

  .call-screen__address {
    font-size: 1.1132rem;
  }

  .call-screen--chat-open .call-screen__chat-client-name {
    font-size: clamp(1.15rem, 2.99vw, 1.288rem);
  }

  .call-screen--chat-open .call-screen__chat-client {
    max-width: 100%;
    padding-right: 0;
  }

  .call-screen--chat-open .call-screen__chat-client-address {
    display: -webkit-box;
    font-size: clamp(0.88rem, 3.7vw, 0.94rem);
    line-height: 1.2;
    overflow: hidden;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    white-space: normal;
  }

  .chat-panel {
    width: 100vw;
    max-width: 100vw;
    top: var(--chat-panel-mobile-top, calc(var(--app-offset-top, 0px) + env(safe-area-inset-top) + 65px));
    bottom: auto;
    height: calc(var(--app-height, 100dvh) + var(--app-offset-top, 0px) - var(--chat-panel-mobile-top, calc(var(--app-offset-top, 0px) + env(safe-area-inset-top) + 65px)));
    max-height: calc(var(--app-height, 100dvh) + var(--app-offset-top, 0px) - var(--chat-panel-mobile-top, calc(var(--app-offset-top, 0px) + env(safe-area-inset-top) + 65px)));
    border-radius: 0;
  }

  .chat-panel__brand {
    gap: 9px;
  }

  .chat-panel__brand-icon-shell {
    width: 44px;
    height: 31px;
  }

  .chat-panel__brand-wordmark {
    display: inline-flex;
  }

  .chat-panel__brand-wordmark-image {
    height: 19px;
  }

  .debug-ghost {
    display: none;
  }
}

@media (max-height: 760px) {
  .call-screen {
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .call-screen__header {
    font-size: 0.88rem;
  }

  .call-screen__status {
    font-size: 0.78rem;
  }
}
