:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --text: #17212b;
  --muted: #6e7b8b;
  --border: #d9e1ec;
  --primary: #2aabee;
  --primary-hover: #1995d3;
  --mine: #d9fdd3;
  --theirs: #ffffff;
  --danger: #ffdfdf;
  --danger-text: #8f1f1f;
  --shadow: 0 12px 32px rgba(20, 31, 56, 0.12);
}

html[data-theme="dark"] {
  --bg: #0f141a;
  --surface: #18222d;
  --surface-2: #111b24;
  --text: #e9edef;
  --muted: #9fb0c0;
  --border: #263340;
  --primary: #2aabee;
  --primary-hover: #40bfff;
  --mine: #005c4b;
  --theirs: #202c33;
  --danger: #422228;
  --danger-text: #ffb8c3;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  transition: background 0.2s ease, color 0.2s ease;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.theme-toggle-wrap {
  display: flex;
  justify-content: flex-end;
  padding: 20px 20px 0;
}

.theme-toggle,
.ghost-btn,
.primary-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: 0.2s ease;
}

.theme-toggle,
.ghost-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.theme-toggle:hover,
.ghost-btn:hover {
  background: var(--surface-2);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.login-shell {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card__header h1 {
  margin: 0 0 8px;
  font-size: 32px;
}

.login-card__header p {
  margin: 0 0 20px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

.field input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
}

.field input:focus,
.composer textarea:focus {
  border-color: var(--primary);
}

.alert-error {
  background: var(--danger);
  color: var(--danger-text);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.chat-page {
  min-height: 100vh;
}

.app-shell {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 20, 26, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

html[data-theme="light"] .topbar {
  background: rgba(244, 246, 251, 0.88);
}

.topbar-title {
  font-size: 22px;
  font-weight: 700;
}

.topbar-subtitle {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 82px);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 140px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-row.theirs {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(78%, 640px);
  padding: 10px 14px 9px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}

.message-row.mine .message-bubble {
  background: var(--mine);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.message-row.theirs .message-bubble {
  background: var(--theirs);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.message-author {
  font-size: 12px;
  margin-bottom: 6px;
  opacity: 0.85;
  font-weight: 700;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 15px;
}

.message-time {
  margin-top: 8px;
  font-size: 11px;
  opacity: 0.7;
  text-align: right;
}

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px 16px 18px;
  border-top: 1px solid var(--border);
  background: rgba(15, 20, 26, 0.92);
  backdrop-filter: blur(10px);
}

html[data-theme="light"] .composer {
  background: rgba(244, 246, 251, 0.92);
}

.composer textarea {
  min-height: 56px;
  max-height: 180px;
  resize: none;
}

.composer-btn {
  min-width: 130px;
  align-self: end;
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-right {
    justify-content: space-between;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-btn {
    width: 100%;
  }

  .message-bubble {
    max-width: 92%;
  }
}