/* ============================================
   Little Book Ministries — Dark Theme CSS
   ============================================ */

@media print {
  /* Scope rule to radar spokes only — does NOT touch data polygon or score dots */
  svg .radar-spoke {
    stroke: #059669 !important;
    stroke-opacity: 0.18 !important;
  }
}

/* --- Design Tokens --- */
:root {
  --bg-deep: #0a0a0f;
  --bg-primary: #0f1019;
  --bg-surface: #161825;
  --bg-elevated: #1c1f30;
  --bg-hover: #232740;
  --bg-active: #2a2f4a;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.12);

  --text-primary: #e8e9f0;
  --text-secondary: #9499b3;
  --text-muted: #5d6280;
  --text-inverse: #0f1019;

  --accent: #6c5ce7;
  --accent-hover: #7f71ed;
  --accent-glow: rgba(108, 92, 231, 0.25);
  --accent-subtle: rgba(108, 92, 231, 0.1);

  --success: #00cec9;
  --danger: #ff6b6b;
  --warning: #feca57;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);

  --sidebar-width: 280px;
  --topbar-height: 56px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* --- Reset --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection {
  background: var(--accent);
  color: white;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================
   AUTH SCREEN
   ============================================ */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  position: relative;
  overflow: hidden;
}

/* Animated background gradient */
.auth-screen::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 30% 50%, rgba(108, 92, 231, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 50%, rgba(0, 206, 201, 0.05) 0%, transparent 50%);
  animation: auth-bg-drift 20s ease-in-out infinite alternate;
}

@keyframes auth-bg-drift {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(2%, 2%) rotate(3deg); }
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 48px 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  text-align: center;
  margin-bottom: 36px;
}

.auth-logo {
  font-size: 48px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 20px rgba(108, 92, 231, 0.3));
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.form-group {
  margin-bottom: 14px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-top: 4px;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-glow);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 20px;
}

.auth-error {
  text-align: center;
  color: var(--danger);
  font-size: 13px;
  margin-top: 14px;
  padding: 10px;
  background: rgba(255, 107, 107, 0.08);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 107, 107, 0.15);
}

/* ============================================
   APP LAYOUT
   ============================================ */
.app-screen {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
  z-index: 50;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  font-size: 22px;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.btn-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

/* Workspace List */
.workspace-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.ws-group {
  margin-bottom: 4px;
}

.ws-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  user-select: none;
}

.ws-header:hover {
  background: var(--bg-hover);
}

.ws-header.active {
  background: var(--bg-active);
}

.ws-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.ws-header.active .ws-name {
  color: var(--text-primary);
}

.ws-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.ws-header:hover .ws-actions {
  opacity: 1;
}

.ws-action-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  transition: all var(--transition-fast);
}

.ws-action-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.ws-action-btn.delete:hover {
  color: var(--danger);
}

.ws-threads {
  padding-left: 8px;
}

.thread-item {
  display: flex;
  align-items: center;
  padding: 7px 10px 7px 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
}

.thread-item::before {
  content: '';
  position: absolute;
  left: 10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-fast);
}

.thread-item:hover {
  background: var(--bg-hover);
}

.thread-item.active {
  background: var(--accent-subtle);
}

.thread-item.active::before {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.thread-name {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.thread-item.active .thread-name {
  color: var(--text-primary);
}

.thread-item:hover .thread-name {
  color: var(--text-secondary);
}

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--success));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-deep);
}

/* --- Top Bar --- */
.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-height);
  padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  gap: 12px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 1;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* ============================================
   CHAT AREA
   ============================================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 20px;
  filter: grayscale(0.3);
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
}

/* Chat Empty State (no thread selected) */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.chat-empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.chat-empty-text {
  font-size: 14px;
  color: var(--text-muted);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 0;
  animation: msg-fade-in 0.3s ease;
}

@keyframes msg-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--success), #00b894);
  color: white;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.thread-delete-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}
.thread-item:hover .thread-delete-btn { opacity: 0.6; }
.thread-delete-btn:hover { opacity: 1 !important; color: #e74c3c; }

.ws-name, .thread-name { cursor: default; }
.ws-name:hover, .thread-name:hover { text-decoration: underline dotted; }

.message.user .message-role { color: var(--accent); }
.message.assistant .message-role { color: var(--success); }


.message-text {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  word-wrap: break-word;
}

.message-text p { margin-bottom: 8px; }
.message-text p:last-child { margin-bottom: 0; }

/* Headings */
.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
  color: var(--text-primary);
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 10px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child { margin-top: 0; }
.message-text h1 { font-size: 22px; }
.message-text h2 { font-size: 18px; padding-bottom: 6px; border-bottom: 1px solid var(--border-default); }
.message-text h3 { font-size: 16px; }
.message-text h4 { font-size: 15px; }
.message-text h5 { font-size: 14px; }
.message-text h6 { font-size: 13px; color: var(--text-secondary); }

/* Horizontal Rule */
.message-text hr {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 16px 0;
}

/* Blockquote */
.message-text blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--accent-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}
.message-text blockquote p { margin-bottom: 4px; }
.message-text blockquote p:last-child { margin-bottom: 0; }

/* Lists */
.message-text ul,
.message-text ol {
  margin: 8px 0;
  padding-left: 24px;
}
.message-text ul { list-style-type: disc; }
.message-text ol { list-style-type: decimal; }
.message-text li {
  margin-bottom: 4px;
  line-height: 1.6;
}
.message-text li > ul,
.message-text li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

/* Table */
.message-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}
.message-text thead {
  background: var(--bg-elevated);
}
.message-text th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}
.message-text td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-primary);
}
.message-text tbody tr:hover {
  background: var(--bg-hover);
}
.message-text tbody tr:last-child td {
  border-bottom: none;
}

/* Links inside messages */
.message-text a {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.message-text a:hover {
  color: var(--accent);
}

/* Strong / Em */
.message-text strong { color: var(--text-primary); font-weight: 600; }
.message-text em { color: var(--text-secondary); }

.message-text code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Fira Code', 'Consolas', monospace;
  color: var(--accent-hover);
}

.message-text pre {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: var(--text-primary);
}

/* Thinking indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.thinking-text {
  font-size: 13px;
  font-style: italic;
  color: var(--success);
  animation: thinking-glow 2s ease-in-out infinite;
  letter-spacing: 0.5px;
}

@keyframes thinking-glow {
  0%, 100% { opacity: 0.5; text-shadow: 0 0 4px rgba(0, 184, 148, 0); }
  50% { opacity: 1; text-shadow: 0 0 12px rgba(0, 184, 148, 0.35); }
}

/* ============================================
   INPUT AREA
   ============================================ */
.input-area {
  padding: 16px 24px 20px;
  background: var(--bg-deep);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 18px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 8px 0;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow-glow);
}

.send-btn:disabled {
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
.mobile-only { display: none; }

@media (max-width: 768px) {
  .mobile-only { display: flex; }
  
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .messages { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }
}

/* ============================================
   UTILITY
   ============================================ */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Loading spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Power Tools ────────────────── */
.power-tools {
  padding: 8px 12px;
  margin-top: auto;
  border-top: 1px solid var(--border-default);
}

.power-tools-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 6px;
  padding: 0 4px;
}

.power-tool-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.power-tool-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
}

.pt-icon {
  font-size: 18px;
  line-height: 1;
}

.pt-name {
  font-weight: 500;
}

/* ── Power Tool iframe Overlay ──── */
.power-tool-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  animation: fadeInOverlay 0.25s ease;
}

.power-tool-overlay.hidden {
  display: none;
}

.power-tool-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #060d06;
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}
