/* --- Variabili tema --- */
:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1a2230;
  --muted: #5a6b89;
  --border: #d4dbe7;
  --accent: #ff5e3a;
  --accent-2: #2151c4;
  --topbar-bg: #1a2230;
  --topbar-text: #ecf1fa;
  --chip-bg: #eef2f8;
  --chip-border: #d4dbe7;
  --chip-text: #1a2230;
  --love-from: #ff3d7f;
  --love-to: #ff8aab;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-hover: 0 4px 14px rgba(33, 81, 196, 0.12);
}
[data-theme="dark"] {
  --bg: #0f1622;
  --panel: #1a2230;
  --text: #ecf1fa;
  --muted: #92a3c4;
  --border: #2c3a52;
  --accent: #ff7a5a;
  --accent-2: #6fa3ff;
  --topbar-bg: #0a121f;
  --topbar-text: #ecf1fa;
  --chip-bg: #232f47;
  --chip-border: #324162;
  --chip-text: #ecf1fa;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-hover: 0 4px 14px rgba(0,0,0,0.6);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
button { font: inherit; cursor: pointer; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

/* --- Banner amore --- */
.love-banner {
  position: relative;
  text-align: center;
  padding: 8px 14px;
  background: linear-gradient(90deg, var(--love-from), var(--love-to), var(--love-from));
  background-size: 300% 100%;
  color: white;
  font-weight: 700;
  letter-spacing: 0.4px;
  font-size: 14px;
  z-index: 6;
  animation: lovePulse 1.4s ease-in-out infinite, loveShift 6s linear infinite;
  box-shadow: 0 1px 4px rgba(255, 61, 127, 0.4);
}
.love-banner .love-text { display: inline-block; animation: loveBeat 1s ease-in-out infinite; }
@keyframes lovePulse { 0%,100% { opacity: 0.92; } 50% { opacity: 1; } }
@keyframes loveBeat  { 0%,100% { transform: scale(1); } 25% { transform: scale(1.06); } 60% { transform: scale(0.98); } }
@keyframes loveShift { 0% { background-position: 0% 50%; } 100% { background-position: 300% 50%; } }
@media (prefers-reduced-motion: reduce) {
  .love-banner { animation: none; background: var(--love-from); }
}

/* --- Topbar --- */
.topbar {
  display: grid;
  grid-template-columns: 220px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 10px 18px;
  background: var(--topbar-bg);
  color: var(--topbar-text);
  position: sticky; top: 0; z-index: 5;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: inline-block; padding: 4px 8px;
  background: var(--accent); color: white; border-radius: 6px;
  font-weight: 700; letter-spacing: 0.5px;
}
.brand-text { font-weight: 600; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-wrap { position: relative; min-width: 0; }
.search-wrap input {
  width: 100%; padding: 9px 36px 9px 14px;
  border-radius: 8px; border: 1px solid #2c3a52;
  background: #2a334a; color: white; font-size: 15px;
}
[data-theme="dark"] .search-wrap input { background: #182236; border-color: #324162; }
.search-wrap input::placeholder { color: #8aa0c4; }
.search-wrap input:focus { outline: none; border-color: var(--accent-2); }
#clearq {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: #b4c2dc;
  width: 28px; height: 28px; border-radius: 6px; font-size: 18px;
}
#clearq:hover { background: rgba(255,255,255,0.08); color: white; }

.meta { display: flex; align-items: center; gap: 8px; justify-content: flex-end; font-size: 13px; flex-wrap: wrap; }
.btn-ghost {
  background: transparent; color: var(--topbar-text); border: 1px solid #3a4a6a;
  padding: 6px 10px; border-radius: 6px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.08); }
.btn-icon {
  background: transparent; color: var(--topbar-text); border: 1px solid #3a4a6a;
  padding: 6px 10px; border-radius: 6px; font-size: 16px;
}
.btn-icon[aria-pressed="true"] {
  background: var(--love-from); border-color: var(--love-from);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); }
.btn-icon[aria-pressed="true"]:hover { background: var(--love-from); }

/* --- Layout --- */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  padding: 18px 20px;
  flex: 1;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}
.sidebar { display: flex; flex-direction: column; gap: 0; }
.sidebar-toggle {
  display: none; width: 100%; padding: 10px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-weight: 600;
  margin-bottom: 12px;
}
.sidebar-inner { display: flex; flex-direction: column; gap: 14px; }
.sidebar section {
  background: var(--panel); border-radius: 10px; padding: 12px 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.sidebar h3 {
  margin: 0 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--muted);
}
.sidebar select, .sidebar input[type="search"] {
  width: 100%; padding: 7px 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit;
}
.sidebar input[type="search"] { margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-compact { max-height: 220px; overflow: auto; padding-right: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--chip-bg); color: var(--chip-text);
  border: 1px solid var(--chip-border); font-size: 13px;
  user-select: none;
}
.chip:hover { background: var(--border); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.chip .count { color: inherit; opacity: 0.7; font-size: 11px; }

/* --- Risultati --- */
.results { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.toolbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; flex-wrap: wrap;
}
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-removable {
  background: var(--text); color: var(--bg); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center;
}
.tag-removable button {
  background: none; border: none; color: inherit; cursor: pointer;
  padding: 0 0 0 4px; font-size: 14px;
}
.sort { display: flex; gap: 10px; flex-wrap: wrap; }
.sort select {
  padding: 6px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font: inherit;
}
.sort label { font-size: 13px; color: var(--muted); }

.lista { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel); border-radius: 10px;
  padding: 12px 16px; cursor: pointer;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--accent-2); box-shadow: var(--shadow-hover); }
.card h2 { margin: 0 0 4px; font-size: 16px; line-height: 1.3; }
.card .path {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px; color: var(--muted); word-break: break-all;
}
.card .descr {
  margin: 6px 0 8px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .panoramica-card {
  font-size: 13px; color: var(--muted);
  margin: 6px 0; padding: 6px 8px;
  background: var(--bg); border-left: 3px solid var(--accent-2);
  border-radius: 4px;
}
.card .meta-line { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.badge {
  background: var(--chip-bg); color: var(--chip-text);
  padding: 2px 8px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--chip-border);
}
.badge.cat { background: #ffe7df; border-color: #ffc8b5; color: #92341d; }
.badge.trig { background: #e0f2e9; border-color: #b6dec6; color: #205c3c; }
.badge.compl { background: #f0e3ff; border-color: #d2bff0; color: #4a2785; }
.badge.integr { background: #e6f0ff; border-color: #c2d6f5; color: #1d3f87; }
[data-theme="dark"] .badge.cat { background: #4a2818; border-color: #7a4226; color: #ffd2bf; }
[data-theme="dark"] .badge.trig { background: #1d3a26; border-color: #2e5a3d; color: #c2efd2; }
[data-theme="dark"] .badge.compl { background: #2c1f49; border-color: #4a3680; color: #d8c2ff; }
[data-theme="dark"] .badge.integr { background: #1a2c52; border-color: #2c4682; color: #c2d6ff; }

/* --- Paginazione --- */
.pager {
  display: flex; flex-wrap: wrap; gap: 4px;
  justify-content: center; align-items: center;
  margin: 18px 0 30px;
}
.page-btn {
  min-width: 38px; height: 36px; padding: 0 10px;
  border-radius: 7px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
  font-weight: 500;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent-2); }
.page-btn[aria-current="page"] {
  background: var(--accent); color: white; border-color: var(--accent);
}
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-ellipsis { padding: 0 6px; color: var(--muted); user-select: none; }
.page-info {
  width: 100%; text-align: center;
  font-size: 12px; color: var(--muted);
  margin-bottom: 6px;
}

/* --- Footer --- */
.footer {
  text-align: center; padding: 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border); background: var(--panel);
}

/* --- Modal dettaglio --- */
.modal {
  border: none; border-radius: 12px; padding: 0;
  width: min(880px, 94vw); max-height: 90vh;
  background: var(--panel); color: var(--text);
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal::backdrop { background: rgba(15, 22, 38, 0.6); backdrop-filter: blur(2px); }
.modal article { padding: 22px 26px; max-height: 90vh; overflow-y: auto; }
.modal h1 { margin: 0 0 4px; font-size: 22px; line-height: 1.25; }
.modal .path-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: var(--muted);
  margin-bottom: 10px;
}
.modal .copy-btn {
  background: var(--chip-bg); color: var(--chip-text); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 6px; font-size: 11px;
}
.modal h3 {
  margin: 18px 0 8px; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--muted);
}
.modal .badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.modal .panoramica-box {
  background: var(--bg);
  border-left: 3px solid var(--accent-2);
  padding: 10px 12px; margin: 8px 0;
  font-size: 14px; line-height: 1.5;
  border-radius: 4px;
}
.modal ul { padding-left: 20px; margin: 8px 0; }
.modal li { margin-bottom: 6px; line-height: 1.5; }

/* Flusso step-by-step */
.steps { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.step {
  display: grid; grid-template-columns: 28px 28px 1fr; gap: 10px;
  align-items: start;
  padding: 8px 10px; background: var(--bg);
  border-radius: 8px; border: 1px solid var(--border);
}
.step-num {
  background: var(--accent); color: white; width: 24px; height: 24px;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.step-icon { font-size: 16px; text-align: center; }
.step-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.step-label { font-weight: 600; font-size: 14px; }
.step-detail { font-size: 12px; color: var(--muted); word-break: break-word; }
.step-name {
  font-size: 11px; color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.modal-close {
  position: fixed; top: 14px; right: 18px;
  background: rgba(0,0,0,0.5); color: white; border: none;
  width: 36px; height: 36px; border-radius: 50%; font-size: 22px;
  display: grid; place-items: center;
}
.modal-close:hover { background: rgba(0,0,0,0.7); }

/* --- Responsive --- */
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; gap: 8px; padding: 10px 12px; }
  .brand { grid-column: 1 / -1; justify-content: space-between; }
  .search-wrap { grid-column: 1 / -1; }
  .meta { grid-column: 1 / -1; justify-content: flex-end; }
  .layout { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .sidebar-toggle { display: block; }
  .sidebar-inner { display: none; }
  .sidebar.open .sidebar-inner { display: flex; }
  .step { grid-template-columns: 24px 24px 1fr; }
  .modal article { padding: 18px 16px; }
  .modal h1 { font-size: 18px; }
}

@media (max-width: 480px) {
  .love-banner { font-size: 13px; padding: 6px 10px; }
  .badge { font-size: 11px; padding: 2px 6px; }
  .card { padding: 10px 12px; }
}
