/* Prevent unintended zoom on mobile when focusing inputs (iOS) */
input, select, textarea {
    font-size: 16px;
}

/* Ensure buttons and interactive controls also avoid zoom triggers */
button, input[type="submit"], input[type="button"], input[type="text"], input[type="password"] {
    -webkit-text-size-adjust: 100%;
}

/* Generale */
body {
        font-family: Arial, sans-serif;
        background-color: #f4f4f9;
        margin: 0;
        padding: 0;
        color: #333;
}
/* Generale */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f9;
    margin: 0;
    padding: 0;
    color: #333;
}

/* Disable native pull-to-refresh by containing overscroll at viewport */
html, body {
    overscroll-behavior-y: contain; /* prevents refresh on pull at top */
    touch-action: pan-y; /* allow vertical scroll, avoid gestures triggering refresh */
    -webkit-text-size-adjust: 100%; /* prevent unexpected zoom scaling on iOS */
}

/* Ensure internal scroll containers don't bubble overscroll to viewport */
.container,
.list-container,
.product-list,
.instances-container,
.instances-list,
.table-container {
    overscroll-behavior: contain;
}

@media (prefers-color-scheme: dark) {
    body {
        background-color: #f4f4f9 !important;
        color: #333333 !important;
    }
}

.container {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
}

.logo {
    /* Use flex centering to ensure consistent centering across pages
       (more robust than text-align for different image display modes). */
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}
.logo img {
    max-width: 150px;
    height: auto;
    display: block; /* block inside flex ensures margin auto centering works */
    margin: 0;
}

h1, h2, h3 {
    text-align: center;
    color: #333;
}

a {
    text-decoration: none;
    color: inherit;
}

a:hover {
    text-decoration: underline;
}

/* Pulsanti */
button {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #0056b3;
}

/* Manage Brands button bar */
.manage-brands-container {
    width: 100%;

/* Strong, page-specific fix: ensure product card action buttons split available
   space evenly and buttons fill their half. This overrides conflicting rules
   coming from templates or other selectors without removing them. */
.product-card .card-actions {
    width: 100% !important;
    display: flex !important;
    gap: 8px !important;
    align-items: stretch !important;
}
.product-card .card-actions > * {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}
.product-card .card-actions > form {
    display: flex !important;
    margin: 0 !important;
}
.product-card .card-actions > form button,
.product-card .card-actions > .edit-button,
.product-card .card-actions > button {
    width: 100% !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 14px !important;
    min-height: 40px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
}

/* Also apply same strong rules to .product-item (used in index.html) */
.product-item .card-actions {
    width: 100% !important;
    display: flex !important;
    gap: 8px !important;
    align-items: stretch !important;
}
.product-item .card-actions > * {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}
.product-item .card-actions > form {
    display: flex !important;
    margin: 0 !important;
}
.product-item .card-actions > form button,
.product-item .card-actions > .edit-button,
.product-item .card-actions > button {
    width: 100% !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 14px !important;
    min-height: 40px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
}
    display: flex;
    justify-content: center; /* center the inner wrapper */
    margin: 16px 0 12px 0;
}

.manage-brands-inner {
    width: 100%;
    max-width: 800px; /* match .container max width */
}

.manage-brands-btn {
    width: 100%;
    text-align: center;
    padding: 12px 16px;
}

/* Pulsanti nella barra gestione: usare lo stile dei pulsanti "Modifica prodotto" */
.manage-brands-inner .edit-button,
.manage-action.edit-button {
    min-height: 44px; /* maggiore altezza visibile rispetto a prima */
    padding: 10px 18px; /* spazio interno ripristinato e un po' più largo */
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0,0,0,0.06);
    background: linear-gradient(180deg, #0d73e0 0%, #0b67d0 100%); /* gradiente per cambiamento visivo */
    color: #fff;
    cursor: pointer;
    font-size: 15px; /* leggermente più grande per maggiore leggibilità */
    font-weight: 700; /* spessore del testo come richiesto */
    line-height: 1;
    transition: background 140ms ease, transform 90ms ease, box-shadow 120ms ease;
    flex: 1; /* mantiene comportamento di estensione orizzontale */
    box-shadow: 0 2px 6px rgba(11,103,208,0.12);
}
.manage-brands-inner .edit-button:hover,
.manage-action.edit-button:hover {
    background: linear-gradient(180deg, #0b5ec8 0%, #0954a8 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(11,103,208,0.18);
}
.manage-brands-inner .edit-button:active,
.manage-action.edit-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.manage-brands-inner .edit-button:focus,
.manage-action.edit-button:focus {
    outline: 3px solid rgba(11,103,208,0.16);
    outline-offset: 2px;
}

/* Regole molto specifiche per forzare l'aspetto dei pulsanti nella barra di gestione
   Usano ID/class per avere priorità su possibili stili inline o generici. */
.manage-brands-inner #manage-brands-btn,
.manage-brands-inner #add-product-btn,
.manage-brands-inner .manage-brands-btn {
    min-height: 44px !important;
    padding: 10px 18px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    background: linear-gradient(180deg, #0d73e0 0%, #0b67d0 100%) !important;
    color: #fff !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 6px rgba(11,103,208,0.12) !important;
}

.manage-brands-inner .edit-button:hover,
.manage-action.edit-button:hover {
    background: #0954a8;
    transform: translateY(-1px);
}

/* rely on .submit-button hover/active colors */

.home-button, .logout-button {
    position: absolute;
    top: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.home-button {
    left: 20px;
    background-color: #007bff;
}

.home-button:hover {
    background-color: #0056b3;
}

.logout-button {
    right: 20px;
    background-color: #ff4d4d;
}

.logout-button:hover {
    background-color: #cc0000;
}

.home-button svg, .logout-button svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Tabelle */
table {
    width: 100%; /* Mantiene la tabella al 100% del contenitore */
    border-collapse: collapse;
    margin-bottom: 20px;
    table-layout: auto; /* Permette alle colonne di adattarsi al contenuto */
}

table th, table td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: center;
    font-size: 14px;
    word-wrap: break-word; /* Permette di andare a capo nelle celle */
    max-width: 2400px; /* Imposta una larghezza massima per le colonne */
}

table th {
    background-color: #007bff;
    color: white;
}

table td {
    white-space: normal; /* Permette al testo di andare a capo */
    overflow: visible; /* Rimuove il taglio del testo */
    text-overflow: clip; /* Mostra tutto il contenuto senza "..." */
}

/* Thumbnail / table images: keep small to avoid layout blowout in tables/lists */
table img,
.product-image img,
.instances-list img,
.product-list img {
    max-width: 50px;
    height: auto;
    border-radius: 4px;
}

/* Moduli */
form {
    margin-bottom: 20px;
}

input[type="text"], input[type="file"], select {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px; /* prevent iOS auto-zoom on focus */
    box-sizing: border-box;
}

/* Also ensure other text-input types use 16px to avoid zoom */
input[type="password"], input[type="email"], input[type="search"], input[type="number"], textarea {
    font-size: 16px;
}

input[type="file"] {
    display: none;
}

.submit-button {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.submit-button:hover {
    background-color: #0056b3;
}

/* Primary button used in header/profile actions: keep same visual but don't force full width inside .actions */
.primary-btn {
    padding: 10px 14px;
    background-color: #0b67d0;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.actions .submit-button {
    width: auto; /* allow buttons in .actions to sit inline */
}

/* Flash Messages */
.flash-messages {
    list-style: none;
    padding: 0;
    margin: 10px 0;
}

.flash-messages li {
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 4px;
}

.flash-messages .success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.flash-messages .warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}


/* Media Queries */
@media (max-width: 768px) {
    table th, table td {
        padding: 8px; /* Riduce il padding per dispositivi mobili */
        font-size: 16px; /* Riduce ulteriormente il font per schermi piccoli */
    }
    table th {
        white-space: nowrap; /* Impedisce che il testo nelle intestazioni vada a capo */
    }
    table td {
        white-space: nowrap; /* Impedisce che il testo nelle celle vada a capo */
        overflow: hidden;
        text-overflow: ellipsis; /* Mostra "..." per i testi troppo lunghi */
    }
    .sort-button {
        font-size: 14px;
        padding: 4px;
    }
    img {
        max-width: 40px; /* Riduce ulteriormente le immagini per schermi piccoli */
    }
    th:nth-child(1),
    td:nth-child(1) {
        min-width: 70px;
        max-width: 150px;
        width: 90px;
        overflow: scroll;
        text-overflow: clip;
        white-space: nowrap;
    }
}

/* Pull-To-Refresh (PTR) overlay styles */
#pull-to-refresh-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transform: translateY(-100%);
    transition: transform 180ms ease, opacity 180ms ease;
    opacity: 0;
    z-index: 9999;
}

/* Quando l'overlay è inserito dentro .container usiamo posizionamento assoluto */
#pull-to-refresh-overlay.inside-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    /* Manteniamo lo stesso height/transform/transition definiti sopra */
}

#pull-to-refresh-overlay .ptr-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    color: #007bff;
    font-size: 18px;
    line-height: 1;
    transform-origin: center center;
    transition: transform 180ms ease, opacity 180ms ease;
}

#pull-to-refresh-overlay.refreshing .ptr-spinner {
    animation: ptr-rotate 900ms linear infinite;
    transform: scale(1.05);
}

@keyframes ptr-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@media (prefers-color-scheme: dark) {
    #pull-to-refresh-overlay .ptr-spinner {
        background: rgba(30, 30, 30, 0.9);
        color: #9fd3ff;
        box-shadow: 0 2px 6px rgba(0,0,0,0.6);
    }
}

/* Modal / Overlay for edit and add-instance forms */
.modal-backdrop {
    position: fixed; /* iOS: fixed to viewport */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000; /* above all content */
    /* Respect iOS safe areas to avoid clipping */
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    height: 100dvh; /* iOS Safari: dynamic viewport height */
    width: 100%; /* avoid 100vw causing overflow on iOS PWAs */
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden; /* clamp horizontal overflow in iOS PWA */
}

.modal-container {
    background: #fff;
    border-radius: 10px;
    width: 100%;
    max-width: 800px; /* align with main container */
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    max-height: 90dvh; /* iOS dynamic viewport */
    overflow: auto;
    overflow-x: hidden; /* prevent right-side spill */
    padding: clamp(12px, 3vw, 20px); /* reduce padding on tiny screens */
    position: fixed; /* fix to viewport to avoid parent layout issues */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin: 0; /* center via transform */
    box-sizing: border-box; /* include padding in width calc */
    overflow-wrap: anywhere; /* prevent long strings from causing overflow */
}

/* iOS PWA: guard against sub-pixel overflow by constraining inline size */
.modal-container {
    inline-size: min(100%, 800px);
}

.modal-container.card-like {
    border: 1px solid #e9e9e9;
    background: #ffffff;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.modal-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #0b67d0;
}

.modal-subtitle {
    font-size: 13px;
    color: #555;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #333;
}

/* Improve form readability inside modal */
.modal-container h3.modal-title {
    margin: 0 36px 12px 0; /* leave space for close button */
    font-size: 18px;
    font-weight: 700;
    color: #203244;
}

.modal-container form {
    width: 100%;
}

.modal-container .edit-row {
    gap: 12px;
    align-items: flex-start;
}

.modal-container .edit-row label,
.modal-container .edit-row input,
.modal-container .edit-row select,
.modal-container .edit-row button {
    margin-bottom: 8px; /* override negative margins from inline form */
}

.modal-container .edit-row input,
.modal-container .edit-row select {
    padding: 10px;
    border: 1px solid #dfe6ef;
    border-radius: 6px;
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}

.modal-container .submit-button,
.modal-container button[type="submit"],
.modal-container .delete-button {
    width: auto; /* buttons shouldn't stretch full width in modal */
    height: 36px;
    padding: 6px 12px;
    border-radius: 6px;
}

/* Ensure inline card action buttons are aligned and same size.
   Do not force flex or use !important here so page-specific
   rules (e.g. product card layout) can control expansion. */
.card-actions .submit-button,
.card-actions .delete-button,
.card-actions button,
.card-actions input[type="submit"] {
    width: auto;
    height: 36px;
    padding: 6px 12px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #dfe6ef;
    font-size: 14px;
    line-height: 1;
}
.card-actions .submit-button {
    background-color: #0b67d0;
    color: #fff;
    border: 1px solid transparent;
}
.card-actions .delete-button {
    background-color: #c02b2b;
    color: #fff;
    border: 1px solid transparent;
}

@media (max-width: 768px) {
    .modal-container { width: 100%; max-width: 100%; padding: clamp(10px, 3vw, 16px); }
    .modal-title { font-size: 18px; }
    .modal-container .edit-row { gap: 10px; }
}

.modal-container .submit-button,
.modal-container button[type="submit"] {
    width: auto; /* buttons shouldn't stretch full width in modal */
}

@media (max-width: 600px) {
    .modal-container { padding: 12px; border-radius: 8px; }
}

/* Prevent body from scrolling when modal open */
.modal-open {
    overflow: hidden; /* applied to body when modal is open via JS */
    touch-action: none; /* iOS: prevent background scroll */
    overflow-x: hidden; /* prevent horizontal scroll while modal open */
}

/* Inline modal that appears inside a product card (sul posto) */
.inline-modal-backdrop {
    position: absolute;
    inset: 0 auto auto 0; /* allow height auto, align to top-left of product card */
    background: rgba(0,0,0,0.15);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 9999;
    padding: 8px;
}

.inline-modal-container {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 680px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
    padding: 12px;
    max-height: 85vh;
    overflow: auto;
}

.inline-modal-backdrop .modal-close {
    color: #222;
}

/* Ensure inner elements never exceed modal width */
.modal-container *,
.inline-modal-container * {
    max-width: 100%;
    box-sizing: border-box;
}

