/* AU3D Studio — pannello admin. Usa i token e i componenti di ../styles.css */

body.admin { background: var(--surface); min-height: 100vh; }
[hidden] { display: none !important; }

/* ---------- Accesso ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px var(--gutter); }
.login__card {
  width: 100%; max-width: 420px;
  display: grid; gap: 16px; justify-items: start;
  padding: clamp(28px, 5vw, 44px);
  background: var(--white);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow);
}
.login__logo { width: 120px; height: auto; margin-bottom: 8px; }
.login__lead { color: var(--muted); font-size: 15px; margin-top: -4px; }
.login__card .field, .login__card .btn { width: 100%; }
.login__error { min-height: 1.2em; font-size: 14px; color: #b42318; }
.login__demo { font-size: 13px; color: var(--muted); padding: 12px 14px; background: var(--surface); border-radius: var(--r-md); }

/* ---------- Campi ---------- */
.field { display: grid; gap: 6px; align-content: start; font-size: 13px; font-weight: 600; }
.field > span:first-child { color: var(--ink); }
.field input:not([type="checkbox"]), .field textarea, .select, .search input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--surface-2); border-radius: 12px;
  background: var(--white); color: var(--ink);
  font: 400 15px/1.4 var(--font);
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { resize: vertical; min-height: 120px; }
.field input:focus, .field textarea:focus, .select:focus, .search input:focus {
  outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(25, 23, 28, .08);
}
.field.is-invalid input { border-color: #b42318; }
.input-prefix { position: relative; display: block; }
.input-prefix em { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-weight: 500; }
.input-prefix input { padding-left: 30px !important; }
.input-prefix input:disabled { background: var(--surface); color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: var(--muted); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--black); }
.counter { justify-self: end; font-size: 12px; font-weight: 500; color: var(--muted); }
.select {
  width: auto; padding-right: 36px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2319171c' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.linkbtn { padding: 0; border: 0; background: none; font: 500 14px var(--font); color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.linkbtn:hover { color: var(--ink); }
.linkbtn--danger { color: #b42318; }
.linkbtn--danger:hover { color: #8a1a12; }
.btn--danger { background: #b42318; color: var(--white); }
.btn--danger:hover { background: #8a1a12; }

/* ---------- Barra in alto ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .9); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-bottom: 1px solid var(--surface-2); }
.topbar__inner { display: flex; align-items: center; gap: 14px; max-width: var(--wrap); height: 64px; margin: 0 auto; padding: 0 var(--gutter); }
.topbar__logo img { height: 26px; width: auto; }
.topbar__label { padding-left: 14px; border-left: 1px solid var(--surface-2); font-size: 14px; font-weight: 600; }
.topbar__mode { padding: 4px 10px; border-radius: 99px; background: var(--surface); font-size: 12px; font-weight: 600; color: var(--muted); }
.topbar__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.topbar__user { font-size: 13px; color: var(--muted); margin-right: 6px; }

/* ---------- Pannello ---------- */
.panel { padding-top: clamp(28px, 4vw, 48px); padding-bottom: 64px; }
.panel__head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.panel__lead { margin-top: 8px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
.stat { display: grid; gap: 4px; padding: 18px 20px; background: var(--white); border-radius: var(--r-lg); }
.stat span { font-size: 13px; color: var(--muted); }
.stat strong { font: 800 32px/1 var(--display); letter-spacing: -.03em; }

.toolbar--admin { align-items: flex-start; }
.toolbar--admin .filter { background: var(--white); }
.toolbar--admin .filter.is-active { background: var(--black); }
.filter em { margin-left: 6px; font-style: normal; opacity: .55; }
.toolbar__right { display: flex; flex-wrap: wrap; gap: 8px; }
.search { position: relative; display: block; min-width: 260px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 40px; border-color: transparent; }
.toolbar--admin .select { border-color: transparent; }

/* Lista prodotti */
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.pcard {
  position: relative;
  min-width: 0;
  display: flex; flex-direction: column;
  padding: 10px;
  background: var(--white);
  border-radius: var(--r-lg);
  transition: transform .3s var(--ease), box-shadow .3s;
}
.pcard:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.pcard.is-draft .pcard__media img { opacity: .55; filter: grayscale(.6); }
.pcard__media { position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: var(--r-md); background: var(--surface); }
.pcard__media img { width: 100%; height: 100%; object-fit: cover; }
.pcard__noimg { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.pcard__status {
  position: absolute; top: 10px; left: 10px;
  padding: 4px 10px; border-radius: 99px;
  background: var(--white); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.pcard__status--draft { background: var(--black); color: var(--white); }
.pcard__photos { position: absolute; bottom: 10px; right: 10px; padding: 3px 8px; border-radius: 99px; background: rgba(11, 11, 12, .7); color: var(--white); font-size: 11px; font-weight: 600; }
.pcard__body { display: grid; min-width: 0; gap: 4px; padding: 14px 6px 8px; }
.pcard__cat { font-size: 12px; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.pcard h3 { font: 800 19px/1.2 var(--display); letter-spacing: -.02em; overflow-wrap: anywhere; }
.pcard__open { all: unset; cursor: pointer; }
.pcard__open:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 4px; }
.pcard__open::after { content: ""; position: absolute; inset: 0; z-index: 1; border-radius: inherit; }
.pcard dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin: 8px 0 0; font-size: 12px; }
.pcard dl > div { min-width: 0; }
.pcard dl > div:last-child { grid-column: 1 / -1; }
.pcard dt { color: var(--muted); }
.pcard dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.pcard__actions { position: relative; z-index: 2; display: flex; gap: 6px; padding: 6px 6px 4px; margin-top: auto; }
.pcard__actions .btn { flex: 1; }
.pcard__actions .icon-btn { flex-shrink: 0; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--surface); color: var(--ink); cursor: pointer; transition: background-color .2s; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn--danger:hover { background: #fde8e6; color: #b42318; }

.empty { display: grid; justify-items: center; gap: 8px; padding: 64px 24px; background: var(--white); border-radius: var(--r-xl); text-align: center; }
.empty strong { font: 800 22px var(--display); }
.empty p { color: var(--muted); margin-bottom: 8px; }

.panel__foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-top: 28px; font-size: 13px; color: var(--muted); }

/* ---------- Editor (pannello laterale) ---------- */
.drawer {
  width: min(980px, 100vw); max-width: none; height: 100dvh; max-height: none;
  margin: 0 0 0 auto; padding: 0; border: 0;
  background: var(--white); color: var(--ink);
  box-shadow: -30px 0 60px -30px rgba(0, 0, 0, .35);
}
.drawer::backdrop { background: rgba(11, 11, 12, .4); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.drawer[open] { animation: drawerIn .45s var(--ease); }
.drawer[open]::backdrop { animation: fadeIn .3s; }
@keyframes drawerIn { from { transform: translateX(40px); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } }
.drawer__form { display: grid; grid-template-rows: auto 1fr auto; height: 100%; }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--surface-2); }
.drawer__head h2 { font: 800 24px var(--display); letter-spacing: -.02em; }
.drawer__body { display: grid; grid-template-columns: 1fr 300px; gap: 28px; padding: 24px; overflow-y: auto; }
.drawer__fields { display: grid; gap: 20px; align-content: start; }
.drawer__foot { display: flex; align-items: center; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--surface-2); background: var(--white); }
.drawer__spacer { flex: 1; }

.group { margin: 0; padding: 0; border: 0; display: grid; gap: 10px; }
.group legend { padding: 0; margin-bottom: 10px; font-size: 13px; font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-error { min-height: 1.2em; font-size: 14px; color: #b42318; }

/* Foto */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.photos:empty { display: none; }
.photo { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: var(--r-md); background: var(--surface); cursor: grab; }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo.is-loading img { opacity: .4; }
.photo.is-loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 22px; height: 22px; border: 2px solid var(--ink); border-right-color: transparent; border-radius: 50%; animation: spinner .8s linear infinite; }
@keyframes spinner { to { transform: rotate(360deg); } }
.photo__cover { position: absolute; left: 6px; bottom: 6px; padding: 2px 7px; border-radius: 99px; background: var(--black); color: var(--white); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.photo__remove, .photo__first {
  position: absolute; top: 6px; width: 24px; height: 24px; padding: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: rgba(255, 255, 255, .92); color: var(--ink);
  cursor: pointer; opacity: 0; transition: opacity .2s;
}
.photo__remove { right: 6px; }
.photo__first { left: 6px; }
.photo:hover .photo__remove, .photo:hover .photo__first, .photo:focus-within .photo__remove, .photo:focus-within .photo__first { opacity: 1; }
@media (hover: none) { .photo__remove, .photo__first { opacity: 1; } }
.photo.is-dragging { opacity: .4; }
.dropzone {
  display: grid; justify-items: center; gap: 4px;
  padding: 22px; text-align: center;
  border: 1.5px dashed var(--line); border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer; transition: border-color .2s, background-color .2s;
}
.dropzone strong { font-size: 15px; }
.dropzone span { font-size: 12px; color: var(--muted); }
.dropzone:hover, .dropzone.is-over { border-color: var(--ink); background: var(--white); }

/* Categoria */
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: inline-flex; align-items: center; height: 38px; padding: 0 16px; border-radius: 99px; background: var(--surface); font-size: 14px; font-weight: 500; transition: background-color .2s, color .2s; }
.segmented input:checked + span { background: var(--black); color: var(--white); }
.segmented input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.segmented.is-invalid span { box-shadow: inset 0 0 0 1px #b42318; }

/* Interruttore pubblicato / bozza */
.switch { display: inline-flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 500; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { position: relative; width: 44px; height: 26px; border-radius: 99px; background: var(--surface-2); transition: background-color .25s; }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--white); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .3s var(--ease); }
.switch input:checked + .switch__track { background: var(--black); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Anteprima */
.drawer__preview { position: sticky; top: 0; align-self: start; display: grid; gap: 10px; }
.preview__label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.product--preview { pointer-events: none; }
.product--preview .product__media { position: relative; }
.product--preview h3:empty::before { content: "Nome del prodotto"; color: var(--faint); }
.pv-empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.pv-price { font-size: 14px; font-weight: 700; }

/* ---------- Conferma ---------- */
.confirm { width: min(420px, calc(100vw - 32px)); padding: 28px; border: 0; border-radius: var(--r-xl); box-shadow: var(--shadow); }
.confirm::backdrop { background: rgba(11, 11, 12, .4); }
.confirm h2 { font: 800 22px/1.2 var(--display); letter-spacing: -.02em; }
.confirm p { margin-top: 8px; color: var(--muted); font-size: 15px; }
.confirm__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ---------- Notifica ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100;
  padding: 12px 18px; border-radius: 99px;
  background: var(--black); color: var(--white);
  font-size: 14px; font-weight: 500;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: transform .35s var(--ease), opacity .3s;
}
.toast.is-on { transform: translate(-50%, 0); opacity: 1; }
.toast.is-error { background: #b42318; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .drawer__body { grid-template-columns: 1fr; }
  .drawer__preview { position: static; grid-row: 1; max-width: 320px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .topbar__user, .topbar__mode { display: none; }
}
@media (max-width: 640px) {
  .drawer { width: 100vw; }
  .drawer__body { padding: 18px 16px; }
  .drawer__head, .drawer__foot { padding-left: 16px; padding-right: 16px; }
  .drawer__preview { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .search { min-width: 0; flex: 1 1 100%; }
  .toolbar__right .select { flex: 1; }
  .panel__head .btn { width: 100%; }
  .topbar__label { display: none; }
  .plist { grid-template-columns: 1fr; }
}
