* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    color: #333;
    touch-action: manipulation; /* Previene zoom su doppio tap */
    -webkit-user-select: none; /* Previene selezione testo */
    user-select: none;
}

.container {
    width: 100%;
    height: 100vh;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mode-toggle {
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 15px 20px;
    background: rgba(102, 126, 234, 0.1);
}

.mode-btn {
    padding: 12px 24px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s;
    flex: 1;
    max-width: 200px;
}

.mode-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

.mode-btn:active {
    transform: scale(0.95);
}

.scanner-section {
    display: none;
    position: relative;
    width: 100%;
    background: #000;
    flex-shrink: 0;
}

.scanner-section.active {
    display: block;
    padding: 0;
    background: #000;
    position: relative;
}

.camera-container {
    position: relative;
    width: 100%;
    height: 28vh; /* Ridotto del 30% da 40vh */
    max-height: 280px; /* Ridotto del 30% da 400px */
    background: #000;
    overflow: hidden;
}

.manual-input-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: auto;
    padding: 8px 16px;
    border-radius: 5px;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    border: 2px solid white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s, opacity 0.2s;
    line-height: 1;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    visibility: visible !important;
    opacity: 1 !important;
}

.manual-input-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.manual-input-btn:active {
    transform: scale(0.95);
}

/* Stili per Html5Qrcode */
#cameraContainer video {
    width: 100%;
    height: auto;
    position: relative;
    z-index: 1;
}

#cameraContainer canvas {
    display: none;
}

/* Nascondi il box verde e le guide di Html5Qrcode */
#qr-shaded-region,
#qr-shaded-region > div,
#qr-shaded-region > div > div {
    display: none !important;
    border: none !important;
    background: none !important;
}

#qr-shaded-region {
    border: none !important;
    background: none !important;
    box-shadow: none !important;
}

/* Nascondi anche eventuali overlay di Html5Qrcode */
#cameraContainer > div > div {
    display: none !important;
}

/* Assicura che gli elementi di Html5Qrcode non coprano il pulsante */
#cameraContainer > div {
    z-index: 1 !important;
}

#cameraContainer > div > video {
    z-index: 1 !important;
}

.input-section {
    display: none;
    padding: 20px;
}

.input-section.active {
    display: block;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#codeInput {
    width: 100%;
    padding: 15px;
    font-size: 18px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    outline: none;
    transition: border-color 0.3s;
}

#codeInput:focus {
    border-color: #667eea;
}

.scan-button {
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.scan-button:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.results-area {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    position: relative;
}

.product-info {
    background: transparent;
    border: none;
    padding: 20px 0;
    margin-bottom: 15px;
}

.product-info h2 {
    font-size: 22px;
    margin-bottom: 15px;
    color: #333;
    word-break: break-all;
}

.product-code.status-venduto {
    color: #8B1538;
}

.product-code.status-prenotato {
    color: #FFC107;
}

.product-code.status-disponibile {
    color: #28a745;
}

.status-badge {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 5px;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 15px;
}

.status-badge.disponibile {
    background: #d4edda;
    color: #155724;
}

.status-badge.venduto {
    background: #8B1538;
    color: white;
}

.status-badge.prenotato {
    background: #FFC107;
    color: #333;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}

.action-btn {
    width: 100%;
    padding: 35px;
    border: none;
    border-radius: 5px;
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    min-height: 90px;
}

.action-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-sell {
    background: #8B1538;
    color: white;
}

.btn-reserve {
    background: #FFC107;
    color: #333;
}

.btn-available {
    background: #28a745;
    color: white;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-info.btn-prenotato {
    background: #FFC107;
    color: #333;
}

.btn-info.btn-venduto {
    background: #8B1538;
    color: white;
}

.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error-message,
.success-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 25px;
    border-radius: 5px;
    font-weight: 600;
    z-index: 1001;
    max-width: 90%;
    text-align: center;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c6cb;
}

.success-message {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 5px;
    padding: 25px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.modal-content h3 {
    margin: 0;
    color: #333;
    font-size: 20px;
    flex: 1;
}

.discount-gear-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 5px 10px;
    transition: transform 0.2s;
    line-height: 1;
}

.discount-gear-btn:hover {
    transform: rotate(90deg);
}

.discount-gear-btn:active {
    transform: rotate(90deg) scale(0.9);
}

.discount-input-container {
    margin: 15px 0;
}

.discount-input-container label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.discount-input-container input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    outline: none;
}

.discount-input-container input:focus {
    border-color: #667eea;
}

.modal-content p {
    margin-bottom: 15px;
    color: #666;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    margin-bottom: 20px;
    outline: none;
}

.modal-content input:focus {
    border-color: #667eea;
}

.notes-container {
    margin: 15px 0;
}

.notes-container label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.notes-input {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    font-family: inherit;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    resize: vertical;
    outline: none;
    min-height: 80px;
    box-sizing: border-box;
}

.notes-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-actions {
    display: flex;
    gap: 10px;
    flex-direction: row; /* Conferma a sinistra, Annulla a destra */
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 15px;
    border: none;
    border-radius: 5px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    min-height: 50px;
}

.discount-icon {
    text-align: center;
    padding: 15px;
    margin: 15px 0;
    background: #fff3cd;
    border-radius: 5px;
    font-size: 18px;
    color: #856404;
}

.discount-icon span {
    font-size: 24px;
    margin-right: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-primary:active,
.btn-secondary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Debug Panel */
.debug-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: transform 0.2s, background 0.2s;
}

.debug-toggle:hover {
    transform: scale(1.1);
    background: #764ba2;
}

.debug-toggle:active {
    transform: scale(0.95);
}

.debug-panel {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 90%;
    max-width: 400px;
    max-height: 70vh;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    display: none; /* Nascosto di default */
    flex-direction: column;
    overflow: hidden;
}

.debug-panel.visible {
    display: flex;
}

.debug-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.debug-header h3 {
    margin: 0;
    font-size: 18px;
}

.debug-close,
.debug-clear {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.debug-close {
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 20px;
    font-weight: bold;
}

.debug-close:hover,
.debug-clear:hover {
    background: rgba(255, 255, 255, 0.3);
}

.debug-content {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
}

.debug-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.debug-section:last-child {
    border-bottom: none;
}

.debug-section h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #667eea;
    font-weight: 600;
}

.debug-info {
    font-size: 12px;
    color: #666;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    word-break: break-all;
    line-height: 1.5;
}

.debug-logs {
    max-height: 200px;
    overflow-y: auto;
    font-size: 11px;
    font-family: 'Courier New', monospace;
}

.debug-log-entry {
    padding: 8px;
    margin-bottom: 5px;
    border-radius: 4px;
    border-left: 3px solid #ccc;
    background: #f8f9fa;
}

.debug-log-entry.info {
    border-left-color: #17a2b8;
    background: #d1ecf1;
}

.debug-log-entry.success {
    border-left-color: #28a745;
    background: #d4edda;
}

.debug-log-entry.error {
    border-left-color: #dc3545;
    background: #f8d7da;
}

.debug-log-entry.warning {
    border-left-color: #ffc107;
    background: #fff3cd;
}

.debug-log-time {
    color: #999;
    font-size: 10px;
    margin-right: 8px;
}

.debug-log-message {
    color: #333;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .container {
        max-width: 600px;
        margin: 20px auto;
        min-height: auto;
    }

    .camera-container {
        padding-top: 56.25%; /* 16:9 aspect ratio for larger screens */
    }

    .actions {
        flex-direction: row;
    }

    .debug-panel {
        width: 400px;
    }
}

