/* Librarium — scheda libro v2 (stelle, genere, stato, prestito), libreria (genere/ordina),
   pagina Prestiti, Esporta/Importa. Usa solo i gettoni di app.css; bersagli tattili ≥ 44 px. */

/* --- stelle ------------------------------------------------------------------------ */
.stars { display: inline-flex; flex-wrap: nowrap; width: max-content; max-width: none; align-items: center; gap: 2px; vertical-align: middle; line-height: 1; --star: 1.05rem; --star-on: #C9973F; height: var(--star); }
.stars.small { --star: .9rem; margin-top: 2px; }
.stars.big { --star: 2rem; gap: 4px; }
.star { position: relative; flex: none; width: var(--star); height: var(--star); display: inline-block; font-size: var(--star); line-height: 1; }
.star::before, .star::after { content: "★"; position: absolute; inset: 0; line-height: 1; overflow: hidden; }
.star::before { color: color-mix(in srgb, var(--ink-2) 28%, transparent); }
.star::after { color: var(--star-on); width: 0; }
.star.full::after { width: 100%; }
.star.half::after { width: 50%; }
@media (prefers-color-scheme: dark) { .stars { --star-on: #E3B35C; } }

.rating-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.rating-input { display: inline-flex; flex-wrap: wrap; max-width: 100%; align-items: center; gap: 6px 12px; line-height: 1.2; min-height: 52px; padding: 4px 12px 4px 8px; border-radius: 12px;
  border: 1px solid var(--field-border); background: var(--surface); cursor: pointer; touch-action: manipulation; user-select: none; }
.rating-input:focus-visible { border-color: var(--accent); }
.rating-val { font-size: var(--step--1); color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 6.5em; }
.rating-line { display: flex; align-items: center; gap: 8px; margin: 4px 0; line-height: 1; }
.rating-line .stars { --star: 1.4rem; height: var(--star); }
.rating-line .muted { line-height: 1; }

/* --- genere ------------------------------------------------------------------------ */
.genre-input { display: grid; gap: 8px; }
.genre-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.genre-chips:empty { display: none; }
.genre-chip { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 2px 0 14px; border-radius: 999px;
  background: color-mix(in srgb, var(--cloth) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cloth) 35%, transparent); font-weight: 600; }
.genre-chip { max-width: 100%; }
.genre-chip > :first-child { min-width: 0; overflow-wrap: anywhere; }
button.genre-x { flex: none; min-height: 44px; width: 44px; padding: 0; border: 0; background: none; border-radius: 50%; color: var(--ink-2); }
button.genre-x:hover { background: var(--surface-2); }
.genre-add { display: flex; gap: 8px; }
.genre-add input { flex: 1; min-width: 0; }
.genre-add button { flex: none; }
.quick-dates { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* --- testata della scheda ------------------------------------------------------------ */
.series-line { margin: 0 0 6px; color: var(--ink-2); font-size: var(--step--1); font-weight: 600; letter-spacing: .01em; }
.hero-stars { margin: 0 0 6px; line-height: 1; }
.hero-stars .stars { --star: 1.25rem; width: max-content; }
.genre-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
a.genre-tag { display: inline-flex; align-items: center; min-height: 32px; padding: 2px 12px; border-radius: 999px; font-size: .8125rem; font-weight: 600;
  color: var(--cloth); background: color-mix(in srgb, var(--cloth) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cloth) 28%, transparent); text-decoration: none; }
@media (prefers-color-scheme: dark) { a.genre-tag { color: var(--link); } }
@media (pointer: coarse) { a.genre-tag { min-height: 44px; padding-inline: 14px; } }

/* stato del libro: segmenti su pergamena; quello attivo è avorio con icona colorata (colore + icona + testo) */
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 4px 0 2px; }
.status-chips { display: flex; flex-wrap: wrap; width: 100%; padding: 5px; gap: 6px; border-radius: 18px; background: var(--pergamena, #EDE4D3); }
.status-chips .chip { flex: 1 1 6.5rem; min-width: 0; border: 0; background: transparent; min-height: 44px; height: auto; padding: 0 8px; gap: 6px; border-radius: 14px;
  color: var(--seppia, #5E5248); font: 700 .8125rem/1.2 var(--sans, sans-serif); white-space: normal; text-align: center; justify-content: center; box-shadow: none; }
.status-chips .chip:hover { background: color-mix(in srgb, var(--avorio, #FFFDF8) 45%, transparent); color: var(--inchiostro, #231A14); }
.status-chips .chip[aria-pressed="true"] { background: var(--avorio, #FFFDF8); color: var(--verde, #1E4434); box-shadow: 0 4px 12px -6px rgb(35 26 20 / .35); }
.status-chips .chip .icon { width: 16px; height: 16px; flex: none; }
.status-chips .chip[aria-pressed="true"] .icon { width: 20px; height: 20px; padding: 3px; border-radius: 50%; stroke-width: 2.4; }
.status-chips .st-own[aria-pressed="true"] { color: var(--ok-ink, #1F4F38); }
.status-chips .st-own[aria-pressed="true"] .icon { background: var(--ok-bg, #DCE7DD); }
.status-chips .st-lent[aria-pressed="true"] { color: var(--order-ink, #7A4410); }
.status-chips .st-lent[aria-pressed="true"] .icon { background: var(--order-bg, #F6E6CF); }
.status-chips .st-wish[aria-pressed="true"] { color: var(--no-ink, #7E2A1F); }
.status-chips .st-wish[aria-pressed="true"] .icon { background: var(--no-bg, #F4DFDA); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .status-chips .st-own[aria-pressed="true"] { color: var(--ok-ink); } }
@media (max-width: 360px) { .status-chips .chip { font-size: .75rem; padding: 0 4px; gap: 4px; } }
.wish-flag { display: inline-flex; align-items: center; gap: 6px; font-size: var(--step--1); font-weight: 700; color: var(--order-ink, #7A4410);
  padding: 6px 12px; border-radius: 999px; background: var(--order-bg, #F6E6CF); }

/* --- prestito --------------------------------------------------------------------------- */
.loan-card { border-left: 4px solid var(--q-sky-ink, var(--shared)); }
.loan-card.soon { border-left-color: var(--warn); }
.loan-card.late { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 5%, var(--surface)); }
.loan-line { font-size: 1.05rem; margin: 2px 0 4px; }
.loan-due.late { color: var(--danger); font-weight: 650; }
.loan-due.soon { color: var(--warn); font-weight: 600; }
.loan-due .icon { width: 1em; height: 1em; margin-right: 2px; }
.loan-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.loan-actions .button, .loan-actions button { min-height: 44px; width: 100%; padding: 8px 10px; text-align: center; line-height: 1.2; white-space: normal; }
@media (min-width: 700px) { .loan-actions { display: flex; flex-wrap: wrap; } .loan-actions .button, .loan-actions button { width: auto; padding-inline: 14px; } }
.badge.lent.late { color: var(--danger); background: color-mix(in srgb, var(--danger) 11%, var(--surface)); }

/* --- libreria: genere e ordinamento ---------------------------------------------------- */
.lib-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 2px; }
.lib-tool { position: relative; flex: 1 1 11rem; min-width: min(11rem, 100%); max-width: 280px; }   /* la scelta («Tutti i generi») si legge intera */
.lib-tool > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; width: 1.1em; height: 1.1em; }
.lib-tool select { padding-left: 38px; min-height: 44px; font-size: var(--step--1); border-radius: 999px; border-color: var(--line);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--field-border) 55%, transparent); }

/* --- foto: copertina scelta --------------------------------------------------------------- */
.photos.v2 figure { width: 150px; }
.photos.v2 img { width: 150px; height: 150px; }
.photos.v2 figure button { width: 100%; padding-inline: 8px; }
.photos.v2 .add-photo { width: 150px; height: 150px; }
.photos.v2 figure.is-cover img { outline: 3px solid var(--tape); outline-offset: 2px; }
.cover-flag { display: inline-flex; align-items: center; gap: 4px; font-size: .8125rem; font-weight: 650; color: var(--warn); }
.cover-flag .icon { width: 14px; height: 14px; }
@media (max-width: 380px) { .photos.v2 figure, .photos.v2 img, .photos.v2 .add-photo { width: 136px; } .photos.v2 img, .photos.v2 .add-photo { height: 136px; } }

/* --- pagina Prestiti --------------------------------------------------------------------- */
.loan-group h2 .count { font-family: var(--sans); font-size: var(--step--1); color: var(--ink-2); font-weight: 500; margin-left: 2px; }
.loan-group.overdue h2, .loan-group.overdue h2 .icon { color: var(--danger); }
ul.loans { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.loan-item { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--shared); border-radius: var(--r-m); padding: 12px 14px; }
.loan-item.soon { border-left-color: var(--warn); }
.loan-item.late { border-left-color: var(--danger); }
.loan-book { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 14px; align-items: start; }
.loan-book .title { font-size: 1.1rem; line-height: 1.25; }
/* chi e da quando: testo che scorre (il nome lungo va a capo con il resto, non in colonne strette) */
.loan-who { display: block; font-size: var(--step--1); margin-top: 4px; line-height: 1.4; overflow-wrap: break-word; }
.loan-who .icon { width: 1em; height: 1em; vertical-align: -.125em; margin-right: 6px; }
.loan-book .loan-due { display: flex; align-items: center; gap: 6px; font-size: var(--step--1); margin-top: 4px; }
.loan-book .loan-due .icon { width: 1em; height: 1em; flex: none; }
.loans-privacy { margin-top: 18px; display: flex; gap: 6px; align-items: flex-start; }

/* --- Esporta / Importa ------------------------------------------------------------------- */
.io-box { display: grid; gap: 12px; }
.io-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.io-actions > * { flex: 1 1 auto; }
@media (min-width: 600px) { .io-actions > * { flex: 0 0 auto; } }
.io-summary { font-weight: 650; font-size: 1rem; line-height: 1.35; display: flex; align-items: flex-start; gap: 6px; margin: 6px 0; }
.io-summary .icon { margin-top: 1px; color: var(--ok); }
.io-mapping summary { font-size: var(--step--1); font-weight: 600; color: var(--link); text-decoration: underline; text-underline-offset: 3px; }
.io-mapping ul.plain li { padding: 4px 0; }
.io-summary.ok { color: var(--ok); }
.io-progress { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.io-progress progress { flex: 1; max-width: 240px; height: 8px; accent-color: var(--accent); }
.io-table { max-height: 46dvh; overflow: auto; border: 1px solid var(--line); border-radius: 18px; margin: 8px 0; background: var(--avorio, var(--surface)); }
.io-table table { font-size: .8125rem; }
.io-table th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
.io-table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink-2); }
.io-table tr.io-invalid td { background: color-mix(in srgb, var(--danger) 6%, transparent); }
.io-status { display: inline-block; font-weight: 650; white-space: nowrap; }
.io-status { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 8px; font-size: .75rem; }
.io-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.io-status.ok { color: var(--ok-ink, var(--ok)); background: var(--ok-bg, transparent); }
.io-status.duplicate { color: var(--order-ink, var(--warn)); background: var(--order-bg, transparent); }
.io-status.invalid { color: var(--no-ink, var(--danger)); background: var(--no-bg, transparent); }
.io-reason { display: block; color: var(--ink-2); font-size: .75rem; }
.io-tr { margin-left: 6px; font-size: .75rem; padding: 0 6px; }
.io-options { margin: 8px 0; }
.io-options legend { font-size: 1.05rem; }

/* --- Esporta / Importa: sistema «Biblioteca Mia» ------------------------------------------- */
.io-card.card-sec { border-radius: 22px; padding: 18px; }
.io-card .card-head h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; }
.io-card .card-head h2 .icon { width: 40px; height: 40px; padding: 9px; border-radius: 14px; background: var(--q-sage, #DCE7DD); color: var(--q-sage-ink, #1E4434); }
.io-card.io-import-card .card-head h2 .icon { background: var(--q-peach, #F3DED0); color: var(--q-peach-ink, #A8481F); }
.io-card select { background-color: var(--pergamena, #EDE4D3); border-color: transparent; }
.io-actions button, .io-actions .button { min-height: 48px; border-radius: 14px; }
label.io-pick { width: 100%; min-height: 96px; flex-direction: column; gap: 6px; border-radius: 18px; background: var(--carta, #F5EFE4); color: var(--inchiostro, #231A14);
  border: 2px dashed color-mix(in srgb, var(--verde, #1E4434) 40%, transparent); box-shadow: none; font-weight: 800; }
label.io-pick:hover { background: color-mix(in srgb, var(--ok-bg, #DCE7DD) 60%, var(--carta, #F5EFE4)); color: var(--inchiostro, #231A14); }
label.io-pick .icon { width: 28px; height: 28px; color: var(--verde, #1E4434); }
.io-pick-sub { font: 600 .75rem/1.3 var(--sans, sans-serif); color: var(--seppia, #5E5248); }
#io-file:focus-visible + label.io-pick, label.io-pick:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.io-summary { padding: 12px 14px; border-radius: 16px; background: var(--avorio, #FFFDF8); border: 1px solid var(--line, rgb(35 26 20 / .08)); font-weight: 700; }
.io-summary.ok { background: var(--ok-bg, #DCE7DD); color: var(--ok-ink, #1F4F38); border-color: transparent; }
.io-summary.ok .icon, .io-summary .icon { color: var(--ok-ink, var(--ok)); }
.io-options { background: var(--carta, #F5EFE4); border-radius: 18px; padding: 12px 14px 4px; }
.io-progress progress { accent-color: var(--verde, #1E4434); }
.io-table th { background: var(--pergamena, #EDE4D3); }
