/* ═══════════════════════════════════════════════════════════════
   InsightForge — Design System
   Aesthetic: Industrial / Utilitarian Dark
   Fonts: Syne (display) + DM Mono (code/data)
═══════════════════════════════════════════════════════════════ */

:root {
  --bg-base:        #0c0d0f;
  --bg-surface:     #131519;
  --bg-elevated:    #1a1d23;
  --bg-hover:       #1f232b;

  --border:         #252830;
  --border-active:  #3a3f4d;

  --text-primary:   #e8eaf0;
  --text-secondary: #8892a4;
  --text-muted:     #525c6e;

  --accent:         #5b8def;
  --accent-dim:     rgba(91, 141, 239, 0.12);
  --accent-border:  rgba(91, 141, 239, 0.3);

  --success:        #3ecf8e;
  --success-dim:    rgba(62, 207, 142, 0.1);
  --warning:        #f5a623;
  --warning-dim:    rgba(245, 166, 35, 0.1);
  --danger:         #ef5b5b;
  --danger-dim:     rgba(239, 91, 91, 0.1);

  --radius:         6px;
  --radius-lg:      10px;
  --font-display:   'Syne', sans-serif;
  --font-mono:      'DM Mono', monospace;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font-display);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Navbar ────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  font-size: 1.4rem;
  color: var(--accent);
  line-height: 1;
}

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-version {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s;
}

.nav-link:hover, .nav-link.active { color: var(--text-primary); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #4a7de0; border-color: #4a7de0; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-active);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent-border); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-elevated); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(239,91,91,0.3);
}
.btn-danger:hover { background: rgba(239,91,91,0.2); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-disabled { opacity: 0.4; pointer-events: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Flash messages ─────────────────────────────────────────── */
.flash-container { padding: 0.75rem 2rem 0; }
.flash {
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}
.flash-error   { background: var(--danger-dim);  color: var(--danger);  border: 1px solid rgba(239,91,91,0.3); }
.flash-success { background: var(--success-dim); color: var(--success); border: 1px solid rgba(62,207,142,0.3); }
.flash-warning { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(245,166,35,0.3); }

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
}

.back-link {
  display: inline-block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text-secondary); }

.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* ── Tags & Badges ──────────────────────────────────────────── */
.tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.tag-success { background: var(--success-dim); color: var(--success); border-color: rgba(62,207,142,0.3); }

/* ── Status badges ──────────────────────────────────────────── */
.project-status {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-created  { background: var(--bg-elevated); color: var(--text-muted); border: 1px solid var(--border); }
.status-uploaded { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(245,166,35,0.3); }
.status-extracted { background: var(--success-dim); color: var(--success); border: 1px solid rgba(62,207,142,0.3); }

/* ── Projects grid ──────────────────────────────────────────── */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: border-color 0.15s, transform 0.15s;
}
.project-card:hover {
  border-color: var(--border-active);
  transform: translateY(-1px);
}

.project-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.project-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.project-client {
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.project-description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.project-date {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.project-actions {
  display: flex;
  gap: 0.5rem;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.empty-state h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.empty-state p { margin-bottom: 1.5rem; font-size: 0.875rem; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-container { max-width: 600px; }

.project-form { display: flex; flex-direction: column; gap: 1.25rem; }

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.required { color: var(--danger); }

.form-input, .form-select, .form-textarea {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.875rem;
  padding: 0.6rem 0.875rem;
  transition: border-color 0.15s;
  outline: none;
  width: 100%;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-input-sm { max-width: 200px; }

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

.form-textarea { resize: vertical; min-height: 80px; }

.form-select option { background: var(--bg-elevated); }

.form-actions {
  display: flex;
  gap: 0.75rem;
  padding-top: 0.5rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] { accent-color: var(--accent); }

.input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* ── Steps ──────────────────────────────────────────────────── */
.steps-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.step-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: border-color 0.15s;
}

.step-done { border-color: rgba(62,207,142,0.3); }
.step-disabled { opacity: 0.5; pointer-events: none; }

.step-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.step-done .step-number {
  background: var(--success-dim);
  border-color: rgba(62,207,142,0.4);
  color: var(--success);
}

.step-title {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}

.step-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--success);
  background: var(--success-dim);
  border: 1px solid rgba(62,207,142,0.3);
  padding: 2px 8px;
  border-radius: 4px;
}

.step-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* ── Upload zone ────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border-active);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 0.75rem;
  position: relative;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon { font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text-muted); }
.upload-text { font-size: 0.875rem; color: var(--text-secondary); }
.upload-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Extract options ────────────────────────────────────────── */
.extract-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* ── Status messages ────────────────────────────────────────── */
.status-message {
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  margin-top: 0.75rem;
  display: none;
}

.status-message:not(:empty) { display: block; }

.status-loading {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  animation: pulse 1.5s infinite;
}

.status-success {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(62,207,142,0.3);
}

.status-error {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(239,91,91,0.3);
}

@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:0.6 } }

/* ── Structure layout ───────────────────────────────────────── */
.structure-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  height: calc(100vh - 180px);
}

.structure-tree {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tree-search { padding: 0.75rem; border-bottom: 1px solid var(--border); }

.tree-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.tree-node { font-size: 0.82rem; }

.tree-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text-secondary);
}

.tree-label:hover { background: var(--bg-elevated); color: var(--text-primary); }
.tree-label.active { background: var(--accent-dim); color: var(--accent); }

.tree-arrow {
  font-size: 0.6rem;
  color: var(--text-muted);
  width: 10px;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.tree-icon { flex-shrink: 0; }
.tree-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tree-children { padding-left: 1rem; }
.tree-children.collapsed { display: none; }

.tree-app > .tree-label { color: var(--text-primary); font-weight: 600; }
.tree-epic > .tree-label { color: var(--text-secondary); }
.tree-leaf .tree-arrow { visibility: hidden; }

.structure-detail {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-y: auto;
  padding: 1.5rem;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
}

.detail-empty-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.detail-empty h3 { font-size: 1rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.detail-empty p { font-size: 0.8rem; }

.detail-loading { color: var(--text-muted); font-size: 0.875rem; padding: 2rem; text-align: center; }
.detail-error { color: var(--danger); font-size: 0.875rem; padding: 2rem; text-align: center; }

/* ── US Detail ──────────────────────────────────────────────── */
.us-detail { max-width: 800px; }

.us-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.us-id {
  display: inline-block;
  margin-bottom: 1.5rem;
}

.us-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.us-section:last-child { border-bottom: none; }

.section-title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

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

.us-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.us-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.us-list li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding-left: 1rem;
  position: relative;
  line-height: 1.5;
}

.us-list li::before {
  content: "–";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

.us-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.us-table th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-active);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.us-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
}

.us-table tr:hover td { background: var(--bg-elevated); }

/* ── Search results ─────────────────────────────────────────── */
.search-results { margin-top: 1rem; }

.result-group { margin-bottom: 1rem; }

.result-group h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: background 0.1s;
}

.result-item.clickable { cursor: pointer; }
.result-item.clickable:hover { background: var(--bg-elevated); color: var(--text-primary); }

.result-id {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ── Import results ─────────────────────────────────────────── */
.import-results { margin-top: 1rem; }

.result-summary {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.result-stat { text-align: center; }

.stat-val {
  display: block;
  font-size: 1.75rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--success);
  line-height: 1;
}

.error-stat .stat-val { color: var(--danger); }

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-link { margin-left: auto; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-active); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Hint ───────────────────────────────────────────────────── */
.hint { font-size: 0.75rem; color: var(--text-muted); }
.error { color: var(--danger); font-size: 0.8rem; }
