:root {
  --bg-0: #f4f6f8;
  --bg-1: #e8edf2;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #1a2530;
  --muted: #61758a;
  --border: #d7e0e8;
  --accent: #0f8b8d;
  --accent-strong: #0c6f71;
  --accent-soft: #d8f2f1;
  --danger: #c0392b;
  --shadow: 0 14px 34px rgba(20, 35, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  background: linear-gradient(140deg, var(--bg-0), var(--bg-1));
  min-height: 100vh;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.02em;
}

.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.2rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(460px, 96vw);
  padding: 1.4rem;
}

.auth-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
}

.auth-card p {
  margin: 0 0 1rem;
  color: var(--muted);
}

label {
  display: block;
  margin: 0.7rem 0;
  color: #324457;
}

input,
textarea,
select,
button {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.68rem 0.74rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
}

textarea {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #8cc7c8;
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.14);
}

button,
.btn {
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-weight: 700;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

button:hover,
.btn:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  padding: 0.55rem 0.85rem;
  font-size: 0.92rem;
}

.btn-secondary {
  background: #fff;
  color: var(--accent-strong);
  border-color: #9dd4d5;
}

.btn-secondary:hover {
  background: #eef9f9;
}

.btn-danger {
  background: #a93a2f;
  border-color: #a93a2f;
  color: #fff;
}

.btn-danger:hover {
  background: #8f2f26;
}

button:active,
.btn:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.error {
  color: var(--danger);
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
  gap: 1rem;
  padding: 1rem;
}

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

.sidebar {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  padding: 1rem;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 1rem;
  min-height: 0;
  overflow: hidden;
}

.brand {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.brand .eyebrow {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  font-weight: 800;
}

.side-section h3 {
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.rooms-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.rooms-nav {
  overflow: auto;
  min-height: 0;
}

.room-link {
  display: block;
  padding: 0.5rem 0.58rem;
  border-radius: 9px;
  margin-bottom: 0.3rem;
  color: var(--text);
  font-weight: 600;
}

.room-link:hover {
  background: var(--accent-soft);
  text-decoration: none;
}

.room-link.active {
  background: var(--accent-soft);
  color: #0a5354;
}

#online-list {
  margin: 0;
  padding-left: 1rem;
  color: var(--muted);
  max-height: 170px;
  overflow: auto;
}

.meta-links {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.chat-header h1 {
  font-size: 1.4rem;
}

#load-older {
  margin: 0.75rem 1rem 0;
  width: fit-content;
  background: transparent;
  color: var(--accent-strong);
  border-color: #9cd3d4;
}

#messages {
  padding: 0.9rem 1.1rem;
  overflow: auto;
  min-height: 0;
  max-height: none;
  background: linear-gradient(180deg, #fcfeff, #f5f8fb 72%);
}

.msg {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid #edf2f7;
  border-radius: 9px;
  padding: 0.38rem 0.55rem;
  margin-bottom: 0.28rem;
}

.msg header {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin: 0;
  transition: opacity 0.14s ease, max-height 0.14s ease, margin 0.14s ease;
}

.msg:hover header,
.msg:focus-within header {
  max-height: 2rem;
  opacity: 1;
  margin-bottom: 0.18rem;
}

.msg .msg-body {
  margin: 0;
  line-height: 1.38;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.deleted {
  opacity: 0.75;
  font-style: italic;
}

.msg.mention {
  border-color: #99cdce;
  box-shadow: 0 0 0 2px rgba(15, 139, 141, 0.16);
}

.msg-action {
  width: auto;
  margin-left: 0.15rem;
  padding: 0.12rem 0.34rem;
  font-size: 0.72rem;
  background: transparent;
  border-color: #b7c7d8;
  color: #3d566d;
}

.reactions {
  margin-top: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.react-btn {
  width: auto;
  font-size: 0.8rem;
  padding: 0.25rem 0.46rem;
  background: #eef5fb;
  border-color: #d8e3ef;
  color: #29465e;
}

.react-btn.active {
  border-color: #8ec8c9;
  background: var(--accent-soft);
}

#chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: #fff;
}

#chat-input {
  resize: none;
  min-height: 120px;
  max-height: 50vh;
  line-height: 1.45;
}

pre {
  background: #0f1720;
  color: #f6f8fa;
  padding: 0.95rem;
  border-radius: 10px;
  overflow: auto;
  position: relative;
  border: 1px solid #253242;
  margin: 0.5rem 0;
  white-space: pre;
}

pre code,
code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.9rem;
}

.copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  width: auto;
  padding: 0.16rem 0.42rem;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

blockquote {
  margin: 0.35rem 0;
  padding-left: 0.8rem;
  border-left: 3px solid #a8bdcf;
  color: #475e74;
}

.admin-wrap {
  width: min(1020px, 98vw);
  margin: 1rem auto;
  padding-bottom: 1rem;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}

.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.9rem;
  margin-bottom: 0.9rem;
}

.admin-list {
  display: grid;
  gap: 0.55rem;
}

.admin-item {
  border: 1px solid #e3eaf2;
  border-radius: 12px;
  padding: 0.75rem;
  background: #fcfdff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.admin-item-main strong {
  display: block;
  margin-bottom: 0.2rem;
}

.admin-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid #cde1ef;
  background: #eef6ff;
  color: #37526a;
  margin-right: 0.35rem;
}

.tag.warn {
  border-color: #e9d39a;
  background: #fff5dc;
  color: #6e5314;
}

.tag.off {
  border-color: #e3b6b6;
  background: #fdeaea;
  color: #6c2c2c;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.admin-actions form,
.admin-actions button,
.admin-actions .btn {
  width: auto;
  margin: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.7rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  padding: 0.6rem 0;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }

  #chat-form {
    grid-template-columns: 1fr;
  }

  .msg header {
    max-height: 2rem;
    opacity: 1;
    margin-bottom: 0.18rem;
  }
}
