@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --ink: #16232E;
    --paper: #F7F4EC;
    --paper-raised: #FFFFFF;
    --mare: #1E6E64;
    --mare-soft: #E4EFEC;
    --login-blue: #3D4C8C;
    --monti: #6B4A2F;
    --monti-soft: #EFE8DE;
    --line: #DED7C6;
    --danger: #B3392C;
    --shadow: 0 1px 2px rgba(22,35,46,0.06), 0 4px 12px rgba(22,35,46,0.06);
    --radius: 10px;
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
}

button {
    font-family: var(--font-body);
    cursor: pointer;
}

a {
    color: inherit;
}

/* --- App shell --- */

#topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--ink);
    color: var(--paper);
}

    #topbar .brand {
        font-family: var(--font-display);
        font-size: 1.15rem;
        font-weight: 600;
        display: flex;
        align-items: baseline;
        gap: 6px;
    }

        #topbar .brand small {
            font-family: var(--font-body);
            font-size: 0.7rem;
            opacity: 0.6;
            font-weight: 400;
        }

    #topbar button.icon-btn {
        background: none;
        border: none;
        color: var(--paper);
        font-size: 1rem;
        padding: 6px 10px;
        border-radius: 999px;
        opacity: 0.85;
    }

        #topbar button.icon-btn:hover {
            background: rgba(247,244,236,0.12);
        }

#view {
    flex: 1;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 0 100px;
}

/* --- Container Responsivo per schermate --- */
.app-container {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: 0 16px 24px;
    box-sizing: border-box;
    font-family: var(--font-body, sans-serif);
    color: var(--ink, #111);
}

@media (min-width: 768px) {
    .app-container {
        max-width: 880px;
        padding: 0 24px 32px;
    }
}

@media (min-width: 1024px) {
    .app-container {
        max-width: 1100px;
        padding: 0 32px 40px;
    }
}

/* --- Wave divider: signature element between Mare / Monti --- */

.section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 28px 0 14px;
}

    .section-divider svg {
        flex: 1;
        height: 10px;
        width: 100%;
    }

    .section-divider.mare svg path {
        stroke: var(--mare);
    }

    .section-divider.monti svg path {
        stroke: var(--monti);
    }

    .section-divider .label {
        font-family: var(--font-display);
        font-size: 0.95rem;
        font-weight: 600;
        white-space: nowrap;
    }

    .section-divider.mare .label {
        color: var(--mare);
    }

    .section-divider.monti .label {
        color: var(--monti);
    }

/* --- Cards / lists --- */

.card {
    background: var(--paper-raised);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

/* --- SOLO IL MENU: griglia verticale pulita --- */
#products-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

    #products-container .product-row {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 14px 16px !important;
        background: var(--paper-raised) !important;
        border-radius: var(--radius) !important;
        box-shadow: var(--shadow) !important;
        border: 1px solid var(--line) !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #products-container .product-info {
        flex: 1 !important;
        min-width: 0 !important;
    }

        #products-container .product-info .name {
            font-weight: 600 !important;
            font-size: 0.95rem !important;
            text-transform: uppercase !important;
            color: var(--ink) !important;
        }

        #products-container .product-info .desc {
            font-size: 0.8rem !important;
            color: #5b6a74 !important;
            margin-top: 2px !important;
        }

        #products-container .product-info .price {
            font-size: 0.85rem !important;
            margin-top: 4px !important;
            color: var(--ink) !important;
            font-weight: 500 !important;
        }

    #products-container .qty-control {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }

        #products-container .qty-control button {
            width: 30px !important;
            height: 30px !important;
            border-radius: 8px !important;
            border: 1px solid var(--line) !important;
            background: var(--paper) !important;
            font-size: 1rem !important;
            line-height: 1 !important;
            color: var(--ink) !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
        }

            #products-container .qty-control button:active {
                background: var(--line) !important;
            }

        #products-container .qty-control .qty {
            min-width: 18px !important;
            text-align: center !important;
            font-weight: 600 !important;
        }

        /* Selettori qty-control alla stessa altezza del testo PRODOTTI */
        #qty-selector-row {
            display: flex;
            gap: 4px;
            align-items: center;
            padding: 0;
            min-height: 32px;
        }

        .qty-control {
            min-width: 32px;
            text-align: center;
        }

        .qty-control button {
            width: 32px !important;
            height: 32px !important;
            border-radius: 8px !important;
            border: 1px solid var(--line) !important;
            background: var(--paper) !important;
            font-size: 1rem !important;
            line-height: 1 !important;
            color: var(--ink) !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
        }

            .qty-control button:active {
                background: var(--line) !important;
            }

        .qty-control .qty {
            min-width: 18px !important;
            text-align: center !important;
            font-weight: 600 !important;
        }

        /* Selezionatore attivo - giallo */
        #qty-selector-row .qty-control.selected,
        .qty-control.selected {
            background: #faf089 !important;
            color: #1a2a3a !important;
        }

        #qty-selector-row .qty-control.selected button,
        .qty-control.selected button {
            background: #faf089 !important;
            color: #1a2a3a !important;
        }

        /* Stile diretto sui pulsanti qty-control (button class="qty-control") */
        .qty-control[data-qty] {
            width: 32px !important;
            height: 32px !important;
            border-radius: 8px !important;
            border: 1px solid var(--line) !important;
            background: var(--paper) !important;
            font-size: 1rem !important;
            line-height: 1 !important;
            color: var(--ink) !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            cursor: pointer !important;
            transition: background 0.15s, transform 0.1s !important;
        }

            .qty-control[data-qty]:active {
                background: var(--line) !important;
                transform: scale(0.94) !important;
            }

            /* Selected state keeps yellow on active press */
            .qty-control[data-qty].selected:active {
                background: #faf089 !important;
            }


.field {
    margin-bottom: 14px;
}

    .field label {
        display: block;
        font-size: 0.82rem;
        font-weight: 600;
        margin-bottom: 6px;
        color: #3b4a54;
    }

    .field input {
        width: 100%;
        padding: 12px 14px;
        border-radius: 8px;
        border: 1px solid var(--line);
        background: var(--paper-raised);
        font-family: var(--font-body);
        font-size: 0.95rem;
        color: var(--ink);
    }

        .field input:focus {
            outline: 2px solid var(--mare);
            outline-offset: 1px;
        }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 13px 18px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.95rem;
    background: var(--ink);
    color: var(--paper);
}

    .btn:active {
        opacity: 0.85;
    }

    .btn.secondary {
        background: transparent;
        color: var(--ink);
        border: 1px solid var(--line);
    }

    .btn.danger {
        background: var(--danger);
    }

    .btn:disabled {
        opacity: 0.5;
    }

/* --- Login screen --- */

.login-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 0 28px;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    box-sizing: border-box;
}

    .login-wrap .login-body {
        padding: 24px 24px 0;
        text-align: center;
    }

    .login-wrap .headline {
        font-family: var(--font-display);
        font-size: 2rem;
        font-weight: 700;
        color: var(--login-blue);
        margin-bottom: 6px;
    }

    .login-wrap .sub {
        color: #5b6a74;
        font-size: 1rem;
        margin-bottom: 24px;
    }

    .login-wrap form {
        text-align: left;
    }

.login-logo-container {
    text-align: center;
    padding: 22px 16px 18px;
}

    .login-logo-container img {
        max-width: 320px;
        width: 100%;
        height: auto;
        object-fit: contain;
    }

.login-hero {
    width: 100%;
    height: 170px;
    object-fit: cover;
    display: block;
    margin: 0 0 26px;
}

.login-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper-raised);
    padding: 0 14px;
}

    .login-input-wrapper .login-icon {
        margin-right: 10px;
        font-size: 1.15rem;
        opacity: 0.75;
    }

    .login-input-wrapper input {
        border: none;
        background: transparent;
        padding: 15px 0;
        width: 100%;
        outline: none;
        font-family: var(--font-body);
        font-size: 1rem;
        color: var(--ink);
    }

    .login-input-wrapper #toggle-password {
        background: none;
        border: none;
        cursor: pointer;
        font-size: 1.15rem;
        padding: 4px;
    }

.login-options-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 18px 0 24px 0;
    font-size: 0.9rem;
}

    .login-options-row label {
        display: flex;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        font-weight: 400;
        color: var(--ink);
    }

    .login-options-row input[type="checkbox"] {
        width: 18px;
        height: 18px;
        margin: 0;
        accent-color: var(--login-blue);
    }

.login-forgot-btn {
    background: none;
    border: none;
    color: var(--login-blue);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}

    .login-forgot-btn:hover {
        text-decoration: underline;
    }

.login-btn {
    background: var(--login-blue) !important;
    border-radius: 10px !important;
    padding: 16px !important;
    font-size: 1rem !important;
}

.login-footer {
    background: var(--mare-soft);
    color: #5b6a74;
    text-align: center;
    font-size: 0.78rem;
    line-height: 1.5;
    padding: 16px 24px;
    margin-top: 28px;
}

body:has(.login-wrap) #topbar {
    display: none !important;
}

body:has(.login-wrap) #view {
    max-width: 100%;
    padding: 0;
}

.login-wrap img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* --- Schermata Clienti & Ricerca --- */

#clients-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 768px) {
    #clients-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
}

.clients-header {
    margin-bottom: 16px;
}

.search-box {
    position: relative;
    margin-bottom: 16px;
}

    .search-box input {
        width: 100%;
        padding: 12px 14px 12px 40px;
        border-radius: 8px;
        border: 1px solid var(--line);
        background: var(--paper-raised);
        font-family: var(--font-body);
        font-size: 0.95rem;
        color: var(--ink);
    }

        .search-box input:focus {
            outline: 2px solid var(--mare);
            outline-offset: 1px;
        }

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    opacity: 0.5;
}

.client-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: var(--paper-raised);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 0;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    border: 1px solid var(--line);
}

    .client-card:hover {
        border-color: var(--mare);
        box-shadow: 0 4px 12px rgba(22,35,46,0.08);
    }

    .client-card .name {
        font-weight: 600;
        font-size: 1rem;
        color: var(--ink);
    }

    .client-card .addr {
        font-size: 0.82rem;
        color: #5b6a74;
        margin-top: 3px;
    }

.badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

    .badge.ordered {
        background: var(--mare-soft);
        color: var(--mare);
    }

    .badge.pending {
        background: #EFE3DD;
        color: #9C5A3C;
    }

/* --- Lista Prodotti & Card Prodotto --- */

#products-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

@media (min-width: 768px) {
    #products-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
}

.product-item-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    padding: 14px 16px;
    border: 1px solid #e2e8f0;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.2s ease;
    gap: 12px;
}

.product-item-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.product-item-card.is-selected {
    background: #f0fdf4;
    border-color: #10b981;
}

.product-item-card .prod-info {
    flex: 1;
    min-width: 0;
}

.product-item-card .prod-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: #111;
    text-transform: uppercase;
    line-height: 1.35;
    word-break: break-word;
}

.product-item-card .prod-code {
    font-size: 0.8rem;
    color: #777;
    margin-top: 4px;
}

.product-item-card .prod-code .prod-price {
    color: #00838f;
    font-weight: 700;
}

.product-item-card .prod-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.product-item-card .prod-actions button {
    background: #eef2f5;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, transform 0.1s;
}

.product-item-card .prod-actions button:hover {
    background: #dfe6eb;
    transform: scale(1.06);
}

.product-item-card .prod-actions button:active {
    transform: scale(0.94);
}

.product-item-card .prod-badge {
    font-size: 0.75rem;
    font-weight: bold;
    background: #10b981;
    color: #fff;
    padding: 3px 8px;
    border-radius: 8px;
    margin-right: 4px;
    white-space: nowrap;
}

/* --- Bottom cart bar --- */

#cartbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--ink);
    color: var(--paper);
    padding: 12px 20px;
    display: none;
    z-index: 20;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
}

    #cartbar.visible {
        display: block;
    }

    #cartbar .cartbar-content {
        max-width: 1100px;
        margin: 0 auto;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    #cartbar .info {
        font-size: 0.9rem;
        opacity: 0.9;
        font-weight: 500;
    }

    #cartbar .total {
        font-family: var(--font-display);
        font-weight: 600;
        font-size: 1.1rem;
    }

    #cartbar button {
        background: var(--mare);
        color: white;
        border: none;
        padding: 10px 20px;
        border-radius: 8px;
        font-weight: 600;
        font-size: 0.95rem;
        transition: background 0.2s;
    }

        #cartbar button:hover {
            background: #17574f;
        }

    /* Vai al carrello button: grows to fill remaining space */
    #cartbar .cart-gotocart-btn {
        flex: 1;
        min-width: 120px;
    }

/* --- Utility --- */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #5b6a74;
}

    .empty-state h3 {
        color: var(--ink);
        margin-bottom: 6px;
    }

.error-msg {
    background: #FBEAE7;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 14px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #5b6a74;
    font-size: 0.9rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: #5b6a74;
    margin-bottom: 14px;
    background: none;
    border: none;
    padding: 0;
}
/* --- CORRETTA VISUALIZZAZIONE VERTICALE DETTAGLIO ORDINE / LISTA PRODOTTI --- */

/* Assicura che il contenitore principale dei dettagli ordine sia a colonna */
#view .card, .order-details-container, .cart-items-list {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    width: 100% !important;
    overflow-x: visible !important;
}

    /* Ogni riga di prodotto all'interno dei dettagli ordine deve stare in colonna, una sotto l'altra */
    #view .card .product-row,
    .order-product-row {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
        padding: 12px 0 !important;
        border-bottom: 1px solid var(--line) !important;
        box-sizing: border-box !important;
    }

        #view .card .product-row:last-child {
            border-bottom: none !important;
        }
