/* NAS di casa: pensato per il telefono, va bene anche sul PC. Segue il tema del sistema. */
:root {
  --bg: #0a0f1c; --bg-2: #0f1628; --panel: #131b30; --panel-2: #18223b; --line: #232f4b; --line-2: #2e3c5e;
  --text: #eef3ff; --text-2: #b9c5dd; --muted: #8494b4; --accent: #2de2e6; --accent-ink: #032326;
  --green: #3cff9e; --amber: #ffb547; --red: #ff5c7a; --violet: #9d8bff; --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --r: 16px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb; --bg-2: #eaeef6; --panel: #ffffff; --panel-2: #f6f8fc; --line: #e1e6f0; --line-2: #cfd7e6;
    --text: #0e1628; --text-2: #34415c; --muted: #66748f; --accent: #0a9ea3; --accent-ink: #ffffff;
    --green: #109a5c; --amber: #b86e00; --red: #d2344f; --violet: #6a55e0; --shadow: 0 18px 50px rgba(20, 30, 60, .16);
    color-scheme: light;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); overscroll-behavior-y: none;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---- accesso */
.auth { min-height: 100%; display: grid; place-items: center; padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b)); }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.logo { width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 24px; display: grid; place-items: center;
  background: radial-gradient(120% 120% at 30% 20%, #1d3b5a, #0b1424 70%); box-shadow: 0 0 0 1px var(--line-2), 0 14px 40px rgba(45, 226, 230, .18); }
.logo svg { width: 46px; height: 46px; stroke: var(--accent); stroke-width: 1.6; fill: none; }
.auth h1 { font-size: 28px; margin: 0 0 6px; letter-spacing: -.3px; }
.auth p { margin: 0 0 26px; color: var(--muted); }
.field { display: block; text-align: left; margin: 0 0 14px; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin: 0 0 6px; }
.field input { width: 100%; padding: 14px 15px; border-radius: 13px; border: 1px solid var(--line-2); background: var(--panel);
  outline: none; font-size: 17px; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.field input.code { text-transform: uppercase; letter-spacing: 2px; text-align: center; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.links { margin-top: 22px; display: grid; gap: 12px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 6px; }

/* ---- pulsanti */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 13px;
  border: 1px solid var(--line-2); background: var(--panel); font-weight: 600; min-height: 46px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { width: 100%; font-size: 17px; padding: 15px 18px; min-height: 54px; }
.btn.danger { color: var(--red); }
.btn.solid-danger { background: var(--red); border-color: transparent; color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.icon-btn { width: 44px; height: 44px; border-radius: 13px; border: 0; background: transparent; display: grid; place-items: center; color: var(--text-2); }
.icon-btn:active { background: var(--panel-2); }

/* ---- struttura principale */
.top { position: sticky; top: 0; z-index: 5; padding: calc(10px + var(--safe-t)) 14px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 8px; max-width: 1100px; margin: 0 auto; }
.top-row h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.2px; }
.areas { display: flex; gap: 8px; max-width: 1100px; margin: 10px auto 0; overflow-x: auto; scrollbar-width: none; }
.areas::-webkit-scrollbar { display: none; }
.area { flex: none; padding: 8px 15px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel); font-weight: 600; font-size: 15px; }
.area.on { background: var(--text); color: var(--bg); border-color: transparent; }
.crumbs { display: flex; align-items: center; gap: 2px; max-width: 1100px; margin: 8px auto 0; font-size: 14px; color: var(--muted); overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { background: none; border: 0; color: var(--text-2); padding: 4px 6px; border-radius: 8px; }
.crumbs button:last-child { color: var(--text); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 12px 14px calc(110px + var(--safe-b)); }

/* ---- elenco e griglia */
.list { display: grid; gap: 2px; }
.row { display: flex; align-items: center; gap: 13px; padding: 10px 10px; border-radius: 14px; position: relative; user-select: none; -webkit-user-select: none; }
.row:active { background: var(--panel-2); }
.row.sel { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.thumb { width: 48px; height: 48px; border-radius: 11px; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; flex: none; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.dir { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.thumb.safe { color: var(--green); background: color-mix(in srgb, var(--green) 13%, var(--panel)); }
.row .meta { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-2); flex: none; display: grid; place-items: center; }
.row.sel .check, .tile.sel .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check svg { width: 15px; height: 15px; stroke-width: 3; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 4px; margin-top: 10px; }
.tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--panel-2); border: 0; padding: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .55); color: #fff; border-radius: 7px; padding: 1px 6px; font-size: 12px; display: flex; gap: 4px; align-items: center; }
.tile .badge svg { width: 13px; height: 13px; }
.tile .check { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .25); border-color: #fff; }
.tile .ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 18px 4px 6px; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty svg { width: 54px; height: 54px; stroke-width: 1.3; color: var(--line-2); margin-bottom: 10px; }
.safe-note { display: flex; gap: 10px; align-items: center; padding: 11px 13px; border-radius: 13px; margin: 4px 0 10px;
  background: color-mix(in srgb, var(--green) 10%, var(--panel)); color: var(--text-2); font-size: 14px; border: 1px solid color-mix(in srgb, var(--green) 25%, transparent); }
.safe-note svg { color: var(--green); }

/* ---- barra in basso */
.dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); z-index: 6; display: flex; gap: 6px;
  padding: 7px; border-radius: 20px; background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line-2);
  box-shadow: var(--shadow); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); max-width: calc(100% - 24px); }
.dock button { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 66px; padding: 7px 8px; border: 0; background: transparent;
  border-radius: 14px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.dock button.main { background: var(--accent); color: var(--accent-ink); }
.dock button:disabled { opacity: .4; }
.dock button:active:not(:disabled) { background: var(--panel-2); }
.dock button.main:active { background: var(--accent); filter: brightness(.92); }

/* ---- finestre dal basso */
#sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(4, 8, 18, .55); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
#sheet { width: 100%; max-width: 520px; background: var(--panel); border-radius: 22px 22px 0 0; padding: 10px 18px calc(20px + var(--safe-b)); box-shadow: var(--shadow);
  max-height: 88vh; overflow: auto; animation: up .22s cubic-bezier(.2, .8, .2, 1); }
@media (min-width: 700px) { #sheet-wrap { align-items: center; } #sheet { border-radius: 22px; padding-bottom: 20px; } }
#sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 0 auto 12px; }
#sheet h2 { margin: 0 0 4px; font-size: 20px; }
#sheet p { margin: 0 0 14px; color: var(--muted); font-size: 14.5px; }
.menu { display: grid; gap: 2px; margin: 6px 0 4px; }
.menu button { display: flex; align-items: center; gap: 14px; padding: 13px 10px; border-radius: 13px; border: 0; background: transparent; text-align: left; font-size: 16px; }
.menu button:active { background: var(--panel-2); }
.menu button.danger { color: var(--red); }
.menu button:disabled { opacity: .4; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; }
.folders { max-height: 46vh; overflow: auto; margin: 4px -6px; }
.recovery { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 22px; letter-spacing: 2px; text-align: center; padding: 16px; border-radius: 14px;
  background: var(--bg-2); border: 1px dashed var(--line-2); margin: 6px 0 12px; user-select: all; -webkit-user-select: all; word-break: break-all; }
.pk { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); }
.pk:first-child { border-top: 0; }
.pk .meta { flex: 1; min-width: 0; }

/* ---- visore foto e video */
#viewer { position: fixed; inset: 0; z-index: 30; background: #000; color: #fff; display: flex; flex-direction: column; animation: fade .15s ease; touch-action: pan-y; }
#viewer .vbar { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 8px 8px; background: linear-gradient(#000c, #0000); position: absolute; inset: 0 0 auto; z-index: 2; }
#viewer .vbar .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
#viewer .icon-btn { color: #fff; }
#viewer .stage { flex: 1; position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; }
#viewer video { max-width: 100%; max-height: 100%; display: block; }
/* la foto riempie lo spazio restando intera e centrata; si ingrandisce con transform */
#viewer .stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block;
  touch-action: none; user-select: none; -webkit-user-drag: none; cursor: zoom-in;
  transform-origin: center; transition: transform .15s ease-out; will-change: transform; }
#viewer .stage.zoomed img { cursor: grab; transition: none; }
#viewer .stage.zoomed img:active { cursor: grabbing; }
#viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: 0; background: rgba(255, 255, 255, .08); color: #fff; border-radius: 12px; display: grid; place-items: center; }
#viewer .nav.prev { left: 10px; } #viewer .nav.next { right: 10px; }
@media (hover: none) { #viewer .nav { display: none; } }
#viewer .vfoot { position: absolute; inset: auto 0 0; padding: 10px 14px calc(12px + var(--safe-b)); background: linear-gradient(#0000, #000c); font-size: 13px; color: #cfd6e6; text-align: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .2); border-top-color: var(--accent); animation: spin .8s linear infinite; }

/* ---- caricamenti */
#uploads { position: fixed; left: 12px; right: 12px; bottom: calc(86px + var(--safe-b)); z-index: 7; max-width: 520px; margin: 0 auto; background: var(--panel);
  border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 14px; }
#uploads .up-head { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14.5px; }
#uploads .up-head span { flex: 1; }
.bar { height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; margin-top: 9px; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
#uploads .up-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#toast { position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translate(-50%, -140%); z-index: 40; background: var(--text); color: var(--bg);
  padding: 11px 16px; border-radius: 14px; font-size: 14.5px; font-weight: 600; box-shadow: var(--shadow); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  max-width: calc(100% - 28px); text-align: center; opacity: 0; visibility: hidden; }
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
#toast.err { background: var(--red); color: #fff; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
