/* =========================================================
   CdC MANAGER — stylesheet
   ========================================================= */

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background: #fafaf7;
  color: #1a1a1a;
}

/* ---------- Header ---------- */

.app-header {
  background: white;
  border-bottom: 1px solid #e5e5e0;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.app-title { font-size: 17px; font-weight: 600; margin: 0; flex-shrink: 0; }
.app-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  margin-left: 24px;
}
.app-nav a {
  text-decoration: none;
  font-size: 13px;
  color: #555;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.app-nav a:hover { background: #f1efe8; }
.app-nav a.active {
  background: #e6f1fb;
  color: #0c447c;
  border-color: #b9d4ee;
  font-weight: 500;
}
.page { display: block; }
.page[hidden] { display: none; }
.app-user {
  font-size: 13px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-user-badge {
  background: #e6f1fb;
  color: #0c447c;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

/* ---------- Workspace / toolbar ---------- */

.kw { padding: 1rem 24px; max-width: 1600px; margin: 0 auto; }

.tb {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e5e0;
}
.tb input[type=text], .tb input[type=search] {
  flex: 1;
  min-width: 160px;
  max-width: 240px;
  padding: 6px 10px;
  border: 1px solid #d3d1c7;
  border-radius: 6px;
  font-size: 13px;
}
.tb select, .tb button {
  padding: 6px 12px;
  border: 1px solid #d3d1c7;
  border-radius: 6px;
  background: white;
  font-size: 13px;
  cursor: pointer;
}
.tb button:hover:not(:disabled) { background: #f1efe8; }
.tb button.primary { background: #185fa5; color: white; border-color: #185fa5; }
.tb button.primary:hover { background: #0c447c; }
.tb button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Stats row ---------- */

.sr {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 1rem;
}
.sc {
  background: white;
  border: 1px solid #e5e5e0;
  border-radius: 8px;
  padding: 10px 12px;
}
.sl { font-size: 11px; color: #666; margin: 0 0 2px; }
.sv { font-size: 18px; font-weight: 500; margin: 0; }

/* ---------- Kanban board ---------- */

.bd {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 0 12px;
  min-height: 400px;
}
.col {
  flex: 0 0 240px;
  background: white;
  border-radius: 12px;
  border: 1px solid #e5e5e0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 230px);
  min-height: 200px;
  transition: flex-basis 0.15s ease;
}
/* Colonna collassata: striscia verticale stretta come un font-size, col
   nome del direttore ruotato 90° leggibile dal basso verso l'alto. */
.col.collapsed {
  flex: 0 0 18px;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.col.collapsed .ch {
  padding: 0;
  border: none;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.col.collapsed .ctr,
.col.collapsed .cs,
.col.collapsed .cm,
.col.collapsed .cb {
  display: none;
}
.col.collapsed .ct {
  display: block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  letter-spacing: 0.5px;
  margin: 0;
  padding: 8px 0;
}
.col.collapsed .ctr {
  display: flex !important;
  flex-direction: column;
}
.col.collapsed .ccol,
.col.collapsed .cmb { display: none; }
.col.un {
  background: #faeeda;
  border-color: #efb971;
}
.col.ce {
  background: #ededed;
  border-color: #b4b2a9;
}
.col.ce .ct { color: #555; }
.ch {
  padding: 10px 12px;
  border-bottom: 1px solid #e5e5e0;
  position: sticky;
  top: 0;
  background: inherit;
  border-radius: 12px 12px 0 0;
}
.ctr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.ct {
  font-size: 12px;
  font-weight: 500;
  margin: 0;
  word-break: break-word;
  line-height: 1.3;
  flex: 1;
  cursor: default;
}
.ct.clickable { cursor: pointer; }
.ct.clickable:hover { color: #185fa5; }
.cmb, .ccol, .cexp {
  cursor: pointer;
  font-size: 14px;
  color: #666;
  border: none;
  background: transparent;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.cmb:hover, .ccol:hover, .cexp:hover { background: #f1efe8; color: #185fa5; }
.ccol { font-size: 14px; }
.cexp {
  font-size: 14px;
  /* Pillola di sfondo per renderlo evidente come azione */
  background: #f1efe8;
  border: 1px solid #d3d1c7;
}
.cexp:hover { background: #e6f1fb; border-color: #185fa5; }
.cs {
  font-size: 10px;
  color: #888;
  margin: 0 0 4px;
  font-style: italic;
}
.cm {
  font-size: 10px;
  color: #666;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cb {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 60px;
}
.cb.dr { background: #e6f1fb; }
.cd {
  background: white;
  border: 1px solid #e5e5e0;
  border-radius: 6px;
  margin-bottom: 3px;
  cursor: grab;
  font-size: 11px;
  position: relative;
  transition: padding 0.15s ease;
}
.cd:active { cursor: grabbing; }
.cd.dg { opacity: 0.4; }
.cd.na { border-left: 3px solid #e24b4a; }
.cd.cessato {
  border-left: 3px solid #999;
  background: #f7f7f5;
  opacity: 0.85;
}
.cd.cessato .cn { color: #666; text-decoration: line-through; }
.cd.loading { opacity: 0.6; pointer-events: none; }
.cd.readonly { cursor: pointer; }

/* Compatto = default. Una riga sola: nome + sintesi metriche. */
.cd:not(.expanded) {
  padding: 5px 56px 5px 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 26px;
}
.cd:not(.expanded) .cn {
  font-weight: 500;
  font-size: 11px;
  margin: 0;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd:not(.expanded) .cr-stack { display: none; }
.cd:not(.expanded) .cr-summary {
  font-size: 10px;
  color: #666;
  white-space: nowrap;
  letter-spacing: -0.1px;
  display: flex;
  gap: 6px;
}
.cd:not(.expanded) .cr-summary .neg { color: #e24b4a; }
.cd:not(.expanded) .cr-summary .pos { color: #1d9e75; }

/* Espansa = layout originale, mostrata cliccando sulla card. */
.cd.expanded {
  padding: 8px 10px;
  cursor: default;
}
.cd.expanded .cr-summary { display: none; }
.cd.expanded .cn {
  font-weight: 500;
  font-size: 12px;
  margin: 0 0 4px;
  word-break: break-word;
  padding-right: 40px;
}
.cd.expanded .cr {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #666;
  margin: 1px 0;
}
.cd.expanded .cr.ng { color: #e24b4a; }
.cd.expanded .cr.ps { color: #1d9e75; }

.cessato-badge {
  display: inline-block;
  font-size: 10px;
  margin-right: 3px;
  vertical-align: 1px;
}
.cessato-badge.manual { color: #c44; }
.cessato-badge.auto { color: #999; }

/* Veicolato: badge sul nome del padre + lista figli espandibile */
.kids-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  color: white;
  background: #185fa5;
  border-radius: 8px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: 1px;
}
.cd.has-kids { border-left: 3px solid #185fa5; }
.kids-block {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #d3d1c7;
}
.kids-toggle {
  border: none;
  background: transparent;
  font-size: 11px;
  color: #185fa5;
  cursor: pointer;
  padding: 2px 0;
  width: 100%;
  text-align: left;
}
.kids-toggle:hover { text-decoration: underline; }
.kids-list { display: none; margin-top: 4px; }
.cd.kids-open .kids-list { display: block; }
.kid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
  padding: 3px 4px;
  font-size: 10px;
  color: #555;
  border-radius: 4px;
}
.kid:hover { background: #f7f6f1; }
.kid-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kid-summary {
  font-size: 9px;
  color: #888;
  white-space: nowrap;
}
.kid-edit {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  color: #888;
  padding: 1px 4px;
  border-radius: 3px;
}
.kid-edit:hover { background: #e6f1fb; color: #185fa5; }

.ce, .cdh {
  position: absolute;
  cursor: pointer;
  font-size: 11px;
  color: #888;
  border: none;
  background: transparent;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  z-index: 1;
}
.cd:not(.expanded) .ce, .cd:not(.expanded) .cdh {
  top: 50%;
  transform: translateY(-50%);
}
.cd.expanded .ce, .cd.expanded .cdh { top: 6px; }
.ce { right: 6px; }
.cdh { right: 26px; }
.ce:hover, .cdh:hover { background: #f1efe8; color: #185fa5; }

/* Add-column / add-direttore affordance */

.ac {
  flex: 0 0 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #b4b2a9;
  border-radius: 12px;
  color: #666;
  cursor: pointer;
  font-size: 12px;
  background: transparent;
  min-height: 120px;
}
.ac:hover { background: #f1efe8; color: #185fa5; }

/* ---------- Modal ---------- */

.mb {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  z-index: 100;
}
.md {
  background: white;
  border-radius: 12px;
  padding: 20px;
  min-width: 340px;
  max-width: 460px;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid #e5e5e0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}
.md h3 { margin: 0 0 14px; font-size: 16px; font-weight: 500; }
.md h3.warn { color: #c0392b; }
.md label {
  display: block;
  font-size: 12px;
  color: #666;
  margin: 8px 0 4px;
}
.md input, .md select, .md textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #d3d1c7;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.md .hint {
  font-size: 12px;
  color: #666;
  margin: 0 0 12px;
}

/* Tri-state cessato radio nel modale modifica CdC */
.cessato-radio {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 12px;
}
.cessato-radio label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: #333;
  cursor: pointer;
}
.cessato-radio input { width: auto; margin: 0; }

/* Lista capoarea nella modale "Capoarea" */
.ca-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 8px;
}
.ca-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid #e5e5e0;
  border-radius: 6px;
  font-size: 13px;
}
.ca-row button {
  padding: 4px 10px;
  margin-left: 4px;
  border: 1px solid #d3d1c7;
  background: white;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
.ca-row button.dn { color: #e24b4a; border-color: #f09595; }
.ma {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.ma button {
  padding: 6px 14px;
  border: 1px solid #d3d1c7;
  border-radius: 6px;
  background: white;
  font-size: 13px;
  cursor: pointer;
}
.ma .dn { color: #e24b4a; border-color: #f09595; }
.ma .pri { background: #185fa5; color: white; border-color: #185fa5; }
.ma .danger {
  background: #c0392b;
  color: white;
  border-color: #962d22;
  font-weight: 500;
}
.ma .danger:hover { background: #962d22; }

/* ---------- Legend ---------- */

.lg {
  font-size: 11px;
  color: #666;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.lg span { display: inline-flex; align-items: center; gap: 4px; }
.lg i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* ---------- Toast notifications ---------- */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: white;
  border-left: 4px solid #185fa5;
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  min-width: 260px;
  max-width: 360px;
  animation: slideIn 0.2s ease-out;
}
.toast.success { border-left-color: #1d9e75; }
.toast.error { border-left-color: #e24b4a; }
.toast.warning { border-left-color: #ba7517; }
@keyframes slideIn {
  from { transform: translateX(400px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---------- Log history ---------- */

.log-entry {
  padding: 8px 0;
  border-bottom: 1px solid #f1efe8;
  font-size: 12px;
}
.log-entry:last-child { border-bottom: none; }
.log-meta { color: #666; font-size: 11px; margin-top: 2px; }

/* ---------- Spinner & empty / error state ---------- */

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #e5e5e0;
  border-top-color: #185fa5;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 40px;
  color: #666;
  width: 100%;
}
.empty-state.error { color: #e24b4a; }
.empty-state .spinner { width: 20px; height: 20px; }
