/* ============================================================
   LENTE — Design system
   Palette "camera oscura": inchiostro blu notte + blu elettrico
   Display: Sora · Testo: Inter · Meta: JetBrains Mono
   Firma visiva: hover a mirino (cornice blu con angoli da viewfinder)
   ============================================================ */

:root {
  --bg:        #0B0E14;
  --surface:   #12161F;
  --surface-2: #1A2030;
  --line:      #242C40;
  --text:      #E9EDF5;
  --muted:     #8B95AB;
  --accent:    #3E7BFF;
  --accent-2:  #6FA0FF;
  --accent-soft: rgba(62, 123, 255, .14);
  --danger:    #FF5D6C;
  --radius:    14px;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
.mono { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .08em; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 6px 24px rgba(62,123,255,.35);
}
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: rgba(255,93,108,.4); color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: rgba(255,93,108,.08); }
.btn.small { padding: 6px 13px; font-size: 12.5px; }
.btn.xl { padding: 16px 34px; font-size: 17px; font-family: var(--font-display); font-weight: 700; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-body {
  display: grid; place-items: center;
  position: relative; overflow: hidden;
}
.aperture {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
}
.aperture span {
  position: absolute; left: 50%; top: 50%;
  translate: -50% -50%;
  border: 1px solid rgba(62,123,255,.14);
  border-radius: 50%;
  animation: breathe 9s ease-in-out infinite;
}
.aperture span:nth-child(1) { width: 46vmin; height: 46vmin; }
.aperture span:nth-child(2) { width: 72vmin; height: 72vmin; animation-delay: -3s; border-color: rgba(62,123,255,.09); }
.aperture span:nth-child(3) { width: 104vmin; height: 104vmin; animation-delay: -6s; border-color: rgba(62,123,255,.05); }
@keyframes breathe { 50% { scale: 1.06; } }
@media (prefers-reduced-motion: reduce) { .aperture span { animation: none; } }

.login-card {
  position: relative; z-index: 1;
  width: min(420px, 92vw);
  background: linear-gradient(180deg, var(--surface) 0%, #0E1219 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 44px 40px 36px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
  animation: rise .5s ease both;
}
@keyframes rise { from { opacity: 0; translate: 0 14px; } }
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 14px; }
.brand-mark { color: var(--accent); }
.brand h1 {
  font-family: var(--font-display);
  font-size: 34px; font-weight: 800; letter-spacing: -0.03em;
}
.tagline { color: var(--muted); margin-bottom: 30px; font-size: 14.5px; }
.login-actions { display: grid; justify-items: start; gap: 14px; margin-bottom: 28px; }
.login-note { font-size: 12.5px; color: var(--muted); }
.login-features { list-style: none; border-top: 1px solid var(--line); padding-top: 20px; display: grid; gap: 9px; }
.login-features li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.login-features .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.login-footer { position: fixed; bottom: 18px; width: 100%; text-align: center; color: #3D465C; z-index: 1; }

/* ============================================================
   APP — struttura
   ============================================================ */
.app-body { display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 14px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(11,14,20,.85);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
}
.topbar-brand {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-display); font-weight: 800; font-size: 18px; letter-spacing: -.02em;
}
.accent-ico { color: var(--accent); }
.topbar-tabs { display: flex; gap: 4px; margin-inline: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent-2); }
.topbar-user { display: flex; align-items: center; gap: 11px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line); }
.user-name { font-size: 13px; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.view { display: none; padding: 34px clamp(18px, 4vw, 48px); flex: 1; }
.view.active { display: block; animation: fadeIn .25s ease both; }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- Home ---------- */
.hero { max-width: 720px; margin: 9vh auto 0; text-align: center; display: grid; justify-items: center; gap: 20px; }
.eyebrow { color: var(--accent-2); }
.hero h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(32px, 5vw, 52px); line-height: 1.12; letter-spacing: -.03em;
}
.hero-sub { color: var(--muted); max-width: 520px; font-size: 15.5px; }
.hero-stats { color: var(--muted); display: flex; gap: 12px; margin-top: 6px; }
.hero-stats b { color: var(--text); font-weight: 500; }
.hero-stats .sep { color: #333D55; }

/* ---------- Finestra browser ---------- */
.browser-window {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  height: calc(100vh - 140px);
  min-height: 480px;
}
.browser-chrome {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.traffic { display: flex; gap: 7px; }
.traffic i { width: 11px; height: 11px; border-radius: 50%; background: #2A3145; }
.traffic i:first-child { background: #FF5D6C; }
.traffic i:nth-child(2) { background: #FFC24B; }
.traffic i:nth-child(3) { background: #35D07F; }
.urlbar {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 16px;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.urlbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent-2); }
.urlbar input {
  flex: 1; border: 0; background: transparent; color: var(--text);
  font-size: 14px; outline: none;
}
.urlbar input::placeholder { color: #55617D; }
.browser-mode { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode-btn { border: 0; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 6px 14px; border-radius: 999px; }
.mode-btn.active { background: var(--accent-soft); color: var(--accent-2); }

.browser-body { flex: 1; overflow-y: auto; padding: 22px; position: relative; }
.browser-empty {
  height: 100%; display: grid; place-content: center; justify-items: center;
  gap: 18px; text-align: center; color: var(--text);
}
.browser-empty .muted { font-size: 13px; }

/* ---------- Griglia risultati + FIRMA: hover a mirino ---------- */
.results-grid {
  columns: 5 200px;
  column-gap: 14px;
}
.img-card {
  position: relative;
  break-inside: avoid;
  margin-bottom: 14px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: zoom-in;
  isolation: isolate;
}
.img-card img { width: 100%; transition: transform .3s ease, filter .2s ease; }

/* velo blu */
.img-card::before {
  content: '';
  position: absolute; inset: 0; z-index: 1;
  background: rgba(62,123,255,0);
  transition: background .18s ease;
  pointer-events: none;
}
/* mirino: angoli da viewfinder */
.img-card::after {
  content: '';
  position: absolute; inset: 7px; z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease, inset .18s ease;
  background:
    linear-gradient(var(--accent-2), var(--accent-2)) top left    / 18px 2.5px,
    linear-gradient(var(--accent-2), var(--accent-2)) top left    / 2.5px 18px,
    linear-gradient(var(--accent-2), var(--accent-2)) top right   / 18px 2.5px,
    linear-gradient(var(--accent-2), var(--accent-2)) top right   / 2.5px 18px,
    linear-gradient(var(--accent-2), var(--accent-2)) bottom left / 18px 2.5px,
    linear-gradient(var(--accent-2), var(--accent-2)) bottom left / 2.5px 18px,
    linear-gradient(var(--accent-2), var(--accent-2)) bottom right/ 18px 2.5px,
    linear-gradient(var(--accent-2), var(--accent-2)) bottom right/ 2.5px 18px;
  background-repeat: no-repeat;
  filter: drop-shadow(0 0 6px rgba(62,123,255,.8));
}
.img-card:hover::before, .img-card:focus-within::before { background: rgba(62,123,255,.28); }
.img-card:hover::after,  .img-card:focus-within::after  { opacity: 1; inset: 5px; }
.img-card:hover img { transform: scale(1.03); }

/* pulsantino download in basso a sinistra */
.img-dl {
  position: absolute; left: 9px; bottom: 9px; z-index: 3;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: 9px;
  background: var(--accent); color: #fff;
  opacity: 0; translate: 0 6px;
  transition: opacity .18s ease, translate .18s ease, background .15s;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
.img-card:hover .img-dl, .img-card:focus-within .img-dl { opacity: 1; translate: 0 0; }
.img-dl:hover { background: var(--accent-2); }
.img-dl.done { background: #35D07F; }

/* segnalibro libreria in basso a destra della card */
.img-save {
  position: absolute; right: 9px; bottom: 9px; z-index: 3;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: 9px;
  background: rgba(11,14,20,.82); color: var(--text);
  opacity: 0; translate: 0 6px;
  transition: opacity .18s ease, translate .18s ease, background .15s, color .15s;
}
.img-card:hover .img-save, .img-card:focus-within .img-save { opacity: 1; translate: 0 0; }
.img-save:hover { background: var(--accent); color: #fff; }
.img-save.done { background: #35D07F; color: #fff; }

.img-meta {
  position: absolute; top: 8px; left: 9px; right: 9px; z-index: 3;
  display: flex; justify-content: space-between; gap: 8px;
  opacity: 0; transition: opacity .18s ease;
  pointer-events: none;
}
.img-card:hover .img-meta { opacity: 1; }
.img-res, .img-site {
  font-family: var(--font-mono); font-size: 10px;
  background: rgba(11,14,20,.85); color: var(--accent-2);
  padding: 3px 7px; border-radius: 6px;
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.img-site { color: var(--muted); }

/* ---------- Risultati web ---------- */
.web-results { display: grid; gap: 6px; max-width: 760px; }
.web-result {
  display: block; padding: 15px 18px;
  border: 1px solid transparent; border-radius: var(--radius);
  text-decoration: none; color: inherit;
  transition: background .15s, border-color .15s;
}
.web-result:hover { background: var(--surface-2); border-color: var(--line); }
.web-result .wr-site { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.web-result .wr-title { color: var(--accent-2); font-weight: 600; font-size: 16px; margin: 3px 0 4px; }
.web-result .wr-snippet { color: var(--muted); font-size: 13.5px; }

.load-more-wrap { display: grid; place-items: center; padding: 22px 0 8px; }

/* ---------- Loader ---------- */
.loader { display: flex; gap: 7px; justify-content: center; padding: 30px; }
.loader span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 50% { opacity: .25; scale: .7; } }

/* ---------- FAB librerie (basso a destra) ---------- */
.lib-fab-wrap { position: absolute; right: 20px; bottom: 20px; z-index: 20; }
.lib-fab {
  width: 52px; height: 52px; border-radius: 16px; border: 0;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(62,123,255,.45);
  transition: transform .15s, background .15s;
}
.lib-fab:hover { transform: translateY(-2px) scale(1.04); background: var(--accent-2); }
.lib-panel {
  position: absolute; right: 0; bottom: 62px;
  width: 280px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
  animation: rise .2s ease both;
}
.lib-panel-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.lib-panel-hint { font-size: 12px; margin-bottom: 12px; }
.lib-panel-list { display: grid; gap: 5px; max-height: 190px; overflow-y: auto; margin-bottom: 12px; }
.lib-choice {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 13.5px; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.lib-choice:hover { border-color: var(--accent); }
.lib-choice.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.lib-choice .cnt { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.lib-panel-new { display: flex; gap: 8px; }
.lib-panel-new input {
  flex: 1; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; color: var(--text); font-size: 13px; outline: none;
}
.lib-panel-new input:focus { border-color: var(--accent); }

/* ---------- Viste Cronologia / Librerie ---------- */
.view-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 18px;
  margin-bottom: 26px; flex-wrap: wrap;
}
.view-head h2 { font-family: var(--font-display); font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.view-head .muted { font-size: 13.5px; margin-top: 3px; }

.history-list { display: grid; gap: 8px; max-width: 900px; }
.history-item {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px;
  transition: border-color .15s;
}
.history-item:hover { border-color: var(--accent); }
.history-item img { width: 64px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.hi-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.hi-actions { display: flex; gap: 8px; }

.libraries-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px;
}
.library-card {
  position: relative;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); overflow: hidden;
  cursor: pointer; text-align: left;
  transition: border-color .15s, transform .15s;
}
.library-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.library-card .lc-cover { height: 130px; background: var(--surface-2); display: grid; place-items: center; color: #333D55; }
.library-card .lc-cover img { width: 100%; height: 130px; object-fit: cover; }
.library-card .lc-body { padding: 13px 15px; }
.library-card .lc-name { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.library-card .lc-count { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.lib-detail-title { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.lib-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.results-grid.gallery .img-card { cursor: zoom-in; }
.img-check {
  position: absolute; top: 8px; left: 8px; z-index: 4;
  width: 22px; height: 22px; border-radius: 7px;
  border: 2px solid rgba(255,255,255,.75);
  background: rgba(11,14,20,.5);
  display: none; place-items: center; color: #fff; font-size: 13px;
}
.select-mode .img-check { display: grid; }
.select-mode .img-card { cursor: pointer; }
.img-card.selected .img-check { background: var(--accent); border-color: var(--accent); }
.img-card.selected::before { background: rgba(62,123,255,.32); }

.empty-state { color: var(--muted); text-align: center; padding: 70px 0; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,7,11,.92);
  display: grid; place-items: center;
  animation: fadeIn .18s ease both;
  padding: 40px;
}
.lightbox img { max-width: 92vw; max-height: 78vh; border-radius: 12px; box-shadow: 0 30px 90px rgba(0,0,0,.7); }
.lightbox-close {
  position: absolute; top: 20px; right: 24px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 15px;
}
.lightbox-close:hover { border-color: var(--accent); }
.lightbox-bar {
  position: absolute; bottom: 26px; left: 50%; translate: -50% 0;
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 10px 8px 20px;
  max-width: 90vw;
}
.lightbox-title { font-size: 13px; color: var(--muted); max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; translate: -50% 0; z-index: 200;
  background: var(--surface-2); border: 1px solid var(--accent);
  color: var(--text); font-size: 13.5px; font-weight: 500;
  padding: 11px 20px; border-radius: 999px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: rise .2s ease both;
}
.toast.err { border-color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .topbar-tabs { order: 3; width: 100%; justify-content: center; }
  .user-name { display: none; }
  .browser-chrome { flex-wrap: wrap; }
  .urlbar { order: 3; width: 100%; flex: none; }
  .browser-window { height: calc(100vh - 190px); }
  .results-grid { columns: 3 130px; }
  .view { padding: 20px 14px; }
  .hero { margin-top: 4vh; }
}

/* ---------- Visualizzatore pagine (browser interno) ---------- */
.page-viewer {
  position: absolute; inset: 0; z-index: 15;
  display: flex; flex-direction: column;
  background: var(--surface);
}
.page-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.page-url {
  flex: 1; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.page-frame { flex: 1; width: 100%; border: 0; background: #fff; }
