/* PSC Web App — Design System */
@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700&family=Barlow+Condensed:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────────────────── */
:root {
  --navy:       #1a2744;
  --navy-dark:  #111b30;
  --navy-mid:   #243360;
  --navy-light: #2e4080;
  --accent:     #c8490a;
  --accent-hover: #e05510;
  --accent-light: #f9ede7;
  --gold:       #d4a017;
  --success:    #2e7d54;
  --success-bg: #eaf4ef;
  --warning:    #b45309;
  --warning-bg: #fef3e2;
  --danger:     #c0392b;
  --danger-bg:  #fdecea;
  --bg:         #f5f4f0;
  --bg-card:    #ffffff;
  --border:     #ddd9d0;
  --border-light: #eeebe4;
  --text:       #1a1a1a;
  --text-mid:   #4a4a4a;
  --text-muted: #888880;
  --sidebar-w:  240px;
  --header-h:   56px;
  --radius:     4px;
  --radius-lg:  8px;
  --shadow:     0 1px 4px rgba(0,0,0,.10);
  --shadow-lg:  0 4px 16px rgba(0,0,0,.12);
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Barlow', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────── */
.app-header {
  grid-column: 1 / -1;
  background: var(--navy-dark);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header .logo {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  letter-spacing: .04em;
  white-space: nowrap;
}
.app-header .logo span { color: var(--accent); }
.header-project {
  flex: 1;
  color: rgba(255,255,255,.6);
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-project strong { color: rgba(255,255,255,.9); font-weight: 600; }
.header-actions { display: flex; gap: 8px; margin-left: auto; }
.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-bozza    { background: rgba(255,255,255,.15); color: rgba(255,255,255,.7); }
.badge-definitivo { background: var(--gold); color: #1a1a1a; }
.badge-trasmesso  { background: var(--success); color: #fff; }
.progress-ring {
  width: 32px; height: 32px;
  transform: rotate(-90deg);
}
.progress-ring circle {
  fill: none;
  stroke-width: 3;
  cx: 16; cy: 16; r: 13;
}
.progress-ring .track { stroke: rgba(255,255,255,.15); }
.progress-ring .fill  { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.progress-label {
  font-size: .7rem;
  color: rgba(255,255,255,.5);
  font-family: 'IBM Plex Mono', monospace;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.app-sidebar {
  background: var(--navy);
  overflow-y: auto;
  border-right: 1px solid var(--navy-dark);
  padding: 12px 0 24px;
}
.sidebar-section-label {
  padding: 16px 16px 6px;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: rgba(255,255,255,.65);
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
  position: relative;
}
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-link.active {
  background: rgba(200,73,10,.15);
  border-left-color: var(--accent);
  color: #fff;
}
.sidebar-icon {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: .9rem;
}
.sidebar-link-text { flex: 1; }
.sidebar-status {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}
.sidebar-status.done    { background: var(--success); }
.sidebar-status.partial { background: var(--gold); }
.sidebar-status.empty   { background: rgba(255,255,255,.15); }

/* ── Main Content ─────────────────────────────────────────────────────── */
.app-main {
  overflow-y: auto;
  padding: 28px 32px;
}

/* ── Page Header ─────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .02em;
  line-height: 1.1;
}
.page-subtitle {
  margin-top: 4px;
  font-size: .8rem;
  color: var(--text-muted);
}

/* ── Sezione ─────────────────────────────────────────────────────────── */
.section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  background: #faf9f6;
  cursor: pointer;
  user-select: none;
}
.section-head:hover { background: #f5f3ed; }
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.section-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  background: var(--navy);
  color: #fff;
  border-radius: 50%;
  font-size: .7rem;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  flex-shrink: 0;
}
.section-toggle {
  font-size: .75rem;
  color: var(--text-muted);
  transition: transform .2s;
}
.section-toggle.open { transform: rotate(180deg); }
.section-body { padding: 20px; }
.section-body.collapsed { display: none; }

/* ── Form Elements ─────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px 20px;
}
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field.half-l { grid-column: 1 / 2; }
.field.half-r { grid-column: 2 / 3; }

label {
  font-size: .73rem;
  font-weight: 600;
  color: var(--text-mid);
  letter-spacing: .04em;
  text-transform: uppercase;
}
label .req { color: var(--accent); margin-left: 2px; }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: .875rem;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(46,64,128,.12);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
textarea { resize: vertical; min-height: 80px; }
input[type="checkbox"] { width: auto; accent-color: var(--navy); }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: .875rem;
  color: var(--text-mid);
}
.checkbox-row input { cursor: pointer; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 600;
  font-family: 'Barlow', sans-serif;
  letter-spacing: .03em;
  border: none;
  transition: background .15s, transform .1s;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-mid); }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-mid);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .73rem; }
.btn-xs { padding: 3px 7px; font-size: .7rem; }
.btn-icon { padding: 6px 8px; }

/* ── Cards repeater ─────────────────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 12px; }
.card-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
}
.card-item-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: #faf9f6;
  cursor: pointer;
  user-select: none;
}
.card-item-head:hover { background: #f4f2ea; }
.card-item-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px; height: 22px;
  padding: 0 7px;
  background: var(--navy);
  color: #fff;
  border-radius: 11px;
  font-size: .68rem;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  flex-shrink: 0;
}
.card-item-badge.ruolo-affidataria { background: var(--navy); }
.card-item-badge.ruolo-sub         { background: var(--navy-mid); }
.card-item-badge.ruolo-autonomo    { background: #5a6a8a; }
.card-item-title {
  flex: 1;
  font-weight: 600;
  font-size: .875rem;
  color: var(--text);
}
.card-item-title .hint { font-weight: 400; color: var(--text-muted); }
.card-item-actions { display: flex; gap: 4px; }
.card-item-body { padding: 16px 14px; border-top: 1px solid var(--border-light); }
.card-item-body.collapsed { display: none; }

/* Drag handle */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  padding: 4px;
  font-size: 1.1rem;
}
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: .4; background: var(--accent-light) !important; }

/* ── Alert / Notice ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .83rem;
  margin-bottom: 16px;
}
.alert-info    { background: #eaf0fb; color: #1e3a8a; border: 1px solid #bfcfee; }
.alert-warning { background: var(--warning-bg); color: #7c3a00; border: 1px solid #f5cca0; }
.alert-success { background: var(--success-bg); color: #1a5c3a; border: 1px solid #a4d4bc; }
.alert-danger  { background: var(--danger-bg); color: #7b1111; border: 1px solid #f5b7b1; }
.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }

/* ── Table ─────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
}
.data-table th {
  text-align: left;
  padding: 8px 12px;
  background: #f0ede5;
  border-bottom: 2px solid var(--border);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-mid);
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #faf9f6; }
.data-table input, .data-table select {
  border: 1px solid transparent;
  background: transparent;
  padding: 3px 6px;
  width: 100%;
}
.data-table input:focus, .data-table select:focus {
  border-color: var(--border);
  background: #fff;
}
.cell-num  { text-align: right; font-family: 'IBM Plex Mono', monospace; }
.cell-code { font-family: 'IBM Plex Mono', monospace; font-weight: 500; color: var(--navy); }
.table-footer {
  padding: 10px 12px;
  background: #f5f2e9;
  border-top: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .83rem;
}
.total-label { font-weight: 600; color: var(--text-mid); }
.total-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
}

/* ── Trasmissioni ─────────────────────────────────────────────────── */
.trasmissione-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.trasmissione-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #faf9f6;
}
.trasmissione-type {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
}
.type-invio_psc      { background: #dbeafe; color: #1e40af; }
.type-aggiornamento  { background: #fce7f3; color: #831843; }
.type-modulo_obbligo { background: #dcfce7; color: #14532d; }
.type-organigramma   { background: #fef3c7; color: #78350f; }
.type-richiesta_dati { background: #f3e8ff; color: #4c1d95; }

.stato-badge {
  margin-left: auto;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}
.stato-bozza     { background: #e5e7eb; color: #374151; }
.stato-inviato   { background: #dbeafe; color: #1e40af; }
.stato-confermato{ background: #dcfce7; color: #14532d; }

.suggerimento-card {
  border-left: 3px solid var(--accent);
  background: var(--accent-light);
  padding: 14px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.sug-icon { font-size: 1.3rem; flex-shrink: 0; }
.sug-body { flex: 1; }
.sug-title { font-weight: 700; color: var(--navy); font-size: .9rem; }
.sug-desc  { font-size: .82rem; color: var(--text-mid); margin-top: 3px; }
.sug-actions { margin-top: 10px; display: flex; gap: 8px; }

/* ── Checklist ─────────────────────────────────────────────────────── */
.checklist { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.checklist li {
  display: flex; align-items: center; gap: 8px;
  font-size: .83rem; color: var(--text-mid);
}
.check-icon { width: 18px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-size: .7rem; }
.check-icon.ok  { background: var(--success-bg); color: var(--success); }
.check-icon.nok { background: var(--danger-bg); color: var(--danger); }
.check-icon.warn{ background: var(--warning-bg); color: var(--warning); }

/* ── Interferenze matrix ─────────────────────────────────────────────── */
.int-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.int-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #faf9f6; cursor: pointer;
}
.int-codes { display: flex; align-items: center; gap: 6px; }
.int-code {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700; font-size: .85rem;
  background: var(--navy); color: #fff;
  padding: 2px 8px; border-radius: 3px;
}
.int-arrow { color: var(--accent); font-size: 1rem; }
.int-title { flex: 1; font-size: .83rem; color: var(--text-mid); }
.int-sfasamenti { display: flex; gap: 6px; }
.sfas-tag {
  font-size: .65rem; font-weight: 700; padding: 2px 6px; border-radius: 10px;
  background: #e5e7eb; color: #374151;
  letter-spacing: .04em; text-transform: uppercase;
}
.sfas-tag.attivo-spaz { background: #dbeafe; color: #1e40af; }
.sfas-tag.attivo-temp { background: #d1fae5; color: #065f46; }
.int-body { padding: 14px; border-top: 1px solid var(--border-light); }

/* ── Toast ─────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: .83rem;
  font-weight: 600;
  background: var(--navy-dark);
  color: #fff;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  animation: slideIn .2s ease;
}
.toast.saved  { border-left: 3px solid var(--success); }
.toast.error  { border-left: 3px solid var(--danger); background: #2c1010; }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Utility ─────────────────────────────────────────────────────────── */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.flex  { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap-8 { gap: 8px; }
.flex-gap-12 { gap: 12px; }
.gap-8  { gap: 8px; }
.gap-16 { gap: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.text-mono { font-family: 'IBM Plex Mono', monospace; }
.text-right { text-align: right; }
.divider { border: none; border-top: 1px solid var(--border-light); margin: 16px 0; }
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  background: var(--border-light); color: var(--text-mid);
}
.tag-navy { background: var(--navy); color: #fff; }

/* ── Print ─────────────────────────────────────────────────────────── */
@media print {
  .app-header, .app-sidebar, .no-print { display: none !important; }
  .app-main { padding: 0; overflow: visible; }
  .app-layout { display: block; }
}

/* ── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.25); }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 52px; }
  .sidebar-link-text, .sidebar-section-label { display: none; }
  .app-main { padding: 20px 16px; }
}
