/* ==========================================================================
   Componenti: marchio, ricerca, tasto tema, cartelle, dispense, messaggi
   ========================================================================== */

/* Icone inserite dal JS -------------------------------------------------- */

.icon {
  display: inline-grid;
}

.icon svg {
  width: 16px;
  height: 16px;
}

/* Marchio ---------------------------------------------------------------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 4px;
  border-radius: var(--radius-s);
}

.brand__mark {
  width: 24px;
  height: 24px;
}

.brand__name {
  font: 900 1.7rem/1 var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.01em;
}

/* Ricerca ---------------------------------------------------------------- */

.search {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 360px;
  height: 44px;
  margin-left: auto;
  padding: 0 8px 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  cursor: text;
  transition: border-color 0.18s ease, background-color 0.25s ease;
}

.search:focus-within {
  border-color: var(--text);
  color: var(--text);
}

.search__icon {
  flex: none;
  width: 18px;
  height: 18px;
}

.search input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search__key {
  flex: none;
  min-width: 26px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.search:focus-within .search__key {
  visibility: hidden;
}

/* Tasto tema ------------------------------------------------------------- */

.theme-toggle {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.25s ease;
}

.theme-toggle:hover {
  border-color: var(--muted);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* Nel tema scuro il tasto mostra il sole (porta al chiaro), e viceversa */
.theme-toggle__moon,
[data-theme="light"] .theme-toggle__sun {
  display: none;
}

[data-theme="light"] .theme-toggle__moon {
  display: block;
}

/* Bottone: "Carica dispensa", "Entra" ------------------------------------ */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px 0 16px;
  border: 1px solid var(--text);
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--bg);
  font: 500 0.82rem/1 var(--font-mono);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.button:hover {
  background: transparent;
  color: var(--text);
}

/* Senza icona i due lati hanno lo stesso margine */
button.button {
  padding-inline: 20px;
}

/* Password all'ingresso --------------------------------------------------- */

.lock {
  max-width: 420px;
}

.lock__row {
  display: flex;
  gap: 10px;
}

.lock__input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  outline: 0;
  background: var(--surface);
  transition: border-color 0.18s ease, background-color 0.25s ease;
}

.lock__input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.lock__input:focus {
  border-color: var(--text);
}

.lock__error {
  min-height: 1.5em;
  margin-top: 12px;
  padding-inline: 18px;
  color: var(--muted);
  font: 400 0.78rem/1.5 var(--font-mono);
}

/* Finché la password non è stata inserita la ricerca non serve */
html[data-locked] .search {
  visibility: hidden;
}

html[data-locked] .state--loading {
  display: none;
}

/* Cartella --------------------------------------------------------------- */

.folder {
  display: grid;
  grid-template-rows: auto 1fr;
  border-radius: var(--radius-l);
}

/* Linguetta colorata: piena se la cartella contiene dispense */
.folder__tab {
  justify-self: start;
  padding: 6px 14px 5px;
  border: 1px solid var(--accent);
  border-bottom: 0;
  border-radius: 13px 13px 0 0;
  background: var(--accent);
  color: var(--on-accent);
  font: 500 0.72rem/1.4 var(--font-mono);
  white-space: nowrap;
  transition: padding 0.18s ease, margin 0.18s ease;
}

.folder--empty .folder__tab {
  background: transparent;
  color: var(--muted);
}

.folder__body {
  display: flex;
  align-items: flex-end;
  min-height: 128px;
  padding: 18px 20px 16px;
  border: 1px solid var(--line);
  border-radius: 0 var(--radius-l) var(--radius-l) var(--radius-l);
  background: var(--surface);
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.folder__name {
  font: 900 2rem/0.95 var(--font-display);
  text-transform: uppercase;
  overflow-wrap: break-word;
}

.folder:hover .folder__body,
.folder:focus-visible .folder__body {
  border-color: var(--accent);
  background: var(--surface-raised);
}

/* Al passaggio la linguetta si alza, come sfilando la cartella */
.folder:hover .folder__tab,
.folder:focus-visible .folder__tab {
  margin-top: -5px;
  padding-top: 11px;
}

/* Dispensa --------------------------------------------------------------- */

.doc {
  min-width: 0;
}

.doc__tile {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--surface);
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.doc__tile:hover,
.doc__tile:focus-within {
  border-color: var(--accent);
  background: var(--surface-raised);
}

.doc__open {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
}

.doc__open:focus-visible {
  outline-offset: -5px;
}

.doc__ext {
  color: var(--muted);
  color: color-mix(in srgb, var(--text) 32%, transparent);
  font: 900 clamp(2.4rem, 9vw, 3.5rem) / 1 var(--font-display);
  transition: color 0.18s ease;
}

.doc__tile:hover .doc__ext,
.doc__tile:focus-within .doc__ext {
  color: var(--accent);
}

.doc__thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.doc__kind {
  position: absolute;
  bottom: 10px;
  left: 10px;
  max-width: calc(100% - 20px);
  padding: 3px 10px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--muted);
  font: 400 0.68rem/1.5 var(--font-mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc__download {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.doc__tile:hover .doc__download,
.doc__download:focus-visible {
  opacity: 1;
}

.doc__download:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Senza mouse il tasto di download resta sempre visibile */
@media (hover: none) {
  .doc__download {
    opacity: 1;
  }
}

.doc__title,
.doc__desc,
.doc__author {
  padding-inline: 6px;
  overflow-wrap: anywhere;
}

.doc__title {
  margin-top: 14px;
  font: 600 1.05rem/1.25 var(--font-body);
}

.doc__desc {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.doc__author {
  margin-top: 10px;
  color: var(--muted);
  font: 400 0.72rem/1.5 var(--font-mono);
}

/* Link "torna all'archivio" ---------------------------------------------- */

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font: 500 0.78rem/1.4 var(--font-mono);
  transition: color 0.18s ease, border-color 0.18s ease;
}

.crumb:hover {
  border-color: var(--muted);
  color: var(--text);
}

/* Messaggi: caricamento, cartella vuota, nessun risultato, errori -------- */

.state {
  max-width: 620px;
  margin-top: clamp(28px, 6vw, 72px);
  padding: clamp(22px, 4vw, 34px);
  border: 1px dashed var(--line);
  border-radius: var(--radius-l);
  color: var(--muted);
}

.page-head + .state {
  margin-top: 0;
}

.state__title {
  color: var(--text);
  font: 900 clamp(1.8rem, 6vw, 2.4rem) / 0.95 var(--font-display);
  text-transform: uppercase;
}

.state__text {
  margin-top: 12px;
}

.state__code {
  margin-top: 14px;
  padding: 12px 16px;
  overflow-x: auto;
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.6;
}

.state__text code {
  color: var(--text);
  font-size: 0.86em;
}

/* Avviso mostrato solo se la pagina è aperta con doppio clic (file://) */
.state--file,
html[data-file] .state--loading {
  display: none;
}

html[data-file] .state--file {
  display: block;
}

/* Schermi piccoli -------------------------------------------------------- */

@media (max-width: 560px) {
  .brand__mark {
    display: none;
  }

  .search__key {
    display: none;
  }

  .search {
    padding-right: 16px;
  }

  .folder__tab {
    padding-inline: 11px;
    font-size: 0.68rem;
  }

  .folder__body {
    min-height: 104px;
    padding: 14px 16px;
  }

  .folder__name {
    font-size: clamp(1.2rem, 6vw, 2rem);
  }

  .doc__kind {
    display: none;
  }
}
