/* ===============================================
   === STYLE.CSS - STILE PIDUEMME v2.3 ===========
   ===============================================
   Design coerente con odoo-modifiche-schede
   Colori: Verde #36a763, Verde scuro #125632
   Font: Ubuntu
*/

/* --- RESET E VARIABILI --- */
@import url("https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;500;700&display=swap");

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

:root {
    /* Colori Piduemme */
    --color-primary: #36a763;
    --color-primary-dark: #125632;
    --color-primary-light: #4db87a;
    --color-primary-hover: #2d8a52;

    /* Colori UI */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f5;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;

    /* Colori Stato */
    --color-success: #36a763;
    --color-warning: #ff9800;
    --color-danger: #dc3545;
    --color-info: #17a2b8;

    /* Badge operazioni */
    --color-estrusione: #dc3545;
    --color-saldatura: #9365b8;
    --color-stampa: #d6145f;

    /* Dimensioni */
    --header-height: 60px;
    --toolbar-height: 60px;
    --card-min-width: 220px;
    --card-max-width: 300px;
    --spacing: 20px;
    --spacing-sm: 10px;
    --spacing-lg: 30px;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Ombre */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);

    /* Transizioni */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* --- DARK MODE --- */
[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #b8b8b8;
    --text-muted: #666666;
    --border-color: #333355;
    --color-primary-dark: #2d8a52;
}

/* --- BASE --- */
body {
    font-family:
        "Ubuntu",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition:
        background-color var(--transition-normal),
        color var(--transition-normal);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

.hidden {
    display: none !important;
}

/* --- HEADER --- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing);
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing);
}

.header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background var(--transition-fast);
    color: white;
}

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

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-warning);
    animation: pulse 1.5s infinite;
}

.status-dot.connected {
    background: #90ee90;
    animation: none;
}

.status-dot.error {
    background: var(--color-danger);
    animation: none;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* --- TOOLBAR --- */
.toolbar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: var(--toolbar-height);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    padding: 0 var(--spacing);
    gap: var(--spacing);
    z-index: 99;
    box-shadow: var(--shadow-sm);
}

.search-bar {
    flex: 1;
    max-width: 400px;
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0 14px;
    height: 42px;
    transition: border-color var(--transition-fast);
}

.search-bar:focus-within {
    border-color: var(--color-primary);
}

.search-icon {
    margin-right: 10px;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.search-bar input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 1rem;
    font-family: "Ubuntu", sans-serif;
    color: var(--text-primary);
    outline: none;
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.search-clear {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 1.1rem;
}

.btn-scan {
    background: var(--color-primary);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px 12px;
    font-size: 1.2rem;
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
}

.btn-scan:hover {
    background: var(--color-primary-dark);
    transform: scale(1.05);
}

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

/* Modal Scanner */
.modal-scanner {
    width: 95%;
    max-width: 500px;
}

.modal-scanner .modal-body {
    padding: var(--spacing);
    padding-top: 0;
}

#scannerContainer {
    width: 100%;
    min-height: 350px;
    background: #000;
    border-radius: var(--border-radius);
    overflow: hidden;
}

/* Stile per l'area di scansione della libreria */
#scannerContainer video {
    border-radius: var(--border-radius);
}

#scannerContainer #qr-shaded-region {
    border-color: rgba(76, 175, 80, 0.5) !important;
}

.scanner-hint {
    text-align: center;
    color: var(--text-secondary);
    margin-top: var(--spacing);
    font-size: 0.95rem;
    padding: 10px;
    background: #f5f5f5;
    border-radius: var(--border-radius);
}

.scanner-hint::before {
    content: "📷 ";
}

/* Pulsante torcia scanner */
.torch-btn {
    display: block;
    width: 100%;
    margin-top: var(--spacing-sm);
    padding: 12px;
    font-size: 1rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    transition: all 0.2s ease;
}

.torch-btn.active {
    background: #fff3e0;
    border-color: #ff9800;
    color: #e65100;
}

.toolbar-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing);
}

.auto-refresh-control {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.control-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.refresh-select {
    padding: 6px 10px;
    border-radius: 6px;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: "Ubuntu", sans-serif;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: var(--transition-fast);
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-fast);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--color-primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: "Ubuntu", sans-serif;
    transition: background var(--transition-fast);
}

.toolbar-btn:hover {
    background: var(--color-primary-hover);
}

.toolbar-btn:active {
    transform: scale(0.98);
}

.toolbar-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: calc(var(--toolbar-height) - 4px);
    left: var(--spacing);
    right: var(--spacing);
    max-width: 500px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow: hidden;
    z-index: 200;
    border: 1px solid var(--color-primary);
}

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px var(--spacing);
    background: var(--color-primary);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
}

.btn-close-search {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.btn-close-search:hover {
    background: rgba(255, 255, 255, 0.3);
}

.search-results-list {
    overflow-y: auto;
    max-height: 340px;
}

.search-result-item {
    padding: 14px var(--spacing);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.search-result-item:hover {
    background: #e8f5e9;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-name {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--color-primary-dark);
}

.search-result-details {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.search-result-state {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.search-result-state.ready {
    background: #e3f2fd;
    color: #1565c0;
}

.search-result-state.progress {
    background: #e8f5e9;
    color: var(--color-primary-dark);
}

/* --- MAIN CONTENT --- */
.main-content {
    margin-top: calc(var(--header-height) + var(--toolbar-height));
    padding: var(--spacing);
    min-height: calc(100vh - var(--header-height) - var(--toolbar-height));
}

/* --- SECTIONS --- */
.step-section {
    margin-bottom: var(--spacing-lg);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--spacing);
    margin-bottom: var(--spacing);
    padding-bottom: var(--spacing);
    border-bottom: 2px solid var(--color-primary);
}

.section-header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing);
}

.section-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-primary-dark);
}

.highlight {
    color: var(--color-primary);
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: "Ubuntu", sans-serif;
    transition: all var(--transition-fast);
}

.btn-back:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Filters */
.filters {
    display: flex;
    gap: var(--spacing);
    flex-wrap: wrap;
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}

.filter-toggle:hover {
    border-color: var(--color-primary);
}

.filter-toggle input {
    cursor: pointer;
    accent-color: var(--color-primary);
    width: 16px;
    height: 16px;
}

/* Tooltip per filtri */
.filter-toggle[title] {
    position: relative;
}

/* --- TABS --- */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: var(--spacing);
    background: var(--bg-tertiary);
    padding: 6px;
    border-radius: var(--border-radius);
    width: fit-content;
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    font-family: "Ubuntu", sans-serif;
    transition: all var(--transition-fast);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    background: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.tab-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
}

.tab.active .tab-count {
    background: rgba(255, 255, 255, 0.25);
}

.tab-content {
    min-height: 200px;
}

.active-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing);
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    display: inline-block;
    box-shadow: var(--shadow-sm);
}

.active-info:empty {
    display: none;
}

/* --- KANBAN GRID --- */
.kanban-grid {
    display: grid;
    grid-template-columns: repeat(
        auto-fill,
        minmax(var(--card-min-width), var(--card-max-width))
    );
    gap: var(--spacing);
}

/* Vista compatta */
.compact .kanban-grid {
    --card-min-width: 180px;
    --card-max-width: 220px;
    gap: var(--spacing-sm);
}

.compact .workorder-card {
    min-height: auto;
    padding: var(--spacing-sm);
}

.compact .workorder-card .card-details,
.compact .workorder-card .card-state {
    display: none;
}

.compact .workorder-card .card-name {
    font-size: 0.9rem;
}

/* --- WORKCENTER CARD --- */
.workcenter-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 5px solid var(--color-primary);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.workcenter-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.workcenter-card:active {
    transform: scale(0.98);
}

/* Sfondi per tipo operazione */
.workcenter-card.op-estrusione {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-left-color: #4caf50;
}
.workcenter-card.op-estrusione:hover {
    background: linear-gradient(135deg, #c8e6c9 0%, #a5d6a7 100%);
}

.workcenter-card.op-saldatura {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-left-color: #ff9800;
}
.workcenter-card.op-saldatura:hover {
    background: linear-gradient(135deg, #ffe0b2 0%, #ffcc80 100%);
}

.workcenter-card.op-stampa {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-left-color: #2196f3;
}
.workcenter-card.op-stampa:hover {
    background: linear-gradient(135deg, #bbdefb 0%, #90caf9 100%);
}

.workcenter-card .card-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--color-primary-dark);
}

.workcenter-card .card-code {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.workcenter-card .card-counts {
    display: flex;
    gap: 10px;
    margin-top: auto;
}

.workcenter-card .count-badge {
    font-size: 0.8rem;
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
}

.count-badge.ready {
    background: #e3f2fd;
    color: #1565c0;
}

.count-badge.active {
    background: #e8f5e9;
    color: var(--color-primary-dark);
}

/* --- WORKORDER CARD --- */
.workorder-card {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 5px solid var(--color-primary);
    min-height: 150px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.workorder-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.workorder-card:active {
    transform: scale(0.98);
}

.workorder-card.active {
    border-left-color: var(--color-success);
    background: linear-gradient(to right, rgba(54, 167, 99, 0.05), transparent);
}

.workorder-card.other-workcenter {
    border-left-color: var(--color-warning);
}

.workorder-card .card-header {
    margin-bottom: 10px;
}

.workorder-card .card-name {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 6px;
    color: var(--color-primary-dark);
}

.workorder-card .card-product {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.workorder-card .card-workcenter {
    font-size: 0.75rem;
    margin-top: 8px;
    padding: 4px 10px;
    border-radius: 4px;
    display: inline-block;
    font-weight: 500;
}

.card-workcenter.same {
    background: #e8f5e9;
    color: var(--color-primary-dark);
}

.card-workcenter.different {
    background: #fff3e0;
    color: #e65100;
    font-weight: 600;
}

.workorder-card .card-details {
    margin-top: auto;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.workorder-card .card-timer {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 0.8rem;
    padding: 4px 10px;
    background: var(--color-primary);
    color: white;
    border-radius: 6px;
    font-weight: 700;
    font-family: "Ubuntu Mono", "SF Mono", Monaco, monospace;
}

.workorder-card .card-state {
    margin-top: 10px;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-block;
    width: fit-content;
    letter-spacing: 0.5px;
}

.card-state.ready {
    background: #e3f2fd;
    color: #1565c0;
}

.card-state.progress {
    background: #e8f5e9;
    color: var(--color-primary-dark);
}

/* --- EMPTY & LOADING STATES --- */
.empty-state,
.loading-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px var(--spacing);
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
}

.empty-state .empty-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing);
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    margin: 0 auto var(--spacing);
    animation: spin 1s linear infinite;
}

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

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--spacing);
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing);
    background: var(--color-primary);
    color: white;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 1.3rem;
    color: white;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    line-height: 1;
}

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

.modal-body {
    padding: var(--spacing);
}

.modal-workorder-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: var(--spacing);
    background: var(--bg-tertiary);
    padding: var(--spacing);
    border-radius: var(--border-radius);
}

.info-row {
    display: flex;
    gap: 10px;
}

.info-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 130px;
    font-weight: 500;
}

.info-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Pulsanti workcenter nel modale */
.modal-workcenter-buttons {
    padding: 14px;
    background: #f5f5f5;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing);
}

.workcenter-buttons-title {
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.workcenter-buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.wc-btn {
    padding: 14px 12px;
    font-size: 0.95rem;
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.wc-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Pulsanti compatibili */
.wc-btn-compatible {
    background: #e8f5e9;
    border-color: #4caf50;
    color: #2e7d32;
}

.wc-btn-compatible:hover:not(:disabled) {
    background: #c8e6c9;
    transform: scale(1.02);
}

.wc-btn-compatible:active:not(:disabled) {
    transform: scale(0.98);
}

/* Pulsanti incompatibili */
.wc-btn-incompatible {
    background: #fff3e0;
    border-color: #ff9800;
    color: #e65100;
}

.wc-btn-incompatible:hover:not(:disabled) {
    background: #ffe0b2;
    transform: scale(1.02);
}

/* Colori per tipo operazione sui pulsanti */
.wc-btn.op-estrusione {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-color: #4caf50;
}

.wc-btn.op-saldatura {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-color: #ff9800;
}

.wc-btn.op-stampa {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-color: #2196f3;
}

.modal-warning {
    display: flex;
    gap: 12px;
    padding: 14px;
    background: #fff3e0;
    border: 2px solid var(--color-warning);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing);
}

.warning-icon {
    font-size: 1.4rem;
}

.warning-text {
    font-size: 0.9rem;
    color: #e65100;
    font-weight: 500;
}

.modal-error {
    display: flex;
    gap: 12px;
    padding: 14px;
    background: #ffebee;
    border: 2px solid var(--color-danger);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing);
}

.modal-error .warning-text {
    color: #c62828;
}

.modal-notes {
    margin-top: var(--spacing);
    padding: var(--spacing);
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
}

.modal-notes h4 {
    font-size: 0.9rem;
    color: var(--color-primary-dark);
    margin-bottom: 10px;
}

.notes-content {
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

.modal-actions {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

/* --- BUTTONS --- */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: "Ubuntu", sans-serif;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex: 1;
    min-width: 100px;
}

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

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

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

.btn-success:hover {
    background: #2d8a52;
}

.btn-warning {
    background: var(--color-warning);
    color: #212529;
}

.btn-warning:hover {
    background: #e68900;
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.btn-info {
    background: var(--color-info);
    color: white;
}

.btn-info:hover {
    background: #138496;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- TIME TRACKING --- */
.time-tracking {
    margin-top: var(--spacing);
}

.time-tracking h4 {
    font-size: 0.95rem;
    color: var(--color-primary-dark);
    margin-bottom: var(--spacing-sm);
}

.time-tracking-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.time-log-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 0.85rem;
}

.time-log-date {
    color: var(--text-secondary);
}

.time-log-duration {
    font-weight: 700;
    color: var(--color-primary);
}

/* --- TOAST --- */
.toast-container {
    position: fixed;
    bottom: var(--spacing);
    right: var(--spacing);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 380px;
    font-size: 0.95rem;
    font-weight: 500;
}

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

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

.toast.warning {
    background: var(--color-warning);
    color: #212529;
}

.toast.info {
    background: var(--color-info);
    color: white;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* --- BADGE OPERAZIONI --- */
.workcenter-type-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    margin-left: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.workcenter-type-badge.estrusione {
    background: var(--color-estrusione);
    color: white;
}

.workcenter-type-badge.saldatura {
    background: var(--color-saldatura);
    color: white;
}

.workcenter-type-badge.stampa {
    background: var(--color-stampa);
    color: white;
}

.operation-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.operation-badge.estrusione {
    background: var(--color-estrusione);
    color: white;
}

.operation-badge.saldatura {
    background: var(--color-saldatura);
    color: white;
}

.operation-badge.stampa {
    background: var(--color-stampa);
    color: white;
}

/* Card incompatibile */
.workorder-card.incompatible {
    opacity: 0.6;
    border-left-color: var(--color-danger) !important;
    background: repeating-linear-gradient(
        -45deg,
        var(--bg-secondary),
        var(--bg-secondary) 10px,
        rgba(220, 53, 69, 0.06) 10px,
        rgba(220, 53, 69, 0.06) 20px
    ) !important;
}

.workorder-card.incompatible:hover {
    opacity: 0.8;
}

/* --- CACHE INFO (opzionale, per debug) --- */
.cache-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: auto;
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    :root {
        --card-min-width: 160px;
        --card-max-width: 1fr;
        --spacing: 15px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .toolbar {
        flex-wrap: wrap;
        height: auto;
        padding: var(--spacing-sm);
        gap: var(--spacing-sm);
    }

    .search-bar {
        flex: 1 1 100%;
        max-width: none;
    }

    .toolbar-controls {
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .btn-text {
        display: none;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .filters {
        flex-wrap: wrap;
    }

    .modal {
        margin: var(--spacing-sm);
        max-height: calc(100vh - 32px);
    }

    .modal-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .tabs {
        width: 100%;
    }

    .tab {
        flex: 1;
        justify-content: center;
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .auto-refresh-control .control-label {
        display: none;
    }

    .header-btn {
        width: 36px;
        height: 36px;
    }

    .connection-status .status-text {
        display: none;
    }
}

/* ===============================================
   === SCHEDE TECNICHE (SPECS) EDITOR ============
   =============================================== */

/* Modal specifico per schede tecniche */
.modal-specs {
    max-width: 900px;
}

.modal-body-scroll {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    padding: var(--spacing);
}

/* Badge modifiche non salvate */
.badge-changes {
    background: var(--color-warning);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: auto;
    margin-right: var(--spacing);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Sezione info MO */
.specs-info-section {
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    padding: var(--spacing);
    margin-bottom: var(--spacing);
}

/* Layout a righe per info MO */
.specs-info-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm) var(--spacing);
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
}

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

.specs-info-row-full {
    display: block;
}

.info-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 150px;
}

.info-cell-small {
    flex: 0 0 auto;
    min-width: auto;
}

.info-cell-full {
    width: 100%;
    flex: none;
}

.info-cell-full .info-value,
.info-cell-full .click-to-edit {
    flex: 1;
    font-size: 1.1em;
    font-weight: 600;
}

.info-cell-full .click-to-edit-input {
    flex: 1;
    font-size: 1.1em;
}

.specs-info-section .info-label {
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 80px;
}

.specs-info-section .info-value {
    font-weight: 600;
    color: var(--text-primary);
}

.info-uom {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Click to edit */
.click-to-edit {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition-fast);
    border: 1px dashed transparent;
}

.click-to-edit:hover {
    background: rgba(54, 167, 99, 0.1);
    border-color: var(--color-primary);
}

.click-to-edit.modified {
    background: #fff3cd;
    border-color: var(--color-warning);
}

[data-theme="dark"] .click-to-edit.modified {
    background: rgba(255, 152, 0, 0.2);
}

.click-to-edit-input {
    padding: 4px 8px;
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    font-family: inherit;
    font-size: inherit;
    font-weight: 600;
    width: 200px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.click-to-edit-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(54, 167, 99, 0.2);
}

/* State badge */
.state-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.state-badge.draft {
    background: #e9ecef;
    color: #495057;
}
.state-badge.confirmed {
    background: #cce5ff;
    color: #004085;
}
.state-badge.progress {
    background: #d4edda;
    color: #155724;
}
.state-badge.done {
    background: var(--color-primary);
    color: white;
}
.state-badge.cancel {
    background: #f8d7da;
    color: #721c24;
}

/* Sezioni specs e BOM */
.specs-section,
.bom-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing);
    margin-bottom: var(--spacing);
}

.specs-section h4,
.bom-section h4 {
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Tabelle */
.specs-table,
.bom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.specs-table th,
.specs-table td,
.bom-table th,
.bom-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.specs-table th,
.bom-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.specs-table tbody tr:hover,
.bom-table tbody tr:hover {
    background: rgba(54, 167, 99, 0.05);
}

/* Colonne azioni */
.col-actions {
    width: 60px;
    text-align: center;
}

.col-qty {
    width: 120px;
}

/* Input nelle tabelle */
.specs-table input,
.specs-table select,
.specs-table textarea,
.bom-table input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.specs-table textarea {
    min-height: 40px;
    resize: vertical;
    line-height: 1.4;
}

.specs-table input:focus,
.specs-table select:focus,
.specs-table textarea:focus,
.bom-table input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(54, 167, 99, 0.15);
}

/* Righe modificate/nuove/eliminate */
.specs-table tr.modified,
.bom-table tr.modified {
    background: #fff3cd !important;
}

.specs-table tr.new-row,
.bom-table tr.new-row {
    background: #d4edda !important;
}

.specs-table tr.deleted-row,
.bom-table tr.deleted-row {
    background: #f8d7da !important;
    text-decoration: line-through;
    opacity: 0.7;
}

[data-theme="dark"] .specs-table tr.modified,
[data-theme="dark"] .bom-table tr.modified {
    background: rgba(255, 152, 0, 0.15) !important;
}

[data-theme="dark"] .specs-table tr.new-row,
[data-theme="dark"] .bom-table tr.new-row {
    background: rgba(54, 167, 99, 0.15) !important;
}

[data-theme="dark"] .specs-table tr.deleted-row,
[data-theme="dark"] .bom-table tr.deleted-row {
    background: rgba(220, 53, 69, 0.15) !important;
}

/* Bottoni nelle tabelle */
.btn-delete {
    background: none;
    border: none;
    color: var(--color-danger);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 1rem;
    transition: background var(--transition-fast);
}

.btn-delete:hover {
    background: rgba(220, 53, 69, 0.1);
}

.btn-delete:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Azioni sotto le tabelle */
.specs-actions {
    margin-top: var(--spacing-sm);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-outline {
    background: transparent;
    border: 1px dashed var(--color-primary);
    color: var(--color-primary);
}

.btn-outline:hover {
    background: rgba(54, 167, 99, 0.1);
    border-style: solid;
}

/* Totale BOM */
.bom-total-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    font-weight: 600;
    border-top: 2px solid var(--border-color);
    margin-top: var(--spacing-sm);
}

.bom-total-value {
    font-size: 1.1rem;
    padding: 4px 12px;
    border-radius: 4px;
}

.bom-total-value.valid {
    background: #d4edda;
    color: #155724;
}

.bom-total-value.invalid {
    background: #f8d7da;
    color: #721c24;
}

/* Ricerca prodotti dropdown */
.product-search-container {
    position: relative;
}

.product-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: var(--shadow-md);
    display: none;
}

.product-search-results.active {
    display: block;
}

.product-search-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.product-search-item:last-child {
    border-bottom: none;
}

.product-search-item:hover {
    background: rgba(54, 167, 99, 0.1);
}

.product-search-loading {
    padding: 10px 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* Responsive schede tecniche */
@media (max-width: 768px) {
    .modal-specs {
        margin: var(--spacing-sm);
    }

    .specs-info-row {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .info-cell {
        min-width: 100%;
    }

    .specs-table,
    .bom-table {
        font-size: 0.8rem;
    }

    .specs-table th,
    .specs-table td,
    .bom-table th,
    .bom-table td {
        padding: 8px;
    }

    .col-actions {
        width: 40px;
    }
}

/* Stile default (Piduemme) - Mobile specs layout */
@media (max-width: 600px) {
    .modal-specs {
        margin: 0;
        max-height: 100vh;
        height: 100%;
        max-width: 100%;
    }

    .specs-table,
    .bom-table {
        display: block;
    }

    .specs-table thead,
    .bom-table thead {
        display: none;
    }

    .specs-table tbody,
    .bom-table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .specs-table tr,
    .bom-table tr {
        display: flex;
        flex-direction: column;
        background: var(--bg-tertiary);
        padding: 16px;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius);
        position: relative;
    }

    .specs-table td,
    .bom-table td {
        display: flex;
        flex-direction: column;
        padding: 8px 0;
        border: none;
        width: 100% !important;
    }

    /* Label sopra ogni campo */
    .specs-table td::before,
    .bom-table td::before {
        font-size: 0.7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-secondary);
        margin-bottom: 4px;
    }

    /* Labels per specifiche tecniche */
    .specs-table td:nth-child(1)::before { content: "Tipo Macchina"; }
    .specs-table td:nth-child(2)::before { content: "Chiave"; }
    .specs-table td:nth-child(3)::before { content: "Valore"; }

    /* Labels per BOM */
    .bom-table td:nth-child(1)::before { content: "Prodotto"; }
    .bom-table td:nth-child(2)::before { content: "Quantità %"; }

    /* Colonna azioni - posiziona in alto a destra */
    .specs-table td.col-actions,
    .bom-table td.col-actions,
    .specs-table td:last-child,
    .bom-table td:last-child {
        position: absolute;
        top: 8px;
        right: 8px;
        width: auto !important;
        padding: 0;
    }

    .specs-table td:last-child::before,
    .bom-table td:last-child::before {
        content: none;
    }

    /* Input più grandi per touch */
    .specs-table input,
    .specs-table select,
    .bom-table input {
        padding: 12px;
        font-size: 1rem;
    }

    /* Campo valore - textarea multilinea */
    .specs-table td:nth-child(3) textarea {
        width: 100%;
        min-height: 60px;
        padding: 10px;
        font-size: 1rem;
        font-family: 'Ubuntu', sans-serif;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius);
        resize: vertical;
        line-height: 1.4;
    }

    .specs-table td:nth-child(3) {
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
    }

    /* Campo CHIAVE - permetti multi-linea se necessario */
    .specs-table td:nth-child(2) {
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
        line-height: 1.4;
    }

    .specs-table td:nth-child(2) select,
    .specs-table td:nth-child(2) span,
    .specs-table td:nth-child(2) div {
        white-space: normal !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* Info section */
    .specs-info-section {
        padding: 16px;
        margin-bottom: 16px;
    }

    .specs-info-row {
        flex-direction: column;
        gap: 12px;
    }

    .info-cell {
        min-width: 100%;
    }
}
