:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #FBFBFD;
  --accent: #ec5a28;
  --accent-h: #cc4a1e;
  --ocean: #2E6F8E;
  --text: #1D1D1F;
  --text-2: #6E6E73;
  --border: #E5E5EA;
  --success: #34C759;
  --error: #FF3B30;
  --r-card: 14px;
  --r-btn: 10px;
  --r-input: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --shadow-h: 0 4px 16px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.main { padding: 24px 20px 80px; min-width: 0; }
.page { max-width: 1900px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- sidebar ---------- */
.brand {
  height: 64px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-btn); cursor: pointer; margin-bottom: 8px; padding: 6px;
}
.brand:hover { background: var(--bg); }
.brand img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-ph {
  width: 100%; height: 100%; border: 1.5px dashed var(--border); border-radius: var(--r-btn);
  display: flex; align-items: center; justify-content: center; color: var(--text-2); font-size: 12px;
}
.nav-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-2); padding: 14px 10px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: var(--r-btn);
  color: var(--text); font: inherit; font-weight: 500;
  background: none; border: 0; cursor: pointer; text-align: left;
  transition: background .15s;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: rgba(236,90,40,.1); color: var(--accent); }
.nav-item svg { width: 16px; height: 16px; flex: none; }
.nav-count { margin-left: auto; font-size: 12px; color: var(--text-2); font-weight: 500; }
.nav-add { color: var(--text-2); font-weight: 400; }
.side-foot { margin-top: auto; padding: 8px 10px; }
.link { background: none; border: 0; color: var(--ocean); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.link:hover { text-decoration: underline; }

/* ---------- components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-h); }
.card-flat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow); }
.card-sm { padding: 12px 14px; }

.btn-primary, .btn-secondary {
  font: inherit; font-weight: 600; font-size: 13px;
  padding: 9px 16px; border-radius: var(--r-btn); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--text-2); }
.btn-secondary.danger { color: var(--error); }
.btn-secondary.danger:hover { border-color: var(--error); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: none; border-radius: var(--r-btn); color: var(--text-2); cursor: pointer; flex: none;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { color: var(--error); }
.btn-icon svg { width: 16px; height: 16px; }

.input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-input);
  padding: 8px 10px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(236,90,40,.12); }
textarea.input { resize: vertical; min-height: 38px; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin: 0 0 4px; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: rgba(52,199,89,.14);  color: #1f8a3b; }
.badge-red    { background: rgba(255,59,48,.12);  color: #d1281e; }
.badge-blue   { background: rgba(46,111,142,.13); color: var(--ocean); }
.badge-purple { background: rgba(142,84,233,.12); color: #7342c4; }
.badge-yellow { background: rgba(255,204,0,.2);   color: #8a6d00; }
.badge-gray   { background: #ECECF0; color: var(--text-2); }
.badge-orange { background: rgba(236,90,40,.12);  color: var(--accent); }

@keyframes slide-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.animate-slide-up { animation: slide-up .25s ease-out; }

/* ---------- filtri ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  font: inherit; font-weight: 500; font-size: 13px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; color: var(--text); display: inline-flex; gap: 8px; align-items: center;
  transition: all .15s;
}
.chip span { font-size: 12px; color: var(--text-2); }
.chip:hover { border-color: var(--text-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.active span { color: rgba(255,255,255,.8); }

/* ---------- offerte ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.empty { text-align: center; padding: 48px 16px; color: var(--text-2); }
.offer-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.chev { width: 18px; height: 18px; color: var(--text-2); transition: transform .18s; flex: none; }
.offer.open .chev { transform: rotate(90deg); }
.offer-info { flex: 1; min-width: 0; }
.offer-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.num { font-weight: 700; }
.client { font-weight: 500; }
.desc { color: var(--text-2); margin-top: 2px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--text-2); font-size: 12px; margin-top: 2px; }

.cost-box { display: flex; flex-direction: column; gap: 6px; width: 150px; flex: none; cursor: default; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.cost-input { padding: 6px 10px; }
.cost-box.frozen { width: 210px; }
.cost-box.frozen .check { flex-wrap: wrap; cursor: default; }
.cost-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cost-line strong { font-size: 15px; }
.qnote { flex: 0 1 680px; min-width: 180px; cursor: default; }
.qnote textarea.input { height: 54px; min-height: 54px; resize: vertical; font-size: 13px; padding: 6px 8px; }
.qtext { font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 54px; overflow: auto; }

.offer-body {
  border-top: 1px solid var(--border); background: var(--surface-2);
  padding: 16px 18px 18px; border-radius: 0 0 var(--r-card) var(--r-card);
  display: flex; flex-direction: column; gap: 16px;
}
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions .spacer { flex: 1; }
.note-box { border-radius: var(--r-input); padding: 10px 12px; font-size: 13px; }
.note-box strong { display: block; font-size: 12px; margin-bottom: 2px; }
.note-red { background: rgba(255,59,48,.08); color: #a81f17; }
.note-green { background: rgba(52,199,89,.12); color: #1b6e31; }
.note-yellow { background: rgba(255,204,0,.16); color: #6b5400; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

/* fasi e documenti: righe snelle con caselle affiancate */
.block h3 { margin-bottom: 8px; }
.grid-row { display: grid; gap: 8px; align-items: center; }
.ph-grid  { grid-template-columns: 20px 112px minmax(120px,1.2fr) 132px minmax(140px,1.8fr) minmax(140px,1.2fr) 150px; }
.doc-grid { grid-template-columns: 112px minmax(120px,1.2fr) minmax(110px,1fr) minmax(140px,1.8fr) 140px 150px; }
.row-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); padding: 0 9px 4px; }
.row {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 8px; margin-bottom: 6px; min-height: 46px;
}
.row.editing { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(236,90,40,.08); }
.row .input { padding: 6px 8px; font-size: 13px; }
.row textarea.input { height: 34px; min-height: 34px; resize: vertical; }
.row-done { background: var(--surface-2); }
.row-done .v-title { color: var(--text-2); text-decoration: line-through; }
.v-title { font-weight: 600; word-break: break-word; }
.v-notes { white-space: pre-wrap; word-break: break-word; }
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.add-btn { margin-top: 2px; }
.grip { cursor: grab; color: var(--text-2); user-select: none; text-align: center; letter-spacing: -2px; font-size: 14px; line-height: 1; }
.grip:active { cursor: grabbing; }
.row.dragging { opacity: .4; }
.row.drop-before { box-shadow: 0 -3px 0 0 var(--accent); }
.row.drop-after { box-shadow: 0 3px 0 0 var(--accent); }
.done-cell { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.done-cell input { width: 16px; height: 16px; accent-color: var(--success); margin: 0; cursor: pointer; flex: none; }
.done-date { font-size: 11px; font-weight: 600; color: #1f8a3b; background: rgba(52,199,89,.14); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.assignees { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.assignee-chip {
  display: inline-flex; align-items: center; gap: 2px; background: rgba(46,111,142,.1); color: var(--ocean);
  border-radius: 999px; padding: 1px 2px 1px 9px; font-size: 12px; font-weight: 600;
}
.assignee-chip.ro { padding: 1px 9px; }
.assignee-chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 4px; }
.assignee-add { width: 56px; padding: 3px 4px !important; font-size: 12px !important; }

/* sezione documenti espandibile */
.fold { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.fold-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; border-radius: 12px; }
.fold-head:hover { background: var(--surface-2); }
.fold-head h3 { margin: 0; }
.fold-head .meta { margin: 0 0 0 auto; }
.fold.open .chev { transform: rotate(90deg); }
.fold-body { border-top: 1px solid var(--border); padding: 12px 14px 14px; background: var(--surface-2); border-radius: 0 0 12px 12px; }

.rev-links { font-size: 13px; color: var(--text-2); display: flex; gap: 16px; flex-wrap: wrap; }
.rev-links .link { font-size: 13px; font-weight: 600; }
.btn-danger { font: inherit; font-weight: 600; font-size: 13px; padding: 9px 16px; border-radius: var(--r-btn); cursor: pointer; background: var(--error); color: #fff; border: 1px solid var(--error); }
.btn-danger:hover { filter: brightness(.92); }
.dlg-msg { line-height: 1.5; }
.dlg-wrap { flex-wrap: wrap; }

/* team */
.inline-form { display: flex; gap: 12px; align-items: flex-end; padding: 16px; }
.inline-form > div { flex: 1; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 16px; }
.person { display: flex; align-items: center; gap: 12px; }
.person > div:nth-child(2) { flex: 1; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: rgba(236,90,40,.12); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none;
}
.pname { font-weight: 600; }

/* dialog */
dialog { border: 0; border-radius: var(--r-card); padding: 0; width: min(480px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dlg-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg-form h3 { font-size: 17px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 140px; gap: 12px; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: var(--r-btn); font-weight: 500;
  transition: all .2s; z-index: 100;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .ph-grid, .doc-grid { grid-template-columns: 1fr; }
  .row-head { display: none; }
  .row-actions { justify-content: flex-start; }
  .grip { display: none; }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { width: 120px; height: 44px; margin: 0; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
  .nav-title, .side-foot { display: none; }
  .nav-item { width: auto; }
  .main { padding: 20px 16px 60px; }
  .offer-head { flex-wrap: wrap; }
  .cost-box, .cost-box.frozen { width: 100%; flex-direction: row; align-items: center; }
  .qnote { flex: 1 1 100%; }
}
