:root {
    --primary-color: #034530; /* Verde scuro come mockup */
    --primary-light: #e6efea; /* Sfondo verde chiaro */
    --accent-green: #10b981;
    --danger-red: #ef4444;
    --bg-body: #f8fafc;
    --surface-color: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --header-height: 70px;
    --sidebar-width: 320px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
}

/* HEADER */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    flex-shrink: 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.back-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: background 0.2s;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.header-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px;
    border-radius: 8px;
}

.header-info h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.header-info p {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

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

/* AREA DI LAVORO A SCHERMO INTERO */
.app-workspace {
    display: flex;
    flex: 1;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    position: relative;
}

/* CONTENITORE DELLE SCHERMATE DISSOLVENZA */
.screens-container {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    position: relative;
    background-color: var(--surface-color);
    display: flex;
    flex-direction: column;
}

.screen-view {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: 32px;
    overflow-y: auto;
}

.screen-view.active {
    display: flex;
}

/* SIDEBAR (ORDINI APERTI) */
.sidebar {
    width: var(--sidebar-width);
    border-left: 1px solid var(--border-color);
    background: #fafafa;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

.sidebar-header {
    padding: 24px 20px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.order-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.order-item {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: white;
    transition: all 0.2s ease;
}

.order-item:hover {
    background: #f1f5f9;
}

.order-item.active {
    background: var(--primary-light);
    border-left: 5px solid var(--primary-color);
}

.order-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.order-id {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-main);
}

.order-status {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.order-badge {
    background: #f1f5f9;
    padding: 8px 12px;
    border-radius: 8px;
    text-align: center;
    min-width: 65px;
    transition: background 0.2s;
}

.order-item.active .order-badge {
    background: white;
}

.order-badge .num {
    font-weight: 700;
    font-size: 16px;
    color: var(--primary-color);
    line-height: 1;
}

.order-badge .lbl {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
}

.sidebar-footer {
    padding: 16px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    border-top: 1px solid var(--border-color);
    background: #f1f5f9;
    line-height: 1.4;
}

/* SCHERMATA 1: LETTURA ORDINE */
.scan-instruction {
    text-align: center;
    margin-bottom: 32px;
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 500;
}

.barcode-camera-container {
    border: 2px dashed var(--border-color);
    border-radius: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 32px;
    background: #fafafa;
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s;
}

.barcode-camera-container:hover {
    border-color: var(--primary-color);
}

.viewfinder-corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 4px solid var(--primary-color);
}

.top-left { top: 20px; left: 20px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.top-right { top: 20px; right: 20px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.bottom-left { bottom: 20px; left: 20px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.bottom-right { bottom: 20px; right: 20px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }

.barcode-scanner-line {
    width: 80%;
    height: 2px;
    background-color: var(--danger-red);
    position: absolute;
    top: 50%;
    left: 10%;
    box-shadow: 0 0 8px var(--danger-red);
    animation: scanAnimation 3s infinite ease-in-out;
}

@keyframes scanAnimation {
    0%, 100% { top: 20%; }
    50% { top: 80%; }
}

/* INPUTS E PULSANTI */
.btn-action-main {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 18px 36px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(3, 69, 48, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-action-main:hover {
    background-color: #023323;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px -2px rgba(3, 69, 48, 0.3);
}

.btn-action-main:active {
    transform: translateY(0);
}

/* SCHERMATA 2: INSERIMENTO */
.form-row {
    margin-bottom: 24px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon input {
    width: 100%;
    padding: 16px 54px 16px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s;
    background: white;
}

.input-with-icon input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(3, 69, 48, 0.1);
}

.input-with-icon .input-icon {
    position: absolute;
    right: 16px;
    color: var(--text-muted);
    cursor: pointer;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.quantity-card {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.quantity-card label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.quantity-input-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.quantity-input-wrapper input {
    border: none;
    background: transparent;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
    width: 100px;
    outline: none;
}

.quantity-unit-icon {
    color: var(--text-muted);
    font-size: 28px;
}

/* TOTALS CARD */
.totals-card {
    background-color: var(--primary-light);
    border: 1px solid rgba(3, 69, 48, 0.15);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.totals-card .icon-badge {
    background: var(--surface-color);
    color: var(--primary-color);
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.totals-info {
    display: flex;
    flex-direction: column;
}

.totals-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
}

.totals-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* MATCHED PRODUCT BAR */
.product-matched-bar {
    background: #fafafa;
    padding: 16px 20px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin-bottom: 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.product-meta h4 {
    font-size: 15px;
    font-weight: 700;
}

.product-meta p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.delivery-meta {
    text-align: right;
}

.delivery-meta .lbl {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.delivery-meta .val {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 2px;
}

/* GRID DELLE AZIONI */
.actions-grid-menu {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: auto;
}

.action-tile-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.action-tile-btn:hover {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
    transform: translateY(-2px);
}

.action-tile-btn .tile-icon {
    font-size: 30px;
    color: var(--primary-color);
}

.action-tile-btn .tile-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* SCHERMATA 3: ELENCO LETTURE */
.table-responsive {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: white;
    margin-bottom: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

th {
    background: #f8fafc;
    padding: 16px;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

.art-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 14px;
}

.art-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.status-badge.confirmed {
    background-color: #d1fae5;
    color: #065f46;
}

.status-badge.evaded {
    background-color: #f1f5f9;
    color: #475569;
}

.row-actions {
    display: flex;
    gap: 12px;
}

.row-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-action-btn:hover {
    color: var(--primary-color);
}

.row-action-btn.delete:hover {
    color: var(--danger-red);
}

.table-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    margin-top: auto;
}

.total-pieces-counter {
    font-size: 16px;
    font-weight: 500;
}

.total-pieces-counter strong {
    color: var(--primary-color);
    font-size: 22px;
    font-weight: 800;
    margin-left: 6px;
}

/* SCHERMATA 4: INSERIMENTO MANUALE / MODIFICA */
.manual-buttons-container {
    display: flex;
    gap: 16px;
    margin-top: auto;
}

.manual-buttons-container button {
    flex: 1;
}

.btn-outline {
    background: white;
    border: 1.5px solid var(--border-color);
    color: var(--text-main);
    padding: 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
}

.btn-outline:hover {
    background: #f8fafc;
    border-color: var(--text-main);
}

/* MODALE INFO ORDINE */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    width: 480px;
    max-width: 90%;
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    padding: 20px 24px;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.modal-body {
    padding: 24px;
}

.info-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.info-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px dashed var(--border-color);
}

.info-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.info-row .row-icon {
    color: var(--primary-color);
    background-color: var(--primary-light);
    padding: 8px;
    border-radius: 8px;
}

.info-texts {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-lbl {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-val {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
}

/* PANNELLO LEGENDA ICONE & FLUSSO IN FONDO */
.help-panel-toggle {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 30px;
    padding: 12px 24px;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: 0 10px 15px -3px rgba(3, 69, 48, 0.3);
    z-index: 50;
    transition: transform 0.2s, background 0.2s;
}

.help-panel-toggle:hover {
    background-color: #023323;
    transform: scale(1.05);
}

.help-drawer {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid var(--primary-color);
    box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: bottom 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 32px;
    max-height: 80vh;
    overflow-y: auto;
}

.help-drawer.open {
    bottom: 0;
}

.help-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.help-drawer-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
}

.help-sections-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 32px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8fafc;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.legend-item .item-icon {
    color: var(--primary-color);
    font-size: 22px;
}

.legend-item .item-name {
    font-size: 13px;
    font-weight: 600;
}

.workflow-timeline {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.workflow-step {
    display: flex;
    align-items: center;
    gap: 12px;
}

.step-num {
    background: var(--primary-color);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
}

.step-text {
    font-size: 14px;
    font-weight: 500;
}

/* TOAST NOTIFICATION */
.toast-notification {
    position: fixed;
    top: 24px;
    right: 24px;
    background: #1e293b;
    color: white;
    padding: 16px 24px;
    border-radius: 10px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 2000;
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-notification.show {
    transform: translateY(0);
    opacity: 1;
}

/* RESPONSIVE PER TABLET */
@media(max-width: 1024px) {
    .help-sections-grid {
        grid-template-columns: 1fr;
    }
    .legend-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}