/* e-Ink Manager: stile condiviso (login, dashboard).
   Regole di riferimento: skill design-taste-frontend (v2).
   Dial: VARIANCE 4 / MOTION 4 / DENSITY 4.
   Tema: auto (prefers-color-scheme), un solo accento, un solo sistema di raggi. */

@font-face {
  font-family: "Geist";
  src: url("../fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ─── Token ─────────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  --bg:          #f4f4f5;
  --surface:     #fcfcfc;
  --surface-2:   #ececee;
  --line:        #dcdce0;
  --text:        #18181b;
  --text-muted:  #5b5b64;   /* 6.2:1 su --surface */
  --accent:      #0f766e;
  --accent-ink:  #f4fffd;   /* testo sui bottoni accent, 5.5:1 */
  --accent-soft: #d7efec;
  --danger:      #b42318;
  --danger-soft: #fbe4e1;
  --panel-paper: #f7f7f5;   /* il bianco del pannello, appena attenuato per lo schermo */
  --shadow:      0 1px 2px rgb(24 24 40 / .06), 0 8px 24px -12px rgb(24 24 40 / .18);

  /* Sistema di raggi (una sola regola): controlli 10px, contenitori 16px,
     solo i badge di stato sono pill. */
  --r-control: 10px;
  --r-card:    16px;

  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0e0e11;
    --surface:     #17171b;
    --surface-2:   #202026;
    --line:        #2d2d35;
    --text:        #ededf0;
    --text-muted:  #a0a0ab;   /* 7:1 su --surface */
    --accent:      #2dd4bf;
    --accent-ink:  #04201c;   /* 10:1 sull'accent */
    --accent-soft: #12332f;
    --danger:      #ff8a80;
    --danger-soft: #3a1815;
    --panel-paper: #e9e9e6;
    --shadow:      0 1px 2px rgb(0 0 0 / .4), 0 10px 28px -14px rgb(0 0 0 / .7);
  }
}

/* ─── Base ──────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

a { color: inherit; text-underline-offset: 3px; }

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

/* ─── Bottoni ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: 0 1.1rem; white-space: nowrap;
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--surface); color: var(--text);
  font-weight: 500; font-size: .95rem; cursor: pointer;
  transition: transform .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .ph { font-size: 1.15rem; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-block { width: 100%; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-muted); }

/* ─── Form ──────────────────────────────────────────────────────────────── */
.field { display: grid; gap: .4rem; }
.field label { font-size: .9rem; font-weight: 500; }
.field .hint { font-size: .85rem; color: var(--text-muted); }
.field .error-text { font-size: .85rem; color: var(--danger); }

.input {
  width: 100%; min-height: 46px; padding: 0 .85rem;
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--surface); color: var(--text);
}
.input::placeholder { color: var(--text-muted); opacity: .8; }
.input[aria-invalid="true"] { border-color: var(--danger); }

/* ─── Banner di stato (errori/successi inline) ──────────────────────────── */
.notice {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .75rem .9rem; border-radius: var(--r-control);
  font-size: .92rem; line-height: 1.4;
  background: var(--surface-2); color: var(--text);
}
.notice .ph { font-size: 1.2rem; flex: none; margin-top: 1px; }
.notice-ok     { background: var(--accent-soft); }
.notice-ok .ph { color: var(--accent); }
.notice-error  { background: var(--danger-soft); }
.notice-error .ph { color: var(--danger); }

/* ─── Shell e header ────────────────────────────────────────────────────── */
.shell { width: min(100% - 2rem, 920px); margin-inline: auto; padding-block: 1.25rem 3rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 56px; margin-bottom: 1.5rem;
}
.brand { display: inline-flex; align-items: center; gap: .75rem; text-decoration: none; min-width: 0; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-name {
  font-weight: 600; letter-spacing: -.01em; font-size: 1rem; white-space: nowrap;
  padding-left: .75rem; border-left: 1px solid var(--line);
}
.auth-logo { height: 52px; width: auto; display: block; margin-bottom: 1.1rem; }
.topbar-end { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.who {
  font-size: .88rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 24ch;
}

.page-title { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.1; letter-spacing: -.03em; font-weight: 650; }
.page-sub { margin-top: .5rem; color: var(--text-muted); max-width: 52ch; }

/* ─── Card gateway ──────────────────────────────────────────────────────── */
.gateways { display: grid; gap: 1.25rem; margin-top: 1.75rem; }

.gateway {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--shadow);
  padding: 1.25rem;
  display: grid; gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 768px) {
  .gateway { grid-template-columns: minmax(0, 300px) minmax(0, 1fr); padding: 1.5rem; gap: 2rem; align-items: start; }
}

.gw-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.gw-name { font-size: 1.1rem; font-weight: 600; letter-spacing: -.01em; }

/* Badge di stato: vero stato semantico (gateway raggiungibile o no). */
.badge {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .2rem .65rem; border-radius: 999px;
  font-size: .82rem; font-weight: 500;
  background: var(--surface-2); color: var(--text-muted);
}
.badge .ph { font-size: 1rem; }
.badge.on { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: light) { .badge.on { color: #0b5a54; } }

.gw-panels { margin-top: .35rem; font-size: .9rem; color: var(--text-muted); }

/* ─── Anteprima nel formato del pannello ────────────────────────────────── */
.frame {
  --frame-ratio: 3 / 4;                       /* 1200x1600 */
  position: relative; width: calc(100% - 14px); max-width: 286px; margin: 7px auto;
  aspect-ratio: var(--frame-ratio);
  border-radius: 4px;
  background: var(--panel-paper);
  /* cornice del pannello disegnata all'esterno, così l'area utile è esattamente 3:4 */
  box-shadow: 0 0 0 6px var(--surface-2), 0 0 0 7px var(--line), var(--shadow);
  overflow: hidden;
}
.viewport { position: absolute; inset: 0; overflow: hidden; }
.viewport img {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  object-fit: contain; max-width: none;
  user-select: none; -webkit-user-drag: none;
}
.frame.is-fill .viewport img { object-fit: fill; cursor: grab; touch-action: none; }
.frame.is-fill .viewport img.dragging { cursor: grabbing; }

.dropzone {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: .6rem;
  padding: 1rem; text-align: center;
  border: 1.5px dashed var(--line); border-radius: 4px; width: 100%;
  color: var(--text-muted); font-size: .92rem; line-height: 1.35;
  background: transparent; cursor: pointer;
  transition: border-color .2s var(--ease), background-color .2s var(--ease), color .2s var(--ease);
}
.dropzone .ph { font-size: 2rem; color: var(--text); }
.dropzone strong { color: var(--text); font-weight: 550; }
.dropzone:hover, .frame.is-over .dropzone { border-color: var(--accent); background: var(--accent-soft); }
.frame.is-over .dropzone { color: var(--text); }

.frame-caption { margin-top: .6rem; text-align: center; font-size: .82rem; color: var(--text-muted); }

/* ─── Controlli di invio ────────────────────────────────────────────────── */
.controls { display: grid; gap: 1.1rem; min-width: 0; }

.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: var(--r-control);
}
.seg button {
  min-height: 40px; padding: 0 .75rem; border: 0; border-radius: calc(var(--r-control) - 3px);
  background: transparent; color: var(--text-muted); font-weight: 500; font-size: .92rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.seg button:disabled { opacity: .5; cursor: not-allowed; }

.file-meta { font-size: .88rem; color: var(--text-muted); overflow-wrap: anywhere; }

.actions { display: grid; gap: .6rem; }
@media (min-width: 480px) { .actions { grid-template-columns: 1fr auto; } }

/* ─── Avanzamento upload ────────────────────────────────────────────────── */
.progress { display: grid; gap: .75rem; }

.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.stages li {
  display: flex; align-items: center; gap: .6rem;
  font-size: .93rem; color: var(--text-muted);
}
.stages li .ph { font-size: 1.15rem; }
.stages li[data-state="active"] { color: var(--text); font-weight: 500; }
.stages li[data-state="active"] .ph { color: var(--accent); }
.stages li[data-state="done"] .ph { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .stages li[data-state="active"] .ph { animation: spin 1s linear infinite; }
}
@keyframes spin { to { transform: rotate(360deg); } }
.stages li[data-state="error"] { color: var(--danger); }

.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > span {
  display: block; height: 100%; width: 0; background: var(--accent);
  transform-origin: left; transition: width .25s var(--ease);
}
.bar.indeterminate > span { width: 40%; animation: slide 1.4s var(--ease) infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

.wait-note { font-size: .88rem; color: var(--text-muted); }

/* ─── Aggiunta dispositivo ──────────────────────────────────────────────── */
.claim {
  margin-top: 1.25rem; padding: 1.25rem; border-radius: var(--r-card);
  border: 1px dashed var(--line); display: grid; gap: .9rem;
}
.claim h2 { font-size: 1rem; font-weight: 600; }
.claim-row { display: grid; gap: .6rem; }
@media (min-width: 480px) { .claim-row { grid-template-columns: 1fr auto; align-items: end; } }
#claimCode { text-transform: uppercase; letter-spacing: .04em; }

/* ─── Stato vuoto e scheletro ───────────────────────────────────────────── */
.empty {
  padding: 2rem 1.25rem; border-radius: var(--r-card);
  border: 1px dashed var(--line); text-align: center; display: grid; gap: .5rem; justify-items: center;
}
.empty .ph { font-size: 2rem; color: var(--text-muted); }
.empty p { color: var(--text-muted); max-width: 40ch; }

.skeleton {
  border-radius: var(--r-card); min-height: 220px;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%) 0 0 / 200% 100%;
  border: 1px solid var(--line);
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ─── Login ─────────────────────────────────────────────────────────────── */
.auth {
  min-height: 100dvh; display: grid; align-content: center;
  width: min(100% - 2rem, 400px); margin-inline: auto; padding-block: 2rem; gap: 1.75rem;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow); padding: 1.5rem; display: grid; gap: 1.25rem;
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: var(--r-control); }
.tabs button {
  min-height: 40px; border: 0; border-radius: calc(var(--r-control) - 3px);
  background: transparent; color: var(--text-muted); font-weight: 500; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.auth form { display: grid; gap: 1rem; }
.auth-foot { font-size: .88rem; color: var(--text-muted); }

/* ─── Movimento ridotto ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .bar.indeterminate > span { width: 100%; opacity: .5; }
}

/* ─── Libreria immagini ─────────────────────────────────────────────────── */
.library { grid-column: 1 / -1; display: grid; gap: .9rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.library-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.library-head h3 { font-size: 1rem; font-weight: 600; }
.library-count { font-size: .85rem; color: var(--text-muted); }

.library-grid { display: grid; gap: .9rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 560px) { .library-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 768px) { .library-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.shot { display: grid; gap: .5rem; min-width: 0; }
.shot-img {
  position: relative; aspect-ratio: 3 / 4; overflow: hidden;
  border-radius: var(--r-control); border: 1px solid var(--line); background: var(--panel-paper);
}
.shot-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot.is-current .shot-img { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.shot-name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shot-date { font-size: .78rem; color: var(--text-muted); margin-top: -.35rem; }
.shot-tag {
  position: absolute; left: .4rem; top: .4rem;
  padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 550;
  background: var(--accent); color: var(--accent-ink);
}
.shot-actions { display: grid; grid-template-columns: 1fr auto; gap: .4rem; }
.shot-actions .btn { min-height: 38px; padding: 0 .7rem; font-size: .88rem; }
.btn-icon { width: 38px; padding: 0 !important; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.library-empty { font-size: .92rem; color: var(--text-muted); padding: .5rem 0; }
.shot-skeleton { aspect-ratio: 3 / 4; }

/* ─── Zoom ──────────────────────────────────────────────────────────────── */
.zoom { display: grid; gap: .5rem; }
.zoom-label { display: flex; justify-content: space-between; align-items: baseline; font-size: .9rem; font-weight: 500; }
.zoom-value { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 400; }
.zoom-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: .5rem; align-items: center; }
.zoom-row .btn { min-height: 40px; min-width: 40px; padding: 0 .6rem; }
.zoom-row .btn-text { padding: 0 .9rem; font-size: .88rem; }

input[type="range"] { width: 100%; height: 40px; background: transparent; accent-color: var(--accent); cursor: pointer; }
input[type="range"]:disabled { cursor: not-allowed; opacity: .5; }

/* Su schermi stretti l'email lascia spazio a logo e nome */
@media (max-width: 639px) { .who { display: none; } }
.topbar-end { flex: none; }

.notice-text { flex: 1; min-width: 0; }
.notice-action { min-height: 36px; padding: 0 .8rem; font-size: .88rem; flex: none; }

/* ─── Tessera "Nuova foto" nella libreria ───────────────────────────────── */
.shot-add {
  aspect-ratio: 3 / 4; display: grid; place-content: center; justify-items: center; gap: .5rem;
  border: 1.5px dashed var(--line); border-radius: var(--r-control); background: transparent;
  color: var(--text-muted); font-size: .9rem; cursor: pointer;
  transition: border-color .2s var(--ease), background-color .2s var(--ease), color .2s var(--ease);
}
.shot-add .ph { font-size: 1.8rem; color: var(--text); }
.shot-add:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.shot-add:disabled { opacity: .5; cursor: not-allowed; }
.library-grid .library-empty { grid-column: span 1; align-self: center; }

.progress-cancel { justify-self: start; min-height: 38px; font-size: .88rem; }
.progress-cancel[hidden] { display: none; }

/* ─── Orientamento orizzontale ──────────────────────────────────────────── */
.frame.is-land { --frame-ratio: 4 / 3; max-width: 406px; }
@media (min-width: 768px) {
  .gateway.is-land { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); }
}
.shot-img.is-land img { object-fit: contain; }
.seg [class~="ph-rotate"] { transform: rotate(90deg); }
.gateway .seg button .ph { font-size: 1.1rem; }

/* ─── Editor di scritte ─────────────────────────────────────────────────── */
.txt-root { position: absolute; inset: 0; overflow: hidden; }
.txt-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.txt-editor { cursor: text; }
.txt-editor:empty::before {
  content: attr(data-placeholder); opacity: .45; pointer-events: none;
}
.txt-editor:focus-visible { outline: none; }
.frame:has(.txt-editor:focus) { box-shadow: 0 0 0 6px var(--accent-soft), 0 0 0 7px var(--accent), var(--shadow); }

.txt-controls { display: grid; gap: 1.1rem; }
.txt-group { display: grid; gap: .6rem; }
.txt-label { font-size: .9rem; font-weight: 500; }
.txt-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.txt-select { width: auto; min-width: 0; flex: 1 1 7rem; min-height: 44px; }
.txt-select[aria-label="Dimensione"] { flex: 0 0 5.5rem; }
.txt-tools { gap: .35rem; }
.txt-tool { min-height: 44px; width: 44px; }
.txt-tool[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.txt-sep { width: 1px; align-self: stretch; margin: .35rem .25rem; background: var(--line); }
.txt-seg3 { grid-template-columns: repeat(3, 1fr); }
.txt-seg3 button { padding: 0 .4rem; font-size: .85rem; }

.txt-colorlabel, .txt-bgbtn { position: relative; }
.txt-colorlabel {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; padding: 0 .6rem;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); cursor: pointer;
}
.txt-colorlabel .ph { font-size: 1.15rem; }
.txt-color { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.txt-bgbtn .txt-color { width: 24px; height: 24px; }

.txt-swatches { display: grid; grid-template-columns: repeat(auto-fill, 48px); gap: .5rem; }
.txt-swatch {
  position: relative; width: 48px; height: 48px; padding: 0; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface);
}
.txt-swatch:disabled { opacity: .5; cursor: not-allowed; }
.txt-swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
/* miniatura: lo stesso sfondo della tela, ridotto */
.txt-mini { position: absolute; left: 0; top: 0; width: 150px; height: 150px; transform: scale(.32); transform-origin: 0 0; }
