/* ============================================= */
/* RESET E VARIABILI */
/* ============================================= */
:root {
    --primary: #00d4ff;
    --secondary: #ff4d4d;
    --success: #00cc66;
    --warning: #ffd93d;
    --bg-dark: #0a0a0a;
    --bg-card: #1a1a1a;
    --bg-darker: #141414;
    --text-light: #fff;
    --text-muted: #888;
    --border-color: #333;
    --sidebar-width: 380px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================= */
/* LAYOUT PRINCIPALE */
/* ============================================= */
.main-container {
    display: flex;
    min-height: 100vh;
}

/* ============================================= */
/* SIDEBAR */
/* ============================================= */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-darker) 100%);
    border-right: 2px solid var(--primary);
    padding: 20px;
    overflow-y: auto;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    box-shadow: 4px 0 20px rgba(0, 212, 255, 0.2);
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg-darker);
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.sidebar-header {
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

.sidebar-header img {
    width: 60px;
    height: auto;
    margin-bottom: 10px;
}

.sidebar-header h2 {
    color: var(--primary);
    font-size: 16px;
    margin: 0;
    letter-spacing: 1px;
}

/* Sezioni Sidebar */
.sidebar-section {
    background: rgba(0, 212, 255, 0.05);
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
}

.sidebar-section h3 {
    color: var(--primary);
    font-size: 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================= */
/* STATO RILEVAMENTO */
/* ============================================= */
.detection-status {
    padding: 12px 15px;
    border-radius: 8px;
    font-weight: bold;
    text-align: center;
    font-size: 13px;
    border: 2px solid;
    animation: pulse 2s ease-in-out infinite;
}

.detection-status.waiting {
    background: rgba(136, 136, 136, 0.2);
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.detection-status.creatore {
    background: rgba(0, 212, 255, 0.2);
    border-color: var(--primary);
    color: var(--primary);
}

.detection-status.ingranaggio {
    background: rgba(255, 77, 77, 0.2);
    border-color: var(--secondary);
    color: var(--secondary);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ============================================= */
/* CASELLE DATI (CREATORE/INGRANAGGIO) */
/* ============================================= */
.data-box {
    background: var(--bg-darker);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 20px;
    border: 2px solid;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.data-box.creatore {
    border-color: var(--primary);
}

.data-box.ingranaggio {
    border-color: var(--secondary);
}

.data-box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: linear-gradient(135deg, var(--bg-card), var(--bg-darker));
    border-bottom: 1px solid var(--border-color);
}

.data-box-header h3 {
    font-size: 14px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-light);
}

.data-box.creatore .data-box-header h3 {
    color: var(--primary);
}

.data-box.ingranaggio .data-box-header h3 {
    color: var(--secondary);
}

.count-badge {
    background: rgba(0, 212, 255, 0.2);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 11px;
    font-weight: bold;
}

.data-box.ingranaggio .count-badge {
    background: rgba(255, 77, 77, 0.2);
    color: var(--secondary);
}

.data-box-content {
    padding: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.data-box-content::-webkit-scrollbar {
    width: 6px;
}

.data-box-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
}

.data-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 20px;
}

.data-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.data-item {
    background: rgba(0, 212, 255, 0.1);
    padding: 10px 12px;
    border-radius: 6px;
    border-left: 3px solid var(--primary);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.data-box.ingranaggio .data-item {
    background: rgba(255, 77, 77, 0.1);
    border-left-color: var(--secondary);
}

.data-item:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
}

.data-item-label {
    color: var(--text-muted);
    font-size: 11px;
}

.data-item-value {
    color: var(--text-light);
    font-weight: bold;
}

/* ============================================= */
/* LOG */
/* ============================================= */
.match-log {
    background: var(--bg-darker);
    border-radius: 6px;
    padding: 10px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 12px;
}

.match-log-item {
    padding: 8px 10px;
    margin-bottom: 6px;
    border-radius: 4px;
    border-left: 3px solid;
    display: flex;
    align-items: center;
    gap: 8px;
}

.match-log-item.success {
    background: rgba(0, 204, 102, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.match-log-item.info {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.match-log-item.warning {
    background: rgba(255, 217, 61, 0.1);
    border-color: var(--warning);
    color: var(--warning);
}

.match-log-item.error {
    background: rgba(255, 77, 77, 0.1);
    border-color: var(--secondary);
    color: var(--secondary);
}

/* ============================================= */
/* AZIONI SIDEBAR */
/* ============================================= */
.sidebar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding-top: 15px;
    border-top: 2px solid var(--border-color);
}

.btn-sidebar {
    padding: 10px 15px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-sidebar.full-width {
    grid-column: 1 / -1;
}

.btn-export {
    background: linear-gradient(135deg, var(--success), #009944);
    color: var(--text-light);
}

.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 204, 102, 0.4);
}

.btn-copy {
    background: linear-gradient(135deg, var(--primary), #0099cc);
    color: var(--text-light);
}

.btn-copy:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 212, 255, 0.4);
}

.btn-clear {
    background: linear-gradient(135deg, var(--secondary), #cc3333);
    color: var(--text-light);
}

.btn-clear:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 77, 77, 0.4);
}

/* ============================================= */
/* AREA PRINCIPALE */
/* ============================================= */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 30px;
    min-height: 100vh;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--primary);
}

.main-header h1 {
    color: var(--secondary);
    font-size: 28px;
    margin: 0;
    letter-spacing: 1px;
}

.header-badge {
    background: linear-gradient(135deg, var(--primary), #0099cc);
    color: var(--text-light);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============================================= */
/* SEZIONE UPLOAD */
/* ============================================= */
.upload-section {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-darker));
    padding: 50px;
    border-radius: 15px;
    border: 3px dashed var(--primary);
    text-align: center;
    margin-bottom: 30px;
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.2);
    transition: all 0.3s ease;
}

.upload-section:hover {
    border-color: var(--secondary);
    box-shadow: 0 0 40px rgba(255, 77, 77, 0.3);
}

.upload-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.upload-section h3 {
    color: var(--primary);
    font-size: 22px;
    margin-bottom: 10px;
}

.upload-section p {
    color: var(--text-muted);
    margin-bottom: 25px;
    font-size: 14px;
}

input[type="file"] {
    display: none;
}

.custom-upload-button {
    background: linear-gradient(135deg, var(--primary), #0099cc);
    color: #000;
    border: 3px solid var(--secondary);
    padding: 15px 40px;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 10px;
    display: inline-block;
    font-size: 16px;
    letter-spacing: 1px;
}

.custom-upload-button:hover {
    background: linear-gradient(135deg, var(--secondary), #cc3333);
    color: var(--text-light);
    box-shadow: 0 0 30px var(--secondary);
    transform: scale(1.05);
}

/* ============================================= */
/* CANVAS SECTION */
/* ============================================= */


.zoom-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    background: var(--bg-card);
    border-left: 5px solid var(--secondary);
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.15);
    flex-wrap: wrap;
}

.zoom-bar button {
    background: var(--primary);
    color: #000;
    border: 2px solid var(--secondary);
    padding: 10px 20px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    min-width: 45px;
}

.zoom-bar button:hover {
    background: var(--secondary);
    color: var(--text-light);
    box-shadow: 0 0 15px var(--secondary);
    transform: scale(1.05);
}

#zoomLevel {
    color: var(--primary);
    font-weight: bold;
    font-size: 20px;
    min-width: 80px;
    text-align: center;
    background: #000;
    padding: 10px 20px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.zoom-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin-left: auto;
}

/* ============================================= */
/* CANVAS SECTION - CORREZIONE                   */
/* ============================================= */
.canvas-section {
    display: none;
    width: 100%;
    max-width: calc(100% - 40px); /* Adattato per lo spazio disponibile */
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    padding: 0 15px;
}

/* Aggiusta anche il canvas-container per la sidebar */
.canvas-container {
    position: relative;
    background: #111;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
    border: 3px solid var(--primary);
    width: 100%;
    max-width: 100%; /* Cambiato da 1400px a 100% */
}
#imageCanvas {
    display: block;
    cursor: crosshair;
    background-color: #0a0a0a;
    width: 100%;
}

#imageCanvas.panning {
    cursor: grab !important;
}

#imageCanvas.panning:active {
    cursor: grabbing !important;
}

/* ============================================= */
/* INFO BOX */
/* ============================================= */
.info-box {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 30px;
    background: rgba(0, 212, 255, 0.1);
    border: 2px solid var(--primary);
    padding: 15px 30px;
    margin-bottom: 20px;
    border-radius: 30px;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.2);
}

.selection-count {
    font-size: 16px;
    color: var(--text-light);
}

.selection-count strong {
    color: var(--secondary);
    font-size: 24px;
}

/* ============================================= */
/* CONTROLLI */
/* ============================================= */
.controls {
    display: none;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.btn {
    padding: 15px 30px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.btn-process {
    background: linear-gradient(135deg, var(--success), #009944);
    color: var(--text-light);
    border: 2px solid #00ff88;
}

.btn-undo {
    background: linear-gradient(135deg, var(--primary), #0099cc);
    color: var(--text-light);
    border: 2px solid var(--primary);
}

.btn-clear {
    background: linear-gradient(135deg, var(--secondary), #cc3333);
    color: var(--text-light);
    border: 2px solid #ff6666;
}

/* ============================================= */
/* LOADING */
/* ============================================= */
.loading {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 50px;
    border-radius: 20px;
    border: 3px solid var(--primary);
    box-shadow: 0 0 50px rgba(0, 212, 255, 0.5);
    z-index: 10000;
    text-align: center;
}

.spinner-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.spinner {
    width: 70px;
    height: 70px;
    border: 6px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loadingText {
    color: var(--primary);
    font-size: 18px;
    font-weight: bold;
    margin: 0;
}

/* ============================================= */
/* RESPONSIVE */
/* ============================================= */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 320px;
    }
    
    .sidebar-header h2 {
        font-size: 14px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: relative;
        height: auto;
        border-right: none;
        border-bottom: 2px solid var(--primary);
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
    
    .main-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }
    
    .header-badge {
        align-self: stretch;
        text-align: center;
    }
    
    .zoom-hint {
        display: none;
    }
    
    .info-box {
        flex-direction: column;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .upload-section {
        padding: 30px 20px;
    }
    
    .upload-section h3 {
        font-size: 18px;
    }
    
    .custom-upload-button {
        padding: 12px 30px;
        font-size: 14px;
    }
    
    .zoom-bar {
        padding: 10px 15px;
        gap: 8px;
    }
    
    .zoom-bar button {
        padding: 8px 15px;
        font-size: 14px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 13px;
    }
    
    .sidebar-actions {
        grid-template-columns: 1fr;
    }
}


/* ============================================= */
/* PULSANTE RETURN HOME - STILE COORDINATO       */
/* ============================================= */

.sidebar-nav-home {
    padding: 10px 0 20px 0;
    width: 100%;
    display: flex;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.btn-home-return {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--bg-darker), #222);
    color: var(--primary); /* Il tuo azzurro #00d4ff */
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
    letter-spacing: 1px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.1);
}

.btn-home-return:hover {
    background: var(--primary);
    color: #000;
    box-shadow: 0 0 20px var(--primary);
    transform: translateY(-2px);
}

.btn-home-return .icon {
    font-size: 18px;
}

/* Modifica al tasto menu per stare sotto bene */
.posto_btnopen {
    text-align: center;
    padding: 5px 0 15px 0;
    border-bottom: 1px solid var(--border-color);
}