/* ==========================================================================
   FOGLIO DI STILE DEDICATO: PANNELLO ADMIN (Stile Tech Dashboard Dark)
   Variabili, reset, navbar base, form e modale condivisi: vedi css/main.css
   ========================================================================== */


.nav-container {
    max-width: 1400px;
}

/* Layout Principale Dashboard */
.admin-container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 110px 0 40px 0;
}

/* Action Bar Superiore */
.action-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 24px;
}

.btn-primary {
    background-color: var(--accent-neon);
    color: var(--text-white);
    border: none;
    border-radius: 10px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(255, 71, 71, 0.3);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Form Sections e Griglie */
.form-panel,
.qr-panel {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 28px;
}

/* Bottone Submit: solo le differenze rispetto a main.css (full-width, click feedback) */
.btn-submit {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 14px;
    margin-top: 12px;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.btn-submit:active {
    transform: scale(0.99);
}

/* Pannello QR */
.qr-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.qr-panel .panel-header {
    width: 100%;
    text-align: left;
}

.qr-preview-box {
    width: 100%;
    min-height: 240px;
    border: 2px dashed var(--border-color);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.01);
    margin-bottom: 20px;
}

#qrcode img,
#qrcode canvas {
    border: 8px solid #ffffff;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.qr-placeholder-text {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 220px;
    line-height: 1.5;
}

.url-output-box {
    width: 100%;
    text-align: left;
}

.url-copy-wrapper {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.url-copy-wrapper input {
    flex-grow: 1;
    background-color: var(--input-bg);
    font-size: 13px;
    color: var(--text-muted);
}

.url-copy-wrapper button {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-white);
    padding: 0 16px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.2s ease;
}

.url-copy-wrapper button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-download {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-white);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border-radius: 10px;
    margin-top: 14px;
    transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.btn-download:hover {
    background-color: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 71, 71, 0.4);
    transform: translateY(-2px);
}

/* Modale: admin usa display:none/flex via JS invece dell'attributo hidden, vedi main.css per il resto */
.modal {
    display: none;
}

.modal-content {
    max-width: 980px;
}

.modal-grid {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 24px;
    margin-top: 10px;
}

.close-button {
    z-index: 10;
}

/* Sezione Archivio e Ricerca Report */
.reports-section {
    margin-top: 32px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
}

.reports-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 28px;
}

.reports-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.reports-header p {
    font-size: 14px;
    color: var(--text-muted);
}

.search-box input {
    min-width: 280px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-white);
    font-size: 14px;
}

/* Griglia delle Schede Report */
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.report-card {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.report-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 71, 71, 0.3);
}

.report-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.report-badge-id {
    background-color: rgba(255, 71, 71, 0.15);
    color: var(--accent-neon);
    font-weight: 700;
    font-size: 14px;
    padding: 4px 10px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

.report-date {
    font-size: 12px;
    color: var(--text-muted);
}

.report-card-body h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.report-card-body p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
    line-height: 1.4;
}

.report-card-footer {
    margin-top: 16px;
    display: flex;
    gap: 8px;
}

.report-card-footer .btn-select-report {
    flex: 1;
}

.btn-delete-report {
    flex: 0 0 auto;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0 14px;
    font-size: 15px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-delete-report:hover {
    background-color: rgba(255, 71, 71, 0.15);
    border-color: var(--accent-neon);
}

.btn-select-report {
    width: 100%;
    display: block;
    box-sizing: border-box;
    text-align: center;
    text-decoration: none;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-white);
    padding: 10px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-select-report:hover {
    background-color: rgba(255, 71, 71, 0.1);
    border-color: var(--accent-neon);
    color: var(--accent-neon);
}

.no-reports {
    grid-column: 1 / -1;
    color: var(--text-muted);
    text-align: center;
    padding: 32px;
    font-size: 14px;
}

/* Responsiveness */
@media (max-width: 850px) {
    .modal-grid {
        grid-template-columns: 1fr;
    }

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

    .modal-content {
        padding: 20px;
    }
}

@media (max-width: 550px) {
    .admin-container {
        padding: 90px 16px 24px 16px;
    }

    .reports-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-box input {
        width: 100%;
        min-width: unset;
    }
}

/* ==========================================================================
   LOGIN ADMIN
   ========================================================================== */
/* Finché non autenticato: dashboard nascosta e login visibile */
html:not(.is-auth) nav,
html:not(.is-auth) .admin-container {
    display: none;
}

html.is-auth .login-screen {
    display: none;
}

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(255, 71, 71, 0.12), transparent 60%),
        var(--bg-main);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background-color: var(--bg-nav);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 36px 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    animation: modalFadeIn 0.25s ease-out;
}

.login-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.login-logo img {
    max-width: 100%;
    height: auto;
}



.login-card h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 16px 0 6px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-white);
    margin-bottom: 24px;
}

.login-error {
    font-size: 13px;
    color: var(--accent-neon);
    background-color: rgba(255, 71, 71, 0.08);
    border: 1px solid rgba(255, 71, 71, 0.25);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 4px;
}

.login-error[hidden] {
    display: none;
}

.btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-card.shake {
    animation: loginShake 0.35s ease;
}

@keyframes loginShake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    75% {
        transform: translateX(8px);
    }
}

/* Navbar: azioni a destra + logout */
.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-logout {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-white);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: 100px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn-logout:hover {
    background-color: rgba(255, 71, 71, 0.1);
    border-color: var(--accent-neon);
    color: var(--accent-neon);
}

@media (max-width: 550px) {
    .login-card {
        padding: 28px 20px;
    }
}


/* ==========================================================================
   OTTIMIZZAZIONE MOBILE (vedi main.css per le regole condivise)
   ========================================================================== */
@media (max-width: 850px) {

    /* iOS ingrandisce la pagina al focus se il font dell'input è < 16px */
    input,
    textarea,
    select,
    .search-box input {
        font-size: 16px;
    }

    .login-screen {
        min-height: 100dvh;
    }
}

@media (max-width: 600px) {
    nav {
        padding-top: env(safe-area-inset-top);
        box-sizing: content-box;
    }

    .btn-logout {
        min-height: 44px;
        padding: 0 18px;
    }

    .admin-container {
        padding: calc(88px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)) 16px;
    }

    /* "Nuovo Report" a tutta larghezza, facile da raggiungere col pollice */
    .admin-grid .action-bar {
        justify-content: stretch !important;
        margin-bottom: 16px !important;
    }

    .admin-grid .action-bar .btn-primary {
        width: 100%;
        justify-content: center;
        min-height: 52px;
        font-size: 16px;
    }

    .reports-section {
        margin-top: 16px;
        padding: 20px 16px;
        border-radius: 16px;
    }

    .reports-header {
        gap: 14px;
        margin-bottom: 18px;
    }

    .reports-header h2 {
        font-size: 20px;
    }

    .search-box,
    .search-box input {
        width: 100%;
        min-width: 0;
    }

    .search-box input {
        min-height: 48px;
    }

    .reports-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .report-card {
        padding: 16px;
    }

    .btn-select-report {
        padding: 14px 10px;
        font-size: 14px;
    }

    /* Modale a schermo intero */
    .modal {
        align-items: stretch;
    }

    .modal-content .form-panel,
    .modal-content .qr-panel {
        background: transparent;
        border: none;
        padding: 0;
    }

    /* Salva sempre raggiungibile mentre si scorre il modulo */
    .modal-content .btn-submit {
        position: sticky;
        bottom: 0;
        min-height: 52px;
        font-size: 16px;
        box-shadow: 0 -12px 16px 0 #13131a;
    }

    .login-card h1 {
        font-size: 22px;
    }

    .login-card .btn-submit {
        min-height: 52px;
        font-size: 16px;
    }
}

.qr-success-content {
    max-width: 380px;
    text-align: center;
}

.qr-success-content .qr-container {
    display: flex;
    justify-content: center;
    padding: 1rem;
    background: #fff;
}

.qr-plate {
    font-weight: 700;
    font-size: 1.2rem;
    margin: .5rem 0 0;
}

.qr-url {
    font-size: .8rem;
    word-break: break-all;
    opacity: .7;
}

.qr-actions {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-top: 1rem;
}
/* ==========================================================================
   STAMPA QR: in stampa compare solo #print-qr-sheet (vedi printQR in admin.js)
   Pensato per adesivi piccoli: logo, QR e targa alla stessa larghezza (la massima che sta in una pagina),
   testo su due righe in fondo.
   ========================================================================== */
#print-qr-sheet {
  display: none;
}

@media print {
  @page {
    margin: 2mm;
  }

  body > *:not(#print-qr-sheet) {
    display: none !important;
  }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  /* Logo, QR e targa hanno tutti la stessa larghezza (quella del foglio),
     ridotta solo se serve perché tutto stia in una pagina. Spazi e testo sono
     in cqw (% della larghezza del foglio), così le proporzioni restano uguali
     a qualsiasi formato e --stack-ratio (altezza/larghezza) vale sempre. */
  #print-qr-sheet {
    display: block !important;
    container-type: inline-size;
    width: min(100%, calc(96vh / var(--stack-ratio, 1.8)));
    margin: 0 auto;
    text-align: center;
    color: #000;
    font-family: Arial, sans-serif;
  }

  #print-qr-sheet .print-logo,
  #print-qr-sheet .print-qr,
  #print-qr-sheet .print-plate {
    display: block;
    width: 100%;
    height: auto;
  }

  #print-qr-sheet .print-logo {
    margin-bottom: 4cqw;
  }

  #print-qr-sheet .print-plate {
    margin-top: 2cqw;
  }

  #print-qr-sheet .print-hint {
    font-size: 11px;
    font-size: 5.6cqw;
    font-weight: 600;
    line-height: 1.25;
    margin: 2cqw 0 0;
  }
}
