* {
  box-sizing: border-box;
}

:root {
  --safe-top: max(env(safe-area-inset-top), 12px);
  --safe-right: max(env(safe-area-inset-right), 12px);
  --safe-bottom: max(env(safe-area-inset-bottom), 12px);
  --safe-left: max(env(safe-area-inset-left), 12px);
}

html, body {
  margin: 0;
  padding: 0;
  background: #0a0f16;
  color: #e6edf7;
  font-family: Arial, sans-serif;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(16px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
  background:
    radial-gradient(circle at top left, rgba(42,93,201,0.15), transparent 30%),
    radial-gradient(circle at bottom right, rgba(0,180,255,0.10), transparent 25%),
    #0a0f16;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(15, 22, 33, 0.96);
  border: 1px solid #1c2736;
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.38);
}

.auth-title {
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 8px;
}

.auth-sub,
.hint {
  text-align: center;
  color: #90a3bf;
  font-size: 13px;
  line-height: 1.4;
}

.auth-sub {
  margin-bottom: 18px;
}

.auth-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.input,
.textarea {
  width: 100%;
  border: 1px solid #223044;
  background: #0d141d;
  color: #e6edf7;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
}

.input:focus,
.textarea:focus {
  border-color: #3567d6;
  box-shadow: 0 0 0 3px rgba(53,103,214,0.18);
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #3570ea, #2756bf);
  color: white;
  cursor: pointer;
}

.btn.secondary {
  background: #182232;
  color: #dfe7f5;
}

.btn.green {
  background: #194127;
  color: #c7f4d4;
}

.small-btn {
  width: 46px;
  min-width: 46px;
  padding: 0;
}

.mini-btn {
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  background: #182232;
  color: #e5e7eb;
  cursor: pointer;
  font-size: 12px;
}

.icon-btn {
  width: 42px;
  min-width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: #182232;
  color: #f2f6ff;
  cursor: pointer;
  font-size: 18px;
  padding: 0;
}

.send-btn {
  width: 46px;
  min-width: 46px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #3570ea, #2756bf);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  padding: 0;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 360px;
  min-width: 360px;
  background: #0d141d;
  border-right: 1px solid #182230;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  flex: 0 0 auto;
}

.sidebar-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  font-size: 24px;
  font-weight: bold;
}

.brand-sub {
  color: #8da0bd;
  font-size: 12px;
  margin-top: 4px;
}

.sidebar-block {
  background: #111a26;
  border: 1px solid #1a2433;
  border-radius: 18px;
  padding: 12px;
}

.me-block {
  padding-bottom: 10px;
  flex: 0 0 auto;
}

.chats-block {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-title {
  font-size: 12px;
  color: #8da0bd;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex: 0 0 auto;
}

.small-text {
  font-size: 13px;
  color: #dfe7f5;
}

.online-info {
  margin-top: 8px;
  color: #9ab0d1;
  line-height: 1.4;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.chat-item {
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 14px;
  background: #141f2d;
  color: #e5e7eb;
  padding: 12px;
  cursor: pointer;
  transition: 0.12s ease;
}

.chat-item:hover {
  background: #182536;
}

.chat-item.active {
  background: #1a2b46;
  outline: 1px solid #2b5ec8;
}

.chat-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.chat-item-title {
  font-size: 14px;
  font-weight: bold;
}

.chat-item-last {
  font-size: 12px;
  color: #9fb0ca;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-badge {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ff4da6;
  box-shadow: 0 0 0 3px rgba(255,77,166,0.22);
  flex: 0 0 auto;
}

.chat-panel {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background:
    radial-gradient(circle at top right, rgba(42,93,201,0.08), transparent 28%),
    #0a0f16;
  overflow: hidden;
}

.chat-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8da0bd;
  font-size: 16px;
  width: 100%;
  text-align: center;
  padding: 24px;
}

.chat-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid #182230;
  background: rgba(12, 18, 28, 0.92);
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}

.chat-header-left {
  min-width: 0;
}

.chat-header-right {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.chat-title {
  font-size: 20px;
  font-weight: bold;
}

.chat-sub {
  font-size: 13px;
  color: #8da0bd;
  margin-top: 4px;
}

.typing-line {
  font-size: 12px;
  color: #ff9acb;
  margin-top: 6px;
  min-height: 16px;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.msg-row {
  display: flex;
  margin-bottom: 12px;
}

.mine-row {
  justify-content: flex-end;
}

.msg {
  max-width: 72%;
  background: #121c28;
  border: 1px solid #1b2736;
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.14);
}

.msg.mine {
  background: linear-gradient(180deg, #204ca8, #173d89);
  border-color: #2958bc;
}

.msg-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #b7c4da;
  font-size: 12px;
  margin-bottom: 6px;
}

.msg-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.reply-btn,
.delete-btn {
  border: none;
  background: #223049;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

.delete-btn {
  background: #7b2430;
}

.user-link {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-weight: bold;
}

.reply-preview {
  background: rgba(255,255,255,0.06);
  border-left: 3px solid #60a5fa;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 12px;
}

.reply-author {
  font-weight: bold;
  margin-bottom: 4px;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.42;
}

.msg-status {
  margin-top: 6px;
  font-size: 11px;
  color: #d3e1ff;
  text-align: right;
  opacity: 0.92;
}

.file-link {
  color: #c6ddff;
  text-decoration: none;
}

.reply-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 16px 0 16px;
  background: rgba(255,255,255,0.06);
  border-left: 3px solid #60a5fa;
  border-radius: 12px;
  padding: 10px 12px;
  flex: 0 0 auto;
}

.reply-box-text {
  font-size: 13px;
  color: #d8e2f2;
  min-width: 0;
  word-break: break-word;
}

.reply-close {
  border: none;
  background: #223049;
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 0 16px;
  flex: 0 0 auto;
}

.emoji-btn {
  border: none;
  background: #182232;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 18px;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid #17202b;
  background: rgba(12, 18, 28, 0.96);
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}

.composer-input {
  margin-bottom: 0;
}

.file-line {
  padding: 0 16px 16px 16px;
  font-size: 12px;
  color: #9fb0ca;
  flex: 0 0 auto;
}

.row {
  display: flex;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(16px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #111a26;
  border: 1px solid #1d2a3b;
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}

.modal-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 12px;
}

.profile-line {
  margin-bottom: 10px;
  line-height: 1.45;
  word-break: break-word;
}

.modal-actions {
  margin-top: 14px;
  text-align: right;
}

@media (max-width: 1100px) {
  .sidebar {
    width: 320px;
    min-width: 320px;
  }

  .msg {
    max-width: 82%;
  }
}

@media (max-width: 860px) {
  .app-shell.mobile-chat-open .sidebar {
    display: none;
  }

  .app-shell.mobile-chat-open .chat-panel {
    display: flex;
    width: 100%;
    min-width: 0;
  }

  .app-shell:not(.mobile-chat-open) .chat-panel {
    display: none;
  }

  .mobile-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-shell {
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-right: none;
    border-bottom: none;
    padding:
      calc(10px + env(safe-area-inset-top))
      calc(10px + env(safe-area-inset-right))
      calc(10px + env(safe-area-inset-bottom))
      calc(10px + env(safe-area-inset-left));
    gap: 10px;
    overflow: hidden;
  }

  .sidebar-header {
    align-items: flex-start;
  }

  .brand {
    font-size: 18px;
    line-height: 1.1;
  }

  .brand-sub {
    font-size: 11px;
  }

  .sidebar-actions {
    gap: 6px;
    max-width: 45%;
  }

  .mini-btn {
    font-size: 12px;
    padding: 8px 10px;
  }

  .sidebar-block {
    border-radius: 16px;
    padding: 10px;
  }

  .me-block {
    padding-bottom: 10px;
    flex: 0 0 auto;
  }

  .chats-block {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .chat-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding-bottom: 4px;
  }

  .chat-panel {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .chat-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .chat-header {
    padding:
      calc(10px + env(safe-area-inset-top))
      12px
      10px
      12px;
    gap: 8px;
    flex: 0 0 auto;
  }

  .chat-header-right {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .chat-title {
    font-size: 17px;
  }

  .chat-sub {
    font-size: 12px;
  }

  .typing-line {
    font-size: 11px;
  }

  .messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    padding-bottom: 12px;
  }

  .msg {
    max-width: 94%;
    padding: 10px;
    border-radius: 16px;
  }

  .msg-meta {
    gap: 6px;
    flex-wrap: wrap;
  }

  .msg-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
  }

  .reply-box {
    margin: 8px 12px 0 12px;
    padding: 9px 10px;
    flex: 0 0 auto;
  }

  .emoji-panel {
    padding: 8px 12px 0 12px;
    gap: 6px;
    flex: 0 0 auto;
  }

  .emoji-btn {
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  .composer {
    padding:
      10px
      calc(12px + env(safe-area-inset-right))
      calc(10px + env(safe-area-inset-bottom))
      calc(12px + env(safe-area-inset-left));
    gap: 6px;
    flex: 0 0 auto;
    position: relative;
    bottom: auto;
    z-index: 5;
  }

  .composer-input {
    min-width: 0;
    font-size: 16px;
  }

  .icon-btn,
  .send-btn {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .file-line {
    padding:
      0
      calc(12px + env(safe-area-inset-right))
      calc(10px + env(safe-area-inset-bottom))
      calc(12px + env(safe-area-inset-left));
    flex: 0 0 auto;
  }

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

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

  .input,
  .textarea,
  .btn {
    font-size: 16px;
  }
}

@media (max-width: 520px) {
  .sidebar {
    padding:
      calc(8px + env(safe-area-inset-top))
      calc(8px + env(safe-area-inset-right))
      calc(8px + env(safe-area-inset-bottom))
      calc(8px + env(safe-area-inset-left));
  }

  .sidebar-header {
    gap: 8px;
  }

  .brand {
    font-size: 16px;
  }

  .sidebar-actions {
    max-width: 52%;
  }

  .mini-btn {
    font-size: 11px;
    padding: 7px 8px;
    border-radius: 9px;
  }

  .sidebar-block {
    padding: 9px;
    border-radius: 14px;
  }

  .chat-item {
    padding: 10px;
  }

  .chat-item-title {
    font-size: 13px;
  }

  .chat-item-last {
    font-size: 11px;
  }

  .chat-header {
    padding:
      calc(8px + env(safe-area-inset-top))
      10px
      8px
      10px;
  }

  .chat-title {
    font-size: 16px;
  }

  .messages {
    padding: 10px;
  }

  .msg {
    max-width: 98%;
    font-size: 14px;
  }

  .msg-status {
    font-size: 10px;
  }

  .reply-preview,
  .reply-box-text,
  .profile-line,
  .small-text {
    font-size: 12px;
  }

  .composer {
    padding:
      8px
      calc(10px + env(safe-area-inset-right))
      calc(8px + env(safe-area-inset-bottom))
      calc(10px + env(safe-area-inset-left));
  }

  .icon-btn,
  .send-btn {
    width: 38px;
    min-width: 38px;
    height: 38px;
    font-size: 16px;
  }

  .emoji-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
}
