/* ================================================================
   TidyDrawer — Stile principale
   Design: cassetti aperibili, palette neutra, accento per categoria
   ================================================================ */

:root {
  --bg:           #F0F4F8;
  --surface:      #FFFFFF;
  --surface-2:    #F8FAFC;
  --text:         #1A202C;
  --text-muted:   #718096;
  --border:       #E2E8F0;
  --radius:       12px;
  --radius-sm:    6px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --font:         system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --t:            0.2s ease;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Header ───────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  height: 58px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
  flex-shrink: 0;
}
.brand-icon { font-size: 22px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: 500 13px/1 var(--font);
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t), opacity var(--t);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

.btn-primary  { background: #2563EB; color: #fff; }
.btn-primary:hover { background: #1D4ED8; }

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

.btn-large { padding: 13px 28px; font-size: 15px; border-radius: 10px; }

/* ─── Main layout ───────────────────────────────────────────── */
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ─── State visibility ──────────────────────────────────────── */
.state { display: none; }
.state.active { display: block; }

/* ─── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 96px 24px;
}
.empty-icon {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 28px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.1));
}
.empty-state h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 12px;
}
.empty-state p {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 36px;
}

/* ─── Loading state ─────────────────────────────────────────── */
.loading-state {
  text-align: center;
  padding: 96px 24px;
  color: var(--text-muted);
}
.spinner {
  width: 42px; height: 42px;
  border: 3px solid var(--border);
  border-top-color: #2563EB;
  border-radius: 50%;
  animation: spin .75s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Scan summary ──────────────────────────────────────────── */
.scan-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.summary-icon { font-size: 16px; flex-shrink: 0; }
.summary-path {
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.summary-badge {
  flex-shrink: 0;
  background: #EFF6FF;
  color: #2563EB;
  font-weight: 600;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ─── Search ────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  margin-bottom: 20px;
}
.search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  user-select: none;
}
#searchInput {
  width: 100%;
  padding: 11px 16px 11px 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 14px var(--font);
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color var(--t), box-shadow var(--t);
}
#searchInput:focus {
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
#searchInput::placeholder { color: var(--text-muted); }

/* ─── Drawers container ─────────────────────────────────────── */
#drawers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Drawer card ───────────────────────────────────────────── */
.drawer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--cat-color, #CBD5E1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow var(--t);
}
.drawer:not(.empty):hover { box-shadow: var(--shadow-md); }
.drawer.empty { opacity: .55; }

/* Drawer header (button) */
.drawer-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  background: transparent;
  border: none;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: background var(--t);
}
.drawer:not(.empty) .drawer-header:hover { background: var(--surface-2); }
.drawer.empty .drawer-header { cursor: default; }

.drawer-icon { font-size: 20px; line-height: 1; flex-shrink: 0; }

.drawer-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -.01em;
}

.drawer-count {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
  transition: background var(--t), color var(--t);
}
.drawer.open .drawer-count {
  background: var(--cat-bg, #EFF6FF);
  color: var(--cat-color, #2563EB);
}

.drawer-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform var(--t);
}
.drawer.open .drawer-chevron { transform: rotate(90deg); }

/* ─── Drawer body (collapse/expand) ─────────────────────────── */
.drawer-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s cubic-bezier(.4,0,.2,1);
}
.drawer.open .drawer-body {
  max-height: 460px;
  overflow-y: auto;
  /* Scroll personalizzato */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.drawer.open .drawer-body::-webkit-scrollbar { width: 5px; }
.drawer.open .drawer-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

/* ─── File list ─────────────────────────────────────────────── */
.files-list {
  border-top: 1px solid var(--border);
}

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
  transition: background var(--t);
}
.file-row:not(:last-child) { border-bottom: 1px solid var(--border); }
.file-row:hover { background: var(--surface-2); }

/* Extension badge */
.file-ext {
  flex-shrink: 0;
  min-width: 38px;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
  background: var(--bg);
  color: var(--text-muted);
}

.file-name {
  flex: 1;
  font-size: 13px;
  font-weight: 450;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size, .file-date {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.file-size { min-width: 56px; text-align: right; }
.file-date { min-width: 110px; text-align: right; }

.file-open {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--t), background var(--t);
}
.file-row:hover .file-open { opacity: 1; }
.file-open:hover { background: var(--bg); color: var(--text); }

/* Nessun file / nessun risultato ricerca */
.no-files {
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* ─── Pulsante AI + status ──────────────────────────────────── */
.btn-ai {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid #A78BFA;
  border-radius: 20px;
  background: #F5F3FF;
  color: #7C3AED;
  font: 600 11px var(--font);
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}
.btn-ai:hover  { background: #EDE9FE; }
.btn-ai:disabled { opacity: .5; cursor: not-allowed; }

.ai-status {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.ai-status.running  { color: #7C3AED; }
.ai-status.done     { color: #059669; }
.ai-status.error    { color: #DC2626; }
.ai-status.offline  { color: #9CA3AF; }
.ai-status.warn     { color: #D97706; }

/* ─── Bottone scarica modello ───────────────────────────────── */
.btn-pull {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid #FCD34D;
  border-radius: 20px;
  background: #FFFBEB;
  color: #92400E;
  font: 600 11px var(--font);
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}
.btn-pull:hover    { background: #FEF3C7; }
.btn-pull:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Bottone modello veloce (suggerimento upgrade da thinking model) ── */
.btn-faster-model {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid #FCD34D;
  border-radius: 20px;
  background: #FFFBEB;
  color: #92400E;
  font: 600 11px var(--font);
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}
.btn-faster-model:hover { background: #FEF3C7; }

/* ─── Bottone installa AI (wizard) ─────────────────────────── */
.btn-install-ai {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid #6EE7B7;
  border-radius: 20px;
  background: #ECFDF5;
  color: #065F46;
  font: 600 11px var(--font);
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}
.btn-install-ai:hover    { background: #D1FAE5; }
.btn-install-ai:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Bottone installa OCR (Pro+ tier) ─────────────────────── */
.btn-install-ocr {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid #C4B5FD;
  border-radius: 20px;
  background: #F5F3FF;
  color: #5B21B6;
  font: 600 11px var(--font);
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}
.btn-install-ocr:hover    { background: #EDE9FE; }
.btn-install-ocr:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Progress bar download modello ────────────────────────── */
.pull-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.pull-bar {
  width: 80px;
  height: 6px;
  border-radius: 3px;
  background: #E5E7EB;
  overflow: hidden;
}
.pull-fill {
  height: 100%;
  width: 0%;
  background: #F59E0B;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.pull-msg {
  font-size: 11px;
  color: #92400E;
  white-space: nowrap;
}

/* Badge ⚡ AI sui file riclassificati */
.file-ai-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: #F5F3FF;
  color: #7C3AED;
  border: 1px solid #DDD6FE;
  letter-spacing: .02em;
}

/* ─── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  width: 480px;
  max-width: calc(100vw - 48px);
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
}
.modal h2 { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.modal p  { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }
.modal input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: 14px var(--font);
  color: var(--text);
  background: var(--bg);
  outline: none;
  margin-bottom: 20px;
  transition: border-color var(--t);
}
.modal input:focus { border-color: #2563EB; background: var(--surface); }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Barra cartelle scansionate ────────────────────────────── */
.folders-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.folders-bar::-webkit-scrollbar { display: none; }

.folders-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: 20px;
  padding: 4px 6px 4px 10px;
  font-size: 12px;
  color: #1E40AF;
  white-space: nowrap;
  max-width: 240px;
}
.chip-icon { font-size: 13px; flex-shrink: 0; }
.chip-path {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-count {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  background: #BFDBFE;
  color: #1E40AF;
  padding: 1px 6px;
  border-radius: 10px;
}
.chip-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #93C5FD;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 50%;
  line-height: 1;
  transition: background var(--t), color var(--t);
}
.chip-remove:hover { background: #BFDBFE; color: #1D4ED8; }

/* ─── Delta alert ────────────────────────────────────────────── */
.delta-alert {
  background: #FFFBEB;
  border-bottom: 1px solid #FDE68A;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #92400E;
}
.delta-icon { flex-shrink: 0; font-size: 15px; }
.delta-msg  { flex: 1; }
.delta-close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #B45309;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--t);
}
.delta-close:hover { background: #FDE68A; }

/* ─── Utility: pulsante piccolo ─────────────────────────────── */
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ─── Tab Cassetti / Cerca nei documenti ────────────────────── */
.mode-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
}
.mode-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font: 500 13px var(--font);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t);
  position: relative;
}
.mode-tab:hover { background: var(--bg); color: var(--text); }
.mode-tab.active {
  background: #EFF6FF;
  color: #1E40AF;
  font-weight: 600;
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563EB;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
}

/* ─── Barra progresso estrazione ────────────────────────────── */
.extraction-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-muted);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.extr-icon { font-size: 16px; flex-shrink: 0; }
.extr-msg  { flex: 1; font-size: 12px; }
.extr-progress {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.extr-fill {
  height: 100%;
  background: #2563EB;
  border-radius: 2px;
  transition: width .3s ease;
}

/* ─── Box ricerca AI ─────────────────────────────────────────── */
.ai-search-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.ai-query {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: 14px var(--font);
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
  margin-bottom: 10px;
  line-height: 1.5;
}
.ai-query:focus {
  border-color: #2563EB;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: var(--surface);
}
.ai-query::placeholder { color: var(--text-muted); }

.ai-search-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.ai-search-actions .btn { flex: 1; justify-content: center; }

.smart-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.smart-search-row .ai-query {
  flex: 1;
  margin-bottom: 0;
}

.ai-search-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.ai-search-hint b { color: var(--text); }

/* ─── Stato vuoto ricerca ────────────────────────────────────── */
.search-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.se-icon   { font-size: 48px; margin-bottom: 16px; }
.se-hint   { margin-top: 8px; font-size: 12px; }
.se-hint em { color: #2563EB; font-style: normal; font-weight: 500; }

/* ─── Pannello risultati ricerca ─────────────────────────────── */
#searchResults {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
}
.search-meta {
  display: flex;
  gap: 6px;
  padding: 6px 16px 8px;
  flex-wrap: wrap;
}
.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #EDE9FE;
  color: #5B21B6;
  font: 500 11px var(--font);
  white-space: nowrap;
}
.sr-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--t);
}
.sr-clear:hover { background: var(--bg); color: var(--text); }

.search-results-list {
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.search-results-list::-webkit-scrollbar { width: 5px; }
.search-results-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

/* Singola riga risultato */
.sr-row {
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  transition: background var(--t);
}
.sr-row:last-child { border-bottom: none; }
.sr-row:hover { background: var(--surface-2); }

.sr-main {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sr-ext {
  flex-shrink: 0;
  min-width: 36px;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
  background: var(--bg);
  color: var(--text-muted);
}
.sr-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.sr-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.sr-cat {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
}
.sr-open {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-muted);
  transition: all var(--t);
}
.sr-open:hover { background: var(--bg); color: var(--text); }

.sr-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: .02em;
}
.text-badge { background: #ECFDF5; color: #059669; border: 1px solid #A7F3D0; }
.ai-badge   { background: #F5F3FF; color: #7C3AED; border: 1px solid #DDD6FE; }

.sr-snippet {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 4px;
  border-left: 3px solid var(--border);
  word-break: break-word;
}

/* Pulsante 📌 nella riga risultato */
.sr-add-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--t), background var(--t);
}
.sr-row:hover .sr-add-btn { opacity: 1; }
.sr-add-btn:hover { background: var(--bg); }

/* Bottoni reveal (📁) e copia percorso (📋) */
.sr-reveal-btn,
.sr-copy-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--t), background var(--t);
}
.sr-row:hover .sr-reveal-btn,
.sr-row:hover .sr-copy-btn { opacity: 1; }
.sr-reveal-btn:hover,
.sr-copy-btn:hover { background: var(--bg); }

/* Toast notifica breve */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1E293B;
  color: #F8FAFC;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}
.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Intestazione risultati con pulsante salva */
.sr-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Sezione cassetti personalizzati ───────────────────────── */
.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 4px 8px;
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0 14px;
}

/* Drawer personalizzato — aspetto distinto */
.custom-drawer {
  border-left-width: 4px;
  border-left-style: solid;
  border-left-color: var(--cat-color, #F59E0B);
}
.custom-drawer .drawer-header {
  cursor: pointer;
  background: var(--cat-bg, rgba(245,158,11,.08));
}
.custom-drawer .drawer-header:hover {
  background: var(--cat-bg, rgba(245,158,11,.15));
}

/* Bottoni azione (edit/delete) nell'header del cassetto personalizzato */
.custom-drawer-header {
  user-select: none;
}
.custom-drawer-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
  margin-right: 6px;
  opacity: 0;
  transition: opacity var(--t);
}
.custom-drawer:hover .custom-drawer-actions { opacity: 1; }

.cda-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: background var(--t);
}
.cda-btn:hover { background: rgba(0,0,0,.07); }

/* File mancante nel cassetto personalizzato */
.file-missing { opacity: .55; }
.missing-badge {
  font-size: 11px;
  color: #DC2626;
  font-weight: 600;
}

/* Bottone rimuovi dal cassetto (✕) sulla riga file */
.file-rm-custom {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--t), color var(--t), background var(--t);
}
.file-row:hover .file-rm-custom { opacity: 1; }
.file-rm-custom:hover { color: #DC2626; background: #FEE2E2; }

/* Bottone 📌 "aggiungi a cassetto" nei drawer normali */
.file-pin {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--t), background var(--t);
}
.file-row:hover .file-pin { opacity: 1; }
.file-pin:hover { background: var(--bg); }

/* ─── Modal ampio (salva cassetto) ──────────────────────────── */
.modal-wide { width: 520px; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* Picker icona */
.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.icon-opt {
  width: 38px;
  height: 38px;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--bg);
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
}
.icon-opt:hover  { background: var(--surface-2); }
.icon-opt.active { border-color: #2563EB; background: #EFF6FF; }

/* Picker colore */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.color-opt {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color var(--t), transform var(--t);
  outline: none;
}
.color-opt:hover  { transform: scale(1.15); }
.color-opt.active { border-color: var(--text); }

/* ─── Modal "Aggiungi a cassetto" ───────────────────────────── */
.modal-filename {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-choice-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}
.folder-choice-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--cf-color, #F59E0B);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: 500 13px var(--font);
  cursor: pointer;
  text-align: left;
  transition: background var(--t), box-shadow var(--t);
}
.folder-choice-btn:hover {
  background: var(--bg);
  box-shadow: var(--shadow);
}
.folder-choice-btn:disabled { opacity: .5; cursor: not-allowed; }
.fc-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 10px;
}

/* ─── Keyword highlight negli snippet di ricerca ───────────────── */
.sr-snippet mark,
mark.search-highlight {
  background: #FEF9C3;
  color: #854D0E;
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
  font-style: normal;
  /* evita che mark spezzi le linee stranamente */
  display: inline;
}

/* ─── Watcher banner — notifica modifiche live ──────────────────── */
/* ─── Warning cartella root / troppo generica ────────────────────────────── */
.root-warn-banner {
  background: #FFFBEB;
  border-bottom: 1px solid #FCD34D;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: #78350F;
}

.root-warn-icon { font-size: 18px; flex-shrink: 0; }

.root-warn-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.root-warn-text strong { font-size: 13px; }
.root-warn-text span   { font-size: 12px; color: #92400E; }

.root-warn-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.root-warn-cancel {
  padding: 4px 12px;
  border: 1px solid #D97706;
  border-radius: 6px;
  background: none;
  color: #92400E;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t);
}
.root-warn-cancel:hover { background: #FEF3C7; }

.root-warn-confirm {
  padding: 4px 12px;
  border: 1px solid #D97706;
  border-radius: 6px;
  background: #D97706;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--t);
}
.root-warn-confirm:hover { opacity: 0.85; }

.watcher-banner {
  background: #F0FDF4;
  border-bottom: 1px solid #BBF7D0;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #166534;
}

.live-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16A34A;
  animation: live-pulse 1.8s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.8); }
}

#watcherBannerMsg { flex: 1; font-weight: 500; }

.watcher-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #4ADE80;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--t);
}
.watcher-dismiss:hover { background: #DCFCE7; color: #166534; }

/* ─── Pannello Hardware-aware model selector ──────────────────────────────── */

.hw-panel {
  margin: 0 16px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.hw-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.hw-title {
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.hw-specs {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hw-close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--t), color var(--t);
}
.hw-close:hover { background: var(--bg); color: var(--text); }

.hw-loading {
  padding: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.hw-models { padding: 8px 0; }

.hw-model-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background var(--t);
}
.hw-model-row:last-child { border-bottom: none; }
.hw-model-row:hover { background: var(--surface-2); }

.hw-recommended {
  background: #F0FDF4;
  border-left: 3px solid #22C55E;
  padding-left: 11px;
}
.hw-recommended:hover { background: #DCFCE7; }

.hw-model-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.hw-rec-badge {
  font-size: 10px;
  font-weight: 700;
  background: #DCFCE7;
  color: #15803D;
  border: 1px solid #86EFAC;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.hw-model-name {
  font-size: 13px;
  font-weight: 600;
  font-family: monospace;
  flex-shrink: 0;
}

.hw-model-size {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}

.hw-model-desc {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}

.hw-model-req {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.hw-install-btn {
  flex-shrink: 0;
  background: #6366F1;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--t);
  white-space: nowrap;
}
.hw-install-btn:hover { opacity: 0.85; }
.hw-recommended .hw-install-btn { background: #16A34A; }

/* ── Explain Panel ───────────────────────────────────────────────── */
#explainPanel {
  margin: 12px 16px 16px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.explain-content {
  background: var(--bg-secondary, #f8f9fa);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  min-height: 48px;
}
.explain-content.loading::after {
  content: '▌';
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Chat panel ──────────────────────────────────────────────── */
#chatPanel {
  margin: 12px 16px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.chat-messages {
  max-height: 340px;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background: #2563EB;
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
  color: var(--text);
}
.chat-bubble.assistant.loading::after {
  content: '▋';
  animation: blink 0.8s step-end infinite;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.chat-input {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: 14px var(--font);
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t);
}
.chat-input:focus { border-color: #2563EB; }
.chat-input:disabled { opacity: .5; }
