:root {
  --bg: #FBF7F2;
  --ink: #171310;
  --muted: #6B625A;
  --faint: #8A7F74;
  --placeholder: #A89C8F;
  --line: #E7DFD4;
  --dash: #D8CCBC;
  --orange: #F26522;
  --orange-dark: #D9541A;
  --soft: #F2EBE1;
  --tile: #F4EEE6;
  --track: #E2D8CA;
  --live-bg: #FDEEE4;
  --live-ink: #A63E0C;
  --white: #FFFFFF;
  --mono: 'DM Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: Archivo, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--orange-dark); text-decoration: none; }
a:hover { color: var(--ink); text-decoration: underline; }
input, button { font: inherit; color: inherit; }
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
::placeholder { color: var(--placeholder); }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--faint); }

@keyframes gpulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes gcaret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* ------------------------------------------------ layout */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px;
  padding: 18px 26px; border-bottom: 1px solid var(--line);
}
.brand { display: block; line-height: 0; }
.brand img { height: 30px; width: auto; display: block; }
.brand-text { font-size: 24px; font-weight: 900; letter-spacing: -.04em; color: var(--ink); line-height: 30px; }
.brand:hover { text-decoration: none; }
.seg { justify-self: end; display: flex; gap: 3px; padding: 3px; background: var(--soft); border-radius: 999px; }
.seg form { margin: 0; }
.seg a, .seg button {
  display: block; border: 0; background: transparent; color: var(--muted); border-radius: 999px;
  padding: 6px 13px; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap; line-height: 1.45;
}
.seg a:hover, .seg button:hover { color: var(--ink); text-decoration: none; }
.seg a.on { background: var(--ink); color: var(--bg); }

.main {
  flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 44px 26px 48px;
  display: flex; flex-direction: column;
}
.center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px 0 60px; }
.panel { width: 100%; max-width: 380px; }
.panel-code { max-width: 440px; text-align: center; }
.h1 { font-size: 26px; font-weight: 900; letter-spacing: -.03em; }
.h2 { font-size: 22px; font-weight: 900; letter-spacing: -.03em; }
.sub { margin-top: 6px; font-size: 15px; color: var(--muted); }
.notice { margin-bottom: 20px; padding: 13px 18px; border-radius: 14px; background: var(--soft); font-weight: 700; font-size: 15px; }

/* ------------------------------------------------ buttons & fields */
.btn {
  display: inline-block; border: 0; border-radius: 11px; padding: 13px 24px; font-weight: 800; font-size: 16px;
  cursor: pointer; text-align: center; line-height: 1.45; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-lg { border-radius: 12px; padding: 15px 20px; font-size: 17px; }
.btn-sm { border-radius: 9px; padding: 9px 16px; font-size: 14px; font-weight: 700; }
.btn-block { display: block; width: 100%; margin-top: 22px; }
.btn-orange { background: var(--orange); color: var(--ink); }
.btn-orange:hover { background: var(--orange-dark); color: var(--white); }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-dark:hover { background: var(--orange); color: var(--ink); }
.btn-outline { background: var(--white); color: var(--ink); border: 1.5px solid var(--ink); }
.btn-outline:hover { background: var(--ink); color: var(--bg); }
.btn-soft { background: var(--white); color: var(--ink); border: 1.5px solid var(--dash); }
.btn-soft:hover { border-color: var(--ink); color: var(--ink); }
.btn-ghost { background: var(--ink); color: var(--bg); }
.btn-ghost:hover { background: var(--orange); color: var(--ink); }
.btn.disabled { opacity: .35; pointer-events: none; }
.link-btn { background: none; border: 0; padding: 0; color: var(--orange-dark); font-size: 13px; font-weight: 700; cursor: pointer; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }

.label {
  display: block; margin-top: 16px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--faint);
}
.panel-login .label:first-of-type { margin-top: 24px; }
.field {
  width: 100%; margin-top: 7px; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--white); font-size: 16px;
}
.field:focus { border-color: var(--orange); outline: none; }
.form-error { margin-top: 14px; color: var(--live-ink); font-size: 14px; font-weight: 700; }
.forgot { margin-top: 14px; text-align: center; font-size: 13px; }
.forgot summary { color: var(--orange-dark); cursor: pointer; list-style: none; }
.forgot summary::-webkit-details-marker { display: none; }
.forgot summary:hover { color: var(--ink); text-decoration: underline; }
.forgot p { color: var(--muted); margin: 8px 0 0; }

/* ------------------------------------------------ code boxes */
.code-boxes { position: relative; display: flex; gap: 8px; justify-content: center; margin-top: 26px; cursor: text; }
.code-boxes input {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0;
  font-size: 16px; caret-color: transparent; z-index: 1;
}
.box {
  position: relative; width: 52px; height: 64px; border: 1.5px solid var(--line); border-radius: 11px;
  background: var(--white); display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 26px; font-weight: 500;
}
.box.caret::after {
  content: ''; position: absolute; inset: -1.5px; border: 2px solid var(--orange); border-radius: 11px;
}
.box.caret:empty::before {
  content: ''; width: 2px; height: 28px; background: var(--orange); animation: gcaret 1s step-end infinite;
}
/* Senza JS il campo resta visibile. */
html:not(.js) .code-boxes input { position: static; opacity: 1; height: 64px; text-align: center; font-family: var(--mono); font-size: 26px; border: 1.5px solid var(--line); border-radius: 11px; letter-spacing: .3em; }
html:not(.js) .code-boxes .box { display: none; }

/* ------------------------------------------------ upload */
.name-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; min-height: 40px; }
.name-edit { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1 1 300px; margin: 0; }
.name-edit label { font-weight: 800; font-size: 15px; }
.name-edit input {
  flex: 1 1 180px; min-width: 0; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--white); font-size: 15px;
}
.name-edit input:focus { border-color: var(--orange); outline: none; }
.name-saved { flex: 1 1 auto; display: flex; align-items: baseline; gap: 10px; font-size: 15px; }
.name-row > .mono { font-size: 13px; margin-left: auto; }

.dropzone {
  border: 2.5px dashed var(--dash); border-radius: 20px; background: var(--white); padding: 84px 34px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--orange); background: #FFFAF6; }
.glyph { font-size: 86px; font-weight: 900; line-height: 1; color: #EFE5D8; letter-spacing: -.04em; }
.drop-title { margin-top: 16px; font-size: 24px; font-weight: 800; letter-spacing: -.025em; }
.drop-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.hint { margin-top: 26px; font-size: 12px; color: var(--faint); }

.dropbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; padding: 13px 18px;
  border: 1.5px dashed var(--dash); border-radius: 14px; background: var(--white);
}
.dropbar-label { flex: 1 1 170px; min-width: 0; font-size: 15px; font-weight: 700; }

.drag-veil {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(251, 247, 242, .88); border: 3px dashed var(--orange); pointer-events: none;
  opacity: 0; transition: opacity .12s;
}
.drag-veil.on { opacity: 1; }
.drag-veil span { font-size: 28px; font-weight: 900; letter-spacing: -.03em; }

.status-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 22px; padding-top: 16px;
  border-top: 1.5px solid var(--line);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); flex: 0 0 auto; }
.dot.pulse, .pill-live .dot { animation: gpulse 1.8s ease-in-out infinite; }
.status-label { font-size: 14px; font-weight: 700; }
.status-meta { font-size: 13px; margin-left: auto; }

/* ------------------------------------------------ tiles */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(182px, 1fr)); }
.tile {
  display: block; border-radius: 12px; overflow: hidden; background: var(--white); border: 1.5px solid var(--line);
  color: var(--ink); min-width: 0;
}
.tile { position: relative; }
.tile-link { display: block; color: var(--ink); }
.tile-link:hover { text-decoration: none; color: var(--ink); }
.tile:has(.tile-link[href]:hover) { border-color: var(--ink); }
.tile-del {
  position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(23, 19, 16, .78); color: var(--white); font-size: 17px; line-height: 1; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s;
}
.tile:hover .tile-del, .tile-del:focus-visible { opacity: 1; }
.tile-del:hover { background: var(--live-ink); }
@media (hover: none) { .tile-del { opacity: 1; } }
.tile.is-error { border-color: var(--orange); cursor: pointer; }
.tile-img {
  position: relative; aspect-ratio: 4 / 3; background: var(--tile); display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.tile-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-ext { font-size: 20px; font-weight: 500; color: var(--placeholder); letter-spacing: .04em; }
.tile-progress {
  position: absolute; inset: 0; background: rgba(251, 247, 242, .86); display: flex; flex-direction: column;
  justify-content: flex-end; gap: 7px; padding: 11px;
}
.tile-note { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.tile.is-error .tile-note { color: var(--live-ink); }
.bar { width: 100%; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar-fill { height: 100%; background: var(--orange); border-radius: 3px; width: 0; transition: width .2s linear; }
.tile-check {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--orange);
  color: var(--ink); font-size: 14px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px var(--white);
}
.tile-info { padding: 9px 11px 11px; }
.tile-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-size { font-size: 11px; color: var(--faint); margin-top: 2px; }
/* Nel dettaglio admin la spunta non serve: i file completati si scaricano. */
.t-grid .tile-check { display: none; }

/* ------------------------------------------------ dashboard */
.dash-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.dash-range { font-size: 13px; margin-left: auto; }
.rows { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 16px; background: var(--white);
  border: 1.5px solid var(--line); border-radius: 14px; color: var(--ink);
}
.row:hover { border-color: var(--ink); text-decoration: none; color: var(--ink); }
.row-main { flex: 1 1 150px; min-width: 0; }
.row-code { font-size: 15px; font-weight: 500; }
.row-name { font-family: Archivo, Helvetica, Arial, sans-serif; font-weight: 700; margin-left: 6px; }
.row-when { font-size: 13px; color: var(--faint); margin-top: 2px; }
.row-by { color: var(--muted); font-weight: 600; }
.row-thumbs { display: flex; gap: 6px; flex: 0 0 auto; }
.row-thumbs img { width: 46px; height: 36px; border-radius: 6px; border: 1px solid var(--line); background: var(--tile); object-fit: cover; }
.row-meta { flex: 0 0 auto; font-size: 13px; color: var(--muted); min-width: 118px; text-align: right; }
.row-badge { flex: 0 0 auto; min-width: 86px; display: flex; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; background: var(--soft);
  font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.pill-live { background: var(--live-bg); color: var(--live-ink); font-weight: 800; padding-left: 10px; }
.pill-live .dot { width: 7px; height: 7px; }
.pill-open { background: transparent; border: 1.5px solid var(--line); padding: 3.5px 10.5px; }
.empty-list { padding: 28px; border: 1.5px dashed var(--dash); border-radius: 14px; color: var(--muted); text-align: center; }
.new-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.new-form .field { flex: 1 1 260px; max-width: 420px; margin-top: 0; padding: 11px 14px; font-size: 15px; }
.new-form .btn { font-size: 15px; padding: 12px 22px; }

/* ------------------------------------------------ transfer detail */
.back { font-size: 14px; font-weight: 700; color: var(--muted); }
.back:hover { color: var(--ink); text-decoration: none; }
.t-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 12px; padding-bottom: 16px; border-bottom: 2px solid var(--ink);
}
.t-title-wrap { min-width: 0; }
.t-title-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.t-title { font-size: 30px; font-weight: 900; letter-spacing: -.035em; font-stretch: 108%; overflow-wrap: anywhere; }
.t-meta-line { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.t-meta { font-size: 13px; }
.rename { display: flex; gap: 8px; margin-top: 10px; max-width: 460px; }
.rename .field { margin-top: 0; padding: 8px 12px; font-size: 15px; }
.t-actions { display: flex; gap: 10px; flex: 0 0 auto; }
.t-actions form { margin: 0; }
.t-actions .btn { border-radius: 10px; padding: 12px 20px; font-size: 15px; }
.t-grid { margin-top: 20px; }
.danger-zone { margin-top: 36px; padding-top: 16px; border-top: 1.5px solid var(--line); display: flex; justify-content: flex-end; }
.btn-danger { background: var(--white); color: var(--live-ink); border: 1.5px solid #EBC3AE; }
.btn-danger:hover { background: var(--live-ink); color: var(--white); border-color: var(--live-ink); }

.share {
  margin-top: 20px; display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-end; padding: 22px;
  background: var(--white); border: 1.5px dashed var(--dash); border-radius: 16px;
}
.share .label { margin-top: 0; }
.share-code { font-size: 44px; font-weight: 500; letter-spacing: .06em; line-height: 1.1; margin-top: 4px; }
.share-link { flex: 1 1 280px; min-width: 0; }
.share-row { display: flex; gap: 8px; }
.share-row .field { margin-top: 7px; font-size: 13px; padding: 10px 12px; }
.share-row .btn { margin-top: 7px; }

/* ------------------------------------------------ viewer */
body.no-scroll { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 100; background: rgba(23, 19, 16, .97); color: var(--bg);
  display: grid; grid-template-rows: auto 1fr;
}
.viewer-bar { display: flex; align-items: center; gap: 14px; padding: 12px 16px 12px 22px; }
.viewer-title { flex: 1; min-width: 0; }
.viewer-name { font-weight: 800; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-meta { font-size: 12px; color: #B5AA9E; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .btn { flex: 0 0 auto; }
.viewer-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(251, 247, 242, .1);
  color: var(--bg); font-size: 24px; line-height: 1; cursor: pointer;
}
.viewer-btn:hover { background: rgba(251, 247, 242, .22); }
.viewer-stage { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 64px 24px; }
.viewer-img, .viewer-media { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; background: #2A2420; }
.viewer-frame { width: 100%; height: 100%; border: 0; border-radius: 6px; background: var(--white); }
.viewer-audio { width: min(520px, 100%); }
.viewer-none { text-align: center; color: #D8CCBC; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.viewer-ext { font-size: 44px; color: var(--orange); letter-spacing: .06em; }
.viewer-nav {
  position: absolute; top: 50%; width: 46px; height: 64px; margin-top: -8px; border: 0; border-radius: 12px;
  background: rgba(251, 247, 242, .1); color: var(--bg); font-size: 34px; line-height: 1; cursor: pointer;
}
.viewer-nav:hover { background: var(--orange); color: var(--ink); }
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }

/* ------------------------------------------------ small screens */
@media (max-width: 640px) {
  .top { padding: 14px 16px; grid-template-columns: auto 1fr; }
  .top > div:first-child { display: none; }
  .brand img { height: 24px; }
  .main { padding: 28px 16px 36px; }
  .dropzone { padding: 52px 20px; }
  .glyph { font-size: 64px; }
  .box { width: 44px; height: 56px; font-size: 22px; }
  .code-boxes { gap: 6px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .row-meta { text-align: left; min-width: 0; }
  .row-badge { min-width: 0; }
  .t-title { font-size: 24px; }
  .share-code { font-size: 34px; }
  .viewer-stage { padding: 6px 8px 70px; }
  .viewer-nav { top: auto; bottom: 10px; margin-top: 0; height: 48px; }
}
