:root{
  --bg: #ffffff;
  --text: #111111;
  --muted: #555555;
  --line: #e9e9e9;
  --card: #ffffff;

  --dotToday: #ff2d2d;
  --dotWeek:  #ffb000;
  --dotMonth: #1faa59;

  --cal: #5a2ca0; /* viola calendario */
  color-scheme: light;
}

body.dark{
  --bg: #0b0b0f;
  --text: #f3f3f3;
  --muted: #b9b9b9;
  --line: #23232c;
  --card: #0f0f16;

  --cal: #ffffff; /* calendario bianco in dark */
  color-scheme: dark;
}

*{ box-sizing:border-box; }
body{
  margin:0;
  font-family: system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size:16px;
}

.topbar{
  padding:16px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

/* HEADER A 3 COLONNE */
.topbarGrid{
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 18px;
}

.headerLeft h1{ margin:0; font-size:22px; }
.sub{ margin-top:6px; font-size:13px; color: var(--muted); }

.headerLeft{ justify-self: start; }
.headerCenter{ justify-self:center; display:flex; align-items:center; justify-content:center; }
.logoHeaderCenter{ height:65px; width:auto; display:block; object-fit: contain;transform: scale(3);transform-origin: center; }

.headerRight{ justify-self:end; display:flex; gap:10px; align-items:center; flex-wrap:wrap; justify-content:flex-end; }
#status{ font-size:13px; color: var(--muted); }

.btnPrimary, .btnGhost{
  padding:10px 12px;
  border-radius:10px;
  cursor:pointer;
  font-size:14px;
  border:1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
.btnPrimary{ border-color: var(--text); }
.btnGhost{ opacity:.95; }

.activityButtons{
  display:flex;
  flex-direction: column;
  gap:6px;
}

.wrap{ padding:16px 20px 80px; }

.tabs{ display:flex; gap:8px; margin-bottom:10px; }
.tab{
  padding:9px 12px;
  border-radius:10px;
  border:1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor:pointer;
  font-size:14px;
}
.tab.active{
  border-color: var(--text);
  font-weight:700;
}

.tableWrap{ overflow:auto; border-top:1px solid var(--line); }

.tasks{
  width:100%;
  border-collapse: collapse;
  background: var(--card);
  min-width: 1200px;
}

.tasks thead th{
  text-transform: uppercase;
  letter-spacing: .4px;
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--muted);
  text-align:left;
  font-size:12px;
  padding:12px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.tasks tbody td{
  padding:10px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align:middle;
}

.tasks tbody tr:hover{ background: rgba(127,127,127,0.06); }

.colDrag{ width:34px; }
.dragHandle{
  cursor: grab;
  user-select:none;
  display:inline-block;
  padding:4px 6px;
  border-radius:8px;
  color: var(--muted);
}

input.cell, select.cell{
  width:100%;
  padding:6px 0;
  border:none;
  outline:none;
  background: transparent;
  color: var(--text);
  font-size:14px;
}

select.cell{
  background: var(--card);
  color: var(--text);
}
select.cell option{
  background: var(--card);
  color: var(--text);
}

/* Urgenza: quadratino */
.urgencyWrap{
  display:flex;
  align-items:center;
  gap:8px;
}
.dot{
  width:12px;
  height:12px;
  border-radius:3px;
  display:inline-block;
  border:1px solid rgba(0,0,0,0.15);
}
body.dark .dot{ border-color: rgba(255,255,255,0.25); }
.dot.today{ background: var(--dotToday); }
.dot.week{ background: var(--dotWeek); }
.dot.month{ background: var(--dotMonth); }

.actionsWrap{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}
.btnMini{
  padding:7px 10px;
  border-radius:10px;
  border:1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor:pointer;
  font-size:13px;
}
.btnDanger{ border-color: rgba(255,0,0,0.25); }

/* Toggle tema */
.themeToggle{
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border:1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor:pointer;
  font-size:18px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow: 0 10px 25px rgba(0,0,0,0.12);
}
body.dark .themeToggle{
  box-shadow: 0 10px 25px rgba(0,0,0,0.45);
}

/* ===== Calendario custom (colorato / theme aware) ===== */
.dateWrapper{
  position: relative;
  display: inline-block;
  width: 100%;
}
.dateWrapper input{
  padding-right: 32px;
}

/* nascondo icona nativa */
.dateWrapper input[type="datetime-local"]::-webkit-calendar-picker-indicator{
  opacity: 0;
  position: absolute;
  right: 10px;
}

/* icona nostra */
.dateIcon{
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  pointer-events: none;
  fill: var(--cal);
}

/* Mobile: header va in colonna */
@media (max-width: 900px){
  .topbarGrid{
    grid-template-columns: 1fr;
    row-gap: 10px;
  }
  .headerLeft, .headerCenter, .headerRight{
    justify-self: start;
  }
  .headerRight{
    justify-content:flex-start;
  }
  .activityButtons{
    flex-direction: row;
  }
}

/* PRIORITÀ molto più compatta */
.colPriority {
  width: 50px;        /* prima era più larga */
  min-width: 50px;
  max-width: 50px;
  text-align: left;
}

input.cell[data-field="priority"] {
  width: 40px;        /* spazio solo per 1-3 cifre */
  padding: 4px 0;
  text-align: left;
}

/* =============================== */
/* COLONNA PRIORITÀ - SISTEMATA   */
/* =============================== */

.colPriority {
  width: 75px;              /* leggermente più larga */
  min-width: 75px;
  max-width: 75px;
  text-align: center;       /* centra il titolo */
  white-space: nowrap;      /* evita che venga tagliata */
  overflow: visible;        /* non taglia testo */
}

input.cell[data-field="priority"] {
  width: 50px;              /* solo per 1-3 cifre */
  text-align: center;       /* numero centrato */
  margin: 0 auto;           /* perfettamente centrato */
  display: block;
}


/* =============================== */
/* STATO - CENTRATO E PIÙ LARGO   */
/* =============================== */

.colStatus {
  width: 170px;            /* più largo */
  text-align: center;      /* titolo centrato */
}

select.cell[data-field="status"] {
  min-width: 160px;        /* allarga dropdown */
  text-align: center;
}


/* =============================== */
/* RIDISTRIBUZIONE SPAZIO RESTANTE */
/* =============================== */

.colActivity {
  width: 340px;
}

.colNotes {
  width: 240px;
}

/* =============================== */
/* Q.TÀ più stretta */
/* =============================== */
th.colQty { width: 70px; }
input.cell[data-field="qty"]{
  max-width: 60px;
  text-align: center;
}

/* Se non hai la classe colQty nel th, va bene lo stesso: restringo la colonna via nth-child
   (Adatta l’indice se hai colonne diverse; con la tua tabella attuale Q.tà è la 7ª colonna) */
.tasks thead th:nth-child(7),
.tasks tbody td:nth-child(7){
  width: 70px;
}

/* =============================== */
/* URGENZA: nuovi colori e dot */
/* =============================== */
.dot.daily { background: #ff2d2d; }    /* Giornaliera = rosso */
.dot.w12   { background: #ffb000; }    /* Settimana 1-2 = giallo */
.dot.w34   { background: #1faa59; }    /* Settimana 3-4 = verde */

/* SELECT AUTO WIDTH (tranne Attività) */
select.cell:not([data-field="order_ref"]) {
  width: fit-content;
  min-width: 120px;     /* base minima */
  max-width: 100%;
  padding-right: 18px;
}

/* ====== FIX: permetti ai select di NON essere larghi 100% ====== */
/* (lascia input a 100%, ma i select auto-size tranne Attività) */
select.cell { width: auto !important; display: inline-block; }

/* Attività resta grande e controllata (NON autosize) */
select.cell[data-field="order_ref"] { width: 100% !important; }

/* opzionale: rende lo “scatto” più morbido quando cambia dimensione */
select.cell:not([data-field="order_ref"]) { transition: width .08s ease; }

/* =============================== */
/* TITOLI CENTRATI CON CONTENUTO */
/* =============================== */

/* Centra tutti i titoli */
.tasks thead th {
  text-align: center;
  vertical-align: middle;
}

/* PRIORITÀ */
.colPriority,
.tasks tbody td:nth-child(2) {
  text-align: center;
}

/* STATO */
.colStatus,
.tasks tbody td:nth-child(3) {
  text-align: center;
}

/* ATTIVITÀ */
.colActivity,
.tasks tbody td:nth-child(6) {
  text-align: center;
}

/* Q.TÀ */
.tasks thead th:nth-child(7),
.tasks tbody td:nth-child(7) {
  text-align: center;
}

/* URGENZA */
.tasks thead th:nth-child(8),
.tasks tbody td:nth-child(8) {
  text-align: center;
}

/* SCADENZA */
.tasks thead th:nth-child(9),
.tasks tbody td:nth-child(9) {
  text-align: center;
}

/* NOTE */
.colNotes,
.tasks tbody td:nth-child(10) {
  text-align: center;
}

/* ASSEGNATO A */
.tasks thead th:nth-child(11),
.tasks tbody td:nth-child(11) {
  text-align: center;
}

/* ================================== */
/* VERSIONE RAFFINATA ALLINEAMENTI   */
/* ================================== */

/* Tutti i titoli centrati */
.tasks thead th {
  text-align: center;
  vertical-align: middle;
  padding: 8px 6px;
}

/* Celle centrate verticalmente */
.tasks tbody td {
  vertical-align: middle;
}

/* PRIORITÀ */
.colPriority {
  text-align: center;
}

.colPriority input {
  display: block;
  margin: 0 auto;
  text-align: center;
}

/* STATO */
.colStatus {
  text-align: center;
}

.colStatus select {
  display: block;
  margin: 0 auto;
}

/* Q.TÀ */
.tasks thead th:nth-child(7),
.tasks tbody td:nth-child(7) {
  text-align: center;
}

.tasks tbody td:nth-child(7) input {
  display: block;
  margin: 0 auto;
  text-align: center;
  max-width: 60px;
}

/* URGENZA */
.tasks thead th:nth-child(8),
.tasks tbody td:nth-child(8) {
  text-align: center;
}

.tasks tbody td:nth-child(8) .urgencyWrap {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

/* SCADENZA */
.tasks thead th:nth-child(9),
.tasks tbody td:nth-child(9) {
  text-align: center;
}

.tasks tbody td:nth-child(9) input {
  display: block;
  margin: 0 auto;
}

/* NOTE */
.colNotes {
  text-align: center;
}

.colNotes input {
  display: block;
  margin: 0 auto;
}

/* ASSEGNATO A */
.tasks thead th:nth-child(11),
.tasks tbody td:nth-child(11) {
  text-align: center;
}

.tasks tbody td:nth-child(11) select {
  display: block;
  margin: 0 auto;
}
