/* SPDX-License-Identifier: AGPL-3.0-only — Copyright (C) 2026 Gabriele Falcinelli (https://gabrielefalcinelli.com)
   Termini aggiuntivi (attribuzione, nomi e loghi): ADDITIONAL-TERMS.md */
/* Font del logo (Riottosa Bold Condensed): non è su Google Fonts.
   Se installato nel sistema o presente in fonts/, viene usato; altrimenti fallback su Bungee. */
@font-face {
  font-family: "Riottosa";
  src: local("Riottosa Bold Condensed"), local("Riottosa-BoldCondensed"),
       url("fonts/Riottosa-BoldCondensed.woff2") format("woff2"),
       url("fonts/Riottosa-BoldCondensed.woff") format("woff");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg:          #ffffff;
  --ink:         #000000;
  --muted:       #999999;
  --field-border:#999999;
  --preview-bg:  #d9d9d9;
  --accent:      #ff3d00;
  --on-accent:   #ffffff;
  --ok:          #1e8e3e;
  --danger:      #d92d20;
  --pad:         40px;
  --font-display: "Riottosa", "Bungee", "Noto Sans", sans-serif;
}

:root[data-theme="dark"] {
  --bg:          rgb(37, 0, 0);
  --ink:         #f4f4f4;
  --muted:       #8a8a8a;
  --field-border:#777777;
  --preview-bg:  #2b2b2b;
  --ok:          #52b068;
  --danger:      #ff6b5e;
}

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

body {
  font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
a:hover { color: var(--accent); }

input, select, button, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── LAYOUT A DUE COLONNE ── */
.app {
  display: grid;
  grid-template-columns: minmax(400px, 42%) 1fr;
  height: 100vh;
}

.pane {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  min-width: 0;
}
.pane-left { border-right: 2px solid var(--accent); }

/* Scrollbar arancioni come da wireframe */
.pane::-webkit-scrollbar { width: 26px; }
.pane::-webkit-scrollbar-track { background: transparent; margin: 40px 0; }
.pane::-webkit-scrollbar-thumb {
  background: var(--accent);
  border: 8px solid transparent;
  border-radius: 99px;
  background-clip: padding-box;
}
@supports not selector(::-webkit-scrollbar) {
  .pane { scrollbar-color: var(--accent) transparent; scrollbar-width: thin; }
}

/* ── HEADER ── */
.site-header {
  padding: 44px 14px 36px var(--pad);
  border-bottom: 2px solid var(--accent);
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 56px; /* ricalcolato da ui.js per riempire la colonna */
  line-height: 1;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
}
.logo span { display: inline-block; }

.lead {
  margin-top: 36px;
  font-size: 14px;
  line-height: 1.45;
}

.donate-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 16px;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.5;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}
.donate-btn:hover { background: var(--accent); color: var(--on-accent); }

/* ── ISTRUZIONI ── */
.instructions-bar { margin-top: 18px; }

.instructions-toggle {
  color: var(--accent);
  font-size: 11.5px; /* come il testo esplicativo di "come si usa?" (.step-text) */
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.instructions-toggle .arrow { font-size: 7px; transition: transform 0.2s; }
.instructions-toggle.open .arrow { transform: rotate(180deg); }

/* "Perché ho creato questi strumenti?": un testo unico, con il corpo del testo esplicativo di
   "come si usa?" (.step-text), largo quanto la colonna */
.why-panel { display: none; padding-top: 22px; }
.why-panel.visible { display: block; }
.why-text { font-size: 11.5px; line-height: 1.4; }

.instructions-panel { display: none; padding-top: 22px; }
.instructions-panel.visible {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
}

.step-num {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 4px;
}

.step-text { font-size: 11.5px; line-height: 1.4; }
.step-text > strong {
  display: block;
  color: var(--accent);
  font-weight: 700;
}
.step-text em, .step-text span strong { font-style: normal; font-weight: inherit; }

.instr-warning {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}
.caps { font-size: 0.82em; font-weight: 900; text-transform: uppercase; }

/* ── CONTROLLI ── */
.controls { padding: 32px 14px 44px var(--pad); }

.field-group { margin-top: 30px; }

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  margin-bottom: 14px;
}

label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.hint {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.4;
}

.subsection-title {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

.cover-settings {
  margin-bottom: 14px;
  padding: 14px 14px 0;
  border: 2px dashed var(--accent);
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── TOOLTIPS ── */
.tooltip-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  color: var(--bg);
  font-size: 10px;
  font-weight: 900;
  cursor: help;
  position: relative;
  transition: background 0.2s;
}
.tooltip-icon:hover { background: var(--accent); }

.tooltip-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  right: -6px;
  transform: translateY(4px);
  margin-bottom: 8px;
  width: 220px;
  padding: 8px 12px;
  background: var(--ink);
  border-radius: 5px;
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.4;
  text-align: left;
  text-transform: none;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.tooltip-icon:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ── INPUT CON UNITÀ ── */
.input-unit {
  display: flex;
  border: 2px solid var(--field-border);
  border-radius: 5px;
  background: var(--bg);
  overflow: hidden;
  transition: border-color 0.15s;
}
.input-unit:focus-within { border-color: var(--accent); }

.unit {
  flex: 0 0 58px;
  display: grid;
  place-items: center;
  border-right: 2px solid var(--field-border);
  color: var(--muted);
  font-size: 13px;
}

input[type="number"],
input[type="text"] {
  flex: 1;
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 4px 6px;
  outline: none;
  font-size: 14px;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input::placeholder { color: var(--ink); opacity: 1; }

/* ── SELECT ── */
select, .cselect-btn {
  width: 100%;
  border: 2px solid var(--field-border);
  border-radius: 5px;
  background: var(--bg);
  padding: 4px 34px 4px 14px;
  font-size: 14px;
  text-align: left;
  outline: none;
}

.cselect { position: relative; }
.cselect-native { display: none; }
.cselect-btn {
  position: relative;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cselect-btn::after {
  content: '▼';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
}
.cselect.open .cselect-btn::after { content: '▲'; }
.cselect-btn:focus-visible, .cselect.open .cselect-btn { border-color: var(--accent); outline: none; }

.cselect-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  list-style: none;
  padding: 6px 0;
  border-radius: 5px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
}
.cselect-list li { padding: 3px 16px; cursor: pointer; }
.cselect-list li:hover,
.cselect-list li[aria-selected="true"]:hover { background: rgba(0,0,0,0.18); }

/* ── DROPZONE ── */
.dropzone {
  justify-content: flex-start;
  gap: 20px;
  padding: 10px 18px;
  border: 2px dashed var(--accent);
  color: var(--accent);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  transition: background 0.15s, color 0.15s;
}
.dropzone.dragover { background: rgba(255,61,0,0.10); }

.dz-icon {
  flex: 0 0 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
}

.dz-text { display: grid; min-width: 0; }
.dz-text strong, #fileName {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dz-drag, .dropzone small { font-size: 14px; font-weight: 700; }

/* stato "file non caricato" / "file caricato" */
#fileName, .dropzone small { display: none; }
body.has-file .dropzone {
  border-style: solid;
  background: var(--accent);
  color: var(--on-accent);
}
body.has-file .dz-icon { background: transparent; }
body.has-file .dz-text strong, body.has-file .dz-drag { display: none; }
body.has-file #fileName, body.has-file .dropzone small { display: block; }

/* ── GRIDS ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ── TOGGLES ── */
.toggles { margin-top: 24px; }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0 7px;
  border-bottom: 2px solid var(--accent);
}
.toggle-row label { flex: 1; cursor: pointer; }

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--bg) center / 12px no-repeat;
  cursor: pointer;
}
input[type="checkbox"]:checked {
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 6.5l3 3 6-7.5' fill='none' stroke='%23fff' stroke-width='1.6'/%3E%3C/svg%3E");
}
input[type="checkbox"]:disabled { cursor: not-allowed; }

/* ── BUTTONS ── */
.actions {
  display: grid;
  gap: 12px;
  margin-top: 60px;
}

.actions button {
  height: 46px;
  border: 2px solid var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
button.primary { background: var(--accent); color: var(--on-accent); }
button.secondary { background: var(--bg); color: var(--accent); }
button.primary:hover:not(:disabled) { opacity: 0.85; }
button.secondary:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); }
.actions button:disabled { opacity: 0.35; }

/* ── STATUS ── */
.status {
  margin-top: 10px;
  min-height: 16px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}
.status.ok  { color: var(--ok); }
.status.err { color: var(--danger); }

/* ── FOOTER ── */
footer {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 10px;
  font-size: 12px;
}
footer .version { color: var(--muted); }

/* ── COLONNA DESTRA ── */
.pane-right {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 32px;
  padding: 36px 8px 60px 72px;
}

.top-tools {
  position: sticky;
  top: 0;
  display: grid;
  gap: 6px;
}
.tool-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  transition: background 0.15s, color 0.15s;
}
.tool-btn:hover { background: var(--accent); color: var(--on-accent); }
.lang-btn { font-family: var(--font-display); font-size: 10px; }

.panel { min-width: 0; padding-top: 22px; }

/* ── METRICS ── */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  text-align: center;
  color: var(--accent);
}
.metric span {
  display: block;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.metric strong { font-size: 13px; font-weight: 700; }

/* ── PREVIEW ── */
.preview-wrap {
  margin-top: 40px;
  position: relative;
  aspect-ratio: 870 / 665;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--preview-bg);
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
}

.preview-placeholder { color: var(--muted); font-size: 14px; }

canvas { display: none; background: white; }
.preview-wrap.has-preview #pdfPreviewCanvas { display: block; transition: opacity 0.2s; }
.preview-wrap.has-preview .preview-placeholder { display: none; }
.preview-wrap.is-updating #pdfPreviewCanvas { opacity: 0.45; }

.preview-status {
  display: none;
  position: absolute;
  right: 10px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 10.5px;
}
.preview-wrap.is-pending .preview-status,
.preview-wrap.is-updating .preview-status { display: block; }

/* ── PAGER ── */
.pager {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--accent);
}
.pager button { display: grid; place-items: center; padding: 2px; }
.pager button:disabled { opacity: 1; }
.pager button:hover:not(:disabled) { opacity: 0.7; }
.pager-label {
  min-width: 70px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

/* ── TABLE ── */
.signature-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-top: 30px;
  text-align: center;
}
.signature-table th {
  padding: 8px 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.signature-table td {
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 800;
}
.sig-empty { display: none; }

/* ── MODALE DONAZIONE ── */
.modal {
  margin: auto;
  width: min(480px, calc(100vw - 32px));
  height: min(800px, calc(100vh - 32px));
  padding: 0;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}
.modal[open] { display: flex; flex-direction: column; animation: fadeIn 0.2s ease-out; }
.modal::backdrop { background: rgba(0, 0, 0, 0.6); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 12px 18px;
  border-bottom: 2px solid var(--accent);
}
.modal-head h2 {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.modal iframe {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #f9f9f9;
}

.modal-foot {
  padding: 10px 18px;
  border-top: 2px solid var(--accent);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}
.modal-foot a { color: var(--accent); }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  :root { --pad: 20px; }
  body { height: auto; overflow: auto; }
  .app { display: block; height: auto; }
  .pane { overflow: visible; }
  .pane-left { border-right: 0; border-bottom: 2px solid var(--accent); }
  .site-header, .controls { padding-right: var(--pad); }
  .pane-right { padding: 24px var(--pad) 48px; gap: 12px; }
}
@media (max-width: 540px) {
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .instructions-panel.visible { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

/* Theme Icons */
#themeToggle .icon-dark { display: none; }
#themeToggle .icon-light { display: block; }
:root[data-theme="dark"] #themeToggle .icon-dark { display: block; }
:root[data-theme="dark"] #themeToggle .icon-light { display: none; }

#themeToggle svg path.cls-1 { fill: currentColor; }

/* Ghiera del tema: sole e luna stanno su un cerchio che ruota attorno a un punto sotto il pulsante.
   L'icona della modalità attiva è in cima, l'altra a 90° verso destra (fuori dalla finestra).
   Al passaggio del puntatore la ghiera ruota verso sinistra: l'attiva esce a sinistra, l'altra entra
   da destra. Dopo il clic (.dial-reset) la ghiera si riallinea senza animazione fino all'uscita del
   puntatore, così l'icona appena entrata resta ferma. */
#themeToggle { position: relative; overflow: hidden; }
#themeToggle .theme-dial {
  position: absolute;
  inset: 0;
  transform-origin: 50% calc(50% + 22px);
  transition: transform 0.45s cubic-bezier(0.5, 0, 0.2, 1);
}
#themeToggle .theme-dial svg,
:root[data-theme="dark"] #themeToggle .theme-dial svg {
  display: block;
  position: absolute;
  /* icone di 15 px (erano 18, come nell'HTML): il centro resta al centro del pulsante */
  width: 15px;
  height: 15px;
  left: calc(50% - 7.5px);
  top: calc(50% - 7.5px);
  transform-origin: 7.5px calc(7.5px + 22px);
}
/* la luna è un po' più piccola del sole (13 px), con lo stesso centro e lo stesso perno della ghiera */
#themeToggle .theme-dial .icon-dark,
:root[data-theme="dark"] #themeToggle .theme-dial .icon-dark {
  width: 13px;
  height: 13px;
  left: calc(50% - 6.5px);
  top: calc(50% - 6.5px);
  transform-origin: 6.5px calc(6.5px + 22px);
}
#themeToggle .theme-dial .icon-dark { transform: rotate(90deg); }
:root[data-theme="dark"] #themeToggle .theme-dial .icon-dark { transform: none; }
:root[data-theme="dark"] #themeToggle .theme-dial .icon-light { transform: rotate(90deg); }
#themeToggle:hover .theme-dial,
#themeToggle:focus-visible .theme-dial { transform: rotate(-90deg); }
#themeToggle.dial-reset .theme-dial { transform: none; transition: none; }
@media (prefers-reduced-motion: reduce) {
  #themeToggle .theme-dial { transition: none; }
}

/* ── FOOTER POPOVERS ── */
.footer-popover-wrapper {
  position: relative;
  display: inline-block;
}

.footer-popover-content {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  /* --pop-shift / --pop-max: impostati da ui.js perché la finestra resti dentro la colonna */
  transform: translateX(calc(-50% + var(--pop-shift, 0px)));
  width: 280px;
  max-width: var(--pop-max, none);
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg);
  border: 2px solid var(--accent);
  padding: 12px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  cursor: default;
}

.footer-popover-content.active {
  display: block;
}

.footer-popover-content h4 {
  color: var(--accent);
  font-family: inherit;
  font-weight: 900;
  font-size: 14px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.footer-popover-content p {
  font-family: inherit;
  font-weight: 700; /* Bold come il testo di "come si usa?"; i titoli restano Black */
  font-size: 11px; /* Proporzionalmente più piccolo, simile al footer ma leggibile */
  color: var(--ink);
  line-height: 1.3;
  margin-bottom: 8px;
}

.footer-popover-content p:last-child {
  margin-bottom: 0;
}

/* Scrollbar ridotta per il popover */
.footer-popover-content::-webkit-scrollbar {
  width: 12px;
}
.footer-popover-content::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}
.footer-popover-content::-webkit-scrollbar-thumb {
  background: var(--accent);
  border: 4px solid transparent;
  border-radius: 99px;
  background-clip: padding-box;
}




.version-link {
  color: var(--muted);
  text-decoration: none;
}
.version-link:hover {
  color: var(--accent);
}
.changelog-popover {
  width: 320px;
  max-height: 250px;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  word-wrap: break-word;
}
.changelog-popover ul {
  margin-left: 12px;
  margin-bottom: 12px;
  padding-left: 4px;
  padding-right: 8px;
  list-style-type: square;
}
.changelog-popover h5 {
  color: var(--accent);
  font-family: inherit;
  font-weight: 900;
  font-size: 13px;
  margin-top: 8px;
  margin-bottom: 4px;
}
.changelog-popover p, .changelog-popover li {
  font-family: inherit;
  font-weight: 700;
  font-size: 11px;
  color: var(--ink);
  line-height: 1.3;
}
