:root {
  --bg: #0d0f17;
  --bg2: #141720;
  --bg3: #1a1e2e;
  --bg4: #1f2437;
  --border: rgba(255,255,255,0.07);
  --accent: #6C63FF;
  --accent2: #3ECFCF;
  --green: #00c864;
  --red: #ff4757;
  --yellow: #f7b731;
  --text: #e2e4f0;
  --text2: #9ca3af;
  --font: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --sidebar-w: 240px;
  --header-h: 120px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ─── TOP HEADER ─────────────────────────────────────────────────────────── */
.lib-header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 20px;
  gap: 10px;
  flex-shrink: 0;
  z-index: 50;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 16px;
}

.lib-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lib-logo-icon { font-size: 1.6rem; }

.lib-logo h1 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  white-space: nowrap;
}

.lib-logo p {
  font-size: 10px;
  color: var(--text2);
  white-space: nowrap;
}

.header-search {
  flex: 1;
  position: relative;
  max-width: 500px;
}

.header-search input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 36px 8px 34px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.header-search input:focus { border-color: var(--accent); }
.header-search .si { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; pointer-events: none; }
.header-search .sc { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--text2); cursor: pointer; font-size: 13px; line-height: 1; padding: 0; }

.header-stats {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.stat-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  text-align: center;
  min-width: 70px;
}

.stat-chip span {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--accent2);
  line-height: 1.2;
}

.stat-chip label {
  font-size: 9px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-chip.green span { color: var(--green); }
.stat-chip.red span { color: var(--red); }

.header-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover { border-color: rgba(108,99,255,0.5); color: var(--text); }
.filter-btn.active { background: rgba(108,99,255,0.15); border-color: var(--accent); color: var(--accent); }

.check-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}

.check-btn:hover { border-color: var(--accent2); color: var(--accent2); }
.check-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.check-progress-bar {
  flex: 1;
  max-width: 200px;
  display: none;
  align-items: center;
  gap: 8px;
}

.check-progress-bar.visible { display: flex; }
.cpb-track { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.cpb-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 2px; width: 0; transition: width 0.3s; }
.cpb-pct { font-size: 11px; color: var(--text2); font-family: var(--mono); min-width: 32px; }

.source-link {
  margin-left: auto;
  font-size: 11px;
  color: var(--text2);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.source-link:hover { opacity: 1; color: var(--accent2); }

/* ─── LAYOUT: sidebar + main ─────────────────────────────────────────────── */
.lib-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── SIDEBAR ─────────────────────────────────────────────────────────────── */
.lib-sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
  font-weight: 600;
}

.sidebar-count {
  font-size: 10px;
  color: var(--text2);
  background: var(--bg3);
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-search input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 11px;
  font-family: var(--font);
  outline: none;
}

.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-cats {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.12s;
  border-left: 2px solid transparent;
}

.cat-item:hover { background: rgba(255,255,255,0.04); }
.cat-item.active { background: rgba(108,99,255,0.1); border-left-color: var(--accent); }
.cat-item.active .cat-item-name { color: var(--accent); }

.cat-item-emoji { font-size: 13px; flex-shrink: 0; }
.cat-item-name { font-size: 12px; color: var(--text2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item.active .cat-item-name { color: var(--accent); }
.cat-item-cnt { font-size: 10px; color: var(--text2); background: var(--bg4); padding: 1px 6px; border-radius: 8px; flex-shrink: 0; }

/* ─── MAIN CONTENT ─────────────────────────────────────────────────────────── */
.lib-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

/* ─── CAT HEADER IN MAIN ────────────────────────────────────────────────────── */
.main-cat-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.main-cat-header .mch-emoji { font-size: 1.6rem; flex-shrink: 0; }

.main-cat-header .mch-info { flex: 1; min-width: 0; }
.main-cat-header .mch-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.main-cat-header .mch-usecase {
  font-size: 11px;
  color: var(--text2);
  line-height: 1.5;
}
.main-cat-header .mch-tips {
  font-size: 11px;
  color: var(--accent2);
  margin-top: 4px;
  line-height: 1.4;
}
.main-cat-header .mch-count {
  font-size: 11px;
  color: var(--accent);
  background: rgba(108,99,255,0.1);
  border: 1px solid rgba(108,99,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── LINKS GRID ────────────────────────────────────────────────────────────── */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.link-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s;
  cursor: pointer;
}

.link-card:hover {
  border-color: rgba(108,99,255,0.4);
  background: rgba(108,99,255,0.05);
  transform: translateY(-1px);
}

.link-card.dead { opacity: 0.35; }
.link-card.dead:hover { opacity: 0.65; border-color: rgba(255,71,87,0.3); }

.link-favicon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg3);
}

.link-info { flex: 1; min-width: 0; }

.link-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-domain {
  font-size: 10px;
  color: var(--text2);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.link-status.ok { background: var(--green); box-shadow: 0 0 5px rgba(0,200,100,0.6); }
.link-status.dead { background: var(--red); }
.link-status.unknown { background: var(--yellow); }
.link-status.checking { background: var(--accent); animation: blink 1s ease infinite; }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

.link-open {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 3px;
  font-size: 12px;
  flex-shrink: 0;
  transition: color 0.15s;
  line-height: 1;
}
.link-open:hover { color: var(--accent2); }

/* ─── EMPTY / LOADING ────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text2);
  text-align: center;
}
.empty-state .es-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ─── MODAL ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  backdrop-filter: blur(3px);
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 500px;
  max-width: 94vw;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.modal-head-title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.modal-content { padding: 18px; }

.modal-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  align-items: flex-start;
}

.modal-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  min-width: 72px;
  padding-top: 1px;
  flex-shrink: 0;
}

.modal-val {
  font-size: 12px;
  color: var(--text);
  flex: 1;
  word-break: break-all;
  line-height: 1.5;
}

.modal-val a { color: var(--accent2); text-decoration: none; }
.modal-val a:hover { text-decoration: underline; }

.modal-usecase {
  background: rgba(108,99,255,0.07);
  border: 1px solid rgba(108,99,255,0.15);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.modal-usecase .mu-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.modal-usecase .mu-when { font-size: 12px; color: var(--text); margin-bottom: 6px; line-height: 1.5; }
.modal-usecase .mu-tips { font-size: 11px; color: var(--accent2); line-height: 1.5; }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-btn {
  flex: 1;
  padding: 9px;
  border-radius: 7px;
  border: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.modal-btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}
.modal-btn-primary:hover { opacity: 0.85; }

.modal-btn-secondary {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
}
.modal-btn-secondary:hover { border-color: var(--accent); }

/* ─── SCROLLBARS ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(108,99,255,0.4); }

/* ─── ADD BUTTON (header) ────────────────────────────────────────────────── */
.add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: opacity 0.15s;
}
.add-btn:hover { opacity: 0.85; }

/* ─── CUSTOM BADGE on cards ──────────────────────────────────────────────── */
.custom-badge {
  font-size: 9px;
  background: rgba(108,99,255,0.2);
  color: var(--accent);
  border: 1px solid rgba(108,99,255,0.3);
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

/* Sidebar custom category marker */
.cat-item-custom { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

/* ─── CARD EDIT ACTIONS (visible on hover) ───────────────────────────────── */
.link-card { position: relative; }
.link-card-actions {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  gap: 3px;
}
.link-card:hover .link-card-actions { display: flex; }

.card-action-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  cursor: pointer;
  color: var(--text2);
  transition: all 0.12s;
  line-height: 1.4;
}
.card-action-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }
.card-action-btn.del:hover { color: var(--red); border-color: var(--red); }

/* ─── CAT EDIT ACTIONS (in main header) ─────────────────────────────────── */
.mch-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.mch-action-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text2);
  font-family: var(--font);
  transition: all 0.12s;
}
.mch-action-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }
.mch-action-btn.del:hover { color: var(--red); border-color: var(--red); }

/* ─── FORM MODAL (add/edit) ──────────────────────────────────────────────── */
.form-modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 480px;
  max-width: 94vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 11px;
  color: var(--text2);
  margin-bottom: 5px;
  font-weight: 500;
}
.form-label span { color: var(--red); margin-left: 2px; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 70px; }
.form-select option { background: var(--bg3); }

.form-row {
  display: flex;
  gap: 10px;
}
.form-row .form-group { flex: 1; }

.form-hint {
  font-size: 10px;
  color: var(--text2);
  margin-top: 4px;
}

.form-error {
  font-size: 11px;
  color: var(--red);
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(255,71,87,0.08);
  border-radius: 6px;
  display: none;
}
.form-error.visible { display: block; }

.form-actions {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.form-btn-save {
  flex: 1;
  padding: 9px;
  border-radius: 7px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.form-btn-save:hover { opacity: 0.85; }
.form-btn-save:disabled { opacity: 0.4; cursor: not-allowed; }

.form-btn-cancel {
  padding: 9px 20px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.form-btn-cancel:hover { border-color: rgba(255,255,255,0.2); }

/* ─── TOAST NOTIFICATIONS ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease;
  min-width: 240px;
}
.toast.success { border-color: rgba(0,200,100,0.3); }
.toast.success .toast-icon { color: var(--green); }
.toast.error { border-color: rgba(255,71,87,0.3); }
.toast.error .toast-icon { color: var(--red); }

@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile / Tablet
   ════════════════════════════════════════════════════════════ */

/* ─── Tablet (≤ 1024px) ─── */
@media (max-width: 1024px) {
  :root { --header-h: auto; }
  .lib-header { padding: 12px 16px; gap: 8px; }
  .header-top { flex-wrap: wrap; gap: 10px; }
  .header-search { max-width: 100%; order: 3; flex-basis: 100%; }
  .header-stats { margin-left: 0; }
  .header-bottom { flex-wrap: wrap; }
  .source-link { display: none; }

  .lib-sidebar { width: 220px; }
  .links-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* ─── Mobile (≤ 768px) — App native ─── */
@media (max-width: 768px) {
  body { height: 100vh; height: 100dvh; }

  .lib-header { padding: 10px 12px; gap: 8px; }
  .header-top { gap: 8px; }
  .lib-logo { flex: 1; min-width: 0; }
  .lib-logo h1 { font-size: 0.95rem; }
  .lib-logo p { font-size: 9px; }
  .header-stats { display: none; }  /* Gain de place */

  .header-bottom {
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 4px;
    flex-wrap: nowrap;
  }
  .header-bottom::-webkit-scrollbar { display: none; }
  .filter-btn, .check-btn, .add-btn { font-size: 11px; padding: 6px 10px; white-space: nowrap; flex-shrink: 0; }
  .check-progress-bar { max-width: 100px; }

  /* ── Sidebar: drawer overlay on mobile ── */
  .lib-body { position: relative; }
  .lib-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 82vw; max-width: 300px;
    height: 100vh; height: 100dvh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .lib-sidebar.open { transform: translateX(0); }

  /* Burger button injected by JS, fallback CSS */
  .lib-sidebar-toggle {
    display: flex !important;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 150;
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px; height: 40px;
    border-radius: 8px;
    font-size: 18px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }

  /* Main content full width */
  .lib-main { padding: 12px; }

  /* Links grid: 1 column on very small screens */
  .links-grid { grid-template-columns: 1fr; gap: 6px; }
  .link-card { padding: 10px; gap: 8px; }
  .link-name { font-size: 13px; }

  /* Header cat — plus compact */
  .main-cat-header { padding: 10px 12px; gap: 10px; }
  .mch-title { font-size: 13px; }
  .mch-usecase { font-size: 10.5px; }

  /* Modal — full screen mobile */
  .modal-box, .form-modal-box { width: 100%; max-width: 100%; height: 100%; border-radius: 0; }
  .modal-overlay { padding: 0; }
  .modal-content { padding: 14px; }
  .modal-row { flex-direction: column; gap: 4px; }
  .modal-label { min-width: 0; padding-top: 0; }

  /* Toast — bottom au lieu de top-right */
  .toast-container { bottom: 12px; right: 12px; left: 12px; }
  .toast { min-width: 0; padding: 10px 14px; font-size: 12px; }

  /* OSINT Reports */
  .reports-container { padding: 12px; }
  .reports-header { flex-direction: column; gap: 10px; align-items: stretch; }
  .reports-grid { grid-template-columns: 1fr; gap: 12px; }
  .report-card { padding: 14px; }
  .report-target { font-size: 14px; }
  .report-actions { flex-wrap: wrap; }
  .report-actions .btn { flex: 1 1 100px; }

  /* Login page */
  .login-container { padding: 28px 20px; max-width: 100%; }
  .login-title { font-size: 20px; }
  .login-logo { font-size: 40px; }
}

/* Très petits écrans (≤ 400px) */
@media (max-width: 400px) {
  .lib-logo h1 { font-size: 0.85rem; }
  .lib-logo p { display: none; }
  .header-bottom { padding-bottom: 2px; }
  .filter-btn, .check-btn, .add-btn { font-size: 10px; padding: 5px 8px; }
}

