/* Palette controlli (allineata al bordeaux del sito) */
:root {
  --form-accent: #7a0b12;
  --form-control-text: #1a1a1a;
  --caritas-red: #7a0b12;
  --surface-bg: #f6f6f8;
  --surface-card: #ffffff;
  --surface-top: #ffffff;
  --border-soft: #e5e7eb;
  --text-main: #111111;
  --text-muted: #666666;
  --surface-input: #ffffff;
  --surface-table-alt: #f8fafc;
  --surface-table-hover: var(--nav-active-bg);
  --surface-table-hover-border: var(--nav-active-border);
  --surface-code: #f1f5f9;
  --border-strong: #cbd5e1;
  /* Barra menu superiore (partner / capofila / comune) */
  --nav-active-bg: rgba(122, 11, 18, 0.1);
  --nav-active-border: rgba(122, 11, 18, 0.18);
  --nav-dropdown-bg: #ffffff;
  --nav-dropdown-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
  --nav-badge-bg: rgba(122, 11, 18, 0.12);
  --nav-badge-text: #5c0a0f;
  /* Accento programma (barra alto + badge) */
  --program-accent-bar: var(--caritas-red);
  --program-top-bg: var(--surface-top);
  --program-top-edge: var(--border-soft);
  --program-chip-bg: rgba(122, 11, 18, 0.1);
  --program-chip-text: var(--nav-badge-text);
  /* Scala tipografica globale (coerenza cross-page) */
  --font-size-base: 12px;
  --font-size-muted: 12px;
  --font-size-heading: 16px;
  --font-size-subheading: 14px;
  --font-size-table: 12px;
  --font-size-chip: 11px;
  --font-size-nav: 13px;
  /* Stack unico: le pagine usano var(--font-sans) invece di ripetere la lista. */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Tipografia globale CoproGest */
html,
body {
  font-size: var(--font-size-base);
}

body {
  font-family: var(--font-sans);
  line-height: 1.45;
  color: var(--text-main);
  background: var(--surface-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.top {
  position: relative;
  z-index: 20;
  overflow: visible;
  background: var(--program-top-bg, var(--surface-top, #ffffff));
  border-bottom: 1px solid var(--program-top-edge, var(--border-soft, #e5e7eb));
  box-shadow: inset 0 3px 0 var(--program-accent-bar, var(--caritas-red, #7a0b12));
}

/* Pagine con stile inline su .top: rispetta comunque il tema programma */
html:has(#copro-program-theme) .top {
  background: var(--program-top-bg, var(--surface-top)) !important;
  border-bottom-color: var(--program-top-edge, var(--border-soft)) !important;
  box-shadow: inset 0 3px 0 var(--program-accent-bar) !important;
}

.top > :last-child {
  margin-left: auto;
  align-items: flex-end;
  text-align: right;
}

.top h1 {
  font-size: var(--font-size-heading) !important;
  line-height: 1.25 !important;
}

.card h2,
.card h3 {
  font-size: var(--font-size-subheading) !important;
  line-height: 1.3 !important;
}

.muted {
  font-size: var(--font-size-muted) !important;
}

.btnlink {
  color: var(--caritas-red);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--font-size-base);
}

.btnlink:hover,
.btnlink:focus {
  text-decoration: underline;
}

table {
  font-size: var(--font-size-table) !important;
}

th,
td {
  font-size: var(--font-size-table) !important;
}

.btn,
.btn-small,
button,
input,
select,
textarea {
  font-size: var(--font-size-base);
}

/* Azioni nei filtri: tiene Applica/Reset allineati alla base dei campi. */
.filter-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 2.5rem;
  flex-wrap: wrap;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--surface-input);
  color: var(--text-main);
  line-height: 1;
  text-decoration: none;
  box-sizing: border-box;
}

code {
  background: var(--surface-code);
  color: var(--text-main);
  border-radius: 4px;
}

.pill,
.status-badge,
.flow-tag,
.partner-tag {
  font-size: var(--font-size-chip) !important;
}

/* Logo brand (CoproGest) nella barra menu e varianti */
.copro-nav-brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px 4px;
  margin-left: 2px;
  border-radius: 8px;
  line-height: 0;
  text-decoration: none;
  opacity: 0.95;
  transition: opacity 0.15s ease;
}
.copro-nav-brand-logo:hover {
  opacity: 1;
}
.copro-nav-brand-logo img {
  display: block;
  height: 34px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  vertical-align: middle;
}

/* Login / password reset: logo fisso angolo (non interferisce con il flusso centrale) */
.copro-corner-logo {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 100;
  line-height: 0;
}
@media (max-width: 900px) {
  .copro-corner-logo {
    top: 10px;
    right: 10px;
  }
}

/* --- Menu applicativo (coerenza tra pagine) --- */
.copro-nav-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  gap: 2px 0;
  font-size: var(--font-size-nav);
  line-height: 1.25;
}

.copro-nav-sep {
  display: inline-block;
  width: 1px;
  height: 14px;
  margin: 0 6px;
  background: var(--border-soft);
  align-self: center;
  flex-shrink: 0;
}

.copro-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: inherit;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  text-decoration: none;
  color: var(--caritas-red);
  background: transparent;
  cursor: pointer;
  box-sizing: border-box;
  vertical-align: middle;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.copro-nav-link:hover {
  background: rgba(122, 11, 18, 0.06);
  border-color: rgba(122, 11, 18, 0.12);
  text-decoration: none;
}

.copro-nav-link.is-active {
  background: var(--nav-active-bg);
  border-color: var(--nav-active-border);
  font-weight: 500;
}

.copro-nav-link--chev {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1;
  margin-left: 1px;
}

button.copro-nav-link {
  min-height: unset;
  -webkit-appearance: none;
  appearance: none;
}

/* Username · Esci (barra menu in alto a destra) */
.copro-nav-logout-cluster {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
}

.copro-nav-session {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
  margin-left: 2px;
  padding: 6px 2px 6px 4px;
  font-size: 12px;
  line-height: 1.25;
  color: var(--text-muted);
  white-space: nowrap;
}

.copro-page-program {
  display: contents;
  line-height: 1.25;
}

.copro-page-program--themed .copro-page-program__name {
  padding-left: 10px;
  border-left: 3px solid var(--program-border, var(--caritas-red, #7a0b12));
}

.copro-page-program__label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted, #64748b);
}

.copro-page-program__name {
  font-size: var(--font-size-heading, 16px);
  font-weight: 700;
  color: var(--caritas-red, #7a0b12);
  line-height: 1.25;
  min-width: 0;
}

.copro-page-program__theme {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  color: var(--program-chip-text, var(--text-muted, #64748b));
  background: var(--program-chip-bg, transparent);
  letter-spacing: 0.02em;
}

html:has(#copro-program-theme) .copro-page-program__theme {
  color: var(--program-chip-text);
  background: var(--program-chip-bg);
}

/* Intestazione pagina: etichetta programma sopra, nome programma + titolo partner/capofila affiancati a sinistra */
.top > div:first-child:has(.copro-page-program__name) {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  align-content: flex-start;
  column-gap: 10px;
  row-gap: 4px;
  width: fit-content;
  max-width: calc(100% - 12px);
}

.top > div:first-child:has(.copro-page-program__name) > .copro-launch-strip,
.top > div:first-child:has(.copro-page-program__name) .copro-page-program__label,
.top > div:first-child:has(.copro-page-program__name) .copro-page-program__theme,
.top > div:first-child:has(.copro-page-program__name) > .muted,
.top > div:first-child:has(.copro-page-program__name) > .exercise-year-line,
.top > div:first-child:has(.copro-page-program__name) > details,
.top > div:first-child:has(.copro-page-program__name) > p {
  flex: 0 0 100%;
}

.top > div:first-child:has(.copro-page-program__name) .copro-page-program__name,
.top > div:first-child:has(.copro-page-program__name) > h1 {
  flex: 0 1 auto;
  min-width: 0;
}

.top > div:first-child:has(.copro-page-program__name) > h1 {
  margin: 0 !important;
  white-space: nowrap;
}

.top > div:first-child:has(.copro-page-program__name) > h1::before {
  content: "·";
  margin-right: 10px;
  color: var(--text-muted, #94a3b8);
  font-weight: 400;
}

@media (max-width: 720px) {
  .top > div:first-child:has(.copro-page-program__name) .copro-page-program__name,
  .top > div:first-child:has(.copro-page-program__name) > h1 {
    flex: 0 0 100%;
    white-space: normal;
  }

  .top > div:first-child:has(.copro-page-program__name) > h1::before {
    display: none;
  }
}

.copro-nav-session__program {
  font-weight: 700;
  color: var(--caritas-red, #7a0b12);
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(32vw, 280px);
}

.copro-nav-session__partner {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(28vw, 240px);
}

.copro-nav-session__username {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(28vw, 220px);
  color: var(--text-main, #111827);
}

.copro-nav-session__sep {
  margin: 0 5px;
  opacity: 0.55;
  flex-shrink: 0;
}

.copro-nav-user {
  margin-left: 2px;
  padding: 6px 2px 6px 4px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Username fisso a destra quando il menu a tendina è chiuso (viewport stretti) */
.copro-nav-user--peek {
  display: none;
}

.copro-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  background: var(--nav-badge-bg);
  color: var(--nav-badge-text);
  font-variant-numeric: tabular-nums;
}

.copro-nav-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.copro-nav-dropdown > summary {
  list-style: none;
  cursor: pointer;
}

.copro-nav-dropdown > summary::-webkit-details-marker {
  display: none;
}

.copro-nav-dropdown__panel {
  position: absolute;
  right: 0;
  z-index: 1200;
  margin-top: 6px;
  padding: 10px 12px;
  min-width: 260px;
  max-width: min(92vw, 560px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--nav-dropdown-bg);
  box-shadow: var(--nav-dropdown-shadow);
}

/* Messaggi applicativi (Django messages): verde success, rosso error, ambra info/warning. */
.msgbox {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: var(--font-size-base);
  border: 1px solid #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.msgbox--success {
  border-color: #16a34a;
  background: #f0fdf4;
  color: #166534;
}

.msgbox--error {
  border-color: #dc2626;
  background: #fef2f2;
  color: #991b1b;
}

.msgbox--warning,
.msgbox--info {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

/* Messaggi in cima: restano nel flusso documento (niente sticky).
   Lo sticky + ombra faceva “strappare” l’header allo scroll verticale. */
.msgbox-stack--sticky {
  position: relative;
  top: auto;
  z-index: auto;
  padding-bottom: 0;
  margin-bottom: 12px;
  box-shadow: none;
}

.copro-nav-dropdown__panel .btnlink {
  font-weight: 500;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Le pagine spesso ridefiniscono `.btnlink` con pesi diversi: il menu resta uniforme. */
.top .copro-nav-bar .copro-nav-link,
.top .copro-nav-bar .copro-nav-link.is-active {
  font-weight: 500;
}

.top .copro-nav-bar .copro-nav-dropdown__panel .btnlink {
  font-weight: 500;
}

.reporting-nav-cluster {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  font-size: 13px;
}

.reporting-nav-cluster .copro-nav-link {
  white-space: nowrap;
}

.copro-nav-shell {
  display: contents;
}

.copro-nav-toggle {
  display: none;
}

.reporting-nav-alert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #facc15;
  color: #7c2d12;
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  cursor: help;
  flex-shrink: 0;
}

.copro-nav-dropdown__panel--wide {
  min-width: 320px;
}

.copro-hscroll,
.copro-table-scroll,
.scrollX {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
}

.copro-hscroll > table,
.copro-table-scroll > table,
.scrollX > table {
  display: table;
  width: max-content;
  min-width: 100%;
  max-width: none;
}

/* Banner consultazione-only su mobile */
.copro-mobile-readonly-banner {
  width: 100%;
  box-sizing: border-box;
  border-bottom: 1px solid #60a5fa;
  background: #eff6ff;
  font-family: var(--font-sans);
}

.copro-mobile-readonly-banner__inner {
  padding: 9px max(12px, env(safe-area-inset-left, 0px)) 9px max(12px, env(safe-area-inset-right, 0px));
  font-size: 13px;
  color: #1e3a8a;
  line-height: 1.45;
}

@media (max-width: 1200px) {
  html {
    overflow-x: hidden;
  }

  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  body.copro-nav-menu-open {
    overflow: hidden;
  }

  .top {
    flex-wrap: wrap;
    align-items: flex-start !important;
    padding-top: max(14px, env(safe-area-inset-top, 0px)) !important;
    padding-right: max(12px, env(safe-area-inset-right, 0px)) !important;
    padding-left: max(12px, env(safe-area-inset-left, 0px)) !important;
    max-width: 100%;
    box-sizing: border-box;
  }

  .top > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    padding-right: min(200px, 42vw);
    box-sizing: border-box;
  }

  /* Colonna nav in pagina: non allargare oltre lo schermo */
  .top > div:last-child {
    flex: 0 0 auto;
    max-width: 100%;
    margin-left: auto;
    min-width: 0;
  }

  .top > .copro-nav-shell,
  .top .copro-nav-shell {
    flex: 0 0 auto;
    margin: 0 !important;
  }

  /* Ancoraggio unico in alto a destra: hamburger + username non escono dal viewport */
  .copro-nav-shell {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    position: fixed;
    top: max(10px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    left: auto;
    width: auto;
    max-width: min(calc(100vw - 24px), calc(100% - 24px));
    min-width: 0;
    min-height: 44px;
    height: auto;
    z-index: 1001;
    overflow: visible;
    pointer-events: none;
    box-sizing: border-box;
  }

  .copro-nav-shell > .copro-nav-toggle,
  .copro-nav-shell > .copro-nav-user--peek,
  .copro-nav-shell > .copro-nav-session.copro-nav-user--peek,
  .copro-nav-shell > .copro-nav-bar.copro-nav-links {
    pointer-events: auto;
  }

  .copro-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 219;
    background: rgba(15, 23, 42, 0.38);
    border: 0;
    margin: 0;
    padding: 0;
    cursor: pointer;
    pointer-events: auto;
  }

  body.copro-nav-menu-open .copro-nav-backdrop {
    display: block;
  }

  .copro-nav-user--peek,
  .copro-nav-session.copro-nav-user--peek {
    display: inline-flex !important;
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    z-index: 1;
    margin: 0;
    padding: 8px 10px;
    max-width: min(38vw, 168px);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    background: var(--surface-card);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-muted);
    pointer-events: none;
    flex: 0 1 auto;
  }

  .copro-nav-toggle {
    display: inline-flex !important;
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    z-index: 2;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    margin: 0;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--surface-card);
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    color: var(--caritas-red);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .copro-nav-bar.copro-nav-links {
    display: none !important;
    position: fixed;
    top: max(64px, calc(10px + env(safe-area-inset-top, 0px) + 44px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    width: auto;
    max-width: none;
    z-index: 220;
    max-height: calc(100dvh - 80px - env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    background: var(--surface-card);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    box-sizing: border-box;
  }

  .copro-nav-bar.copro-nav-links.is-open {
    display: flex !important;
  }

  .copro-nav-bar .copro-nav-sep {
    display: none;
  }

  .copro-nav-bar .copro-nav-dropdown {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .copro-nav-bar.copro-nav-links .copro-nav-dropdown__panel {
    position: static !important;
    right: auto !important;
    margin-top: 8px !important;
    min-width: 0 !important;
    width: 100%;
    box-shadow: none !important;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
  }

  .copro-nav-bar.copro-nav-links .copro-nav-dropdown__panel .muted {
    display: none;
  }

  .copro-nav-bar.copro-nav-links .copro-nav-dropdown__panel .btnlink {
    display: block;
    width: 100%;
    padding: 10px 8px;
    min-height: 44px;
    line-height: 1.35;
    box-sizing: border-box;
  }

  .copro-nav-bar.copro-nav-links .copro-nav-link,
  .copro-nav-bar.copro-nav-links .copro-nav-dropdown > summary {
    min-height: 44px;
    width: 100%;
    box-sizing: border-box;
    color: var(--text-main);
  }

  .copro-nav-bar.copro-nav-links .btnlink {
    display: inline-block;
    padding: 8px 4px;
    min-height: 40px;
    line-height: 1.35;
  }

  .copro-nav-bar.copro-nav-links details.copro-nav-dropdown > summary {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .copro-nav-bar.copro-nav-links .muted {
    color: var(--text-muted) !important;
  }

  .reporting-nav-cluster {
    flex-wrap: wrap;
    width: 100%;
  }
}

/* Evita sovrapposizioni tra campi e allinea box-sizing al bordo.
   Checkbox/radio esclusi: altrimenti diventano enormi (min-height su tutti gli input). */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea,
button {
  box-sizing: border-box;
  max-width: 100%;
  min-height: 2.5rem;
  line-height: 1.35;
}

input[type="checkbox"],
input[type="radio"] {
  box-sizing: border-box;
  width: 1.05rem;
  height: 1.05rem;
  min-height: unset;
  max-width: none;
  margin: 0 0.5rem 0 0;
  vertical-align: middle;
  flex-shrink: 0;
  accent-color: var(--form-accent);
  cursor: pointer;
  border-radius: 2px;
}

input[type="radio"] {
  border-radius: 50%;
}

/* Controlli compatti nelle tabelle elenco (non i CTA di pagina). */
.table-wrap button,
.table-scroll button,
.todo-table-wrap button,
.bundle-table button,
.copro-table-scroll button,
.sem-tree button {
  min-height: unset;
  line-height: 1.2;
}

/* Allinea label accanto ai controlli nelle liste di opzioni (radio/checkbox) */
ul li label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--form-control-text);
  cursor: pointer;
  font-weight: 500;
}

ul li:has(input[type="radio"]),
ul li:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
}

textarea {
  min-height: 4.75rem;
  vertical-align: top;
}

.form-field {
  margin-bottom: 14px;
}

.form-field > label,
label.field-label {
  display: block;
  margin-bottom: 6px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  align-items: start;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 16px;
  align-items: start;
}

@media (max-width: 720px) {
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Radio / checkbox: elenchi di opzioni nei form */
ul {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
}

ul li {
  margin-bottom: 8px;
}

ul.errorlist {
  margin: 4px 0 0;
  padding-left: 1.1rem;
  list-style: disc;
}

/* Promemoria/stato rendicontazione: barra uniforme tra partner e capofila. */
.reporting-status-strip {
  position: sticky;
  top: 0;
  z-index: 90;
  width: 100%;
  box-sizing: border-box;
  border-bottom: 1px solid #f59e0b;
  background: #fffbeb;
  font-family: var(--font-sans);
}

.reporting-status-strip--neutral {
  z-index: 85;
  border-bottom-color: #cbd5e1;
  background: #f8fafc;
}

.reporting-status-inner,
.reporting-reminder-details > summary {
  padding: 10px 22px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  font-size: 13px;
  line-height: 1.45;
  color: #92400e;
}

.reporting-status-strip--neutral .reporting-status-inner {
  color: #334155;
}

.reporting-status-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.reporting-status-link {
  color: #9a3412;
  font-weight: 700;
  text-decoration: none;
}

.reporting-status-strip--neutral .reporting-status-link {
  color: #7a0b12;
}

.reporting-reminder-close {
  border: 1px solid #f59e0b;
  background: #fff7ed;
  color: #9a3412;
  border-radius: 999px;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  line-height: 1;
  font-weight: 800;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.reporting-reminder-body {
  margin: 0 22px;
  padding: 10px 0 14px;
  border-top: 1px dashed #fcd34d;
  font-size: 13px;
  color: #78350f;
  line-height: 1.5;
}

.reporting-reminder-details > summary {
  list-style: none;
}
.reporting-reminder-details > summary::-webkit-details-marker {
  display: none;
}

.dashboard-scroll-hint {
  display: none;
}

.copro-nav-kbd-hint {
  font-size: 11px;
  opacity: 0.75;
}

@media (max-width: 900px) {
  :root {
    --font-size-base: 13px;
    /* Tabelle: restano dense su desktop stretto (801–900px); evita righe alte. */
    --font-size-table: 12px;
    --font-size-nav: 14px;
    --font-size-heading: 17px;
    --font-size-subheading: 15px;
  }

  body {
    line-height: 1.5;
  }

  table {
    line-height: 1.25;
  }

  .muted {
    line-height: 1.45;
  }

  .top {
    padding: 14px 12px !important;
    align-items: flex-start !important;
  }

  .wrap {
    padding: 14px !important;
  }

  .top h1 {
    font-size: 15px !important;
    line-height: 1.3 !important;
  }

  .card {
    padding: 14px !important;
    border-radius: 12px !important;
  }

  .btn {
    min-height: 40px;
  }

  .top > div:last-child:not(.copro-nav-shell) {
    width: auto;
    max-width: 100%;
  }

  .copro-nav-bar.copro-nav-links.is-open {
    width: auto;
    justify-content: flex-start;
    gap: 8px;
  }

  .copro-nav-user--peek,
  .copro-nav-session.copro-nav-user--peek {
    max-width: min(34vw, 140px);
  }

  .copro-nav-sep {
    display: none;
  }

  .dashboard-scroll-hint {
    display: block;
  }

  .copro-nav-kbd-hint {
    display: none;
  }

  .reporting-status-inner,
  .reporting-reminder-details > summary,
  .reporting-reminder-body {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .reporting-status-actions {
    white-space: normal;
    flex-wrap: wrap;
  }

  .card:has(> table),
  .card:has(> .copro-hscroll),
  .card:has(> .copro-table-scroll),
  .box:has(> table),
  .box:has(> .copro-hscroll),
  .wrap:has(> .card > table),
  .wrap:has(> .card > .copro-hscroll),
  .wrap:has(> .card > .copro-table-scroll) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  .card > table,
  .wrap table {
    min-width: 520px;
  }

  table th,
  table td {
    white-space: nowrap;
  }

  .amount-split {
    min-width: 7.5rem;
  }

  .wrap,
  .wrap .card,
  .wrap .grid,
  .wrap .grid > .card {
    max-width: 100%;
    min-width: 0;
  }

  .wrap .card:has(details.area-card) {
    overflow-x: hidden;
  }

  /* Dashboard: scroll orizzontale dentro l'area aperta (tabelle wide) */
  details.area-card {
    max-width: 100% !important;
    min-width: 0;
    overflow: hidden !important;
  }

  details.area-card > .detailsBody {
    max-width: 100% !important;
    min-width: 0;
    overflow: hidden !important;
  }

  .copro-hscroll,
  .copro-table-scroll,
  .scrollX,
  .dashboard-area-scroll {
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    padding-bottom: 6px;
    margin-bottom: 4px;
  }

  .copro-hscroll > table,
  .copro-table-scroll > table,
  .scrollX > table,
  .dashboard-area-scroll > table {
    width: max-content !important;
    min-width: 720px !important;
    max-width: none !important;
  }

  .scrollX > table.grouped-table,
  .scrollX > table.super-table,
  .scrollX > .grouped-table,
  .scrollX > .super-table,
  .scrollX > table.line-table,
  .dashboard-area-scroll > table.grouped-table {
    table-layout: auto !important;
  }

  .grouped-table > thead > tr:first-child > th:first-child,
  .grouped-table > tbody > tr:not(.action-voice-row) > td:first-child,
  .grouped-table > thead > tr:nth-child(2) > th {
    width: auto !important;
    min-width: 0;
  }

  .action-voice-panel {
    max-width: 100%;
    min-width: 0;
    overflow-x: visible;
    overflow-y: visible;
  }

  html.copro-native-app details.area-card,
  html.copro-native-app details.area-card > .detailsBody,
  html.copro-native-app .wrap .card:has(details.area-card) {
    overflow-x: visible !important;
    overflow-y: visible !important;
  }

  .action-voice-row .scrollX {
    margin-left: 0;
    margin-right: 0;
  }

  /* App nativa WebView: forza scroll orizzontale tabelle anche oltre breakpoint mobile */
  html.copro-native-app .copro-hscroll,
  html.copro-native-app .copro-table-scroll,
  html.copro-native-app .scrollX,
  html.copro-native-app .dashboard-area-scroll,
  html.copro-native-app .card:has(> table),
  html.copro-native-app .box:has(> table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  details.area-card > summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .sumMeta {
    justify-content: flex-start !important;
    white-space: normal !important;
  }

  .action-voice-panel .line-table {
    min-width: 520px;
    width: max-content;
  }

  .dash-exp-group-scroll > table,
  .dash-line-groups-scroll > table {
    width: max-content !important;
    min-width: 720px !important;
    max-width: none !important;
    table-layout: auto !important;
  }
}

/* Home: su web il conteggio azioni resta nella riga meta; in app va accanto al titolo. */
.sumHead {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.sumHead > .sumCount {
  display: none;
  font-weight: 400;
}
.sumRow {
  display: contents;
}

/* App nativa: titolo + N azioni, poi preventivo, poi speso, due colonne allineate. */
html.copro-native-app details.area-card > summary,
html.copro-native-app details.partner-totals-card > summary,
html.copro-native-app details.dash-action-card > summary {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
html.copro-native-app details.area-card .sumHead > .sumCount {
  display: inline;
  font-weight: 400;
  color: var(--muted, #666);
  white-space: nowrap;
}
html.copro-native-app details.area-card .sumCount-web {
  display: none;
}
html.copro-native-app details.area-card .sumMeta,
html.copro-native-app details.partner-totals-card .sumMeta,
html.copro-native-app .dash-totals-block .sumMeta,
html.copro-native-app details.dash-action-card .sumMeta {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: 100%;
  white-space: normal !important;
  justify-content: flex-start !important;
}
html.copro-native-app details.area-card .sumRow,
html.copro-native-app details.partner-totals-card .sumRow,
html.copro-native-app .dash-totals-block .sumRow,
html.copro-native-app details.dash-action-card .sumRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 12px;
  align-items: baseline;
}
html.copro-native-app details.area-card .sumCell,
html.copro-native-app details.partner-totals-card .sumCell,
html.copro-native-app .dash-totals-block .sumCell,
html.copro-native-app details.dash-action-card .sumCell {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  font-weight: 400;
}
html.copro-native-app details.area-card .sumCell strong,
html.copro-native-app details.partner-totals-card .sumCell strong,
html.copro-native-app .dash-totals-block .sumCell strong,
html.copro-native-app details.dash-action-card .sumCell strong {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.dash-totals-stack {
  display: none;
}

html.copro-native-app .dash-totals-table {
  display: none !important;
}

html.copro-native-app .dash-totals-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

html.copro-native-app .dash-totals-block {
  padding: 4px 0;
}

html.copro-native-app .dash-totals-block .sumTitle {
  font-weight: 700;
  font-size: 13px;
}

.dash-action-stack {
  display: none;
}

html.copro-native-app .dashboard-area-scroll {
  display: none !important;
}

html.copro-native-app .dashboard-scroll-hint {
  display: none !important;
}

html.copro-native-app .dash-action-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

html.copro-native-app details.dash-action-card {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  margin: 0;
}

html.copro-native-app details.dash-action-card > summary {
  padding: 10px 12px;
}

html.copro-native-app details.dash-action-card .sumHead {
  width: 100%;
  justify-content: space-between;
  flex-wrap: wrap;
}

html.copro-native-app .dash-action-status {
  flex: 0 0 auto;
}

html.copro-native-app .dash-action-card-body {
  padding: 0 10px 10px;
}

html.copro-native-app .copro-nav-sep,
html.copro-native-app .copro-nav-bar.copro-nav-links .copro-nav-dropdown__panel .muted {
  display: none !important;
}

html.copro-native-app .copro-nav-bar.copro-nav-links .copro-nav-dropdown__panel {
  position: static !important;
  right: auto !important;
  margin-top: 8px !important;
  min-width: 0 !important;
  width: 100%;
  box-shadow: none !important;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 2px;
}

html.copro-native-app .copro-nav-bar.copro-nav-links .copro-nav-dropdown__panel .btnlink {
  display: block;
  width: 100%;
  padding: 10px 8px;
  min-height: 44px;
  line-height: 1.35;
  box-sizing: border-box;
}

/* App WebView: scroll orizzontale anche nelle tabelle accorpate dashboard */
html.copro-native-app .dash-exp-group-scroll,
html.copro-native-app .dash-line-groups-scroll {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
}

html.copro-native-app .dash-exp-group-scroll > table,
html.copro-native-app .dash-line-groups-scroll > table,
html.copro-native-app .dash-exp-group-scroll > table.line-table,
html.copro-native-app .dash-line-groups-scroll > table.line-table {
  display: table;
  width: max-content !important;
  min-width: 720px !important;
  max-width: none !important;
  table-layout: auto !important;
}

html.copro-native-app .dash-line-groups,
html.copro-native-app .dash-exp-group {
  max-width: 100%;
  min-width: 0;
}

html.copro-native-app .action-voice-panel {
  overflow-x: visible;
  overflow-y: visible;
}

/* App nativa: sblocca scroll orizzontale tabelle annidate in dashboard */
html.copro-native-app .wrap .card:has(details.area-card),
html.copro-native-app details.area-card,
html.copro-native-app details.area-card > .detailsBody,
html.copro-native-app .action-voice-panel,
html.copro-native-app .voice-block,
html.copro-native-app .voice-lines,
html.copro-native-app .dash-line-groups {
  overflow-x: visible !important;
  overflow-y: visible !important;
  max-width: 100%;
  min-width: 0;
}

/* Tabelle movimenti dashboard: layout originale, testo a sinistra */
.action-voice-row > td,
.dash-exp-group-cell,
.dash-exp-group__summary,
.dash-exp-group__text {
  text-align: left !important;
}

.grouped-table .action-voice-row .line-table th,
.grouped-table .action-voice-row .line-table td,
.dash-line-groups .line-table th,
.dash-line-groups .line-table td,
.line-table.dash-moves-table th,
.line-table.dash-moves-table td,
.line-table.dash-exp-group-inner-table th,
.line-table.dash-exp-group-inner-table td {
  text-align: left !important;
  vertical-align: top;
}

.grouped-table .action-voice-row .line-table .amt,
.dash-line-groups .line-table .amt,
.line-table.dash-moves-table .amt,
.line-table.dash-exp-group-inner-table .amt {
  text-align: left !important;
  white-space: nowrap;
}

tr.dash-exp-group-detail td {
  background: #f8fafc;
  font-size: 12px;
}

/* Dashboard: evidenzia la riga al passaggio del mouse (tinta accento programma).
   Attivo solo con >= 4 righe dati (table_row_hover.js aggiunge .table-row-hover). */
.line-table.dash-moves-table.table-row-hover tbody tr.dash-move-row:hover > td,
.line-table.dash-moves-table.table-row-hover tbody tr.dash-exp-group-detail:hover > td,
.line-table.dash-exp-group-inner-table.table-row-hover tbody tr:hover > td,
.grouped-table.table-row-hover > tbody > tr:not(.action-voice-row):hover > td,
.super-table.table-row-hover tbody tr:hover > td,
.partner-voice-table.table-row-hover tbody tr:hover > td {
  background: var(--surface-table-hover) !important;
}

tr.dash-exp-group-anchor:hover .dash-exp-group__summary {
  background: var(--surface-table-hover);
  border-color: var(--surface-table-hover-border);
}

tr.dash-exp-group-detail + tr.dash-exp-group-anchor .dash-exp-group__summary,
tr.dash-exp-group-anchor + tr.dash-exp-group-detail td {
  border-top: 1px solid #eef1f4;
}

.dash-exp-group-cell .dash-exp-group-more {
  display: block;
  margin: 4px 10px 8px;
  font-size: 12px;
}

.scrollX .line-table.dash-moves-table,
.dash-line-groups-scroll .line-table.dash-moves-table,
.dash-line-groups-scroll .dash-moves-table,
.scrollX .dash-moves-table,
.dash-exp-group-scroll .line-table.dash-exp-group-inner-table {
  width: max-content !important;
  min-width: 720px !important;
  max-width: none !important;
  table-layout: auto !important;
}

html.copro-native-app .dash-line-groups-scroll,
html.copro-native-app .dash-exp-group-scroll {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  padding-bottom: 8px;
  margin-bottom: 2px;
}

html.copro-native-app .dash-line-groups-scroll::-webkit-scrollbar,
html.copro-native-app .dash-exp-group-scroll::-webkit-scrollbar {
  height: 6px;
}

html.copro-native-app .dash-line-groups-scroll::-webkit-scrollbar-thumb,
html.copro-native-app .dash-exp-group-scroll::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.28);
  border-radius: 999px;
}

.dash-exp-group-cell {
  padding: 0 !important;
  border-top: 0;
  vertical-align: top;
}

@media (max-width: 480px) {
  .copro-nav-link {
    padding: 8px 6px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  .top > div:first-child {
    padding-right: 56px;
  }
}

@media (max-width: 380px) {
  .copro-nav-user--peek,
  .copro-nav-session.copro-nav-user--peek {
    display: none !important;
  }

  .copro-nav-shell {
    max-width: calc(100vw - 16px);
  }
}

/* --- Tema scuro (sistema automatico o scelta «Scuro» in impostazioni) --- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --form-accent: #f08a96;
    --form-control-text: #eef1f6;
    --caritas-red: #ff9aa8;
    --surface-bg: #121820;
    --surface-card: #1b2433;
    --surface-top: #1f293b;
    --surface-input: #283246;
    --surface-table-alt: rgba(255, 255, 255, 0.045);
    --surface-code: #2f3b50;
    --border-soft: #425066;
    --border-strong: #5a6b82;
    --text-main: #eef1f6;
    --text-muted: #b9c2d1;
    /* Allinea le variabili usate dagli <style> di pagina (evita box bianchi + testo chiaro). */
    --bg: #121820;
    --card: #1b2433;
    --text: #eef1f6;
    --muted: #b9c2d1;
    --font-size-base: 13px;
    --font-size-muted: 13px;
    --font-size-table: 13px;
    --nav-active-bg: rgba(255, 154, 168, 0.18);
    --nav-active-border: rgba(255, 154, 168, 0.42);
    --surface-table-hover: rgba(255, 154, 168, 0.14);
    --surface-table-hover-border: rgba(255, 154, 168, 0.32);
    --nav-dropdown-bg: #1f293b;
    --nav-dropdown-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
    --nav-badge-bg: rgba(255, 154, 168, 0.22);
    --nav-badge-text: #ffd8de;
    --program-chip-bg: rgba(255, 154, 168, 0.14);
    --program-chip-text: #ffd8de;
  }
}

html[data-theme="dark"] {
  --form-accent: #f08a96;
  --form-control-text: #eef1f6;
  --caritas-red: #ff9aa8;
  --surface-bg: #121820;
  --surface-card: #1b2433;
  --surface-top: #1f293b;
  --surface-input: #283246;
  --surface-table-alt: rgba(255, 255, 255, 0.045);
  --surface-code: #2f3b50;
  --border-soft: #425066;
  --border-strong: #5a6b82;
  --text-main: #eef1f6;
  --text-muted: #b9c2d1;
  --bg: #121820;
  --card: #1b2433;
  --text: #eef1f6;
  --muted: #b9c2d1;
  --font-size-base: 13px;
  --font-size-muted: 13px;
  --font-size-table: 13px;
  --nav-active-bg: rgba(255, 154, 168, 0.18);
  --nav-active-border: rgba(255, 154, 168, 0.42);
  --surface-table-hover: rgba(255, 154, 168, 0.14);
  --surface-table-hover-border: rgba(255, 154, 168, 0.32);
  --nav-dropdown-bg: #1f293b;
  --nav-dropdown-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  --nav-badge-bg: rgba(255, 154, 168, 0.22);
  --nav-badge-text: #ffd8de;
  --program-chip-bg: rgba(255, 154, 168, 0.14);
  --program-chip-text: #ffd8de;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]),
  html:not([data-theme="light"]) body {
    background: var(--surface-bg) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) body {
    line-height: 1.5;
  }
}

html[data-theme="dark"],
html[data-theme="dark"] body {
  background: var(--surface-bg) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] body {
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .top,
  html:not([data-theme="light"]) .card,
  html:not([data-theme="light"]) footer,
  html:not([data-theme="light"]) .copro-nav-links,
  html:not([data-theme="light"]) .copro-nav-bar,
  html:not([data-theme="light"]) .copro-nav-links details > div,
  html:not([data-theme="light"]) .copro-nav-dropdown__panel,
  html:not([data-theme="light"]) .rulebox {
    background: var(--surface-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) .top {
    background: var(--program-top-bg, var(--surface-top)) !important;
    border-bottom-color: var(--program-top-edge, var(--border-soft)) !important;
    box-shadow: inset 0 3px 0 var(--program-accent-bar, var(--caritas-red)) !important;
  }

  html:not([data-theme="light"]) .card {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  }

  html:not([data-theme="light"]) .muted,
  html:not([data-theme="light"]) label {
    color: var(--text-muted) !important;
  }

  html:not([data-theme="light"]) th {
    color: var(--text-main) !important;
    font-weight: 600;
  }

  html:not([data-theme="light"]) .copro-nav-user,
  html:not([data-theme="light"]) .copro-nav-link--chev {
    color: var(--text-muted) !important;
  }

  html:not([data-theme="light"]) .copro-nav-session__username,
  html:not([data-theme="light"]) .copro-page-program__name,
  html:not([data-theme="light"]) .copro-nav-session__program {
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .copro-nav-user--peek {
    background: var(--surface-card) !important;
    border-color: var(--border-soft) !important;
    color: var(--text-muted) !important;
  }

  html:not([data-theme="light"]) .btnlink,
  html:not([data-theme="light"]) .copro-nav-link {
    color: var(--caritas-red) !important;
  }

  html:not([data-theme="light"]) .copro-nav-link:hover {
    background: var(--nav-active-bg) !important;
    border-color: var(--nav-active-border) !important;
  }

  html:not([data-theme="light"]) input:not([type="checkbox"]):not([type="radio"]),
  html:not([data-theme="light"]) select,
  html:not([data-theme="light"]) textarea {
    background: var(--surface-input) !important;
    color: var(--form-control-text) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) input::placeholder,
  html:not([data-theme="light"]) textarea::placeholder {
    color: #8b97ab !important;
    opacity: 1;
  }

  html:not([data-theme="light"]) input:focus-visible,
  html:not([data-theme="light"]) select:focus-visible,
  html:not([data-theme="light"]) textarea:focus-visible,
  html:not([data-theme="light"]) button:focus-visible {
    outline: 2px solid rgba(255, 154, 168, 0.55);
    outline-offset: 1px;
  }

  html:not([data-theme="light"]) button.btn-small,
  html:not([data-theme="light"]) .filter-btn {
    background: var(--surface-input) !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }

  /* CTA principali: restano colorate con testo chiaro leggibile */
  html:not([data-theme="light"]) button.btn {
    background: var(--caritas-red, #ff9aa8) !important;
    color: #121820 !important;
    border-color: transparent !important;
  }

  html:not([data-theme="light"]) table th,
  html:not([data-theme="light"]) table td {
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) table thead th {
    background: var(--surface-top) !important;
  }

  html:not([data-theme="light"]) table tbody tr:nth-child(even) {
    background: var(--surface-table-alt) !important;
  }

  html:not([data-theme="light"]) .msgbox {
    border-color: #d4a017;
    background: #3a2f12;
    color: #fde68a;
  }

  html:not([data-theme="light"]) .msgbox--success {
    border-color: #4ade80;
    background: #142a1c;
    color: #bbf7d0;
  }

  html:not([data-theme="light"]) .msgbox--error {
    border-color: #f87171;
    background: #3a1518;
    color: #fecaca;
  }

  html:not([data-theme="light"]) .msgbox--warning,
  html:not([data-theme="light"]) .msgbox--info {
    border-color: #d4a017;
    background: #3a2f12;
    color: #fde68a;
  }

  html:not([data-theme="light"]) .warnbox {
    background: #3a2d08 !important;
    border-color: #d4a017 !important;
    color: #fde68a !important;
  }

  html:not([data-theme="light"]) .badbox {
    background: #3a1518 !important;
    border-color: #f87171 !important;
    color: #fecaca !important;
  }

  html:not([data-theme="light"]) .reporting-status-strip {
    border-bottom-color: #d4a017;
    background: #3a2f12;
  }

  html:not([data-theme="light"]) .reporting-status-strip--neutral {
    border-bottom-color: var(--border-soft);
    background: var(--surface-top);
  }

  html:not([data-theme="light"]) .reporting-status-inner,
  html:not([data-theme="light"]) .reporting-reminder-details > summary {
    color: #fde68a;
  }

  html:not([data-theme="light"]) .reporting-status-strip--neutral .reporting-status-inner {
    color: var(--text-main);
  }

  html:not([data-theme="light"]) .reporting-status-link {
    color: #ffb4a0;
  }

  html:not([data-theme="light"]) .reporting-reminder-close {
    border-color: #d4a017;
    background: #4a3a14;
    color: #fde68a;
  }

  html:not([data-theme="light"]) .copro-nav-backdrop {
    background: rgba(0, 0, 0, 0.72);
  }

  html:not([data-theme="light"]) .copro-mobile-readonly-banner {
    border-bottom-color: #38a3c9;
    background: #152a38;
  }

  html:not([data-theme="light"]) .copro-mobile-readonly-banner__inner {
    color: #bae6fd;
  }
}

html[data-theme="dark"] .top,
html[data-theme="dark"] .card,
html[data-theme="dark"] footer,
html[data-theme="dark"] .copro-nav-links,
html[data-theme="dark"] .copro-nav-bar,
html[data-theme="dark"] .copro-nav-links details > div,
html[data-theme="dark"] .copro-nav-dropdown__panel,
html[data-theme="dark"] .rulebox {
  background: var(--surface-card) !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] .top {
  background: var(--program-top-bg, var(--surface-top)) !important;
  border-bottom-color: var(--program-top-edge, var(--border-soft)) !important;
  box-shadow: inset 0 3px 0 var(--program-accent-bar, var(--caritas-red)) !important;
}

html[data-theme="dark"] .card {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

html[data-theme="dark"] .muted,
html[data-theme="dark"] label {
  color: var(--text-muted) !important;
}

html[data-theme="dark"] th {
  color: var(--text-main) !important;
  font-weight: 600;
}

html[data-theme="dark"] .copro-nav-user,
html[data-theme="dark"] .copro-nav-link--chev {
  color: var(--text-muted) !important;
}

html[data-theme="dark"] .copro-nav-session__username,
html[data-theme="dark"] .copro-page-program__name,
html[data-theme="dark"] .copro-nav-session__program {
  color: var(--text-main) !important;
}

html[data-theme="dark"] .copro-nav-user--peek {
  background: var(--surface-card) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-muted) !important;
}

html[data-theme="dark"] .btnlink,
html[data-theme="dark"] .copro-nav-link {
  color: var(--caritas-red) !important;
}

html[data-theme="dark"] .copro-nav-link:hover {
  background: var(--nav-active-bg) !important;
  border-color: var(--nav-active-border) !important;
}

html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-input) !important;
  color: var(--form-control-text) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #8b97ab !important;
  opacity: 1;
}

html[data-theme="dark"] input:focus-visible,
html[data-theme="dark"] select:focus-visible,
html[data-theme="dark"] textarea:focus-visible,
html[data-theme="dark"] button:focus-visible {
  outline: 2px solid rgba(255, 154, 168, 0.55);
  outline-offset: 1px;
}

html[data-theme="dark"] button.btn-small,
html[data-theme="dark"] .filter-btn {
  background: var(--surface-input) !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] button.btn {
  background: var(--caritas-red, #ff9aa8) !important;
  color: #121820 !important;
  border-color: transparent !important;
}

html[data-theme="dark"] table th,
html[data-theme="dark"] table td {
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] table thead th {
  background: var(--surface-top) !important;
}

html[data-theme="dark"] table tbody tr:nth-child(even) {
  background: var(--surface-table-alt) !important;
}

html[data-theme="dark"] .msgbox {
  border-color: #d4a017;
  background: #3a2f12;
  color: #fde68a;
}

html[data-theme="dark"] .msgbox--success {
  border-color: #4ade80;
  background: #142a1c;
  color: #bbf7d0;
}

html[data-theme="dark"] .msgbox--error {
  border-color: #f87171;
  background: #3a1518;
  color: #fecaca;
}

html[data-theme="dark"] .msgbox--warning,
html[data-theme="dark"] .msgbox--info {
  border-color: #d4a017;
  background: #3a2f12;
  color: #fde68a;
}

html[data-theme="dark"] .warnbox {
  background: #3a2d08 !important;
  border-color: #d4a017 !important;
  color: #fde68a !important;
}

html[data-theme="dark"] .badbox {
  background: #3a1518 !important;
  border-color: #f87171 !important;
  color: #fecaca !important;
}

html[data-theme="dark"] .reporting-status-strip {
  border-bottom-color: #d4a017;
  background: #3a2f12;
}

html[data-theme="dark"] .reporting-status-strip--neutral {
  border-bottom-color: var(--border-soft);
  background: var(--surface-top);
}

html[data-theme="dark"] .reporting-status-inner,
html[data-theme="dark"] .reporting-reminder-details > summary {
  color: #fde68a;
}

html[data-theme="dark"] .reporting-status-strip--neutral .reporting-status-inner {
  color: var(--text-main);
}

html[data-theme="dark"] .reporting-status-link {
  color: #ffb4a0;
}

html[data-theme="dark"] .reporting-reminder-close {
  border-color: #d4a017;
  background: #4a3a14;
  color: #fde68a;
}

html[data-theme="dark"] .copro-nav-backdrop {
  background: rgba(0, 0, 0, 0.72);
}

html[data-theme="dark"] .copro-mobile-readonly-banner {
  border-bottom-color: #38a3c9;
  background: #152a38;
}

html[data-theme="dark"] .copro-mobile-readonly-banner__inner {
  color: #bae6fd;
}

@media (max-width: 1200px) {
  @media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .copro-nav-toggle,
    html:not([data-theme="light"]) .copro-nav-user--peek,
    html:not([data-theme="light"]) .copro-nav-session.copro-nav-user--peek {
      border-color: var(--border-strong);
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.42);
    }

    html:not([data-theme="light"]) .copro-nav-bar.copro-nav-links {
      border-color: var(--border-strong);
    }

    html:not([data-theme="light"]) .copro-nav-bar.copro-nav-links .copro-nav-link,
    html:not([data-theme="light"]) .copro-nav-bar.copro-nav-links .copro-nav-dropdown > summary {
      color: var(--text-main) !important;
    }

    html:not([data-theme="light"]) .wrap .muted,
    html:not([data-theme="light"]) .card .muted {
      color: var(--text-muted) !important;
    }
  }

  html[data-theme="dark"] .copro-nav-toggle,
  html[data-theme="dark"] .copro-nav-user--peek,
  html[data-theme="dark"] .copro-nav-session.copro-nav-user--peek {
    border-color: var(--border-strong);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.42);
  }

  html[data-theme="dark"] .copro-nav-bar.copro-nav-links {
    border-color: var(--border-strong);
  }

  html[data-theme="dark"] .copro-nav-bar.copro-nav-links .copro-nav-link,
  html[data-theme="dark"] .copro-nav-bar.copro-nav-links .copro-nav-dropdown > summary {
    color: var(--text-main) !important;
  }

  html[data-theme="dark"] .wrap .muted,
  html[data-theme="dark"] .card .muted {
    color: var(--text-muted) !important;
  }
}

/* Box informativi con colori inline (spese, dashboard): leggibili in scuro */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .card[style*="background:#f0f9ff"],
  html:not([data-theme="light"]) .card[style*="background: #f0f9ff"],
  html:not([data-theme="light"]) .rulebox[style*="background:#f0f9ff"],
  html:not([data-theme="light"]) .rulebox[style*="background: #f0f9ff"] {
    background: #152a38 !important;
    border-color: #38a3c9 !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .rulebox[style*="background:#f0fdf4"],
  html:not([data-theme="light"]) .rulebox[style*="background: #f0fdf4"] {
    background: #142a1c !important;
    border-color: #4ade80 !important;
    color: #bbf7d0 !important;
  }

  html:not([data-theme="light"]) .rulebox[style*="background:#fff1f2"],
  html:not([data-theme="light"]) .rulebox[style*="background: #fff1f2"] {
    background: #3a1518 !important;
    border-color: #f87171 !important;
    color: #fecaca !important;
  }

  html:not([data-theme="light"]) div[style*="background:#fff5f5"],
  html:not([data-theme="light"]) div[style*="background: #fff5f5"] {
    background: #3a1518 !important;
    border-color: #f87171 !important;
    color: #fecaca !important;
  }

  html:not([data-theme="light"]) div[style*="background:#f8fafc"],
  html:not([data-theme="light"]) div[style*="background: #f8fafc"] {
    background: var(--surface-card) !important;
    border-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) code[style*="background:#f1f5f9"],
  html:not([data-theme="light"]) code[style*="background: #f1f5f9"] {
    background: var(--surface-code) !important;
    color: var(--text-main) !important;
  }
}

html[data-theme="dark"] .card[style*="background:#f0f9ff"],
html[data-theme="dark"] .card[style*="background: #f0f9ff"],
html[data-theme="dark"] .rulebox[style*="background:#f0f9ff"],
html[data-theme="dark"] .rulebox[style*="background: #f0f9ff"] {
  background: #152a38 !important;
  border-color: #38a3c9 !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .rulebox[style*="background:#f0fdf4"],
html[data-theme="dark"] .rulebox[style*="background: #f0fdf4"] {
  background: #142a1c !important;
  border-color: #4ade80 !important;
  color: #bbf7d0 !important;
}

html[data-theme="dark"] .rulebox[style*="background:#fff1f2"],
html[data-theme="dark"] .rulebox[style*="background: #fff1f2"] {
  background: #3a1518 !important;
  border-color: #f87171 !important;
  color: #fecaca !important;
}

html[data-theme="dark"] div[style*="background:#fff5f5"],
html[data-theme="dark"] div[style*="background: #fff5f5"] {
  background: #3a1518 !important;
  border-color: #f87171 !important;
  color: #fecaca !important;
}

html[data-theme="dark"] div[style*="background:#f8fafc"],
html[data-theme="dark"] div[style*="background: #f8fafc"] {
  background: var(--surface-card) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] code[style*="background:#f1f5f9"],
html[data-theme="dark"] code[style*="background: #f1f5f9"] {
  background: var(--surface-code) !important;
  color: var(--text-main) !important;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) button.btn[style*="background:#334155"],
  html:not([data-theme="light"]) button.btn[style*="background:#475569"],
  html:not([data-theme="light"]) button.btn[style*="background:#0f766e"],
  html:not([data-theme="light"]) button.btn[style*="background: #334155"],
  html:not([data-theme="light"]) button.btn[style*="background: #475569"],
  html:not([data-theme="light"]) button.btn[style*="background: #0f766e"] {
    background: #3f5268 !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }
}

html[data-theme="dark"] button.btn[style*="background:#334155"],
html[data-theme="dark"] button.btn[style*="background:#475569"],
html[data-theme="dark"] button.btn[style*="background:#0f766e"],
html[data-theme="dark"] button.btn[style*="background: #334155"],
html[data-theme="dark"] button.btn[style*="background: #475569"],
html[data-theme="dark"] button.btn[style*="background: #0f766e"] {
  background: #3f5268 !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

/* Pagine portale con blocchi <style> locali (:root chiaro): contrasto mobile/scuro */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .copro-launch-strip {
    background: linear-gradient(90deg, #3a1518 0%, #152a38 100%) !important;
    border-color: #7a0b12 !important;
    color: #e5e7eb !important;
  }

  html:not([data-theme="light"]) .copro-launch-strip strong {
    color: #ff9aa8 !important;
  }

  html:not([data-theme="light"]) .copro-launch-strip a {
    color: #ffb4a0 !important;
  }

  html:not([data-theme="light"]) .onboarding,
  html:not([data-theme="light"]) .readonly-mobile-note,
  html:not([data-theme="light"]) .mcard,
  html:not([data-theme="light"]) .desc-chip {
    background: var(--surface-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) .mcard .line,
  html:not([data-theme="light"]) .mcard strong {
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .pill.ok {
    background: #164e2c !important;
    color: #bbf7d0 !important;
  }

  html:not([data-theme="light"]) .pill.no {
    background: #4c1d24 !important;
    color: #fecdd3 !important;
  }

  html:not([data-theme="light"]) .pill.neutral {
    background: #334155 !important;
    color: #e2e8f0 !important;
  }

  html:not([data-theme="light"]) .pill.warn {
    background: #4a3412 !important;
    color: #fde68a !important;
  }

  html:not([data-theme="light"]) .wrap .muted,
  html:not([data-theme="light"]) .card .muted,
  html:not([data-theme="light"]) .card p.muted,
  html:not([data-theme="light"]) details .muted {
    color: #cbd5e1 !important;
  }

  html:not([data-theme="light"]) .card h2,
  html:not([data-theme="light"]) .card p,
  html:not([data-theme="light"]) .card strong,
  html:not([data-theme="light"]) .card label {
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) footer[style*="background:#fff"],
  html:not([data-theme="light"]) footer[style*="background: #fff"] {
    background: var(--surface-card) !important;
    border-top-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) [style*="color:#334155"],
  html:not([data-theme="light"]) [style*="color: #334155"],
  html:not([data-theme="light"]) [style*="color:#475569"],
  html:not([data-theme="light"]) [style*="color: #475569"],
  html:not([data-theme="light"]) [style*="color:#6b7280"],
  html:not([data-theme="light"]) [style*="color: #6b7280"] {
    color: var(--text-main) !important;
  }
}

html[data-theme="dark"] .copro-launch-strip {
  background: linear-gradient(90deg, #3a1518 0%, #152a38 100%) !important;
  border-color: #7a0b12 !important;
  color: #e5e7eb !important;
}

html[data-theme="dark"] .copro-launch-strip strong {
  color: #ff9aa8 !important;
}

html[data-theme="dark"] .copro-launch-strip a {
  color: #ffb4a0 !important;
}

html[data-theme="dark"] .onboarding,
html[data-theme="dark"] .readonly-mobile-note,
html[data-theme="dark"] .mcard,
html[data-theme="dark"] .desc-chip {
  background: var(--surface-card) !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] .mcard .line,
html[data-theme="dark"] .mcard strong {
  color: var(--text-main) !important;
}

html[data-theme="dark"] .pill.ok {
  background: #164e2c !important;
  color: #bbf7d0 !important;
}

html[data-theme="dark"] .pill.no {
  background: #4c1d24 !important;
  color: #fecdd3 !important;
}

html[data-theme="dark"] .pill.neutral {
  background: #334155 !important;
  color: #e2e8f0 !important;
}

html[data-theme="dark"] .pill.warn {
  background: #4a3412 !important;
  color: #fde68a !important;
}

html[data-theme="dark"] .wrap .muted,
html[data-theme="dark"] .card .muted,
html[data-theme="dark"] .card p.muted,
html[data-theme="dark"] details .muted {
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .card h2,
html[data-theme="dark"] .card p,
html[data-theme="dark"] .card strong,
html[data-theme="dark"] .card label {
  color: var(--text-main) !important;
}

html[data-theme="dark"] footer[style*="background:#fff"],
html[data-theme="dark"] footer[style*="background: #fff"] {
  background: var(--surface-card) !important;
  border-top-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] [style*="color:#334155"],
html[data-theme="dark"] [style*="color: #334155"],
html[data-theme="dark"] [style*="color:#475569"],
html[data-theme="dark"] [style*="color: #475569"],
html[data-theme="dark"] [style*="color:#6b7280"],
html[data-theme="dark"] [style*="color: #6b7280"] {
  color: var(--text-main) !important;
}

/* Dashboard partner/capofila: override stili inline chiari in tema scuro */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) details.area-card {
    background: var(--surface-card) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) details.area-card > summary {
    background: var(--surface-top) !important;
    border-bottom-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) details.area-card[open] > summary {
    background: #283246 !important;
  }

  html:not([data-theme="light"]) details.area-card > .detailsBody,
  html:not([data-theme="light"]) details:not(.area-card) {
    background: var(--surface-card) !important;
    border-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .sumTitle,
  html:not([data-theme="light"]) details.area-card strong,
  html:not([data-theme="light"]) .grouped-table tbody td,
  html:not([data-theme="light"]) .grouped-table tbody td strong {
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .sumMeta,
  html:not([data-theme="light"]) .voice-meta,
  html:not([data-theme="light"]) .grouphead {
    color: var(--text-muted) !important;
  }

  html:not([data-theme="light"]) .grouped-table thead tr:first-child th,
  html:not([data-theme="light"]) .grouped-table thead tr:nth-child(2) th,
  html:not([data-theme="light"]) .super-table thead tr:first-child th,
  html:not([data-theme="light"]) .super-table thead tr:nth-child(2) th {
    background: var(--surface-top) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .action-voice-row td {
    background: var(--surface-table-alt) !important;
  }

  html:not([data-theme="light"]) .action-voice-panel > details,
  html:not([data-theme="light"]) .voice-block,
  html:not([data-theme="light"]) .voice-lines {
    background: var(--surface-card) !important;
    border-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .action-voice-panel > details > summary {
    color: var(--text-main) !important;
  }

  /* Dashboard: evita testo chiaro su strisce ancora chiare (gruppi spese / online). */
  html:not([data-theme="light"]) .dash-exp-group__summary,
  html:not([data-theme="light"]) .dash-exp-group[open] > .dash-exp-group__summary,
  html:not([data-theme="light"]) .dash-exp-group-body,
  html:not([data-theme="light"]) tr.dash-exp-group-detail td {
    background: var(--surface-input) !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) .dash-exp-group__chevron {
    color: var(--text-muted) !important;
  }

  html:not([data-theme="light"]) .dash-move-row td {
    background: var(--surface-card) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .online-list {
    background: var(--surface-card) !important;
    border-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .pill.bad {
    background: #4c1d24 !important;
    color: #fecdd3 !important;
  }
}

html[data-theme="dark"] details.area-card {
  background: var(--surface-card) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] details.area-card > summary {
  background: var(--surface-top) !important;
  border-bottom-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] details.area-card[open] > summary {
  background: #283246 !important;
}

html[data-theme="dark"] details.area-card > .detailsBody,
html[data-theme="dark"] details:not(.area-card) {
  background: var(--surface-card) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .sumTitle,
html[data-theme="dark"] details.area-card strong,
html[data-theme="dark"] .grouped-table tbody td,
html[data-theme="dark"] .grouped-table tbody td strong {
  color: var(--text-main) !important;
}

html[data-theme="dark"] .sumMeta,
html[data-theme="dark"] .voice-meta,
html[data-theme="dark"] .grouphead {
  color: var(--text-muted) !important;
}

html[data-theme="dark"] .grouped-table thead tr:first-child th,
html[data-theme="dark"] .grouped-table thead tr:nth-child(2) th,
html[data-theme="dark"] .super-table thead tr:first-child th,
html[data-theme="dark"] .super-table thead tr:nth-child(2) th {
  background: var(--surface-top) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .action-voice-row td {
  background: var(--surface-table-alt) !important;
}

html[data-theme="dark"] .action-voice-panel > details,
html[data-theme="dark"] .voice-block,
html[data-theme="dark"] .voice-lines {
  background: var(--surface-card) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .action-voice-panel > details > summary {
  color: var(--text-main) !important;
}

html[data-theme="dark"] .dash-exp-group__summary,
html[data-theme="dark"] .dash-exp-group[open] > .dash-exp-group__summary,
html[data-theme="dark"] .dash-exp-group-body,
html[data-theme="dark"] tr.dash-exp-group-detail td {
  background: var(--surface-input) !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] .dash-exp-group__chevron {
  color: var(--text-muted) !important;
}

html[data-theme="dark"] .dash-move-row td {
  background: var(--surface-card) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .online-list {
  background: var(--surface-card) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .pill.bad {
  background: #4c1d24 !important;
  color: #fecdd3 !important;
}

/* ------------------------------------------------------------------ */
/* Safari / iPhone - Scenario 1: hardening mobile web (no PWA/iOS app) */
/* ------------------------------------------------------------------ */
@supports (-webkit-touch-callout: none) {
  html,
  body {
    -webkit-text-size-adjust: 100%;
  }

  input,
  select,
  textarea,
  button {
    font-size: 16px; /* evita zoom automatico Safari su focus */
  }
}

@media (max-width: 720px) {
  /* Mitiga min-width inline storici che causano overflow orizzontale su iPhone */
  form[style*="min-width"],
  .mini-form,
  input[style*="min-width"],
  select[style*="min-width"] {
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .wrap,
  .card,
  .box,
  .filebox {
    max-width: 100%;
    overflow-x: clip;
  }

  /* I contenitori di scroll tabelle devono vincere sul clip di .card/.wrap (app/WebView). */
  .scrollX,
  .copro-hscroll,
  .copro-table-scroll,
  .dashboard-area-scroll,
  .dash-exp-group-scroll,
  .dash-line-groups-scroll {
    overflow-x: auto !important;
    overflow-y: hidden;
    max-width: 100%;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  #expense-form,
  #expense-form-actions,
  .budget-overrun-confirm,
  .wizard-steps {
    max-width: 100%;
  }

  #expense-form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  #expense-form-actions .btn,
  #expense-form-actions a {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  input[type="file"] {
    max-width: 100%;
  }

  .top + .wrap .filters,
  .toolbar,
  .filter-row {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .copro-mobile-app-update,
  .copro-mobile-app-update__actions {
    flex-direction: column;
    align-items: stretch;
  }

  .copro-mobile-app-update__download {
    width: 100%;
    box-sizing: border-box;
  }
}

/* Tema scuro: pannelli interni ancora chiari (Personale, Impostazioni, form annidati). */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .okbox,
  html:not([data-theme="light"]) .legal-first-access,
  html:not([data-theme="light"]) .ro-badge,
  html:not([data-theme="light"]) .btn-ghost,
  html:not([data-theme="light"]) .btn-small,
  html:not([data-theme="light"]) .btn-danger-link,
  html:not([data-theme="light"]) .btn-secondary,
  html:not([data-theme="light"]) .rate-history-edit-form,
  html:not([data-theme="light"]) .rate-history-add-form,
  html:not([data-theme="light"]) .personnel-edit-row > td,
  html:not([data-theme="light"]) .personnel-list th.col-actions,
  html:not([data-theme="light"]) .personnel-list td.col-actions,
  html:not([data-theme="light"]) .personnel-list tr.personnel-row-editing > td,
  html:not([data-theme="light"]) .personnel-list tr.personnel-row-editing > td.col-actions,
  html:not([data-theme="light"]) .notice {
    background: var(--surface-input) !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) .card [style*="background:#fff"],
  html:not([data-theme="light"]) .card [style*="background: #fff"],
  html:not([data-theme="light"]) .card [style*="background:#f8fafc"],
  html:not([data-theme="light"]) .card [style*="background: #f8fafc"],
  html:not([data-theme="light"]) .card [style*="background:#fff7f7"],
  html:not([data-theme="light"]) .card [style*="background: #fff7f7"],
  html:not([data-theme="light"]) .card [style*="background:#fff7ed"],
  html:not([data-theme="light"]) .card [style*="background: #fff7ed"],
  html:not([data-theme="light"]) .card [style*="background:#fffbeb"],
  html:not([data-theme="light"]) .card [style*="background: #fffbeb"] {
    background: var(--surface-input) !important;
    color: var(--text-main) !important;
    border-color: var(--border-soft) !important;
  }

  html:not([data-theme="light"]) [style*="color:#111"],
  html:not([data-theme="light"]) [style*="color: #111"],
  html:not([data-theme="light"]) [style*="color:#4b5563"],
  html:not([data-theme="light"]) [style*="color: #4b5563"],
  html:not([data-theme="light"]) [style*="color:#9a3412"],
  html:not([data-theme="light"]) [style*="color: #9a3412"] {
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .pill.on {
    background: #164e2c !important;
    color: #bbf7d0 !important;
  }

  html:not([data-theme="light"]) .pill.off {
    background: #4c1d24 !important;
    color: #fecdd3 !important;
  }
}

html[data-theme="dark"] .okbox,
html[data-theme="dark"] .legal-first-access,
html[data-theme="dark"] .ro-badge,
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .btn-small,
html[data-theme="dark"] .btn-danger-link,
html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .rate-history-edit-form,
html[data-theme="dark"] .rate-history-add-form,
html[data-theme="dark"] .personnel-edit-row > td,
html[data-theme="dark"] .personnel-list th.col-actions,
html[data-theme="dark"] .personnel-list td.col-actions,
html[data-theme="dark"] .personnel-list tr.personnel-row-editing > td,
html[data-theme="dark"] .personnel-list tr.personnel-row-editing > td.col-actions,
html[data-theme="dark"] .notice {
  background: var(--surface-input) !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] .card [style*="background:#fff"],
html[data-theme="dark"] .card [style*="background: #fff"],
html[data-theme="dark"] .card [style*="background:#f8fafc"],
html[data-theme="dark"] .card [style*="background: #f8fafc"],
html[data-theme="dark"] .card [style*="background:#fff7f7"],
html[data-theme="dark"] .card [style*="background: #fff7f7"],
html[data-theme="dark"] .card [style*="background:#fff7ed"],
html[data-theme="dark"] .card [style*="background: #fff7ed"],
html[data-theme="dark"] .card [style*="background:#fffbeb"],
html[data-theme="dark"] .card [style*="background: #fffbeb"] {
  background: var(--surface-input) !important;
  color: var(--text-main) !important;
  border-color: var(--border-soft) !important;
}

html[data-theme="dark"] [style*="color:#111"],
html[data-theme="dark"] [style*="color: #111"],
html[data-theme="dark"] [style*="color:#4b5563"],
html[data-theme="dark"] [style*="color: #4b5563"],
html[data-theme="dark"] [style*="color:#9a3412"],
html[data-theme="dark"] [style*="color: #9a3412"] {
  color: var(--text-main) !important;
}

html[data-theme="dark"] .pill.on {
  background: #164e2c !important;
  color: #bbf7d0 !important;
}

html[data-theme="dark"] .pill.off {
  background: #4c1d24 !important;
  color: #fecdd3 !important;
}

/* Notifiche: tile riepilogo / righe non lette (stili spesso locali alla pagina). */
html[data-theme="dark"] .summary-tile {
  background: var(--surface-input) !important;
  border-color: var(--border-soft) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .summary-tile.is-active {
  background: #3b2f14 !important;
  border-color: #b45309 !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .summary-tile .muted,
html[data-theme="dark"] .summary-tile strong {
  color: inherit !important;
}

html[data-theme="dark"] table tr.unread,
html[data-theme="dark"] tr.unread {
  background: #3b2f14 !important;
}

html[data-theme="dark"] table tr.unread td,
html[data-theme="dark"] tr.unread td {
  color: var(--text-main) !important;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .summary-tile {
    background: var(--surface-input) !important;
    border-color: var(--border-soft) !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .summary-tile.is-active {
    background: #3b2f14 !important;
    border-color: #b45309 !important;
    color: var(--text-main) !important;
  }

  html:not([data-theme="light"]) .summary-tile .muted,
  html:not([data-theme="light"]) .summary-tile strong {
    color: inherit !important;
  }

  html:not([data-theme="light"]) table tr.unread,
  html:not([data-theme="light"]) tr.unread {
    background: #3b2f14 !important;
  }

  html:not([data-theme="light"]) table tr.unread td,
  html:not([data-theme="light"]) tr.unread td {
    color: var(--text-main) !important;
  }
}
