:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171c21;
  --panel-strong: #20272d;
  --surface: #11161a;
  --line: #303941;
  --text: #f4f1e8;
  --muted: #a8b0b4;
  --accent: #56d0a7;
  --danger: #f06f5f;
  --bubble-in: #222a30;
  --bubble-out: #dbeee6;
  --bubble-out-text: #14211d;
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.22);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #08130f;
  cursor: pointer;
  font-weight: 750;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1316;
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(86, 208, 167, 0.16);
}

.auth-view,
.app-shell {
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(86, 208, 167, 0.12), transparent 22rem),
    linear-gradient(145deg, #101418 0%, #15191d 58%, #0f1415 100%);
}

.auth-view {
  display: grid;
  align-items: center;
  padding: 18px;
}

.auth-card {
  display: grid;
  gap: 22px;
  width: min(100%, 440px);
  margin: 0 auto;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(23, 28, 33, 0.96);
  box-shadow: var(--shadow);
}

.auth-card h1,
.app-header-copy h1,
.chat-header h2 {
  margin: 0;
  font-size: 1.32rem;
  line-height: 1.12;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1316;
}

.auth-tabs button {
  min-height: 38px;
  background: transparent;
  color: var(--muted);
}

.auth-tabs button.active {
  background: var(--panel-strong);
  color: var(--text);
}

.auth-form,
.profile-form {
  display: grid;
  gap: 10px;
}

.auth-form label,
.profile-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.auth-form input,
.profile-form input,
.composer textarea {
  min-height: 44px;
  padding: 0 12px;
}

.status-text {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.app-header,
.tab-view,
.chat-pane {
  min-width: 0;
  min-height: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 62px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 20, 24, 0.94);
  backdrop-filter: blur(16px);
}

.app-header-copy {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.app-header-copy h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header-meta {
  min-height: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.header-action {
  display: grid;
  margin-left: auto;
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--accent);
}

.app-header-back {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  border-radius: 8px;
  font-size: 1.55rem;
}

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

.tab-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  padding: 14px 14px 88px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(23, 28, 33, 0.94);
}

.chats-view,
.contacts-view {
  grid-template-rows: minmax(0, 1fr);
  align-content: stretch;
}

.settings-view {
  grid-template-rows: auto;
  align-content: start;
}

.chat-open .app-header,
.chat-open .tab-view,
.chat-open .bottom-bar {
  display: none;
}

.chat-pane {
  display: none;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(23, 28, 33, 0.9);
}

.chat-open .chat-pane {
  display: grid;
  position: fixed;
  inset: 0;
  z-index: 20;
}

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

.chat-header {
  position: sticky;
  top: 0;
  z-index: 3;
  min-height: 70px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 20, 24, 0.94);
  backdrop-filter: blur(16px);
}

.icon-button {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  place-items: center;
  padding: 0;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 1.2rem;
}

.icon-button svg,
.header-action svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.secondary-button {
  min-width: 84px;
  padding: 0 12px;
  background: var(--panel-strong);
  color: var(--text);
}

.profile-panel {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(32, 39, 45, 0.62);
}

.settings-main,
.settings-detail {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
}

.settings-profile-card,
.settings-group,
.settings-placeholder {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(32, 39, 45, 0.62);
}

.settings-profile-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 82px;
  padding: 12px;
  color: var(--text);
  text-align: left;
}

.settings-profile-avatar,
.settings-row-icon,
.settings-placeholder-icon {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--accent);
  font-weight: 800;
}

.settings-profile-avatar {
  width: 58px;
  height: 58px;
  font-size: 1.25rem;
}

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

.settings-profile-copy,
.settings-row-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.settings-profile-copy strong,
.settings-row-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.2;
}

.settings-profile-copy span,
.settings-row-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 540;
}

.settings-group {
  display: grid;
  overflow: hidden;
}

.settings-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 62px;
  padding: 10px 12px;
  border-radius: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-profile-card:hover,
.settings-row:hover {
  background: rgba(86, 208, 167, 0.08);
}

.settings-row-icon {
  width: 40px;
  height: 40px;
}

.settings-row-icon svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.settings-chevron {
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
}

.settings-placeholder {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 26px 18px;
  color: var(--muted);
  text-align: center;
}

.settings-placeholder-icon {
  width: 58px;
  height: 58px;
  font-size: 1.1rem;
}

.settings-placeholder h2,
.settings-placeholder p {
  margin: 0;
}

.settings-placeholder h2 {
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.2;
}

.settings-placeholder p {
  max-width: 22rem;
  line-height: 1.45;
}

.avatar-button,
.contact-avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--accent);
}

.avatar-button {
  width: 68px;
  height: 68px;
  min-height: 68px;
  padding: 0;
  font-size: 1.35rem;
}

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

.profile-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.profile-form label {
  grid-column: 1 / -1;
}

.profile-form p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.profile-form button {
  padding: 0 14px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.composer button {
  padding: 0 14px;
}

.chat-list,
.contact-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-button,
.contact-button {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 66px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(17, 22, 26, 0.82);
  color: var(--text);
  text-align: left;
}

.chat-button.active,
.chat-button:hover,
.contact-button.active,
.contact-button:hover:not(:disabled) {
  border-color: rgba(86, 208, 167, 0.42);
  background: rgba(86, 208, 167, 0.08);
}

.chat-button time {
  align-self: start;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}

.contact-avatar {
  width: 46px;
  height: 46px;
  font-weight: 800;
}

.contact-copy {
  min-width: 0;
}

.contact-copy strong,
.contact-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-copy span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.empty-panel {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  min-height: 48dvh;
  color: var(--muted);
  text-align: center;
}

.empty-panel p {
  max-width: 18rem;
  margin: 0;
  line-height: 1.5;
}

.empty-panel button {
  padding: 0 16px;
}

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

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

.message-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.empty-state {
  margin: auto;
  max-width: 25rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.message {
  max-width: 88%;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--bubble-in);
  color: var(--text);
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.message.mine {
  align-self: flex-end;
  background: var(--bubble-out);
  color: var(--bubble-out-text);
}

.message.failed {
  border: 1px solid rgba(240, 111, 95, 0.5);
}

.message strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.72rem;
  opacity: 0.72;
}

.message small {
  display: block;
  margin-top: 6px;
  color: currentColor;
  opacity: 0.62;
  font-size: 0.7rem;
}

.composer {
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(16, 20, 24, 0.92);
}

.composer textarea {
  max-height: 144px;
  min-height: 44px;
  padding: 11px 12px;
  line-height: 1.35;
  resize: none;
  overflow-y: auto;
}

.composer textarea:disabled + button {
  opacity: 0.52;
}

.bottom-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(16, 20, 24, 0.96);
  backdrop-filter: blur(16px);
}

.bottom-tab {
  min-height: 46px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
}

.bottom-tab.active {
  background: var(--panel-strong);
  color: var(--text);
}

.logout-button {
  width: 100%;
  margin-top: 6px;
  background: rgba(240, 111, 95, 0.13);
  color: #ffd4cd;
}

.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 (min-width: 860px) {
  body {
    background:
      radial-gradient(circle at top left, rgba(86, 208, 167, 0.14), transparent 34rem),
      linear-gradient(135deg, #101418 0%, #15191d 48%, #0f1415 100%);
  }

  .app-shell {
    width: min(100%, 960px);
    margin: 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .tab-view {
    padding: 20px 20px 92px;
  }

  .chat-open .chat-pane {
    inset: 20px;
    width: min(calc(100vw - 40px), 960px);
    margin: 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .chat-header {
    padding: 18px;
  }

  .auth-card h1,
  .app-header-copy h1,
  .chat-header h2 {
    font-size: 1.38rem;
  }

  .profile-panel,
  .message-list {
    padding: 18px;
  }

  .message {
    max-width: min(72%, 42rem);
    padding: 10px 12px;
  }

  .composer {
    padding: 14px;
  }
}
