/* ── Reset & Base ───────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #275b57;
    --primary-light: #3a7a74;
    --primary-lighter: #47b6a5;
    --primary-bg: #eef5f3;
    --accent: #47b6a5;
    --text-dark: #141414;
    --text-body: #474747;
    --text-muted: #8a8a8a;
    --bg-page: #f4f8f1;
    --bg-card: #ffffff;
    --bg-hover: #f9faf8;
    --border: #e2e6df;
    --border-focus: #275b57;
    --danger: #d44;
    --success: #3a9e6e;
    --warning: #f0a030;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(20, 20, 20, .06);
    --shadow-md: 0 4px 16px rgba(20, 20, 20, .08);
    --shadow-lg: 0 8px 32px rgba(20, 20, 20, .1);
    --transition: .2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-page);
    color: var(--text-body);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary); color: #fff; }

/* ── Header ─────────────────────────────────────────── */
.page-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, .92);
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    text-decoration: none;
    color: var(--text-dark);
    transition: opacity var(--transition);
}

.logo-link:hover { opacity: .8; }

.logo-link svg {
    height: 32px;
    width: auto;
    display: block;
}

.header-badge {
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--primary);
    background: var(--primary-bg);
    padding: .35rem .85rem;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* ── Container ──────────────────────────────────────── */
.container {
    max-width: 900px;
    margin: 2rem auto;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    padding: 0 0 2rem;
}

.page-title {
    padding: 2rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary-bg) 0%, transparent 100%);
}

.page-title h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-dark);
    letter-spacing: -.02em;
    margin-bottom: .35rem;
}

.page-title p {
    color: var(--text-muted);
    font-size: .95rem;
}

/* ── Form ───────────────────────────────────────────── */
form {
    padding: 2rem;
}

.form-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
}

.form-section h2 {
    color: var(--primary);
    font-size: 1rem;
    margin-bottom: 1.2rem;
    font-weight: 600;
    letter-spacing: -.01em;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group {
    margin-bottom: 1rem;
    position: relative;
}

label {
    display: block;
    margin-bottom: .4rem;
    color: var(--text-dark);
    font-weight: 500;
    font-size: .875rem;
}

.required {
    color: var(--danger);
    font-weight: 600;
}

input:not([type="file"]):not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100%;
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px; /* 16px per evitare zoom automatico su iOS Safari */
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text-body);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:not([type="file"]):not([type="checkbox"]):not([type="radio"]):hover,
select:hover,
textarea:hover {
    border-color: var(--primary-lighter);
}

input:not([type="file"]):not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(39, 91, 87, .1);
}

input.field-error,
input:invalid:not(:placeholder-shown) {
    border-color: var(--danger);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23275b57' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .9rem center;
    padding-right: 2.5rem;
}

small {
    display: block;
    margin-top: .4rem;
    color: var(--text-muted);
    font-size: .8rem;
}

/* ── File upload ────────────────────────────────────── */
.file-upload {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: .5rem;
    transition: border-color var(--transition), background var(--transition);
    background: var(--bg-hover);
}

.file-upload:hover {
    border-color: var(--accent);
    background: var(--primary-bg);
}

input[type="file"] {
    width: 100%;
    padding: .75rem;
    font-family: inherit;
    font-size: .875rem;
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    background: var(--primary);
    color: white;
    padding: .5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: .8rem;
    margin-right: .75rem;
    transition: background var(--transition);
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: var(--primary-light);
}

.file-list {
    margin-top: .5rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    background: var(--primary-bg);
    border-radius: 6px;
    font-size: .85rem;
}

.file-icon { font-size: 1rem; }

.file-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-dark);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: var(--text-muted);
    font-size: .8rem;
}

/* ── Buttons ────────────────────────────────────────── */
.form-actions {
    display: flex;
    gap: .75rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

button {
    padding: .85rem 2rem;
    border: none;
    border-radius: var(--radius);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn-primary {
    flex: 1;
    background: var(--primary);
    color: #fff;
    margin-left: auto;
}

.btn-primary:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-page);
    color: var(--text-body);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

/* ── Loading ────────────────────────────────────────── */
.loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin .9s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    font-size: 1rem;
    color: var(--primary);
    font-weight: 500;
}

/* ── Result ─────────────────────────────────────────── */
.result {
    padding: 3rem 2rem;
    text-align: center;
    margin: 1rem 2rem;
    border-radius: var(--radius);
}

.result.success {
    background: #e8f5ed;
    border: 1px solid #c7e5cf;
}

.result.error {
    background: #fce8e6;
    border: 1px solid #f5c5c0;
}

.result-icon {
    font-size: 3rem;
    margin-bottom: .5rem;
}

.result h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-dark);
}

.result.success h2 { color: var(--success); }
.result.error h2 { color: var(--danger); }

.result p {
    font-size: 1rem;
    margin-bottom: .75rem;
    color: var(--text-body);
}

.result .warning {
    background: #fff3cd;
    padding: .75rem 1rem;
    border-radius: 6px;
    border-left: 3px solid var(--warning);
    color: #856404;
    text-align: left;
    margin: 1rem 0;
}

.ticket-number {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    margin: 1.5rem auto;
    max-width: 300px;
    display: block;
    border-left: 4px solid var(--primary);
}

.ticket-number span {
    display: block;
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: .25rem;
}

.ticket-number strong {
    font-size: 1.25rem;
    color: var(--primary);
    font-family: 'Courier New', monospace;
}

/* ── Footer ─────────────────────────────────────────── */
.page-footer {
    text-align: center;
    padding: 2rem 1rem;
    font-size: .82rem;
    color: var(--text-muted);
    max-width: 900px;
    margin: 0 auto;
}

.page-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.page-footer a:hover { text-decoration: underline; }

/* ── Responsive (Tablet) ────────────────────────────── */
@media (max-width: 768px) {
    body { padding: 0 0 2rem; }

    .container {
        margin: 0;
        border-radius: 0;
    }

    .page-header { padding: 0 1rem; }
    .header-inner { height: 60px; }

    .logo-link svg { height: 24px; }
    .header-badge { font-size: .65rem; padding: .25rem .5rem; }

    .page-title { padding: 1.25rem; }
    .page-title h1 { font-size: 1.35rem; }
    .page-title p { font-size: .88rem; }

    form { padding: 1.25rem; }

    .form-section {
        margin-bottom: 1.5rem;
        padding-bottom: 1.25rem;
    }

    .form-section h2 {
        font-size: .95rem;
        margin-bottom: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .form-group { margin-bottom: .75rem; }

    label { font-size: .875rem; }

    input:not([type="file"]):not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        /* Touch target minimo per mobile (>= 44px iOS) */
        padding: .875rem 1rem;
        font-size: 1rem;
    }

    .result {
        margin: 1rem;
        padding: 2rem 1.25rem;
    }

    .result h2 { font-size: 1.25rem; }
    .result-icon { font-size: 2.5rem; }

    .form-actions {
        flex-direction: column-reverse;
    }

    .btn-primary { margin-left: 0; }
    .btn-secondary, .btn-primary {
        width: 100%;
        /* Touch target >= 44px */
        padding: 1rem;
    }

    .page-footer {
        padding: 1.5rem 1rem;
        font-size: .78rem;
    }
}

/* ── Responsive (Smartphone) ────────────────────────── */
@media (max-width: 480px) {
    .page-header { padding: 0 .75rem; }
    .header-inner {
        height: 54px;
        gap: .5rem;
    }
    .logo-link svg { height: 22px; }
    .header-badge {
        font-size: .6rem;
        padding: .2rem .45rem;
        letter-spacing: .04em;
    }
    .badge-dot { width: 5px; height: 5px; }

    .page-title { padding: 1rem; }
    .page-title h1 { font-size: 1.2rem; }
    .page-title p { font-size: .82rem; }

    form { padding: 1rem; }

    .form-section h2 {
        font-size: .9rem;
        margin-bottom: .9rem;
    }

    .result {
        margin: .75rem;
        padding: 1.5rem 1rem;
    }

    .ticket-number { padding: .75rem 1rem; }
    .ticket-number strong { font-size: 1.05rem; }
}

/* ── Touch device (all) ─────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    /* Disabilita hover "sticky" su touch device */
    .btn-primary:hover { transform: none; }
    .btn-primary:active {
        background: var(--primary-light);
        transform: scale(.98);
    }
    .btn-secondary:active {
        background: var(--border);
        transform: scale(.98);
    }
    input[type="file"]::-webkit-file-upload-button:active {
        background: var(--primary-light);
    }
}

/* ── Accessibility ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus outline for keyboard navigation */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
