:root {
  font-family: system-ui, -apple-system, sans-serif;
  color: #182033;
  background: #f3f5f8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

header {
  background: #172033;
  color: white;
  padding: 28px max(18px, calc((100vw - 900px) / 2));
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

small {
  letter-spacing: 0.16em;
  color: #b9c5d8;
}

h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  margin: 5px 0;
}

header p {
  color: #cbd4e2;
  margin: 0;
}

.counter {
  background: #293650;
  padding: 12px 20px;
  border-radius: 12px;
  display: grid;
  text-align: center;
}

.counter b {
  font-size: 1.5rem;
}

.counter span {
  font-size: 0.8rem;
}

main {
  max-width: 900px;
  margin: 24px auto;
  padding: 0 15px;
  display: grid;
  gap: 18px;
}

.panel {
  background: white;
  border: 1px solid #e2e7ef;
  border-radius: 15px;
  padding: 20px;
}

h2 {
  font-size: 1.2rem;
  margin: 0 0 15px;
}

.actions,
.line {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.duplicate-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 0;
}

.duplicate-actions button {
  width: 100%;
  text-align: center;
}

button,
.button {
  border: 0;
  border-radius: 9px;
  padding: 11px 15px;
  background: #e9edf4;
  color: #23314a;
  font-weight: 650;
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
}

.primary {
  background: #315eea;
  color: white;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

input {
  font: inherit;
  border: 1px solid #cbd3df;
  border-radius: 9px;
  padding: 11px;
  min-width: 0;
}

.line input {
  flex: 1 1 200px;
}

.line button {
  flex: 0 0 auto;
}

label {
  display: block;
  font-size: 0.88rem;
  font-weight: 650;
  color: #47536a;
  margin: 12px 0;
}

label input,
label select,
label textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
}

textarea {
  font: inherit;
  border: 1px solid #cbd3df;
  border-radius: 9px;
  padding: 11px;
  min-width: 0;
  resize: vertical;
}

select {
  font: inherit;
  border: 1px solid #cbd3df;
  border-radius: 9px;
  padding: 11px;
  background: white;
  color: inherit;
  min-width: 0;
}

.video-wrap {
  position: relative;
  margin-top: 14px;
  background: #111;
  border-radius: 12px;
  overflow: hidden;
}

.video-wrap[hidden] {
  display: none;
}

#video {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: #111;
}

.scan-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(80%, 460px);
  height: 32%;
  transform: translate(-50%, -50%);
  border: 2px solid #ffffffcc;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px #0006;
  pointer-events: none;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: #5b677c;
  font-size: 0.85rem;
}

.zoom-controls[hidden] {
  display: none;
}

.zoom-controls input {
  flex: 1;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

label.button {
  display: inline-block;
  margin: 0;
  color: #23314a;
  font-size: 0.9rem;
  font-weight: 650;
  text-align: center;
}

#status {
  color: #5b677c;
  font-size: 0.9rem;
  min-height: 1.2em;
}

.hint {
  color: #5b677c;
  font-size: 0.82rem;
  margin: 10px 0 0;
}

/* Sul Mac il QR serve per aprire il catalogo sul telefono; sul telefono
   sarebbe solo un codice che punta alla pagina già aperta. */
.phone-link {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #edf0f4;
}

.phone-link summary {
  cursor: pointer;
  font-weight: 650;
  color: #24409b;
}

.invite-button {
  display: inline-block;
  margin-top: 10px;
}

.phone-link img {
  display: block;
  width: 180px;
  height: 180px;
  margin-top: 10px;
  background: white;
  border: 1px solid #e2e7ef;
  border-radius: 8px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.section-head h2 {
  margin: 0;
}

.section-head input {
  width: min(240px, 55vw);
}

.book {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 12px;
  align-items: center;
  border-top: 1px solid #edf0f4;
  padding: 12px 8px;
  margin: 0 -8px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.book:hover,
.book:focus-visible {
  background: #f4f7fb;
  outline: none;
}

.book:focus-visible {
  box-shadow: inset 0 0 0 2px #315eea55;
}

.book-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.edit {
  background: #eef3ff;
  color: #24409b;
  padding: 8px;
}

.cover {
  width: 58px;
  height: 78px;
  object-fit: cover;
  background: #edf0f4;
  border-radius: 4px;
}

.book h3 {
  font-size: 1rem;
  margin: 0 0 4px;
}

.book p {
  font-size: 0.83rem;
  color: #5b677c;
  margin: 3px 0;
}

.delete {
  background: #fff0f0;
  color: #9b2525;
  padding: 8px;
}

#editor {
  border: 0;
  border-radius: 15px;
  width: min(500px, calc(100% - 24px));
  padding: 20px;
  box-shadow: 0 20px 70px #0005;
}

#editor::backdrop {
  background: #10182799;
}

#bookForm {
  display: grid;
  gap: 5px;
}

#coverPreview img {
  width: 58px;
  height: 78px;
  object-fit: cover;
  border-radius: 4px;
}

.x {
  font-size: 1.4rem;
  padding: 2px 10px;
}

.end {
  justify-content: flex-end;
  margin-top: 12px;
}

footer {
  max-width: 900px;
  margin: 0 auto 25px;
  padding: 0 15px;
  color: #5b677c;
  font-size: 0.8rem;
}

:focus-visible {
  outline: 3px solid #315eea;
  outline-offset: 2px;
}

@media (max-width: 550px) {
  header {
    padding: 22px 16px;
  }

  .panel {
    padding: 16px;
  }

  .section-head .actions {
    width: 100%;
  }

  .section-head input {
    flex: 1;
    width: 100%;
  }
}

/* --------------------------- catalogazione --------------------------- */

.count-badge {
  display: inline-block;
  background: #eef3ff;
  color: #24409b;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
  vertical-align: middle;
  margin-left: 6px;
}

.filters {
  margin: 14px 0;
}

.filter-main {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-main #filter {
  flex: 1 1 240px;
}

.filter-main select {
  flex: 0 1 210px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #edf0f4;
}

.filter-grid[hidden] {
  display: none;
}

.filter-grid label {
  margin: 8px 0;
}

.filter-grid .reset {
  align-self: end;
  margin: 8px 0;
  background: #f3f5f8;
}

.facets {
  display: grid;
  gap: 8px;
  margin: 10px 0 6px;
}

.facets[hidden] {
  display: none;
}

.facet-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.facet-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7a8598;
  min-width: 76px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips.small {
  margin-top: 6px;
}

#subjectSuggestions {
  margin: 6px 0 12px;
}

#subjectSuggestions:empty {
  display: none;
}

.chip {
  display: inline-block;
  background: #eef1f6;
  color: #3d4a61;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 0;
}

.chip-genre {
  background: #e6ecff;
  color: #24409b;
}

.chip-button {
  cursor: pointer;
  font-family: inherit;
}

.chip-button:hover {
  background: #dde5f7;
}

.chip-button.active {
  background: #315eea;
  color: white;
}

.book-info {
  min-width: 0;
}

.load-more {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.load-more button[hidden] {
  display: none;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

@media (max-width: 550px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

#editor {
  width: min(680px, calc(100% - 24px));
  max-height: 92vh;
  overflow-y: auto;
}

/* ----------------------------- scheda libro ----------------------------- */

#detail {
  border: 0;
  border-radius: 15px;
  width: min(680px, calc(100% - 24px));
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 70px #0005;
}

#detail::backdrop {
  background: #10182799;
}

.detail-top {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 18px;
  margin: 6px 0 14px;
}

.detail-cover-img,
.detail-cover .placeholder {
  width: 140px;
  height: 196px;
  object-fit: cover;
  border-radius: 6px;
  background: #edf0f4;
}

.detail-cover .placeholder {
  display: grid;
  place-items: center;
  font-size: 2.4rem;
}

.detail-meta {
  margin: 0;
}

.meta-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #f0f2f6;
  font-size: 0.86rem;
}

.meta-row:last-child {
  border-bottom: 0;
}

.meta-row dt {
  color: #7a8598;
  font-weight: 650;
}

.meta-row dd {
  margin: 0;
  color: #2a3446;
  overflow-wrap: anywhere;
}

.detail-section {
  margin-top: 16px;
}

.detail-section h3 {
  font-size: 0.95rem;
  margin: 0 0 6px;
  color: #3d4a61;
}

.long-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: #333e52;
  white-space: pre-line;
}

.detail-section.missing .long-text {
  color: #7a8598;
  font-style: italic;
}

.edition-list {
  display: grid;
  gap: 8px;
}

.edition-item {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #dbe1ea;
  border-radius: 7px;
  background: #f8fafc;
  color: #2a3446;
  text-align: left;
  cursor: pointer;
}

.edition-item:hover,
.edition-item:focus-visible {
  border-color: #172033;
  background: #eef2f7;
}

.edition-item strong {
  font-size: 0.9rem;
}

.edition-item span {
  color: #7a8598;
  font-size: 0.78rem;
}

@media (max-width: 550px) {
  .detail-top {
    grid-template-columns: 96px 1fr;
  }

  .detail-cover-img,
  .detail-cover .placeholder {
    width: 96px;
    height: 134px;
  }

  .meta-row {
    grid-template-columns: 78px 1fr;
  }
}

/* --------------------------- sezioni mobile ------------------------------ */

/* Sul desktop restano il catalogo unico e i suoi filtri: questi elementi
   servono solo alla navigazione a schede del telefono. */
.search-panel,
.mobile-nav {
  display: none;
}

@media (max-width: 700px) {
  body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .phone-link {
    display: none;
  }

  header {
    padding: 15px 16px;
    gap: 12px;
  }

  header small,
  header p {
    display: none;
  }

  header h1 {
    margin: 0;
    font-size: 1.55rem;
  }

  .counter {
    padding: 8px 14px;
    border-radius: 10px;
  }

  .counter b {
    font-size: 1.25rem;
  }

  .counter span {
    font-size: 0.72rem;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: fixed;
    z-index: 60;
    left: 0;
    right: 0;
    bottom: 0;
    padding:
      8px max(10px, env(safe-area-inset-left))
      calc(8px + env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-right));
    background: #172033;
    border-top: 1px solid #2b3953;
    box-shadow: 0 -8px 24px #10182726;
  }

  .mobile-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: transparent;
    color: #cbd4e2;
    padding: 11px 10px;
    border-radius: 11px;
    font-size: 0.92rem;
  }

  .mobile-tab.active {
    background: #2b3b59;
    color: white;
  }

  main > [data-mobile-section] {
    display: none;
  }

  body[data-mobile-section="library"] main > [data-mobile-section="library"],
  body[data-mobile-section="search"] main > [data-mobile-section="search"] {
    display: block;
  }

  /* Nel catalogo mobile basta l'elenco: tutti i filtri vivono in «Ricerca». */
  body[data-mobile-section="library"] #filterForm,
  body[data-mobile-section="library"] #facets {
    display: none;
  }

  .search-panel .filter-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px 10px;
    border-top: 0;
    padding-top: 0;
    margin-top: 12px;
  }

  .search-panel .filter-grid label {
    margin: 0;
    font-size: 0.8rem;
  }

  .search-panel .filter-grid input,
  .search-panel .filter-grid select {
    width: 100%;
    font-size: 1rem;
    padding: 9px;
  }

  .search-panel .search-actions {
    margin-top: 14px;
  }

  .search-panel .search-actions .primary {
    flex: 1;
  }

  .search-panel .section-head .reset {
    padding: 9px 12px;
    font-size: 0.82rem;
  }
}

/* --------------------------- valori e prestiti --------------------------- */

.value-summary {
  margin: 10px 0 4px;
  padding: 9px 12px;
  border-radius: 9px;
  background: #f4f7fb;
  color: #3d4a61;
  font-size: 0.84rem;
  line-height: 1.5;
}

.value-summary[hidden] {
  display: none;
}

.book-price {
  color: #24409b !important;
  font-weight: 650;
}

.loan-badge {
  color: #8a5a00 !important;
  font-weight: 650;
}

.loan-badge.overdue {
  color: #9b2525 !important;
}

.loan-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.loan-status[hidden] {
  display: none;
}

.loan-status > p {
  margin: 0;
  font-size: 0.88rem;
}

.loan-available {
  color: #3f7a4d;
  font-weight: 600;
}

.loan-active {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #dfe4ec;
  border-radius: 9px;
  background: #f8fafc;
}

.loan-active.overdue {
  border-color: #e7b4b4;
  background: #fff6f6;
}

.loan-active p {
  margin: 2px 0;
  font-size: 0.85rem;
}

.loan-active .actions {
  margin-top: 8px;
}

.loan-notes {
  color: #5b677c;
  white-space: pre-line;
}

.loan-form {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #dfe4ec;
  border-radius: 9px;
  background: #f8fafc;
}

.loan-form[hidden] {
  display: none;
}

.loan-history-inline {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.loan-history-title {
  margin: 8px 0 2px;
  font-size: 0.86rem;
  font-weight: 650;
  color: #3d4a61;
}

.loan-history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid #f0f2f6;
  font-size: 0.8rem;
  color: #5b677c;
}

.link-danger {
  padding: 2px 4px;
  background: none;
  color: #9b2525;
  font-size: 0.78rem;
}

.loan-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.loan-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #e4e8ef;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.loan-item:hover,
.loan-item:focus-visible {
  background: #f7f9fc;
  outline: none;
}

.loan-item:focus-visible {
  box-shadow: inset 0 0 0 2px #315eea55;
}

.loan-item.overdue {
  border-color: #e7b4b4;
  background: #fff8f8;
}

.loan-cover {
  width: 44px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  background: #edf0f4;
}

.loan-info {
  min-width: 0;
}

.loan-info h3 {
  margin: 0 0 2px;
  font-size: 0.95rem;
}

.loan-info p {
  margin: 2px 0;
  font-size: 0.8rem;
  color: #5b677c;
}

.loan-info .loan-meta {
  color: #7a8598;
}

.loan-info .loan-who b {
  color: #2a3446;
}

.loan-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loan-actions button {
  padding: 8px 10px;
  font-size: 0.8rem;
}

.loan-history {
  margin-top: 16px;
}

.loan-history > summary {
  padding: 6px 0;
  color: #3d4a61;
  font-weight: 650;
  cursor: pointer;
}

.tab-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #315eea;
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
}

.tab-badge[hidden] {
  display: none;
}

.tab-badge.alert {
  background: #c0392b;
}

@media (max-width: 700px) {
  .mobile-nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .mobile-tab {
    flex-direction: column;
    gap: 2px;
    padding: 8px 4px;
    font-size: 0.8rem;
  }

  body[data-mobile-section="loans"] main > [data-mobile-section="loans"] {
    display: block;
  }

  .loan-item {
    grid-template-columns: 38px 1fr auto;
    gap: 9px;
    padding: 9px;
  }

  .loan-cover {
    width: 38px;
    height: 52px;
  }

  .loan-actions button {
    padding: 7px 8px;
    font-size: 0.75rem;
  }
}

/* ------------------------------ visore copertina ------------------------------ */

.cover-zoom {
  cursor: zoom-in;
}

.detail-cover-img.cover-zoom {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.detail-cover-img.cover-zoom:hover,
.detail-cover-img.cover-zoom:focus-visible {
  transform: scale(1.02);
  box-shadow: 0 8px 24px #0003;
}

#coverPreview img.cover-zoom:hover,
#coverPreview img.cover-zoom:focus-visible {
  box-shadow: 0 4px 14px #0002;
}

.cover-viewer {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #0b0f17;
  color: #e7ecf4;
  overflow: hidden;
}

.cover-viewer::backdrop {
  background: #05080de6;
}

.cover-viewer[open] {
  display: flex;
  flex-direction: column;
}

.cover-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding:
    10px max(14px, env(safe-area-inset-left))
    10px max(14px, env(safe-area-inset-right));
  border-bottom: 1px solid #22304a;
  background: #0b0f17;
}

.cover-caption {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 0.9rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cover-viewer-bar .actions {
  flex: 0 0 auto;
}

.cover-viewer-bar .button {
  padding: 7px 11px;
  background: #22304a;
  color: #e7ecf4;
  font-size: 0.82rem;
}

.cover-viewer-bar .x {
  padding: 4px 10px;
  background: transparent;
  color: #e7ecf4;
}

#coverFull {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: #0b0f17;
  cursor: zoom-out;
}

@media (max-width: 550px) {
  .cover-viewer-bar {
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .cover-viewer-bar .button {
    font-size: 0.78rem;
  }

  #loanForm .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------- cestino -------------------------------- */

.trash-panel[hidden] {
  display: none !important;
}

.trash-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.trash-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e2e7ef;
  border-radius: 11px;
}

.trash-item strong {
  display: block;
}

.trash-item p {
  margin: 4px 0 0;
}

.trash-item .actions {
  flex: 0 0 auto;
}

.undo-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 560px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #172033;
  color: white;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
}

.undo-toast[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .trash-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .trash-item .actions {
    width: 100%;
  }

  .undo-toast {
    bottom: 84px;
  }
}

/* ---------------------------- stato sistema ----------------------------- */

.system-panel[hidden] {
  display: none !important;
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.system-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #e2e7ef;
  border-radius: 11px;
  background: #f8fafc;
}

.system-card span {
  font-size: 0.78rem;
  font-weight: 650;
  color: #5b677c;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.system-card strong {
  font-size: 0.95rem;
  line-height: 1.35;
  word-break: break-word;
}

.system-card.system-warn {
  border-color: #f0b4ae;
  background: #fff4f2;
}

.system-card.system-warn strong {
  color: #a6261c;
}

/* --------------------------- posizioni fisiche ---------------------------- */

.location-field {
  display: flex;
  gap: 8px;
  margin-top: 5px;
}

.location-field input {
  flex: 1;
  margin-top: 0;
  background: #f8fafc;
}

.location-field button {
  flex: 0 0 auto;
}

.locations-panel[hidden] {
  display: none !important;
}

.location-tree {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.location-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid #e2e7ef;
  border-radius: 10px;
}

.location-info {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.location-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.location-info .muted {
  font-size: 0.78rem;
  color: #5b677c;
}

.location-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.location-actions button {
  padding: 6px 10px;
  font-size: 0.78rem;
}

#locationPicker,
#locationEditor,
#mergeLocation,
#locationLabel {
  border: 0;
  border-radius: 15px;
  width: min(520px, calc(100% - 24px));
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 70px #0005;
}

#locationPicker::backdrop,
#locationEditor::backdrop,
#mergeLocation::backdrop,
#locationLabel::backdrop {
  background: #10182799;
}

.location-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 12px 0 8px;
  font-size: 0.85rem;
}

.location-breadcrumb button {
  padding: 5px 9px;
  font-size: 0.8rem;
  background: #eef2f8;
}

.location-breadcrumb span {
  color: #8a94a6;
}

.location-choices {
  display: grid;
  gap: 6px;
  max-height: 42vh;
  overflow-y: auto;
}

.location-choice {
  display: flex;
  align-items: stretch;
  gap: 6px;
  border: 1px solid #e2e7ef;
  border-radius: 10px;
  overflow: hidden;
}

.location-choice.selected {
  border-color: #315eea;
  background: #eef3ff;
}

.location-choice-main {
  flex: 1;
  display: grid;
  gap: 2px;
  text-align: left;
  background: transparent;
  padding: 9px 11px;
}

.location-choice-main .muted {
  font-size: 0.76rem;
  color: #5b677c;
  font-weight: 500;
}

.location-choice-pick {
  flex: 0 0 auto;
  border-left: 1px solid #e2e7ef;
  border-radius: 0;
  padding: 0 12px;
  font-size: 0.8rem;
}

.location-choice.selected .location-choice-pick {
  background: #315eea;
  color: white;
}

.location-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.location-add input {
  flex: 1;
}

.location-add button {
  flex: 0 0 auto;
}

.label-sheet {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 18px;
  border: 2px dashed #cbd3df;
  border-radius: 12px;
  margin: 12px 0;
}

.label-code {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.label-path {
  text-align: center;
  color: #47536a;
}

#labelQr {
  width: 180px;
  height: 180px;
}

@media (max-width: 640px) {
  .location-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .location-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media print {
  body > *:not(dialog[open]) {
    display: none !important;
  }

  dialog[open] {
    position: static;
    width: 100%;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  dialog[open]::backdrop {
    display: none;
  }

  .label-actions,
  dialog[open] > .section-head {
    display: none !important;
  }

  .label-sheet {
    border: 1px solid #000;
  }
}

/* ----------------------------- accesso utenti ---------------------------- */

.header-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #cbd4e2;
  font-size: 0.82rem;
}

.logout-form button {
  background: #293650;
  color: #fff;
  padding: 7px 12px;
  font-size: 0.8rem;
}

.logout-form .user-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: #172033;
}

.login-card {
  width: min(400px, 100%);
  padding: 32px 28px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(4, 10, 24, 0.35);
}

.login-card small {
  color: #5a6b86;
}

.login-card h1 {
  margin: 6px 0 10px;
  font-size: 1.9rem;
}

.login-intro,
.login-hint,
.login-setup {
  color: #47536a;
  font-size: 0.92rem;
}

.login-form {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.login-form label {
  font-size: 0.85rem;
  font-weight: 650;
  color: #23314a;
  margin-top: 6px;
}

.login-form input {
  width: 100%;
}

.login-form button {
  margin-top: 14px;
  padding: 12px 16px;
}

.login-error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: #fef3f2;
  color: #b42318;
  font-size: 0.88rem;
}

.login-command {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 9px;
  background: #f3f5f8;
  border: 1px solid #e2e7ef;
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .header-side {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .logout-form .user-name {
    display: none;
  }

  .logout-form button {
    padding: 6px 10px;
  }

  .login-card {
    padding: 26px 20px;
  }
}
