:root {
  --paper: #f2eee4;
  --ink: #1b1b18;
  --red: #a3342a;
  --blue: #243f6b;
  --line: #c7c0b2;
  --muted: #6b675f;
  --verified: #2d664a;
  --pending: #966015;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(255,255,255,.25), rgba(255,255,255,.25)),
    repeating-linear-gradient(90deg, transparent, transparent 89px, rgba(0,0,0,.025) 90px),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.masthead {
  padding: 24px clamp(22px, 6vw, 92px) 28px;
  border-bottom: 1px solid var(--ink);
}

.brand-row { display: flex; align-items: center; gap: clamp(24px, 5vw, 72px); }
.brand-lockup { flex: 0 0 auto; width: clamp(92px, 10vw, 126px); text-align: center; }
.client-logo { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; mix-blend-mode: multiply; }
.powered-by { display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 5px; white-space: nowrap; }
.powered-by span { color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.powered-by img { display: block; width: 58px; height: 34px; object-fit: contain; }
h1, h2 { font-family: Georgia, 'Times New Roman', serif; font-weight: 400; margin: 0; }
.product-title { flex: 1; min-width: 0; }
.product-title-main { display: block; font-size: clamp(48px, 7.4vw, 100px); line-height: .82; letter-spacing: -.055em; }
.product-title-main em { color: var(--red); font-weight: 400; }
.product-title-context { display: flex; align-items: center; gap: 9px; max-width: 650px; margin-top: 17px; font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: clamp(10px, 1.15vw, 14px); line-height: 1; letter-spacing: .19em; text-transform: uppercase; white-space: nowrap; }
.product-title-context::before { content: ''; width: clamp(30px, 4vw, 58px); height: 1px; margin-right: 3px; background: var(--red); }
.product-title-context::after { content: ''; flex: 1; height: 1px; margin-left: 8px; background: var(--line); }
.product-title-context span { color: var(--muted); }
.product-title-context strong { font-weight: 600; color: var(--ink); }

main { padding: 0 clamp(22px, 6vw, 92px) 80px; }
.search-panel { padding: 38px 0 32px; border-bottom: 1px solid var(--line); }
.search-panel form > label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .13em; margin-bottom: 10px; }
.search-row { display: grid; grid-template-columns: 1fr auto; border: 1px solid var(--ink); background: #faf8f2; }
.search-row input { border: 0; background: transparent; padding: 18px 20px; min-width: 0; outline: 0; font-size: clamp(17px, 2vw, 23px); }
.search-row button { border: 0; border-left: 1px solid var(--ink); background: var(--ink); color: white; padding: 0 34px; text-transform: uppercase; letter-spacing: .08em; }

.search-shortcuts { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 12px; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; }
.suggestions button { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 7px 12px; font-size: 12px; color: var(--muted); }
.suggestions button:hover { border-color: var(--red); color: var(--red); }
.favorites-button { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--red); background: transparent; color: var(--red); border-radius: 99px; padding: 8px 14px; font-size: 12px; white-space: nowrap; }
.favorites-button span { font-size: 15px; line-height: 1; }
.favorites-button:hover, .favorites-button.active { background: var(--red); color: white; }

.filters { display: flex; gap: 28px; flex-wrap: wrap; align-items: end; margin-top: 28px; }
.filters label { display: grid; gap: 7px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.filters select { min-width: 210px; border: 0; border-bottom: 1px solid var(--ink); padding: 8px 24px 8px 0; background: transparent; }
.active-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 16px; color: var(--pending); }
.active-filters strong { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; margin-right: 3px; }
.active-filters .intent-chip { border-color: var(--pending); }
.active-filters button { border: 0; background: transparent; color: var(--red); padding: 4px 6px; text-decoration: underline; text-underline-offset: 3px; font-size: 11px; }
.intent-panel { margin-top: 24px; border: 1px solid var(--blue); padding: 16px; background: rgba(36,63,107,.055); }
.intent-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.intent-heading strong { font-family: Georgia, serif; font-size: 19px; font-weight: 400; }
.intent-heading span, .intent-panel small { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.intent-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.intent-grid > div, .intent-synonyms { display: flex; align-items: center; align-content: flex-start; flex-wrap: wrap; gap: 6px; }
.intent-grid small, .intent-synonyms small { flex-basis: 100%; margin-bottom: 2px; }
.intent-chip { border: 1px solid var(--line); background: var(--paper); padding: 4px 7px; font-size: 11px; }
.intent-synonyms { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

.results-section { padding-top: 36px; }
.results-heading { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 22px; }
.results-heading h2 { font-size: 34px; }
#result-count { color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 28px 18px; }
.card { border-top: 1px solid var(--ink); padding-top: 10px; position: relative; cursor: pointer; }
.image-wrap { aspect-ratio: 4 / 5; overflow: hidden; background: #ddd6c8; position: relative; border: 1px solid #d8d0c1; display: flex; align-items: center; justify-content: center; }
.image-wrap.loading::before { content: ''; position: absolute; inset: 0; background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,.48) 46%, transparent 62%); transform: translateX(-100%); animation: image-loading 1.25s ease-in-out infinite; }
.image-wrap.unavailable::after { content: 'Anteprima non disponibile'; max-width: 150px; color: var(--muted); font-family: Georgia, serif; font-size: 15px; line-height: 1.2; text-align: center; }
.image-wrap img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; display: block; filter: saturate(.82) contrast(1.02); }
.card:hover .image-wrap img { transform: scale(1.015); transition: transform .25s ease; }
.card-body { padding-top: 12px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.badge { font-size: 9px; letter-spacing: .09em; text-transform: uppercase; border: 1px solid currentColor; padding: 4px 6px; }
.badge.type { color: var(--blue); }
.badge.source { color: var(--ink); background: rgba(27,27,24,.055); }
.card h3 { font-family: Georgia, serif; font-size: 21px; line-height: 1.1; margin: 0 0 8px; font-weight: 400; }
.meta { color: var(--muted); font-size: 12px; line-height: 1.45; min-height: 34px; }
.card-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
.card-actions button { border: 0; padding: 0; background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.action-links { display: flex; gap: 12px; align-items: center; font-size: 12px; }
.source-link { color: var(--red); text-underline-offset: 3px; }
.favorite { font-size: 20px; text-decoration: none !important; color: var(--muted); }
.favorite.active { color: var(--red); }

.notice { margin-bottom: 22px; padding: 13px 16px; border-left: 4px solid var(--blue); background: rgba(36,63,107,.08); }
.empty { grid-column: 1 / -1; padding: 60px 0; font-family: Georgia, serif; font-size: 25px; color: var(--muted); }
.favorites-empty { grid-column: 1 / -1; min-height: 250px; display: grid; place-items: center; align-content: center; gap: 8px; border: 1px dashed var(--line); color: var(--muted); text-align: center; }
.favorites-empty span { color: var(--red); font-size: 30px; }
.favorites-empty h3 { margin: 0; font-family: Georgia, serif; font-size: 27px; font-weight: 400; color: var(--ink); }
.favorites-empty p { max-width: 430px; margin: 0; font-size: 13px; line-height: 1.5; }

dialog { width: min(1080px, calc(100vw - 30px)); max-height: calc(100vh - 30px); border: 1px solid var(--ink); padding: 0; background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(16,17,15,.78); }
.dialog-close { position: sticky; float: right; top: 10px; right: 10px; z-index: 2; width: 40px; height: 40px; border: 1px solid var(--ink); background: var(--paper); font-size: 25px; }
.detail { padding: 26px; }
.detail h2 { font-size: clamp(34px, 5vw, 62px); max-width: 850px; line-height: .95; margin-bottom: 20px; }
.detail-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 20px 0 30px; }
.detail-gallery figure { margin: 0; background: #ded8cb; border: 1px solid #d2cabb; }
.detail-image-frame { height: min(430px, 56vh); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.detail-gallery img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.detail-gallery figcaption { padding: 8px 10px; font-size: 10px; color: var(--muted); border-top: 1px solid #d2cabb; }
.resolution-note { display: block; margin-top: 4px; text-transform: none; letter-spacing: 0; }
.limited-resolution .resolution-note { color: var(--pending); }
.image-unavailable .detail-image-frame::after { content: 'Anteprima non disponibile dalla fonte'; padding: 18px; color: var(--red); text-align: center; }
.image-unavailable img { display: none; }
.image-actions { padding: 0 10px 10px; }
.download-link { display: inline-block; color: var(--red); font-size: 12px; text-underline-offset: 3px; }
.similar-records { grid-column: 1 / -1; margin: -12px 0 18px; border: 1px solid var(--line); background: #f7f4ee; }
.similar-records > summary { cursor: pointer; padding: 12px 16px; color: var(--blue); font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.similar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; padding: 0 16px 16px; }
.load-more-wrap { grid-column: 1 / -1; display: flex; justify-content: center; padding: 22px 0 8px; }
.load-more { min-width: min(360px, 100%); border: 1px solid var(--ink); background: transparent; color: var(--ink); padding: 13px 26px; text-transform: uppercase; letter-spacing: .08em; }
.load-more:hover { background: var(--ink); color: white; }
.load-more span { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .04em; text-transform: none; }
.load-more:hover span { color: #d9d5ca; }
.detail-storage-note { margin: -15px 0 28px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 30px; border-top: 1px solid var(--ink); }
.field { padding: 12px 0; border-bottom: 1px solid var(--line); }
.field dt { text-transform: uppercase; letter-spacing: .1em; font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.field dd { margin: 0; line-height: 1.4; }
.provenance { margin-top: 24px; border: 1px solid var(--verified); padding: 16px; color: var(--verified); }
.provenance a { color: inherit; font-weight: 700; }

footer { border-top: 1px solid var(--ink); padding: 22px clamp(22px, 6vw, 92px); display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
footer a { color: var(--ink); }
.footer-links { display: flex; gap: 22px; }

@keyframes image-loading {
  to { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  .image-wrap.loading::before { animation: none; }
}

@media (max-width: 720px) {
  .brand-row { gap: 20px; }
  .brand-lockup { width: 86px; }
  .product-title-main { font-size: clamp(40px, 11vw, 68px); }
  .product-title-context { margin-top: 13px; letter-spacing: .12em; white-space: normal; }
  .product-title-context::after { display: none; }
  .search-row { grid-template-columns: 1fr; }
  .search-row button { border-left: 0; border-top: 1px solid var(--ink); padding: 14px; }
  .search-shortcuts { align-items: flex-start; flex-direction: column; }
  .intent-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-image-frame { height: 330px; }
}

@media (max-width: 480px) {
  .masthead { padding-top: 18px; }
  .brand-row { align-items: flex-start; gap: 16px; }
  .brand-lockup { width: 68px; }
  .product-title-main { font-size: clamp(35px, 10.6vw, 48px); line-height: .88; }
  .product-title-context { gap: 6px; margin-top: 10px; font-size: 8px; line-height: 1.35; }
  .product-title-context::before { width: 18px; margin-right: 0; }
  .powered-by { display: block; }
  .powered-by img { margin: 2px auto 0; }
  .intent-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Schermate aggiunte nella versione PHP: accesso, diagnostica, sessione.
   -------------------------------------------------------------------------- */

.session-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  padding: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.session-user strong { color: var(--ink); font-weight: 600; }

.session-link {
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.session-link:hover { border-bottom-color: var(--blue); }

.gate-body { display: flex; min-height: 100vh; }

.gate {
  margin: auto;
  padding: 24px;
  width: 100%;
  max-width: 420px;
}

.gate-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 32px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .06);
}

.gate-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -.01em;
}

.gate-subtitle {
  margin: 2px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

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

.gate-card input[type="text"],
.gate-card input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  font: inherit;
  color: var(--ink);
}

.gate-card input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.gate-card button {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 3px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.gate-card button:disabled { background: var(--muted); cursor: not-allowed; }

.gate-error {
  margin: 0 0 18px;
  padding: 10px 12px;
  border-left: 3px solid var(--red);
  background: rgba(163, 52, 42, .07);
  color: var(--red);
  font-size: 14px;
}

.gate-note {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.admin {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 8px;
}

.admin h1 { font-size: 24px; margin: 0; }

.admin h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 36px 0 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
  border: 1px solid var(--line);
}

.admin-table td, .admin-table th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-weight: 400;
}

.admin-table tr:last-child td,
.admin-table tr:last-child th { border-bottom: 0; }

.admin-table th { font-weight: 600; white-space: nowrap; }
.admin-table td:first-child { width: 28px; font-weight: 700; }
.check-ok td:first-child { color: var(--verified); }
.check-ko td:first-child { color: var(--red); }
.check-ko { background: rgba(163, 52, 42, .05); }

.admin-note { font-size: 14px; color: var(--muted); max-width: 62ch; }

.admin-action, .admin-form button {
  padding: 9px 14px;
  margin: 0 8px 8px 0;
  border: 1px solid var(--blue);
  border-radius: 3px;
  background: #fff;
  color: var(--blue);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.admin-action:hover, .admin-form button:hover { background: var(--blue); color: #fff; }
.admin-action:disabled { opacity: .5; cursor: progress; }

.admin-form { display: flex; gap: 8px; flex-wrap: wrap; }

.admin-form input {
  flex: 1 1 240px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  font: inherit;
}

.admin-output {
  margin-top: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 12.5px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
