/* EnterpriseClaw - global styles (palette in wwwroot/js/tailwind-config.js) */

/*
 * Scala tipografica UI (Plus Jakarta Sans, vedi layout):
 * - corpo: 1rem / leading-relaxed (~1.625) su body
 * - intro lunghi: .ec-intro-body (1rem, 1.65, max 65ch)
 * - etichette sezione: .ec-section-label / .ec-kicker (12px, maiuscole, tracking)
 * - titolo pagina: .ec-page-title (fluid clamp)
 */
:root {
    --ec-shell-bg: #f1f5f9;
    --ec-shell-bg-mid: #f8fafc;
    /* Allineati a tailwind-config.js (navy / primary sidebar attiva) */
    --ec-navy-900: #132843;
    --ec-navy-800: #1c3658;
    --ec-sidebar-active-bg: #dbeafe;
    --ec-sidebar-active-fg: #1e3a8a;
    --ec-sidebar-active-icon: #1d4ed8;
}

.ec-skip-link {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    z-index: 10060;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    background-color: #1e3a8a;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

.ec-skip-link:focus {
    left: 0.75rem;
    top: 0.75rem;
    width: auto;
    height: auto;
    overflow: visible;
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

html {
    font-size: 100%;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    text-size-adjust: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Paragrafi intro / testi guida: misura lettura comoda (≈45–75 caratteri) */
.ec-intro-body {
    font-size: 1rem;
    line-height: 1.65;
    font-weight: 400;
    color: #334155;
    max-width: 65ch;
}

/* Sfondo area applicazione: gradiente + alone primary in alto a destra (brand, no “AI slop”) */
body.ec-app-shell {
    background-color: var(--ec-shell-bg);
    background-image:
        radial-gradient(ellipse 115% 70% at 100% -15%, rgba(30, 58, 138, 0.07) 0%, transparent 52%),
        linear-gradient(165deg, var(--ec-shell-bg) 0%, var(--ec-shell-bg-mid) 44%, #f8fafc 100%);
    background-attachment: fixed;
}

body.ec-public-shell {
    background-color: #eef2f7;
    background-image:
        radial-gradient(ellipse 100% 60% at 100% 0%, rgba(30, 58, 138, 0.055) 0%, transparent 50%),
        linear-gradient(180deg, #eef2f7 0%, #f8fafc 32%);
    background-attachment: fixed;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #bfdbfe; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #93c5fd; }

/*
 * Sidebar: sfondo navy-900 (#132843) - vedi tailwind-config.js.
 * Separatori interni: white/10. Superfici “in rilievo”: white/10–15.
 */
#sidebar {
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.2s ease-out;
    background-color: var(--ec-navy-900);
}

/* Drawer mobile: sidebar sopra il contenuto */
@media (max-width: 767.98px) {
    #sidebar.ec-sidebar-shell {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        max-width: min(16rem, calc(100vw - 2rem));
        transform: translateX(-100%);
    }

    body.ec-sidebar-open #sidebar.ec-sidebar-shell {
        transform: translateX(0);
    }
}

@media (min-width: 768px) {
    #sidebar.ec-sidebar-shell {
        position: relative;
        max-width: none;
        transform: none !important;
    }
}

.ec-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgb(15 23 42 / 0.45);
}

.ec-sidebar-backdrop.ec-sidebar-backdrop--visible {
    display: block;
}

@media (min-width: 768px) {
    .ec-sidebar-backdrop {
        display: none !important;
    }
}

.kanban-card { cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.55; }

/* Kanban: disclosure “sposta” senza marker nativo ingombrante */
.kanban-move-details > summary {
    list-style: none;
}
.kanban-move-details > summary::-webkit-details-marker {
    display: none;
}

#toast-container {
    pointer-events: none;
    /* iOS home indicator / safe area: evita toast tagliati in basso */
    bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
    right: max(1.25rem, env(safe-area-inset-right, 0px));
}
#toast-container > * { pointer-events: auto; }
#toast-container > * { max-width: min(100vw - 2rem, 28rem); }

/* Area principale: momentum su iOS; safe area orizzontale su notch / landscape */
body.ec-app-shell main#main-content.ec-main-content {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}

@media (min-width: 640px) {
    body.ec-app-shell main#main-content.ec-main-content {
        padding-left: max(1.125rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.125rem, env(safe-area-inset-right, 0px));
    }
}

@media (min-width: 1024px) {
    body.ec-app-shell main#main-content.ec-main-content {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

body.ec-public-shell main#main-content.ec-main-content {
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}

@media (min-width: 640px) {
    body.ec-public-shell main#main-content.ec-main-content {
        padding-left: max(1.125rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.125rem, env(safe-area-inset-right, 0px));
    }
}

@media (min-width: 1024px) {
    body.ec-public-shell main#main-content.ec-main-content {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

/* Richiede viewport-fit=cover: header/footer rispettano notch e home indicator */
body.ec-app-shell header.ec-app-header {
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}

@media (min-width: 640px) {
    body.ec-app-shell header.ec-app-header {
        padding-left: max(1.125rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.125rem, env(safe-area-inset-right, 0px));
    }
}

@media (min-width: 1024px) {
    body.ec-app-shell header.ec-app-header {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

body.ec-app-shell footer.ec-app-footer {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
}

@media (min-width: 640px) {
    body.ec-app-shell footer.ec-app-footer {
        padding-left: max(1.125rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.125rem, env(safe-area-inset-right, 0px));
    }
}

@media (min-width: 1024px) {
    body.ec-app-shell footer.ec-app-footer {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

body.ec-public-shell header.ec-app-header {
    padding-top: max(0px, env(safe-area-inset-top, 0px));
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

@media (min-width: 640px) {
    body.ec-public-shell header.ec-app-header {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

body.ec-public-shell footer.ec-app-footer {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

@media (min-width: 640px) {
    body.ec-public-shell footer.ec-app-footer {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

/* Wizard setup: stessi inset orizzontali del portale pubblico; bottom + home indicator */
body.ec-public-shell .ec-setup-outer {
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    padding-bottom: calc(2.5rem + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 640px) {
    body.ec-public-shell .ec-setup-outer {
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
        padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
    }
}

/* Testo lungo, URL, CJK, emoji: evita overflow in flex/grid */
.ec-text-break {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/*
 * Voce attiva sidebar: allineata a docs/design/color-palette.md
 * (primary-100 su navy, testo primary-900, icone primary-700).
 */
#sidebar .nav-item.active,
#sidebar .nav-item.active:hover {
    background-color: var(--ec-sidebar-active-bg);
    color: var(--ec-sidebar-active-fg);
    font-weight: 600;
}

#sidebar .nav-item.active svg,
#sidebar .nav-item.active:hover svg {
    color: var(--ec-sidebar-active-icon);
}

/* Focus visibile coerente (link e controlli custom) */
#sidebar a:focus-visible,
.ec-focus-ring:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    #sidebar {
        transition: none;
    }

    .ec-surface-card-interactive {
        transition: none;
    }

    .ec-busy-overlay__spinner,
    .ec-busy-overlay__spinner--sm {
        animation: none;
        border-color: rgb(226 232 240);
        border-top-color: #1e3a8a;
        opacity: 0.85;
    }
}

/* ── Pattern UI portale (pannelli, etichette, pulsanti) ── */
.ec-kicker {
    font-size: 0.75rem;
    font-weight: 700;
    color: #1e3a8a;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    line-height: 1.35;
}

.ec-section-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    line-height: 1.35;
}

/* Titoli sezione / hero interni (accoppiati a ec-intro-rail dove serve) */
.ec-page-title {
    font-size: clamp(1.25rem, 2.2vw, 1.65rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.22;
    color: #0f172a;
}

/* Colonna editoriale: barra primary come ancora visiva */
.ec-intro-rail {
    padding-left: 1rem;
    margin-left: 0;
    border-left: 4px solid #1e3a8a;
}

@media (max-width: 639.98px) {
    .ec-intro-rail {
        padding-left: 0.75rem;
        border-left-width: 3px;
    }
}

/* Home: blocco benvenuto “hero” interno */
.ec-home-hero {
    border-radius: 1rem;
    border: 1px solid rgba(30, 58, 138, 0.1);
    background-color: #fff;
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.05),
        0 14px 36px -10px rgb(30 58 138 / 0.11);
    padding: 1.5rem 1.5rem 1.5rem 1.35rem;
    border-left: 4px solid #1e3a8a;
}

@media (min-width: 640px) {
    .ec-home-hero {
        padding: 1.75rem 1.75rem 1.75rem 1.5rem;
    }
}

/* Tile dashboard (moduli / link): ombra e hover più decisi, sempre nel primary */
.ec-surface-card-interactive {
    border-radius: 0.75rem;
    border: 1px solid rgba(226, 232, 239, 0.95);
    background-color: #fff;
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.04),
        0 8px 20px -8px rgb(30 58 138 / 0.08);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.ec-surface-card-interactive:hover {
    border-color: rgba(59, 130, 246, 0.42);
    background-color: rgba(239, 246, 255, 0.45);
    box-shadow:
        0 2px 4px rgb(30 58 138 / 0.06),
        0 16px 32px -10px rgb(30 58 138 / 0.14);
}

.ec-panel {
    border-radius: 1rem;
    border: 1px solid rgba(30, 58, 138, 0.08);
    background-color: #fff;
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.045),
        0 10px 28px -8px rgb(30 58 138 / 0.09);
}

.ec-panel__head {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(226, 232, 239, 0.95);
    background: linear-gradient(180deg, rgba(239, 246, 255, 0.55) 0%, rgba(248, 250, 252, 0.96) 100%);
}

.ec-stat-grid {
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid rgba(30, 58, 138, 0.08);
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.045),
        0 10px 28px -8px rgb(30 58 138 / 0.09);
}

.ec-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25;
    border-radius: 0.75rem;
    background-color: #1e3a8a;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.14),
        0 4px 12px -2px rgb(30 58 138 / 0.22);
}

.ec-btn-primary:hover {
    background-color: #172554;
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.18),
        0 6px 16px -2px rgb(30 58 138 / 0.28);
}

.ec-btn-primary:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.ec-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ec-btn-primary--sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0.5rem;
    box-shadow:
        0 1px 2px rgb(30 58 138 / 0.12),
        0 2px 8px -2px rgb(30 58 138 / 0.16);
}

/* Secondario: bordo neutro, stesso raggio “pill” delle CTA principali */
.ec-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    border-radius: 0.75rem;
    border: 1px solid rgba(226, 232, 239, 0.9);
    background-color: #fff;
    color: #1e293b;
    cursor: pointer;
    box-shadow: 0 1px 2px 0 rgb(15 23 42 / 0.04);
    text-decoration: none;
}

.ec-btn-secondary:hover {
    background-color: #f8fafc;
}

.ec-btn-secondary:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.ec-btn-secondary--sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0.5rem;
    box-shadow: none;
}

/* Link/ghost azione tabella o secondaria (testo primary) */
.ec-link-action {
    font-size: 0.75rem;
    font-weight: 600;
    color: #1e40af;
    background: none;
    border: none;
    padding: 0.125rem 0.125rem;
    cursor: pointer;
    border-radius: 0.375rem;
    text-decoration: none;
    display: inline;
}

.ec-link-action:hover {
    color: #172554;
}

.ec-link-action--md {
    font-size: 0.875rem;
}

button.ec-link-action {
    display: inline-flex;
    align-items: center;
}

a.ec-link-action {
    display: inline-flex;
    align-items: center;
}

.ec-link-action:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Validazione server MVC (input / select con errore in ModelState) */
.input-validation-error {
    border-color: rgb(220 38 38 / 0.85) !important;
    box-shadow: 0 0 0 1px rgb(220 38 38 / 0.25);
}

/* Fallback: se una vista usa ancora .ec-input - stesso aspetto di AppPageChrome.FieldBase */
.ec-input {
    width: 100%;
    border-radius: 0.5rem;
    border: 1px solid rgb(226 232 240 / 0.9);
    background-color: #fff;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: #0f172a;
}
.ec-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px #2563eb;
    border-color: #1d4ed8;
}

/* ── Overlay “operazione in corso” (submit form) ───────────────────────── */
.ec-busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.ec-busy-overlay[hidden] {
    display: none !important;
}

.ec-busy-overlay__backdrop {
    position: absolute;
    inset: 0;
    background: rgb(15 23 42 / 0.4);
}

.ec-busy-overlay__panel {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 2rem;
    border-radius: 0.75rem;
    background: rgb(255 255 255 / 0.98);
    border: 1px solid rgb(226 232 240 / 0.95);
    box-shadow: 0 12px 40px rgb(15 23 42 / 0.12);
}

.ec-busy-overlay__spinner {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    border: 3px solid rgb(226 232 240);
    border-top-color: #1e3a8a;
    animation: ec-busy-spin 0.65s linear infinite;
}

/* Stessa rotella, formato compatto per pulsanti / controlli inline */
.ec-busy-overlay__spinner--sm {
    width: 1.125rem;
    height: 1.125rem;
    border-width: 2px;
}

.ec-busy-overlay__label {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #334155;
    text-align: center;
    max-width: 16rem;
    line-height: 1.4;
}

@keyframes ec-busy-spin {
    to {
        transform: rotate(360deg);
    }
}
