/* shared/styles.css — Base styles for all chat UIs */

/* =========================================================================
   Theme Variables
   ========================================================================= */
:root, [data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --border: #334155;
  --text-primary: #e2e8f0;
  --text-heading: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #60a5fa;
  --accent-light: #a5b4fc;
  --msg-user: #1d4ed8;
  --bg-hover: #1e3a5f;
  --code-bg: #0c1222;
  --code-header-bg: #162032;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-heading: #0f172a;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-light: #6366f1;
  --msg-user: #3b82f6;
  --bg-hover: #e0e7ff;
  --code-bg: #f1f5f9;
  --code-header-bg: #e2e8f0;
}

/* =========================================================================
   Base
   ========================================================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading, inherit);
}

/* =========================================================================
   Header
   ========================================================================= */
.header {
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header h1 { font-size: 20px; color: var(--text-heading); }
.header h1 .accent { color: var(--accent); }
.header .subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 8px; }

/* =========================================================================
   Connection Status
   ========================================================================= */
.status-badge { font-size: 12px; padding: 4px 10px; border-radius: 12px; }
.status-badge.connected { background: #0a3d2a; color: #4ade80; }
.status-badge.disconnected { background: #3d0a0a; color: #f87171; }
.status-badge.checking { background: #3d3a0a; color: #fbbf24; }

[data-theme="light"] .status-badge.connected { background: #dcfce7; color: #16a34a; }
[data-theme="light"] .status-badge.disconnected { background: #fee2e2; color: #dc2626; }
[data-theme="light"] .status-badge.checking { background: #fef9c3; color: #ca8a04; }

/* =========================================================================
   Theme Toggle
   ========================================================================= */
.btn-theme {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, color 0.2s;
}
.btn-theme:hover { border-color: var(--accent); color: var(--text-primary); }

/* =========================================================================
   Settings Bar (developer mode)
   ========================================================================= */
.settings {
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; align-items: center;
}
.settings label { font-size: 12px; color: var(--text-muted); }

.settings input, .settings select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px; border-radius: 6px; font-size: 13px;
}
.settings input:focus, .settings select:focus { outline: none; border-color: var(--accent); }
.settings .field { display: flex; flex-direction: column; gap: 2px; }

/* =========================================================================
   Chat Area
   ========================================================================= */
.chat {
  flex: 1; overflow-y: auto;
  padding: 16px 24px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}

/* Message appear animation */
@keyframes message-appear {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message {
  max-width: 80%; padding: 14px 18px;
  border-radius: 16px; line-height: 1.6;
  font-size: 14px; overflow-wrap: break-word;
  animation: message-appear 0.25s ease-out;
  position: relative;
}

.message.user {
  align-self: flex-end;
  background: var(--msg-user);
  color: var(--brand-on-primary, #fff);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.error {
  align-self: center;
  background: #3d0a0a; color: #f87171; font-size: 13px;
}
[data-theme="light"] .message.error { background: #fee2e2; color: #dc2626; }

.message .meta { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

/* =========================================================================
   Markdown Styles (assistant messages)
   ========================================================================= */
.message.assistant p { margin-bottom: 10px; }
.message.assistant p:last-child { margin-bottom: 0; }

.message.assistant strong { color: var(--accent); }
.message.assistant em { color: var(--accent-light); }

.message.assistant a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.message.assistant a:hover { color: var(--accent-light); }

.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
  color: var(--text-heading);
  margin: 16px 0 8px;
  line-height: 1.3;
}
.message.assistant h2 { font-size: 16px; }
.message.assistant h3 { font-size: 15px; }
.message.assistant h4 { font-size: 14px; }
.message.assistant h2:first-child,
.message.assistant h3:first-child,
.message.assistant h4:first-child { margin-top: 0; }

.message.assistant ul,
.message.assistant ol {
  margin: 8px 0 10px 20px;
  line-height: 1.7;
}
.message.assistant li { margin-bottom: 4px; }
.message.assistant li:last-child { margin-bottom: 0; }

.message.assistant code {
  background: var(--code-bg);
  padding: 2px 6px; border-radius: 4px; font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.message.assistant pre {
  background: var(--code-bg);
  border-radius: 8px; overflow-x: auto; margin: 10px 0;
  border: 1px solid var(--border);
}
.message.assistant pre code {
  background: none; padding: 12px; display: block;
  border-radius: 0;
}

.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px;
  background: var(--code-header-bg);
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}
.code-lang {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.copy-code-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); padding: 2px 8px;
  border-radius: 4px; font-size: 11px; cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.copy-code-btn:hover { border-color: var(--accent); color: var(--text-primary); }

/* =========================================================================
   Message Copy Button
   ========================================================================= */
.msg-copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg-primary); border: 1px solid var(--border);
  color: var(--text-muted); padding: 2px 8px;
  border-radius: 4px; font-size: 11px; cursor: pointer;
  opacity: 0; transition: opacity 0.2s, border-color 0.2s, color 0.2s;
}
.message.assistant:hover .msg-copy-btn { opacity: 1; }
.msg-copy-btn:hover { border-color: var(--accent); color: var(--text-primary); }

/* =========================================================================
   Typing Indicator
   ========================================================================= */
.typing-indicator {
  display: flex; gap: 5px; padding: 4px 0;
}
.typing-indicator span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* =========================================================================
   Conversation Starters
   ========================================================================= */
.starters {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 24px; justify-content: center;
}
.starters.hidden { display: none; }

.starter-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 16px; border-radius: 12px;
  font-size: 13px; cursor: pointer;
  transition: all 0.2s;
}

.starter-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* =========================================================================
   Input Area
   ========================================================================= */
.input-area {
  padding: 12px 24px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
}

.chat-prompt {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 16px; border-radius: 12px;
  font-size: 14px; font-family: inherit;
  resize: none; min-height: 48px; max-height: 200px;
}
.chat-prompt:focus { outline: none; border-color: var(--accent); }

.btn-send {
  background: var(--brand-primary, var(--accent, #3b82f6));
  color: var(--brand-on-primary, #fff);
  border: none;
  padding: 12px 20px; border-radius: 12px;
  font-size: 14px; cursor: pointer; font-weight: 600;
}
.btn-send:hover { filter: brightness(1.08); }
.btn-send:disabled { background: var(--border); cursor: not-allowed; }

.btn-clear, .btn-retry, .btn-export {
  background: var(--border);
  color: var(--text-muted);
  border: none; padding: 12px 14px;
  border-radius: 12px; font-size: 14px; cursor: pointer;
  transition: filter 0.2s, color 0.2s;
}
.btn-clear:hover, .btn-retry:hover, .btn-export:hover {
  filter: brightness(1.3); color: var(--text-primary);
}

/* =========================================================================
   School Monogram Badge (header)
   ========================================================================= */
.school-monogram:empty { display: none; }

.school-monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px; height: 44px; padding: 0 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  background: var(--brand-primary, var(--accent));
  color: var(--brand-on-primary, #fff);
  flex-shrink: 0;
  font-family: var(--font-heading, inherit);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* =========================================================================
   Change-school Button (header)
   ========================================================================= */
.btn-change-school {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  white-space: nowrap;
}
.btn-change-school:hover { border-color: var(--accent); color: var(--text-primary); }

/* =========================================================================
   School Picker Overlay
   ========================================================================= */
.school-picker-overlay {
  position: fixed; inset: 0;
  background: rgb(0 0 0 / 82%);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fade-in 0.15s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.school-picker-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 560px;
  width: 92%;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.school-picker-box h2 { color: var(--text-heading); margin-bottom: 6px; font-size: 20px; }
.school-picker-box > p { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; line-height: 1.5; }

.school-picker-search {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 12px;
  font-family: inherit;
}
.school-picker-search:focus { outline: none; border-color: var(--accent); }

.school-picker-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 4px;
}

.school-picker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.school-picker-item:hover,
.school-picker-item:focus {
  background: var(--bg-primary);
  border-color: var(--border);
  outline: none;
}

.school-picker-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.school-picker-text .school-name {
  font-weight: 600;
  color: var(--text-heading);
  font-size: 14px;
}
.school-picker-text .school-sub {
  color: var(--text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.school-picker-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px;
  text-align: center;
  line-height: 1.5;
}

.monogram-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

/* =========================================================================
   Mobile Responsive
   ========================================================================= */
@media (max-width: 600px) {
  .message { max-width: 92%; }
  .header { padding: 12px 16px; }
  .header h1 { font-size: 17px; }
  .chat { padding: 12px 12px; gap: 10px; }
  .input-area { padding: 10px 12px 14px; gap: 6px; }
  .settings { flex-direction: column; padding: 10px 12px; }
  .starters { gap: 6px; padding: 10px 12px; }
  .starter-btn { font-size: 12px; padding: 8px 12px; }
  .btn-export { display: none; }
  .school-monogram { min-width: 38px; height: 38px; font-size: 14px; padding: 0 8px; }
  .header-left { gap: 10px; }
  .btn-change-school { font-size: 11px; padding: 0 8px; height: 30px; }
  .school-picker-box { padding: 18px; width: 96%; max-height: 92vh; }
  .app-shell { grid-template-columns: 1fr !important; }
  .sidebar { display: none; }
  .auth-card { padding: 24px 18px; }
}

/* =========================================================================
   App shell (sidebar + main) — used on the chat page
   ========================================================================= */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.btn-new-conv {
  width: 100%;
  background: var(--brand-primary, var(--accent, #3b82f6));
  color: var(--brand-on-primary, #fff);
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-new-conv:hover { filter: brightness(1.08); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 16px;
  text-align: center;
  line-height: 1.5;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.conv-item:hover { background: var(--bg-primary); }
.conv-item.active {
  background: var(--bg-hover);
  border-color: var(--border);
}
.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { color: #f87171; }

.sidebar-foot {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-direction: column;
}
.btn-invite, .btn-logout {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-invite:hover, .btn-logout:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* =========================================================================
   Auth pages (login, signup, privacy)
   ========================================================================= */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 100vh;
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 440px;
  width: 100%;
}
.auth-card-wide { max-width: 720px; }

.auth-card h1 {
  color: var(--text-heading);
  font-size: 24px;
  margin-bottom: 6px;
}
.auth-card h2 {
  color: var(--text-heading);
  font-size: 16px;
  margin: 20px 0 8px;
}
.auth-lede {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}
.auth-card ul {
  list-style: disc;
  margin: 6px 0 10px 20px;
  color: var(--text-primary);
  line-height: 1.6;
}
.auth-card code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
}

.auth-card label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 4px;
}
.auth-hint {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 4px;
}
.auth-hint-inline { color: var(--text-muted); font-weight: normal; font-size: 12px; }

.auth-card input[type=text],
.auth-card input[type=email] {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }

.auth-card button[type=submit] {
  margin-top: 20px;
  background: var(--brand-primary, var(--accent, #3b82f6));
  color: var(--brand-on-primary, #fff);
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  font-weight: 600;
}
.auth-card button[type=submit]:hover { filter: brightness(1.08); }
.auth-card button[type=submit]:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.auth-ok {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--text-primary);
  margin-top: 8px;
  line-height: 1.5;
}
.auth-ok p { margin-top: 4px; color: var(--text-muted); font-size: 13px; }

.auth-err {
  background: #3d0a0a;
  color: #f87171;
  border-radius: 10px;
  padding: 10px 14px;
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.5;
}
[data-theme="light"] .auth-err { background: #fee2e2; color: #dc2626; }

.auth-aside {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 20px;
  line-height: 1.5;
}
.auth-aside a { color: var(--accent); text-decoration: underline; }

.hidden { display: none !important; }

