/* ============================================
   PACKING LABEL SYSTEM - STYLES
   Brand color: #ff7514 (orange)
   ============================================ */

:root {
    --primary: #ff7514;
    --primary-dark: #e56600;
    --primary-light: #ff9a4d;
    --bg-light: #f8f9fa;
    --bg-white: #ffffff;
    --text-dark: #1a1a2e;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.5;
}

/* ============================================
   LOGIN
   ============================================ */

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 1rem;
}

.login-box {
    background: white;
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h1 {
    margin-bottom: 0.5rem;
    color: var(--text-dark);
    font-size: 1.75rem;
}

.login-box p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-box button[type="submit"] {
    padding: 0.875rem 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 117, 20, 0.3);
    margin-top: 0.5rem;
}

.login-box button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 117, 20, 0.4);
}

.login-box button[type="submit"]:active {
    transform: translateY(0);
}

.login-box button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.error {
    color: var(--danger);
    font-size: 0.875rem;
    background: rgba(220, 53, 69, 0.1);
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-top: 0.5rem;
}

/* ============================================
   APP LAYOUT
   ============================================ */

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
    overflow: hidden;
}

header {
    background: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.header-right span {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ============================================
   NAVIGATION TABS
   ============================================ */

.tabs {
    background: white;
    padding: 0 2rem;
    display: flex;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.tabs button {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
    font-weight: 500;
    margin-bottom: -2px;
}

.tabs button:hover {
    color: var(--primary);
    background: rgba(255, 117, 20, 0.05);
}

.tabs button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* ============================================
   FORM ELEMENTS - MODERN STYLE
   ============================================ */

/* Base input styles */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-dark);
    background: var(--bg-white);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="search"]:hover,
input[type="tel"]:hover,
input[type="url"]:hover,
textarea:hover,
select:hover {
    border-color: #bbb;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(255, 117, 20, 0.1);
}

input::placeholder,
textarea::placeholder {
    color: #aaa;
    font-weight: 400;
}

/* Select dropdown */
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ff7514' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

/* Textarea */
textarea {
    min-height: 100px;
    resize: vertical;
    line-height: 1.5;
}

/* Modern Checkbox */
input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

input[type="checkbox"]:hover {
    border-color: var(--primary-light);
}

input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 40%;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -50%) rotate(45deg);
}

input[type="checkbox"]:focus {
    box-shadow: 0 0 0 4px rgba(255, 117, 20, 0.15);
}

/* Modern Radio Button */
input[type="radio"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: white;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

input[type="radio"]:hover {
    border-color: var(--primary-light);
}

input[type="radio"]:checked {
    border-color: var(--primary);
}

input[type="radio"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 4px;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
}

input[type="radio"]:focus {
    box-shadow: 0 0 0 4px rgba(255, 117, 20, 0.15);
}

/* Number input - hide spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* Disabled state */
input:disabled,
select:disabled,
textarea:disabled {
    background: var(--bg-light);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Form labels */
label {
    display: block;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

/* Input groups */
.input-group {
    position: relative;
}

.input-group input {
    padding-left: 2.5rem;
}

.input-group-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* Small inputs */
.input-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn-primary {
    padding: 0.625rem 1.25rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(255, 117, 20, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(255, 117, 20, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(255, 117, 20, 0.3);
}

.btn-secondary {
    padding: 0.625rem 1.25rem;
    background: white;
    color: var(--text-dark);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(255, 117, 20, 0.05);
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s ease;
    padding: 0.375rem;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    line-height: 1;
}

.btn-icon:hover {
    opacity: 1;
    background: var(--bg-light);
    color: var(--primary);
}

.btn-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    text-decoration: none;
    font-size: inherit;
    font-weight: 500;
    transition: color 0.2s;
}

.btn-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.btn-remove {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-remove:hover {
    background: #c82333;
    transform: scale(1.1);
}

/* ============================================
   ORDERS VIEW
   ============================================ */

.orders-view {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    width: 320px;
    background: white;
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border);
    background: linear-gradient(135deg, var(--bg-light) 0%, white 100%);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    color: var(--text-dark);
}

.orders-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.order-item {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    transition: all 0.2s ease;
}

.order-item:hover {
    background: rgba(255, 117, 20, 0.05);
}

.order-item.selected {
    background: rgba(255, 117, 20, 0.1);
    border-left: 4px solid var(--primary);
}

.order-item strong {
    color: var(--text-dark);
    font-size: 0.95rem;
}

.order-item small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.badge {
    align-self: flex-start;
    padding: 0.25rem 0.625rem;
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef0f2 100%);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.badge-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 0.5rem;
    background: linear-gradient(135deg, var(--success) 0%, #1e7e34 100%);
    color: white;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

.badge-pending {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main-content {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.main-content.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

/* Order Header Compatto */
.order-header-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.order-header-info {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-width: 0;
}

.order-header-info h2 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--primary);
    white-space: nowrap;
}

.order-separator {
    color: var(--border);
    font-weight: 300;
}

.order-header-info .order-client {
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
}

.order-header-info .order-dest {
    color: var(--text-muted);
    white-space: nowrap;
}

.order-header-info .order-address {
    color: var(--text-muted);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

.order-header-compact .order-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.order-actions {
    display: flex;
    gap: 0.5rem;
}

/* ============================================
   BOXES SECTION
   ============================================ */

.boxes-section {
    margin-bottom: 2rem;
}

.boxes-section h3 {
    margin-bottom: 1rem;
    color: var(--text-dark);
    font-size: 1.1rem;
}

.boxes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.box-card {
    background: white;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    transition: all 0.2s ease;
}

.box-card:hover {
    border-color: var(--primary-light);
    box-shadow: 0 4px 12px rgba(255, 117, 20, 0.1);
}

.box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.box-header strong {
    color: var(--primary);
    font-size: 1rem;
}

.box-details {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.box-details input {
    flex: 1;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
}

.box-symbols {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-light);
    border-radius: var(--radius);
}

.box-symbols label {
    cursor: pointer;
    margin: 0;
}

.box-symbols input[type="checkbox"] {
    display: none;
}

.box-symbols span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 6px;
    opacity: 0.3;
    transition: all 0.2s ease;
    border-radius: 6px;
    background: white;
    color: var(--text-muted);
}

.box-symbols span svg {
    width: 100%;
    height: 100%;
}

.box-symbols span:hover {
    opacity: 0.6;
}

.box-symbols input:checked+span {
    opacity: 1;
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(255, 117, 20, 0.3);
}

.box-pieces {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

/* ============================================
   PIECES TABLE
   ============================================ */

.pieces-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.pieces-table {
    width: 100%;
    background: white;
    border: 2px solid var(--border);
    border-radius: 12px;
    border-collapse: separate;
    border-spacing: 0;
}

.pieces-table-wrapper {
    flex: 1;
    min-height: 0;
    border-radius: 12px;
}

.pieces-table-wrapper .pieces-table {
    width: 100%;
}

/* Wrapper tabella con scroll e header fisso */
.pieces-table-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: white;
}

.pieces-table-wrapper .pieces-table {
    border: none;
    border-radius: 0;
}

.pieces-table-wrapper .pieces-table th:first-child {
    border-top-left-radius: 10px;
}

.pieces-table-wrapper .pieces-table th:last-child {
    border-top-right-radius: 10px;
}

.pieces-table th,
.pieces-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.pieces-table th {
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef0f2 100%);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.pieces-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

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

.pieces-table tr.packed {
    background: rgba(40, 167, 69, 0.08);
}

.pieces-table tbody tr {
    transition: background 0.2s ease;
}

.pieces-table tbody tr:hover {
    background: rgba(255, 117, 20, 0.05);
}

/* ============================================
   PACKING VIEW (TABLET)
   ============================================ */

.packing-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    background: var(--bg-light);
    min-height: 0;
    overflow: hidden;
}

.packing-header {
    margin-bottom: 1.5rem;
}

.packing-header select {
    padding: 0.875rem 1.25rem;
    font-size: 1rem;
    min-width: 350px;
    font-weight: 500;
}

.packing-content {
    flex: 1;
    display: grid;
    grid-template-columns: 180px 1fr 1fr;
    gap: 1.5rem;
    overflow: hidden;
    min-height: 0;
}

.packing-boxes {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.packing-boxes .box-buttons {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.packing-boxes h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
}

.box-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.box-btn {
    padding: 1.25rem 1rem;
    background: var(--bg-light);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-weight: 600;
    font-size: 1rem;
}

.box-btn:hover {
    border-color: var(--primary);
    background: rgba(255, 117, 20, 0.05);
}

.box-btn.selected {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(255, 117, 20, 0.3);
}

.box-btn small {
    opacity: 0.7;
    font-weight: 400;
    font-size: 0.85rem;
}

.packing-pieces {
    background: white;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.packing-pieces .piece-cards {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.packing-pieces-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.packing-pieces h3 {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.packing-pieces-header .packing-search {
    margin: 0;
    flex: 1;
    max-width: 250px;
}

.packing-pieces-header .packing-search input {
    padding: 0.4rem 0.75rem 0.4rem 2rem;
    font-size: 0.85rem;
}

/* Stili base piece-cards spostati nella sezione dedicata sotto */

.packing-current {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 2px solid var(--primary);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.packing-current .current-pieces {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.packing-current h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--primary);
    font-weight: 600;
}

.current-pieces {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.current-piece {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    background: rgba(255, 117, 20, 0.1);
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.current-piece:hover {
    background: rgba(255, 117, 20, 0.2);
    border-color: var(--primary-light);
}

/* ============================================
   PACKING VIEW - CARD PEZZI DIMENSIONI FISSE
   ============================================ */

/* Card pezzi con dimensioni fisse - 4 COLONNE */
.packing-pieces .piece-cards {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 10px;
    padding: 8px;
}

/* Responsive: 3 colonne su tablet */
@media (max-width: 1100px) {
    .packing-pieces .piece-cards {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* Responsive: 2 colonne su mobile */
@media (max-width: 700px) {
    .packing-pieces .piece-cards {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

.packing-pieces .piece-card {
    position: relative;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    padding-right: 38px; /* Spazio per badge cassa a destra */
    cursor: pointer;
    transition: all 0.2s;
    min-height: 100px;
    max-height: 115px;
    height: 105px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.packing-pieces .piece-card:hover {
    border-color: #ff7514;
    box-shadow: 0 2px 8px rgba(255, 117, 20, 0.2);
    transform: none;
}

.packing-pieces .piece-card.already-packed {
    background: #f5f5f5;
    border-color: #ccc;
    cursor: default;
    opacity: 0.7;
}

/* Numero pezzo in alto a destra (arancione) */
.packing-pieces .piece-number {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #ff7514;
    color: white;
    font-weight: bold;
    font-size: 12px;
    padding: 3px 7px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

/* Badge cassa - CERCHIO CENTRATO VERTICALMENTE A DESTRA */
.packing-pieces .piece-card .packed-badge {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: #4CAF50;
    color: white;
    font-size: 11px;
    font-weight: bold;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    bottom: auto;
    left: auto;
}

/* Badge copia (es. 1/2, 2/3) - in basso a sinistra per non sovrapporsi */
.packing-pieces .piece-copy-badge {
    position: absolute;
    bottom: 6px;
    left: 8px;
    right: auto;
    background: #2196F3;
    color: white;
    font-size: 9px;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 8px;
}

/* Contenuto card */
.packing-pieces .piece-room {
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.packing-pieces .piece-furniture {
    font-size: 12px;
    font-weight: bold;
    color: #333;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.packing-pieces .piece-part {
    font-size: 11px;
    color: #555;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.packing-pieces .piece-part-en {
    font-size: 10px;
    color: #888;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   DISABILITA ZOOM SU TOUCH
   ============================================ */

/* Previeni zoom doppio tap */
* {
    touch-action: manipulation;
}

/* Previeni selezione testo accidentale su touch */
.packing-view {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: pan-x pan-y;
}

/* Input ricerca deve permettere selezione */
.packing-search input {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ============================================
   DICTIONARY VIEW
   ============================================ */

.dictionary-view {
    flex: 1;
    padding: 1.5rem;
    background: var(--bg-light);
}

.dictionary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.dictionary-header h2 {
    font-size: 1.25rem;
}

.dictionary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 0.75rem;
}

.dict-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    background: white;
    border: 2px solid var(--border);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.dict-item:hover {
    border-color: var(--primary-light);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.dict-it {
    flex: 1;
    font-weight: 500;
}

.dict-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.dict-en {
    flex: 1;
    color: var(--primary);
    font-weight: 500;
}

/* ============================================
   BADGES
   ============================================ */

.badge {
    align-self: flex-start;
    padding: 0.25rem 0.625rem;
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef0f2 100%);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.badge-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 0.5rem;
    background: linear-gradient(135deg, var(--success) 0%, #1e7e34 100%);
    color: white;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

.badge-pending {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* ============================================
   MODALS
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.25);
    animation: slideUp 0.3s ease;
}

.modal-large {
    max-width: 700px;
}

.modal h2 {
    margin-bottom: 1.5rem;
    color: var(--text-dark);
    font-size: 1.35rem;
    font-weight: 600;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.modal label {
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: -0.75rem;
    font-size: 0.9rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: -0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.symbols-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.symbol-checkbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.symbol-checkbox:hover {
    background: rgba(255, 117, 20, 0.1);
    border-color: var(--primary-light);
}

.symbol-checkbox:has(input:checked) {
    background: rgba(255, 117, 20, 0.15);
    border-color: var(--primary);
}

.symbol-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    padding: 4px;
    border-radius: 6px;
    border: 1px solid var(--border);
    object-fit: contain;
}

img.symbol-icon {
    width: 40px;
    height: 40px;
    padding: 4px;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border);
    object-fit: contain;
}

.symbol-checkbox:has(input:checked) .symbol-icon {
    background: var(--primary-light);
    border-color: var(--primary);
}

.symbol-name {
    font-size: 0.85rem;
    color: var(--text-dark);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.95rem;
}

/* ============================================
   PRINT SECTION
   ============================================ */

.print-section {
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef0f2 100%);
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.print-section h3 {
    margin-bottom: 0.75rem;
    font-size: 1rem;
    color: var(--text-dark);
}

.print-section p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.print-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.print-options label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    background: white;
    border-radius: var(--radius);
    border: 2px solid transparent;
    transition: all 0.2s ease;
    margin: 0;
    font-weight: 400;
}

.print-options label:hover {
    border-color: var(--primary-light);
}

.print-options label:has(input:checked) {
    border-color: var(--primary);
    background: rgba(255, 117, 20, 0.05);
}

.print-section .checkbox-label {
    margin-bottom: 1rem;
}

.print-section .btn-primary {
    margin-top: 0.5rem;
}

/* ============================================
   BOX CARD - VERSIONE COMPATTA
   ============================================ */

.box-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.box-info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.box-label {
    color: var(--text-muted);
}

.box-pieces-count {
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-weight: 600;
    color: var(--primary);
}

/* ============================================
   MODAL ACTIONS SPLIT
   ============================================ */

.modal-actions-split {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.modal-actions-right {
    display: flex;
    gap: 0.75rem;
}

.btn-danger {
    padding: 0.625rem 1.25rem;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background: #c82333;
}

/* ============================================
   PACKING VIEW - LAYOUT RIDIMENSIONATO
   ============================================ */

.packing-content {
    flex: 1;
    display: grid;
    grid-template-columns: 180px 1fr 1fr;
    gap: 1.5rem;
    overflow: hidden;
}

.packing-current {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 2px solid var(--primary);
}

.piece-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.piece-card {
    padding: 1rem;
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef0f2 100%);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.piece-number {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--primary);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.current-piece {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: rgba(255, 117, 20, 0.1);
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.current-piece-number {
    background: var(--primary);
    color: white;
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.current-piece-info {
    flex: 1;
}

/* ============================================
   SUB-TABS (Pezzi / Casse)
   ============================================ */

.sub-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.sub-tabs button {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
    margin-bottom: -2px;
}

.sub-tabs button:hover {
    color: var(--primary);
    background: rgba(255, 117, 20, 0.05);
}

.sub-tabs button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* ============================================
   SECTION HEADER
   ============================================ */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.section-header-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-header h3 {
    font-size: 1rem;
    color: var(--text-dark);
    margin: 0;
    white-space: nowrap;
}

/* ============================================
   TAB CONTENT
   ============================================ */

.tab-content {
    animation: fadeIn 0.2s ease;
}

/* ============================================
   EMPTY STATE
   ============================================ */

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    background: var(--bg-light);
    border-radius: 12px;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* ============================================
   ORDER ADDRESS
   ============================================ */

.order-address {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ============================================
   TEXTAREA
   ============================================ */

textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-dark);
    background: var(--bg-white);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: all 0.2s ease;
    resize: vertical;
    min-height: 80px;
}

textarea:hover {
    border-color: #bbb;
}

textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(255, 117, 20, 0.1);
}

/* ============================================
   SYMBOLS GRID - PIÙ SPAZIATO
   ============================================ */

.symbols-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.symbol-checkbox {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.symbol-checkbox:hover {
    background: rgba(255, 117, 20, 0.1);
    border-color: var(--primary-light);
}

.symbol-checkbox:has(input:checked) {
    background: rgba(255, 117, 20, 0.15);
    border-color: var(--primary);
}

/* Ridefinizione per symbols grid più spaziata - sovrascrive */
.symbols-grid .symbol-icon {
    width: 44px;
    height: 44px;
    padding: 6px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border);
    object-fit: contain;
}

.symbols-grid .symbol-checkbox:has(input:checked) .symbol-icon {
    background: var(--primary-light);
    border-color: var(--primary);
}

.symbol-name {
    font-size: 0.9rem;
    color: var(--text-dark);
    font-weight: 500;
}

/* ============================================
   BOX SYMBOLS (nella card) - PIÙ SPAZIATO
   ============================================ */

.box-symbols {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: var(--radius);
}

.box-symbols span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 8px;
    opacity: 0.3;
    transition: all 0.2s ease;
    border-radius: 8px;
    background: white;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.box-symbols span svg {
    width: 100%;
    height: 100%;
}

.box-symbols span:hover {
    opacity: 0.6;
}

.box-symbols input:checked+span {
    opacity: 1;
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 6px rgba(255, 117, 20, 0.3);
}

/* ============================================
   UPPERCASE PER TUTTI I DATI
   ============================================ */

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
    text-transform: uppercase;
}

input::placeholder,
textarea::placeholder {
    text-transform: none;
}

.pieces-table td,
.order-item strong,
.order-item small,
.order-header h2,
.order-header p,
.order-address,
.box-info-row span,
.box-pieces-count,
.piece-card,
.current-piece-info,
.dict-item span {
    text-transform: uppercase;
}

/* ============================================
   TEMPLATES VIEW
   ============================================ */

.templates-view {
    flex: 1;
    padding: 1.5rem;
    background: var(--bg-light);
    overflow-y: auto;
}

.templates-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.templates-section {
    margin-bottom: 2rem;
}

.templates-section h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.template-card {
    background: white;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    transition: all 0.2s ease;
}

.template-card:hover {
    border-color: var(--primary-light);
    box-shadow: 0 4px 12px rgba(255, 117, 20, 0.1);
}

.template-card.custom {
    border-color: var(--primary-light);
}

.template-preview {
    background: #f5f5f5;
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    aspect-ratio: 210 / 297;
    /* A4 ratio */
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-grid {
    display: grid;
    gap: 2px;
    width: 90%;
    height: 90%;
}

.preview-label {
    background: white;
    border: 1px solid #ddd;
    border-radius: 2px;
}

.template-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.template-info strong {
    font-size: 0.95rem;
}

.template-info small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.template-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* Template Modal */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group small {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}

.form-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.info-box {
    background: var(--bg-light);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}

.info-box small {
    color: var(--text-muted);
}

.info-box .text-muted {
    color: var(--text-muted);
    font-style: italic;
}

.template-live-preview {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 1rem;
    margin: 1.5rem 0;
}

.template-live-preview h4 {
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.a4-preview {
    background: white;
    border: 2px solid var(--border);
    aspect-ratio: 210 / 297;
    max-height: 300px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.preview-grid-live {
    display: grid;
    gap: 3px;
    width: 100%;
    height: 100%;
}

.preview-label-live {
    background: rgba(255, 117, 20, 0.2);
    border: 1px solid var(--primary);
    border-radius: 2px;
}

/* Print Template Info */
.print-template-info {
    margin: 0.5rem 0 1rem 0;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 117, 20, 0.1);
    border-radius: 6px;
    border-left: 3px solid var(--primary);
}

.print-template-info small {
    color: var(--text-dark);
    font-size: 0.85rem;
}

.print-section select {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

/* ============================================
   QUANTITY & ACCORDION STYLES
   ============================================ */

/* Riga espandibile */
.pieces-table tr.expandable {
    cursor: pointer;
}

.pieces-table tr.expandable:hover {
    background: rgba(255, 117, 20, 0.08);
}

/* Badge quantità */
.qty-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-light);
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.85rem;
}

.qty-badge.qty-multiple {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    cursor: pointer;
}

/* Icona espansione */
.expand-icon {
    transition: transform 0.2s ease;
}

.expand-icon.rotated {
    transform: rotate(180deg);
}

/* Indicatore range numeri */
.range-indicator {
    color: var(--primary);
    font-weight: 400;
}

/* Sub-rows (righe espanse) */
.sub-row {
    background: rgba(255, 117, 20, 0.03);
    border-left: 3px solid var(--primary-light);
}

.sub-row td {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    font-size: 0.85rem;
}

.sub-row.packed {
    background: rgba(40, 167, 69, 0.05);
    border-left-color: var(--success);
}

.sub-number {
    position: relative;
    padding-left: 1.5rem !important;
    color: var(--text-muted);
}

.sub-connector {
    position: absolute;
    left: 0.75rem;
    top: 0;
    bottom: 50%;
    width: 10px;
    border-left: 2px solid var(--border);
    border-bottom: 2px solid var(--border);
    border-bottom-left-radius: 4px;
}

.sub-info {
    color: var(--text-muted);
    font-style: italic;
}

.sub-label {
    background: var(--bg-light);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Input quantità nel modal */
.quantity-input {
    display: flex;
    align-items: center;
    gap: 0;
    max-width: 150px;
}

.quantity-input input {
    text-align: center;
    border-radius: 0;
    border-left: none;
    border-right: none;
    width: 60px;
    -moz-appearance: textfield;
}

.quantity-input input::-webkit-outer-spin-button,
.quantity-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.qty-btn {
    width: 40px;
    height: 42px;
    border: 2px solid var(--border);
    background: var(--bg-light);
    font-size: 1.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-dark);
}

.qty-btn:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.qty-btn:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.qty-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

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

/* ============================================
   AUTOCOMPLETE WRAPPER
   ============================================ */

.autocomplete-wrapper {
    position: relative;
    width: 100%;
}

.autocomplete-wrapper input {
    width: 100%;
}

/* Nasconde l'icona del datalist in alcuni browser */
input::-webkit-calendar-picker-indicator {
    display: none !important;
}

input[list]::-webkit-list-button {
    display: none !important;
}

/* ============================================
   PACKING VIEW - COPY BADGE
   ============================================ */

.piece-copy-badge {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
}

.piece-card {
    position: relative;
}

.current-piece-info small {
    color: var(--text-muted);
    font-style: italic;
}

/* ============================================
   MODAL PDF COMPATTATO - LAYOUT INLINE
   ============================================ */

.modal-large h2 {
    margin-bottom: 1rem;
    font-size: 1.15rem;
}

.modal-large .print-section {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
}

.modal-large .print-section h3 {
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}

/* Riga 1: Label + Select inline */
.print-row-inline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.print-row-inline label {
    white-space: nowrap;
    font-size: 0.85rem;
    font-weight: 500;
    margin: 0;
    color: var(--text-dark);
}

.print-row-inline select {
    flex: 1;
    padding: 0.45rem 0.7rem;
    font-size: 0.85rem;
    min-width: 0;
}

/* Riga 2: Nota + Bottone inline */
.print-row-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.print-row-action .print-template-info {
    flex: 1;
    margin: 0;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    background: rgba(255, 117, 20, 0.08);
    border-left: 3px solid var(--primary);
    border-radius: 0 4px 4px 0;
}

.print-row-action .print-template-info small {
    font-size: 0.75rem;
    color: var(--text-dark);
}

.print-row-action .btn-primary {
    white-space: nowrap;
    padding: 0.45rem 0.875rem;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* Sezione Packing List */
.print-section-packing .print-options {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 0.5rem;
}

.print-section-packing .print-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    margin: 0;
    cursor: pointer;
}

.print-section-packing .print-row-action {
    margin-top: 0.5rem;
}

.print-section-packing .checkbox-label {
    font-size: 0.85rem;
    margin: 0;
}

.print-section-packing .checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.modal-large .modal-actions {
    margin-top: 1rem;
    padding-top: 1rem;
}

/* ============================================
   FILTRI COLONNE TABELLA
   ============================================ */

.th-filterable {
    cursor: pointer;
    position: relative;
    user-select: none;
}

.th-filterable:hover {
    background: rgba(255, 117, 20, 0.1);
}

.th-filter-icon {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.th-filterable:hover .th-filter-icon,
.th-filterable.filter-active .th-filter-icon {
    opacity: 1;
}

.th-filterable.filter-active .th-filter-icon {
    color: var(--primary);
}

.filter-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    padding: 0.5rem 0;
}

.filter-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.filter-dropdown-item:hover {
    background: rgba(255, 117, 20, 0.1);
}

.filter-dropdown-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.filter-dropdown-item span {
    font-size: 0.85rem;
    text-transform: uppercase;
}

.filter-dropdown-actions {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

.filter-dropdown-actions button {
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}

.filter-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* ============================================
   BARRA RICERCA IMBALLAGGIO
   ============================================ */

.packing-search {
    margin-bottom: 0.5rem;
}

.packing-search input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    font-size: 0.9rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.75rem center;
}

.search-highlight {
    background: rgba(255, 117, 20, 0.3);
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
}

/* Badge per pezzi gia imballati - stili gestiti nella sezione dedicata sopra */

/* ============================================
   TAB CONTENT SCROLL
   ============================================ */

.tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.tab-content .pieces-table-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.section-header {
    flex-shrink: 0;
}

/* ============================================
   ACTIVE FILTERS BAR (inline con header)
   ============================================ */

.active-filters-bar {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-left: 1.5rem;
}

.active-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 117, 20, 0.15);
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.25rem 0.5rem 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.active-filter-tag button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
    opacity: 0.7;
}

.active-filter-tag button:hover {
    opacity: 1;
}

.clear-all-filters {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
}

.clear-all-filters:hover {
    color: var(--danger);
}

/* ============================================
   SCROLLBAR MODERNE AUTO-NASCONDIBILI
   ============================================ */

/* Contenitori con scroll */
.orders-list,
.pieces-table-wrapper,
.packing-boxes .box-buttons,
.packing-pieces .piece-cards,
.packing-current .current-pieces,
.boxes-grid,
.filter-dropdown,
.modal {
    /* Firefox */
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
    transition: scrollbar-color 0.3s ease;
}

/* Mostra scrollbar su hover e scroll (Firefox) */
.orders-list:hover,
.orders-list:focus-within,
.pieces-table-wrapper:hover,
.pieces-table-wrapper:focus-within,
.packing-boxes .box-buttons:hover,
.packing-pieces .piece-cards:hover,
.packing-current .current-pieces:hover,
.boxes-grid:hover,
.filter-dropdown:hover,
.modal:hover {
    scrollbar-color: rgba(255, 117, 20, 0.4) transparent;
}

/* Webkit (Chrome, Safari, Edge) */
.orders-list::-webkit-scrollbar,
.pieces-table-wrapper::-webkit-scrollbar,
.packing-boxes .box-buttons::-webkit-scrollbar,
.packing-pieces .piece-cards::-webkit-scrollbar,
.packing-current .current-pieces::-webkit-scrollbar,
.boxes-grid::-webkit-scrollbar,
.filter-dropdown::-webkit-scrollbar,
.modal::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.orders-list::-webkit-scrollbar-track,
.pieces-table-wrapper::-webkit-scrollbar-track,
.packing-boxes .box-buttons::-webkit-scrollbar-track,
.packing-pieces .piece-cards::-webkit-scrollbar-track,
.packing-current .current-pieces::-webkit-scrollbar-track,
.boxes-grid::-webkit-scrollbar-track,
.filter-dropdown::-webkit-scrollbar-track,
.modal::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 10px;
    margin: 4px;
}

.orders-list::-webkit-scrollbar-thumb,
.pieces-table-wrapper::-webkit-scrollbar-thumb,
.packing-boxes .box-buttons::-webkit-scrollbar-thumb,
.packing-pieces .piece-cards::-webkit-scrollbar-thumb,
.packing-current .current-pieces::-webkit-scrollbar-thumb,
.boxes-grid::-webkit-scrollbar-thumb,
.filter-dropdown::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 10px;
    transition: background 0.3s ease;
}

/* Mostra scrollbar su hover (Webkit) */
.orders-list:hover::-webkit-scrollbar-thumb,
.pieces-table-wrapper:hover::-webkit-scrollbar-thumb,
.packing-boxes .box-buttons:hover::-webkit-scrollbar-thumb,
.packing-pieces .piece-cards:hover::-webkit-scrollbar-thumb,
.packing-current .current-pieces:hover::-webkit-scrollbar-thumb,
.boxes-grid:hover::-webkit-scrollbar-thumb,
.filter-dropdown:hover::-webkit-scrollbar-thumb,
.modal:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 117, 20, 0.6);
}

/* Scrollbar più visibile su hover diretto */
.orders-list::-webkit-scrollbar-thumb:hover,
.pieces-table-wrapper::-webkit-scrollbar-thumb:hover,
.packing-boxes .box-buttons::-webkit-scrollbar-thumb:hover,
.packing-pieces .piece-cards::-webkit-scrollbar-thumb:hover,
.packing-current .current-pieces::-webkit-scrollbar-thumb:hover,
.boxes-grid::-webkit-scrollbar-thumb:hover,
.filter-dropdown::-webkit-scrollbar-thumb:hover,
.modal::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 117, 20, 0.7);
}

/* Scrollbar attiva (durante il drag) */
.orders-list::-webkit-scrollbar-thumb:active,
.pieces-table-wrapper::-webkit-scrollbar-thumb:active,
.packing-boxes .box-buttons::-webkit-scrollbar-thumb:active,
.packing-pieces .piece-cards::-webkit-scrollbar-thumb:active,
.packing-current .current-pieces::-webkit-scrollbar-thumb:active,
.boxes-grid::-webkit-scrollbar-thumb:active,
.filter-dropdown::-webkit-scrollbar-thumb:active,
.modal::-webkit-scrollbar-thumb:active {
    background: var(--primary);
}

/* Angoli arrotondati per contenitori con bordi arrotondati */
.packing-boxes .box-buttons::-webkit-scrollbar-track,
.packing-pieces .piece-cards::-webkit-scrollbar-track,
.packing-current .current-pieces::-webkit-scrollbar-track {
    margin: 8px 4px;
}

/* Scrollbar corner (angolo in basso a destra se scroll sia X che Y) */
.orders-list::-webkit-scrollbar-corner,
.pieces-table-wrapper::-webkit-scrollbar-corner,
.packing-boxes .box-buttons::-webkit-scrollbar-corner,
.packing-pieces .piece-cards::-webkit-scrollbar-corner,
.packing-current .current-pieces::-webkit-scrollbar-corner,
.boxes-grid::-webkit-scrollbar-corner,
.filter-dropdown::-webkit-scrollbar-corner,
.modal::-webkit-scrollbar-corner {
    background: transparent;
}

/* Scrollbar sovrapposta al contenuto */
.orders-list,
.pieces-table-wrapper,
.packing-boxes .box-buttons,
.packing-pieces .piece-cards,
.packing-current .current-pieces,
.boxes-grid {
    overflow-y: overlay;
}

/* Fallback per browser che non supportano overlay */
@supports not (overflow-y: overlay) {

    .orders-list,
    .pieces-table-wrapper,
    .packing-boxes .box-buttons,
    .packing-pieces .piece-cards,
    .packing-current .current-pieces,
    .boxes-grid {
        overflow-y: auto;
    }
}

/* Variante più sottile per dropdown filtri */
.filter-dropdown::-webkit-scrollbar {
    width: 4px;
}

.filter-dropdown::-webkit-scrollbar-thumb {
    border-radius: 4px;
}

/* Opzioni generali etichette */
.print-section-options {
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--bg-light);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

.print-section-options .checkbox-label {
    font-size: 0.85rem;
    margin: 0;
    color: var(--text-muted);
}

/* ============================================
   HIGHLIGHT NUOVA RIGA
   ============================================ */

@keyframes highlightFade {
    0% {
        background-color: rgba(255, 117, 20, 0.3);
    }

    100% {
        background-color: transparent;
    }
}

.pieces-table tr.highlight-new {
    animation: highlightFade 2s ease-out;
}

/* ============================================
   BACKUP VIEW
   ============================================ */

.backup-view {
    flex: 1;
    padding: 2rem;
    background: var(--bg-light);
    overflow-y: auto;
}

.backup-container {
    max-width: 800px;
    margin: 0 auto;
}

.backup-container h2 {
    margin-bottom: 2rem;
    color: var(--text-dark);
    font-size: 1.5rem;
}

.backup-section {
    background: white;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.backup-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef0f2 100%);
    border-bottom: 1px solid var(--border);
}

.backup-section-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.backup-section-content {
    padding: 1.5rem;
}

.backup-info {
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.backup-stats {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--bg-light);
    border-radius: var(--radius);
}

.backup-stats span {
    font-size: 0.9rem;
    color: var(--text-dark);
}

.backup-stats strong {
    color: var(--primary);
}

.backup-last {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    transition: all 0.2s ease;
    margin-bottom: 1rem;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--primary);
    background: rgba(255, 117, 20, 0.05);
}

.upload-area.has-file {
    border-style: solid;
    border-color: var(--success);
    background: rgba(40, 167, 69, 0.05);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
}

.upload-placeholder svg {
    opacity: 0.5;
}

.upload-placeholder p {
    margin: 0;
}

.upload-file-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: center;
}

.upload-file-info svg {
    color: var(--success);
}

.file-details {
    text-align: left;
}

.file-details strong {
    display: block;
    color: var(--text-dark);
}

.file-details small {
    color: var(--text-muted);
}

/* Import Preview */
.import-preview {
    background: var(--bg-light);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h4 {
    margin: 0;
    font-size: 1rem;
}

.validation-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.validation-badge.valid {
    background: rgba(40, 167, 69, 0.15);
    color: var(--success);
}

.validation-badge.invalid {
    background: rgba(220, 53, 69, 0.15);
    color: var(--danger);
}

.preview-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-item {
    flex: 1;
    text-align: center;
    padding: 0.75rem;
    background: white;
    border-radius: var(--radius);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.preview-table th,
.preview-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.preview-table th {
    background: white;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.preview-more {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.preview-error {
    color: var(--danger);
    padding: 1rem;
    background: rgba(220, 53, 69, 0.1);
    border-radius: var(--radius);
}

/* Import Options */
.import-options {
    margin-bottom: 1rem;
    padding: 1rem;
    background: rgba(255, 117, 20, 0.1);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}

/* Import Result */
.import-result {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    font-weight: 500;
}

.import-result.success {
    background: rgba(40, 167, 69, 0.15);
    color: var(--success);
}

.import-result.error {
    background: rgba(220, 53, 69, 0.15);
    color: var(--danger);
}

/* Test Badge */
.test-badge {
    padding: 0.25rem 0.75rem;
    background: var(--warning);
    color: #856404;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* Verify Actions */
.verify-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Verify Result */
.verify-result {
    margin-top: 1rem;
    padding: 1.25rem;
    border-radius: var(--radius);
}

.verify-result.success {
    background: rgba(40, 167, 69, 0.1);
    border: 1px solid var(--success);
}

.verify-result.error {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid var(--danger);
}

.verify-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.verify-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.verify-icon.success {
    background: var(--success);
    color: white;
}

.verify-icon.error {
    background: var(--danger);
    color: white;
}

.verify-details {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.verify-details p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Button with icon */
.backup-section .btn-primary,
.backup-section .btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.backup-section .btn-primary svg,
.backup-section .btn-danger svg {
    flex-shrink: 0;
}

/* ============================================
   RESPONSIVE PACKING
   ============================================ */

@media (max-width: 1200px) {
    .packing-content {
        grid-template-columns: 150px 1fr 1fr;
    }
}

@media (max-width: 1024px) {
    .packing-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
    }

    .packing-current {
        min-height: 200px;
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
    .packing-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .packing-boxes {
        order: 1;
    }

    .box-buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .box-btn {
        flex: 1;
        min-width: 100px;
    }

    .packing-pieces {
        order: 2;
    }

    .packing-current {
        order: 3;
    }
}

@media (max-width: 768px) {
    .orders-view {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 200px;
    }

    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .tabs {
        padding: 0 1rem;
        overflow-x: auto;
    }

    .order-header {
        flex-direction: column;
        gap: 1rem;
    }

    .order-actions {
        flex-wrap: wrap;
    }
}

/* ============================================
   DISABILITA ZOOM SU TOUCH (TABLET)
   ============================================ */

/* Previeni zoom doppio tap su tutti gli elementi */
* {
    touch-action: manipulation;
}

/* Previeni selezione testo accidentale su touch nella vista packing */
.packing-view {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: pan-x pan-y;
}

/* Input ricerca deve permettere selezione */
.packing-search input {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    touch-action: auto;
}