/* ============================================================
   EasyBOM - Stile principale v5
   Bootstrap 5.3 + custom
   ============================================================ */

:root {
    --eb-primary:    #0057FF;
    --eb-primary-dk: #0040CC;
    --eb-success:    #34C759;
    --eb-danger:     #FF3B30;
    --eb-gray-light: #E5E5EA;
    --eb-gray:       #8E8E93;
    --eb-bg:         #F2F2F7;
    --eb-card:       #FFFFFF;
    --eb-text:       #1C1C1E;
    --eb-text-sec:   #6C6C70;
    --eb-bar-h:      72px;
    --eb-radius:     14px;
    --eb-radius-sm:  10px;
    --eb-plate-red:  #FF3B30;
    --eb-plate-gray: #8E8E93;
    --eb-plate-green:#34C759;
}

* { box-sizing: border-box; }

body {
    background: var(--eb-bg);
    color: var(--eb-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    padding-bottom: calc(var(--eb-bar-h) + 16px);
    min-height: 100vh;
}

/* ── Login ───────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0057FF 0%, #003BB5 100%);
    padding: 24px;
}

.login-card {
    background: #fff;
    border-radius: 24px;
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18);
}

.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--eb-primary);
    letter-spacing: -1px;
    margin: 0;
}
.login-logo p {
    color: var(--eb-text-sec);
    font-size: .9rem;
    margin: 4px 0 0;
}

/* ── Card / Box ──────────────────────────────────────────── */
.eb-card {
    background: var(--eb-card);
    border-radius: var(--eb-radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}

.eb-card-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--eb-primary);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--eb-gray-light);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Row toggle ──────────────────────────────────────────── */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 0;
    border-bottom: 1px solid var(--eb-gray-light);
}
.toggle-row:last-child { border-bottom: none; }

.toggle-label {
    font-size: .97rem;
    font-weight: 500;
    color: var(--eb-text);
}

/* ── Toggle iOS ──────────────────────────────────────────── */
.ios-toggle {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
}
.ios-toggle input { opacity: 0; width: 0; height: 0; }
.ios-toggle .slider {
    position: absolute;
    inset: 0;
    background: var(--eb-gray-light);
    border-radius: 31px;
    cursor: pointer;
    transition: background .25s;
}
.ios-toggle .slider:before {
    content: '';
    position: absolute;
    width: 27px;
    height: 27px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
    transition: transform .25s;
}
.ios-toggle input:checked + .slider { background: var(--eb-success); }
.ios-toggle input:checked + .slider:before { transform: translateX(20px); }

/* ── Segmented Control (Scheda Alimentazione) ────────────── */
.segmented-ctrl {
    display: flex;
    background: var(--eb-gray-light);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.seg-btn {
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-size: .85rem;
    font-weight: 600;
    color: var(--eb-gray);
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}

.seg-btn.active {
    background: #fff;
    color: var(--eb-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,.12);
}

/* ── Input numero piastre ────────────────────────────────── */
.plate-input-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 14px;
    border-bottom: 1px solid var(--eb-gray-light);
}
.plate-input-wrap label { font-weight: 500; font-size: .97rem; }

.plate-number-input {
    width: 90px;
    border: 2px solid var(--eb-gray-light);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    outline: none;
    transition: border-color .2s;
}
.plate-number-input:focus { border-color: var(--eb-primary); }

/* ── Pulsante calcola ────────────────────────────────────── */
.btn-calcola {
    width: 100%;
    padding: 16px;
    background: var(--eb-primary);
    color: #fff;
    border: none;
    border-radius: var(--eb-radius);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: .3px;
    cursor: pointer;
    transition: all .2s;
    box-shadow: 0 4px 16px rgba(0,87,255,.3);
}
.btn-calcola:hover  { background: var(--eb-primary-dk); }
.btn-calcola:active { transform: scale(.98); }
.btn-calcola:disabled {
    background: var(--eb-gray);
    box-shadow: none;
    cursor: not-allowed;
}

/* ── Risultati ───────────────────────────────────────────── */
.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.result-item {
    background: var(--eb-bg);
    border-radius: var(--eb-radius-sm);
    padding: 12px 14px;
    border-left: 4px solid var(--eb-primary);
}
.result-item.highlight {
    border-left-color: var(--eb-success);
    background: #edfaf1;
}
.result-item .r-label {
    font-size: .75rem;
    color: var(--eb-text-sec);
    margin-bottom: 4px;
    line-height: 1.3;
}
.result-item .r-value {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--eb-text);
}
.result-item .r-um {
    font-size: .8rem;
    font-weight: 500;
    color: var(--eb-gray);
    margin-left: 3px;
}

/* ── Salvataggio ─────────────────────────────────────────── */
.save-row { display: flex; gap: 10px; }
.save-row input {
    flex: 1;
    border: 2px solid var(--eb-gray-light);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: .95rem;
    outline: none;
    transition: border-color .2s;
}
.save-row input:focus { border-color: var(--eb-primary); }

.btn-salva {
    padding: 10px 20px;
    background: var(--eb-success);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: .95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all .2s;
    white-space: nowrap;
}
.btn-salva:hover { opacity: .9; }

/* ── Bottom App Bar ──────────────────────────────────────── */
.app-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--eb-bar-h);
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0,0,0,.08);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    z-index: 999;
    padding-bottom: env(safe-area-inset-bottom);
}

.bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--eb-gray);
    padding: 6px 8px;
    border-radius: 12px;
    transition: all .2s;
    min-width: 44px;
    cursor: pointer;
    background: none;
    border: none;
}
.bar-item svg { transition: all .2s; }
.bar-item span { font-size: .58rem; font-weight: 600; letter-spacing: .2px; }
.bar-item.active, .bar-item:hover { color: var(--eb-primary); }
.bar-item.logout:hover { color: var(--eb-danger); }

/* ── Archivio ────────────────────────────────────────────── */
.archive-item {
    padding: 14px;
    border-bottom: 1px solid var(--eb-gray-light);
    cursor: pointer;
    transition: background .15s;
}
.archive-item:last-child { border-bottom: none; }
.archive-item:hover { background: var(--eb-bg); }

.ai-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1rem;
    color: var(--eb-text);
}
.ai-meta { font-size: .8rem; color: var(--eb-text-sec); margin-top: 3px; }

.btn-del-arch {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 6px;
    color: var(--eb-danger);
    opacity: .7;
    transition: opacity .2s;
}
.btn-del-arch:hover { opacity: 1; background: #FFE5E3; }

/* ── Assemblaggio — contatore ───────────────────────────── */
.assembly-counter {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

#counter-done {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--eb-primary);
    line-height: 1;
}

.counter-sep {
    font-size: 1rem;
    color: var(--eb-text-sec);
}

#counter-total {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--eb-text-sec);
}

.counter-label {
    font-size: .85rem;
    color: var(--eb-text-sec);
    font-weight: 500;
}

.counter-bar-wrap {
    flex-basis: 100%;
    height: 6px;
    background: var(--eb-gray-light);
    border-radius: 4px;
    overflow: hidden;
}

.counter-bar-fill {
    height: 100%;
    background: var(--eb-primary);
    border-radius: 4px;
    transition: width .4s ease, background .4s;
    width: 0%;
}

/* ── Assemblaggio — griglia piastre ─────────────────────── */
.legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .82rem;
    color: var(--eb-text-sec);
    margin-bottom: 14px;
}
.leg-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.leg-dot.red   { background: var(--eb-plate-red); }
.leg-dot.gray  { background: var(--eb-plate-gray); }
.leg-dot.green { background: var(--eb-plate-green); }

.plate-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Piastra vuota: solo numero */
.plate-rect.plate-num-only {
    width: 64px;
    height: 96px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 800;
    color: #fff;
    cursor: pointer;
    user-select: none;
    transition: transform .15s, box-shadow .15s;
    box-shadow: 0 3px 10px rgba(0,0,0,.18);
    border: 3px solid rgba(255,255,255,.25);
}

/* Piastra con dati: layout verticale con info */
.plate-rect.plate-with-data {
    width: 110px;
    min-height: 118px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    padding: 6px 8px;
    color: #000000;
    cursor: pointer;
    user-select: none;
    transition: transform .15s, box-shadow .15s;
    box-shadow: 0 3px 10px rgba(0,0,0,.18);
    border: 3px solid rgba(255,255,255,.25);
    gap: 2px;
}

.plate-rect:active { transform: scale(.95); }

.plate-rect.plate-empty       { background: var(--eb-plate-red); }
.plate-rect.plate-in_progress { background: var(--eb-plate-gray); }
.plate-rect.plate-complete    { background: var(--eb-plate-green); }

/* Piastra bloccata da un altro utente */
.plate-rect.plate-locked {
    opacity: .55;
    cursor: not-allowed;
    position: relative;
}
.plate-rect.plate-locked:active { transform: none; }

/* Badge "In uso da X" sulla piastra */
.plate-lock-badge {
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.62);
    color: #fff;
    font-size: .5rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 6px;
    white-space: nowrap;
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Piastra bloccata dall'utente corrente (aperta in modifica) */
.plate-rect.plate-locked-mine {
    outline: 2px solid #0057FF;
    outline-offset: -2px;
}

/* Numero piastra nella versione con dati */
.pl-num {
    font-size: .75rem;
    font-weight: 800;
    opacity: .7;
    margin-bottom: 2px;
}

/* Singola riga info piastra */
.pl-field {
    font-size: .6rem;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-all;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pl-lbl {
    opacity: .7;
    font-weight: 700;
    margin-right: 2px;
}

/* ── Settings / Admin ────────────────────────────────────── */
.user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--eb-gray-light);
}
.user-row:last-child { border-bottom: none; }

.online-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}
.online-dot.online  { background: var(--eb-success); }
.online-dot.offline { background: var(--eb-danger); }

.btn-sm-action {
    padding: 5px 12px;
    border-radius: 8px;
    font-size: .8rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all .2s;
}
.btn-danger-sm  { background: #FFE5E3; color: var(--eb-danger); }
.btn-warning-sm { background: #FFF3CD; color: #856404; }
.btn-success-sm { background: #D1F2DF; color: #198754; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0,0,0,.08);
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.topbar-logo {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--eb-primary);
    letter-spacing: -0.5px;
}
.topbar-user {
    font-size: .82rem;
    color: var(--eb-text-sec);
    font-weight: 500;
}

/* ── Modale ──────────────────────────────────────────────── */
.modal-content { border-radius: 18px; border: none; }
.modal-header  { border-bottom: 1px solid var(--eb-gray-light); padding: 18px 20px 14px; }
.modal-body    { padding: 20px; }

/* ── Alert ───────────────────────────────────────────────── */
.eb-alert { border-radius: var(--eb-radius-sm); padding: 12px 16px; font-size: .9rem; font-weight: 500; margin-bottom: 14px; }
.eb-alert-success { background: #D1F2DF; color: #0A5C2B; }
.eb-alert-error   { background: #FFE5E3; color: #8B0000; }
.eb-alert-info    { background: #D9EDFF; color: #003580; }

/* ── Form ────────────────────────────────────────────────── */
.form-control:focus, .form-select:focus {
    border-color: var(--eb-primary);
    box-shadow: 0 0 0 3px rgba(0,87,255,.15);
}

/* ── Acquisti — tabella ordine ───────────────────────────── */
.order-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
}

.order-table {
    width: 100%;
    min-width: 650px;
    border-collapse: collapse;
}

.order-table thead th {
    background: var(--eb-primary);
    color: #fff;
    font-size: .82rem;
    font-weight: 700;
    padding: 10px 8px;
    white-space: nowrap;
    border: none;
}

.order-table tbody tr:nth-child(even) {
    background: #F8F9FF;
}

.order-table tbody tr:hover {
    background: #EFF3FF;
}

.ord-input {
    width: 100%;
    border: 1.5px solid var(--eb-gray-light);
    border-radius: 7px;
    padding: 6px 8px;
    font-size: .83rem;
    outline: none;
    background: transparent;
    transition: border-color .2s;
}
.ord-input:focus { border-color: var(--eb-primary); background: #fff; }

.btn-del-row {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--eb-danger);
    opacity: .65;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s;
}
.btn-del-row:hover { opacity: 1; background: #FFE5E3; }

/* ── Autocomplete dropdown ───────────────────────────────── */
td.ac-wrap {
    position: relative;
}
.ac-dropdown {
    position: absolute;
    left: 0; top: 100%;
    z-index: 1060;
    background: #fff;
    border: 1.5px solid var(--eb-primary);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 6px 20px rgba(0,87,255,.14);
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
    min-width: 180px;
    display: none;
}
.ac-item {
    padding: 7px 12px;
    font-size: .82rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: #EFF3FF; color: var(--eb-primary); }

/* ── Catalogo articoli (modale) ──────────────────────────── */
.catalog-table td, .catalog-table th {
    padding: 6px 10px;
    font-size: .82rem;
    vertical-align: middle;
}
.catalog-table thead th {
    background: #f4f6ff;
    font-weight: 700;
    border-bottom: 2px solid #dee2e6;
    color: var(--eb-primary);
}

/* ── Param table ─────────────────────────────────────────── */
.param-table td, .param-table th { padding: 10px 14px; vertical-align: middle; }

.param-edit-input {
    width: 100px;
    border: 2px solid var(--eb-gray-light);
    border-radius: 8px;
    padding: 5px 8px;
    font-size: .9rem;
    text-align: center;
}
.param-edit-input:focus { border-color: var(--eb-primary); outline: none; }

/* ── Audit log ───────────────────────────────────────────── */
.audit-row {
    padding: 10px 0;
    border-bottom: 1px solid var(--eb-gray-light);
    font-size: .85rem;
}
.audit-row:last-child { border-bottom: none; }

/* ── Spinner / Loading ───────────────────────────────────── */
.spinner-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
.spinner-overlay.show { display: flex; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 576px) {
    .result-grid { grid-template-columns: 1fr; }
    .eb-card     { padding: 16px; }
    .save-row    { flex-direction: column; }
    .save-row .btn-salva { width: 100%; justify-content: center; }
    .plate-rect.plate-num-only  { width: 56px; height: 84px; font-size: 1.1rem; }
    .plate-rect.plate-with-data { width: 80px; min-height: 100px; }
    .pl-field { font-size: .55rem; }
    .bar-item span { font-size: .52rem; }
    .seg-btn { padding: 5px 10px; font-size: .8rem; }
}

/* ── Stampa PDF ──────────────────────────────────────────── */
@media print {
    .app-bar, .topbar, .spinner-overlay,
    .modal-footer, .btn-close, #search-input,
    .btn, button { display: none !important; }
    .modal-dialog { max-width: 100%; margin: 0; }
    .modal-content { border-radius: 0; box-shadow: none; }
    body { padding-bottom: 0; background: #fff; }
    .eb-card { box-shadow: none; border: 1px solid #ddd; }
    .order-table-wrap { overflow: visible; }
    .order-table { min-width: unset; }
}
