/* ============================================================
   LexIA — Stylesheet
   Bastion IT — Interface professionnelle pour juristes
   ============================================================ */

/* ---------------------------------------------------------
   1. CSS Variables
   --------------------------------------------------------- */
:root {
  --navy: #1B2E52;
  --navy-dark: #0F1A2E;
  --navy-light: #243B60;
  --navy-mid: #1E3461;
  --green: #1FA855;
  --green-dark: #178A45;
  --green-light: #25C966;
  --green-glow: rgba(31, 168, 85, 0.12);
  --surface: #F7F9FB;
  --surface-alt: #EDF1F5;
  --white: #FFFFFF;
  --text: #1E293B;
  --text-light: #5A6A7E;
  --text-muted: #94A3B8;
  --border: #DDE3EB;
  --red: #E53E3E;
  --red-bg: #FFF5F5;
  --orange: #DD6B20;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

table {
  border-collapse: collapse;
  width: 100%;
}

img {
  max-width: 100%;
  display: block;
}

/* ---------------------------------------------------------
   3. Navbar
   --------------------------------------------------------- */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 900;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.nav-logo img {
  height: 32px;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  height: 56px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.nav-link:hover {
  color: var(--white);
  border-bottom-color: var(--green);
}

.nav-link.active {
  color: var(--white);
  border-bottom-color: var(--green);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.nav-user-name {
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}

.nav-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--white);
}

.nav-logout {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.nav-logout:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}

.nav-mobile-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  cursor: pointer;
}

.nav-mobile-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--white);
  border-radius: 1px;
  transition: transform var(--transition), opacity var(--transition);
}

/* ---------------------------------------------------------
   4. Login Page
   --------------------------------------------------------- */
#page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--surface);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.login-logo img {
  height: 48px;
  width: auto;
}

.login-title {
  text-align: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.login-subtitle {
  text-align: center;
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

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

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

.login-submit {
  width: 100%;
  height: 48px;
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  margin-top: 8px;
}

.login-submit:hover {
  background: var(--green-dark);
}

.login-submit:active {
  background: var(--green-dark);
  transform: translateY(1px);
}

.login-error {
  background: var(--red-bg);
  color: var(--red);
  font-size: 0.85rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-align: center;
}

/* ---------------------------------------------------------
   5. Documents Page
   --------------------------------------------------------- */
#page-documents {
  padding-top: 80px;
  padding-bottom: 40px;
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
}

/* Upload Zone */
#upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 60px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 32px;
}

#upload-zone:hover,
#upload-zone.upload-zone-active {
  border-color: var(--green);
  background: var(--green-glow);
}

.upload-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.upload-zone-active .upload-icon {
  color: var(--green);
}

.upload-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Upload Progress */
.upload-progress {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.upload-progress-info {
  flex: 1;
  min-width: 0;
}

.upload-progress-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface-alt);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.upload-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 200ms ease;
}

.upload-progress-pct {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  flex-shrink: 0;
}

/* Documents Table */
.documents-table-wrap {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.documents-table {
  width: 100%;
}

.documents-table th {
  background: var(--surface-alt);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.documents-table td {
  padding: 14px 16px;
  font-size: 0.9rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.documents-table tr:last-child td {
  border-bottom: none;
}

.documents-table tbody tr {
  transition: background var(--transition);
}

.documents-table tbody tr:hover {
  background: var(--surface);
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
}

.status-ready {
  background: var(--green-glow);
  color: var(--green-dark);
}

.status-processing {
  background: rgba(221, 107, 32, 0.1);
  color: var(--orange);
}

.status-error {
  background: var(--red-bg);
  color: var(--red);
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Delete button (inline table) */
.btn-delete-row {
  font-size: 0.8rem;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  background: transparent;
  transition: background var(--transition), color var(--transition);
}

.btn-delete-row:hover {
  background: var(--red);
  color: var(--white);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 0.95rem;
}

/* ---------------------------------------------------------
   6. Chat Page
   --------------------------------------------------------- */
#page-chat {
  height: calc(100vh - 56px);
  margin-top: 56px;
  display: flex;
  overflow: hidden;
}

/* Chat Sidebar */
#chat-history {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.chat-sidebar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.chat-new-btn {
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.chat-new-btn:hover {
  background: var(--green-glow);
}

.chat-sessions {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}

.chat-session-item {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-light);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-session-item:hover {
  background: var(--white);
  color: var(--text);
}

.chat-session-item.active {
  background: var(--white);
  color: var(--navy);
  border-left-color: var(--green);
  font-weight: 500;
}

/* Chat Main Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Messages */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 720px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 0.925rem;
  line-height: 1.65;
  word-wrap: break-word;
}

.message-user {
  align-self: flex-end;
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

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

.message-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.message-sources summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-light);
}

.message-sources ul {
  margin-top: 6px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Typing Indicator */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingDot 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingDot {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Chat Input Area */
.chat-input-area {
  padding: 16px 24px;
  background: var(--white);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.chat-input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.925rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  min-height: 44px;
  max-height: 160px;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.chat-input-area textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--green);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
  transition: background var(--transition);
}

.chat-send-btn:hover {
  background: var(--green-dark);
}

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

/* ---------------------------------------------------------
   7. Admin Page
   --------------------------------------------------------- */
#page-admin {
  padding-top: 80px;
  padding-bottom: 40px;
}

/* Services Grid */
.services-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.service-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.service-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.service-card-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.service-card-desc {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.5;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-online {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

.status-offline {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.12);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  text-align: center;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

/* Logs Section */
.logs-section {
  margin-top: 32px;
}

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

.logs-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.logs-container {
  background: var(--navy-dark);
  color: rgba(255, 255, 255, 0.85);
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  padding: 20px;
  border-radius: var(--radius-lg);
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.logs-container::-webkit-scrollbar {
  width: 8px;
}

.logs-container::-webkit-scrollbar-track {
  background: transparent;
}

.logs-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* ---------------------------------------------------------
   8. Confirm Dialog
   --------------------------------------------------------- */
#confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 26, 46, 0.6);
  padding: 24px;
}

#confirm-dialog.visible {
  display: flex;
}

.confirm-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  padding: 32px;
  text-align: center;
}

.confirm-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--red-bg);
  color: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto 20px;
}

.confirm-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.confirm-desc {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 28px;
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-confirm-cancel {
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-light);
  background: var(--white);
  transition: background var(--transition), color var(--transition);
}

.btn-confirm-cancel:hover {
  background: var(--surface);
  color: var(--text);
}

.btn-confirm-action {
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--red);
  color: var(--white);
  transition: background var(--transition);
}

.btn-confirm-action:hover {
  background: #C53030;
}

.btn-confirm-action:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

.confirm-input-wrapper {
  margin-top: 16px;
}

.confirm-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  text-align: center;
  outline: none;
  transition: border-color var(--transition);
}

.confirm-input:focus {
  border-color: var(--red);
}

.text-danger {
  color: var(--red);
}

/* Badge classes (used by app.js) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-success {
  background: var(--green-glow);
  color: var(--green-dark);
}

.badge-warning {
  background: rgba(221, 107, 32, 0.1);
  color: var(--orange);
}

.badge-danger {
  background: var(--red-bg);
  color: var(--red);
}

.badge-default {
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* Chat message classes (used by app.js) */
.chat-message {
  display: flex;
  max-width: 720px;
}

.chat-message-user {
  align-self: flex-end;
}

.chat-message-assistant {
  align-self: flex-start;
}

.chat-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 0.925rem;
  line-height: 1.65;
  word-wrap: break-word;
}

.bubble-user {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

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

.chat-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  opacity: 0.7;
}

.chat-content {
  line-height: 1.65;
}

.chat-content pre {
  background: var(--navy-dark);
  color: rgba(255,255,255,0.9);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.85rem;
}

.chat-content code {
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

.bubble-user .chat-content code {
  background: rgba(255,255,255,0.15);
}

details.chat-sources-inline {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

details.chat-sources-inline summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-light);
}

details.chat-sources-inline ul {
  margin-top: 6px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bubble-user details.chat-sources-inline {
  border-top-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
}

.bubble-user details.chat-sources-inline summary {
  color: rgba(255,255,255,0.85);
}

/* Typing dots */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingDot 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

/* Service status dots (used by app.js renderServices) */
.service-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-ok {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

.dot-warning {
  background: var(--orange);
  box-shadow: 0 0 0 3px rgba(221, 107, 32, 0.12);
}

.dot-error {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.12);
}

.dot-unknown {
  background: var(--text-muted);
}

/* Chat welcome */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  color: var(--text-muted);
}

.chat-welcome-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.chat-welcome h2 {
  color: var(--navy);
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.chat-welcome p {
  font-size: 0.9rem;
  max-width: 400px;
}

/* Loading cell in table */
.loading-cell,
.error-cell,
.empty-cell {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.error-cell {
  color: var(--red);
}

/* btn-sm */
.btn-sm {
  padding: 4px 12px;
  font-size: 0.8rem;
}

/* btn-outline */
.btn-outline {
  background: transparent;
  color: var(--text-light);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--surface);
  color: var(--text);
}

/* btn-block */
.btn-block {
  width: 100%;
}

/* btn-icon */
.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--surface-alt);
}

/* btn-send */
.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  flex-shrink: 0;
}

/* btn-logout */
.btn-logout {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.btn-logout:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}

/* input-wrapper with icon */
.input-wrapper {
  position: relative;
}

.input-wrapper i,
.input-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.input-wrapper input {
  padding-left: 42px;
}

/* login-logo-img */
.login-logo-img {
  height: 64px;
  width: auto;
}

/* Navbar inner layout */
.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
}

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

.navbar-logo {
  height: 32px;
  width: auto;
}

.navbar-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--white);
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.user-name {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Page header flex layout */
.page-header-left,
.page-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Documents section */
.documents-section {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-container {
  overflow-x: auto;
}

/* Upload zone content layout */
.upload-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.upload-formats {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Admin section */
.admin-section {
  max-width: 1200px;
  margin: 0 auto 32px;
  padding: 0 24px;
}

.admin-section h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Service card body */
.service-card-body {
  margin-top: 8px;
}

.service-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-light);
}

.service-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Stat card layout */
.stat-icon {
  margin-bottom: 8px;
  color: var(--navy);
}

.stat-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}

/* Ingestion logs */
.ingestion-logs {
  background: var(--navy-dark);
  color: rgba(255, 255, 255, 0.85);
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  padding: 20px;
  border-radius: var(--radius-lg);
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.empty-state-inline {
  text-align: center;
  padding: 24px;
  color: rgba(255, 255, 255, 0.4);
  font-style: italic;
}

/* Empty state icons */
.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-hint {
  font-size: 0.85rem;
  margin-top: 4px;
}

/* Modal layout */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 26, 46, 0.6);
  padding: 24px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-dialog {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  padding: 32px;
}

.modal-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-icon-warning {
  width: 56px;
  height: 56px;
  color: var(--red);
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.modal-body {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* Chat form layout */
.chat-form {
  width: 100%;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.925rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  min-height: 44px;
  max-height: 200px;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.chat-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

/* Chat sources panel */
.chat-sources {
  border-left: 1px solid var(--border);
  width: 300px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--surface);
}

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

.chat-sources-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-sources-content {
  padding: 16px;
}

/* Chat sidebar session list */
.chat-session-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}

/* ---------------------------------------------------------
   9. User Management
   --------------------------------------------------------- */
.users-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.user-form-container {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 20px;
  box-shadow: var(--shadow-sm);
}

.user-form-container h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 16px;
}

.user-form-container select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.user-form-container select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

/* Users table wrap */
#admin-users-section .documents-table {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ---------------------------------------------------------
   9b. Document Viewer
   --------------------------------------------------------- */
.document-viewer {
  max-width: 1200px;
  margin: 32px auto 0;
  padding: 0 24px;
}

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

.viewer-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80%;
}

.viewer-frame-container {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.viewer-iframe {
  width: 100%;
  height: 80vh;
  border: none;
  display: block;
}

/* Document actions cell */
.doc-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Graph fullscreen mode */
#graph-section.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: var(--white);
  margin: 0;
  padding: 16px;
  max-width: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#graph-section.fullscreen h2 {
  flex-shrink: 0;
}

#graph-section.fullscreen #graph-container {
  flex: 1;
  min-height: 0;
  height: 100% !important;
}

/* Document viewer fullscreen mode */
.document-viewer.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: var(--white);
  margin: 0;
  padding: 16px;
  max-width: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.document-viewer.fullscreen .viewer-header {
  flex-shrink: 0;
}

.document-viewer.fullscreen .viewer-frame-container {
  flex: 1;
}

.document-viewer.fullscreen .viewer-iframe {
  height: 100%;
}

/* ---------------------------------------------------------
   10. Toast Notifications
   --------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--white);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 0.875rem;
  color: var(--text);
  border-left: 4px solid var(--border);
  max-width: 380px;
  animation: toastIn 250ms ease forwards;
}

.toast-success {
  border-left-color: var(--green);
}

.toast-error {
  border-left-color: var(--red);
}

.toast-info {
  border-left-color: var(--navy);
}

.toast-out {
  animation: toastOut 200ms ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ---------------------------------------------------------
   10. Purge / Danger Button
   --------------------------------------------------------- */
#btn-purge,
.btn-danger {
  background: var(--red);
  color: var(--white);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: var(--radius);
  transition: background var(--transition);
}

#btn-purge:hover,
.btn-danger:hover {
  background: #C53030;
}

/* ---------------------------------------------------------
   11. Utility Classes
   --------------------------------------------------------- */
.hidden {
  display: none !important;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

#page-chat.active {
  display: flex;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--green);
  color: var(--white);
  border-color: var(--green);
}

.btn-primary:hover {
  background: var(--green-dark);
  border-color: var(--green-dark);
}

.btn-secondary {
  background: transparent;
  color: var(--navy);
  border-color: var(--navy);
}

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

/* Loading Spinner */
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Fade In */
.fade-in {
  animation: fadeIn 200ms ease forwards;
}

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

/* Scrollbar (general) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------------------------------------------------------
   12. Responsive
   --------------------------------------------------------- */
@media (max-width: 768px) {
  /* Navbar */
  .nav-mobile-toggle {
    display: flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--navy);
    padding: 8px 0;
    box-shadow: var(--shadow-md);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-link {
    height: auto;
    padding: 12px 24px;
    border-bottom: none;
    border-left: 3px solid transparent;
  }

  .nav-link:hover,
  .nav-link.active {
    border-bottom: none;
    border-left-color: var(--green);
    background: rgba(255, 255, 255, 0.05);
  }

  .nav-user {
    display: none;
  }

  /* Chat Page */
  #page-chat {
    flex-direction: column;
  }

  #chat-history {
    width: 100%;
    max-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-sessions {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0;
  }

  .chat-session-item {
    flex-shrink: 0;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 10px 16px;
  }

  .chat-session-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--green);
  }

  #chat-messages {
    padding: 16px;
  }

  .chat-input-area {
    padding: 12px 16px;
  }

  /* Admin Page */
  .services-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Documents Page */
  #upload-zone {
    padding: 40px 16px;
  }

  .page-container {
    padding: 0 16px;
  }

  .documents-table-wrap {
    overflow-x: auto;
  }

  /* Dialog */
  .confirm-box {
    padding: 24px;
  }

  .confirm-actions {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 28px 24px;
  }

  .message {
    max-width: 95%;
  }
}

/* ---------------------------------------------------------
   13. Health Indicator (navbar)
   --------------------------------------------------------- */
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--text-muted);
  margin-right: 8px;
  flex-shrink: 0;
}

.health-ok {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.health-error {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
  animation: healthPulse 1.5s ease infinite;
}

@keyframes healthPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------------------------------------------------------
   14. Document Search Bar
   --------------------------------------------------------- */
.documents-toolbar {
  margin-bottom: 16px;
}

.search-wrapper {
  position: relative;
  max-width: 400px;
}

.search-wrapper i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}

.doc-search-input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  background: var(--white);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.doc-search-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

/* ---------------------------------------------------------
   15. Dark Mode
   --------------------------------------------------------- */
body.dark-mode {
  --navy: #0F1A2E;
  --navy-dark: #080E18;
  --navy-light: #1B2E52;
  --surface: #111827;
  --surface-alt: #1F2937;
  --white: #1E293B;
  --text: #E2E8F0;
  --text-light: #94A3B8;
  --text-muted: #64748B;
  --border: #334155;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

body.dark-mode .login-card,
body.dark-mode .service-card,
body.dark-mode .stat-card,
body.dark-mode .documents-table,
body.dark-mode .chat-messages,
body.dark-mode .modal-dialog {
  background: var(--surface-alt);
  color: var(--text);
}

body.dark-mode .navbar {
  background: var(--navy-dark);
}

body.dark-mode input,
body.dark-mode textarea,
body.dark-mode select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

body.dark-mode .upload-zone {
  background: var(--surface-alt);
  border-color: var(--border);
}

body.dark-mode .upload-zone.drag-over {
  border-color: var(--green);
  background: rgba(31, 168, 85, 0.08);
}

body.dark-mode .chat-bubble.bubble-assistant {
  background: var(--surface-alt);
  color: var(--text);
}

body.dark-mode .chat-bubble.bubble-user {
  background: var(--navy-light);
  color: var(--text);
}

body.dark-mode .chat-sidebar {
  background: var(--surface);
  border-color: var(--border);
}

body.dark-mode .badge-default {
  background: var(--surface);
  color: var(--text-light);
}

body.dark-mode .btn-outline {
  border-color: var(--border);
  color: var(--text);
}

body.dark-mode .btn-outline:hover {
  background: var(--surface);
}

body.dark-mode code,
body.dark-mode pre {
  background: var(--surface);
  color: var(--green-light);
}

body.dark-mode .doc-search-input {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

body.dark-mode .toast {
  background: var(--surface-alt);
  color: var(--text);
}

body.dark-mode ::-webkit-scrollbar-thumb {
  background: var(--border);
}

/* Navbar icon buttons (dark mode toggle, etc.) */
.navbar-user .btn-icon {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
}

.navbar-user .btn-icon:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.1);
}
