/* ============================================================
   AI Vulnerability Intelligence Dashboard — Design System
   ============================================================ */

:root {
  /* High-Contrast Color Palette */
  --bg-deep: #020617;
  /* Slate-950 */
  --bg-surface: #0f172a;
  /* Slate-900 */
  --bg-card: #1e293b;
  /* Slate-800 */

  --border: rgba(255, 255, 255, 0.08);
  --border-active: rgba(34, 197, 94, 0.3);

  --text-primary: #b6a7a7;
  --text-secondary: #ffffff;
  --text-muted: #64748b;

  /* Brand Colors */
  --accent: #22c55e;
  --blue: #3b82f6;
  --critical: #ef4444;
  --high: #f97316;
  --medium: #eab308;
  --low: #10b981;

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 70px;
  --radius: 8px;
  --glass: rgba(15, 23, 42, 0.6);
}

/* ─── Base Styles ────────────────────────────────────────────── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ─── KNOWLEDGE BASE & CHAT ────────────────────────────── */

/* KB Grid & Cards */
.kb-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.kb-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.kb-card .category-tag {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.75rem;
  display: block;
}

.kb-card h4 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.kb-card .kb-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* KB Detail View */
.kb-detail-body {
  padding: 1.5rem;
  color: var(--text-primary);
  line-height: 1.6;
}

.kb-detail-body h5 {
  color: var(--accent);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.kb-detail-body ul {
  padding-left: 1.5rem;
}

/* Chat Container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.05), transparent);
}

.user-msg,
.ai-msg {
  max-width: 80%;
  margin-bottom: 0.5rem;
}

.user-msg {
  align-self: flex-end;
}

.ai-msg {
  align-self: flex-start;
}

.msg-bubble {
  padding: 0.85rem 1.25rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.user-msg .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg .msg-bubble {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-input-area {
  padding: 1.25rem;
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 1rem;
}

.chat-input-area input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  color: #fff;
  font-family: inherit;
  transition: border-color 0.3s ease;
}

.chat-input-area input:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-input-area button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.chat-input-area button:hover {
  transform: scale(1.05);
  background: #10b981;
}

/* Utility */
.hidden {
  display: none !important;
}

/* ─── Authentication Page ────────────────────────────────────── */
#authPage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, #1e293b, #020617);
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-header i {
  font-size: 3rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

.auth-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-toggle {
  display: flex;
  background: var(--bg-deep);
  padding: 0.25rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
}

.auth-toggle button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.auth-toggle button.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.form-group input {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--border-active);
}

.btn-large {
  width: 100%;
  padding: 0.9rem;
  background: var(--accent);
  color: #020617;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s ease;
}

.btn-large:hover {
  filter: brightness(1.1);
}

.btn-large:active {
  transform: scale(0.98);
}

.error-msg {
  color: var(--critical);
  font-size: 0.85rem;
  margin-top: 1rem;
  text-align: center;
  min-height: 1.25rem;
}

/* ─── Dashboard Layout ────────────────────────────────────────── */
#dashboardPage {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent);
  color: #020617;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
}

/* ─── SPA Page Routing ────────────────────────────────────────── */
.page {
  display: none;
}

.page.active {
  display: block;
}

#page-chat.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
}

/* ─── Components ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 1.5rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card .label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 800;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
}

/* ─── Tables ─────────────────────────────────────────────────── */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

/* ─── AI Insights ───────────────────────────────────────────── */
.ai-insights-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.ai-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

.ai-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.4rem;
}

.ai-dot.critical {
  background: var(--critical);
  box-shadow: 0 0 10px var(--critical);
}

.ai-dot.high {
  background: var(--high);
}

.ai-dot.medium {
  background: var(--medium);
}

.ai-dot.low {
  background: var(--low);
}

/* ─── Utils ─────────────────────────────────────────────────── */
.text-critical {
  color: var(--critical);
}

.text-high {
  color: var(--high);
}

.text-medium {
  color: var(--medium);
}

.text-low {
  color: var(--low);
}