/* Menú Express · grafica delle pagine di gestione
 * Idea: la pizarra del bar. Verde lavagna, gesso, e il giallo zafferano dei cartelli.
 * Caratteri: Young Serif (titoli) e Atkinson Hyperlegible (testo), inclusi nel programma. */
@font-face { font-family: "Young Serif"; src: url("fonts/YoungSerif-Regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/AtkinsonHyperlegible-Regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/AtkinsonHyperlegible-Bold.woff") format("woff"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/AtkinsonHyperlegible-Italic.woff") format("woff"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
    --ink: #183a2f;          /* verde lavagna */
    --ink-2: #245241;
    --chalk: #f5f4ec;        /* gesso */
    --cyan: #1d6a4e;         /* link e controlli */
    --cyan-soft: #e2ede4;    /* selezione */
    --saffron: #f2b233;      /* zafferano: azioni principali e accenti */
    --saffron-deep: #d99a17;
    --accent: var(--saffron);
    --bg: #edf0ea;
    --surface: #ffffff;
    --text: #1a2520;
    --muted: #59685f;
    --line: #d4dcd5;
    --danger: #b0392b;
    --danger-soft: #f9e7e3;
    --ok: #1d7347;
    --ok-soft: #e1f2e6;
    --warn-soft: #fdf1d3;
    --radius: 14px;
    --radius-sm: 10px;
    --font-head: "Young Serif", Georgia, "Times New Roman", serif;
    --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
    color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.5 var(--font-body);
}

img { max-width: 100%; }

a { color: var(--cyan); text-underline-offset: 3px; }
a:hover { color: var(--ink); }

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

h1, h2, h3 { font-family: var(--font-head); font-weight: 400; line-height: 1.15; font-synthesis: none; }

/* Icone: tratto nel colore del testo, campitura zafferano leggermente sfalsata (come una stampa a due colori) */
.icon { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.icon .a { fill: var(--accent); stroke: none; transform: translate(2.5px, 2.5px); }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.muted { color: var(--muted); }
.small { font-size: 14px; }
.upper { text-transform: uppercase; }
.print-only { display: none; }

/* ---------- Intestazione ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px clamp(16px, 4vw, 32px);
    background: var(--ink);
    color: var(--chalk);
    border-bottom: 3px solid var(--saffron);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--chalk);
    text-decoration: none;
    min-width: 0;
}
.brand:hover { color: #fff; }
.brand img { flex: none; border-radius: 10px; box-shadow: 0 0 0 1.5px rgba(245, 244, 236, .25); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-family: var(--font-head); font-size: 19px; font-weight: 400; letter-spacing: .005em; }
.brand-text span { font-size: 14px; color: #b9cdc2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topnav { display: flex; align-items: center; gap: 4px; }
.topnav form { margin: 0; }
.topnav a, .topnav .linklike {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--chalk);
    text-decoration: none;
    font: inherit;
    font-size: 16px;
    background: none;
    border: 0;
    cursor: pointer;
}
.topnav .icon { width: 22px; height: 22px; stroke-width: 3; }
.topnav a:hover, .topnav .linklike:hover { background: var(--ink-2); color: #fff; }

/* ---------- Pagina ---------- */
.page {
    max-width: 880px;
    margin: 0 auto;
    padding: 24px clamp(16px, 4vw, 32px) 64px;
}
.page-wide { max-width: 1240px; }
.page-home .page-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.page-title {
    margin: 6px 0 22px;
    font-size: clamp(30px, 5vw, 42px);
    letter-spacing: -.005em;
    color: var(--ink);
}

.backlink {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 16px;
}
.backlink:hover { color: var(--ink); }

.section-title { font-size: 22px; margin: 26px 0 10px; color: var(--ink); }

/* ---------- Messaggi ---------- */
.flash {
    margin: 0 0 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border-left: 5px solid;
    background: var(--surface);
}
.flash-ok    { border-color: var(--ok); background: var(--ok-soft); }
.flash-error { border-color: var(--danger); background: var(--danger-soft); }
.flash-warn  { border-color: var(--saffron); background: var(--warn-soft); }
.flash-info  { border-color: var(--cyan); background: var(--cyan-soft); }

/* ---------- Pulsanti ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 48px;
    padding: 10px 20px;
    border: 2px solid var(--ink);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink);
    font: 700 16px/1.1 var(--font-body);
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s, color .15s, border-color .15s;
}
.btn .icon { width: 22px; height: 22px; margin-left: -4px; }
.btn:hover { background: var(--ink); color: var(--chalk); }
.btn:hover .icon .a { fill: var(--saffron); }
.btn-primary { background: var(--saffron); border-color: var(--saffron); color: var(--ink); }
.btn-primary .icon .a { fill: #fff; }
.btn-primary:hover { background: var(--ink); border-color: var(--ink); color: var(--chalk); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--cyan); text-decoration: underline; text-underline-offset: 3px; }
.btn-ghost:hover { background: var(--cyan-soft); color: var(--ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8a271e; border-color: #8a271e; color: #fff; }
.btn-danger-ghost { border-color: transparent; background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.btn-small { min-height: 38px; padding: 6px 14px; font-size: 15px; border-width: 1.5px; }
.btn-small .icon { width: 18px; height: 18px; }
.btn-block { width: 100%; }

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 20px 0;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    margin: 20px -24px -24px;
    padding: 14px 24px;
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--line);
    border-radius: 0 0 var(--radius) var(--radius);
}

.danger-zone { margin: 24px 0; text-align: right; }

/* ---------- Schede e form ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.form { display: flex; flex-direction: column; gap: 22px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend, .field-label { font-weight: 700; color: var(--ink); }
.field > legend { padding: 0; margin-bottom: 8px; }
.field small, .field-label small { font-weight: 400; }
.field.compact > span { font-weight: 400; color: var(--muted); font-size: 15px; }

input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1.5px solid #b9c6bb;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font: 17px/1.4 var(--font-body);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); outline: 3px solid var(--cyan-soft); outline-offset: 0; }
input[type=color] { width: 64px; height: 44px; padding: 2px; border: 1.5px solid #b9c6bb; border-radius: var(--radius-sm); background: #fff; }
.input-small { width: 110px; min-height: 40px; text-align: right; }
.field-date input { max-width: 240px; }

.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form-inline .field { flex: 1 1 200px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 18px; }
.field-group { border: 0; padding: 0; margin: 0; }
.field-group > legend { font-family: var(--font-head); font-weight: 700; font-size: 19px; color: var(--ink); margin-bottom: 10px; }

/* Selettore tipo (radio a segmenti) */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; max-width: 440px; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; padding: 10px 8px; font-weight: 700; color: var(--ink); text-align: center; }
.seg label + label span { border-left: 2px solid var(--ink); }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--saffron); outline-offset: -3px; }

/* Allergeni (checkbox con icona) */
.alg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.alg { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: #fff; }
.alg input { position: absolute; opacity: 0; }
.alg img { width: 34px; height: 34px; object-fit: contain; filter: grayscale(1); opacity: .55; }
.alg span { font-size: 15px; line-height: 1.2; }
.alg:has(input:checked) { border-color: var(--ink); background: var(--cyan-soft); box-shadow: inset 0 0 0 1px var(--ink); }
.alg:has(input:checked) img { filter: none; opacity: 1; }
.alg:has(input:focus-visible) { outline: 3px solid var(--saffron); outline-offset: 2px; }

.photo-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.photo-preview { width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); }
.filepick { display: inline-flex; flex-direction: column; gap: 6px; font-size: 15px; color: var(--muted); }
.filepick input { font: inherit; color: var(--text); }

/* ---------- Home: la pizarra del giorno ---------- */
.today {
    position: relative;
    margin-bottom: 26px;
    padding: clamp(22px, 4vw, 36px);
    border: 9px solid #6f4d2e;
    border-radius: 16px;
    background:
        radial-gradient(ellipse 70% 55% at 22% 18%, rgba(245, 244, 236, .07), transparent 70%),
        radial-gradient(ellipse 60% 50% at 85% 90%, rgba(245, 244, 236, .05), transparent 70%),
        var(--ink);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25), inset 0 2px 18px rgba(0, 0, 0, .25), 0 10px 24px -14px rgba(24, 58, 47, .55);
    color: var(--chalk);
}
.today-head { margin-bottom: 20px; }
.today-kicker { margin: 0 0 2px; color: var(--saffron); font-weight: 700; font-size: 16px; }
.today h2 { margin: 0; font-size: clamp(32px, 6.4vw, 52px); color: var(--chalk); letter-spacing: -.005em; }
.today-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.today-cols h3 { margin: 0 0 8px; font-size: 21px; color: var(--saffron); }
.today-cols ul { margin: 0; padding: 0; list-style: none; }
.today-cols li { padding: 8px 0; border-bottom: 1.5px dashed rgba(245, 244, 236, .22); font-size: 16.5px; letter-spacing: .01em; }
.today-empty { margin: 0; font-size: 20px; font-family: var(--font-head); }
.today .actions { margin: 24px 0 0; }
.today .btn { border-color: rgba(245, 244, 236, .7); background: transparent; color: var(--chalk); }
.today .btn:hover { background: var(--chalk); border-color: var(--chalk); color: var(--ink); }
.today .btn-primary { background: var(--saffron); border-color: var(--saffron); color: var(--ink); }
.today .btn-primary:hover { background: var(--chalk); border-color: var(--chalk); }
.today .btn-ghost { border-color: transparent; color: #cfe1d6; }
.today .btn-ghost:hover { background: rgba(245, 244, 236, .1); color: #fff; }
.today .btn:not(.btn-primary) .icon .a { fill: rgba(242, 178, 51, .85); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 26px 12px 20px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    text-align: center;
    font-weight: 700;
    transition: border-color .15s, transform .15s;
}
.tile .icon { width: 64px; height: 64px; stroke-width: 2.4; }
.tile small { display: inline-block; margin-left: 4px; padding: 0 9px; border-radius: 99px; background: var(--saffron); font-size: 13px; color: var(--ink); vertical-align: 2px; }
.tile:hover { border-color: var(--ink); color: var(--ink); transform: translateY(-2px); }
.subnav { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 20px 0; }
.subnav a { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.subnav .icon { width: 24px; height: 24px; }

/* ---------- Elenchi ---------- */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.search { flex: 1 1 260px; max-width: 420px; }

.dish-group { margin-bottom: 28px; }
.dish-group h2 { margin: 0 0 10px; font-size: 24px; color: var(--ink); }
.dish-group h2 small { font: 400 15px var(--font-body); color: var(--muted); }

.dish-rows, .menu-rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.dish-rows li, .menu-rows li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.dish-rows li + li, .menu-rows li + li { border-top: 1px solid var(--line); }
.dish-link, .menu-row-link { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; color: var(--text); text-decoration: none; }
.dish-link img { flex: none; width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: cover; background: var(--bg); }
.dish-title { flex: 1 1 auto; min-width: 10ch; font-weight: 700; overflow-wrap: break-word; }
.dish-link:hover .dish-title, .menu-row-link:hover .menu-row-date { color: var(--cyan); text-decoration: underline; }
.menu-row-link { flex-direction: column; align-items: flex-start; gap: 0; }
.menu-row-date { font-weight: 700; }
.menu-rows li.is-today { background: var(--warn-soft); }

.alg-icons { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 3px; margin-left: auto; flex: 0 1 auto; }
.alg-icons img { height: 26px; width: auto; }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }
.chips li { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; border-radius: 99px; background: var(--cyan-soft); font-size: 15px; font-weight: 700; color: var(--ink); }
.chips img { height: 28px; width: auto; }

.pill { display: inline-block; margin: 0 0 12px; padding: 2px 12px; border-radius: 99px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 700; font-style: normal; }
.pill-accent { background: var(--saffron); color: var(--ink); margin: 0 0 0 6px; vertical-align: 2px; }

.empty { text-align: center; }
.empty p { font-size: 18px; }

/* Scheda piatto */
.dish-sheet { display: grid; grid-template-columns: minmax(200px, 320px) 1fr; gap: 28px; }
.dish-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); display: block; }
.dish-info h3 { margin: 24px 0 8px; font-size: 19px; color: var(--ink); }
.prose { max-width: 65ch; }
.kcal { margin: 6px 0 12px; }

/* Tabelle */
.table-scroll { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table thead th { font-size: 14px; color: var(--muted); font-weight: 700; background: #f3f6f1; }
.table tfoot th { border-bottom: 0; }
.table td form { margin: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Carta degli allergeni (matrice) */
.matrix { border-collapse: collapse; width: 100%; font-size: 15px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); padding: 8px 6px; }
.matrix thead th { position: sticky; top: 0; background: #f3f6f1; vertical-align: bottom; }
.matrix-alg { width: 58px; text-align: center; font-weight: 400; }
.matrix-alg img { display: block; height: 34px; width: auto; margin: 0 auto 4px; }
.matrix-alg span { display: block; font-size: 11.5px; line-height: 1.15; color: var(--muted); }
.matrix-dish { text-align: left; min-width: 180px; padding-left: 16px !important; }
.matrix tbody th.matrix-dish a { color: var(--text); text-decoration: none; font-weight: 700; }
.matrix-cell { text-align: center; }
.matrix tbody tr:not(.matrix-group):hover { background: #f3f6f1; }
.matrix-group th { padding-top: 18px !important; text-align: left; font-family: var(--font-head); font-size: 18px; color: var(--ink); background: var(--surface); }
.dot-yes { color: var(--danger); font-size: 18px; line-height: 1; }

/* Menu: selezione dei piatti */
.picker { border: 0; padding: 0; margin: 0; }
.picker legend { font-family: var(--font-head); font-size: 20px; font-weight: 700; color: var(--ink); margin-bottom: 10px; padding: 0; }
.picker-count { font: 400 16px var(--font-body); color: var(--muted); }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: #fff; }
.pick input { width: 20px; height: 20px; accent-color: var(--ink); flex: none; }
.pick span { font-size: 15px; line-height: 1.25; overflow-wrap: anywhere; }
.pick:has(input:checked) { border-color: var(--ink); background: var(--cyan-soft); }
.pick:has(input:disabled) { opacity: .45; cursor: not-allowed; }

/* Ricerca ingredienti */
.search-results { list-style: none; margin: -12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.search-results button { font: 15px var(--font-body); padding: 8px 12px; border: 1.5px dashed var(--cyan); border-radius: 99px; background: #fff; color: var(--ink); cursor: pointer; }
.search-results button:hover { background: var(--cyan-soft); border-style: solid; }

/* Pagine con il foglio del menu */
.page-sheet .page { max-width: 900px; }
.page-sheet .sheet-wrap { margin-top: 8px; }
.style-layout { display: grid; grid-template-columns: minmax(300px, 440px) 1fr; gap: 28px; align-items: start; }
.style-preview { position: sticky; top: 84px; }

/* Login ed errori */
.page-login, .page-error {
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: radial-gradient(ellipse 60% 45% at 25% 20%, rgba(245, 244, 236, .07), transparent 70%), var(--ink);
}
.login-card, .error-box { width: min(100%, 420px); padding: 34px 28px; border-radius: var(--radius); background: var(--surface); text-align: center; border-top: 6px solid var(--saffron); box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .55); }
.login-card h1, .error-box h1 { margin: 14px 0 4px; font-size: 32px; color: var(--ink); }
.login-card img, .error-box img { border-radius: 18px; }
.login-card form { text-align: left; margin-top: 22px; }

/* ---------- Telefono ---------- */
@media (max-width: 720px) {
    body { font-size: 16px; }
    .brand-text strong { font-size: 16px; }
    .today-cols { grid-template-columns: 1fr; gap: 12px; }
    .tiles { grid-template-columns: repeat(2, 1fr); }
    .tile .icon { width: 52px; height: 52px; }
    .topnav span { display: none; }
    .topnav a, .topnav .linklike { padding: 8px; }
    .card { padding: 18px; }
    .sticky-actions { margin: 18px -18px -18px; padding: 12px 18px; }
    .dish-sheet { grid-template-columns: 1fr; }
    .dish-link { display: grid; grid-template-columns: 56px 1fr; column-gap: 14px; row-gap: 4px; align-items: center; }
    .dish-link img { grid-row: span 2; }
    .dish-link .alg-icons { justify-content: flex-start; margin-left: 0; }
    .dish-link .alg-icons img { height: 22px; }
    .page-home .page-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .style-layout { grid-template-columns: 1fr; }
    .table th, .table td { padding: 8px 6px; }
    .input-small { width: 76px; }
    .table .btn-small { padding: 6px 8px; }
    .style-preview { position: static; }
    .actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ---------- Stampa (pagine di gestione) ---------- */
@media print {
    body { background: #fff; font-size: 12pt; }
    .topbar, .backlink, .no-print, .actions, .flash, .toolbar { display: none !important; }
    .page { max-width: none; padding: 0; }
    .card { border: 0; padding: 0; }
    .print-only { display: block; }
    .page-allergens .page-title { display: none; }
    .print-head { font-family: var(--font-head); font-size: 16pt; font-weight: 700; margin: 0 0 8pt; }
    .matrix { font-size: 10pt; }
    .matrix-alg { width: auto; }
    .matrix-alg img { height: 24px; }
    .matrix thead th { position: static; }
    .table-scroll { overflow: visible; }
    a { color: inherit; text-decoration: none; }
}

/* ---------- Diseño e impresión (stampa.php) ---------- */
[hidden] { display: none !important; }

.studio { display: grid; grid-template-columns: 430px minmax(0, 1fr); gap: 24px; align-items: start; }

.studio-panel {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 6px;
    background: #eef2ec;
    border-bottom: 1px solid var(--line);
}
.tab {
    padding: 10px 6px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font: 700 14.5px/1.15 var(--font-body);
    cursor: pointer;
}
.tab:hover { color: var(--ink); background: #e3e9e1; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(24, 58, 47, .12); }

.tab-panel { padding: 20px 22px 8px; display: flex; flex-direction: column; gap: 14px; }
.panel-title { margin: 6px 0 0; font-size: 17px; color: var(--ink); }
.panel-title:first-child { margin-top: 0; }
.panel-help { margin: -6px 0 0; font-size: 14px; color: var(--muted); }

.panel-foot {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding: 14px 22px;
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid var(--line);
}
.panel-foot .dirty { flex-basis: 100%; text-align: right; color: #8a5a00; font-weight: 700; }

/* Formati */
.format-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.format-opt { position: relative; display: grid; grid-template-columns: 30px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 10px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: #fff; }
.format-opt input { position: absolute; opacity: 0; }
.format-shape { grid-row: span 2; justify-self: center; border: 2px solid var(--ink); border-radius: 3px; background: #fff; }
.shape-a4 { width: 20px; height: 28px; }
.shape-square { width: 26px; height: 26px; }
.shape-portrait { width: 22px; height: 28px; }
.shape-story { width: 16px; height: 28px; }
.format-name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.format-opt small { font-size: 12.5px; }
.format-opt:has(input:checked) { border-color: var(--ink); background: var(--cyan-soft); box-shadow: inset 0 0 0 1px var(--ink); }
.format-opt:has(input:checked) .format-shape { background: var(--saffron); }
.format-opt:has(input:focus-visible) { outline: 3px solid var(--saffron); outline-offset: 2px; }

/* Interruttori */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 700; color: var(--ink); }
.switch input { appearance: none; -webkit-appearance: none; flex: none; order: 2; width: 46px; height: 26px; border-radius: 99px; background: #c3cdc4; position: relative; cursor: pointer; transition: background-color .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s; }
.switch input:checked { background: var(--cyan); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; }

/* Stili rapidi */
.preset-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.preset-card { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 0; border: 0; background: none; cursor: pointer; font: inherit; }
.preset-swatch { position: relative; display: grid; place-items: center; aspect-ratio: 3 / 4; border: 1.5px solid var(--line); border-radius: var(--radius-sm); }
.preset-aa { font-size: 24px; line-height: 1; }
.preset-dots { position: absolute; bottom: 7px; display: flex; gap: 4px; }
.preset-dots i { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .12); }
.preset-name { font-size: 12.5px; font-weight: 700; color: var(--ink); text-align: center; line-height: 1.15; }
.preset-card:hover .preset-swatch { border-color: var(--ink); }
.preset-card:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; border-radius: var(--radius-sm); }

/* Miniature (sfondo, logo, cornice) */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.tile-opt { position: relative; display: flex; flex-direction: column; gap: 5px; cursor: pointer; }
.tile-opt > input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.tile-thumb { position: relative; display: grid; place-items: center; aspect-ratio: 3 / 4; overflow: hidden; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-square { aspect-ratio: 1; }
.thumb-logo { background: repeating-conic-gradient(#eef1ec 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.thumb-logo img { object-fit: contain; padding: 8px; }
.thumb-none { background: #fff; }
.thumb-chalk { background: radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, .12), transparent 60%), #23302b; }
.none-x { width: 40%; height: 2px; background: #c2ccd0; transform: rotate(-45deg); }
.tile-upload .tile-thumb { border-style: dashed; background: #f3f6f1; }
.plus { font-size: 28px; color: var(--cyan); line-height: 1; }
.tile-label { font-size: 12.5px; text-align: center; color: var(--muted); line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-opt:hover .tile-thumb { border-color: var(--ink); }
.tile-opt:has(> input:checked) .tile-thumb { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.tile-opt:has(> input:checked) .tile-label { color: var(--ink); font-weight: 700; }
.tile-opt:has(> input:checked) .tile-thumb::after {
    content: "✓"; position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center; background: var(--ink); color: #fff; font-size: 12px; font-weight: 700;
}
.tile-opt:has(> input:focus-visible) .tile-thumb { outline: 3px solid var(--saffron); outline-offset: 2px; }

.mini-frame { aspect-ratio: 3 / 4; background: #fbf9f4; }
.mini-frame::before { content: ""; position: absolute; inset: 9px; }
.mf-line::before { border: 1.5px solid #8a6d3b; }
.mf-double::before { border: 4px double #8a6d3b; }
.mf-rounded::before { border: 2px solid #8a6d3b; border-radius: 9px; }
.mf-corners::before {
    background:
        linear-gradient(#8a6d3b, #8a6d3b) top left / 14px 2px, linear-gradient(#8a6d3b, #8a6d3b) top left / 2px 14px,
        linear-gradient(#8a6d3b, #8a6d3b) top right / 14px 2px, linear-gradient(#8a6d3b, #8a6d3b) top right / 2px 14px,
        linear-gradient(#8a6d3b, #8a6d3b) bottom left / 14px 2px, linear-gradient(#8a6d3b, #8a6d3b) bottom left / 2px 14px,
        linear-gradient(#8a6d3b, #8a6d3b) bottom right / 14px 2px, linear-gradient(#8a6d3b, #8a6d3b) bottom right / 2px 14px;
    background-repeat: no-repeat;
}

/* Controlli testo */
.text-group { display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #f8faf6; }
.text-group h3 { margin: 0; font-size: 15.5px; color: var(--ink); }
.text-group h3 small { font: 400 13px var(--font-body); }
.ctl-line { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ctl-line .font-select { flex: 1; min-width: 0; }
.font-sample { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; font-size: 22px; color: var(--ink); }
.color-ctl { display: inline-flex; align-items: center; gap: 8px; font-size: 14.5px; color: var(--text); cursor: pointer; }
.color-ctl input[type=color] { width: 38px; height: 38px; padding: 0; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1.5px #b9c6bb; cursor: pointer; background: none; }
.color-ctl input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color-ctl input[type=color]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.color-ctl input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }
.size-ctl { display: grid; grid-template-columns: auto 1fr 52px; align-items: center; gap: 10px; font-size: 14.5px; }
.size-ctl input[type=range] { min-height: 32px; accent-color: var(--cyan); width: 100%; }
.size-ctl output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.seg-small { width: auto; max-width: none; grid-template-columns: repeat(3, auto); border-width: 1.5px; }
.seg-small span { padding: 6px 10px; font-size: 13.5px; }
.seg-small label + label span { border-left-width: 1.5px; }
.ctl-row { display: flex; flex-direction: column; gap: 8px; }
input[type=range] { accent-color: var(--cyan); }

/* Palco dell'anteprima */
.studio-stage { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.stage-menu select { min-width: 240px; font-weight: 700; }
.stage-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stage-canvas {
    display: flex;
    justify-content: center;
    padding: clamp(16px, 3vw, 32px);
    border-radius: var(--radius);
    background: #dfe5dc radial-gradient(circle at 1px 1px, rgba(24, 58, 47, .08) 1px, transparent 0) 0 0 / 18px 18px;
}
.stage-canvas .sheet-wrap { width: 100%; margin: 0 auto; transition: max-width .2s; }
.stage-info { margin: 0; text-align: center; }

.wa-dialog { width: min(92vw, 520px); border: 0; border-radius: var(--radius); padding: 24px; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45); }
.wa-dialog::backdrop { background: rgba(24, 58, 47, .55); }
.wa-dialog h2 { margin: 0 0 12px; font-size: 22px; color: var(--ink); }
.wa-dialog textarea { font-size: 15px; background: #f3f6f1; }
.wa-dialog .actions { margin-bottom: 0; }

@media (max-width: 980px) {
    .studio { grid-template-columns: 1fr; }
    .studio-stage { position: static; order: -1; }
    .preset-grid { grid-template-columns: repeat(5, minmax(60px, 1fr)); overflow-x: auto; }
    .stage-menu, .stage-menu select { width: 100%; min-width: 0; }
}
@media (max-width: 520px) {
    .tabs { grid-template-columns: repeat(2, 1fr); }
    .tab-panel { padding: 16px 14px 6px; }
    .panel-foot { padding: 12px 14px; }
    .format-grid { grid-template-columns: 1fr; }
    .stage-actions .btn { flex: 1 1 auto; }
}
