/* Theme Variables: Nuclear Law & Safety Edition (IAEA Cobalt & Deep Ocean) */
:root {
  --primary-color: #0284c7;        /* IAEA Cobalt Blue */
  --primary-hover: #0369a1;        /* Deep Nuclear Blue */
  --primary-light: #e0f2fe;        /* Soft Ice Blue */
  --primary-glow: rgba(2, 132, 199, 0.22);
  
  --accent-cyan: #06b6d4;          /* Radiation Safety Cyan */
  --success-color: #059669;        /* Verified Emerald Green */
  --success-light: #ecfdf5;
  --error-color: #e11d48;
  --error-light: #fff1f2;
  
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #f1f5f9;
  --bg-bubble-user: #0369a1;       /* Prestigious Deep Blue */
  --bg-bubble-bot: #ffffff;
  --bg-input: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-bubble-user: #ffffff;
  --text-bubble-bot: #1e293b;
  
  --border-color: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --primary-color: #38bdf8;        /* Vivid Atomic Cyan/Blue */
  --primary-hover: #7dd3fc;
  --primary-light: #082f49;
  --primary-glow: rgba(56, 189, 248, 0.28);
  
  --accent-cyan: #22d3ee;
  --success-color: #10b981;
  --success-light: #064e3b;
  --error-color: #f43f5e;
  --error-light: #4c0519;
  
  --bg-main: #0a0f1d;             /* Cosmic Nuclear Navy */
  --bg-card: #111827;
  --bg-sidebar: #0d1527;
  --bg-bubble-user: #0284c7;       /* Glowing Cyan/Blue */
  --bg-bubble-bot: #162033;
  --bg-input: #111827;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-bubble-user: #ffffff;
  --text-bubble-bot: #f1f5f9;
  
  --border-color: #1e293b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* App Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-main);
}

/* Documents Sidebar */
.documents-sidebar {
  width: 320px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding: 16px;
  gap: 16px;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-title h3 {
  font-size: 1rem;
  font-weight: 700;
}

.btn-icon-sm {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: none; /* Desktop default */
}

/* Workspace Card */
.workspace-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ws-info {
  display: flex;
  flex-direction: column;
}

.ws-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ws-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-color);
}

.btn-secondary-sm {
  background: var(--primary-light);
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary-sm:hover {
  background: var(--primary-color);
  color: white;
}

/* Upload Dropzone */
.upload-section h4 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  padding: 18px 12px;
  text-align: center;
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

.upload-icon {
  font-size: 24px;
  margin-bottom: 4px;
  display: block;
}

.dropzone p {
  font-size: 0.85rem;
  margin-bottom: 2px;
}

.file-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
}

/* Upload Status Card */
.upload-status-card {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
}

.upload-status-card.verifying {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

.upload-status-card.success {
  border-color: var(--success-color);
  background: var(--success-light);
}

.upload-status-card.error {
  border-color: var(--error-color);
  background: var(--error-light);
}

.status-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 4px;
}

.status-desc {
  font-size: 0.78rem;
  color: var(--text-main);
  line-height: 1.3;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--primary-color);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* Documents List */
.documents-list-section {
  flex: 1;
}

.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.docs-header h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.badge {
  background: var(--primary-color);
  color: white;
  border-radius: 12px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
}

.docs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}

.empty-docs {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 0;
}

.doc-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.doc-title {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-delete-doc {
  background: none;
  border: none;
  color: var(--error-color);
  cursor: pointer;
  padding: 4px;
  font-size: 0.85rem;
  border-radius: 4px;
}

.btn-delete-doc:hover {
  background: var(--error-light);
}

/* Baseline Toggle */
.baseline-toggle-section {
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-main);
}

.toggle-container input {
  accent-color: var(--primary-color);
  width: 16px;
  height: 16px;
}

/* Chat Main Viewport */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: var(--bg-card);
}

.app-header {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}

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

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

.logo-icon {
  font-size: 26px;
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

.brand-text .subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.brand-text .subtitle strong {
  color: var(--primary-color);
}

.badge-mini {
  background: var(--primary-color);
  color: white;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: 4px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

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

/* Chat Viewport & Messages */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.welcome-card {
  background: var(--primary-light);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-color);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  margin-bottom: 12px;
}

.welcome-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.welcome-card h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.welcome-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 18px;
}

.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chips-title {
  width: 100%;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.chip-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
}

.chip-btn:hover {
  background-color: var(--primary-color);
  color: #ffffff;
  border-color: var(--primary-color);
}

/* Messages */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-row {
  display: flex;
  gap: 12px;
  max-width: 85%;
}

.message-row.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message-row.assistant {
  margin-right: auto;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background-color: var(--border-color);
}

.message-row.user .message-avatar {
  background-color: var(--primary-color);
  color: white;
}

.message-row.assistant .message-avatar {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.message-bubble {
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 0.95rem;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.message-row.user .message-bubble {
  background-color: var(--bg-bubble-user);
  color: var(--text-bubble-user);
  border-bottom-right-radius: 4px;
}

.message-row.assistant .message-bubble {
  background-color: var(--bg-bubble-bot);
  color: var(--text-bubble-bot);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

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

/* Sources */
.sources-card {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-color);
  font-size: 0.85rem;
}

.sources-header {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 4px;
}

.sources-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sources-list li {
  color: var(--text-muted);
  font-size: 0.8rem;
  background: var(--primary-light);
  padding: 3px 8px;
  border-radius: 4px;
}

/* Typing */
.typing-indicator {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-left: 46px;
}

.typing-bubble {
  background: var(--bg-bubble-bot);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 6px;
  height: 6px;
  background-color: var(--primary-color);
  border-radius: 50%;
  animation: pulse 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes pulse {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.typing-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 4px;
}

/* Footer & Input */
.chat-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1.5px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.chat-form:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea#userInput {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  max-height: 120px;
  padding: 4px 0;
}

.btn-send {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-send:hover {
  background: var(--primary-hover);
}

.disclaimer {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-card);
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 1.1rem;
}

.modal-body p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group input {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .documents-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  .documents-sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .btn-icon-sm {
    display: block;
  }
  .message-row { max-width: 95%; }
  .chat-viewport { padding: 14px; }
  .app-header { padding: 10px 14px; }
  .chat-footer { padding: 12px 14px; }
}
