/* ============================================================
   MCSHA — App Design System
   Dark theme · Steam-industrial aesthetic · Modern UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg-base:        #fdfbf7;
  --bg-surface:     #f5f3ec;
  --bg-elevated:    #ffffff;
  --bg-overlay:     #eae6db;
  --border:         #e0dcd0;
  --border-bright:  #c8c3b5;

  --accent:         #8eb271;
  --accent-hover:   #789c5b;
  --accent-glow:    rgba(142,178,113,0.18);
  --success:        #34d399;
  --warning:        #fbbf24;
  --danger:         #f87171;
  --info:           #a78bfa;

  --text-primary:   #2c2b29;
  --text-secondary: #5c5a56;
  --text-muted:     #8a8782;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.12);

  --sidebar-w: 240px;
  --header-h:  60px;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; }

/* ── Layout ────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}
.sidebar-logo {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
}
.sidebar-logo .logo-icon {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent), #598547);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 10px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
}
.nav-item:hover, .nav-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.nav-item.active { color: var(--accent); }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

/* Main area */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0; z-index: 90;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.page-body { padding: 28px 28px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -1px;
}
.card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
}

/* Grid for two columns */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-elevated); }
tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

/* ── Badges / Pills ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-blue    { background: rgba(79,142,247,0.15); color: #4f8ef7; }
.badge-green   { background: rgba(52,211,153,0.15); color: var(--success); }
.badge-yellow  { background: rgba(251,191,36,0.15);  color: var(--warning); }
.badge-red     { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-purple  { background: rgba(167,139,250,0.15); color: var(--info); }
.badge-gray    { background: var(--bg-overlay);      color: var(--text-muted); }

/* match_type badges */
.badge-semantic { background: rgba(167,139,250,0.15); color: var(--info); }
.badge-keyword  { background: rgba(142,178,113,0.15); color: var(--accent); }
.badge-both     { background: rgba(52,211,153,0.15);  color: var(--success); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-overlay); }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--danger); border: 1px solid rgba(248,113,113,0.25); }
.btn-danger:hover { background: rgba(248,113,113,0.25); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-elevated); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control option { background: var(--bg-elevated); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 18px;
}
.filter-bar .form-control { flex: 1; min-width: 140px; }

/* Search bar */
.search-bar-wrap {
  position: relative;
  flex: 1;
}
.search-bar-wrap .search-icon {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-bar-wrap .form-control { padding-left: 36px; }

/* ── Upload / Dropzone ─────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border-bright);
  border-radius: var(--radius-md);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-elevated);
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.dropzone-icon { font-size: 32px; margin-bottom: 10px; color: var(--text-muted); }
.dropzone-label { font-size: 13px; color: var(--text-secondary); }
.dropzone-label span { color: var(--accent); }

/* ── Timeline builder ──────────────────────────────────────── */
.timeline-row {
  display: grid;
  grid-template-columns: 160px 1fr 130px auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* ── Image gallery ─────────────────────────────────────────── */
.image-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.image-thumb {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
  background: var(--bg-elevated);
}
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-thumb .img-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s;
}
.image-thumb:hover .img-overlay { opacity: 1; }

/* ── Chat UI ───────────────────────────────────────────────── */
.chat-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; height: calc(100vh - var(--header-h) - 56px); }
.chat-thread {
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 85%; }
.msg-user { align-self: flex-end; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
}
.msg-user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-ai .msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.source-pill {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  background: var(--accent-glow);
  border: 1px solid rgba(142,178,113,0.3);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
}
.source-pill:hover { background: rgba(142,178,113,0.3); }
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.chat-input-bar textarea {
  flex: 1;
  resize: none;
  height: 44px;
  max-height: 120px;
  overflow-y: auto;
}
.chat-sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

/* ── Search results ────────────────────────────────────────── */
.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.result-card:hover {
  border-color: var(--border-bright);
  box-shadow: var(--shadow-sm);
}
.result-card-icon {
  font-size: 22px;
  margin-top: 2px;
}
.result-card-body { flex: 1; }
.result-card-title { font-weight: 600; margin-bottom: 4px; }
.result-card-meta { font-size: 12px; color: var(--text-muted); }

/* ── Toast ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  min-width: 260px;
  animation: slideUp 0.2s ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent); }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: min(520px, 95vw);
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.18s ease;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Pagination ────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  margin-top: 20px;
}
.pagination .page-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.pagination .page-btn:hover, .pagination .page-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Utility ───────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.mt-1 { margin-top: 6px; }  .mt-2 { margin-top: 12px; }  .mt-3 { margin-top: 20px; }
.mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 20px; }
.flex { display: flex; } .flex-center { display: flex; align-items: center; }
.gap-1 { gap: 6px; } .gap-2 { gap: 12px; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.mono { font-family: var(--font-mono); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 42px; margin-bottom: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Loading spinner ───────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .two-col, .form-row { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
}
