:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --text: #1a1c20;
  --text-dim: #6b7280;
  --border: #e3e5e9;
  --accent: #4f6df5;
  --accent-text: #ffffff;
  --bubble-me: #4f6df5;
  --bubble-me-text: #ffffff;
  --bubble-them: #eef0f4;
  --bubble-them-text: #1a1c20;
  --danger: #e5484d;
  --online: #2fb35c;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 20, 30, 0.08);
  font-size: 16px;
}

[data-theme='dark'] {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel-2: #22262f;
  --text: #eef0f4;
  --text-dim: #9aa1ad;
  --border: #2b2f3a;
  --accent: #6d87ff;
  --accent-text: #0d0e12;
  --bubble-me: #6d87ff;
  --bubble-me-text: #0d0e12;
  --bubble-them: #262b35;
  --bubble-them-text: #eef0f4;
  --danger: #ff6b6f;
  --online: #46d17a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

a { color: var(--accent); }

/* ---------- login ---------- */

.center-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

.card p.sub {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 14px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-dim);
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.error-msg {
  color: var(--danger);
  font-size: 13.5px;
  margin: -6px 0 16px;
  min-height: 1em;
}

/* ---------- chat layout ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar .title {
  font-weight: 700;
  font-size: 16px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.2s;
}

.status-dot.online { background: var(--online); }
.status-dot.offline { background: var(--danger); }

.topbar .presence {
  font-size: 12.5px;
  color: var(--text-dim);
}

.topbar .spacer { flex: 1; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.readonly-banner {
  background: #fff3cd;
  color: #7a5b00;
  font-size: 13px;
  padding: 8px 16px;
  text-align: center;
  display: none;
}

[data-theme='dark'] .readonly-banner {
  background: #3a2f00;
  color: #f5cf5a;
}

.readonly-banner.show { display: block; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day-sep {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin: 18px 0 10px;
  font-weight: 600;
}

.row {
  display: flex;
  margin: 3px 0;
  max-width: 100%;
  position: relative;
}

.row.me { justify-content: flex-end; }
.row.them { justify-content: flex-start; }

.bubble-wrap {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

.row.me .bubble-wrap { align-items: flex-end; }
.row.them .bubble-wrap { align-items: flex-start; }

.author {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 8px 4px 2px;
  font-weight: 600;
}

.bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}

.row.me .bubble {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  border-bottom-right-radius: 4px;
}

.row.them .bubble {
  background: var(--bubble-them);
  color: var(--bubble-them-text);
  border-bottom-left-radius: 4px;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 4px 0;
  font-size: 11px;
  color: var(--text-dim);
}

.reactions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin: 3px 4px 0;
}

.reaction-pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  display: flex;
  gap: 3px;
  align-items: center;
}

.reaction-pill.mine {
  border-color: var(--accent);
}

.msg-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}

.row:hover .msg-actions { opacity: 1; }

.msg-actions button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 6px;
}

.msg-actions button:hover { background: var(--panel-2); color: var(--text); }

.emoji-picker {
  position: absolute;
  top: -34px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 4px 6px;
  display: none;
  gap: 2px;
  z-index: 5;
}

.row.me .emoji-picker { right: 0; }
.row.them .emoji-picker { left: 0; }

.emoji-picker.show { display: flex; }

.emoji-picker button {
  border: none;
  background: transparent;
  font-size: 17px;
  padding: 3px 4px;
  border-radius: 6px;
}

.emoji-picker button:hover { background: var(--panel-2); }

.typing-indicator {
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 2px 18px 6px;
  min-height: 18px;
}

.composer-wrap {
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.reply-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.reply-bar.show { display: flex; }

.reply-bar-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.reply-bar-user {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.reply-bar-text {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  flex-shrink: 0;
}

.reply-quote {
  border-left: 3px solid var(--accent);
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 5px;
  cursor: pointer;
  max-width: 100%;
}

[data-theme='dark'] .reply-quote {
  background: rgba(255, 255, 255, 0.08);
}

.row.me .reply-quote {
  border-left-color: var(--bubble-me-text);
  background: rgba(255, 255, 255, 0.18);
}

.rq-user {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.row.me .rq-user { color: var(--bubble-me-text); }

.rq-text {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.row.me .rq-text { color: rgba(255, 255, 255, 0.75); }

.bubble-text { white-space: pre-wrap; word-break: break-word; }

.row.flash .bubble {
  box-shadow: 0 0 0 3px var(--accent);
  transition: box-shadow 1.1s ease;
}

.ticks {
  font-size: 12px;
  letter-spacing: -1px;
}

.ticks.sent { color: var(--text-dim); opacity: 0.6; }
.ticks.delivered { color: var(--text-dim); }
.ticks.read { color: var(--accent); }

.presence-count {
  display: flex;
  align-items: center;
  gap: 4px;
}

.composer textarea {
  flex: 1;
  resize: none;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 15px;
  font-size: 15px;
  max-height: 120px;
  line-height: 1.35;
}

.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.send-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:disabled { opacity: 0.4; }

.char-count {
  font-size: 11px;
  color: var(--text-dim);
  align-self: center;
  min-width: 42px;
  text-align: right;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 40px 20px;
}

/* ---------- admin ---------- */

.admin-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 18px 60px;
}

.admin-wrap h1 { font-size: 20px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 18px 0 26px;
}

.stat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.stat-box .num { font-size: 22px; font-weight: 700; }
.stat-box .label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.section h2 {
  font-size: 14px;
  margin: 0 0 12px;
}

.session-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.session-row:last-child { border-bottom: none; }
.session-row .sname { font-weight: 600; flex: 1; }
.session-row .sidle { color: var(--text-dim); font-size: 12px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.btn-small {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
}

.btn-small:hover { border-color: var(--accent); }
.btn-small.danger { color: var(--danger); border-color: var(--danger); }

@media (max-width: 480px) {
  .bubble-wrap { max-width: 88%; }
}
