/*

 */

:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --bg-sunken: #e9e9ee;
  --fg: #111114;
  --fg-muted: #6e6e78;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --accent: #0b84fe;
  --accent-fg: #ffffff;
  --admin: #8e44ec;
  --admin-fg: #ffffff;
  --other: #e9e9eb;
  --other-fg: #111114;
  --system: #fff3c4;
  --system-fg: #5a4300;
  --solved: #1fa463;
  --attention: #ff3b30;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-sunken: #121214;
    --fg: #f2f2f7;
    --fg-muted: #98989f;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --other: #26252a;
    --other-fg: #f2f2f7;
    --system: #3a2f00;
    --system-fg: #ffe28a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-sunken: #121214;
  --fg: #f2f2f7;
  --fg-muted: #98989f;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --other: #26252a;
  --other-fg: #f2f2f7;
  --system: #3a2f00;
  --system-fg: #ffe28a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(180%) blur(20px);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { font-weight: 700; color: var(--fg); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand__dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--admin)); }
.topbar__nav { display: flex; align-items: center; gap: 6px; }
.navlink { color: var(--fg); padding: 6px 10px; border-radius: 10px; background: transparent; border: 0; cursor: pointer; }
.navlink:hover { background: var(--bg-sunken); text-decoration: none; }
.navlink--muted { color: var(--fg-muted); }
.navlink--button { }
.iconbtn {
  border: 0; background: transparent; cursor: pointer; font-size: 16px;
  width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--fg);
}
.iconbtn:hover { background: var(--bg-sunken); }
.theme-icon--dark { display: none; }
:root[data-theme="dark"] .theme-icon--dark { display: inline; }
:root[data-theme="dark"] .theme-icon--light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon--dark { display: inline; }
  :root:not([data-theme="light"]) .theme-icon--light { display: none; }
}

.pill {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-sunken); color: var(--fg-muted); white-space: nowrap;
}
.pill--admin { background: var(--admin); color: var(--admin-fg); }
.pill--solved { background: var(--solved); color: #fff; }
.pill--attention { background: var(--attention); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
.pill--locked { }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- flash ---------- */
.flash-wrap { position: fixed; top: 64px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 30; pointer-events: none; }
.flash { padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); background: var(--bg-elev); border: 1px solid var(--border); transition: opacity 0.4s; }
.flash--alert { border-color: var(--attention); }
.flash--hide { opacity: 0; }

/* ---------- cards / forms ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow);
}
.card--center { max-width: 420px; width: calc(100% - 32px); margin: 8vh auto; }
.card__title { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.02em; }
.card__subtitle { margin: 0 0 20px; color: var(--fg-muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 11px; font-weight: 700; color: var(--fg-muted); margin: 0 0 4px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.field input, .select, .broadcast__input {
  font: inherit; font-weight: 400; font-size: 15px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-sunken); color: var(--fg); outline: none;
}
.field input:focus, .select:focus, .broadcast__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11, 132, 254, 0.2); }
.hint { font-weight: 500; color: var(--admin); }
.form-errors { color: var(--attention); font-size: 13px; }
.btn {
  font-weight: 600; border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: var(--bg-sunken); color: var(--fg);
}
.btn--primary { background: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--block { width: 100%; }
.muted { color: var(--fg-muted); }

/* ---------- lobby ---------- */
.lobby { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; max-width: 980px; width: calc(100% - 32px); margin: 24px auto; align-items: start; }
@media (max-width: 760px) { .lobby { grid-template-columns: 1fr; } }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.room-card__link {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-radius: 14px; background: var(--bg-sunken); color: var(--fg); font-weight: 600;
  border: 1px solid transparent; transition: transform 0.1s, border-color 0.1s;
}
.room-card__link:hover { text-decoration: none; transform: translateY(-1px); border-color: var(--accent); }
.room-card--solved .room-card__link { border-color: var(--solved); }
.room-card__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chat ---------- */
.body--chat .main { height: calc(100vh - 55px); }
.room-page { flex: 1; display: flex; min-height: 0; max-width: 900px; width: 100%; margin: 0 auto; }
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; flex: 1; background: var(--bg-elev); position: relative; }
.room-page .chat { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.chat__header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg-elev);
}
.chat__title { display: flex; align-items: center; gap: 10px; min-width: 0; overflow: hidden; }
.chat__actions { flex-shrink: 0; }
.chat__name { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__actions { display: flex; gap: 2px; }
.room-status { display: inline-flex; gap: 6px; }
/* members never see the attention chip */
body:not(.body--dashboard) .admin-only { display: none; }

.rules-drawer { padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--system); color: var(--system-fg); font-size: 13px; }
.rules { margin: 10px 0 18px; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.rules--small { margin: 6px 0 0; gap: 4px; }

.chat__scroll { flex: 1; overflow-y: auto; padding: 14px 14px 6px; scroll-behavior: smooth; overscroll-behavior: contain; }
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.message { display: flex; flex-direction: column; align-items: flex-start; max-width: 78%; margin-top: 8px; animation: pop 0.18s ease-out; }
@keyframes pop { from { transform: translateY(6px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.message__sender { font-size: 11px; color: var(--fg-muted); margin: 0 0 2px 10px; }
.message__role { background: var(--admin); color: var(--admin-fg); font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 6px; margin-left: 3px; vertical-align: middle; }
.message__bubble {
  background: var(--other); color: var(--other-fg); padding: 8px 13px; border-radius: var(--radius); border-bottom-left-radius: 5px;
  overflow-wrap: anywhere; position: relative;
}
.message__bubble p { margin: 0; }
.message__bubble p + p { margin-top: 6px; }
.message__time { font-size: 10px; color: var(--fg-muted); margin: 2px 10px 0; opacity: 0; transition: opacity 0.15s; }
.message:hover .message__time { opacity: 1; }

.message--admin .message__bubble { background: var(--admin); color: var(--admin-fg); }
.message--broadcast .message__bubble { background: linear-gradient(135deg, var(--admin), #c43ad6); }
.message--system { align-self: center; align-items: center; max-width: 90%; }
.message--system .message__bubble { background: var(--system); color: var(--system-fg); border-radius: 12px; text-align: center; font-weight: 600; }

.message--mine { align-self: flex-end; align-items: flex-end; }
.message--mine .message__sender { margin: 0 10px 2px 0; }
.message--mine .message__bubble { border-bottom-left-radius: var(--radius); border-bottom-right-radius: 5px; background: var(--accent); color: var(--accent-fg); }
.message--mine.message--admin .message__bubble { background: var(--admin); color: var(--admin-fg); }
.message--mine.message--broadcast .message__bubble { background: linear-gradient(135deg, var(--admin), #c43ad6); }

/* typing indicator */
.typing { display: flex; flex-direction: column; gap: 4px; min-height: 8px; padding: 6px 0 2px; }
.typer { display: flex; flex-direction: column; align-items: flex-start; animation: pop 0.18s ease-out; }
.typer__name { font-size: 11px; color: var(--fg-muted); margin: 0 0 2px 10px; }
.dots { background: var(--other); border-radius: var(--radius); border-bottom-left-radius: 5px; padding: 10px 14px; display: inline-flex; gap: 4px; }
.dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-muted); animation: bounce 1.2s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
.typer--admin .dots { background: var(--admin); }
.typer--admin .dots span { background: rgba(255, 255, 255, 0.85); }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--bg-elev); }
.composer__input {
  flex: 1; resize: none; font: inherit; font-size: 15px; padding: 9px 14px; border-radius: 20px; max-height: 140px;
  border: 1px solid var(--border); background: var(--bg-sunken); color: var(--fg); outline: none; line-height: 1.35;
}
.composer__input:focus { border-color: var(--accent); }
.composer__send {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.body--dashboard .composer__send { background: var(--admin); }
.composer__send:hover { filter: brightness(1.08); }
.effects { position: absolute; inset: 0; pointer-events: none; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(4px); }
.modal__panel { position: relative; background: var(--bg-elev); border-radius: 20px; padding: 28px; max-width: 540px; width: calc(100% - 32px); box-shadow: var(--shadow); animation: pop 0.2s ease-out; }

/* ---------- admin dashboard ---------- */
.body--dashboard .main { height: calc(100vh - 55px); }
.dashboard { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.dashboard__toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 16px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
}
.toolbar__field { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.select { padding: 7px 10px; min-width: 180px; }
.toolbar__pager { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--fg-muted); }
.broadcast { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 280px; }
.broadcast__label { font-weight: 700; font-size: 13px; color: var(--admin); white-space: nowrap; }
.broadcast__input { flex: 1; padding: 8px 12px; }

.panes {
  flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); grid-auto-rows: minmax(320px, 1fr); overflow-y: auto;
}
.pane { display: flex; min-height: 0; min-width: 0; border: 2px solid var(--border); border-radius: 16px; overflow: hidden; background: var(--bg-elev); transition: border-color 0.2s, box-shadow 0.2s; }
.pane .chat { border-radius: 14px; }
.pane .chat__name { font-size: 14px; }
.pane .chat__header { padding: 8px 10px; }
.pane .message { max-width: 88%; }
.pane:has(.room-status[data-attention="true"]) { border-color: var(--attention); box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.25); }
.pane:has(.room-status[data-solved="true"]) { border-color: var(--solved); }
.pane:has(.room-status[data-attention="true"]) .chat__header { background: color-mix(in srgb, var(--attention) 12%, var(--bg-elev)); }
.pane--max { position: fixed; inset: 55px 0 0 0; z-index: 40; border-radius: 0; border-width: 0; }
.pane--max .chat { border-radius: 0; }
.panes__empty { padding: 24px; text-align: center; }

@media (max-width: 640px) {
  .topbar { padding: 8px 10px; }
  .navlink { padding: 6px 7px; }
  .message { max-width: 88%; }
  .panes { grid-template-columns: 1fr; }
}

.room-list:has(li) + #no_rooms_hint { display: none; }

.message__bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.message--member:not(.message--mine) .message__bubble a { color: var(--accent); }

.field__row { display: flex; gap: 6px; }
.field__row input { flex: 1; min-width: 0; }
.btn--small { padding: 6px 10px; font-size: 13px; }
.iconbtn--danger:hover { background: color-mix(in srgb, var(--attention) 15%, transparent); }
.chat--deleted { justify-content: center; align-items: center; }

/* Fallback when the admin leaves a room and it comes back as a deleted notice */
.chat--deleted .card { margin: 0; }

.modal__panel--narrow { max-width: 440px; text-align: center; }
.modal__emoji { font-size: 40px; line-height: 1; margin-bottom: 10px; }
.modal__panel--narrow .field { text-align: left; margin-bottom: 16px; }
.modal__panel--narrow .field input { width: 100%; }
.modal__actions { display: flex; gap: 10px; justify-content: center; }
.modal__actions .btn { min-width: 120px; }
.btn--danger { background: var(--attention); color: #fff; }
.shake { animation: shake 0.35s; border-color: var(--attention) !important; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.hint--muted { color: var(--fg-muted); font-weight: 500; }
