/* ============================================================
   Tema UI Archivet IDP
   Default istituzionale: "archivet" (arancio Extra + steel)
   Temi utente: bosco, oceano, tramonto, lavanda, sabbia, grafite, notte
   ============================================================ */

/* ---- DESIGN TOKENS (comuni a tutti i temi) ---- */
:root {
    /* Spacing scale (base 4px) */
    --space-1: .25rem;   /*  4px */
    --space-2: .5rem;    /*  8px */
    --space-3: .75rem;   /* 12px */
    --space-4: 1rem;     /* 16px */
    --space-5: 1.25rem;  /* 20px */
    --space-6: 1.5rem;   /* 24px */
    --space-8: 2rem;     /* 32px */
    --space-10: 2.5rem;  /* 40px */
    --space-12: 3rem;    /* 48px */
    --space-16: 4rem;    /* 64px */

    /* Typography scale */
    --text-xs: .75rem;
    --text-sm: .85rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;
    --text-3xl: 2.75rem;
    --text-hero: 3.75rem;

    --leading-tight: 1.2;
    --leading-normal: 1.5;
    --leading-loose: 1.75;

    --font-display: 'DM Serif Display', Georgia, serif;
    --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'DM Mono', 'SF Mono', Menlo, monospace;

    /* Geometry */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --border-w: 1px;
    --border-w-2: 2px;

    /* Motion */
    --ease: cubic-bezier(.4, 0, .2, 1);
    --dur-1: 150ms;   /* micro-interazioni */
    --dur-2: 200ms;   /* transizioni di stato */
    --dur-3: 300ms;   /* entrata componenti */
}

@media (prefers-reduced-motion: reduce) {
    :root { --dur-1: .001ms; --dur-2: .001ms; --dur-3: .001ms; }
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- THEME TOKENS: ARCHIVET (default istituzionale) ---- */
:root,
:root[data-theme="archivet"] {
    --bg: #fbf9f6;
    --bg2: #f3eee7;
    --surface: #ffffff;
    --surface2: #faf8f5;
    --border: #e2dcd1;
    --accent: #c2671a;
    --accent2: #f58220;
    --accent-light: #fde8d4;
    --steel: #727d84;
    --steel-dark: #4a5358;
    --steel-light: #d8dde0;
    --danger: #9b2335;
    --danger-light: #fce4e7;
    --warning: #a05c00;
    --warning-light: #fef3c7;
    --success: #2d6a4f;
    --success-light: #d8f3dc;
    --info: #1d6fa5;
    --info-light: #d6ebf7;
    --text: #1c1917;
    --text2: #4a5358;
    --text3: #98a0a6;
    --gold: #c9a84c;
    --gold-light: #fdf6e3;
    --shadow-sm: 0 1px 3px rgba(28,25,23,.06);
    --shadow-md: 0 4px 16px rgba(28,25,23,.08);
    --shadow-lg: 0 12px 32px rgba(28,25,23,.14);
    --shadow-focus: 0 0 0 3px var(--accent-light);
    --transition: var(--dur-2) var(--ease);
}

/* ---- THEME TOKENS: BOSCO (verde, opzione utente) ---- */
:root[data-theme="bosco"] {
    --bg: #f4f1ec;
    --bg2: #ede9e1;
    --surface: #ffffff;
    --surface2: #fafaf8;
    --border: #ddd8ce;
    --accent: #1a4731;
    --accent2: #2d6a4f;
    --accent-light: #d8f3dc;
    --steel: #57534e;
    --steel-dark: #3a3633;
    --steel-light: #c9c2b9;
    --danger: #9b2335;
    --danger-light: #fce4e7;
    --warning: #a05c00;
    --warning-light: #fef3c7;
    --success: #2d6a4f;
    --success-light: #d8f3dc;
    --info: #1d6fa5;
    --info-light: #d6ebf7;
    --text: #1c1917;
    --text2: #57534e;
    --text3: #a8a29e;
    --gold: #c9a84c;
    --gold-light: #fdf6e3;
    --shadow-focus: 0 0 0 3px rgba(45,106,79,.18);
}

/* Future themes hooks — placeholder per estensione futura
   :root[data-theme="oceano"]   { ... }
   :root[data-theme="tramonto"] { ... }
   :root[data-theme="grafite"]  { ... }
   :root[data-theme="lavanda"]  { ... }
   :root[data-theme="sabbia"]   { ... }
*/

/* ---- THEME: OCEANO (acqua, blu profondo) ---- */
:root[data-theme="oceano"] {
    --bg: #eef4f8;
    --bg2: #e2ecf2;
    --surface: #ffffff;
    --surface2: #f7fafc;
    --border: #cfdde6;
    --accent: #0b3d5c;
    --accent2: #1d6fa5;
    --accent-light: #d6ebf7;
    --danger: #9b2335;
    --danger-light: #fce4e7;
    --warning: #a05c00;
    --warning-light: #fef3c7;
    --text: #0f1d2a;
    --text2: #4a5b6b;
    --text3: #8fa1b0;
    --gold: #2bb5b8;
    --gold-light: #d8f4f5;
}

/* ---- THEME: TRAMONTO (caldo, ambra/corallo) ---- */
:root[data-theme="tramonto"] {
    --bg: #fbf3ec;
    --bg2: #f6e8db;
    --surface: #ffffff;
    --surface2: #fef9f4;
    --border: #ecd9c5;
    --accent: #8a2f1f;
    --accent2: #d2542d;
    --accent-light: #fde4d3;
    --danger: #a01e2a;
    --danger-light: #fce0e3;
    --warning: #8a5a00;
    --warning-light: #fef0c7;
    --text: #2b1a14;
    --text2: #6b4f44;
    --text3: #b09a8e;
    --gold: #c98b2a;
    --gold-light: #fdf0d8;
}

/* ---- THEME: GRAFITE (dark mode neutro) ---- */
:root[data-theme="grafite"] {
    --bg: #15171a;
    --bg2: #1c1f23;
    --surface: #22262b;
    --surface2: #2a2f35;
    --border: #353b42;
    --accent: #8fb3a3;
    --accent2: #a5c8b8;
    --accent-light: #2c3a35;
    --danger: #f0707f;
    --danger-light: #4a2329;
    --warning: #e7a85a;
    --warning-light: #4a3722;
    --text: #f0ede6;
    --text2: #c2bdb3;
    --text3: #7a766f;
    --gold: #d4b769;
    --gold-light: #3d3520;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,.5);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.6);
}

/* ---- THEME: LAVANDA (viola tenue, femminile) ---- */
:root[data-theme="lavanda"] {
    --bg: #f5f1f8;
    --bg2: #ece5f3;
    --surface: #ffffff;
    --surface2: #faf7fc;
    --border: #ddd2e8;
    --accent: #4b2a7a;
    --accent2: #7a4caf;
    --accent-light: #ece1f8;
    --danger: #9b2335;
    --danger-light: #fce4e7;
    --warning: #a05c00;
    --warning-light: #fef3c7;
    --text: #1f1226;
    --text2: #524563;
    --text3: #9b8eaa;
    --gold: #c89b3c;
    --gold-light: #fbf2d9;
}

/* ---- THEME: SABBIA (chiaro, beige caldo) ---- */
:root[data-theme="sabbia"] {
    --bg: #faf6ee;
    --bg2: #f1ead7;
    --surface: #ffffff;
    --surface2: #fdfaf1;
    --border: #e3d8ba;
    --accent: #6b4d1a;
    --accent2: #a87a2c;
    --accent-light: #f5e9c6;
    --danger: #9b2335;
    --danger-light: #fce4e7;
    --warning: #a05c00;
    --warning-light: #fef3c7;
    --text: #2a1f10;
    --text2: #5e4d33;
    --text3: #a89880;
    --gold: #b88a2b;
    --gold-light: #fbf0c8;
}

/* ---- THEME: NOTTE (dark blu profondo) ---- */
:root[data-theme="notte"] {
    --bg: #0e1726;
    --bg2: #15203a;
    --surface: #1a2742;
    --surface2: #21304f;
    --border: #2c3a5c;
    --accent: #7eb6ff;
    --accent2: #a3cdff;
    --accent-light: #1f3258;
    --danger: #f0707f;
    --danger-light: #4a2329;
    --warning: #ffba5c;
    --warning-light: #4a3722;
    --text: #eaf0fa;
    --text2: #b8c4dd;
    --text3: #6c7a98;
    --gold: #ffcb6b;
    --gold-light: #3d3520;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
    --shadow-md: 0 4px 16px rgba(0,0,0,.6);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.7);
}

/* ---- BASE ---- */
.app-shell *,
.app-shell *::before,
.app-shell *::after { box-sizing: border-box; }

.app-shell body,
body.app-shell {
    font-family: 'DM Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
}

.app-shell a { color: var(--accent2); text-decoration: none; }
.app-shell a:hover { color: var(--accent); text-decoration: underline; }

/* Reset link color/decoration for branded chrome on dark backgrounds */
.app-shell .ds-nav a,
.app-shell .ds-nav-brand,
.app-shell .ds-nav-tab,
.app-shell .ds-nav-logout,
.app-shell .ds-nav-login,
.app-shell .ds-btn {
    text-decoration: none;
}

.app-shell .ds-nav a:hover,
.app-shell .ds-nav-brand:hover,
.app-shell .ds-btn:hover { text-decoration: none; }

.app-shell .ds-nav-brand,
.app-shell .ds-nav-brand:hover,
.app-shell .ds-nav-brand:visited,
.app-shell .ds-nav-tab,
.app-shell .ds-nav-tab:visited { color: #ffffff; }

.app-shell .ds-nav-tab:hover,
.app-shell .ds-nav-tab.active,
.app-shell .ds-nav-tab.active:hover { color: var(--gold); }

.app-shell .ds-nav-logout,
.app-shell .ds-nav-logout:hover,
.app-shell .ds-nav-logout:visited { color: #ffffff; }

.app-shell .ds-nav-login,
.app-shell .ds-nav-login:hover,
.app-shell .ds-nav-login:visited { color: var(--accent); }

.app-shell .ds-btn-primary,
.app-shell .ds-btn-primary:hover,
.app-shell .ds-btn-primary:visited,
.app-shell .ds-btn-primary:focus,
.app-shell .ds-btn-primary:active,
.app-shell .ds-btn-danger,
.app-shell .ds-btn-danger:hover,
.app-shell .ds-btn-danger:visited,
.app-shell .ds-btn-danger:focus,
.app-shell .ds-btn-danger:active { color: #ffffff; }

.app-shell .ds-btn-gold,
.app-shell .ds-btn-gold:hover,
.app-shell .ds-btn-gold:visited { color: #1c1917; }

/* Heading globali: solo H1 è DM Serif Display (regola firma del design system).
   Da H2 in giù si usa DM Sans, sempre con colore --text. Mai arancio. */
.app-shell h1 {
    font-family: var(--font-display);
    color: var(--text);
    font-weight: 400;
    margin: 0 0 .5rem;
    line-height: 1.2;
}

.app-shell h2,
.app-shell h3,
.app-shell h4 {
    font-family: var(--font-sans);
    color: var(--text);
    font-weight: 600;
    margin: 0 0 .5rem;
    line-height: 1.25;
}

.app-shell hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ---- FOCUS RING ---- */
.app-shell :focus-visible {
    outline: 2px solid var(--accent2);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- NAV (top) ---- */
/* Navbar in grigio acciaio (--steel), neutro istituzionale del design system. */
.ds-nav {
    background: linear-gradient(135deg, var(--steel-dark, #4a5358) 0%, var(--steel, #727d84) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 16px rgba(0,0,0,.18);
}

.ds-nav-brand {
    font-family: 'DM Serif Display', serif;
    font-size: 1.15rem;
    letter-spacing: .02em;
    display: flex;
    align-items: center;
    gap: .6rem;
    color: #ffffff;
    text-decoration: none;
}

    .ds-nav-brand:hover { color: #ffffff; text-decoration: none; }

    .ds-nav-brand img { height: 28px; width: auto; }

    .ds-nav-brand .badge {
        font-family: 'DM Mono', monospace;
        font-size: .65rem;
        background: var(--gold);
        color: #1c1917;
        padding: 2px 7px;
        border-radius: 3px;
        font-weight: 500;
    }

.ds-nav-tabs {
    display: flex;
    gap: .25rem;
    height: 100%;
    flex: 1;
    margin: 0 1.5rem;
}

.ds-nav-tab {
    padding: 0 1.1rem;
    border: none;
    background: transparent;
    color: #ffffff;
    font-family: 'DM Sans', sans-serif;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .4rem;
    border-bottom: 3px solid transparent;
    transition: all .2s;
    text-decoration: none;
    height: 100%;
}

    .ds-nav-tab:hover { color: var(--gold); background: rgba(255,255,255,.12); text-decoration: none; }
    .ds-nav-tab.active { color: var(--gold); border-bottom-color: var(--gold); background: rgba(255,255,255,.08); font-weight: 600; }
    .ds-nav-tab.active:hover { color: var(--gold); }

.ds-nav-user {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .8rem;
    color: #ffffff;
}

.ds-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gold);
    color: #1c1917;
    font-weight: 700;
    font-size: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ds-user-info { display: flex; flex-direction: column; line-height: 1.15; }
.ds-user-name { font-weight: 600; font-size: .82rem; color: #ffffff; }
.ds-user-meta { font-size: .68rem; color: rgba(255,255,255,.85); }

.ds-nav-logout {
    background: rgba(255,255,255,.08);
    color: #fff;
    border: 1px solid rgba(255,255,255,.18);
    padding: .35rem .75rem;
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

    .ds-nav-logout:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); color: #fff; text-decoration: none; }

.ds-nav-login {
    background: var(--gold);
    color: var(--accent);
    border: none;
    padding: .4rem .9rem;
    border-radius: 6px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

    .ds-nav-login:hover { filter: brightness(.95); color: var(--accent); text-decoration: none; }

/* ---- MAIN ---- */
.ds-main {
    max-width: 1300px;
    margin: 0 auto;
    padding: 1.5rem 2rem 2rem;
    animation: ds-pageIn .35s ease-out;
}

@keyframes ds-pageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- BREADCRUMB ---- */
.ds-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .35rem;
    font-size: .8rem;
    color: var(--text2);
    margin-bottom: 1.25rem;
}

    .ds-breadcrumb .bc-item { color: var(--accent2); text-decoration: none; }
    .ds-breadcrumb .bc-item:hover { text-decoration: underline; }
    .ds-breadcrumb .bc-current { color: var(--text2); font-weight: 600; }
    .ds-breadcrumb .bc-sep { color: var(--text3); }

/* ---- PAGE HEADER (legacy reset) ----
   Le regole moderne sono più sotto, blocco "DS COMPONENTS: PAGE HEADER".
   Qui resettiamo eventuali residui ereditati. */

/* ---- SUB-NAV (tabs interne, es. Manage) ---- */
.ds-subnav {
    display: flex;
    gap: .25rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.ds-subnav-tab {
    padding: .6rem 1rem;
    color: var(--text2);
    font-size: .85rem;
    font-weight: 500;
    text-decoration: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    transition: color .15s, border-color .15s, background .15s;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    border-radius: 6px 6px 0 0;
}

    .ds-subnav-tab:hover { color: var(--accent); background: var(--bg2); text-decoration: none; }
    .ds-subnav-tab.active { color: var(--accent); border-bottom-color: var(--gold); font-weight: 600; }

/* ---- CARD ---- */
.ds-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}

    .ds-card .ds-card-title {
        font-family: var(--font-sans);
        font-weight: 600;
        color: var(--text);
        font-size: var(--text-xl);
        margin: 0 0 .25rem;
    }

    .ds-card .ds-card-subtitle {
        font-size: .82rem;
        color: var(--text2);
        margin: 0 0 1rem;
    }

/* ---- BUTTONS ---- */
.ds-btn {
    padding: .5rem 1.15rem;
    border-radius: 6px;
    border: none;
    font-family: 'DM Sans', sans-serif;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    text-decoration: none;
    line-height: 1.2;
}

    .ds-btn:active:not(:disabled) { transform: scale(.97); }
    .ds-btn:disabled { opacity: .45; cursor: not-allowed; }

.ds-btn-primary { background: var(--accent2); color: #ffffff; box-shadow: 0 2px 8px rgba(245,130,32,.25); }
    .ds-btn-primary:hover { background: var(--accent); color: #ffffff; text-decoration: none; box-shadow: 0 4px 12px rgba(245,130,32,.30); }
    .ds-btn-primary:visited,
    .ds-btn-primary:focus,
    .ds-btn-primary:active { color: #ffffff; }

.ds-btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text2); }
    .ds-btn-ghost:hover { background: var(--bg2); color: var(--text); text-decoration: none; }

.ds-btn-gold { background: var(--gold); color: #1c1917; }
    .ds-btn-gold:hover { filter: brightness(.93); color: #1c1917; text-decoration: none; }

.ds-btn-danger { background: var(--danger); color: #ffffff; }
    .ds-btn-danger:hover { background: #7f1d1d; color: #ffffff; text-decoration: none; }
    .ds-btn-danger:visited,
    .ds-btn-danger:focus,
    .ds-btn-danger:active { color: #ffffff; }

.ds-btn-lg { padding: .7rem 1.6rem; font-size: .95rem; }

/* ---- FORM ---- */
.ds-form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }

.ds-form-group label,
.ds-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-family: 'DM Mono', monospace;
}

/* Utility per evitare style inline nelle pagine.
   .ds-card-actions: riga di azioni (pulsanti, link) sotto il contenuto di una card.
   .ds-meta-row:     riga di meta-info su due lati (etichetta a sx, copyright/stato a dx).
   .ds-meta-mono:    valore tecnico in monospace (versione, GUID, ID).
   .ds-meta-text:    testo accessorio piccolo (footer card, copyright). */
.ds-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.ds-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
}

.ds-meta-mono {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text2);
}

.ds-meta-text {
    font-size: var(--text-xs);
    color: var(--text3);
}

.ds-input,
.ds-select,
.app-shell .form-control,
.app-shell .form-select {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .55rem .8rem;
    font-family: 'DM Sans', sans-serif;
    font-size: .9rem;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

    .ds-input:focus,
    .ds-select:focus,
    .app-shell .form-control:focus,
    .app-shell .form-select:focus {
        border-color: var(--accent2);
        box-shadow: 0 0 0 3px rgba(45,106,79,.15);
    }

    .ds-input:disabled,
    .app-shell .form-control:disabled {
        background: var(--bg2);
        color: var(--text2);
        cursor: not-allowed;
    }

.ds-form-hint { font-size: .75rem; color: var(--text3); }
.ds-form-error,
.app-shell .text-danger { color: var(--danger); font-size: .8rem; }

.ds-checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text2); }

/* Bootstrap form-floating compat (Manage pages) */
.app-shell .form-floating > label { color: var(--text3); }
.app-shell .form-floating > .form-control:focus ~ label,
.app-shell .form-floating > .form-control:not(:placeholder-shown) ~ label { color: var(--accent2); }

/* ---- AUTH LAYOUT (Login/Register) ---- */
.ds-auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background:
        radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
        radial-gradient(circle at 80% 80%, color-mix(in srgb, var(--gold) 22%, transparent), transparent 55%),
        var(--bg);
}

.ds-auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    overflow: hidden;
}

.ds-auth-header {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
    color: #fff;
    padding: 1.75rem 2rem 1.5rem;
    text-align: center;
}

    .ds-auth-header h1 {
        color: #fff;
        font-family: 'DM Serif Display', serif;
        font-size: 1.5rem;
        margin: 0 0 .25rem;
    }

    .ds-auth-header p { font-size: .85rem; opacity: .85; margin: 0; }

    .ds-auth-header .ds-auth-badge {
        display: inline-block;
        font-family: 'DM Mono', monospace;
        font-size: .65rem;
        background: var(--gold);
        color: #1c1917;
        padding: 2px 8px;
        border-radius: 3px;
        margin-bottom: .5rem;
        font-weight: 600;
        letter-spacing: .04em;
    }

.ds-auth-body { padding: 1.75rem 2rem 1.5rem; }

.ds-auth-footer {
    padding: 1rem 2rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--surface2);
    display: flex;
    flex-direction: column;
    gap: .35rem;
    font-size: .8rem;
    text-align: center;
}

/* ---- TABLE ---- */
.app-shell table,
.ds-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
    background: var(--surface);
}

.app-shell table thead th,
.ds-table thead th {
    text-align: left;
    font-family: 'DM Mono', monospace;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text2);
    background: var(--bg2);
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.app-shell table tbody td,
.ds-table tbody td {
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.app-shell table tbody tr:last-child td,
.ds-table tbody tr:last-child td { border-bottom: none; }

.app-shell table tbody tr,
.ds-table tbody tr { transition: background var(--transition); }

.app-shell table tbody tr:hover,
.ds-table tbody tr:hover { background: var(--bg2); }

/* Reset Bootstrap .table override quando dentro app-shell */
.app-shell .table { color: var(--text); }
.app-shell .table > :not(caption) > * > * { background-color: transparent; }

/* Booleani auto-renderizzati come checkbox disabled → camuffa con accento */
.app-shell table input[type="checkbox"][disabled],
.ds-table input[type="checkbox"][disabled] {
    accent-color: var(--accent2);
    width: 1rem;
    height: 1rem;
    cursor: default;
    margin: 0;
}

/* ---- BADGE ---- */
.ds-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-family: 'DM Sans', sans-serif;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.4;
    border: 1px solid transparent;
    white-space: nowrap;
}

.ds-badge-success { background: var(--success-light); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.ds-badge-info    { background: var(--info-light); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.ds-badge-danger  { background: var(--danger-light); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.ds-badge-warning { background: var(--warning-light); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.ds-badge-neutral { background: var(--bg2); color: var(--text2); border-color: var(--border); }

/* ---- PAGINATION (Bootstrap override) ---- */
.app-shell .pagination {
    display: inline-flex;
    gap: .25rem;
    padding: 0;
    margin: 0;
    list-style: none;
}

.app-shell .pagination .page-item .page-link {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text2);
    border-radius: 6px !important;
    padding: .35rem .65rem;
    font-size: .8rem;
    font-weight: 500;
    font-family: 'DM Sans', sans-serif;
    min-width: 34px;
    text-align: center;
    transition: all var(--transition);
    box-shadow: none;
}

.app-shell .pagination .page-item .page-link:hover {
    background: var(--bg2);
    color: var(--accent);
    border-color: var(--accent2);
}

.app-shell .pagination .page-item.active .page-link {
    background: var(--accent2);
    color: #fff;
    border-color: var(--accent2);
}

.app-shell .pagination .page-item.disabled .page-link {
    opacity: .45;
    cursor: not-allowed;
    background: var(--surface);
    color: var(--text3);
}

.app-shell .pagination .page-item .page-link:focus {
    box-shadow: 0 0 0 3px rgba(45,106,79,.15);
    outline: none;
}

/* ---- SKELETON LOADING ---- */
@keyframes ds-skeleton-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes ds-skeleton-pulse {
    0%   { opacity: .7; }
    50%  { opacity: .35; }
    100% { opacity: .7; }
}

@keyframes ds-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.ds-skeleton,
.ds-skeleton-line {
    display: block;
    border-radius: 4px;
    background: linear-gradient(90deg,
        var(--bg2) 0%,
        color-mix(in srgb, var(--bg2) 55%, var(--surface)) 50%,
        var(--bg2) 100%);
    background-size: 200% 100%;
    animation: ds-skeleton-shimmer 1.4s linear infinite;
}

.ds-skeleton-line { height: 14px; margin-bottom: 8px; }
.ds-skeleton-line:last-child { margin-bottom: 0; }
.ds-skeleton-line.title { width: 40%; height: 18px; margin-bottom: 12px; }
.ds-skeleton-line.short { width: 60%; }
.ds-skeleton-line.tags  { width: 80%; height: 12px; }
.ds-skeleton-line.meta  { width: 50%; height: 12px; }
.ds-skeleton-line.full  { width: 100%; }
.ds-skeleton-line.cell  { width: 90%; height: 12px; margin: 0; }

.ds-skeleton-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: .5rem;
}

.ds-skeleton-info {
    text-align: center;
    padding: .75rem;
    color: var(--text3);
    font-size: .85rem;
    animation: ds-skeleton-pulse 1.5s ease-in-out infinite;
}

.ds-skeleton-block { padding: 1rem 0; }

/* Page-level navigation overlay (shown on internal link clicks / form submits) */
.ds-page-overlay {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(2px);
    z-index: 9000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 18vh;
}

.ds-page-overlay.is-visible { display: flex; }

.ds-page-overlay .ds-overlay-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-lg, 0 12px 32px rgba(0,0,0,.18));
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 220px;
}

.ds-page-overlay .ds-spinner {
    width: 42px;
    height: 42px;
    border: 4px solid var(--border);
    border-top-color: var(--accent2, #f58220);
    border-radius: 50%;
    animation: ds-spin 1s linear infinite;
}

.ds-page-overlay .ds-overlay-text {
    margin-top: .85rem;
    font-family: 'DM Sans', sans-serif;
    font-size: .85rem;
    color: var(--text2);
    text-align: center;
}

/* ---- DS COMPONENTS: PAGE HEADER ---- */
.ds-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
    padding-bottom: var(--space-5);
    margin-bottom: var(--space-6);
    border-bottom: 1px solid var(--border);
}

.ds-page-header-text { flex: 1 1 auto; min-width: 0; }

.ds-page-header h1 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: var(--text-3xl);
    line-height: var(--leading-tight);
    margin: 0 0 var(--space-2);
    /* Reset esplicito: niente gradient, niente clip text. Il titolo è leggibile e neutro. */
    color: var(--text);
    background: none;
    -webkit-background-clip: border-box;
    -webkit-text-fill-color: var(--text);
    background-clip: border-box;
    /* Display block: l'icona resta inline, la linea oro va a capo come block element. */
    display: block;
}

/* Decisione UX: i titoli di pagina restano puliti e tipografici.
   L'icona è ridondante con la voce di navigazione, quindi la nascondiamo
   centralmente invece di rimuoverla da ogni .cshtml. Reversibile. */
.ds-page-header h1 > i,
.ds-page-header h1 [class*="fa-"] {
    display: none !important;
}

.ds-page-header p {
    margin: 0;
    color: var(--text2);
    font-size: var(--text-base);
    max-width: 720px;
}

/* Dettaglio firma: linea oro 40px SOTTO il titolo (block element).
   Vive come ::after dell'H1 in modo da seguire sempre il titolo. */
.ds-page-header h1::after {
    content: "";
    display: block;
    width: 40px;
    height: 2px;
    background: var(--gold);
    border-radius: 2px;
    margin-top: var(--space-3);
}

.ds-page-header-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .ds-page-header h1 { font-size: var(--text-2xl); }
}

/* ---- DS COMPONENTS: EMPTY STATE ---- */
.ds-empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text2);
}

.ds-empty-state .ds-empty-icon {
    font-size: 2.5rem;
    color: var(--text3);
    margin-bottom: var(--space-3);
    display: block;
}

.ds-empty-state h3 {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: var(--text-lg);
    color: var(--text2);
    margin: 0 0 var(--space-2);
}

.ds-empty-state p {
    color: var(--text3);
    font-size: var(--text-sm);
    margin: 0 0 var(--space-5);
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.ds-empty-state-actions {
    display: inline-flex;
    gap: var(--space-2);
    justify-content: center;
}

/* ---- DS COMPONENTS: FORM GRID ---- */
.ds-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.ds-form-grid > .ds-col-full { grid-column: 1 / -1; }

@media (max-width: 600px) {
    .ds-form-grid { grid-template-columns: 1fr; }
}

/* Field standard (label + control) */
.ds-field { display: flex; flex-direction: column; gap: var(--space-1); }
.ds-field label,
.ds-field .form-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text2);
    margin: 0;
}
.ds-field-help {
    font-size: var(--text-xs);
    color: var(--text3);
}

/* ---- DS COMPONENTS: ALERT ---- */
.ds-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius);
    border-left: 4px solid;
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
    background: var(--surface);
}
.ds-alert i { font-size: 1.05rem; flex-shrink: 0; margin-top: 2px; }
.ds-alert-success { background: var(--success-light); border-color: var(--success); color: var(--success); }
.ds-alert-warning { background: var(--warning-light); border-color: var(--warning); color: var(--warning); }
.ds-alert-danger  { background: var(--danger-light);  border-color: var(--danger);  color: var(--danger); }
.ds-alert-info    { background: var(--info-light);    border-color: var(--info);    color: var(--info); }

/* ---- FOCUS RING firma (oro) ---- */
.app-shell .ds-btn:focus-visible,
.app-shell .ds-nav-tab:focus-visible,
.app-shell .ds-subnav-tab:focus-visible,
.app-shell .ds-theme-trigger:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
    box-shadow: var(--shadow-focus);
}

/* ---- DS ANIMATIONS (curva universale + durate canoniche) ---- */
@keyframes ds-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes ds-slide-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes ds-slide-in-right {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes ds-slide-out-right {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(24px); }
}

.ds-anim-fade-in    { animation: ds-fade-in    var(--dur-3) var(--ease) both; }
.ds-anim-slide-up   { animation: ds-slide-up   var(--dur-3) var(--ease) both; }

/* ---- DS COMPONENTS: TOAST ---- */
.ds-toast-stack {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: 9500;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: calc(100vw - var(--space-10));
    pointer-events: none;
}

.ds-toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    min-width: 280px;
    max-width: 380px;
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-left: 4px solid var(--steel);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    line-height: 1.4;
    pointer-events: auto;
    animation: ds-slide-in-right var(--dur-3) var(--ease) both;
}

.ds-toast.is-leaving {
    animation: ds-slide-out-right var(--dur-2) var(--ease) both;
}

.ds-toast i.ds-toast-icon {
    font-size: 1.05rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.ds-toast-body { flex: 1; min-width: 0; }
.ds-toast-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}
.ds-toast-message { color: var(--text2); }

.ds-toast-close {
    background: transparent;
    border: none;
    color: var(--text3);
    cursor: pointer;
    padding: 0;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
    transition: var(--dur-1) var(--ease);
}
.ds-toast-close:hover { background: var(--bg2); color: var(--text); }

.ds-toast-success { border-left-color: var(--success); }
.ds-toast-success .ds-toast-icon { color: var(--success); }

.ds-toast-warning { border-left-color: var(--warning); }
.ds-toast-warning .ds-toast-icon { color: var(--warning); }

.ds-toast-danger  { border-left-color: var(--danger); }
.ds-toast-danger .ds-toast-icon { color: var(--danger); }

.ds-toast-info    { border-left-color: var(--info); }
.ds-toast-info .ds-toast-icon { color: var(--info); }

@media (max-width: 600px) {
    .ds-toast-stack { left: var(--space-3); right: var(--space-3); }
    .ds-toast { min-width: 0; max-width: none; }
}

/* ---- FOOTER ---- */
.ds-footer {
    text-align: center;
    padding: 1.25rem 1rem;
    color: var(--text3);
    font-size: .75rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

    .ds-footer a { color: var(--text2); }

/* ---- THEME SWITCHER ---- */
.ds-theme-switcher {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.ds-theme-trigger {
    background: transparent;
    border: 1px solid color-mix(in srgb, #ffffff 30%, transparent);
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.ds-theme-trigger:hover { background: rgba(255,255,255,.12); }

.ds-theme-popover {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 240px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: .5rem;
    z-index: 8500;
    display: none;
}

.ds-theme-popover.is-open { display: block; }

.ds-theme-popover h4 {
    font-family: 'DM Sans', sans-serif;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text3);
    margin: .25rem .5rem .5rem;
    font-weight: 600;
}

.ds-theme-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .35rem;
}

.ds-theme-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .5rem .6rem;
    cursor: pointer;
    color: var(--text2);
    font-family: 'DM Sans', sans-serif;
    font-size: .82rem;
    text-align: left;
    transition: var(--transition);
}

.ds-theme-option:hover {
    background: var(--bg2);
    color: var(--text);
}

.ds-theme-option.is-active {
    border-color: var(--accent2);
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.ds-theme-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--border);
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--p1, #ccc) 50%, var(--p2, #999) 50%);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
    .ds-nav { padding: 0 1rem; height: auto; flex-wrap: wrap; gap: .5rem; padding-top: .5rem; padding-bottom: .5rem; }
    .ds-nav-tabs { order: 3; flex-basis: 100%; margin: 0; overflow-x: auto; }
    .ds-nav-tab { padding: .6rem .8rem; font-size: .8rem; }
    .ds-user-info { display: none; }
    .ds-main { padding: 1rem; }
    .ds-page-header h1 { font-size: 1.5rem; }
    .ds-theme-popover { right: -1rem; }
}

/* ============================================================
   ACCESSIBILITÀ — Sprint 4
   Utility per screen reader, skip link, focus rinforzato,
   supporto contrasto elevato e riduzione del movimento.
   ============================================================ */

/* Contenuto visibile solo agli screen reader */
.ds-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link: pattern "visually-hidden-focusable" — invisibile finché
   non riceve focus. Usa clip+dimensioni 1px (più robusto di top/transform,
   non sbuca mai dal viewport e non viene letto come spazio occupato). */
.ds-skip-link {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
    background: var(--accent, #f58220);
    color: #fff;
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    text-decoration: none;
}

.ds-skip-link:focus,
.ds-skip-link:focus-visible {
    position: fixed !important;
    top: 0 !important;
    left: var(--space-3, 1rem) !important;
    width: auto !important;
    height: auto !important;
    padding: .6rem 1rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
    white-space: normal !important;
    z-index: 2000;
    border-radius: 0 0 8px 8px;
    outline: 3px solid var(--accent2, #d4af37);
    outline-offset: 2px;
}

/* Focus visibile rinforzato globale (oltre alla regola già presente) */
:focus-visible {
    outline: 2px solid var(--accent2, #d4af37);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Target tastiera per il main content */
#ds-main-content:focus {
    outline: none;
}

/* Tema attivo nello switcher: indicatore extra per contrasto elevato */
.ds-theme-option[aria-pressed="true"] {
    border-color: var(--accent2);
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

/* Supporto contrasto elevato di sistema */
@media (prefers-contrast: more) {
    :root {
        --border: #000;
    }
    .ds-btn,
    .ds-nav-tab,
    .ds-theme-option,
    .form-control,
    .ds-table th,
    .ds-table td {
        border-width: 2px !important;
    }
    :focus-visible {
        outline-width: 3px;
    }
}

/* Riduzione del movimento: disattiva animazioni e transizioni */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .ds-toast {
        animation: none !important;
    }
    .ds-skip-link {
        transition: none !important;
    }}

/* ---- DS UTILITY: token viewer (TokenInfo page) ---- */
/* Box monospace per mostrare token grezzi e JSON decodificati.
   Allineato a card/border tokens del DS, con bottone copia in alto a destra. */
.ds-token-box {
    position: relative;
    margin: var(--space-2) 0 var(--space-3);
}

.ds-token-raw {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    margin: 0;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
    max-height: 360px;
}

.ds-token-box .js-copy {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
}

.ds-btn-sm {
    padding: 4px 10px;
    font-size: var(--text-sm);
    line-height: 1.2;
}

