/* ============================================================
   Serenity Spaces — Main Stylesheet
   Dark glassmorphism design system
   ============================================================ */

:root {
  --bg: #0d0d0f;
  --surface: rgba(255,255,255,0.05);
  --surface-hover: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.1);
  --text: #e8e8f0;
  --text-muted: rgba(255,255,255,0.45);
  --accent: #7c6af7;
  --accent-glow: rgba(124,106,247,0.35);
  --crimson: #8b1a1a;
  --crimson-bright: #dc143c;
  --highlight-yellow: rgba(255,214,0,0.35);
  --highlight-pink: rgba(255,105,180,0.4);
  --highlight-blue: rgba(30,144,255,0.45);
  --highlight-crimson: rgba(139,0,0,0.5);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 280px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
body.scrollable { overflow: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Glass panels ── */
.glass-panel {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, box-shadow 0.15s;
  background: var(--surface);
  color: var(--text);
}
.btn:hover { background: var(--surface-hover); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}
.btn-primary:hover { background: #6a5ae0; box-shadow: 0 0 18px var(--accent-glow); }
.btn-danger {
  background: var(--crimson);
  border-color: var(--crimson-bright);
  color: #fff;
}
.btn-danger:hover { background: #a02020; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Forms ── */
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
label { display: block; margin-bottom: 6px; color: var(--text-muted); font-size: 13px; }
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 12px; }
.form-error { color: #ff6b6b; font-size: 13px; margin-top: 4px; }

/* ── Centered auth layouts ── */
.auth-page {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 30% 30%, rgba(124,106,247,0.08) 0%, transparent 60%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  margin: 20px;
}
.auth-card h1 {
  font-size: 28px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #e8e8f0, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 15px;
}
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 12px; }
.auth-footer { margin-top: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ── Dashboard layout ── */
.dashboard-page { overflow: auto; background: var(--bg); }
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(13,13,15,0.9);
  backdrop-filter: blur(20px);
  z-index: 100;
}
.dashboard-header .app-name {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, #e8e8f0, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.dashboard-body { padding: 32px; max-width: 1200px; margin: 0 auto; }
.dashboard-section { margin-bottom: 40px; }
.dashboard-section h2 { font-size: 18px; margin-bottom: 20px; color: var(--text); }

/* ── Room cards ── */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.room-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.room-card-name { font-size: 16px; font-weight: 600; }
.room-card-token {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  background: rgba(0,0,0,0.3);
  padding: 4px 8px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Background thumbnails ── */
.bg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.bg-thumb {
  position: relative;
  aspect-ratio: 16/9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}
.bg-thumb img { width: 100%; height: 100%; object-fit: cover; }
.bg-thumb:hover { border-color: var(--accent); }
.bg-thumb .bg-thumb-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 4px 6px;
  font-size: 11px;
  background: rgba(0,0,0,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Create room form ── */
.create-room-form { padding: 24px; }
.bg-option-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
}

/* ── Room layout (main session page) ── */
#container { display: flex; height: 100%; }
#main { flex: 4; position: relative; padding: 10px; }
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(10px);
  border-left: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  gap: 16px;
}

/* ── Room pane ── */
#room {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  height: calc(var(--room-height,60%) - 10px);
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(20px);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
#room .bg {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  background: center/cover;
  filter: brightness(0.45);
}

/* ── Horizontal divider ── */
#horizontal-divider {
  position: absolute;
  top: calc(var(--room-height,60%));
  left: 10px; right: 10px;
  height: 6px; cursor: row-resize;
  background: var(--border);
  border-radius: 3px;
  z-index: 10;
  transition: background 0.15s;
}
#horizontal-divider:hover { background: var(--accent); }

/* ── Chat pane ── */
#chat-pane {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  height: calc(100% - var(--room-height,60%) - 26px);
  display: flex; flex-direction: column;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(20px);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
#messages {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#input-area {
  display: flex;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}
#input-area input {
  flex: 1; padding: 12px 16px;
  background: transparent;
  border: none; border-radius: 0;
  color: var(--text);
  font-size: 14px;
}
#input-area input:focus { box-shadow: none; }
#send-btn {
  padding: 0 20px;
  background: var(--accent);
  border: none;
  border-left: 1px solid var(--border);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s;
}
#send-btn:hover { background: #6a5ae0; }

/* ── Chat messages — original demo style ── */
.chat-message {
  display: flex;
  align-items: flex-start;
  margin-bottom: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  word-break: break-word;
  line-height: 1.5;
  gap: 12px;
}
.chat-message.you   { background: rgba(140,207,255,0.2); }
.chat-message.other { background: rgba(255,255,255,0.05); }
.chat-message.pinned {
  background: rgba(139,0,0,0.35) !important;
  border: 1px solid rgba(220,20,60,0.3);
}
/* ① Timestamp — left edge, small, vertically centred */
.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 3px;
  min-width: 42px;
}
/* ② Avatar */
.chat-message img.chat-avatar {
  width: 40px; height: 40px;
  object-fit: cover;
  flex-shrink: 0;
}
/* ③ Name + text */
.chat-message .msg-body { flex: 1; min-width: 0; }
.chat-message strong { white-space: nowrap; }
.chat-message .msg-text { word-break: break-word; }
.chat-image {
  max-width: 150px; max-height: 150px;
  margin: 0 3px;
  border-radius: 4px;
  vertical-align: middle;
}

/* ── Highlights ── */
mark.hl-yellow  { background: var(--highlight-yellow);  color: inherit; border-radius: 2px; padding: 0 2px; }
mark.hl-pink    { background: var(--highlight-pink);    color: inherit; border-radius: 2px; padding: 0 2px; }
mark.hl-blue    { background: var(--highlight-blue);    color: inherit; border-radius: 2px; padding: 0 2px; }
mark.hl-crimson { background: var(--highlight-crimson); color: inherit; border-radius: 2px; padding: 0 2px; }

/* ── Highlight toolbar ── */
.highlight-toolbar {
  position: fixed;
  display: none;
  background: rgba(20,20,30,0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  gap: 6px;
  align-items: center;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.highlight-toolbar.visible { display: flex; }
.hl-btn {
  width: 28px; height: 28px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, border-color 0.1s;
  background: transparent;
}
.hl-btn:hover { transform: scale(1.2); border-color: rgba(255,255,255,0.3); }
.hl-btn-yellow { background: var(--highlight-yellow); }
.hl-btn-pink   { background: var(--highlight-pink); }
.hl-btn-blue   { background: var(--highlight-blue); }
.hl-btn-pin    { color: var(--crimson-bright); font-size: 18px; }

/* ── Avatars in room ── */
.avatar {
  position: absolute;
  width: 100px;
  height: 100px;
  user-select: none;
  cursor: grab;
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  object-fit: cover;
}
.avatar:active { cursor: grabbing; }
.avatar.linked { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }

/* ── Typing bubble on room avatar ── */
.typing-bubble {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 8px;
  background: rgba(30,30,40,0.85);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  z-index: 25;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.typing-bubble span {
  width: 5px; height: 5px;
  background: #ccc;
  border-radius: 50%;
  display: block;
  animation: typingBounce 1.1s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
  30%           { transform: translateY(-5px); opacity: 1;    }
}

/* ── Chat bubbles ── */
.chat-bubble {
  position: absolute;
  max-width: 200px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 20;
  border: 1px solid rgba(255,255,255,0.15);
}
.chat-bubble.show { opacity: 1; }
.chat-bubble::before {
  content: "";
  position: absolute;
  width: 0; height: 0;
  border: 8px solid transparent;
}
.chat-bubble.br::before { top: -16px; left: 12px; border-bottom-color: rgba(255,255,255,0.12); }
.chat-bubble.bl::before { top: -16px; right: 12px; border-bottom-color: rgba(255,255,255,0.12); }
.chat-bubble.tr::before { bottom: -16px; left: 12px; border-top-color: rgba(255,255,255,0.12); }
.chat-bubble.tl::before { bottom: -16px; right: 12px; border-top-color: rgba(255,255,255,0.12); }

/* ── Sidebar components ── */
.sidebar-section { border-bottom: 1px solid var(--border); padding-bottom: 16px; }
.sidebar-section:last-child { border-bottom: none; }
.sidebar-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Room tab ── */
.room-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 13px;
}
.room-tab-name { font-weight: 600; }
.room-tab-count { color: var(--text-muted); font-size: 12px; }

/* ── Participant list ── */
#user-list { list-style: none; }
.participant-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: default;
}
.participant-card:hover { background: var(--surface-hover); }
.participant-avatar {
  width: 48px; height: 48px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.participant-name { font-size: 13px; }

/* ── Split nameplate (linked users) ── */
.user-linked {
  position: relative;
  height: 48px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: linear-gradient(
    45deg,
    rgba(255,255,255,0.05) 0 50%,
    rgba(255,255,255,0.08) 50% 100%
  ) !important;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.user-linked .link-half {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  padding: 0 8px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.user-linked .link-half:nth-child(1) {
  left: 0;
  background: rgba(255,255,255,0.05);
  justify-content: flex-start;
}
.user-linked .link-half:nth-child(3) {
  right: 0;
  background: rgba(255,255,255,0.08);
  justify-content: flex-start;
  padding: 0 8px 0 12px;
}
.user-linked .link-half:hover { background: rgba(255,255,255,0.15); }
.user-linked .link-half.selected { background: rgba(255,255,255,0.25); }
.user-linked .role-icon { width: 24px; height: 24px; margin-right: 8px; }
.link-heart {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.6));
}

/* ── Notes panel ── */
.notes-panel { display: flex; flex-direction: column; gap: 8px; }
.notes-participant-select {
  margin-bottom: 8px;
}
.notes-textarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  font-size: 13px;
  font-family: inherit;
}
.notes-save-indicator {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* ── Pin panel ── */
.pin-panel { display: flex; flex-direction: column; gap: 6px; }
.pin-item {
  background: rgba(139,0,0,0.2);
  border: 1px solid rgba(220,20,60,0.2);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.pin-item:hover { background: rgba(139,0,0,0.35); }
.pin-item-text { margin-bottom: 4px; }
.pin-item-annotation { color: var(--text-muted); font-style: italic; }
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  margin-bottom: 10px;
}
.collapsible-header:hover .sidebar-label { color: var(--text); }
.collapsible-toggle { color: var(--text-muted); font-size: 12px; }

/* ── End session button ── */
#end-session-btn {
  margin-top: auto;
  width: 100%;
  justify-content: center;
  padding: 12px;
}

/* ── Context menu ── */
#ctx-menu {
  position: fixed;
  background: rgba(20,20,30,0.98);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: none;
  z-index: 1000;
  padding: 6px;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#ctx-menu.visible { display: block; }
#ctx-menu button {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  border-radius: 4px;
  transition: background 0.1s;
}
#ctx-menu button:hover { background: var(--surface-hover); }
#ctx-menu button.danger { color: var(--crimson-bright); }


/* ── Landing page ── */
.landing-page {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(124,106,247,0.1) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(139,0,0,0.08) 0%, transparent 50%);
}
.landing-card {
  text-align: center;
  padding: 60px 40px;
  max-width: 500px;
  width: 90%;
}
.landing-card h1 {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, #e8e8f0 0%, var(--accent) 60%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}
.landing-card .tagline {
  color: var(--text-muted);
  font-size: 18px;
  margin-bottom: 40px;
}
.landing-actions { display: flex; gap: 12px; justify-content: center; }

/* ── Join room page ── */
.join-page {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 50% 30%, rgba(124,106,247,0.1) 0%, transparent 60%);
}
.join-card {
  width: 100%;
  max-width: 480px;
  padding: 40px;
  margin: 20px;
}
.join-card h1 { font-size: 24px; margin-bottom: 6px; }
.join-card .room-name { color: var(--accent); margin-bottom: 28px; font-size: 16px; }
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.upload-area:hover { border-color: var(--accent); }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Alerts / flash messages ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error { background: rgba(220,20,60,0.15); border: 1px solid rgba(220,20,60,0.3); color: #ff6b6b; }
.alert-success { background: rgba(34,197,94,0.12); border: 1px solid rgba(34,197,94,0.3); color: #4ade80; }

/* ── Utilities ── */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }

/* ── Flash overlay for newly pinned ── */
.msg.flash-pin { animation: flashCrimson 0.6s ease; }
@keyframes flashCrimson {
  0%   { background: rgba(220,20,60,0.5); }
  100% { background: inherit; }
}

/* ── Participant name label under avatar in room ── */
.avatar-label {
  position: absolute;
  font-size: 11px;
  white-space: nowrap;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
  color: var(--text);
  z-index: 5;
  transform: translateX(-50%);
}

/* ── Participant card with host crown ── */
.participant-card { position: relative; }
.host-crown {
  position: absolute;
  top: 2px; right: 2px;
  font-size: 13px;
  line-height: 1;
  pointer-events: none;
}

/* ── System message in chat ── */
.chat-system {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 6px 0;
  padding: 3px 10px;
}

/* ── Practitioner sidebar tabs (info strip) ── */
.room-info-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.room-info-strip .room-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.room-info-strip .session-info { font-size: 12px; color: var(--text-muted); }
