:root {
  --bg: #eef3c7;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(247, 255, 208, 0.92);
  --line: rgba(109, 142, 0, 0.22);
  --text: #213100;
  --muted: #698000;
  --accent: #7ec400;
  --accent-strong: #4d8f00;
  --bubble-self: linear-gradient(180deg, #dcff8b 0%, #bce953 100%);
  --bubble-peer: #ffffff;
  --shadow: 0 22px 60px rgba(76, 103, 0, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 30%),
    linear-gradient(135deg, #eff5c6 0%, #d7ea79 48%, #b7d432 100%);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  appearance: none;
}

.background-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.75), transparent 18%),
    radial-gradient(circle at 80% 15%, rgba(170, 217, 28, 0.3), transparent 16%),
    radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.55), transparent 22%);
  pointer-events: none;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.window {
  width: min(1320px, 100%);
  min-height: min(880px, calc(100vh - 48px));
  background: rgba(244, 250, 203, 0.88);
  backdrop-filter: blur(14px);
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 30px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.window::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(131, 164, 0, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(131, 164, 0, 0.06) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
}

.auth-window {
  width: min(760px, 100%);
  min-height: auto;
}

.titlebar,
.window-body,
.chat-panel,
.sidebar {
  position: relative;
  z-index: 1;
}

.titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  background: linear-gradient(180deg, rgba(134, 181, 0, 0.95), rgba(95, 137, 0, 0.95));
  color: #f9ffeb;
}

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

.language-switcher {
  position: relative;
  z-index: 30;
}

.lang-button {
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, #8ccc00, #5e9800);
  color: #fff;
  box-shadow: 0 12px 22px rgba(88, 135, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.lang-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.85),
    0 2px 6px rgba(0, 0, 0, 0.12);
}

.lang-button:hover {
  filter: brightness(1.05);
}

.lang-button:active {
  transform: translateY(1px);
}

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 140px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(248, 255, 226, 0.96);
  border: 1px solid rgba(109, 142, 0, 0.24);
  box-shadow: 0 16px 32px rgba(76, 103, 0, 0.18);
  display: grid;
  gap: 6px;
  z-index: 40;
}

.lang-menu[hidden] {
  display: none;
}

.bottom-menu {
  top: auto;
  bottom: calc(100% + 8px);
}

.lang-option {
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(126, 196, 0, 0.08);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.lang-option:hover {
  background: rgba(126, 196, 0, 0.18);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  opacity: 0.8;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2vw, 2.2rem);
}

.logo {
  width: 56px;
  height: 56px;
  position: relative;
}

.logo span {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fffef0;
  box-shadow: 0 2px 0 rgba(68, 97, 0, 0.25);
}

.logo span:nth-child(1) { top: 0; left: 20px; }
.logo span:nth-child(2) { top: 10px; left: 0; }
.logo span:nth-child(3) { top: 10px; right: 0; }
.logo span:nth-child(4) { bottom: 6px; left: 8px; }
.logo span:nth-child(5) {
  bottom: 6px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: #ffce33;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.auth-body {
  display: grid;
  place-items: center;
  padding: 40px 24px 48px;
}

.auth-panel {
  width: min(440px, 100%);
  padding: 24px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.auth-tab,
.logout-button,
.small-button,
.mini-action {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 800;
  cursor: pointer;
}

.auth-tab,
.mini-action {
  background: rgba(126, 196, 0, 0.1);
  color: var(--accent-strong);
}

.auth-tab.active,
.logout-button,
.small-button {
  background: linear-gradient(180deg, #8ccc00, #5e9800);
  color: #fff;
}

.accent-button {
  background: linear-gradient(180deg, #ffd348, #f2a800);
  color: #4b3b00;
}

.auth-hint,
.empty-state,
.empty-card {
  color: var(--muted);
  line-height: 1.5;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label,
.creation-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.auth-form input,
.search input,
textarea,
select,
.creation-panel input {
  width: 100%;
  border: 1px solid rgba(124, 157, 0, 0.25);
  background: rgba(254, 255, 242, 0.9);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
  outline: none;
}

.auth-form input:focus,
.search input:focus,
textarea:focus,
select:focus,
.creation-panel input:focus {
  border-color: rgba(92, 141, 0, 0.55);
  box-shadow: 0 0 0 4px rgba(158, 205, 18, 0.14);
}

.auth-submit {
  width: 100%;
}

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 120;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 14px 16px;
  border-radius: 18px;
  color: #fff;
  font-weight: 700;
  line-height: 1.4;
  box-shadow: 0 18px 36px rgba(53, 79, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(-8px);
  animation: toast-in 180ms ease forwards;
}

.toast.is-hiding {
  animation: toast-out 180ms ease forwards;
}

.toast-success {
  background: linear-gradient(180deg, rgba(90, 162, 0, 0.96), rgba(63, 122, 0, 0.96));
}

.toast-error {
  background: linear-gradient(180deg, rgba(214, 61, 40, 0.97), rgba(155, 24, 12, 0.97));
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

.auth-uin-note {
  margin: -4px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.verification-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: 24px;
}

.verification-modal[hidden] {
  display: none;
}

.verification-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 47, 0, 0.34);
  backdrop-filter: blur(10px);
}

.verification-dialog {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 24px;
  background: rgba(248, 255, 226, 0.96);
}

.verification-dialog h2 {
  margin: 0 0 10px;
  font-size: 1.5rem;
}

.verification-code-field {
  margin-top: 18px;
}

.verification-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.window-body {
  display: grid;
  grid-template-columns: 350px 1fr;
  min-height: calc(100% - 96px);
}

.bottom-actions {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 6;
  display: flex;
  gap: 10px;
  align-items: center;
}

.sidebar {
  padding: 20px;
  border-right: 1px solid rgba(108, 142, 0, 0.16);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(241, 250, 193, 0.7));
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 14px;
  min-height: 0;
}

.profile-card,
.chat-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.profile-card {
  justify-content: space-between;
}

.profile-text {
  flex: 1;
}

.profile-card p,
.chat-user p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #9fcb10, #6f9c05);
  box-shadow: inset 0 2px 8px rgba(255, 255, 255, 0.22);
  overflow: hidden;
  flex: 0 0 auto;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar::after {
  content: attr(data-fallback);
}

.avatar.has-image::after,
.profile-avatar img[hidden] {
  content: "";
}

.self-avatar {
  background: linear-gradient(180deg, #ffd73b, #f5b300);
  color: #334100;
}

.creation-panel {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.inline-input-group {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.mini-action {
  text-align: center;
  white-space: nowrap;
}

.contacts-header {
  display: flex;
  justify-content: space-between;
  margin: 4px 4px 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.contact-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
  min-height: 0;
}

.contact-card {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid transparent;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.46);
  text-align: left;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.contact-card:hover,
.contact-card.active {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(109, 142, 0, 0.24);
}

.contact-card strong,
.chat-user strong {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}

.contact-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.contact-meta {
  text-align: right;
  font-size: 0.82rem;
  color: var(--muted);
}

.contact-meta .unread-badge {
  display: inline-flex;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  margin-top: 6px;
  background: linear-gradient(180deg, #8ccc00, #5e9800);
  color: #fff;
  font-weight: 800;
}

.status-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  object-fit: contain;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 20px 20px 96px;
  min-height: 0;
}

.chat-user,
.chat-badges {
  display: flex;
  gap: 14px;
  align-items: center;
}

.chat-top {
  justify-content: space-between;
}

.badge {
  display: inline-flex;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(126, 196, 0, 0.12);
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 700;
}

.empty-state,
.empty-card {
  padding: 22px;
}

.message-area {
  overflow: auto;
  min-height: 0;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message-row {
  display: flex;
  gap: 12px;
  max-width: 78%;
}

.message-row.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-bubble {
  padding: 14px 16px;
  border-radius: 20px 20px 20px 6px;
  background: var(--bubble-peer);
  box-shadow: 0 14px 30px rgba(121, 148, 7, 0.1);
}

.message-row.self .message-bubble {
  border-radius: 20px 20px 6px 20px;
  background: var(--bubble-self);
}

.message-author {
  margin-bottom: 8px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.message-bubble p {
  margin: 0;
  line-height: 1.45;
}

.message-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.attachment-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(126, 196, 0, 0.08);
  color: inherit;
  text-decoration: none;
}

.attachment-card img {
  width: 100%;
  aspect-ratio: 1.25;
  object-fit: cover;
  border-radius: 10px;
}

.attachment-card.file {
  align-content: center;
}

.composer {
  padding: 16px;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.attachment-chip {
  border: none;
  border-radius: 999px;
  background: rgba(126, 196, 0, 0.12);
  color: var(--accent-strong);
  padding: 8px 12px;
  cursor: pointer;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.tool-button,
.send-button {
  border: none;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}

.tool-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: rgba(126, 196, 0, 0.12);
  color: var(--accent-strong);
}

.send-button {
  min-width: 132px;
  padding: 14px 20px;
  color: white;
  background: linear-gradient(180deg, #8ccc00, #5e9800);
  box-shadow: 0 12px 22px rgba(88, 135, 0, 0.24);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1024px) {
  .window-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(108, 142, 0, 0.16);
    grid-template-rows: auto auto auto auto auto;
  }

  .contact-list {
    max-height: 260px;
  }

  .chat-panel {
    min-height: 520px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
    place-items: stretch;
  }

  .window {
    width: 100%;
    min-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .titlebar,
  .sidebar,
  .chat-panel {
    padding: 16px;
  }

  .auth-window {
    width: 100%;
  }

  .titlebar {
    padding: 14px 16px;
    gap: 12px;
    align-items: flex-start;
  }

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

  .brand {
    gap: 12px;
    width: 100%;
  }

  .brand h1 {
    font-size: 1.3rem;
  }

  .eyebrow {
    font-size: 0.66rem;
    letter-spacing: 0.08em;
  }

  .logo {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
  }

  .logo span {
    width: 13px;
    height: 13px;
  }

  .logo span:nth-child(1) { left: 16px; }
  .logo span:nth-child(2) { top: 8px; }
  .logo span:nth-child(3) { top: 8px; }
  .logo span:nth-child(5) {
    width: 20px;
    height: 20px;
  }

  .auth-body {
    padding: 20px 14px 28px;
  }

  .auth-panel,
  .verification-dialog {
    width: 100%;
    padding: 18px;
    border-radius: 18px;
  }

  .window-body {
    gap: 0;
  }

  .sidebar {
    padding: 14px;
    gap: 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(241, 250, 193, 0.78));
  }

  .profile-card,
  .chat-top {
    padding: 14px;
  }

  .profile-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 12px;
  }

  .mini-action {
    grid-column: 1 / -1;
    width: 100%;
  }

  .creation-panel {
    padding: 12px;
  }

  .creation-panel select {
    min-height: 132px;
  }

  .inline-input-group {
    grid-template-columns: 1fr;
  }

  .contacts-header {
    margin: 0;
    font-size: 0.78rem;
  }

  .contact-list {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 2px 8px;
    max-height: none;
    min-height: auto;
    scroll-snap-type: x proximity;
  }

  .contact-card {
    min-width: 240px;
    max-width: 240px;
    grid-template-columns: 44px 1fr;
    grid-template-areas:
      "avatar body"
      "meta meta";
    gap: 10px;
    padding: 12px;
    scroll-snap-align: start;
  }

  .contact-card > .avatar {
    grid-area: avatar;
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .contact-card > div:nth-child(2) {
    grid-area: body;
    min-width: 0;
  }

  .contact-card > .contact-meta {
    grid-area: meta;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
  }

  .contact-card p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-panel {
    padding: 14px 14px 92px;
    gap: 14px;
  }

  .chat-top {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .chat-user {
    gap: 10px;
    min-width: 0;
  }

  .chat-user > div:last-child {
    min-width: 0;
  }

  .chat-user strong,
  .chat-user p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chat-badges {
    flex: 0 0 auto;
  }

  .badge {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .message-area {
    gap: 10px;
    padding: 2px 0 6px;
  }

  .message-row {
    max-width: 100%;
    gap: 8px;
  }

  .message-row > .avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    flex: 0 0 38px;
  }

  .message-bubble {
    padding: 12px 13px;
    max-width: calc(100vw - 90px);
  }

  .message-author {
    font-size: 0.72rem;
  }

  .message-meta {
    font-size: 0.72rem;
  }

  .attachment-grid {
    grid-template-columns: 1fr;
  }

  .bottom-actions {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
    justify-content: stretch;
  }

  .bottom-actions > * {
    flex: 1 1 0;
    min-width: 0;
  }

  .lang-button,
  .logout-button,
  .small-button,
  .auth-tab,
  .mini-action {
    min-height: 46px;
  }

  .lang-button {
    justify-content: center;
    width: 100%;
    padding-inline: 12px;
  }

  .toast-container {
    top: 12px;
    left: 12px;
    right: 12px;
    width: auto;
  }

  .message-row {
    max-width: 100%;
  }

  .composer-actions {
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .verification-actions {
    flex-direction: column-reverse;
  }

  .composer {
    padding: 12px;
  }

  .composer textarea {
    min-height: 92px;
  }

  .tool-button {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
  }

  .send-button {
    width: 100%;
    min-width: 0;
  }

  .verification-modal {
    padding: 12px;
  }
}

@media (max-width: 420px) {
  .titlebar {
    padding: 12px;
  }

  .auth-body,
  .sidebar,
  .chat-panel {
    padding: 12px;
  }

  .profile-card,
  .chat-top,
  .composer,
  .auth-panel,
  .verification-dialog {
    padding: 14px;
  }

  .auth-tabs {
    gap: 8px;
  }

  .contact-card {
    min-width: 220px;
    max-width: 220px;
  }

  .message-bubble {
    max-width: calc(100vw - 74px);
    padding: 11px 12px;
  }

  .bottom-actions {
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .lang-button {
    gap: 6px;
    font-size: 0.92rem;
  }
}
