/* assets/css/style.css */

:root {
    /* Tema Chiaro (default) */
    --bg-primary: #f5f7fd;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-card-light: #eef1fb;
    --border-color: #dde5f4;
    --border-color-strong: #c3d0ea;

    --text-primary: #10182b;
    --text-secondary: #4e5771;
    --text-muted: #8891a8;

    --brand-primary: #145a97;
    --brand-hover: #0f4879;
    --brand-accent: #0ea5e9;
    --brand-vivid: #1f7ae0;
    --brand-cyan: #00b8d9;

    --success: #0f9d70;
    --warning: #b45309;
    --danger: #dc2626;
    --info: #0891b2;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px 0 rgba(16, 24, 43, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(16, 24, 43, 0.07), 0 2px 4px -1px rgba(16, 24, 43, 0.04);
    --shadow-lg: 0 10px 25px -5px rgba(16, 24, 43, 0.12), 0 8px 10px -6px rgba(16, 24, 43, 0.06);

    /* Pannelli "incassati" usati per box informativi dentro le card */
    --bg-inset-soft: rgba(37, 99, 235, 0.045);
    --bg-inset: rgba(37, 99, 235, 0.07);
    --bg-inset-strong: rgba(37, 99, 235, 0.1);
    --gradient-panel: linear-gradient(135deg, #eef2fd, #f8fafc);

    /* Chrome: sidebar e barra mobile restano sempre scure, indipendenti dal tema del contenuto */
    --chrome-bg: #145a97;
    --chrome-bg-2: #0b3a63;
    --chrome-border: rgba(255, 255, 255, 0.14);
    --chrome-text: #cfe0f2;
    --chrome-text-dim: #7fa3c4;
    --chrome-text-strong: #ffffff;
    --chrome-accent: #1f7ae0;
    --chrome-accent-strong: #00b8d9;

    --sidebar-width: 264px;
}

/* Tema Scuro (attivabile dall'utente) */
[data-theme="dark"] {
    --bg-primary: #0b0e1a;
    --bg-surface: #131a2e;
    --bg-card: #131a2e;
    --bg-card-light: #1a2340;
    --border-color: #212a48;
    --border-color-strong: #2c3860;

    --text-primary: #eef1fb;
    --text-secondary: #a3aed0;
    --text-muted: #656f92;

    --brand-primary: #60a5fa;
    --brand-hover: #93c5fd;
    --brand-accent: #38bdf8;
    --brand-vivid: #3b82f6;
    --brand-cyan: #22d3ee;

    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --info: #38bdf8;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.35), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);

    --bg-inset-soft: rgba(255, 255, 255, 0.035);
    --bg-inset: rgba(255, 255, 255, 0.055);
    --bg-inset-strong: rgba(255, 255, 255, 0.08);
    --gradient-panel: linear-gradient(135deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.92));
}

body,
.card,
.form-control,
.btn,
.badge,
.alert,
.table th,
.table td,
.login-card,
.form-section,
.form-check {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

a {
    color: var(--brand-primary);
}

a:hover {
    color: var(--brand-hover);
}

/* Titoli: un serif per l'impronta "documento ufficiale" del sistema di compliance */
h1, h2, h3, h4,
.card-title,
.form-section-title,
.login-brand h1 {
    font-family: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
    letter-spacing: -0.01em;
}

/* Header / Navbar (legacy, non più usata nelle pagine autenticate ma mantenuta per compatibilità) */
.navbar {
    background-color: var(--chrome-bg);
    border-bottom: 1px solid var(--chrome-border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--chrome-text-strong);
    text-decoration: none;
}

.navbar-brand span {
    background: linear-gradient(135deg, var(--chrome-accent), var(--chrome-accent-strong));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-user-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.nav-user-info strong {
    color: var(--text-primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-vivid), var(--brand-cyan));
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(31, 122, 224, 0.35);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(31, 122, 224, 0.45);
    opacity: 0.95;
}

.btn-secondary {
    background-color: var(--bg-inset-soft);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--bg-inset);
    color: var(--text-primary);
}

.btn-danger {
    background-color: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.3);
    color: #dc2626;
}

.btn-danger:hover {
    background-color: rgba(220, 38, 38, 0.18);
}

[data-theme="dark"] .btn-danger {
    color: #fca5a5;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.825rem;
    border-radius: var(--radius-sm);
}

/* Layout container: usa tutta la larghezza disponibile accanto alla sidebar */
.container {
    max-width: none;
    width: 100%;
    margin: 2rem 0;
    padding: 0 3rem;
    flex: 1;
}

/* Cards & Containers */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    max-width: 100%;
}

.card-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card-description {
    font-size: 0.925rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Login box */
.login-wrapper {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, rgba(37, 99, 235, 0.12), transparent 40%),
                radial-gradient(circle at bottom left, rgba(96, 165, 250, 0.12), transparent 40%);
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 440px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

/* Sul login il toggle tema vive sullo sfondo di pagina (chiaro/scuro), non sulla sidebar scura */
.login-wrapper .theme-toggle {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    width: auto;
    color: var(--text-primary);
    border-color: var(--border-color-strong);
    background-color: var(--bg-inset-soft);
}

.login-wrapper .theme-toggle:hover {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-brand h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.login-brand p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Form controls */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color-strong);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--bg-inset-strong);
}

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
    padding: 0.65rem 0.9rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.form-check:hover {
    border-color: var(--border-color-strong);
    background-color: var(--bg-inset-soft);
}

.form-check-input {
    width: 1.15rem;
    height: 1.15rem;
    margin-top: 0.15rem;
    accent-color: var(--brand-vivid);
    cursor: pointer;
    flex-shrink: 0;
}

.form-check-label {
    font-size: 0.925rem;
    color: var(--text-primary);
    cursor: pointer;
}

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-danger {
    background-color: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.25);
    color: var(--danger);
}

.alert-success {
    background-color: rgba(15, 157, 112, 0.08);
    border: 1px solid rgba(15, 157, 112, 0.25);
    color: var(--success);
}

.alert-info {
    background-color: rgba(8, 145, 178, 0.08);
    border: 1px solid rgba(8, 145, 178, 0.25);
    color: var(--info);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    text-align: left;
}

.table th, .table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.table th {
    background-color: var(--bg-inset-soft);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.table tr:hover td {
    background-color: var(--bg-inset-soft);
}

.table-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    min-width: 148px;
}

.table-actions .btn {
    white-space: nowrap;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
}

.badge-danger {
    background-color: rgba(220, 38, 38, 0.14);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.4);
}

.badge-warning {
    background-color: rgba(180, 83, 9, 0.14);
    color: var(--warning);
    border: 1px solid rgba(180, 83, 9, 0.4);
}

.badge-info {
    background-color: rgba(31, 122, 224, 0.14);
    color: var(--brand-vivid);
    border: 1px solid rgba(31, 122, 224, 0.4);
}

.badge-success {
    background-color: rgba(15, 157, 112, 0.14);
    color: var(--success);
    border: 1px solid rgba(15, 157, 112, 0.4);
}

/* Questionnaire Form Sections */
.form-section {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.form-section-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--brand-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-section-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-family: 'Inter', system-ui, sans-serif;
}

.input-nested {
    margin-left: 1.75rem;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

/* Footer */
.footer {
    border-top: 1px solid var(--border-color);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: auto;
}

/* ==========================================================================
   App Shell: Sidebar laterale (sempre scura) + contenuto (segue il tema)
   ========================================================================== */

.app-shell {
    display: flex;
    align-items: stretch;
    flex: 1;
    width: 100%;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: linear-gradient(195deg, var(--chrome-bg) 0%, var(--chrome-bg-2) 78%);
    border-right: 1px solid var(--chrome-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    color: var(--chrome-text);
    z-index: 200;
    overflow: hidden;
}

/* Onde decorative sul fondo della sidebar */
.sidebar-waves {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 340px;
    pointer-events: none;
    opacity: 0.9;
}

.sidebar-waves svg {
    width: 100%;
    height: 100%;
    display: block;
}

.sidebar-inner {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.4rem 1.25rem 2.1rem;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--brand-primary);
    text-decoration: none;
    background-color: #ffffff;
    position: relative;
    z-index: 3;
}

.sidebar-brand-wave {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    line-height: 0;
}

.sidebar-brand-wave svg {
    display: block;
    width: 100%;
    height: 34px;
}

.sidebar-brand span {
    background: linear-gradient(135deg, var(--chrome-accent), var(--chrome-accent-strong));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.25;
    font-family: Georgia, "Iowan Old Style", serif;
}

.sidebar-brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--chrome-accent), var(--chrome-accent-strong));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand-mark svg {
    width: 17px;
    height: 17px;
    stroke: #ffffff;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 0.75rem;
    flex: 1;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    border-radius: 999px;
    color: var(--chrome-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--chrome-text-strong);
}

.sidebar-link.active {
    background: linear-gradient(135deg, var(--chrome-accent), var(--chrome-accent-strong));
    color: #ffffff;
    box-shadow: 0 6px 16px -4px rgba(31, 122, 224, 0.55);
}

.sidebar-section-label {
    padding: 0.85rem 0.85rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--chrome-text-dim);
}

.sidebar-footer {
    border-top: 1px solid var(--chrome-border);
    padding: 1rem 0.9rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.sidebar-user {
    font-size: 0.8rem;
    color: var(--chrome-text-dim);
    line-height: 1.4;
}

.sidebar-user strong {
    color: var(--chrome-text-strong);
    display: block;
    font-size: 0.9rem;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.55rem;
    width: 100%;
    padding: 0.55rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--chrome-text-strong);
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    flex-shrink: 0;
}

.theme-toggle:hover {
    border-color: var(--chrome-accent);
    color: var(--chrome-accent-strong);
}

.logout-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(220, 38, 38, 0.25);
    background-color: rgba(220, 38, 38, 0.08);
    color: #fca5a5;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

.logout-link svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    flex-shrink: 0;
}

.logout-link:hover {
    background-color: rgba(220, 38, 38, 0.15);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Barra superiore mobile: stessa identita' scura della sidebar, nascosta su desktop */
.mobile-topbar {
    display: none;
    align-items: center;
    gap: 0.85rem;
    padding: 0.9rem 1.25rem;
    background: linear-gradient(185deg, var(--chrome-bg), var(--chrome-bg-2));
    border-bottom: 1px solid var(--chrome-border);
    position: sticky;
    top: 0;
    z-index: 150;
}

.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: transparent;
    color: var(--chrome-text-strong);
    cursor: pointer;
    flex-shrink: 0;
}

.hamburger-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.mobile-topbar-brand {
    font-weight: 700;
    font-family: Georgia, "Iowan Old Style", serif;
    color: var(--chrome-text-strong);
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(5, 8, 16, 0.55);
    z-index: 190;
}

/* ==========================================================================
   Responsive: tablet / mobile
   ========================================================================== */

@media (max-width: 880px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        transition: transform 0.25s ease;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-overlay.is-open {
        display: block;
    }

    .mobile-topbar {
        display: flex;
    }

    .container {
        margin: 1.25rem 0;
        padding: 0 1.25rem;
    }

    .card {
        padding: 1.25rem;
    }

    .card-header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .navbar {
        padding: 1rem 1.25rem;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .nav-links {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .nav-user-info {
        display: none;
    }

    .login-card {
        padding: 1.75rem 1.5rem;
    }
}

@media (max-width: 560px) {
    .btn {
        padding: 0.6rem 1rem;
    }

    .card-title {
        font-size: 1.15rem;
    }

    .table th, .table td {
        padding: 0.6rem 0.7rem;
        font-size: 0.82rem;
    }

    .form-section {
        padding: 1.1rem;
    }
}
