/* Salvia, blu, ambra, lilla. Il vetro liquido è un effetto, non uno stile. */

html[data-stile="salvia"] {
  --stile-bg: #e7eee3;
  --stile-card: #ffffff;
  --stile-ink: #1c1e21;
  --stile-muted: #6e756f;
  --stile-line: #e1e8dc;
  --stile-accento: #1b1d20;
  --stile-accento-2: #000000;
  --stile-dettaglio: #e7f6c4;
  --stile-side: #f3f6f0;
  --su-accento: #fff;
}
html[data-stile="salvia"][data-buio="scuro"] {
  --stile-bg: #141816;
  --stile-card: #1c2320;
  --stile-ink: #f2f5f0;
  --stile-muted: #a3aea6;
  --stile-line: #2c3530;
  --stile-accento: #e7f6c4;
  --stile-accento-2: #f4ffd8;
  --stile-dettaglio: #2a3820;
  --stile-side: #101411;
  --su-accento: #1c1e21;
}
html[data-stile="blu"] {
  --stile-bg: #e8eef8;
  --stile-card: #ffffff;
  --stile-ink: #12203a;
  --stile-muted: #66748c;
  --stile-line: #d9e2f0;
  --stile-accento: #2f6bff;
  --stile-accento-2: #1e56e8;
  --stile-dettaglio: #d6e4ff;
  --stile-side: #f4f7fc;
  --su-accento: #fff;
}
html[data-stile="blu"][data-buio="scuro"] {
  --stile-bg: #0e1524;
  --stile-card: #172033;
  --stile-ink: #e8eef8;
  --stile-muted: #9aabc4;
  --stile-line: #2a3a54;
  --stile-accento: #7ba9fd;
  --stile-accento-2: #9bb8ff;
  --stile-dettaglio: #243656;
  --stile-side: #0b1220;
  --su-accento: #12203a;
}
html[data-stile="ambra"] {
  --stile-bg: #f4efe6;
  --stile-card: #fffdf9;
  --stile-ink: #2c241c;
  --stile-muted: #8a7d6e;
  --stile-line: #e8dfd2;
  --stile-accento: #b86a1d;
  --stile-accento-2: #8a4e12;
  --stile-dettaglio: #f3d7a8;
  --stile-side: #faf6f0;
  --su-accento: #fff;
}
html[data-stile="ambra"][data-buio="scuro"] {
  --stile-bg: #17140f;
  --stile-card: #221e18;
  --stile-ink: #f6f1e8;
  --stile-muted: #b5a898;
  --stile-line: #3a332a;
  --stile-accento: #e2b15a;
  --stile-accento-2: #f0c97a;
  --stile-dettaglio: #3d2e18;
  --stile-side: #120f0c;
  --su-accento: #2c241c;
}
html[data-stile="lilla"] {
  --stile-bg: #efeaf6;
  --stile-card: #fffcff;
  --stile-ink: #241c32;
  --stile-muted: #7a6e8c;
  --stile-line: #e2d9ee;
  --stile-accento: #6b46c1;
  --stile-accento-2: #5534a8;
  --stile-dettaglio: #ddd0f5;
  --stile-side: #f7f4fb;
  --su-accento: #fff;
}
html[data-stile="lilla"][data-buio="scuro"] {
  --stile-bg: #14111a;
  --stile-card: #1e1928;
  --stile-ink: #f3eef8;
  --stile-muted: #b0a4c4;
  --stile-line: #322a42;
  --stile-accento: #c4b0f5;
  --stile-accento-2: #d8ccff;
  --stile-dettaglio: #2c2340;
  --stile-side: #100e16;
  --su-accento: #241c32;
}

html[data-stile] {
  --bg: var(--stile-bg);
  --card: var(--stile-card);
  --ink: var(--stile-ink);
  --navy: var(--ink);
  --muted: color-mix(in srgb, var(--ink) 66%, var(--bg));
  --line: color-mix(in srgb, var(--ink) 14%, var(--card));
  --azure: var(--stile-accento);
  --azure-2: var(--stile-accento-2);
  --side: var(--stile-side);
  color-scheme: light;
}
html[data-buio="scuro"] { color-scheme: dark; }

html[data-stile] body,
html[data-stile] main { background: var(--bg); color: var(--ink); }
html[data-stile] aside {
  background: var(--side);
  color: var(--ink);
  border-right: 1px solid var(--line);
}
html[data-stile] .brand img { filter: none; }
html[data-stile][data-buio="scuro"] .brand img { filter: brightness(0) invert(1); }
html[data-stile] .nav-lab,
html[data-stile] .aside-foot,
html[data-stile] .aside-user-k { color: color-mix(in srgb, var(--ink) 62%, transparent); }
html[data-stile] nav button,
html[data-stile] .nav-ico { color: var(--ink); }
html[data-stile] nav button.on,
html[data-stile] nav button:hover {
  background: color-mix(in srgb, var(--card) 88%, transparent);
  color: var(--ink);
  box-shadow: none;
}
html[data-stile] .aside-user { background: color-mix(in srgb, var(--ink) 8%, transparent); }
html[data-stile] .nav-search {
  background: color-mix(in srgb, var(--card) 80%, transparent);
  color: var(--ink);
  border: 1px solid var(--line);
}
html[data-stile] .primary { color: var(--su-accento, #fff); background: var(--azure); }
html[data-stile] .aw,
html[data-stile] #homeTiles .tile,
html[data-stile] .tile,
html[data-stile] #view-home .dash-ops > div,
html[data-stile] .top-bell,
html[data-stile] .user-chip,
html[data-stile] .burger,
html[data-stile] .acc-card,
html[data-stile] .modal-card {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}
html[data-stile] .dash-ops .ops-row { background: color-mix(in srgb, var(--ink) 4%, var(--card)); }
html[data-stile] .aw-cal-k { color: #ff3b30; }
html[data-stile] .aw-cal-ev li::before,
html[data-stile] .aw-mini b.dot::after { background: #ff3b30; }
html[data-stile] .aw-mini b.oggi { background: #ff3b30; color: #fff; }
html[data-stile] .aw-mini b.oggi.dot::after { background: #fff; }
html[data-stile] #homeTiles .tile-ico {
  background: color-mix(in srgb, var(--azure) 16%, var(--card));
  color: var(--ink);
}
html[data-buio="scuro"] input,
html[data-buio="scuro"] select,
html[data-buio="scuro"] textarea,
html[data-buio="scuro"] .ghost,
html[data-buio="scuro"] .act {
  background-color: color-mix(in srgb, var(--card) 82%, black);
  color: var(--ink);
  border-color: var(--line);
}
html[data-buio="scuro"] .gate,
html[data-buio="scuro"] .gate-panel,
html[data-buio="scuro"] .gate input { background: #fff; color: #12203a; }

/* Vetro liquido sui singoli pezzi. Il fondo resta il colore dello stile. */
html[data-vetro="1"] main { position: relative; z-index: 1; }
@media (max-width: 1100px) {
  html[data-vetro="1"] aside {
    position: fixed;
    z-index: 90;
  }
}

html[data-vetro="1"] :is(
  aside,
  .card, .kpi, .tile, .aw, .acc-card, .modal-card,
  .user-drop, .notif-drop, .act-menu-pop, .datario-pop,
  .top-bell, .user-chip, .burger, .ghost:not(.on), .act,
  nav button.on, nav button:hover,
  .acc-tabs button:not(.on), .tema-stili button, .tema-buio button,
  input, textarea,
  #view-home .dash-ops > div,
  .dash-ops .ops-row
) {
  background:
    linear-gradient(180deg, rgba(255,255,255,.75) 0, rgba(255,255,255,.2) 1px, transparent 16px) !important;
  background-color: color-mix(in srgb, var(--card) 78%, transparent) !important;
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  border: 1px solid rgba(255,255,255,.9);
  box-shadow:
    inset 0 1px 0 #fff,
    inset 0 0 0 1px rgba(255,255,255,.35),
    0 8px 22px rgba(22, 26, 46, .05);
}
html[data-stile][data-vetro="1"] aside {
  background:
    linear-gradient(180deg, rgba(255,255,255,.7) 0, transparent 14px) !important;
  background-color: color-mix(in srgb, var(--side) 86%, transparent) !important;
}
html[data-vetro="1"] .primary {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--azure) 78%, white), var(--azure)) !important;
  color: var(--su-accento, #fff);
  border-color: color-mix(in srgb, white 55%, var(--azure));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.7),
    0 8px 22px color-mix(in srgb, var(--azure) 28%, transparent);
}
/* Filtri e tab attivi: fondo pieno dello stile, testo che contrasta. Niente vetro sopra. */
html[data-stile] :is(
  .scad-filt .ghost.on,
  .todo-picks .ghost.on,
  .mkt-html-bar .ghost.on,
  .mkt-filtri .ghost.on,
  .acc-tabs button.on,
  .cc-tabs button.on,
  .cc-seg button.on,
  .cc-filters button.on,
  .ass-tipo button.on,
  .steps li.on,
  .fic-steps li.on,
  .pager .on,
  .app-tabs button.on
) {
  background: var(--azure) !important;
  background-color: var(--azure) !important;
  background-image: none !important;
  color: var(--su-accento, #fff) !important;
  border-color: var(--azure) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none !important;
}
html[data-stile] .ass-tipo button.on span,
html[data-stile] .cc-tabs button.on .cc-badge {
  color: var(--su-accento, #fff) !important;
}
html[data-stile] .cc-tabs button.on .cc-badge {
  background: color-mix(in srgb, var(--su-accento, #fff) 22%, transparent) !important;
}
html[data-stile] .wiki-toc a.on {
  background: color-mix(in srgb, var(--azure) 14%, var(--card)) !important;
  color: var(--ink) !important;
  border-color: color-mix(in srgb, var(--azure) 35%, var(--line)) !important;
}
html[data-vetro="1"][data-buio="scuro"] :is(
  aside,
  .card, .kpi, .tile, .aw, .acc-card, .modal-card,
  .user-drop, .notif-drop, .act-menu-pop, .datario-pop,
  .top-bell, .user-chip, .burger, .ghost:not(.on), .act,
  nav button.on, nav button:hover,
  .acc-tabs button:not(.on), .tema-stili button, .tema-buio button,
  input, textarea,
  #view-home .dash-ops > div,
  .dash-ops .ops-row
) {
  background:
    linear-gradient(180deg, rgba(255,255,255,.28) 0, transparent 14px) !important;
  background-color: color-mix(in srgb, var(--card) 78%, transparent) !important;
  border-color: rgba(255,255,255,.22);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.35),
    0 10px 28px rgba(0,0,0,.28);
}
/* La regola vetro usa :is() con un selettore #id, quindi batte una classe sola.
   Qui la specificità è più alta: il vetro resta, il fondo è quasi pieno. */
html[data-vetro="1"] :is(
  .act-menu > .act-menu-pop,
  body > .act-menu-pop,
  #view-home .dash-ops > .act-menu-pop
) {
  background: linear-gradient(180deg, color-mix(in srgb, white 88%, transparent), transparent 28px) !important;
  background-color: color-mix(in srgb, var(--card) 96%, var(--bg)) !important;
  backdrop-filter: blur(28px) saturate(1.55) !important;
  -webkit-backdrop-filter: blur(28px) saturate(1.55) !important;
  border: 1px solid color-mix(in srgb, var(--ink) 16%, white) !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.95),
    0 18px 40px rgba(22, 26, 46, .18) !important;
}
html[data-vetro="1"] .act-menu-item,
html[data-vetro="1"] a.act-menu-item {
  color: var(--ink) !important;
  background: var(--card) !important;
}
html[data-vetro="1"] .act-menu-item:hover,
html[data-vetro="1"] a.act-menu-item:hover {
  background: color-mix(in srgb, var(--ink) 8%, var(--card)) !important;
  color: var(--ink) !important;
}
html[data-vetro="1"][data-buio="scuro"] :is(
  .act-menu > .act-menu-pop,
  body > .act-menu-pop,
  #view-home .dash-ops > .act-menu-pop
) {
  background: linear-gradient(180deg, rgba(255,255,255,.22), transparent 28px) !important;
  background-color: color-mix(in srgb, var(--card) 96%, black) !important;
  border-color: rgba(255,255,255,.28) !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.3),
    0 18px 40px rgba(0,0,0,.45) !important;
}
html[data-vetro="1"][data-buio="scuro"] .act-menu-item,
html[data-vetro="1"][data-buio="scuro"] a.act-menu-item {
  background: color-mix(in srgb, var(--card) 90%, white);
  color: var(--ink) !important;
}
html[data-vetro="1"] :is(input[type="checkbox"], input[type="radio"], input[type="color"], input[type="file"]) {
  background: transparent !important;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
  border: 0;
}
html[data-vetro="1"] .gate,
html[data-vetro="1"] .gate :is(input, select, textarea, .primary, .ghost, .acc-card) {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}
html[data-vetro="1"] .gate { background: #fff !important; }
html[data-vetro="1"] .gate input { background: #fff !important; color: #12203a; }

.tema-stili, .tema-buio { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.tema-stili button, .tema-buio button {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 14px; padding: 10px 12px; font: inherit; font-weight: 650; cursor: pointer;
  min-width: 108px;
}
.tema-stili button.on, .tema-buio button.on {
  border-color: var(--azure); box-shadow: 0 0 0 2px color-mix(in srgb, var(--azure) 35%, transparent);
}
.tema-sw { display: block; height: 28px; border-radius: 8px; margin-bottom: 8px; }
.tema-sw.salvia { background: linear-gradient(135deg, #e7eee3, #fff 55%, #1b1d20); }
.tema-sw.blu { background: linear-gradient(135deg, #e8eef8, #fff 50%, #2f6bff); }
.tema-sw.ambra { background: linear-gradient(135deg, #f4efe6, #fffdf9 50%, #b86a1d); }
.tema-sw.lilla { background: linear-gradient(135deg, #efeaf6, #fffcff 50%, #6b46c1); }
.tema-vetro {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  margin: 0 0 16px; font-size: 14px; font-weight: 650; color: var(--ink);
}
.tema-vetro input {
  width: 18px; height: 18px; min-width: 18px; margin: 0; accent-color: var(--azure);
}

/* --- Ottimizzazione grafica: tema scuro, mobile, accessibilità --- */

html[data-stile] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236b778c' d='M1.2 1.2l4.8 4.8 4.8-4.8' stroke='%236b778c' stroke-width='1.2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}
html[data-buio="scuro"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23a3aea6' d='M1.2 1.2l4.8 4.8 4.8-4.8' stroke='%23a3aea6' stroke-width='1.2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
html[data-vetro="1"] select {
  background-color: color-mix(in srgb, var(--card) 78%, transparent) !important;
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  border: 1px solid rgba(255,255,255,.9);
}
html[data-vetro="1"][data-buio="scuro"] select {
  background-color: color-mix(in srgb, var(--card) 78%, transparent) !important;
  border-color: rgba(255,255,255,.22);
}

html[data-stile] .primary:hover { filter: brightness(1.06); }
html[data-stile] :where(a, button, .ghost, .act, .primary, input, select, textarea, .tile, .card):focus-visible {
  outline: 2px solid color-mix(in srgb, var(--azure) 70%, white);
  outline-offset: 2px;
}
html[data-stile] ::placeholder { color: color-mix(in srgb, var(--ink) 45%, var(--bg)); opacity: 1; }
html[data-stile] .ops-row.is-late {
  background: color-mix(in srgb, #b91c1c 8%, var(--card));
}
html[data-stile] .ops-row.is-late strong { color: #b91c1c; }
html[data-stile] .fic-prog-label { color: var(--ink); }
html[data-stile] .modal-card footer .primary,
html[data-stile] .modal-card footer .ghost {
  min-height: 40px;
}

/* Tema scuro: superfici rimaste chiare e testo poco leggibile */
html[data-buio="scuro"] {
  --d-well: color-mix(in srgb, var(--card) 88%, black);
  --d-soft: color-mix(in srgb, var(--card) 92%, var(--ink));
  --d-tint: color-mix(in srgb, var(--azure) 18%, var(--card));
  --d-warm: color-mix(in srgb, #b86a1d 16%, var(--card));
  --d-red: color-mix(in srgb, #b91c1c 18%, var(--card));
  --d-green: color-mix(in srgb, #15803d 18%, var(--card));
  --d-violet: color-mix(in srgb, #6b46c1 16%, var(--card));
}
html[data-buio="scuro"] :where(
  .rep-side, .rep-main, .rep-list button, .rep-cols label,
  .cc-detail-main, .cc-side, .cc-panel, .cc-dialog, .cc-grid7, .cc-dow,
  .cc-chat, .cc-chat header, .cc-chat-log, .cc-chat form, .cc-chat textarea,
  .cc-chat #ccChatStato, .cc-bubble.bot, .cc-actbar,
  .kpi, .card, .tile, .aw, .acc-card, .modal-card
) {
  background: var(--d-well);
  background-color: var(--d-well);
  color: var(--ink);
  border-color: var(--line);
}
html[data-buio="scuro"] :where(
  .rep-list button:hover, .rep-list button.on,
  .cc-day.has:hover, .dash-ops .ops-row
) {
  background: var(--d-soft);
}
html[data-buio="scuro"] :where(
  .app-tabs button.on, .pager .on, .steps li.on, .fic-steps li.on
) {
  background: var(--d-tint) !important;
  color: var(--ink) !important;
}
html[data-buio="scuro"] .ops-row.is-late {
  background: var(--d-red);
}
html[data-buio="scuro"] .ops-row.is-late strong { color: #fca5a5; }
html[data-buio="scuro"] .cc-ok { background: #15803d; color: #fff; }
html[data-buio="scuro"] p.cc-warn,
html[data-buio="scuro"] .hint.cc-warn {
  background: var(--d-warm);
  color: #fde68a;
}
html[data-buio="scuro"] button.cc-warn { background: #b86a1d; color: #fff; }
html[data-buio="scuro"] .aside-foot,
html[data-buio="scuro"] .aside-user-k,
html[data-buio="scuro"] .nav-lab {
  color: color-mix(in srgb, var(--ink) 72%, transparent);
}
html[data-buio="scuro"] .gate,
html[data-buio="scuro"] .gate-panel,
html[data-buio="scuro"] .gate input {
  background: var(--card);
  color: var(--ink);
}
html[data-buio="scuro"] .gate-card h2,
html[data-buio="scuro"] .gate-way-k,
html[data-buio="scuro"] .gate-lab,
html[data-buio="scuro"] .gate-sub,
html[data-buio="scuro"] .gate-way-sub { color: var(--ink); }
html[data-buio="scuro"] .gate-sub,
html[data-buio="scuro"] .gate-lab,
html[data-buio="scuro"] .gate-way-sub { color: var(--muted); }
html[data-buio="scuro"] .cli-hero .ghost {
  background: color-mix(in srgb, white 14%, transparent);
  color: #fff;
  border-color: color-mix(in srgb, white 28%, transparent);
}
html[data-buio="scuro"] .cli-hero .ghost:hover {
  background: #fff;
  color: var(--azure);
}

@media (max-width: 1100px) {
  /* aside globale non deve spostare la colonna report né la chat */
  html[data-stile] aside.rep-side {
    position: sticky;
    inset: auto;
    top: 12px;
    width: auto;
    height: auto;
    max-height: none;
    transform: none;
    z-index: auto;
    box-shadow: none;
    padding-top: 14px;
    padding-bottom: 14px;
    overflow: visible;
  }
  html[data-stile] aside.cc-chat {
    position: fixed;
    top: auto;
    left: auto;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: min(420px, calc(100vw - 24px));
    height: min(640px, calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    transform: translateY(12px);
    padding-top: 0;
    padding-bottom: 0;
    z-index: 96;
  }
  html[data-stile] aside.cc-chat.is-on { transform: none; }
  html[data-stile] .nav-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    background: color-mix(in srgb, var(--ink) 10%, transparent);
  }
  html[data-buio="scuro"] .topbar {
    background: color-mix(in srgb, var(--bg) 88%, transparent);
  }
  html[data-buio="scuro"] .app-tabs {
    background: color-mix(in srgb, var(--card) 92%, transparent);
  }
  html[data-buio="scuro"] .app-tabs button.on {
    background: var(--d-tint);
    color: var(--ink);
  }
  html[data-stile] input,
  html[data-stile] select,
  html[data-stile] textarea {
    font-size: 16px;
  }
  html[data-stile] .cc-dialog {
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  html[data-stile] .modal,
  html[data-stile] .cc-modal {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  html[data-stile] .burger::after,
  html[data-stile] .top-bell::after,
  html[data-stile] .user-chip::after,
  html[data-stile] .nav-close::after {
    content: "";
    position: absolute;
    inset: -6px;
  }
  html[data-stile] .burger,
  html[data-stile] .top-bell,
  html[data-stile] .user-chip { position: relative; }
  html[data-stile] .nav-close { position: absolute; right: 0; top: 0; }
}

@media (min-width: 1101px) and (max-width: 1280px) {
  html[data-stile] .cc-detail {
    grid-template-columns: minmax(0, 1fr);
  }
  html[data-stile] .cc-detail,
  html[data-stile] .cc-detail-main,
  html[data-stile] .cc-side {
    overflow-wrap: anywhere;
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-stile] *,
  html[data-stile] *::before,
  html[data-stile] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
