:root {
  --pico-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --pico-border-radius: 14px;
  --pico-line-height: 1.4;

  /* chiaro = bianco + blu */
  --pico-background-color: #ffffff;
  --pico-card-background-color: #ffffff;
  --pico-primary: #2563eb;
  --pico-primary-background: #2563eb;
  --pico-primary-hover: #1d4ed8;
  --pico-primary-hover-background: #1d4ed8;
  --pico-primary-focus: rgba(37, 99, 235, 0.25);
  --pico-primary-inverse: #fff;
  --pico-secondary: #6b7280;
  --pico-secondary-background: #6b7280;
  --pico-secondary-hover: #4b5563;
  --pico-secondary-hover-background: #4b5563;
  --pico-secondary-focus: rgba(107, 114, 128, 0.25);
  --pico-secondary-inverse: #fff;

  --app-surface: var(--pico-card-background-color);
  --app-page-bg: #f1f3f5;
  --app-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -8px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  /* scuro = nero + verde */
  --pico-background-color: #050505;
  --pico-card-background-color: #121212;
  --pico-primary: #34c98e;
  --pico-primary-background: #1f8f65;
  --pico-primary-hover: #46dba0;
  --pico-primary-hover-background: #24a675;
  --pico-primary-focus: rgba(52, 201, 142, 0.25);
  --pico-primary-inverse: #05130d;
  --pico-secondary: #8a8f98;
  --pico-secondary-background: #8a8f98;
  --pico-secondary-hover: #a1a6ae;
  --pico-secondary-hover-background: #a1a6ae;
  --pico-secondary-focus: rgba(138, 143, 152, 0.25);
  --pico-secondary-inverse: #05130d;

  --app-page-bg: #000000;
  --app-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -8px rgba(0, 0, 0, 0.6);
}

* {
  -webkit-font-smoothing: antialiased;
}

html {
  background: var(--app-page-bg);
}

body {
  padding-bottom: 4rem;
  background: var(--app-page-bg);
}

body:has(app-header) {
  padding-top: 4.25rem;
}

main.container {
  max-width: 720px;
  padding-top: 1.5rem;
}

@media (min-width: 900px) {
  main.container {
    max-width: 900px;
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
    border-radius: var(--pico-border-radius);
    padding: 2.5rem 3rem 3rem;
    margin-top: 2rem;
    margin-bottom: 2.5rem;
  }
}

h1 {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.page-title-row h1 {
  margin-bottom: 0;
}

.page-title-row button {
  flex: 0 0 auto;
  margin-bottom: 0;
}

a {
  text-decoration: none;
}

/* ---------- header ---------- */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--pico-background-color) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--pico-muted-border-color);
}

.app-header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 0.7rem 1rem;
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--pico-color);
  white-space: nowrap;
  letter-spacing: -0.02em;
  flex: 0 0 auto;
}

.app-header-brand svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.app-header-nav {
  display: flex;
  gap: 0.9rem;
  flex: 0 1 auto;
  overflow-x: auto;
  margin-left: auto;
}

.app-header-nav a {
  color: var(--pico-muted-color);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.app-header-nav a[aria-current="page"] {
  color: var(--pico-color);
  border-bottom-color: var(--pico-primary);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  margin-left: 1.25rem;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  flex: 0 0 auto;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 999px;
  background: var(--pico-muted-border-color);
  color: var(--pico-color);
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- generic layout helpers ---------- */

.page-nav {
  margin-bottom: 1.25rem;
}

.page-nav a {
  color: var(--pico-muted-color);
  font-size: 0.9rem;
}

.search-wrap {
  position: relative;
  margin-bottom: 1.25rem;
}

input.page-search {
  width: 100%;
  margin-bottom: 0;
  padding-right: 2.25rem;
}

.page-search::-webkit-search-cancel-button {
  display: none;
}

.search-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 999px;
  background: var(--pico-muted-border-color);
  color: var(--pico-color);
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.toolbar button {
  margin: 0;
  width: auto;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 999px;
}

.toolbar button[aria-current="true"] {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
  border-color: var(--pico-primary);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: var(--pico-muted-border-color);
}

/* ---------- items ---------- */

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}

.item-card {
  color: inherit;
  background: var(--app-surface);
  border-radius: var(--pico-border-radius);
  box-shadow: var(--app-shadow);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: block;
}

.item-card:hover {
  transform: translateY(-2px);
}

.item-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--pico-muted-border-color);
  display: block;
}

.item-card-body {
  padding: 0.6rem 0.75rem 0.8rem;
}

.item-card .price {
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--pico-muted-border-color);
  color: var(--pico-muted-color);
  margin-bottom: 0.35rem;
}

.badge-sold {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
}

/* ---------- confirm dialog ---------- */

button.danger {
  --pico-primary-background: var(--pico-del-color);
  --pico-primary-border: var(--pico-del-color);
  --pico-primary-hover-background: var(--pico-del-color);
  --pico-primary-hover-border: var(--pico-del-color);
  background: var(--pico-del-color);
  border-color: var(--pico-del-color);
}

.empty-state {
  text-align: center;
  color: var(--pico-muted-color);
  padding: 3rem 1rem;
}

/* ---------- floating action button ---------- */

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 15;
  width: 3.4rem;
  height: 3.4rem;
  border-radius: 999px;
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px -4px color-mix(in srgb, var(--pico-primary) 60%, transparent);
  font-size: 1.6rem;
  line-height: 1;
}

.fab svg {
  width: 26px;
  height: 26px;
}

/* ---------- photo thumbs ---------- */

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.photo-thumbs .thumb {
  position: relative;
}

.photo-thumbs img {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: var(--pico-border-radius);
}

.photo-thumbs .thumb.is-primary img {
  outline: 3px solid var(--pico-primary);
  outline-offset: 2px;
}

.photo-thumbs.is-gallery img {
  cursor: pointer;
}

/* ---------- galleria a schermo intero ---------- */

#lightbox {
  border: none;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  background: rgba(10, 10, 10, 0.95);
}

/* Il "display:flex" deve valere solo da aperto: un <dialog> chiuso è
   "display:none" di default nel browser, e sovrascriverlo sempre lo
   terrebbe presente in pagina (e a intercettare i click) anche da chiuso. */
#lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox::backdrop {
  background: rgba(10, 10, 10, 0.95);
}

#lightbox img {
  max-width: 92vw;
  max-height: 85vh;
  object-fit: contain;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close,
.lightbox-nav {
  position: fixed;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox-close {
  top: 0.75rem;
  right: 0.75rem;
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.5rem;
}

.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 2.8rem;
  height: 2.8rem;
  font-size: 1.8rem;
}

.lightbox-prev {
  left: 0.75rem;
}

.lightbox-next {
  right: 0.75rem;
}

.lightbox-counter {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
}

/* ---------- stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.stat-card {
  padding: 1.1rem;
  background: var(--app-surface);
  box-shadow: var(--app-shadow);
  border-radius: var(--pico-border-radius);
  text-align: center;
}

.stat-card .value {
  font-size: 1.7rem;
  font-weight: 700;
  display: block;
  letter-spacing: -0.02em;
}

.stat-card .label {
  color: var(--pico-muted-color);
  font-size: 0.82rem;
}

/* ---------- scanner ---------- */

#reader {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  border-radius: var(--pico-border-radius);
  overflow: hidden;
}

/* ---------- label print ---------- */

/* L'etichetta è sempre nero su bianco, indipendentemente dal tema chiaro/scuro
   dell'app: è un'anteprima fedele di ciò che uscirà stampato. */
.label-preview {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.2rem;
  border: 1px dashed #ccc;
  padding: 0.08rem;
  box-sizing: border-box;
  overflow: hidden;
  background: #fff;
  color: #000;
}

.label-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.label-qr {
  flex: 0 0 auto;
  height: 100%;
}

.label-text {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
}

.label-title {
  font-weight: 700;
  font-size: 0.68rem;
  line-height: 1.15;
  text-align: left;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.label-price {
  font-size: 1.15rem;
  font-weight: 700;
  text-align: left;
}

@media print {
  .app-header,
  .fab,
  .page-nav,
  .no-print {
    display: none !important;
  }

  body,
  body:has(app-header) {
    padding: 0;
    margin: 0;
    background: none;
  }

  main.container {
    max-width: none;
    background: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }

  .label-preview {
    border: none;
  }
}
