:root {
  --bg: #0b1020;
  --bg-soft: #131b2f;
  --card: rgba(19, 27, 47, .75);
  --card-2: rgba(255,255,255,.06);
  --text: #eef2ff;
  --muted: #aab5d4;
  --line: rgba(255,255,255,.1);
  --primary: #4f7cff;
  --danger: #e05a72;
  --shadow: 0 20px 50px rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #eef3fb;
  --bg-soft: #ffffff;
  --card: rgba(255,255,255,.8);
  --card-2: rgba(19,27,47,.05);
  --text: #1d2740;
  --muted: #64718f;
  --line: rgba(19,27,47,.1);
  --primary: #2d63f5;
  --danger: #cf3e58;
  --shadow: 0 20px 50px rgba(46, 70, 114, .18);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #17223d, var(--bg));
  color: var(--text);
}
html[data-theme="light"] body { background: linear-gradient(180deg, #f5f8fd, #e9eff9); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.glass {
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.app-body, .auth-body { min-height: 100vh; }
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}
.sidebar, .chat-panel {
  border-radius: 28px;
  min-height: calc(100vh - 36px);
}
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
}
.sidebar-head, .sidebar-actions, .sidebar-footer, .chat-head, .composer, .modal-head, .tabs, .message-row, .room-card-top, .room-card, .picker-item, .attachment-preview, .modal-actions, .admin-row, .inline-actions, .me-row, .chat-title-wrap, .chat-head-main, .chat-head-actions {
  display: flex;
  align-items: center;
}
.sidebar-head, .chat-head, .modal-head { justify-content: space-between; }
.sidebar-actions, .sidebar-footer { flex-direction: column; gap: 10px; }
.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}
.chat-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  gap: 14px;
}
.chat-title-wrap { gap: 12px; }
.chat-title-wrap h1 { margin: 0 0 4px; font-size: 1.1rem; }
.chat-title-wrap p { margin: 0; color: var(--muted); font-size: .92rem; }
.messages {
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty-state {
  margin: auto;
  color: var(--muted);
  text-align: center;
}
.composer-wrap {
  padding: 0 18px 18px;
  border-top: 1px solid var(--line);
}
.composer {
  gap: 10px;
  padding-top: 14px;
}
.text-input, .message-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 16px;
  outline: none;
}
.text-input::placeholder, .message-input::placeholder { color: var(--muted); }
.message-input {
  resize: none;
  min-height: 46px;
  max-height: 140px;
}
.primary-btn, .ghost-btn, .icon-btn, .tab-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--card-2);
  border-radius: 14px;
  padding: 11px 14px;
  transition: .18s ease;
}
.primary-btn {
  background: linear-gradient(135deg, var(--primary), #7e9cff);
  border-color: transparent;
  color: #fff;
  font-weight: 700;
}
.ghost-btn:hover, .icon-btn:hover, .tab-btn:hover, .room-card:hover, .picker-item:hover { transform: translateY(-1px); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; }
.danger { color: #fff; background: linear-gradient(135deg, var(--danger), #f08a9d); border-color: transparent; }
.small { padding: 8px 10px; border-radius: 12px; font-size: .9rem; }
.full-width { width: 100%; justify-content: center; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(79,124,255,.5), rgba(126,156,255,.18));
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  background-size: cover;
  background-position: center;
  flex: 0 0 auto;
}
.avatar.big { width: 56px; height: 56px; }
.avatar.tiny { width: 30px; height: 30px; font-size: .82rem; }
.room-list, .picker-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.room-card, .picker-item {
  width: 100%;
  gap: 12px;
  text-align: right;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--card-2);
}
.room-card.active { outline: 2px solid rgba(79,124,255,.45); }
.room-card-copy, .message-bubble-wrap { min-width: 0; flex: 1; }
.room-card-copy strong, .picker-item strong { display: block; }
.room-card-copy small, .picker-item small, .muted, .muted-block, .message-meta, .selection-info { color: var(--muted); }
.room-card-top { justify-content: space-between; gap: 12px; }
.badge {
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  font-size: .8rem;
}
.message-row {
  gap: 10px;
  align-items: flex-end;
}
.message-row.mine {
  flex-direction: row-reverse;
}
.message-row.grouped .avatar,
.message-row.mine .avatar { visibility: hidden; }
.message-author {
  color: var(--muted);
  font-size: .82rem;
  margin: 0 0 4px 4px;
}
.message-bubble {
  display: inline-flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(720px, 85%);
  padding: 12px 14px;
  border-radius: 18px 18px 18px 6px;
  background: var(--card-2);
  border: 1px solid var(--line);
}
.message-row.mine .message-bubble {
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(135deg, rgba(79,124,255,.25), rgba(126,156,255,.18));
}
.message-body { line-height: 1.6; word-break: break-word; }
.message-meta { font-size: .76rem; margin-top: 4px; }
.message-image img {
  max-width: 280px;
  max-height: 280px;
  border-radius: 14px;
  display: block;
}
.message-file {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,.04);
  border-radius: 12px;
  border: 1px solid var(--line);
  text-decoration: none;
}
.attachment-preview {
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px dashed var(--line);
  background: var(--card-2);
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.42);
  z-index: 40;
}
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  width: min(560px, 100%);
  border-radius: 26px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-card.wide { width: min(760px, 100%); }
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tabs { gap: 8px; }
.tab-btn.active { background: rgba(79,124,255,.22); border-color: rgba(79,124,255,.45); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.checkbox-item input { margin-left: 8px; }
.selection-info { font-size: .9rem; }
.admin-row { justify-content: space-between; gap: 12px; }
.inline-actions { gap: 8px; flex-wrap: wrap; }
.auth-body {
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(460px, 100%);
  padding: 24px;
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-head h1 { margin: 0 0 8px; }
.auth-head p { margin: 0; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.alert {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(79,124,255,.14);
  border: 1px solid rgba(79,124,255,.35);
}
.alert.error {
  background: rgba(224,90,114,.14);
  border-color: rgba(224,90,114,.35);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  transition: .2s ease;
  z-index: 70;
  background: rgba(19,27,47,.92);
  color: #fff;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.muted-block {
  padding: 18px;
  text-align: center;
  border-radius: 16px;
  border: 1px dashed var(--line);
}
.mobile-only { display: none; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }
  .sidebar {
    position: fixed;
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: min(320px, calc(100vw - 20px));
    z-index: 60;
    transform: translateX(110%);
    transition: .2s ease;
  }
  .sidebar.show-mobile { transform: translateX(0); }
  .chat-panel, .sidebar { min-height: calc(100vh - 20px); }
  .mobile-only { display: inline-flex; }
}

/* Phase 7 additions */
.reset-btn {
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  color: inherit;
  text-align: inherit;
}
.reset-btn:focus-visible,
.clickable-user:focus-visible,
.user-ref-inline:focus-visible {
  outline: 2px solid rgba(79,124,255,.5);
  outline-offset: 3px;
}
.clickable-user,
.user-ref-inline {
  cursor: pointer;
}
.user-ref-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.user-ref-inline .avatar {
  width: 30px;
  height: 30px;
}
.user-ref-inline strong,
.user-ref-inline small {
  display: block;
}
.user-ref-inline small {
  color: var(--muted);
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  flex: 0 0 auto;
  background: rgba(255,255,255,.24);
  border: 1px solid rgba(255,255,255,.12);
}
.status-dot.online { background: #2ecc71; border-color: rgba(46,204,113,.4); }
.status-dot.away { background: #f1c40f; border-color: rgba(241,196,15,.45); }
.status-dot.busy { background: #e74c3c; border-color: rgba(231,76,60,.45); }
.status-dot.offline { background: rgba(255,255,255,.25); border-color: rgba(255,255,255,.16); }
.message-system {
  align-self: center;
  max-width: min(680px, 92%);
  text-align: center;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px dashed var(--line);
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-size: .9rem;
}
.message-bubble .inline-actions {
  margin-top: 2px;
}
.message-author .user-ref-inline {
  gap: 6px;
}
.message-author .avatar {
  width: 22px;
  height: 22px;
  font-size: .72rem;
}
.chat-title-wrap {
  border-radius: 18px;
}
.chat-title-wrap:hover {
  background: rgba(255,255,255,.04);
}
.chat-title-wrap > div:last-child {
  min-width: 0;
}
.chat-title-wrap h1,
.chat-title-wrap p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toggle-row {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.user-profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
}
.user-profile-card h3 {
  margin: 0 0 6px;
}
.user-profile-card p {
  margin: 0 0 8px;
  color: var(--muted);
}
#mobileSidebarCloseBtn {
  font-size: 1.05rem;
}
#roomProfileBtn {
  max-width: 100%;
}
#roomProfileBtn[disabled] {
  opacity: .95;
  cursor: default;
}
@media (max-width: 900px) {
  .sidebar-head {
    align-items: flex-start;
  }
  .sidebar-head .inline-actions {
    align-self: flex-start;
  }
  .chat-head {
    padding: 14px 16px;
  }
  .chat-head-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .chat-title-wrap h1 {
    font-size: 1rem;
  }
  .modal-card,
  .modal-card.wide {
    width: min(100%, 100%);
    max-height: calc(100vh - 26px);
    overflow: auto;
  }
}
