/* purchasing_web style.css */
:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --fg: #1a1a2e;
  --fg-mut: #6b7280;
  --accent: #8e44ad;
  --accent-h: #7d3c98;
  --green: #27ae60;
  --green-h: #1e8449;
  --orange: #f39c12;
  --red: #e74c3c;
  --blue: #2980b9;
  --blue-dark: #1a3a5a;
  --fattura: #16a085;
  --fattura-h: #117a55;
  --border: #e2e8f0;
  --radius: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

/* ── Navbar ── */
.navbar {
  background: var(--fg);
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar .logo {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.5px;
  text-decoration: none;
}
.navbar .logo span { color: var(--accent); }
.navbar .home-btn { order:-1; color:#fff; background:rgba(255,255,255,0.12);
  font-weight:600; }
.navbar .home-btn:hover { background:rgba(255,255,255,0.22); }
.navbar a {
  color: #aab;
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.navbar a:hover, .navbar a.active {
  color: #fff;
  background: rgba(255,255,255,0.1);
}

/* ── Layout ── */
.page { max-width: 1400px; margin: 0 auto; padding: 20px 16px; }

/* ── Hub cards ── */
.hub {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.hub-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  color: var(--fg);
  border: 2px solid transparent;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.hub-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  border-color: var(--accent);
}
.hub-card .icon { font-size: 32px; display: block; margin-bottom: 10px; }
.hub-card .title { font-weight: 600; font-size: 14px; }
.hub-card .sub { font-size: 11px; color: var(--fg-mut); margin-top: 4px; }

/* ── Card ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 14px;
}
.card-hdr {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-accent  { background: var(--accent);  color: #fff; }
.btn-green   { background: var(--green);   color: #fff; }
.btn-blue    { background: var(--blue);    color: #fff; }
.btn-dark    { background: var(--blue-dark); color: #fff; }
.btn-orange  { background: var(--orange);  color: #fff; }
.btn-red     { background: var(--red);     color: #fff; }
.btn-gray    { background: #64748b;        color: #fff; }
.btn-sm      { padding: 4px 10px; font-size: 12px; }
.btn-fattura { background: var(--fattura); color: #000; font-weight: 700; }

/* ── Form fields ── */
.field-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.field-col { display: flex; flex-direction: column; gap: 3px; }
.field-col label { font-size: 11px; color: var(--fg-mut); font-weight: 500; }
.field-col input, .field-col select, .field-col textarea {
  border: 1px solid #c5cad3;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s;
}
.field-col input:focus, .field-col select:focus, .field-col textarea:focus {
  border-color: var(--accent);
}

/* ── Table ── */
.tbl-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.tbl thead th {
  background: #c0c6d4;
  color: var(--fg);
  font-weight: 600;
  font-size: 12px;
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid #b0b6c4;
}
table.tbl tbody tr { border-bottom: 1px solid #eaecf0; }
table.tbl tbody tr:hover { background: #f7f8fa; }
table.tbl tbody tr.even { background: #f5f6fa; }
table.tbl tbody td {
  padding: 8px 10px;
  vertical-align: middle;
}
table.tbl.sm td, table.tbl.sm th { padding: 5px 8px; font-size: 12px; }

/* Partite row colors */
tr.tag-contestazione td { background: #e74c3c22; }
tr.tag-scaduta td { background: #e67e2222; }
tr.tag-aperta td { background: #27ae6022; }
/* Pagamento inviato: azzurro + testo verde (ben distinto da aperta/scaduta) */
tr.tag-pagamento td {
  background: #d6eaf8;
  color: #15803d;
  font-weight: 600;
}
tr.tag-pagamento td .pt-pag-inviata {
  color: #15803d;
  font-weight: 700;
  font-size: 11px;
  margin-left: 6px;
  white-space: nowrap;
}
tr.tag-chiusa td { background: #f5f6fa; color: #888; }
tr.tag-nc td { background: #8e44ad18; }
tr.tag-nc td .pt-nc-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: #8e44ad;
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 4px;
  vertical-align: middle;
}
#partite-tbl .pt-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#partite-tbl .pt-saldo-credito {
  color: #6b21a8;
  font-weight: 600;
}
#partite-tbl .pt-row-act-btn.btn-sm,
#partite-tbl .pt-accredita-btn.btn-sm {
  font-size: 11px;
  padding: 4px 8px;
  white-space: nowrap;
}
#partite-tbl .pt-row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
#partite-tbl .pt-row-act-btn--annulla,
#partite-tbl .pt-row-act-btn--cancel {
  color: #475569;
  background: #cbd5e1;
  border: 1px solid #94a3b8;
}
#partite-tbl .pt-row-act-btn--annulla:hover,
#partite-tbl .pt-row-act-btn--cancel:hover {
  background: #94a3b8;
  border-color: #64748b;
  color: #1e293b;
}
tr.tag-flagged td { background: #bfdbfe; }

/* Partite: quadrato selezione con ✓ testuale (affidabile su tutti i browser) */
#partite-tbl td.pt-flag-td {
  text-align: center;
  vertical-align: middle;
  width: 36px;
  padding: 6px 4px;
  cursor: pointer;
  user-select: none;
}
#partite-tbl .pt-flag-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid #8a93a3;
  border-radius: 4px;
  background: #fff;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  box-sizing: border-box;
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease;
}
#partite-tbl td.pt-flag-td:hover .pt-flag-box {
  border-color: #3b82f6;
}
#partite-tbl .pt-flag-box.on,
#partite-tbl tr.tag-flagged .pt-flag-box {
  background: #2563eb;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: #d4edda; color: #155724; }
.badge-orange { background: #fff3cd; color: #856404; }
.badge-red    { background: #f8d7da; color: #721c24; }
.badge-blue   { background: #d1ecf1; color: #0c5460; }
.badge-gray   { background: #e2e8f0; color: #4a5568; }
.badge-purple { background: #e9d8fd; color: #553c9a; }

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed #c5cad3;
  border-radius: 8px;
  padding: 18px 20px;
  text-align: center;
  cursor: pointer;
  background: #e8ecf1;
  color: #4a4a6a;
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone.drag-over, .drop-zone:hover {
  border-color: var(--accent);
  background: #f3e8fd;
}
.drop-zone.loaded { border-color: var(--green); background: #d4edda; color: #155724; }

/* ── Progress bar ── */
.progress-wrap {
  background: #e2e8f0;
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 10px;
  transition: width 0.3s;
  width: 0%;
}

/* ── Op tracker ── */
.op-tracker { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.op-card {
  flex: 1;
  min-width: 130px;
  background: var(--bg-card);
  border-radius: 8px;
  padding: 10px 14px;
  border-left: 4px solid #e2e8f0;
  font-size: 12px;
}
.op-card.pending { border-color: #94a3b8; }
.op-card.in_progress { border-color: var(--orange); }
.op-card.completed { border-color: var(--green); }
.op-card.error { border-color: var(--red); }
.op-card .op-title { font-weight: 600; margin-bottom: 2px; }
.op-card .op-status { color: var(--fg-mut); font-size: 11px; }

/* ── Modal ── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  min-width: 360px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.modal h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.modal-footer { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1a1a2e;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 360px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 999;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.err { background: var(--red); }
#toast.ok { background: var(--green); }

/* ── Carrier buttons ── */
.carrier-btn {
  padding: 5px 16px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  transition: all 0.15s;
}
.carrier-btn.dhl-active { background: #ffcc00; color: #1a1a2e; border-color: #ffcc00; }
.carrier-btn.dhl-inactive { background: #e8ecf1; color: var(--fg-mut); }
.carrier-btn.fedex-active { background: #4d148c; color: #fff; border-color: #4d148c; }
.carrier-btn.fedex-inactive { background: #e8ecf1; color: var(--fg-mut); }

/* ── Griglia table ── */
.griglia-wrap { overflow-x: auto; }
.griglia-tbl input {
  width: 80px;
  border: 1px solid #d0d4dc;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  text-align: right;
}

/* ── Legenda partite ── */
.legenda { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 11px; }
.leg-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ── Status label ── */
.status-lbl {
  font-size: 12px;
  color: var(--fg-mut);
  padding: 4px 0;
  min-height: 20px;
}

/* ── Colli row ── */
.collo-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #f0f2f5;
  border-radius: 6px;
  margin-bottom: 4px;
  border: 1px solid #d0d4dc;
}
.collo-row input {
  width: 70px;
  border: 1px solid #c5cad3;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
}

/* Mobile / iPad portrait — desktop ≥901px invariato */
@media (max-width: 900px) {
  body { font-size: 14px; }
  .btn, button.btn, .act-btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 13px;
  }
  input.form-control,
  select.form-control,
  input[type="text"],
  input[type="number"],
  input[type="search"],
  select {
    min-height: 44px;
    font-size: 16px;
  }
  .tbl-wrap,
  .table-responsive,
  [style*="overflow-x"] {
    -webkit-overflow-scrolling: touch;
  }
  table {
    font-size: 13px;
  }
  .collo-row {
    flex-wrap: wrap;
    gap: 6px;
  }
  .collo-row input {
    min-height: 40px;
    font-size: 16px;
    width: 80px;
  }
}
