/* ========== RESET & BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: transparent;
    min-height: 100vh;
    padding: 20px;
}

#_fixedBg {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: -999;
    pointer-events: none;
    background: linear-gradient(135deg, #2196F3 0%, #0D2B5B 100%);
}

/* ========== LOGO HEADER ========== */
.app-logo-header {
    position: fixed;
    top: 6px;
    left: 12px;
    z-index: 200;
    pointer-events: none;
}
.app-logo-header img {
    max-height: 46px;
    max-width: 160px;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
}
.app-logo-topbar {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.app-logo-topbar img {
    max-height: 22px;
    max-width: 60px;
    object-fit: contain;
}
#topBar {
    background: linear-gradient(to bottom, #ffffff 55%, rgba(255,255,255,0)) !important;
    box-shadow: none !important;
}

/* ========== CONTAINER ========== */
.container {
    max-width: 600px;
    margin: 20px auto;
    background: var(--card-bg, white);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

h2 {
    color: var(--heading-color, #333);
    margin-bottom: 20px;
    text-align: center;
}

h3 {
    color: #555;
    margin: 20px 0 10px;
}

hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 20px 0;
}

/* ========== FORM ELEMENTS ========== */
label {
    display: block;
    margin-top: 15px;
    margin-bottom: 5px;
    color: #555;
    font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 12px;
    margin: 5px 0;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border 0.3s;
}

input:focus,
select:focus {
    outline: none;
    border-color: #2196F3;
}

/* ========== BUTTONS ========== */
button {
    padding: 12px 24px;
    margin: 10px 5px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

button:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--btn-primary-bg, #2196F3);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    filter: brightness(1.15);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-large {
    width: 100%;
    padding: 20px;
    font-size: 18px;
    margin: 10px 0;
    background: var(--btn-gradient, linear-gradient(135deg, #2196F3 0%, #0D2B5B 100%));
    color: white;
}

.btn-remove {
    background: #dc3545;
    color: white;
    padding: 8px 16px;
}

.btn-remove:hover {
    background: #c82333;
}

/* ========== USER INFO ========== */
.user-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.user-info p {
    margin: 5px 0;
    color: #555;
}

/* ========== NAVIGATION ========== */
.main-actions {
    margin: 20px 0;
}

.nav-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-buttons button {
    flex: 1;
    min-width: 120px;
}

/* ========== ADMIN SECTION ========== */
.admin-section {
    background: #fff3cd;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #ffc107;
}

.admin-form {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

/* ========== PRODUCT INFO ========== */
.product-info {
    margin: 20px 0;
    min-height: 60px;
}

.product-found {
    background: #d4edda;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #28a745;
}

.product-found p {
    margin: 5px 0;
    text-align: left;
}

.scan-input {
    margin: 20px 0;
}

/* ========== LISTS ========== */
.products-list,
.list {
    margin: 20px 0;
}

.product-item,
.list-item {
    background: #f8f9fa;
    padding: 15px;
    margin: 10px 0;
    border-radius: 8px;
    border-left: 4px solid #2196F3;
    text-align: left;
    overflow: hidden;
}

/* ========== CART ========== */
.cart-items {
    margin: 20px 0;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    padding: 15px;
    margin: 10px 0;
    border-radius: 8px;
    border-left: 4px solid #28a745;
}

.cart-item-info {
    flex: 1;
    text-align: left;
}

.cart-item-qty {
    display: inline-block;
    background: #2196F3;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    margin: 0 10px;
    font-size: 12px;
}

.cart-item-type {
    display: inline-block;
    background: #28a745;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
}

.cart-actions {
    display: flex;
    gap: 10px;
}

.cart-actions button {
    flex: 1;
}

/* ========== MESSAGES ========== */
.error {
    color: #dc3545;
    background: #f8d7da;
    padding: 10px;
    border-radius: 5px;
    margin: 10px 0;
}

/* ========== DESTINATION BUTTONS ========== */
.destination-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.btn-dest {
    flex: 1;
    min-width: 100px;
    padding: 15px 10px;
    font-size: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: #f8f9fa;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.btn-dest:hover {
    border-color: #2196F3;
    background: #f0f0ff;
}

.btn-dest-active {
    border-color: #2196F3;
    background: linear-gradient(135deg, #2196F3 0%, #0D2B5B 100%);
    color: white;
    font-weight: bold;
}

.dest-label {
    color: #888;
    font-size: 13px;
    margin-top: 8px;
    margin-bottom: 4px;
    font-weight: 600;
}

small {
    color: #777;
    font-size: 12px;
}

/* ========== MATERIALS TABLE ========== */
.materials-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    font-size: 14px;
}

.materials-table th {
    background: linear-gradient(135deg, #2196F3 0%, #0D2B5B 100%);
    color: white;
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
}

.materials-table td {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
}

.materials-table tbody tr:hover {
    background: #f8f9ff;
}

.qty-cell {
    font-weight: bold;
    text-align: center;
    color: #2196F3;
    font-size: 16px;
}

.van-header {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin: 15px 0;
    border-left: 4px solid #2196F3;
}

.van-header h3 {
    margin: 0;
    color: #333;
}

.van-description {
    color: #777;
    margin-top: 5px;
}

.materials-summary {
    margin: 10px 0;
}

.badge {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}

.btn-small {
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 5px;
    background: #2196F3;
    color: white;
    cursor: pointer;
}

.btn-small:hover {
    background: #5a6fd6;
}

/* ========== IMPORT EXCEL ========== */
.import-section {
    margin: 15px 0;
}

.hint {
    color: #888;
    font-size: 13px;
    margin-bottom: 10px;
}

.file-upload-area {
    border: 2px dashed #ccc;
    border-radius: 10px;
    padding: 30px;
    text-align: center;
    margin: 15px 0;
    transition: all 0.2s;
    background: #fafafa;
}

.file-upload-area.drag-over {
    border-color: #2196F3;
    background: #f0f0ff;
}

.file-label {
    display: inline-block;
    margin-top: 10px;
    cursor: pointer;
}

.file-name {
    margin-top: 10px;
    font-weight: bold;
    color: #2196F3;
}

.result-box {
    margin-top: 15px;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.result-success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.result-error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.watch-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.status-box {
    margin-top: 15px;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
}

.status-active {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.status-inactive {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #6c757d;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .container {
        max-width: 100% !important;
        margin: 4px auto;
        padding: 12px;
        border-radius: 10px;
    }

    h2 {
        font-size: 1.2em;
    }

    /* ---- Intestazioni pagina (titolo + pulsanti) ---- */
    .page-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .page-header h2 {
        margin: 0;
    }
    .page-header-actions {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .page-header-actions button,
    .page-header-actions a {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 12px !important;
        padding: 8px 8px !important;
        white-space: nowrap;
        text-align: center;
    }

    /* ---- Stats bar ---- */
    .stats-bar {
        flex-wrap: wrap;
        gap: 6px;
    }
    .stat-chip {
        flex: 1 1 calc(50% - 6px);
        min-width: 0;
    }

    /* ---- Filtri ---- */
    .filters {
        flex-direction: column;
    }
    .filters input,
    .filters select {
        width: 100% !important;
        min-width: 0 !important;
    }
    .filters button {
        width: 100%;
    }

    /* ---- Righe form a due colonne → singola colonna ---- */
    .report-row {
        flex-direction: column !important;
        gap: 0 !important;
    }
    .report-row > div {
        width: 100% !important;
        flex: none !important;
    }
    .time-row {
        flex-direction: column;
        gap: 0;
    }
    .time-row > div {
        width: 100%;
    }
    .report-actions {
        flex-direction: column !important;
    }
    .report-actions button {
        width: 100%;
        margin: 4px 0;
    }

    /* ---- Schede rapporti/commesse ---- */
    .rc-header {
        flex-wrap: wrap;
        gap: 4px;
    }
    .rc-actions {
        flex-wrap: wrap;
    }
    .rc-actions button {
        flex: 1;
        min-width: 0;
    }
    .cc-actions {
        flex-wrap: wrap;
    }
    .cc-actions button {
        flex: 1;
        min-width: 0;
    }

    /* ---- Griglia 2 colonne → 1 colonna ---- */
    .form-2col {
        grid-template-columns: 1fr !important;
    }

    /* ---- Modale ---- */
    .modal-overlay {
        padding: 8px;
        overflow-y: auto;
        align-items: flex-start;
    }
    .modal-box {
        position: relative !important;
        top: auto !important;
        transform: none !important;
        margin: 0 auto;
        max-height: none !important;
        overflow-y: visible;
        padding: 16px;
    }
    .modal-btns {
        flex-direction: column;
    }
    .modal-btns button {
        width: 100%;
        margin: 3px 0;
    }

    /* ---- App logo header ---- */
    .app-logo-header {
        position: relative;
        top: 0;
        left: 0;
        text-align: center;
        margin-bottom: 10px;
    }
    .app-logo-header img {
        max-height: 50px;
        max-width: 140px;
    }

    .cart-actions {
        flex-direction: column;
    }
    .nav-buttons {
        flex-direction: column;
    }
    .nav-buttons button {
        width: 100%;
    }

    input, select, textarea {
        font-size: 16px; /* Evita zoom automatico su iOS */
    }

    /* ---- Tabella giacenze ---- */
    .location-group {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .stock-table {
        font-size: 13px;
        min-width: 480px;
    }
    .stock-table th,
    .stock-table td {
        padding: 7px 5px;
        white-space: nowrap;
    }

    /* ---- Summary cards ---- */
    .summary-card {
        min-width: 70px;
        padding: 10px 6px;
    }
    .summary-card .number {
        font-size: 20px;
    }
    .summary-card .label {
        font-size: 10px;
    }

    /* ---- Bilancio/fatturazione widget grid ---- */
    #billingWidget [style*="grid-template-columns"] {
        display: flex !important;
        flex-wrap: wrap;
    }
    #billingWidget [style*="grid-template-columns"] > div {
        flex: 1 1 calc(50% - 5px);
        min-width: 0;
    }
}

/* ========== CREATE PRODUCT INLINE ========== */
.create-product-card {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 12px;
    padding: 20px;
    margin: 15px 0;
}

.create-product-card h3 {
    color: #856404;
    margin-bottom: 10px;
}

.ai-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-input-row input {
    flex: 1;
}

.btn-ai {
    background: linear-gradient(135deg, #2196F3 0%, #0D2B5B 100%);
    color: white;
    white-space: nowrap;
    padding: 12px 16px !important;
    font-size: 14px;
    border-radius: 8px;
    min-width: 70px;
}

.btn-ai:hover {
    opacity: 0.9;
}

.btn-ai:disabled {
    opacity: 0.6;
    cursor: wait;
}

.ai-status {
    margin: 8px 0;
    font-size: 13px;
    min-height: 20px;
}

.ai-loading { color: #2196F3; }
.ai-success { color: #28a745; }
.ai-warning { color: #e67e22; }
.ai-error { color: #dc3545; }

.create-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.create-buttons button {
    flex: 1;
}
