:root {
  --bg: #f4f4ef;
  --paper: #fffdf8;
  --ink: #1d1a18;
  --muted: #6a625d;
  --accent: #005f73;
  --accent-2: #0a9396;
  --danger: #ae2012;
  --border: #ddd3c8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 12%, #e9f5f5 0, transparent 35%),
    radial-gradient(circle at 10% 90%, #fef3d7 0, transparent 30%),
    var(--bg);
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

header {
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  border-bottom: 5px solid #0f3f4b;
}

header .wrap {
  padding: 18px 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.auth-box {
  text-align: right;
}

.button-link {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

.button-link:hover {
  background: rgba(255, 255, 255, 0.15);
  text-decoration: none;
}

.link-contrast {
  color: #fff;
  text-decoration: underline;
}

.link-contrast:hover {
  color: #fff;
}

h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.2px;
}

p.sub {
  margin: 6px 0 0;
  opacity: 0.9;
}

.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  padding: 16px;
  margin-top: 16px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-auth {
  grid-template-columns: 1fr;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input,
select,
textarea,
button {
  width: 100%;
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid #c8bfb5;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: #0b7282;
}

.form-actions {
  margin-top: 14px;
  max-width: 260px;
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
}

.ok {
  background: #e7f8ed;
  border: 1px solid #9dd8ae;
  color: #175f2c;
  padding: 10px;
  border-radius: 8px;
}

.err {
  background: #fde9e7;
  border: 1px solid #f0a39c;
  color: var(--danger);
  padding: 10px;
  border-radius: 8px;
}

.table-wrap {
  overflow: auto;
}

.auth-card {
  max-width: 760px;
  margin: 24px auto 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead th {
  text-align: left;
  background: #efe9df;
  border-bottom: 1px solid #d3c7b7;
}

th,
td {
  padding: 8px;
  border-bottom: 1px solid #ece4db;
  vertical-align: top;
}

td {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a {
  color: #0c5c71;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.piani-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.piano-card {
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.piano-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  text-decoration: none;
}

/* Larghezze dinamiche per barre di progresso */
.fill-pct {
  transition: width 0.5s ease;
}

.gruppo-card[style] {
  --pct: 0%;
}

.piano-icona {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.piano-stat {
  display: flex;
  gap: 20px;
  margin: 12px 0;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.minibar {
  height: 6px;
  margin: 8px 0;
}

.piano-cta {
  font-weight: 700;
  color: var(--accent);
  margin-top: auto;
  text-align: right;
}

.progress-card {
  margin-top: 16px;
}

/* ── Layout form moderno ── */
.form-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:16px;}
.form-grid .full-col{grid-column:1/-1;}
.form-grid .half-col{grid-column:span 1;}
@media(max-width:700px){.form-grid{grid-template-columns:1fr;}}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.progress-header h2 {
  margin: 0;
}

.progress-label {
  color: var(--muted);
  font-size: 0.95rem;
}
.progress-label a {
  color: var(--accent);
  text-decoration: underline;
}
.progress-label a:hover {
  color: var(--accent-2);
}

.progress-bar-bg {
  height: 10px;
  background: #e8e2d9;
  border-radius: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  transition: width 0.5s ease;
}

.gruppi-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.gruppo-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.gruppo-card.attivo {
  border-color: var(--accent);
  background: #f0f8fa;
}

.gruppo-card:hover {
  border-color: var(--accent-2);
  text-decoration: none;
}

.gruppo-nome {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.3;
}

.gruppo-stat {
  font-size: 0.82rem;
  color: var(--muted);
}

.gruppo-bar {
  height: 4px;
  background: #e8e2d9;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}

.gruppo-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: width 0.3s;
}

.tema-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.tema-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.tema-section h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: var(--accent);
}

/* ── Card informativa classe ── */
.info-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #f0f8fa;
  border: 1px solid #c5e0e5;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.9rem;
  line-height: 1.5;
}
.info-card .info-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  color: #0a9396;
}
.info-card .info-text {
  color: #2d4a50;
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 10px;
}
.badge.shp-badge {
  background: #e3eef0;
  color: #005f73;
  font-size: 1rem;
  padding: 0 4px;
}
.badge.stato-badge {
  margin-left:8px;
  background: #d5e8e8;
  color: #005f73;
  padding:2px 8px;
  border-radius:12px;
  font-size:0.85em;
}
.required { color: #ae2012; }
.mt4 { margin-top:4px; }
.mb12 { margin-bottom:12px; }
.p15-0 { padding:15px 0; }

/* ── Pulsante small ── */
.small {
  font-size: 0.85rem;
}

/* ── Piano-grid form ── */
.piano-grid-form select {
  font-size: 0.92rem;
}

/* ── Responsive dashboard ── */
@media(max-width:700px) {
  .piani-grid { grid-template-columns: 1fr; }
  .gruppi-list { grid-template-columns: 1fr; }
  .progress-header { flex-direction: column; align-items: flex-start; }
}

.classi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.classi-table th,
.classi-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #ece4db;
}

.classi-table thead th {
  background: #efe9df;
  font-weight: 600;
}

.code-cell {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.82rem;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}

.ok-badge {
  background: #dff0d8;
  color: #3c763d;
}

.empty-badge {
  background: #fcf8e3;
  color: #8a6d3b;
}

.shp-badge {
  background: #d9edf7;
  color: #31708f;
}

.new-badge {
  background: #f5f5f5;
  color: #777;
}

.disabled-badge {
  background: #eee;
  color: #999;
  font-style: italic;
}

.step-num {
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  width: 36px;
}

.action-link {
  font-weight: 600;
}

.inline-form {
  display: inline;
}

.small {
  padding: 3px 8px;
  font-size: 0.82rem;
  width: auto;
}

.danger-btn {
  background: #ae2012;
}

.danger-btn:hover {
  background: #7d150b;
}

.rapidi-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
}

.rapidi-links a {
  padding: 8px 14px;
  background: #efe9df;
  border-radius: 8px;
  font-weight: 600;
}

/* Info card per descrizione classe */
.info-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #e8f4f8;
  border-left: 4px solid var(--accent);
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: 6px;
}

.info-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--accent);
}

/* Toggle switch per campi booleani */
.toggle-label {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc3b8;
  border-radius: 12px;
  transition: 0.3s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-input:checked + .toggle-slider {
  background: #0a9396;
}
.toggle-input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.info-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: #1d3b44;
}

/* Descrizione campo sotto l'etichetta */
.field-desc {
  display: block;
  font-size: 0.78rem;
  font-style: italic;
  color: #6a625d;
  margin-top: 3px;
  margin-bottom: 2px;
  line-height: 1.35;
  max-width: 360px;
}

/* Icona info accanto al label del campo */
.field-info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 0.7rem;
  border-radius: 50%;
  background: #d0e4ea;
  color: var(--accent);
  cursor: help;
  margin-left: 4px;
  vertical-align: middle;
}

.field-info-icon:hover {
  background: var(--accent);
  color: #fff;
}

/* Tooltip info icon nelle tabelle classi */
.classe-nome {
  position: relative;
}

.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 0.75rem;
  border-radius: 50%;
  background: #d0e4ea;
  color: var(--accent);
  cursor: help;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

.info-tip:hover {
  background: var(--accent);
  color: #fff;
}

.rapidi-links a:hover {
  background: #ddd3c8;
  text-decoration: none;
}

@media (max-width: 960px) {
  .topbar {
    flex-direction: column;
  }

  .auth-box {
    text-align: left;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  td {
    white-space: normal;
  }

  .piani-grid {
    grid-template-columns: 1fr;
  }

  .gruppi-list {
    grid-template-columns: 1fr;
  }

  .progress-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Selettore comune a larghezza piena */
.full-width-select {
  width: 100%;
  padding: 0.5em;
  font-size: 1em;
}

/* Griglia selezione piano in index */
.piano-grid-form {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* Piano attivo a tutta larghezza */
.piano-single-col {
  grid-template-columns: 1fr;
}
