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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #f5f5f5;
    -webkit-font-smoothing: antialiased;
}

.page-container {
    min-height: 100vh;
    padding-bottom: 20px;
}

/* Header */
.page-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    padding: 12px 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-back {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-back svg {
    width: 24px;
    height: 24px;
    fill: #333;
}

.header-title {
    flex: 1;
    font-size: 18px;
    font-weight: 800;
    margin: 0;
}

.view-toggle {
    display: flex;
    gap: 4px;
}

.btn-view {
    background: #fff;
    border: 1px solid #ddd;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #666;
    transition: all 0.2s;
}

.btn-view.active {
    background: #1976d2;
    color: #fff;
    border-color: #1976d2;
}

/* Riepilogo */
#riepilogo {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 700;
}

.chip-warning {
    background: #fff3cd;
    color: #856404;
}

.chip-error {
    background: #f8d7da;
    color: #721c24;
}

.chip-outline {
    background: #fff;
    border: 1px solid #ddd;
    color: #666;
}

.chip-small {
    padding: 4px 8px;
    font-size: 11px;
}

/* Filtri */
.filters-card {
    background: #fff;
    margin: 0 16px 16px 16px;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.filter-input {
    flex: 1;
    min-width: 120px;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.filter-input-search {
    flex: 2;
}

.btn-filter {
    padding: 10px 16px;
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.btn-icon {
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon svg {
    width: 20px;
    height: 20px;
    fill: #666;
}

.filters-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.btn-quick {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.filters-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-secondary {
    padding: 8px 14px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Loading */
.loading {
    display: none;
    justify-content: center;
    padding: 40px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Grid View */
#grid-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 0 16px;
}

@media (min-width: 768px) {
    #grid-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1200px) {
    #grid-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

.item-card-grid {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: all 0.2s;
}

.item-card-grid:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.item-image {
    width: 100%;
    height: 180px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.item-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.img-placeholder {
    font-size: 60px;
}

.item-content {
    padding: 12px;
}

.item-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 4px;
    color: #333;
}

.item-subtitle {
    font-size: 12px;
    color: #999;
    margin-bottom: 8px;
}

.item-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.chip-ubicazione {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    color: #fff;
    font-size: 12px;
}

.chip-ubicazione strong {
    font-weight: 900;
    font-size: 14px;
}

.chip-ubicazione .corridor {
    opacity: 0.9;
    font-size: 11px;
}

.item-ref {
    font-size: 11px;
    font-family: 'Courier New', monospace;
    color: #666;
    margin-bottom: 8px;
}

.item-stocks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.stock-chip {
    font-size: 11px;
    padding: 4px 8px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    color: #666;
}

.stock-chip.stock-erp {
    background: #e3f2fd;
    border-color: #1976d2;
    color: #1976d2;
    font-weight: 600;
}

.item-meta {
    font-size: 11px;
    color: #999;
}

/* List View */
#list-container {
    display: none;
    padding: 0 16px;
}

.item-row-list {
    background: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.06);
    transition: all 0.2s;
}

.item-row-list:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.item-image-small {
    width: 52px;
    height: 52px;
    background: #f5f5f5;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.item-image-small img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.img-placeholder-small {
    font-size: 24px;
}

.item-info-list {
    flex: 1;
    min-width: 0;
}

.item-title-list {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-meta-list {
    font-size: 11px;
    color: #999;
}

/* Empty State */
#empty-state {
    display: none;
    text-align: center;
    padding: 60px 20px;
    color: #999;
    font-size: 15px;
}

/* Detail Dialog */
#detail-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

#detail-content {
    background: #fff;
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    margin: auto;
}

.detail-header {
    padding: 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.detail-header h2 {
    font-size: 18px;
    font-weight: 800;
    margin: 0;
    line-height: 1.3;
}

.btn-close {
    background: none;
    border: none;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.detail-body {
    padding: 20px;
}

.detail-main {
    margin-bottom: 20px;
}

.detail-image {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 8px;
    background: #f5f5f5;
    margin-bottom: 12px;
}

.detail-image-placeholder {
    width: 100%;
    height: 200px;
    background: #f5f5f5;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    margin-bottom: 12px;
}

.detail-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.detail-info {
    margin-bottom: 20px;
}

.info-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

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

.info-row strong {
    color: #666;
    font-weight: 600;
}

.detail-stocks-box {
    background: #f5f5f5;
    padding: 16px;
    border-radius: 8px;
}

.detail-stocks-box h3 {
    font-size: 13px;
    color: #666;
    margin: 0 0 12px 0;
}

.stocks-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.detail-actions {
    padding: 16px 20px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-success {
    padding: 12px 20px;
    background: #22c55e;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0,0,0,0.9);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    z-index: 3000;
    opacity: 0;
    transition: all 0.3s;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-success {
    background: #22c55e;
}

.toast-error {
    background: #dc2626;
}
