:root {
  color-scheme: light;
  --bg: #eef2f0;
  --panel: #ffffff;
  --panel-soft: #f7faf8;
  --ink: #17201c;
  --muted: #68756f;
  --line: #dbe4df;
  --accent: #18b66a;
  --accent-dark: #0c8a4c;
  --accent-soft: #dff8eb;
  --danger: #d94d4d;
  --shadow: 0 18px 50px rgba(30, 45, 38, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

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

button {
  cursor: pointer;
}

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

code {
  border-radius: 4px;
  background: #edf2ef;
  padding: 0.08rem 0.3rem;
}

.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-block {
  margin-bottom: 22px;
}

.brand-kicker {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-block h1,
.side-header h1 {
  margin: 0;
  font-size: 1.7rem;
  line-height: 1.2;
}

.brand-block p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 18px;
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 5px;
}

.auth-tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  font-weight: 700;
}

.auth-tab.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 12px rgba(30, 45, 38, 0.08);
}

.auth-form,
.settings-form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: none;
  min-height: 44px;
  max-height: 140px;
  padding: 12px 13px;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 182, 106, 0.16);
}

.primary-button,
.send-button,
.ghost-button,
.danger-button,
.file-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 15px;
  font-weight: 800;
}

.primary-button,
.send-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover,
.send-button:hover {
  background: var(--accent-dark);
}

.primary-button.small {
  min-height: 38px;
}

.ghost-button,
.file-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover,
.file-button:hover {
  background: var(--panel-soft);
}

.danger-button {
  border-color: #ffd1d1;
  background: #fff4f4;
  color: var(--danger);
}

.compact {
  min-height: 30px;
  padding: 0 9px;
  font-size: 0.78rem;
}

.form-message {
  min-height: 1.3em;
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
  line-height: 1.5;
}

.form-message.is-ok {
  color: var(--accent-dark);
}

.settings-preview {
  margin: -3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.settings-preview strong {
  color: var(--ink);
}

.is-hidden {
  display: none;
}

.chat-app {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: #fbfdfc;
  padding: 20px;
  overflow: auto;
}

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

.role-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.side-section {
  display: grid;
  gap: 12px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.side-section h2 {
  margin: 0;
  font-size: 1rem;
}

.select-label {
  gap: 5px;
}

.user-list {
  display: grid;
  gap: 8px;
}

.user-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
}

.user-card-main {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.user-card-main strong {
  font-size: 0.95rem;
}

.user-card-main span,
.user-card-main small,
.muted-line,
.profile-box p {
  color: var(--muted);
}

.user-card-main span,
.user-card-main small {
  overflow-wrap: anywhere;
}

.user-card-actions {
  display: flex;
  gap: 7px;
}

details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.settings-form {
  margin-top: 12px;
}

.profile-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.profile-box h2,
.profile-box p {
  margin: 0;
}

.logout-form {
  margin-top: auto;
}

.chat-shell {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #edf4f0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  padding: 14px 22px;
}

.chat-header h2,
.chat-subtitle {
  margin: 0;
}

.chat-header h2 {
  font-size: 1.2rem;
}

.chat-subtitle {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(24, 182, 106, 0.14);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
}

.message-row {
  display: flex;
  margin: 0 0 12px;
}

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

.message-bubble {
  width: fit-content;
  max-width: min(680px, 78%);
  border: 1px solid rgba(23, 32, 28, 0.06);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  box-shadow: 0 5px 18px rgba(30, 45, 38, 0.08);
}

.message-row.is-mine .message-bubble {
  background: #c9f4dc;
}

.message-row.is-admin:not(.is-mine) .message-bubble {
  border-color: rgba(24, 182, 106, 0.24);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

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

.message-author,
.message-meta time {
  overflow-wrap: anywhere;
}

.message-delete-button {
  min-height: 24px;
  border: 1px solid rgba(217, 77, 77, 0.22);
  border-radius: 6px;
  background: rgba(255, 244, 244, 0.82);
  color: var(--danger);
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 800;
}

.message-delete-button:hover {
  background: #ffe8e8;
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}

.message-image-link {
  display: block;
  margin-top: 8px;
}

.message-image-link img {
  display: block;
  width: min(320px, 100%);
  max-height: 420px;
  border-radius: 6px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.5);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  font-weight: 700;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 14px 18px;
}

.composer-note {
  grid-column: 1 / -1;
  min-height: 1.2em;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.composer-note.is-error {
  color: var(--danger);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.send-button {
  min-width: 74px;
}

.setup-error-body {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
}

.setup-error {
  width: min(680px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 24px;
  box-shadow: var(--shadow);
}

.setup-error h1 {
  margin: 0 0 12px;
  font-size: 1.3rem;
}

.setup-error pre {
  overflow: auto;
  border-radius: 6px;
  background: #17201c;
  color: #fff;
  padding: 14px;
}

@media (max-width: 860px) {
  .chat-app {
    grid-template-columns: 1fr;
  }

  .side-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-shell {
    min-height: calc(100vh - 260px);
  }

  .user-list {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .composer {
    grid-template-columns: 1fr auto;
  }

  .file-button {
    grid-column: 1;
    width: fit-content;
  }

  .send-button {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: stretch;
  }
}

@media (max-width: 560px) {
  .auth-shell {
    padding: 14px;
  }

  .auth-panel {
    padding: 20px;
  }

  .side-panel,
  .messages,
  .chat-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .message-bubble {
    max-width: 88%;
  }

  .composer {
    padding: 12px;
  }
}
