:root {
  color-scheme: light;
  --app-height: 100dvh;
  --keyboard-offset: 0px;
  --bg: #eef6db;
  --panel: #ffffff;
  --panel-soft: #f9fbef;
  --text: #20251d;
  --muted: #65705d;
  --line: #ccd8b8;
  --accent: #6fb52d;
  --accent-strong: #2f7f28;
  --accent-warm: #ffcc3d;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(60, 82, 38, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: Arial, Tahoma, sans-serif;
  background:
    linear-gradient(135deg, rgba(238, 246, 219, 0.94), rgba(255, 248, 210, 0.9)),
    radial-gradient(circle at 15% 15%, rgba(255, 204, 61, 0.35), transparent 28%),
    radial-gradient(circle at 85% 20%, rgba(111, 181, 45, 0.24), transparent 30%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

.shell {
  min-height: var(--app-height);
  height: var(--app-height);
  overflow: hidden;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(460px, 100%);
  padding: 28px;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid rgba(204, 216, 184, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  background: var(--accent-warm);
  color: var(--accent-strong);
  border: 2px solid #f4b900;
  border-radius: 8px;
  font-size: 30px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.1;
}

.brand-lockup p,
.hint,
.message,
.sidebar-head span,
.conversation-head p {
  color: var(--muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 18px;
}

.tab-button {
  border: 0;
  padding: 11px 10px;
  background: var(--panel-soft);
  color: var(--muted);
  cursor: pointer;
}

.tab-button.active {
  background: var(--accent);
  color: white;
}

.auth-form,
.dialog-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 13px;
  background: white;
  color: var(--text);
}

textarea {
  resize: none;
  min-height: 46px;
  max-height: 160px;
}

.primary-action,
.secondary-action,
.icon-button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.primary-action {
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.secondary-action,
.icon-button {
  padding: 9px 12px;
  background: #edf3ef;
  color: var(--text);
}

.message {
  min-height: 22px;
  margin-top: 14px;
}

.message.error {
  color: var(--danger);
}

.chat-view {
  height: 100vh;
  height: 100dvh;
  height: var(--app-height);
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  background: rgba(238, 246, 219, 0.97);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #f7fbeb;
}

.sidebar-head,
.conversation-head,
.room-actions {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.call-actions {
  display: flex;
  gap: 8px;
}

.call-start,
.call-end {
  width: 42px;
  min-width: 42px;
  min-height: 42px;
  border-radius: 50%;
  color: white;
  font-size: 21px;
  font-weight: 800;
}

.call-start {
  background: #16a34a;
}

.call-start:disabled {
  background: #9fb6a6;
}

.video-start {
  font-size: 19px;
}

.call-end {
  background: #dc2626;
  transform: rotate(135deg);
}

.sidebar-head {
  display: flex;
  gap: 12px;
  align-items: center;
  background: linear-gradient(180deg, #e5f4c2, #f7fbeb);
}

.sidebar-head span {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.presence-dot {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent-warm);
  border: 2px solid #f4b900;
  color: var(--accent-strong);
  font-size: 24px;
  font-weight: 700;
}

.sidebar-head .icon-button:first-of-type {
  margin-left: auto;
}

.room-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.update-panel {
  display: grid;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff9dc;
}

.update-panel span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.update-panel a {
  color: var(--accent-strong);
  font-weight: 700;
}

.update-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auto-update {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-weight: 400;
}

.auto-update input {
  width: 18px;
  min-height: 18px;
}

.rooms-list {
  overflow: auto;
  min-height: 0;
}

.room-item {
  width: 100%;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 3px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 11px 14px;
  background: transparent;
  cursor: pointer;
}

.room-item.active {
  background: #e2f2c0;
}

.room-item::before {
  content: "☻";
  grid-row: 1 / span 2;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #d8efaa;
  color: var(--accent-strong);
  font-size: 22px;
  font-weight: 700;
}

.room-item strong {
  color: var(--text);
}

.room-item.invite {
  background: #fff6cd;
}

.room-item.invite strong::after {
  content: " приглашение";
  color: #8a5a00;
  font-size: 12px;
  font-weight: 700;
}

.room-item span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0.5)),
    repeating-linear-gradient(0deg, rgba(111, 181, 45, 0.06) 0 1px, transparent 1px 28px);
}

.messages-list {
  overflow: auto;
  min-height: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-bubble {
  max-width: min(720px, 86%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 8px rgba(31, 37, 35, 0.05);
}

.message-bubble.mine {
  align-self: flex-end;
  border-color: #b7db75;
  background: #edf8d4;
}

.message-bubble header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.message-content {
  display: grid;
  gap: 8px;
  overflow-wrap: anywhere;
}

.media-image,
.media-video {
  width: min(100%, 420px);
  max-height: 58vh;
  border-radius: 8px;
  object-fit: contain;
  background: #111;
}

.media-label {
  color: var(--muted);
  font-size: 13px;
}

.file-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.transcript-action {
  justify-self: start;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: #fff9dc;
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 700;
}

.transcript-action:disabled {
  cursor: progress;
  opacity: 0.75;
}

.reaction-row,
.reaction-menu,
.reaction-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reaction-row {
  margin-top: 8px;
}

.reaction-pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(111, 181, 45, 0.18);
  color: var(--accent-strong);
  font-size: 13px;
  line-height: 1;
}

.reaction-menu {
  position: relative;
  margin-top: 8px;
}

.reaction-toggle {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
}

.reaction-palette {
  position: absolute;
  left: 34px;
  bottom: 0;
  z-index: 4;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  box-shadow: 0 8px 24px rgba(31, 37, 35, 0.16);
}

.reaction-palette button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  cursor: pointer;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #f7fbeb;
}

.composer-tools {
  display: flex;
  gap: 8px;
  align-items: end;
}

.emoji-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff9dc;
}

.emoji-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.emoji-tabs button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  padding: 5px 10px;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.emoji-tabs button.active {
  border-color: #8fbd3d;
  background: #edf8d4;
  color: var(--accent-strong);
  font-weight: 700;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 6px;
  max-height: 168px;
  overflow: auto;
}

.emoji-choice {
  width: 38px;
  height: 38px;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 20px;
}

.kolobok-face {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff7a8, #ffd23c 58%, #d99b00);
  box-shadow: inset 0 -2px 0 rgba(138, 91, 0, 0.25);
  color: #513000;
  font-size: 17px;
  line-height: 1;
}

.kolobok-face.animated {
  animation: kolobok-bounce 1.8s ease-in-out infinite;
}

.kolobok-happy.animated,
.kolobok-laugh.animated,
.kolobok-kiss.animated {
  animation-name: kolobok-wiggle;
}

.kolobok-angry {
  background: radial-gradient(circle at 35% 30%, #ffd6a0, #ff8a45 58%, #c44722);
}

.kolobok-sad,
.kolobok-cry {
  background: radial-gradient(circle at 35% 30%, #e8fbff, #9ed8ff 58%, #4d96d9);
}

.kolobok-cool {
  background: radial-gradient(circle at 35% 30%, #fff7a8, #f4c430 58%, #b88200);
}

@keyframes kolobok-bounce {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-3px) scale(1.04);
  }
}

@keyframes kolobok-wiggle {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  30% {
    transform: rotate(-8deg) scale(1.05);
  }
  65% {
    transform: rotate(8deg) scale(1.05);
  }
}

.composer-input {
  display: block;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-weight: 400;
}

.composer-input textarea {
  display: block;
  width: 100%;
  min-height: 42px;
  max-height: min(150px, 28vh);
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.35;
  overflow-y: hidden;
  background: transparent;
}

.composer-input textarea:focus {
  outline: 2px solid rgba(111, 181, 45, 0.25);
  outline-offset: 1px;
}

.send-action {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.tool-button {
  min-width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf3ef;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: 18px;
  touch-action: none;
  user-select: none;
}

#voiceButton.recording {
  min-width: 76px;
}

.tool-button.recording {
  border-color: #f0b8b0;
  background: #fff0ee;
  color: var(--danger);
  animation: voice-pulse 1s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(31, 37, 35, 0.32);
}

.call-dialog {
  width: min(960px, 96vw);
  max-width: 96vw;
}

.call-panel {
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  width: min(960px, 96vw);
  height: min(680px, 86vh);
  background: #16201d;
  color: white;
}

.call-head,
.call-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.call-head span {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 13px;
}

.call-stage {
  position: relative;
  min-height: 0;
  background: #0c1110;
  overflow: hidden;
}

.remote-media {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0c1110;
}

.remote-audio {
  display: none;
}

.local-video {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: min(180px, 36vw);
  aspect-ratio: 9 / 16;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 8px;
  object-fit: cover;
  background: #222;
}

.call-controls {
  justify-content: center;
  background: #16201d;
}

.incoming-call-dialog {
  width: min(360px, 92vw);
}

.incoming-call-panel {
  display: grid;
  gap: 18px;
  width: min(360px, 92vw);
  padding: 18px;
  background: white;
}

.incoming-call-panel strong,
.incoming-call-panel span {
  display: block;
}

.incoming-call-panel span {
  margin-top: 4px;
  color: var(--muted);
}

.incoming-call-actions {
  display: flex;
  justify-content: center;
  gap: 28px;
}

.incoming-call-actions .call-start,
.incoming-call-actions .call-end {
  width: 58px;
  min-width: 58px;
  min-height: 58px;
  font-size: 27px;
}

.call-message {
  margin: 0;
  font-weight: 700;
  color: var(--accent-strong);
}

.dialog-form {
  width: min(420px, 92vw);
  max-height: 88vh;
  overflow: auto;
  padding: 22px;
  background: white;
}

.settings-form {
  width: min(460px, 94vw);
}

.settings-section {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.settings-section h4 {
  margin: 0;
  font-size: 15px;
}

.profile-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.avatar-button {
  width: 62px;
  height: 62px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff9dc;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}

.avatar-button span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  color: var(--accent-strong);
  font-size: 30px;
}

.settings-section input[type="text"],
.settings-section input[type="password"],
.settings-section input:not([type]),
.settings-section select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: white;
  color: var(--text);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
}

.settings-toggle input {
  width: 20px;
  min-height: 20px;
}

.settings-status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.chat-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.user-suggestions {
  display: grid;
  gap: 6px;
}

.user-suggestions:empty {
  display: none;
}

.user-suggestions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fbeb;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 4px 0 0;
}

@media (max-width: 760px) {
  .chat-view {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .sidebar {
    min-height: 0;
    border-right: 0;
  }

  .conversation {
    display: none;
    min-height: 0;
  }

  .chat-view.room-open .sidebar {
    display: none;
  }

  .chat-view.room-open .conversation {
    display: grid;
    height: calc(var(--app-height) - var(--keyboard-offset));
  }

  .conversation-head {
    align-items: center;
    padding: 10px 12px;
  }

  .call-actions {
    flex-direction: row;
    flex: 0 0 auto;
  }

  .mobile-only {
    display: inline-flex;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
    position: sticky;
    bottom: 0;
    gap: 8px;
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .emoji-panel {
    grid-column: 1 / -1;
  }

  .tool-button {
    min-width: 42px;
    height: 42px;
  }

  .send-action {
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .composer-input textarea {
    min-height: 42px;
    max-height: min(132px, 26vh);
    padding: 9px 11px;
  }

  .messages-list {
    padding: 10px;
  }

  .message-bubble {
    max-width: 92%;
  }

  .reaction-palette {
    left: 34px;
    right: auto;
  }
}
