:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --ink: #1d1b19;
  --muted: #7a756e;
  --line: #e4e0d9;
  --accent: #1d1b19;
  --ok: #2f6b3a;
  --ok-bg: #e5f1e6;
  --out: #8a5a00;
  --out-bg: #fbf0d9;
  --sold: #8f2b2b;
  --sold-bg: #f8e3e1;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: inherit; }
img { max-width: 100%; }
h1 { font-size: 1.5rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 small, h2 small, h3 small { color: var(--muted); font-weight: 400; font-size: .75em; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; font-weight: 600; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
code { background: #efece6; padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; display: block; margin-top: .25rem; }
.pre { white-space: pre-wrap; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 1rem; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top)); }
.brand { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .08em; white-space: nowrap; }
.brand span { font-weight: 300; opacity: .7; letter-spacing: .02em; }
.ver { font-size: .7em; font-weight: 400; opacity: .55; letter-spacing: 0; text-transform: none; }
.menubtn { display: none; background: none; border: 0; color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer; padding: .1rem .3rem; }
.nav { flex: 1; display: flex; flex-wrap: wrap; gap: .15rem; }
.nav a { color: #ddd; text-decoration: none; padding: .35rem .6rem; border-radius: 6px; font-size: .92rem; }
.nav a:hover, .nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.nav a.logout { margin-left: auto; opacity: .7; }
.quicksearch input { width: 200px; border-radius: 20px; border: 0; padding: .4rem .8rem; background: rgba(255,255,255,.14); color: #fff; }
.quicksearch input::placeholder { color: #bbb; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.pagehead .sub { color: var(--muted); margin-top: .3rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.btns { display: flex; gap: .4rem; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.cardhead h2 { margin: 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.cols > .card { margin-bottom: 0; }
.cols + .cols, .cols + .card, .card + .cols { margin-top: 1rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; font: inherit; font-size: .92rem; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #bdb6ab; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--sold); border-color: #e7c3c0; }
.btn.small { padding: .25rem .55rem; font-size: .82rem; }
.btn.wide { width: 100%; justify-content: center; padding: .75rem; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; }
button.link.danger, .danger { color: var(--sold); }

/* Forms */
.form .field { margin-bottom: .8rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea { font: inherit; font-size: 16px; /* evita lo zoom su iPhone */ width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c9b99a; border-color: #c9b99a; }
input[type=checkbox] { width: auto; margin: 0 .35rem 0 0; }
label.check { display: inline-flex; align-items: center; color: var(--ink); font-size: .95rem; margin: .3rem 1.2rem .5rem 0; }
.checks { margin-bottom: .6rem; }
.grid2, .grid3 { display: grid; gap: 0 1rem; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.inputbtn { display: flex; gap: .4rem; }
.inputbtn input { flex: 1; }
.formbar { display: flex; gap: .6rem; justify-content: space-between; align-items: center; margin-top: .5rem; }
.formbar.sticky { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 calc(.6rem + env(safe-area-inset-bottom)); }
form.inline { display: inline-flex; gap: .3rem; align-items: center; margin: 0; }
form.inline input[type=date] { width: auto; padding: .2rem .4rem; font-size: 14px; }
output { display: block; padding: .5rem 0; font-weight: 600; }

/* Flash & badges */
.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--sold-bg); color: var(--sold); }
.flash.warn { background: var(--out-bg); color: var(--out); }
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 20px; font-size: .78rem; background: #eee; color: #555; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.out { background: var(--out-bg); color: var(--out); }
.badge.sold { background: var(--sold-bg); color: var(--sold); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; text-decoration: none; display: block; }
.stat b { display: block; font-size: 1.35rem; font-weight: 600; }
.stat span { color: var(--muted); font-size: .85rem; }
a.stat:hover { border-color: #bdb6ab; }
.todo ul { margin: 0; padding-left: 1.2rem; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .3rem 0; border-bottom: 1px solid #f1eee9; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters input[type=search] { flex: 1 1 240px; }
.filters select { flex: 0 1 auto; width: auto; }
.viewtoggle { margin-left: auto; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.viewtoggle a { padding: .45rem .7rem; text-decoration: none; font-size: .88rem; }
.viewtoggle a.on { background: var(--ink); color: #fff; }

/* Grid of artworks */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .9rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; display: flex; flex-direction: column; }
.tile:hover { border-color: #bdb6ab; }
.tile .thumb { aspect-ratio: 1 / 1; background: #ece9e3; display: flex; align-items: center; justify-content: center; }
.tile .thumb img { width: 100%; height: 100%; object-fit: contain; }
.tile .meta { padding: .6rem .7rem .7rem; display: flex; flex-direction: column; gap: .1rem; }
.tile .meta small { color: var(--muted); font-size: .8rem; }
.tile .row { display: flex; justify-content: space-between; align-items: center; gap: .4rem; margin-top: .35rem; }
.tile .price { font-weight: 600; font-size: .9rem; white-space: nowrap; }

/* Tables */
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .6rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .55rem .7rem; border-bottom: 1px solid #f1eee9; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num { text-align: right; white-space: nowrap; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.mini { width: 56px; padding-right: 0; }
.table td.mini img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; background: #ece9e3; display: block; }
.table.compact td { padding: .35rem .6rem; font-size: .9rem; }

/* Artwork page */
.opera { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.opera > .card { margin-bottom: 0; }
.opera + .cols, .opera + .card { margin-top: 1rem; }
.gallery .main { display: flex; align-items: center; justify-content: center; background: #ece9e3; border-radius: 8px; min-height: 260px; max-height: 70vh; overflow: hidden; }
.gallery .main img { max-height: 70vh; object-fit: contain; }
.gallery .noimg { color: var(--muted); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin-top: .8rem; }
.thumbs figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: .4rem; }
.thumbs figure.is-main { border-color: #c9b99a; }
.thumbs img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 5px; background: #ece9e3; }
.thumbs figcaption { font-size: .8rem; }
.thumbs select { font-size: 14px; padding: .2rem .3rem; margin: .3rem 0; }
.imgbtns { display: flex; gap: .5rem; flex-wrap: wrap; font-size: .8rem; }
.upload { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.upload select { width: auto; }
.pending { margin-top: .8rem; font-size: .9rem; }
.pending summary { cursor: pointer; color: var(--out); }
.details dl, .card dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 .6rem; }
dt { color: var(--muted); font-size: .88rem; }
dd { margin: 0; }
.pricebox { display: flex; gap: 1.5rem; margin-bottom: .8rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.pricebox small { display: block; color: var(--muted); }
.pricebox b { font-size: 1.4rem; font-weight: 600; }

/* Picker (movimentazioni) */
.pickfilter { margin-bottom: .6rem; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .4rem; max-height: 60vh; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--line); border-radius: 8px; padding: .35rem; margin: 0; cursor: pointer; color: var(--ink); }
.pick:has(input:checked) { border-color: var(--ink); background: #f3efe8; }
.pick img { width: 44px; height: 44px; object-fit: cover; border-radius: 5px; background: #ece9e3; }
.pick span { display: flex; flex-direction: column; font-size: .85rem; line-height: 1.25; min-width: 0; }
.pick small { color: var(--muted); font-size: .76rem; }
.pick.sold { opacity: .5; }

/* Login */
.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { text-align: center; margin-bottom: 1.2rem; letter-spacing: .08em; }
.login h1 span { display: block; font-weight: 300; font-size: .9rem; letter-spacing: .15em; color: var(--muted); text-transform: uppercase; }

/* Mobile */
@media (max-width: 900px) {
  .cols, .opera { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .span3 { grid-column: span 2; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .menubtn { display: block; order: 2; margin-left: auto; }
  .nav { display: none; }
  .navopen .nav { display: flex; flex-direction: column; position: absolute; left: 0; right: 0; top: 100%; background: var(--ink); padding: .5rem 1rem 1rem; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
  .navopen .nav a { padding: .7rem .5rem; font-size: 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
  .nav a.logout { margin-left: 0; }
  .quicksearch { order: 3; flex: 1 0 100%; }
  .quicksearch input { width: 100%; }
  .wrap { padding: 1rem .75rem 4rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .filters select { flex: 1 1 45%; }
  .viewtoggle { margin-left: 0; }
  /* tabelle come schede */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--line); padding: .5rem .2rem; position: relative; }
  .table td { border: 0; padding: .15rem .7rem; text-align: left !important; }
  .table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .8rem; }
  .table td.mini { position: absolute; right: .5rem; top: .6rem; width: auto; }
  .table td.actions { text-align: left; }
  .details dl, .card dl { grid-template-columns: 1fr; gap: 0; }
  dd { margin-bottom: .45rem; }
  .pagehead .btns { width: 100%; }
}
@media print {
  .topbar, .btn, .filters, .upload, .formbar { display: none !important; }
  body { background: #fff; }
  .card { border: 0; }
}
