:root {
  --bg: #0f172a;
  --card: #111827;
  --muted: #94a3b8;
  --text: #f8fafc;
  --accent: #22d3ee;
  --danger: #f87171;
  --bubble-self: #155e75;
  --bubble-other: #1e293b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #020617;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-actions form { margin: 0; }
.container { padding: 16px; }
.card {
  background: var(--card);
  border-radius: 10px;
  padding: 14px;
}
.auth-card { max-width: 420px; margin: 20px auto; }
form { display: grid; gap: 10px; }
input, textarea, button {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: var(--text);
}
button {
  cursor: pointer;
  background: #155e75;
}
a { color: var(--accent); }
.error { color: var(--danger); }

.is-hidden { display: none !important; }

.chat-app {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 920px;
  margin: 0 auto;
}
.chat-toolbar-wrap {
  position: relative;
  z-index: 20;
}
.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.toolbar-btn {
  width: auto;
  min-width: 88px;
  padding: 8px 12px;
  font-size: 14px;
}
.toolbar-btn--small {
  min-width: unset;
  padding: 6px 10px;
  font-size: 13px;
}
.toolbar-btn--rooms {
  margin-left: auto;
}
.chat-room-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  z-index: 25;
  min-width: min(100%, 280px);
  max-width: 100%;
}
.room-popover-inner {
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  max-height: min(50vh, 320px);
  overflow: auto;
}
.list--popover li {
  padding: 8px 10px;
  border: 1px solid #1f2937;
  margin-bottom: 6px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.list--popover li.room-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.room-list-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-hint-btn {
  width: auto;
  min-width: 32px;
  padding: 4px 8px;
  font-size: 12px;
  flex-shrink: 0;
  background: #334155;
}
.list--popover li.active {
  border-color: var(--accent);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.drawer:not(.is-hidden) {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
}
.drawer-panel {
  position: relative;
  width: min(100%, 360px);
  max-width: 100%;
  height: 100%;
  background: #0b1220;
  border-right: 1px solid #1f2937;
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25);
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer:not(.is-hidden) .drawer-panel {
  transform: translateX(0);
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #1f2937;
  font-weight: 600;
}
.drawer-body {
  padding: 10px 12px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.menu-details {
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 0 10px 8px;
  background: #111827;
}
.menu-details summary {
  cursor: pointer;
  padding: 10px 0;
  font-weight: 600;
  list-style: none;
}
.menu-details summary::-webkit-details-marker { display: none; }
.menu-details-body {
  display: grid;
  gap: 8px;
  padding-bottom: 4px;
}
.menu-block {
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: #111827;
}
.menu-block-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.file-label-inline {
  display: block;
  font-size: 14px;
  color: var(--muted);
}
.file-label-inline input[type="file"] {
  margin-top: 6px;
}
.status-pill {
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: #cbd5e1;
  background: #0b1220;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: min(58vh, 520px);
  overflow: auto;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 10px 8px;
  background: #0b1220;
  margin-bottom: 10px;
}
.msg {
  max-width: min(82%, 380px);
  padding: 8px 10px;
  border-radius: 12px;
  word-break: break-word;
}
.msg--self {
  align-self: flex-end;
  background: var(--bubble-self);
  border-bottom-right-radius: 4px;
}
.msg--other {
  align-self: flex-start;
  background: var(--bubble-other);
  border-bottom-left-radius: 4px;
}
.msg .meta {
  font-size: 11px;
  color: rgba(248, 250, 252, 0.72);
  margin-bottom: 4px;
  line-height: 1.25;
}
.msg--self .meta {
  text-align: right;
}
.msg p {
  margin: 0;
  font-size: 15px;
}
.msg-img {
  display: block;
  max-width: 100%;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 4px;
  cursor: zoom-in;
}
.msg--self .msg-img {
  margin-left: auto;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 6, 23, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.image-lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
.image-lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
  border-radius: 8px;
  background: #1e293b;
}

.send-box { display: grid; gap: 8px; }
.emoji-row { display: flex; gap: 6px; }
.emoji-btn { max-width: 54px; }
.file-label { display: block; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.admin-row {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 8px;
}
@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
}
