/* pin·image — stesso aspetto del design: grigio neutro, un accento blu, font di sistema
   (nessun font esterno: niente richieste a terzi, niente problemi di privacy). */

:root {
  --ground: #EDEDE9;
  --panel: #FFFFFF;
  --ink: #16181D;
  --ink-2: #3E424A;
  --muted: #565B63;
  --line: #D5D6D1;
  --line-2: #E6E6E2;
  --field: #B9BBB5;
  --soft: #F4F4F1;
  --accent: #1D4ED8;
  --accent-ink: #1E3A8A;
  --accent-soft: #E6ECFB;
  --ok: #15803D;
  --ok-soft: #DCF2E3;
  --warn: #B45309;
  --warn-soft: #FDF0DC;
  --bad: #B91C1C;
  --bad-soft: #FDE7E7;
  --bar: #16181D;
  --bar-ink: #F4F4F2;
  --bar-muted: #C9CBD1;
  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", "Noto Sans", "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 15px/1.45 var(--sans); }
h1 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Barra in alto */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; padding: 12px 24px; background: var(--bar); color: var(--bar-ink); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font: 600 17px/1 var(--mono); letter-spacing: 0.02em; }
.brand:hover { color: inherit; }
.brand-dark { color: var(--ink); }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.nav a { padding: 10px 12px; border-radius: 6px; color: var(--bar-muted); text-decoration: none; }
.nav a:hover { color: #FFFFFF; background: #23262D; }
.nav a[aria-current="page"] { background: #2B2E36; color: #FFFFFF; font-weight: 500; }
.nav-sep { width: 1px; height: 22px; background: #3B3F49; margin: 0 6px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; }
.who-name { color: var(--bar-muted); text-decoration: none; }
.who-name:hover { color: #FFFFFF; }
.who-role { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #2B2E36; }
.who form { margin: 0; }
.btn-quiet { min-height: 36px; padding: 0 12px; border: 1px solid #3B3F49; border-radius: 6px; background: transparent; color: var(--bar-ink); font: inherit; font-size: 14px; cursor: pointer; }

.flash { max-width: 1600px; margin: 16px auto 0; padding: 12px 16px; border-radius: 8px; width: calc(100% - 48px); font-size: 14px; }
.flash-ok { background: var(--ok-soft); color: #14532D; }
.flash-info { background: var(--accent-soft); color: var(--accent-ink); }
.flash-secret { background: var(--warn-soft); color: #7C2D12; font-family: var(--mono); font-size: 15px; word-break: break-word; }

.page { max-width: 1600px; margin: 0 auto; padding: 24px; }

/* Mattoni */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.narrow { max-width: 560px; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-s { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap, .between.wrap { flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.help { font-size: 12px; color: var(--muted); }
.note { padding: 10px 12px; background: var(--accent-soft); color: var(--accent-ink); border-radius: 6px; font-size: 14px; }
.alert { padding: 10px 12px; background: var(--bad-soft); color: #7F1D1D; border-radius: 6px; font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .field .between label { font-size: 13px; color: var(--ink-2); }
input, select, textarea { font: inherit; color: var(--ink); }
input:not([type]), input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[inputmode], select, textarea {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 6px; background: #FFFFFF; font-size: 15px; width: 100%;
}
textarea { padding: 10px 12px; line-height: 1.45; resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
input[type="color"] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--field); border-radius: 4px; background: #FFFFFF; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.unit { display: flex; align-items: center; border: 1px solid var(--field); border-radius: 6px; padding-right: 10px; background: #FFFFFF; }
.unit input { border: 0 !important; min-width: 0; font-family: var(--mono); }
.unit span { font-size: 12px; color: var(--muted); }
.unit:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.unit input:focus-visible { outline: none; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: 14px; }
.indent { padding-left: 26px; }
output { font-family: var(--mono); font-weight: 500; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--field); border-radius: 6px;
  background: #FFFFFF; color: var(--ink); font: inherit; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); color: var(--ink); }
.btn-s { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; font-weight: 500; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #FFFFFF; }
.btn-danger { color: var(--bad); border-color: transparent; background: transparent; }
.btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn-link { min-height: 36px; padding: 0 8px; border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
.dirty { font-size: 12px; color: var(--warn); }

/* Pulsanti a scelta singola (radio) */
.pills { display: grid; gap: 6px; }
.pills-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pills-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pill { position: relative; display: block; }
.pill input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.pill span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 8px; border: 1px solid var(--field); border-radius: 6px;
  background: #FFFFFF; font-size: 14px; font-weight: 500; text-align: center; }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #FFFFFF; font-weight: 600; }
.pill input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.pill input:disabled + span { opacity: 0.4; text-decoration: line-through; }

.why { display: flex; gap: 8px; padding: 10px 12px; background: var(--soft); border-radius: 6px; font-size: 13px; color: var(--ink-2); }
.why svg { flex: none; margin-top: 2px; color: var(--muted); }

/* Workspace */
.ws { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.ws-side { flex: 1 1 320px; max-width: 380px; min-width: 0; }
.ws-main { flex: 999 1 560px; min-width: 0; }
@media (max-width: 720px) {
  .ws-side { max-width: none; }
  .ws-main { order: -1; } /* su telefono prima le sagome e "Scegli file", poi le impostazioni */
}
.summary { padding: 8px 12px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; font-weight: 500; }

.ratios { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ratio { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 10px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: #FFFFFF; font: inherit; color: inherit; cursor: pointer; }
.ratio:hover { border-color: var(--ink-2); }
.ratio-frame { height: 124px; display: flex; align-items: center; justify-content: center; }
.ratio-shape { display: flex; align-items: center; justify-content: center; border: 1.5px dashed #8E9198; border-radius: 3px; background: var(--soft);
  font: 600 16px/1 var(--mono); color: var(--ink); }
.ratio-shape.is-orig { font-size: 13px; }
.ratio-shape.is-free { border-radius: 0; font-size: 14px; }
.ratio-hint { font-size: 13px; line-height: 1.3; color: var(--ink-2); text-align: center; }
.ratio[aria-pressed="true"] { border-color: var(--accent); background: #F7F9FF; }
.ratio[aria-pressed="true"] .ratio-shape { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.ratio.is-over { border-color: var(--accent); background: #F7F9FF; }
.ratio.is-over .ratio-shape { border: 2px dashed var(--accent); background: #D3DEFA; color: var(--accent-ink); }
body.is-dragging .ratio .ratio-shape { border-color: var(--accent); }

.queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.job { display: grid; grid-template-columns: 56px minmax(0, 1fr) 70px auto; gap: 16px; align-items: center; padding: 12px 4px; border-top: 1px solid var(--line-2); }
.job-thumb { width: 52px; height: 52px; border-radius: 4px; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#DADBD6 0 25%, #EEEEEA 0 50%) 0 0 / 12px 12px; }
.job-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.job-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.job-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-src, .job-out { font-size: 13px; color: var(--ink-2); }
.job-notes { font-size: 13px; color: var(--warn); }
.job[data-state="error"] .job-notes { color: var(--bad); }
.job-gain { font-weight: 600; color: var(--muted); text-align: right; }
.job-gain.is-good { color: var(--ok); }
.job-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; min-width: 120px; }
.job-status { font-size: 12px; color: var(--ink-2); }
.job progress { width: 120px; height: 6px; accent-color: var(--accent); }
.job-error { font-size: 13px; font-weight: 600; color: var(--bad); }
@media (max-width: 600px) {
  .job { grid-template-columns: 52px minmax(0, 1fr); }
  .job-gain { text-align: left; }
  .job-gain, .job-actions { grid-column: 2; justify-content: flex-start; }
}

dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: min(520px, calc(100vw - 32px)); color: var(--ink); }
dialog::backdrop { background: rgba(22, 24, 29, 0.45); }

/* Preselezioni */
.split { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.split-main { flex: 999 1 560px; min-width: 0; }
.split-side { flex: 1 1 340px; max-width: 460px; min-width: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.preset { display: flex; flex-direction: column; gap: 10px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; }
.preset:hover { border-color: var(--ink-2); color: inherit; }
.preset[aria-current="true"] { border: 2px solid var(--accent); padding: 17px; }
.preset h2 { font-size: 17px; }
.preset p { font-size: 14px; color: var(--ink-2); }
.preset-new { align-items: center; justify-content: center; min-height: 160px; border: 1.5px dashed #8E9198; background: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12px/1.4 var(--mono); padding: 3px 8px; border-radius: 4px; background: #F0F0EC; border: 1px solid #DEDFDA; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-ink); }
.badge-dark { background: var(--ink); color: #FFFFFF; }
.badge-ok { background: var(--ok-soft); color: #14532D; }
.badge-warn { background: var(--warn-soft); color: #7C2D12; }
.badge-bad { background: var(--bad-soft); color: #7F1D1D; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--field); background: #FFFFFF; color: var(--ink); text-decoration: none; font-size: 13px; }
.filters a[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
legend { font-size: 13px; color: var(--ink-2); padding: 0 4px; }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 0 12px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line-2); vertical-align: top; }
td.mono, td .mono { font-size: 13px; }
.detail { max-width: 640px; word-break: break-word; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--muted); }
.dot-process { background: var(--accent); }
.dot-process_error, .dot-login_failed { background: var(--bad); }
.dot-preset { background: #7C3AED; }
.dot-user, .dot-settings, .dot-password { background: var(--warn); }
.pager { display: flex; gap: 8px; align-items: center; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-warn { color: var(--warn); font-weight: 600; }
.status-fail { color: var(--bad); font-weight: 600; }

/* Pagine senza barra (accesso, errore) */
body.bare { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.bare-main { width: 100%; max-width: 420px; }
.login { display: flex; flex-direction: column; gap: 18px; padding: 28px; }
