/* ── Dedicated Chat Screen ──────────────────────────────────────────────── */

#screen-chat {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  overflow: hidden !important;
  background: var(--bg-base, #f5f5f7);
}

#screen-chat.hidden {
  display: none !important;
}

.cs-auth-gate,
.cs-main {
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* ── Auth gate ──────────────────────────────────────────────────────────── */
.cs-auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.cs-auth-card {
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border, #e0e0e0);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}

.cs-auth-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 1rem;
  border: 3px solid var(--accent-ink, #1a3a6b);
}

.cs-auth-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary, #111);
  margin: 0 0 .5rem;
}

.cs-auth-sub {
  font-size: .9rem;
  color: var(--text-secondary, #666);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.cs-auth-btn {
  background: var(--accent, #1a3a6b);
  color: var(--accent-fg, #fff);
  border: none;
  border-radius: 10px;
  padding: .75rem 1.5rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: opacity .15s;
}
.cs-auth-btn:hover { opacity: .85; }

.cs-auth-perks {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.cs-auth-perks li {
  font-size: .82rem;
  color: var(--text-secondary, #666);
  line-height: 1.4;
}

/* ── Main layout: sidebar + chat area ───────────────────────────────────── */
.cs-main {
  display: flex;
  flex-direction: row-reverse; /* sidebar on right (RTL) */
  min-height: 0;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.cs-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface, #fff);
  border-left: 1px solid var(--border, #e0e0e0);
  overflow: hidden;
}

.cs-new-session-btn {
  margin: .75rem;
  padding: .55rem .85rem;
  background: var(--accent, #1a3a6b);
  color: var(--accent-fg, #fff);
  border: none;
  border-radius: 9px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: opacity .15s;
}
.cs-new-session-btn:hover { opacity: .85; }

.cs-sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 .4rem .75rem;
}

.cs-session-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .55rem .6rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
html[dir="rtl"] .cs-session-item { direction: rtl; }
.cs-session-item:hover { background: var(--bg-card, #f0f0f5); }
.cs-session-item.active { background: var(--team-accent-bg, #e8edf7); }

.cs-session-title {
  flex: 1;
  font-size: .83rem;
  color: var(--text-primary, #111);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cs-session-menu {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-secondary, #888);
  cursor: pointer;
  padding: 0 .2rem;
  border-radius: 5px;
  opacity: 0;
  transition: opacity .15s, background .15s;
  line-height: 1;
}
.cs-session-item:hover .cs-session-menu { opacity: 1; }
.cs-session-menu:hover { background: var(--bg-card, #e0e0e8); opacity: 1; }

/* Mobile: always show menu button */
@media (max-width: 639px) {
  .cs-session-menu { opacity: .6; }
}

/* ── Session dropdown menu ───────────────────────────────────────────────── */
.cs-session-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 200;
  min-width: 130px;
  overflow: hidden;
}

.cs-session-drop-item {
  display: block;
  width: 100%;
  padding: .55rem .85rem;
  background: none;
  border: none;
  font-size: .88rem;
  cursor: pointer;
  text-align: start;
  transition: background .12s;
}
.cs-session-drop-item:hover { background: var(--bg-card, #f5f5f5); }
.cs-session-drop-delete { color: #c0392b; }

/* ── Chat area ───────────────────────────────────────────────────────────── */
.cs-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.cs-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--border, #e0e0e0);
  background: var(--bg-surface, #fff);
  flex-shrink: 0;
}
html[dir="rtl"] /* ── Header ──────────────────────────────────────────────────────────────── */
.cs-header { direction: rtl; }

.cs-sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-secondary, #666);
  cursor: pointer;
  padding: .25rem .35rem;
  border-radius: 6px;
  transition: background .15s;
  flex-shrink: 0;
}
.cs-sidebar-toggle:hover { background: var(--bg-card, #eee); }
/* Sidebar is always visible on desktop (no drawer to toggle) — the button
   did nothing there, which just read as broken. */
@media (min-width: 640px) {
  .cs-sidebar-toggle { display: none; }
}

.cs-header-title {
  flex: 1;
  font-weight: 700;
  font-size: .95rem;
  color: var(--text-primary, #111);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cs-del-btn {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  opacity: .45;
  padding: .25rem .35rem;
  border-radius: 6px;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.cs-del-btn:hover { opacity: 1; background: var(--bg-card, #f0f0f0); }

/* Lab Mode — "stop with the jokes, give me the raw data" toggle. Off by
   default (dim, same treatment as the delete button); on = accent-colored
   pill so it's obviously a state, not just another icon button. */
.cs-lab-toggle {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  opacity: .45;
  padding: .25rem .35rem;
  border-radius: 6px;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.cs-lab-toggle:hover { opacity: 1; background: var(--bg-card, #f0f0f0); }
.cs-lab-toggle.active {
  opacity: 1;
  background: var(--accent1, #2563eb);
  box-shadow: 0 0 0 1px var(--accent1, #2563eb);
}

/* ── Thread ──────────────────────────────────────────────────────────────── */
.cs-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  -webkit-overflow-scrolling: touch;
}

/* ── Messages ────────────────────────────────────────────────────────────── */
.cs-msg {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  max-width: 82%;
}

.cs-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.cs-msg--prof {
  align-self: flex-start;
}

.cs-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--accent-ink, #1a3a6b);
}

.cs-msg-bubble {
  padding: .6rem .85rem;
  border-radius: 16px;
  font-size: .92rem;
  line-height: 1.55;
  word-break: break-word;
}

.cs-msg--user .cs-msg-bubble {
  background: var(--accent, #1a3a6b);
  color: var(--accent-fg, #fff);
  border-bottom-right-radius: 4px;
}

.cs-msg--prof .cs-msg-bubble {
  background: var(--bg-surface, #fff);
  color: var(--text-primary, #111);
  border: 1px solid var(--border, #e0e0e0);
  border-bottom-left-radius: 4px;
}

/* ── Thinking dots ───────────────────────────────────────────────────────── */
.cs-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}
.cs-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-secondary, #999);
  border-radius: 50%;
  animation: cs-bounce .9s infinite;
}
.cs-dots span:nth-child(2) { animation-delay: .15s; }
.cs-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes cs-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-5px); }
}

.cs-thinking-note {
  margin-top: 6px;
  font-size: .8rem;
  color: var(--text-secondary, #999);
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.cs-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .65rem .9rem;
  border-top: 1px solid var(--border, #e0e0e0);
  background: var(--bg-surface, #fff);
  flex-shrink: 0;
}

.cs-input {
  flex: 1;
  border: 1px solid var(--border, #ccc);
  border-radius: 12px;
  padding: .55rem .8rem;
  font-size: .92rem;
  resize: none;
  outline: none;
  background: var(--bg-base, #f5f5f7);
  color: var(--text-primary, #111);
  font-family: inherit;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.45;
  transition: border-color .15s;
}
.cs-input:focus { border-color: var(--accent-ink, #1a3a6b); }

.cs-send-btn {
  background: var(--accent, #1a3a6b);
  color: var(--accent-fg, #fff);
  border: none;
  border-radius: 10px;
  padding: .55rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s;
  align-self: flex-end;
}
.cs-send-btn:hover:not(:disabled) { opacity: .85; }
.cs-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 639px) {
  .cs-sidebar {
    position: absolute;
    inset: 0;
    z-index: 150;
    width: 80%;
    max-width: 280px;
    transform: translateX(100%);
    transition: transform .25s ease;
    border-left: none;
    box-shadow: -4px 0 20px rgba(0,0,0,.12);
  }
  .cs-sidebar.open {
    transform: translateX(0);
  }
  .cs-main { position: relative; }

  /* Backdrop behind the drawer — tapping it closes the sidebar. Without
     this (and without a close button inside the drawer, added separately),
     there was no way to dismiss it once opened. */
  .cs-sidebar-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 149;
    background: rgba(0,0,0,.35);
  }
  .cs-sidebar-backdrop.open { display: block; }

  .cs-sidebar-close {
    display: flex;
    align-self: flex-end;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-secondary, #666);
    cursor: pointer;
    padding: .5rem .75rem;
    line-height: 1;
  }
}
.cs-sidebar-close { display: none; } /* desktop: no drawer, nothing to close */

/* ── Dark theme ──────────────────────────────────────────────────────────── */
[data-theme="dark"] .cs-msg--prof .cs-msg-bubble {
  background: var(--bg-card, #1e1e2e);
  border-color: var(--border, #333);
}
[data-theme="dark"] .cs-input {
  background: var(--bg-card, #1e1e2e);
}
[data-theme="dark"] .cs-session-dropdown {
  background: var(--bg-card, #1e1e2e);
  border-color: var(--border, #333);
}

/* ── "Answering" chip ────────────────────────────────────────────────────────
   Shown when the chat was opened from the post-game report's question to the
   crowd. The question stays visible above the input so the reader isn't
   answering from memory, and so it's obvious what the Professor is about to
   be sent. */
.cs-context {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .55rem .9rem 0;
  background: var(--bg-surface, #fff);
  flex-shrink: 0;
}
.cs-context.hidden { display: none; }
.cs-context-label {
  flex-shrink: 0;
  font-size: .7rem;
  font-weight: 700;
  color: var(--accent-ink, #1a3a6b);
  background: var(--accent-soft, rgba(26, 58, 107, .09));
  border-radius: 6px;
  padding: .18rem .4rem;
  margin-top: .1rem;
}
.cs-context-text {
  flex: 1;
  font-size: .78rem;
  line-height: 1.45;
  color: var(--text-secondary, #666);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cs-context-clear {
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .8rem;
  line-height: 1;
  padding: .2rem;
  color: var(--text-secondary, #999);
}
.cs-context-clear:hover { color: var(--text-primary, #111); }

/* ── Delete confirmation ─────────────────────────────────────────────────────
   Deleting a conversation can't be undone, so it asks first. */
.cs-confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 1.2rem;
}
.cs-confirm {
  background: var(--bg-surface, #fff);
  color: var(--text-primary, #111);
  border-radius: 14px;
  padding: 1.1rem 1.2rem 1rem;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
}
.cs-confirm-title { font-size: 1rem; font-weight: 700; margin-bottom: .35rem; }
.cs-confirm-body  { font-size: .85rem; color: var(--text-secondary, #777); margin-bottom: 1rem; }
.cs-confirm-actions { display: flex; gap: .55rem; justify-content: flex-end; }
.cs-confirm-actions button {
  border: none;
  border-radius: 9px;
  padding: .45rem 1rem;
  font-size: .85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.cs-confirm-cancel { background: var(--bg-base, #eee); color: var(--text-primary, #111); }
.cs-confirm-ok     { background: #c8102e; color: #fff; }
.cs-confirm-ok:hover { opacity: .9; }
