:root {
  color-scheme: dark;
  --bg: #0c0c0c;
  --surface: #141414;
  --border: #252525;
  --text: #e8e4dc;
  --muted: #5a5650;
  --accent: #c9a84c;
  --accent-dim: #7a6028;
  --self-bg: #1a1710;
  --ok: #8eb87a;
  --warn: #c06060;
  --font: Consolas, "Cascadia Code", Menlo, "Courier New", monospace;
  --radius: 6px;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 7px 14px;
  letter-spacing: 0.06em;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

button:hover {
  border-color: var(--accent);
  background: var(--self-bg);
}

button:disabled {
  cursor: wait;
  opacity: 0.45;
}

.secondary {
  border-color: var(--border);
  color: var(--muted);
}

.secondary:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: transparent;
}

.login-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 320px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-panel h1,
.topbar h1 {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: lowercase;
}

.login-panel p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.05em;
}

.login-form {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.login-form label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.login-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.login-form input {
  padding: 8px 10px;
}

.login-form input:focus,
.composer textarea:focus {
  border-color: var(--accent-dim);
}

.error {
  margin-top: 10px;
  color: var(--warn);
  font-size: 11px;
  word-break: break-word;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
}

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

.dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.dot.online {
  background: var(--accent);
}

.messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-thumb {
  border-radius: 2px;
  background: var(--border);
}

.msg {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 0 14px;
  border-radius: var(--radius);
  padding: 3px 0;
  transition: background 0.1s;
}

.msg:hover {
  background: var(--surface);
}

.msg.self {
  background: var(--self-bg);
}

.msg-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 3px 0 3px 10px;
}

.msg-user {
  max-width: 88px;
  overflow: hidden;
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg.self .msg-user {
  color: var(--ok);
}

.msg-time {
  color: var(--muted);
  font-size: 10px;
}

.msg-body {
  min-width: 0;
  padding: 3px 10px 3px 0;
  word-break: break-word;
}

.msg-text {
  margin: 0;
  white-space: pre-wrap;
}

.msg-text strong {
  color: #fff6dc;
  font-weight: 700;
}

.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.message-images img {
  display: block;
  max-width: 280px;
  max-height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  object-fit: contain;
}

.empty-state,
.status {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-align: center;
}

.empty-state {
  margin: auto 0;
}

.status {
  padding: 8px 0;
}

.composer {
  display: flex;
  flex-shrink: 0;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 14px 20px;
}

.composer-main {
  display: grid;
  flex: 1;
  gap: 8px;
  min-width: 0;
}

.composer textarea {
  min-height: 36px;
  max-height: 140px;
  resize: vertical;
  padding: 8px 10px;
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.icon-btn {
  display: flex;
  width: 36px;
  min-width: 36px;
  align-items: center;
  justify-content: center;
  border-color: var(--border);
  color: var(--muted);
  padding: 0;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-btn:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: transparent;
}

.image-preview {
  display: flex;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px 8px;
  color: var(--muted);
  font-size: 11px;
}

.image-preview[hidden] {
  display: none;
}

.image-preview img {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  object-fit: cover;
}

.image-preview span {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview button {
  min-height: 24px;
  padding: 0 7px;
  border-color: var(--border);
  color: var(--muted);
}

#send-button {
  width: 36px;
  padding: 0;
  font-size: 16px;
}

@media (max-width: 640px) {
  body {
    font-size: 12px;
  }

  .topbar,
  .composer,
  .messages {
    padding-right: 14px;
    padding-left: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .msg {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 0 10px;
  }

  .msg-user {
    max-width: 62px;
  }

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

  .composer textarea {
    resize: none;
  }

  .composer-actions {
    gap: 6px;
  }

  .secondary {
    padding-right: 10px;
    padding-left: 10px;
  }

  .composer-actions {
    align-self: end;
  }
}
