/**
 * Temi grafici PhiSyMa
 * Variabili: sfondo generale, sfondo secondario, bordi arrotondati, hover card, bordi card/tabelle, colori font a contrasto.
 * Il tema effettivo è applicato su body con data-theme="<id>".
 */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&family=Open+Sans:wght@400;600;700&display=swap');

/* ========== Variabili base (default tema tech) ========== */
/* Contrasti verificati WCAG: #e2e8f0 su #0f172a ≈14.5:1, su #1e293b ≈11.9:1 (AAA);
   #9aa7bb su #0f172a ≈7.3:1 (AAA), su #1e293b ≈6:1 (AA). */
:root,
body[data-theme="tech"] {
    --theme-bg: #0f172a;
    --theme-bg-secondary: #1e293b;
    --theme-radius: 8px;
    --theme-card-border: rgba(148, 163, 184, 0.35);
    --theme-card-hover-shadow: 0 12px 24px rgba(34, 211, 238, 0.15);
    --theme-card-hover-transform: translateY(-4px);
    --theme-font: #e2e8f0;
    --theme-font-muted: #9aa7bb;
    --theme-sidebar-bg: linear-gradient(180deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
    --theme-input-bg: #1e293b;
    --theme-input-border: rgba(148, 163, 184, 0.4);
}

/* ========== Tema Management (progetti) ========== */
body[data-theme="management"] {
    --theme-bg: #f1f5f9;
    --theme-bg-secondary: #e2e8f0;
    --theme-radius: 10px;
    --theme-card-border: rgba(59, 130, 246, 0.25);
    --theme-card-hover-shadow: 0 10px 30px rgba(59, 130, 246, 0.12);
    --theme-card-hover-transform: translateY(-3px);
    --theme-font: #0f172a;
    --theme-font-muted: #475569;
    --theme-sidebar-bg: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(241,245,249,0.95));
    --theme-input-bg: #ffffff;
    --theme-input-border: rgba(148, 163, 184, 0.35);
}

/* ========== Tema Femminile ========== */
body[data-theme="feminine"] {
    --theme-bg: #fdf2f8;
    --theme-bg-secondary: #fce7f3;
    --theme-radius: 1.25rem;
    --theme-card-border: rgba(219, 39, 119, 0.2);
    --theme-card-hover-shadow: 0 12px 28px rgba(219, 39, 119, 0.12);
    --theme-card-hover-transform: translateY(-4px);
    --theme-font: #4c1d95;
    --theme-font-muted: #7c3aed;
    --theme-sidebar-bg: linear-gradient(180deg, rgba(253, 242, 248, 0.98), rgba(252, 231, 243, 0.95));
    --theme-input-bg: #ffffff;
    --theme-input-border: rgba(219, 39, 119, 0.25);
}

/* ========== Tema Alto contrasto ========== */
body[data-theme="high_contrast"] {
    --theme-bg: #ffffff;
    --theme-bg-secondary: #f1f1f1;
    --theme-radius: 4px;
    --theme-card-border: #000000;
    --theme-card-hover-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    --theme-card-hover-transform: translateY(-2px);
    --theme-font: #000000;
    --theme-font-muted: #333333;
    --theme-sidebar-bg: #f1f1f1;
    --theme-input-bg: #ffffff;
    --theme-input-border: #000000;
}

/* ========== Tema Scuro (caldo, non tech) ========== */
body[data-theme="dark"] {
    --theme-bg: #1c1917;
    --theme-bg-secondary: #292524;
    --theme-radius: 12px;
    --theme-card-border: rgba(168, 162, 158, 0.3);
    --theme-card-hover-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
    --theme-card-hover-transform: translateY(-3px);
    --theme-font: #e7e5e4;
    --theme-font-muted: #a8a29e;
    --theme-sidebar-bg: linear-gradient(180deg, rgba(41, 37, 36, 0.98), rgba(28, 25, 23, 0.99));
    --theme-input-bg: #292524;
    --theme-input-border: rgba(168, 162, 158, 0.4);
}

/* ========== Tema Accessibile (WCAG 2.1 AAA) - mai disattivabile ========== */
body[data-theme="accessible"] {
    --theme-bg: #ffffff;
    --theme-bg-secondary: #f5f5f5;
    --theme-radius: 4px;
    --theme-card-border: #000000;
    --theme-card-hover-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --theme-card-hover-transform: none;
    --theme-font: #000000;
    --theme-font-muted: #333333;
    --theme-sidebar-bg: #f5f5f5;
    --theme-input-bg: #ffffff;
    --theme-input-border: #000000;
    /* Accessibilità: focus molto visibile */
    --theme-focus-outline: 3px solid #000000;
    --theme-focus-outline-offset: 2px;
    /* Tipografia: font leggibili, corpo min 18px */
    --theme-font-family: 'Atkinson Hyperlegible', 'Open Sans', system-ui, sans-serif;
    --theme-font-size-base: 18px;
    --theme-line-height: 1.6;
    --theme-letter-spacing: 0.02em;
}

/* ========== Applicazione variabili tema su layout ========== */
body[data-theme] {
    background-color: var(--theme-bg) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .main-content {
    background: var(--theme-bg) !important;
}

body[data-theme] .sidebar {
    background: var(--theme-sidebar-bg) !important;
}

body[data-theme] .card,
body[data-theme] .glass-card {
    background: var(--theme-bg-secondary) !important;
    border-color: var(--theme-card-border) !important;
    border-radius: var(--theme-radius) !important;
}

body[data-theme] .card:hover,
body[data-theme] .card-dashboard:hover {
    box-shadow: var(--theme-card-hover-shadow) !important;
    transform: var(--theme-card-hover-transform) !important;
}

/* Tabelle: sfondo e testo sempre a contrasto con il tema */
body[data-theme] .table,
body[data-theme] .table th,
body[data-theme] .table td {
    border-color: var(--theme-card-border) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table thead th {
    background: var(--theme-bg-secondary) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table tbody td {
    background: var(--theme-bg) !important;
    color: var(--theme-font) !important;
}

/* table-striped: righe alternate con sfondo secondario, testo a contrasto */
body[data-theme] .table-striped > tbody > tr:nth-of-type(odd) > *,
body[data-theme] .table-striped > tbody > tr:nth-of-type(odd) {
    background-color: var(--theme-bg) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table-striped > tbody > tr:nth-of-type(even) > *,
body[data-theme] .table-striped > tbody > tr:nth-of-type(even) {
    background-color: var(--theme-bg-secondary) !important;
    color: var(--theme-font) !important;
}

/* table-hover: stato hover con sfondo leggermente diverso, testo invariato */
body[data-theme] .table-hover > tbody > tr:hover > *,
body[data-theme] .table-hover > tbody > tr:hover {
    background-color: var(--theme-bg-secondary) !important;
    color: var(--theme-font) !important;
}

/* Combinazione striped + hover: riga hover mantiene contrasto */
body[data-theme] .table-striped.table-hover > tbody > tr:nth-of-type(odd):hover > *,
body[data-theme] .table-striped.table-hover > tbody > tr:nth-of-type(odd):hover {
    background-color: var(--theme-bg-secondary) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table-striped.table-hover > tbody > tr:nth-of-type(even):hover > *,
body[data-theme] .table-striped.table-hover > tbody > tr:nth-of-type(even):hover {
    background-color: var(--theme-bg) !important;
    color: var(--theme-font) !important;
}

/* Override base44 .table.rounded (evita sfondo bianco/trasparente che crea testo chiaro su chiaro) */
body[data-theme] .table.rounded,
body[data-theme] .table[style*="border-radius"] {
    background: var(--theme-bg-secondary) !important;
}

body[data-theme] .table.rounded thead th,
body[data-theme] .table[style*="border-radius"] thead th {
    background: var(--theme-bg-secondary) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table.rounded tbody tr:hover,
body[data-theme] .table[style*="border-radius"] tbody tr:hover > * {
    background-color: var(--theme-bg) !important;
    color: var(--theme-font) !important;
}

/* Icone e bottoni azioni nelle tabelle: contrasto con sfondo riga */
body[data-theme] .table .btn,
body[data-theme] .table .btn i,
body[data-theme] .table td .btn,
body[data-theme] .table td .btn i,
body[data-theme] .table td a:not(.btn) i,
body[data-theme] .table td i.fas,
body[data-theme] .table td i.far,
body[data-theme] .table td i.fab,
body[data-theme] .table td [class^="fa-"],
body[data-theme] .table .dropdown-toggle,
body[data-theme] .table .dropdown-menu,
body[data-theme] .table .dropdown-item {
    color: var(--theme-font) !important;
}

body[data-theme] .table .btn-outline-primary,
body[data-theme] .table .btn-outline-secondary,
body[data-theme] .table .btn-outline-danger,
body[data-theme] .table .btn-outline-warning,
body[data-theme] .table .btn-outline-info,
body[data-theme] .table .btn-outline-success,
body[data-theme] .table .btn-outline-dark,
body[data-theme] .table .btn-outline-light {
    border-color: var(--theme-font) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table .btn-outline-primary:hover,
body[data-theme] .table .btn-outline-secondary:hover,
body[data-theme] .table .btn-outline-danger:hover,
body[data-theme] .table .btn-outline-warning:hover,
body[data-theme] .table .btn-outline-info:hover,
body[data-theme] .table .btn-outline-success:hover {
    background-color: var(--theme-font-muted) !important;
    border-color: var(--theme-font) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .table .btn-link {
    color: var(--theme-font) !important;
}

body[data-theme] .table .btn-link:hover {
    color: var(--theme-font-muted) !important;
}

body[data-theme] .profile-box,
body[data-theme] .bg-light {
    background: var(--theme-bg-secondary) !important;
    color: var(--theme-font) !important;
}

body[data-theme] .text-muted,
body[data-theme] small.text-muted {
    color: var(--theme-font-muted) !important;
}

/* Override globale colore nero di base44-override per temi scuri (tech, dark):
   base44-override imposta *, .card, .card-body, ecc. a #000000; qui si ripristina
   il colore tema per tutto il contenuto. */
body[data-theme="tech"] *,
body[data-theme="tech"] *::before,
body[data-theme="tech"] *::after,
body[data-theme="dark"] *,
body[data-theme="dark"] *::before,
body[data-theme="dark"] *::after {
    color: var(--theme-font) !important;
}

body[data-theme="tech"] .text-muted,
body[data-theme="tech"] small.text-muted,
body[data-theme="dark"] .text-muted,
body[data-theme="dark"] small.text-muted {
    color: var(--theme-font-muted) !important;
}

/* Pulsanti: mantieni testo leggibile (Bootstrap imposta .btn-primary con bianco;
   con tema scuro var(--theme-font) è chiaro, ok per bottoni primari) */
body[data-theme="tech"] .btn-primary,
body[data-theme="tech"] .btn-success,
body[data-theme="tech"] .btn-danger,
body[data-theme="tech"] .btn-info,
body[data-theme="tech"] .btn-warning,
body[data-theme="dark"] .btn-primary,
body[data-theme="dark"] .btn-success,
body[data-theme="dark"] .btn-danger,
body[data-theme="dark"] .btn-info,
body[data-theme="dark"] .btn-warning {
    color: #ffffff !important;
}

/* ========== Tema Accessibile: regole specifiche WCAG ========== */
body[data-theme="accessible"] {
    font-family: var(--theme-font-family) !important;
    font-size: var(--theme-font-size-base) !important;
    line-height: var(--theme-line-height) !important;
    letter-spacing: var(--theme-letter-spacing) !important;
}

body[data-theme="accessible"] * {
    font-family: inherit;
}

body[data-theme="accessible"] .card,
body[data-theme="accessible"] .card-body,
body[data-theme="accessible"] .main-content,
body[data-theme="accessible"] p,
body[data-theme="accessible"] span,
body[data-theme="accessible"] div,
body[data-theme="accessible"] label,
body[data-theme="accessible"] .form-label,
body[data-theme="accessible"] .form-control {
    font-size: var(--theme-font-size-base) !important;
    line-height: var(--theme-line-height) !important;
}

/* Focus visibile: outline almeno 3px */
body[data-theme="accessible"] *:focus-visible {
    outline: var(--theme-focus-outline) !important;
    outline-offset: var(--theme-focus-outline-offset) !important;
}

body[data-theme="accessible"] a:focus-visible {
    outline: var(--theme-focus-outline) !important;
    outline-offset: var(--theme-focus-outline-offset) !important;
    text-decoration: underline !important;
}

/* Link: non solo colore - sottolineatura */
body[data-theme="accessible"] a {
    text-decoration: underline !important;
}

/* Pulsanti: dimensioni minime 44x44px, bordi definiti */
body[data-theme="accessible"] .btn {
    min-width: 44px !important;
    min-height: 44px !important;
    border: 2px solid #000000 !important;
    font-weight: 700 !important;
}

/* Gerarchia titoli chiara */
body[data-theme="accessible"] h1, body[data-theme="accessible"] .h1 { font-size: 2rem !important; font-weight: 800 !important; }
body[data-theme="accessible"] h2, body[data-theme="accessible"] .h2 { font-size: 1.5rem !important; font-weight: 700 !important; }
body[data-theme="accessible"] h3, body[data-theme="accessible"] .h3 { font-size: 1.25rem !important; font-weight: 700 !important; }

/* Icone: sempre con etichetta testuale visibile (gestito in HTML/ARIA) */
body[data-theme="accessible"] .btn i + span,
body[data-theme="accessible"] .nav-link i + .menu-text {
    font-size: var(--theme-font-size-base) !important;
}
