/* Sovetnik UI refinement layer.
   Kept separate from legacy styles so the visual system stays easy to maintain. */

:root {
  --composer-inset: 154px;
  --ui-navy: #12375f;
  --ui-blue: #246aa6;
  --ui-blue-soft: #eaf2fa;
  --ui-gold: #b58a3c;
  --ui-paper: rgba(255, 255, 255, 0.94);
  --ui-line: rgba(107, 137, 171, 0.22);
  --ui-muted: #687a90;
  --ui-focus: 0 0 0 3px rgba(37, 112, 176, 0.2);
  --ui-shadow-sm: 0 10px 26px rgba(21, 55, 93, 0.08);
  --ui-shadow-md: 0 20px 52px rgba(21, 55, 93, 0.12);
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--ui-focus);
}

button:disabled {
  cursor: not-allowed;
  filter: saturate(0.72);
}

::selection {
  background: rgba(49, 119, 181, 0.2);
  color: #102f53;
}

/* Navigation */
.sidebar {
  border-right-color: rgba(100, 130, 166, 0.16);
  box-shadow: 15px 0 50px rgba(26, 55, 89, 0.035);
}

.account-card {
  min-height: 64px;
  border-color: var(--ui-line);
  background:
    radial-gradient(circle at 100% 0, rgba(73, 137, 197, 0.1), transparent 38%),
    rgba(255, 255, 255, 0.78);
  box-shadow: 0 9px 25px rgba(24, 56, 93, 0.055);
}

.settings-btn,
.new-chat,
.quick-new-chat-btn,
.voice-call-btn--topbar {
  display: inline-grid;
  place-items: center;
}

.sidebar-title {
  letter-spacing: -0.02em;
}

.search-chat {
  min-height: 42px;
  border-color: rgba(103, 136, 171, 0.2);
  background-color: rgba(255, 255, 255, 0.77);
}

.history {
  padding: 1px 2px 10px;
}

.history-item {
  position: relative;
  min-height: 47px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.history-item::before {
  content: "";
  position: absolute;
  top: 11px;
  bottom: 11px;
  left: 0;
  width: 3px;
  border-radius: 0 5px 5px 0;
  background: transparent;
}

.history-item:hover {
  border-color: rgba(99, 133, 170, 0.13);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 22px rgba(24, 57, 95, 0.05);
}

.history-item--active {
  border-color: rgba(69, 121, 177, 0.18);
  background: linear-gradient(145deg, #ffffff, #eef5fc);
  box-shadow: 0 10px 25px rgba(25, 65, 108, 0.08);
}

.history-item--active::before {
  background: linear-gradient(180deg, #2d79b9, #174a86);
}

.topbar {
  border-bottom-color: rgba(111, 141, 173, 0.13);
  background:
    linear-gradient(180deg, rgba(252, 254, 255, 0.94), rgba(248, 251, 253, 0.86));
}

.topbar-row {
  min-height: 47px;
}

.topbar-title h1 {
  letter-spacing: -0.035em;
}

.topbar-actions {
  align-items: center;
}

.topbar-actions .voice-call-btn,
.quick-new-chat-btn,
.menu-btn {
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  border-radius: 13px;
}

.menu-btn {
  gap: 7px;
  border-color: rgba(106, 140, 176, 0.22);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 21px rgba(25, 61, 100, 0.06);
}

/* New conversation */
.chat-feed:has(.chat-intro:not(.hidden)) {
  overflow-y: auto;
}

.chat-intro {
  min-height: 0;
  align-content: start;
  gap: 14px;
  padding: clamp(28px, 6.5vh, 68px) 0 22px;
}

.start-card {
  overflow: hidden;
  border-color: rgba(101, 136, 173, 0.18);
  border-radius: 25px;
  padding: clamp(27px, 3.1vw, 38px);
  box-shadow:
    0 24px 58px rgba(26, 58, 96, 0.105),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.start-card h2 {
  max-width: 740px;
  font-size: clamp(35px, 4.6vw, 48px);
  line-height: 1.02;
}

.start-subtitle {
  max-width: 650px;
  margin-top: 14px;
  line-height: 1.58;
}

.suggest-grid {
  gap: 10px;
}

.suggest {
  min-height: 58px;
  border-color: rgba(104, 137, 173, 0.18);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 9px 25px rgba(26, 58, 96, 0.045);
}

.suggest:hover {
  transform: translateY(-2px);
}

/* Messages and context actions */
.message {
  border-color: rgba(111, 142, 175, 0.17);
}

.message--assistant {
  box-shadow: 0 11px 29px rgba(23, 56, 92, 0.055);
}

.message-actions {
  gap: 5px;
}

.message-action-btn {
  min-height: 31px;
  border-radius: 9px;
}

.followup-row {
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.followup-chip {
  scroll-snap-align: start;
  border-color: rgba(91, 127, 165, 0.19);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 7px 20px rgba(22, 57, 95, 0.05);
}

.message-sources {
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}

.source-pill {
  scroll-snap-align: start;
}

/* Composer */
.composer-wrap {
  border-top-color: rgba(100, 133, 169, 0.15);
  background: linear-gradient(180deg, rgba(248, 251, 253, 0.79), rgba(246, 249, 252, 0.98));
}

.composer {
  border-color: rgba(97, 133, 171, 0.29);
  box-shadow:
    0 15px 40px rgba(21, 55, 93, 0.105),
    inset 0 1px 0 rgba(255, 255, 255, 0.94);
}

.composer:focus-within {
  border-color: rgba(46, 112, 174, 0.5);
  box-shadow:
    0 17px 46px rgba(21, 65, 111, 0.14),
    0 0 0 3px rgba(40, 110, 174, 0.075),
    inset 0 1px 0 rgba(255, 255, 255, 0.96);
}

.composer textarea:focus-visible {
  box-shadow: none;
}

.model-switch,
.topic-select {
  border-color: rgba(101, 135, 172, 0.2);
}

.model-btn,
.topic-select,
.send-btn,
.voice-btn,
.attach-btn {
  min-height: 40px;
}

.send-btn {
  border-radius: 12px;
  box-shadow: 0 10px 23px rgba(25, 77, 132, 0.17);
}

.voice-btn,
.attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
}

.voice-btn-icon {
  display: block;
  width: 22px;
  height: 22px;
  margin: 0;
}

.attach-btn::after,
.voice-call-btn::after {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* Install prompt */
.install-banner {
  bottom: 18px;
  width: min(470px, calc(100vw - 24px));
  border-color: rgba(96, 132, 171, 0.24);
  border-radius: 19px;
  background:
    radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.98), transparent 43%),
    rgba(246, 250, 254, 0.96);
  box-shadow: 0 24px 65px rgba(10, 38, 71, 0.22);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}

body.ui-overlay-open .install-banner {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
}

.install-banner-action {
  white-space: nowrap;
}

/* Authentication */
.modal-card--narrow {
  width: min(440px, 100%);
}

.auth-brand {
  margin-bottom: 12px;
}

.modal-card--narrow > .modal-kicker {
  margin-top: 0;
}

#authTitle {
  max-width: 350px;
  font-size: clamp(29px, 5vw, 38px);
  letter-spacing: -0.045em;
}

#authNote {
  max-width: 360px;
  line-height: 1.5;
}

.auth-tabs {
  padding: 3px;
  border: 1px solid rgba(98, 132, 169, 0.17);
}

.auth-tab {
  min-height: 39px;
}

.modal-form input {
  min-height: 46px;
}

.modal-form .auth-password-toggle {
  justify-self: end;
  min-height: 26px;
  margin: -5px 2px -1px;
  border: 0;
  background: transparent;
  color: #426b96;
  padding: 2px 0;
  font-size: 11px;
  font-weight: 800;
  box-shadow: none;
}

.modal-form .auth-password-toggle:hover {
  color: #174a86;
  background: transparent;
  box-shadow: none;
}

.auth-yandex-button {
  min-height: 48px;
}

/* Settings */
.settings-menu-card {
  border-color: rgba(108, 140, 176, 0.21);
  box-shadow: 0 24px 60px rgba(15, 44, 78, 0.18);
}

.settings-menu-row {
  min-height: 48px;
  border-radius: 12px;
}

.settings-menu-row:hover {
  background: rgba(227, 238, 248, 0.75);
}

.settings-menu-icon {
  flex: 0 0 auto;
}

/* Support */
.support-layout {
  background:
    radial-gradient(circle at 90% 0, rgba(54, 119, 183, 0.12), transparent 30%),
    linear-gradient(145deg, #edf3f8, #e7eef4);
}

.support-panel {
  border-color: rgba(122, 154, 189, 0.24);
  box-shadow: 0 30px 80px rgba(19, 50, 85, 0.14);
}

.support-head {
  align-items: center;
}

.support-head h2 {
  font-size: clamp(31px, 4vw, 42px);
}

.support-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  border: 1px solid rgba(96, 132, 171, 0.2);
  background: rgba(255, 255, 255, 0.78);
  color: #174a86;
  box-shadow: 0 9px 23px rgba(31, 82, 143, 0.08);
}

.support-back-btn span:first-child {
  font-size: 18px;
  line-height: 1;
}

.support-empty {
  display: grid;
  justify-items: center;
  max-width: 420px;
  color: var(--ui-muted);
  text-align: center;
}

.support-empty strong {
  margin-top: 13px;
  color: #173b62;
  font: 600 24px/1.1 Fraunces, Georgia, serif;
}

.support-empty p {
  margin: 9px 0 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
}

.support-empty-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(73, 126, 181, 0.18);
  border-radius: 19px;
  background: linear-gradient(145deg, #ffffff, #e9f3fb);
  color: #246aa6;
  box-shadow: 0 15px 35px rgba(27, 71, 117, 0.12);
}

.support-empty-icon::before {
  content: "";
  width: 27px;
  height: 27px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 2a9 9 0 0 0-9 9v4a3 3 0 0 0 3 3h2v-7H5a7 7 0 0 1 14 0h-3v7h2v1h-5v2h5a3 3 0 0 0 3-3v-7a9 9 0 0 0-9-9Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 2a9 9 0 0 0-9 9v4a3 3 0 0 0 3 3h2v-7H5a7 7 0 0 1 14 0h-3v7h2v1h-5v2h5a3 3 0 0 0 3-3v-7a9 9 0 0 0-9-9Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.support-empty button {
  min-height: 42px;
  margin-top: 17px;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(145deg, #174a86, #2d70ac);
  color: #fff;
  padding: 0 18px;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 13px 28px rgba(25, 75, 127, 0.2);
}

.support-panel--guest {
  grid-template-rows: auto minmax(0, 1fr);
}

.support-form[hidden] {
  display: none !important;
}

.support-form input:focus,
.support-form textarea:focus {
  border-color: rgba(47, 111, 173, 0.54);
  box-shadow: 0 0 0 3px rgba(47, 111, 173, 0.08);
}

/* FAQ */
.faq-nav {
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.faq-nav::-webkit-scrollbar {
  display: none;
}

.faq-nav a {
  scroll-snap-align: start;
}

.faq-card {
  border-color: rgba(88, 123, 161, 0.16);
}

/* Voice */
.voice-call-close {
  display: grid;
  place-items: center;
  padding: 0 0 3px;
}

.voice-call-duration {
  font-variant-numeric: tabular-nums;
}

/* Dark theme refinements */
:root[data-theme="dark"] {
  --ui-focus: 0 0 0 3px rgba(100, 174, 238, 0.25);
}

:root[data-theme="dark"] ::selection {
  background: rgba(100, 174, 238, 0.27);
  color: #f1f6ff;
}

:root[data-theme="dark"] .account-card,
:root[data-theme="dark"] .menu-btn,
:root[data-theme="dark"] .followup-chip {
  background: rgba(16, 33, 56, 0.82);
  border-color: rgba(135, 171, 211, 0.16);
}

:root[data-theme="dark"] .support-layout {
  background:
    radial-gradient(circle at 90% 0, rgba(47, 104, 176, 0.18), transparent 31%),
    linear-gradient(145deg, #07111f, #0d1c31);
}

:root[data-theme="dark"] .support-empty strong {
  color: #e4efff;
}

:root[data-theme="dark"] .support-empty {
  color: #98abc3;
}

:root[data-theme="dark"] .support-empty-icon,
:root[data-theme="dark"] .support-back-btn {
  border-color: rgba(135, 171, 211, 0.2);
  background: rgba(17, 36, 60, 0.9);
  color: #9bc6ed;
}

@media (max-width: 1080px) {
  .sidebar {
    border-right: 1px solid rgba(104, 137, 173, 0.18);
    box-shadow: 18px 0 58px rgba(8, 31, 59, 0.18);
  }
}

@media (max-width: 760px) {
  :root {
    --composer-inset: 160px;
  }

  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 10px 8px;
  }

  .topbar-row {
    min-height: 42px;
  }

  .topbar-title h1 {
    max-width: 43vw;
    overflow: hidden;
    font-size: 19px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .voice-call-btn,
  .quick-new-chat-btn,
  .menu-btn {
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    border-radius: 12px;
  }

  .menu-btn {
    padding: 0 11px;
    font-size: 12px;
  }

  .chat-feed {
    padding-top: 5px;
  }

  .chat-intro {
    min-height: 0;
    align-content: start;
    gap: 9px;
    padding: 21px 0 8px;
  }

  .start-card {
    border-radius: 20px;
    padding: 20px 16px 18px;
  }

  .start-card h2 {
    font-size: clamp(28px, 8vw, 35px);
    line-height: 1.03;
  }

  .start-subtitle {
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.47;
  }

  .suggest-grid {
    gap: 7px;
  }

  .suggest {
    min-height: 50px;
    border-radius: 14px;
    padding: 9px 8px 9px 36px;
    font-size: 11px;
    line-height: 1.25;
  }

  .suggest::before {
    left: 11px;
  }

  .chat-stream {
    scroll-padding-bottom: 18px;
  }

  .message {
    border-radius: 15px;
  }

  .followup-row,
  .message-sources {
    margin-right: -10px;
    padding-right: 20px;
  }

  .followup-chip {
    flex: 0 0 auto;
    max-width: min(82vw, 350px);
    min-height: 37px;
    border-radius: 12px;
    padding: 8px 11px;
    overflow: visible;
    white-space: normal;
    text-align: left;
    line-height: 1.3;
  }

  .source-pill {
    min-height: 29px;
  }

  .source-pill-host {
    max-width: 48vw;
  }

  .chat-action {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .chat-action::after {
    width: 15px;
    height: 15px;
  }

  .message-action-btn {
    width: 36px;
    min-height: 34px;
  }

  .composer-wrap {
    padding: 7px 9px max(8px, env(safe-area-inset-bottom));
  }

  .composer {
    gap: 7px;
    border-radius: 15px;
    padding: 8px;
  }

  .composer textarea {
    min-height: 28px;
    max-height: 112px;
    line-height: 1.4;
  }

  .tools-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 41px 41px;
    gap: 6px;
  }

  .model-switch {
    order: 1;
    grid-column: 1;
    width: 100%;
  }

  .model-btn {
    min-width: 0;
    min-height: 36px;
    padding: 7px 5px;
    font-size: 10px;
  }

  .topic-select {
    order: 2;
    grid-column: 2 / -1;
    width: 100%;
    min-height: 36px;
    padding-left: 9px;
  }

  .topic-select > span {
    display: none;
  }

  .topic-select select {
    min-height: 34px;
    font-size: 11px;
  }

  .send-btn {
    order: 3;
    grid-column: 1 / 3;
    width: 100%;
    min-height: 40px;
  }

  .voice-btn {
    order: 4;
    grid-column: 3;
    width: 41px;
    height: 40px;
  }

  .attach-btn {
    order: 5;
    grid-column: 4;
    width: 41px;
    height: 40px;
  }

  .composer-meta {
    min-height: 15px;
  }

  .status {
    font-size: 10px;
  }

  .install-banner {
    bottom: calc(var(--composer-inset) + env(safe-area-inset-bottom) + 7px);
    grid-template-columns: 34px minmax(0, 1fr) auto 32px;
    gap: 8px;
    width: calc(100vw - 18px);
    border-radius: 16px;
    padding: 9px;
  }

  .install-banner-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .install-banner-title {
    font-size: 11px;
  }

  .install-banner-text {
    display: -webkit-box;
    margin-top: 2px;
    overflow: hidden;
    font-size: 9px;
    line-height: 1.3;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .install-banner-action {
    min-height: 34px;
    border-radius: 10px;
    padding: 0 10px;
    font-size: 9px;
  }

  .install-banner-close {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .modal {
    align-items: center;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .modal-card--narrow {
    max-height: calc(var(--app-height) - 16px);
    overflow-y: auto;
    border-radius: 21px;
    padding: 18px 16px;
  }

  .auth-brand {
    margin-bottom: 8px;
  }

  #authTitle {
    font-size: 29px;
  }

  #authNote {
    margin-top: 7px;
    font-size: 11px;
  }

  .auth-tabs {
    margin-top: 13px;
  }

  .modal-form {
    gap: 8px;
  }

  .modal-form input {
    min-height: 43px;
  }

  .auth-yandex-button {
    min-height: 44px;
  }

  .settings-menu-card {
    max-height: min(76dvh, calc(var(--app-height) - 22px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .settings-menu-head {
    position: sticky;
    top: 0;
    z-index: 3;
    background: inherit;
  }

  .settings-menu-row {
    min-height: 47px;
  }

  .support-layout {
    place-items: stretch;
  }

  .support-panel {
    height: var(--app-height);
  }

  .support-head {
    min-height: 92px;
    flex-direction: row;
    align-items: center;
    padding: max(13px, env(safe-area-inset-top)) 14px 13px;
  }

  .support-head h2 {
    margin: 3px 0 4px;
    font-size: 27px;
  }

  .support-kicker,
  .support-status {
    font-size: 10px;
  }

  .support-status {
    max-width: 245px;
    line-height: 1.35;
  }

  .support-back-btn {
    flex: 0 0 auto;
    width: auto;
    min-height: 38px;
    border-radius: 12px;
    padding: 0 11px;
    font-size: 11px;
  }

  .support-messages {
    padding: 14px;
  }

  .support-empty {
    align-self: center;
    margin: auto;
    padding: 10px 8px 20px;
  }

  .support-empty strong {
    font-size: 22px;
  }

  .support-empty p {
    max-width: 310px;
    font-size: 12px;
  }

  .support-form {
    padding: 11px 12px max(12px, env(safe-area-inset-bottom));
  }

  .support-form textarea {
    min-height: 84px;
    max-height: 150px;
  }

  .faq-layout {
    padding-right: 10px;
    padding-left: 10px;
  }

  .faq-head {
    gap: 10px;
  }

  .faq-head h2 {
    font-size: 28px;
  }

  .faq-head p:last-child {
    max-width: 280px;
    font-size: 11px;
  }

  .faq-nav {
    position: relative;
    margin-right: -10px;
    margin-left: -10px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    padding-right: 18px;
    padding-left: 10px;
  }

  .faq-grid {
    gap: 9px;
  }

  .faq-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px;
    grid-template-areas:
      "number demo"
      "title demo"
      "copy copy"
      "example example";
    min-height: 0;
    border-radius: 18px;
    padding: 15px;
  }

  .faq-number {
    grid-area: number;
  }

  .faq-card h3 {
    grid-area: title;
    margin: 7px 0 8px;
    font-size: 18px;
  }

  .faq-card p {
    grid-area: copy;
    max-width: none;
    font-size: 11px;
    line-height: 1.55;
  }

  .faq-card code {
    position: relative;
    right: auto;
    bottom: auto;
    left: auto;
    grid-area: example;
    margin-top: 12px;
  }

  .faq-demo {
    position: relative;
    top: auto;
    right: auto;
    grid-area: demo;
    justify-self: end;
    width: 82px;
    height: 64px;
    border-radius: 14px;
  }

  .faq-demo--modes {
    height: 42px;
  }

  .faq-demo--document i {
    left: 11px;
    top: 7px;
    width: 42px;
    height: 50px;
  }

  .faq-demo--document b {
    margin: 10px 5px 0 58px;
    font-size: 7px;
  }

  .faq-demo--file {
    padding: 8px;
  }

  .faq-demo--file i {
    width: 21px;
    height: 37px;
  }

  .faq-demo--file i:nth-child(2) {
    height: 47px;
  }

  .faq-demo--voice i {
    width: 45px;
    height: 45px;
  }

  .voice-call-card {
    border-radius: 25px;
  }
}

@media (max-width: 370px) {
  .topbar-title {
    display: none;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .start-card h2 {
    font-size: 27px;
  }

  .suggest {
    padding-left: 32px;
    font-size: 10px;
  }

  .suggest::before {
    left: 9px;
    width: 16px;
    height: 16px;
  }
}

@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;
  }
}
