/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f4f4f5;
  --surface:  #ffffff;
  --border:   rgba(0,0,0,0.1);
  --text:     #111;
  --muted:    #888;
  --blue:     #185FA5;
  --blue-lt:  #E6F1FB;
  --green:    #1D9E75;
  --green-lt: #E1F5EE;
  --red:      #E24B4A;
  --red-lt:   #FCEBEB;
  --amber:    #BA7517;
  --amber-lt: #FAEEDA;
  --sidebar:  #1b2033;
  --radius:   10px;
  --top-h:    54px;
  --nav-h:    48px;
}

html, body { height: 100%; overflow: hidden; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  height: var(--top-h);
  background: var(--sidebar);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  flex-shrink: 0;
}
.tb-logo {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--blue); color: #E6F1FB;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.tb-name { font-size: 13px; font-weight: 500; color: rgba(255,255,255,.85); }
.tb-sub  { font-size: 10px; color: rgba(255,255,255,.3); }
.tb-spacer { flex: 1; }
.tb-chip {
  display: flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,.06);
  border: 0.5px solid rgba(255,255,255,.1);
  border-radius: 20px; padding: 4px 10px;
  font-size: 11px; color: rgba(255,255,255,.5);
}
.tb-clock { font-size: 13px; font-weight: 500; color: rgba(255,255,255,.7); font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.tb-op { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.06); border: 0.5px solid rgba(255,255,255,.1); border-radius: 20px; padding: 4px 10px 4px 5px; }
.op-av { width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #E6F1FB; font-size: 9px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
#op-name-label { font-size: 11px; color: rgba(255,255,255,.5); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-green { background: #22c55e; }
.dot-amber { background: #f59e0b; }
.dot-red   { background: #ef4444; }

/* ── Nav tabs ────────────────────────────────────────────────── */
.navtabs {
  height: var(--nav-h);
  display: flex; background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; overflow-x: auto;
}
.navtabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1; min-width: 80px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  font-size: 13px; color: var(--muted);
  border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  position: relative; padding: 0 8px;
  transition: color .15s;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 500; }
.tab i { font-size: 16px; }
.tab-badge {
  background: var(--red); color: #fff;
  font-size: 9px; font-weight: 600;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.tab-badge-warn { background: var(--amber); }

/* ── Main ────────────────────────────────────────────────────── */
.main {
  height: calc(100vh - var(--top-h) - var(--nav-h));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.page { display: none; padding: 12px 14px; }
.page.active { display: block; }
.hidden { display: none !important; }

/* ── Filtri ──────────────────────────────────────────────────── */
.filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-chip {
  padding: 6px 14px; border: 1px solid var(--border);
  border-radius: 20px; font-size: 12px; color: var(--muted);
  background: var(--surface); cursor: pointer;
  transition: all .15s;
}
.filter-chip.active { background: var(--blue-lt); border-color: var(--blue); color: var(--blue); font-weight: 500; }
.filter-spacer { flex: 1; }
.search-mini {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 10px; background: var(--surface);
  font-size: 13px; color: var(--muted);
}
.search-mini input { border: none; outline: none; font-size: 13px; background: transparent; color: var(--text); width: 160px; }

/* ── WO Grid ─────────────────────────────────────────────────── */
.wo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.wo-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: border-color .15s, transform .1s;
  touch-action: manipulation;
}
.wo-card:active { transform: scale(.98); }
.wo-card.active-card { border-color: var(--blue); border-width: 1.5px; }
.wc-head { padding: 11px 13px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 8px; }
.wc-num  { font-size: 13px; font-weight: 600; color: var(--text); }
.wc-item { font-size: 11px; color: var(--muted); margin-top: 2px; }
.wc-body { padding: 10px 13px; display: flex; flex-direction: column; gap: 5px; }
.wc-row  { display: flex; justify-content: space-between; align-items: center; }
.wc-lbl  { font-size: 11px; color: var(--muted); }
.wc-val  { font-size: 12px; font-weight: 500; color: var(--text); }
.prog-bar { height: 5px; background: #e5e7eb; border-radius: 3px; overflow: hidden; margin-top: 2px; }
.prog-fill { height: 100%; border-radius: 3px; background: var(--blue); transition: width .4s; }
.prog-fill.done  { background: var(--green); }
.prog-fill.warn  { background: var(--amber); }
.wc-foot { padding: 8px 10px; background: var(--bg); display: flex; gap: 6px; border-top: 1px solid var(--border); }
.mini-btn {
  flex: 1; padding: 8px 0;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; font-weight: 500;
  background: var(--surface); color: var(--text);
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px;
  touch-action: manipulation; transition: background .12s;
}
.mini-btn:active { background: var(--bg); }
.mini-btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.mini-btn.primary:active { background: #0d4a85; }

/* Status pill */
.sp { font-size: 10px; font-weight: 500; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.sp-run     { background: var(--green-lt); color: #0F6E56; border: 0.5px solid #5DCAA5; }
.sp-planned { background: var(--amber-lt); color: #854F0B; border: 0.5px solid #EF9F27; }
.sp-closed  { background: var(--green-lt); color: #0F6E56; border: 0.5px solid #5DCAA5; }
.sp-new     { background: var(--bg); color: var(--muted); border: 0.5px solid var(--border); }

/* ── Fase operatore ──────────────────────────────────────────── */
.no-wo-selected { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 300px; color: var(--muted); font-size: 14px; }
.hero-fase { background: var(--blue-lt); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; display: flex; gap: 14px; }
.hero-left { flex: 1; }
.hf-label { font-size: 10px; color: var(--blue); letter-spacing: .5px; font-weight: 500; }
.hf-name  { font-size: 22px; font-weight: 600; color: #0C447C; margin-top: 4px; }
.hf-sub   { font-size: 12px; color: var(--blue); margin-top: 5px; }
.hf-timer { font-size: 32px; font-weight: 600; color: #0C447C; font-variant-numeric: tabular-nums; letter-spacing: 2px; margin-top: 10px; }
.hero-stats { display: flex; flex-direction: column; gap: 6px; width: 90px; }
.stat-box { background: var(--surface); border-radius: 8px; padding: 8px; text-align: center; flex: 1; }
.sb-num   { font-size: 22px; font-weight: 600; }
.sb-lbl   { font-size: 10px; color: var(--muted); margin-top: 1px; }
.green { color: #3B6D11; } .red { color: #A32D2D; } .amber { color: #854F0B; }

.act-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.act-btn {
  padding: 18px 12px; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); touch-action: manipulation;
  font-size: 14px; font-weight: 500; transition: transform .1s;
}
.act-btn i { font-size: 28px; }
.act-btn:active { transform: scale(.95); }
.stop-btn  { background: var(--red-lt);   border-color: #F09595; color: #A32D2D; }
.ok-btn    { background: var(--green-lt); border-color: #5DCAA5; color: #0F6E56; }
.scrap-btn { background: var(--amber-lt); border-color: #EF9F27; color: #854F0B; }
.pause-btn { background: var(--bg); color: var(--muted); }

.phase-strip { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.ps-track { display: flex; align-items: center; overflow-x: auto; padding-bottom: 4px; }
.ps-step { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 60px; }
.ps-circle { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; border: 1px solid var(--border); }
.ps-c-done   { background: var(--green); color: #fff; border-color: var(--green); }
.ps-c-active { background: var(--blue);  color: #fff; border-color: var(--blue); }
.ps-c-wait   { background: var(--bg); color: var(--muted); }
.ps-name { font-size: 9px; color: var(--muted); text-align: center; }
.ps-line { flex: 1; height: 2px; background: var(--border); min-width: 20px; }
.ps-line.done { background: var(--green); }

.phase-log { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.log-title { font-size: 10px; color: var(--muted); letter-spacing: .5px; margin-bottom: 8px; }
.log-row   { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.log-row:last-child { border-bottom: none; }
.log-time { font-size: 10px; color: var(--muted); width: 42px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.log-dot  { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.ld-blue  { background: var(--blue); }
.ld-green { background: var(--green); }
.ld-amber { background: var(--amber); }
.ld-red   { background: var(--red); }
.log-text { flex: 1; color: var(--text); }
.log-user { font-size: 10px; color: var(--muted); }

/* ── Materiali ───────────────────────────────────────────────── */
.scan-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.scan-box { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; color: var(--muted); }
.scan-box input { flex: 1; border: none; outline: none; font-size: 14px; background: transparent; color: var(--text); }
.scan-btn { background: var(--blue); color: #fff; border: none; border-radius: var(--radius); padding: 12px 16px; font-size: 13px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 5px; touch-action: manipulation; }
.mat-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.mat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.mat-card.ok      { border-color: #5DCAA5; }
.mat-card.warn    { border-color: #EF9F27; }
.mat-card.missing { border-color: #F09595; }
.mc-head { padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.mc-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.ic-ok   { background: var(--green-lt); color: var(--green); }
.ic-warn { background: var(--amber-lt); color: var(--amber); }
.ic-miss { background: var(--red-lt);   color: var(--red); }
.mc-code { font-size: 10px; color: var(--muted); font-family: monospace; }
.mc-name { font-size: 13px; font-weight: 500; color: var(--text); }
.mc-wh   { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.mc-right { text-align: right; flex-shrink: 0; }
.mc-qlbl { font-size: 10px; color: var(--muted); }
.mc-qval { font-size: 16px; font-weight: 600; color: var(--text); }
.mc-uom  { font-size: 11px; color: var(--muted); }
.mc-body { padding: 10px 12px; background: var(--bg); border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.stock-pill { font-size: 10px; padding: 2px 7px; border-radius: 20px; font-weight: 500; white-space: nowrap; }
.sp-ok2  { background: var(--green-lt); color: #0F6E56; }
.sp-low  { background: var(--amber-lt); color: #854F0B; }
.sp-out  { background: var(--red-lt);   color: #A32D2D; }

.mat-footer { display: flex; align-items: center; gap: 10px; padding-top: 4px; }
.mat-summary { flex: 1; font-size: 12px; color: var(--muted); }
.send-sap-btn { background: var(--blue); color: #fff; border: none; border-radius: var(--radius); padding: 12px 20px; font-size: 14px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 6px; }

/* ── Qualità ─────────────────────────────────────────────────── */
.kpi-bar { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.kpi { padding: 14px; text-align: center; border-right: 1px solid var(--border); }
.kpi:last-child { border-right: none; }
.kpi-num { font-size: 26px; font-weight: 600; }
.kpi-lbl { font-size: 10px; color: var(--muted); margin-top: 3px; }
.qa-progress-bar-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.qa-progress-bar { height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; display: flex; }
.qa-seg-ok   { background: var(--green); height: 100%; }
.qa-seg-sc   { background: var(--red); height: 100%; }
.qa-legend   { display: flex; gap: 14px; margin-top: 8px; }
.leg-item    { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.leg-dot     { width: 8px; height: 8px; border-radius: 50%; }

.qa-two-col  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.declare-col, .nc-log-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.col-title { font-size: 13px; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.col-title i { color: var(--blue); font-size: 16px; }
.form-row { margin-bottom: 10px; }
.form-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; display: block; }
.form-select { width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--bg); color: var(--text); }
.qty-row { display: flex; gap: 8px; align-items: center; }
.qty-btn { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 400; cursor: pointer; background: var(--bg); color: var(--text); flex-shrink: 0; touch-action: manipulation; }
.qty-btn.big { width: 48px; height: 48px; font-size: 28px; }
.qty-input { flex: 1; height: 40px; border: 1px solid var(--border); border-radius: 8px; text-align: center; font-size: 18px; font-weight: 600; background: var(--surface); color: var(--text); }
.qty-input.big { height: 56px; font-size: 26px; }
.cause-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cause-btn { padding: 9px 6px; border: 1px solid var(--border); border-radius: 8px; font-size: 11px; text-align: center; cursor: pointer; background: var(--surface); color: var(--text); touch-action: manipulation; }
.cause-btn.sel { background: var(--amber-lt); border-color: #EF9F27; color: #854F0B; font-weight: 500; }
.qa-submit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.submit-btn { padding: 12px; border: none; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px; touch-action: manipulation; }
.btn-green   { background: var(--green); color: #fff; }
.btn-red     { background: var(--red);   color: #fff; }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.nc-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.nc-head { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.nc-badge { font-size: 10px; font-weight: 500; padding: 2px 7px; border-radius: 20px; }
.nb-scarto  { background: var(--red-lt);   color: #A32D2D; }
.nb-rework  { background: var(--amber-lt); color: #854F0B; }
.nb-ok      { background: var(--green-lt); color: #0F6E56; }
.nc-time    { font-size: 10px; color: var(--muted); flex: 1; text-align: right; }
.nc-desc    { font-size: 12px; color: var(--text); }
.nc-meta    { font-size: 10px; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 20px; width: 280px; }
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.modal-qty-row { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; color: #fff; animation: slideIn .2s ease; max-width: 280px; }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.info    { background: var(--blue); }
@keyframes slideIn { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Utility ─────────────────────────────────────────────────── */
.loading-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; padding: 40px; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.confirm-row { display: flex; gap: 8px; }
.confirm-btn-sap { background: var(--green); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-size: 12px; font-weight: 500; cursor: pointer; }

/* ── Responsive tablet portrait ─────────────────────────────── */
@media (max-width: 600px) {
  .wo-grid { grid-template-columns: 1fr; }
  .qa-two-col { grid-template-columns: 1fr; }
  .kpi-bar { grid-template-columns: repeat(2, 1fr); }
}
