/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --bg:          #0d0d12;
  --bg2:         #13131b;
  --bg3:         #1a1a26;
  --border:      #242436;
  --accent:      #4f8ef7;
  --accent2:     #6f6fff;
  --accent-glow: rgba(79,142,247,.25);
  --success:     #22c55e;
  --danger:      #ef4444;
  --warn:        #f59e0b;
  --text:        #e8e8f0;
  --text2:       #9898b8;
  --text3:       #5a5a7a;
  --sidebar-w:   220px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.5);
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }

/* ── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand-icon { font-size: 22px; }
.brand-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--text);
}
.nav-links { list-style: none; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  margin: 2px 8px;
  color: var(--text2);
  transition: background .15s, color .15s;
  position: relative;
  font-size: 14px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(79,142,247,.18), rgba(111,111,255,.08));
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}
.nav-icon { font-size: 16px; width: 22px; text-align: center; }
.badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 7px;
  min-width: 22px;
  text-align: center;
}
.sidebar-footer {
  padding: 14px 18px 0;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}
.loaded-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text2);
  word-break: break-all;
}
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-green  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot-yellow { background: var(--warn); }

/* ── Main ──────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 36px;
  position: relative;
}

/* ── Pages ─────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; letter-spacing: -.3px; }
.subtitle { font-size: 13px; color: var(--text2); }

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .6px; }
.card-body { padding: 20px; }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text2); letter-spacing: .3px; }
.form-row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.flex-1 { flex: 1; }
.input-full {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input-full:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.input-full::placeholder { color: var(--text3); }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  padding: 9px 0;
}
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  transition: opacity .15s, transform .1s, box-shadow .15s;
}
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 4px 18px var(--accent-glow); }
.btn-ghost {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.btn-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
  transition: background .15s, color .15s;
}
.btn-close:hover { background: var(--bg3); color: var(--text); }

/* ── Progress ──────────────────────────────────────────────────────── */
.progress-bar-wrap {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  margin: 10px 0;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width .3s ease;
}
.job-status { font-size: 13px; color: var(--text2); }
.progress-pct { font-size: 12px; color: var(--text3); text-align: right; }

/* ── Success banner ────────────────────────────────────────────────── */
.success-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: linear-gradient(90deg, rgba(34,197,94,.1), rgba(34,197,94,.04));
  border: 1px solid rgba(34,197,94,.3);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.success-icon { font-size: 24px; }
.success-banner > div { flex: 1; }
.success-title { font-weight: 600; margin-bottom: 2px; }
.success-sub { font-size: 12px; color: var(--text2); }

/* ── Toolbar ───────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.search-input {
  flex: 1;
  min-width: 220px;
  padding: 9px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.search-input::placeholder { color: var(--text3); }
.group-select {
  min-width: 260px;
  max-width: 320px;
  padding: 9px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.group-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}
.chip.active { background: rgba(79,142,247,.15); border-color: var(--accent); color: var(--accent); }

/* ── Groups Grid ───────────────────────────────────────────────────── */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.group-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
  user-select: none;
}
.group-card:hover { border-color: var(--text3); background: var(--bg3); }
.group-card.selected {
  border-color: var(--accent);
  background: rgba(79,142,247,.08);
  box-shadow: 0 0 0 1px var(--accent);
}
.group-check {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid var(--border);
  background: transparent;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s;
}
.group-card.selected .group-check {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
}
.group-info { flex: 1; overflow: hidden; }
.group-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.group-count { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ── Scan / Output lists ───────────────────────────────────────────── */
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.file-row:last-child { border-bottom: none; }
.file-icon { font-size: 20px; flex-shrink: 0; }
.file-info { flex: 1; overflow: hidden; }
.file-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
.file-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Link rows ─────────────────────────────────────────────────────── */
.link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.link-row:last-child { border-bottom: none; }
.link-text { flex: 1; overflow: hidden; }
.link-name { font-size: 13px; font-weight: 600; }
.link-url { font-size: 11px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.link-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 480px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.extract-summary {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text2);
  max-height: 200px;
  overflow-y: auto;
}
.extract-summary .group-pill {
  display: inline-block;
  background: rgba(79,142,247,.12);
  border: 1px solid rgba(79,142,247,.3);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  margin: 3px;
  color: var(--accent);
}

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 260px;
  max-width: 360px;
  animation: slideIn .2s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warn); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Misc ──────────────────────────────────────────────────────────── */
.text-muted { font-size: 13px; color: var(--text3); }
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--text3);
  font-size: 14px;
  text-align: center;
}
.empty-icon { font-size: 40px; opacity: .5; }
.hidden { display: none !important; }
