/* ═══════════════════════════════════════════════════════
   GRC360 AI — Enterprise Policy Intelligence
   Design System & Styles
   ═══════════════════════════════════════════════════════ */

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

:root {
  /* Colours */
  --bg-primary:    #0f1117;
  --bg-secondary:  #161820;
  --bg-tertiary:   #1c1e2a;
  --bg-hover:      #222436;
  --border:        #2a2d3e;
  --border-light:  #363952;

  --text-primary:  #e4e6f0;
  --text-secondary:#9395a5;
  --text-muted:    #6b6e80;
  --text-link:     #7aa2f7;

  --accent:        #7aa2f7;
  --accent-hover:  #5d8bea;
  --accent-glow:   rgba(122,162,247,0.15);
  --success:       #9ece6a;
  --warning:       #e0af68;
  --danger:        #f7768e;
  --info:          #7dcfff;

  /* Category colours */
  --cat-policies:   #bb9af7;
  --cat-laws:       #f7768e;
  --cat-standards:  #7aa2f7;
  --cat-procedures: #9ece6a;
  --cat-guidelines: #e0af68;
  --cat-other:      #7dcfff;

  /* Dimensions */
  --sidebar-width: 340px;
  --radius:        8px;
  --radius-lg:     12px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
}

/* ────────── Utility ────────── */
.hidden { display: none !important; }
.screen { width: 100%; height: 100%; }

/* ────────── Buttons ────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-family: inherit; font-weight: 500; font-size: 0.875rem;
  transition: all 0.2s var(--ease);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #fff; padding: 10px 20px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-full { width: 100%; }
.btn-ghost {
  background: transparent; color: var(--text-secondary); padding: 6px 12px;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-sm { font-size: 0.8rem; padding: 5px 10px; }
.btn-icon {
  background: transparent; color: var(--text-secondary); padding: 6px;
  border-radius: 6px;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger-subtle { color: var(--danger); }
.btn-danger-subtle:hover { background: rgba(247,118,142,0.1); }
.btn-send {
  background: var(--accent); color: #fff; padding: 8px;
  border-radius: 50%; width: 36px; height: 36px; flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.05); }

/* ────────── Forms ────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 10px 12px; font-family: inherit; font-size: 0.9rem;
  background: var(--bg-tertiary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group input::placeholder { color: var(--text-muted); }

/* ═══════════════ LOGIN SCREEN ═══════════════ */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 0%, rgba(122,162,247,0.08), transparent 60%);
}
.login-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 420px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.login-logo { text-align: center; margin-bottom: 28px; color: var(--accent); }
.login-logo h1 { font-size: 1.6rem; margin-top: 10px; color: var(--text-primary); }
.login-logo p { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }
.login-footer {
  text-align: center; margin-top: 18px; font-size: 0.8rem;
  color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 6px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
  display: inline-block; transition: background 0.3s;
}
.status-dot.online  { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* ═══════════════ APP LAYOUT ═══════════════ */
#app-screen { display: flex; }

/* ──── Sidebar ──── */
.sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  height: 100vh; background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform 0.3s var(--ease);
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); min-width: 0; width: 0; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.logo-sm { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--accent); }

.sidebar-section { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.sidebar-section h3 {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 12px;
}
.badge {
  background: var(--bg-hover); color: var(--text-secondary);
  font-size: 0.7rem; padding: 1px 7px; border-radius: 10px; margin-left: auto;
}

/* Tabs */
.upload-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab-btn {
  flex: 1; padding: 7px; font-size: 0.8rem; font-weight: 500; font-family: inherit;
  background: transparent; color: var(--text-muted); border: none;
  border-radius: var(--radius); cursor: pointer; transition: all 0.2s;
}
.tab-btn.active { background: var(--bg-hover); color: var(--text-primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* OCR */
.ocr-options { margin-bottom: 12px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; font-size: 0.85rem; color: var(--text-secondary);
}
.toggle-label { cursor: pointer; }
.toggle-switch { position: relative; width: 38px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--border); border-radius: 10px;
  transition: background 0.3s; cursor: pointer;
}
.toggle-slider::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
  background: var(--text-secondary); border-radius: 50%; transition: transform 0.3s, background 0.3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }
.ocr-lang-group { margin-top: 8px; }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px 16px; text-align: center; cursor: pointer;
  color: var(--text-muted); transition: all 0.2s; margin-bottom: 10px;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent); background: var(--accent-glow);
  color: var(--text-secondary);
}
.drop-zone p { margin-top: 8px; font-size: 0.85rem; }
.drop-zone span { font-size: 0.75rem; color: var(--text-muted); }

.file-name-display {
  font-size: 0.82rem; padding: 6px 10px; background: var(--bg-tertiary);
  border-radius: var(--radius); margin-bottom: 8px; color: var(--text-secondary);
  word-break: break-all;
}

/* Upload Progress */
.upload-progress { padding: 10px 18px; }
.progress-bar {
  height: 4px; background: var(--bg-hover); border-radius: 2px; overflow: hidden; margin-bottom: 6px;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--accent);
  border-radius: 2px; transition: width 0.4s var(--ease);
}
#upload-status-text { font-size: 0.78rem; color: var(--text-muted); }

/* Document Library */
.documents-section { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.category-filter { margin-bottom: 10px; }
.category-filter select {
  width: 100%; padding: 7px 10px; font-family: inherit; font-size: 0.82rem;
  background: var(--bg-tertiary); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.file-list { overflow-y: auto; flex: 1; }
.file-list .empty-state {
  text-align: center; padding: 20px; color: var(--text-muted); font-size: 0.82rem;
}

/* File item */
.file-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  transition: background 0.15s; cursor: default;
}
.file-item:hover { background: var(--bg-hover); }
.file-icon { color: var(--text-muted); flex-shrink: 0; margin-top: 2px; }
.file-info { flex: 1; min-width: 0; }
.file-info .file-title {
  font-size: 0.82rem; font-weight: 500; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-info .file-meta {
  font-size: 0.72rem; color: var(--text-muted); margin-top: 2px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.category-badge {
  display: inline-block; font-size: 0.65rem; font-weight: 600;
  padding: 1px 7px; border-radius: 4px; text-transform: uppercase;
  letter-spacing: 0.04em;
}
.category-badge.policies     { background: rgba(187,154,247,0.15); color: var(--cat-policies); }
.category-badge.laws         { background: rgba(247,118,142,0.15); color: var(--cat-laws); }
.category-badge.standards    { background: rgba(122,162,247,0.15); color: var(--cat-standards); }
.category-badge.procedures   { background: rgba(158,206,106,0.15); color: var(--cat-procedures); }
.category-badge.guidelines   { background: rgba(224,175,104,0.15); color: var(--cat-guidelines); }
.category-badge.other        { background: rgba(125,207,255,0.15); color: var(--cat-other); }
.file-actions { flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.file-item:hover .file-actions { opacity: 1; }
.file-delete-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px; border-radius: 4px;
}
.file-delete-btn:hover { color: var(--danger); background: rgba(247,118,142,0.1); }

/* Category Group Header */
.category-group-header {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: 10px 12px 4px; border-top: 1px solid var(--border); margin-top: 4px;
}
.category-group-header:first-child { border-top: none; margin-top: 0; }

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; min-width: 0; }
.user-details #user-display-id { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-label, .org-label { font-size: 0.7rem; color: var(--text-muted); }

/* ═══════════════ CHAT AREA ═══════════════ */
.chat-area { flex: 1; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.chat-header-left { display: flex; align-items: center; gap: 12px; }
.chat-header h2 { font-size: 1rem; font-weight: 600; }
.sidebar-toggle { display: none; }

/* Messages */
.messages-container {
  flex: 1; overflow-y: auto; padding: 24px; scroll-behavior: smooth;
}

.welcome-message {
  text-align: center; max-width: 560px; margin: 80px auto;
}
.welcome-icon { color: var(--accent); margin-bottom: 16px; }
.welcome-message h2 { font-size: 1.4rem; margin-bottom: 10px; }
.welcome-message p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 28px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.quick-action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; font-size: 0.82rem; font-family: inherit;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-secondary);
  cursor: pointer; transition: all 0.2s;
}
.quick-action:hover { border-color: var(--accent); color: var(--text-primary); background: var(--accent-glow); }

/* Message Bubbles */
.message {
  display: flex; gap: 12px; margin-bottom: 24px; max-width: 800px;
  animation: fadeInUp 0.3s var(--ease);
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.user { flex-direction: row-reverse; margin-left: auto; }
.message-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; flex-shrink: 0;
}
.message.user .message-avatar { background: var(--accent); color: #fff; }
.message.assistant .message-avatar { background: var(--bg-tertiary); color: var(--accent); border: 1px solid var(--border); }

.message-content {
  padding: 12px 16px; border-radius: var(--radius-lg);
  font-size: 0.9rem; line-height: 1.65;
}
.message.user .message-content {
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .message-content {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message.assistant .message-content p { margin-bottom: 8px; }
.message.assistant .message-content p:last-child { margin-bottom: 0; }

/* ── Citation Pills ── */
.citation-pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(122,162,247,0.12); border: 1px solid rgba(122,162,247,0.25);
  color: var(--accent); font-size: 0.72rem; font-weight: 500;
  padding: 2px 8px; border-radius: 4px; margin: 0 2px;
  cursor: default; white-space: nowrap; vertical-align: middle;
  transition: background 0.2s;
}
.citation-pill:hover {
  background: rgba(122,162,247,0.22);
}
.citation-pill svg { flex-shrink: 0; }

/* Sources section at bottom of assistant message */
.sources-summary {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
}
.sources-summary-title {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 6px;
}
.sources-list { display: flex; flex-wrap: wrap; gap: 6px; }
.source-tag {
  font-size: 0.72rem; padding: 3px 8px; border-radius: 4px;
  background: var(--bg-hover); color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* Typing indicator */
.typing-indicator { display: flex; align-items: center; gap: 4px; padding: 8px 0; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Chat Input ── */
.chat-input-area { padding: 16px 24px; border-top: 1px solid var(--border); background: var(--bg-secondary); }
.chat-input-wrapper {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 8px 12px;
  transition: border-color 0.2s;
}
.chat-input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

#chat-input {
  flex: 1; background: transparent; border: none; color: var(--text-primary);
  font-family: inherit; font-size: 0.9rem; resize: none;
  max-height: 140px; outline: none; padding: 4px 0; line-height: 1.5;
}
#chat-input::placeholder { color: var(--text-muted); }

.chat-input-footer {
  text-align: center; margin-top: 8px; font-size: 0.72rem; color: var(--text-muted);
}

/* ═══════════════ TOAST ═══════════════ */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius); font-size: 0.82rem;
  color: #fff; box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  animation: slideIn 0.3s var(--ease);
  max-width: 380px;
}
.toast.success { background: #1a3a2a; border: 1px solid var(--success); color: var(--success); }
.toast.error   { background: #3a1a1a; border: 1px solid var(--danger);  color: var(--danger); }
.toast.info    { background: #1a2a3a; border: 1px solid var(--info);    color: var(--info); }
@keyframes slideIn { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: translateX(0); } }

/* ═══════════════ SCROLLBAR ═══════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 100; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  :root { --sidebar-width: 300px; }
}
