:root {
  --auth-bg: #2c5545;
  --auth-input: #addfad;
  --login-btn: #e8c39e;
  --register-btn: #fdecda;
  --auth-text-dark: #000000;
  --auth-text-light: #ffffff;

  --app-bg: #e7edf3;
  --sidebar-bg: #ffffff;
  --sidebar-border: #d8e1ea;
  --sidebar-hover: #f2f6fa;
  --sidebar-active: #d9ecff;
  --chat-bg: #edf3f8;
  --chat-header-bg: rgba(255, 255, 255, 0.86);
  --message-incoming: #ffffff;
  --message-outgoing: #dff1ff;
  --message-meta: #6d7c8a;
  --text-main: #1f2a33;
  --text-soft: #5f6f7c;
  --telegram-blue: #3390ec;
  --telegram-blue-dark: #2a7fd2;
  --badge-bg: #3390ec;
  --badge-text: #ffffff;
  --white: #ffffff;

  --shadow-soft: 0 10px 30px rgba(31, 42, 51, 0.12);
  --shadow-card: 0 12px 35px rgba(0, 0, 0, 0.18);

  --radius-sm: 14px;
  --radius-md: 20px;
  --radius-lg: 28px;

  --sidebar-width: 340px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, Arial, sans-serif;
  color: var(--text-main);
  background: var(--auth-bg);
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

input {
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.2s ease;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(51, 144, 236, 0.3);
  outline-offset: 2px;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
}

/* Auth */

#auth-screen {
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: var(--auth-bg);
}

.auth-layout {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.auth-logo-wrap {
  display: flex;
  justify-content: center;
}

.auth-cat-logo {
  width: 156px;
  height: 156px;
  object-fit: cover;
  border-radius: 32px;
  box-shadow: var(--shadow-card);
  background: rgba(255, 255, 255, 0.12);
}

.auth-form-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.auth-title {
  margin: 0;
  text-align: center;
  color: var(--auth-text-light);
  font-size: 36px;
  line-height: 1.05;
  font-weight: 700;
}

.auth-subtitle {
  margin: 10px 0 24px;
  text-align: center;
  color: rgba(255, 255, 255, 0.88);
  font-size: 16px;
  line-height: 1.4;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input {
  width: 100%;
  min-height: 56px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  background: var(--auth-input);
  color: var(--auth-text-dark);
  padding: 0 18px;
  box-shadow: none;
}

.auth-form input::placeholder {
  color: rgba(0, 0, 0, 0.62);
}

.auth-form input:focus {
  border-color: rgba(0, 0, 0, 0.18);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.16);
}

.register-extra-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.register-extra-fields[hidden] {
  display: none !important;
}

.nickname-field-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-error {
  margin: 0;
  padding: 0 4px;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.35;
}

.field-error[hidden] {
  display: none !important;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}

.login-btn,
.register-btn {
  min-height: 52px;
  border: 0;
  border-radius: 18px;
  color: var(--auth-text-dark);
  font-weight: 600;
  padding: 0 14px;
}

.login-btn {
  background: var(--login-btn);
}

.register-btn {
  background: var(--register-btn);
}

.login-btn:hover,
.register-btn:hover {
  transform: translateY(-1px);
}

.auth-status {
  min-height: 22px;
  margin: 2px 0 0;
  color: var(--auth-text-light);
  font-size: 14px;
  text-align: center;
}

.auth-status.error {
  color: #ffd2d2;
}

.auth-status.ok {
  color: #d8ffe4;
}

/* Messenger */

#messenger-screen {
  width: 100%;
  min-height: 100vh;
  background: var(--app-bg);
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-top h2 {
  margin: 0 0 4px;
  font-size: 24px;
  color: var(--text-main);
}

.sidebar-subtitle {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
}

.sidebar-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-profile-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--sidebar-border);
  border-radius: 999px;
  background: #ffffff;
  color: #2f6f5f;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.sidebar-profile-link:hover {
  background: #f5f8f7;
  border-color: #cfd8d4;
}

.ghost-btn {
  border: 1px solid var(--sidebar-border);
  background: var(--white);
  color: var(--telegram-blue);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 600;
  white-space: nowrap;
}

.ghost-btn:hover,
.ghost-icon-btn:hover,
.mobile-back-btn:hover {
  background: var(--sidebar-hover);
}

.search-wrap {
  padding: 14px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}

.search-wrap input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--sidebar-border);
  border-radius: 14px;
  background: #f5f8fb;
  color: var(--text-main);
  padding: 0 14px;
}

.search-wrap input::placeholder {
  color: #80909d;
}

.search-wrap input:focus {
  border-color: var(--telegram-blue);
  box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.16);
  background: var(--white);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  text-align: left;
  color: var(--text-main);
}

.chat-item:hover {
  background: var(--sidebar-hover);
}

.chat-item.active {
  background: var(--sidebar-active);
}

.chat-avatar {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #54a8f4, #2a7fd2);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: inset 0 -6px 14px rgba(0, 0, 0, 0.08);
}

.chat-avatar.large {
  width: 50px;
  height: 50px;
  min-width: 50px;
}

.favorite-avatar {
  background: linear-gradient(135deg, #5caeff, #3390ec);
  color: var(--white);
}

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

.chat-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-row + .chat-row {
  margin-top: 4px;
}

.chat-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.chat-time {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-soft);
}

.chat-preview {
  display: inline-block;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-soft);
  font-size: 13px;
}

.chat-badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.chat-panel {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.45), transparent 30%),
    var(--chat-bg);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--chat-header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(216, 225, 234, 0.9);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.chat-header h3 {
  margin: 0 0 3px;
  font-size: 18px;
  color: var(--text-main);
}

.header-meta {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
}

.ghost-icon-btn,
.mobile-back-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.mobile-back-btn {
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.day-separator {
  display: flex;
  justify-content: center;
  margin: 2px 0 4px;
}

.day-separator span {
  background: rgba(99, 120, 140, 0.14);
  color: var(--text-soft);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 999px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: min(72%, 560px);
}

.message.incoming {
  align-self: flex-start;
}

.message.outgoing {
  align-self: flex-end;
}

.message-bubble {
  border-radius: 18px;
  padding: 11px 14px;
  line-height: 1.45;
  color: var(--text-main);
  box-shadow: var(--shadow-soft);
  word-break: break-word;
}

.message.incoming .message-bubble {
  background: var(--message-incoming);
  border-top-left-radius: 8px;
}

.message.outgoing .message-bubble {
  background: var(--message-outgoing);
  border-top-right-radius: 8px;
}

.message-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--message-meta);
}

.message.outgoing .message-meta {
  text-align: right;
}

.message-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 18px;
  background: rgba(231, 237, 243, 0.96);
  border-top: 1px solid rgba(216, 225, 234, 0.9);
}

.message-input-wrap input {
  flex: 1;
  min-height: 48px;
  border: 1px solid var(--sidebar-border);
  border-radius: 999px;
  background: var(--white);
  color: var(--text-main);
  padding: 0 16px;
}

.message-input-wrap input:focus {
  border-color: var(--telegram-blue);
  box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.16);
}

.primary-send-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--telegram-blue);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 10px 22px rgba(51, 144, 236, 0.28);
}

.primary-send-btn:hover {
  background: var(--telegram-blue-dark);
  transform: translateY(-1px);
}

/* New chat button */

.new-chat-menu-wrap {
  position: relative;
  flex: 0 0 auto;
}

.new-chat-fab {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: #dff3e4;
  color: #2c5545;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(44, 85, 69, 0.14);
}

.new-chat-fab span {
  display: block;
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
  color: #2c5545;
  transform: translateY(-1px);
}

.new-chat-fab:hover {
  background: #d3edd9;
  box-shadow: 0 8px 22px rgba(44, 85, 69, 0.18);
  transform: translateY(-1px);
}

.new-chat-fab:active {
  transform: translateY(0);
  background: #c7e7cf;
}

.new-chat-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 170px;
  padding: 8px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1000;
}

.new-chat-menu[hidden] {
  display: none !important;
}

.new-chat-menu-item {
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-main);
}

.new-chat-menu-item:hover {
  background: #f3f4f6;
}

/* Profile */

.profile-page {
  margin: 0;
  min-height: 100vh;
  background: #f4f6fb;
}

.profile-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.profile-topbar {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 18px;
}

.profile-back-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 18px;
  background: #dcefdc;
  border: 1px solid #c6dfc7;
  color: #1f2937;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
}

.profile-back-card:hover {
  background: #d2e8d3;
}

.profile-header-centered {
  text-align: center;
  margin-bottom: 18px;
}

.profile-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  color: #101828;
}

.profile-hero-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0 24px;
}

.profile-avatar-empty {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #dbe4ea;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.profile-change-avatar-btn {
  margin-top: 14px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid #cfe0d1;
  border-radius: 999px;
  background: #dcefdc;
  color: #1f2937;
  font-size: 14px;
  font-weight: 600;
}

.profile-change-avatar-btn:hover {
  background: #d2e8d3;
}

.profile-fullname {
  margin: 16px 0 0;
  color: #111111;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
}

.profile-menu-list {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.profile-menu-card {
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 18px;
  border: 1px solid #cfe0d1;
  border-radius: 20px;
  background: #dcefdc;
  text-align: left;
}

.profile-menu-card:hover:not(:disabled) {
  background: #d2e8d3;
}

.profile-menu-card:disabled {
  cursor: default;
}

.profile-menu-main {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.profile-menu-text {
  color: #111111;
  font-size: 16px;
  font-weight: 600;
}

.profile-menu-note {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: #5f6b76;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.profile-menu-card-disabled {
  opacity: 1;
}

.profile-logout-section {
  margin-top: 18px;
  padding-top: 4px;
}

.profile-logout-btn {
  width: 100%;
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid rgba(180, 35, 24, 0.16);
  border-radius: 20px;
  background: #fff1f1;
  color: #b42318;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.profile-logout-btn:hover {
  background: #ffe6e6;
  border-color: rgba(180, 35, 24, 0.24);
}

/* Responsive */

@media (max-width: 900px) {
  #messenger-screen {
    position: relative;
  }

  .sidebar,
  .chat-panel {
    width: 100%;
    min-width: 0;
  }

  .sidebar {
    border-right: 0;
  }

  .chat-panel {
    display: none;
    height: 100vh;
  }

  .sidebar.mobile-hidden {
    display: none;
  }

  .chat-panel.mobile-visible {
    display: flex;
  }

  .mobile-back-btn {
    display: inline-flex;
  }

  .chat-preview {
    max-width: 100%;
  }

  .message {
    max-width: 88%;
  }

  .sidebar-top-actions {
    gap: 8px;
  }

  .sidebar-profile-link {
    padding: 0 12px;
    min-height: 34px;
    font-size: 13px;
  }

  .new-chat-fab {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  .new-chat-menu {
    min-width: 168px;
  }
}

@media (min-width: 901px) {
  .sidebar {
    display: flex !important;
  }

  .chat-panel {
    display: flex !important;
  }
}

@media (max-width: 640px) {
  .sidebar-top,
  .search-wrap,
  .chat-header,
  .messages,
  .message-input-wrap {
    padding-left: 14px;
    padding-right: 14px;
  }

  .sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .sidebar-top > div:first-child {
    display: none;
  }

  .sidebar-top-actions {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-left: 0;
    flex-shrink: 0;
  }

  .sidebar-profile-link {
    order: 1;
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
    white-space: nowrap;
    flex: 0 0 auto;
    color: #234236;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(44, 85, 69, 0.14);
  }

  .new-chat-menu-wrap {
    order: 2;
    margin-left: auto;
    flex: 0 0 auto;
    position: relative;
    display: inline-flex;
    align-items: center;
  }

  .new-chat-fab {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 999px;
    background: #dff3e4;
    color: #2c5545;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(44, 85, 69, 0.14);
  }

  .new-chat-fab:hover,
  .new-chat-fab:active,
  .new-chat-fab:focus {
    background: #dff3e4;
    color: #2c5545;
  }

  .new-chat-fab span {
    display: block;
    font-size: 26px;
    line-height: 1;
    font-weight: 700;
    color: #2c5545;
    transform: none;
  }

  .chat-header {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .message-input-wrap {
    padding-top: 12px;
    padding-bottom: 14px;
  }
}

@media (max-width: 560px) {
  #auth-screen {
    padding: 24px 16px;
  }

  .auth-layout {
    gap: 18px;
  }

  .auth-cat-logo {
    width: 132px;
    height: 132px;
    border-radius: 28px;
  }

  .auth-title {
    font-size: 32px;
  }

  .auth-subtitle {
    font-size: 15px;
    margin-bottom: 20px;
  }

  .auth-actions {
    gap: 10px;
  }

  .login-btn,
  .register-btn {
    min-height: 50px;
    font-size: 15px;
  }

  .profile-shell {
    padding: 16px 12px 28px;
  }

  .profile-back-card {
    width: 100%;
    justify-content: center;
  }

  .profile-avatar-empty {
    width: 96px;
    height: 96px;
  }

  .profile-fullname {
    font-size: 22px;
  }

  .profile-menu-card {
    min-height: 68px;
    border-radius: 18px;
  }

  .profile-menu-main {
    flex-direction: column;
    align-items: flex-start;
  }

  .profile-logout-section {
    margin-top: 16px;
  }

  .profile-logout-btn {
    min-height: 52px;
    border-radius: 18px;
  }
}