/* css/style.css */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    /* Brand Color */
    --brand-rust: #8B2E0B;
    --brand-rust-light: #A73E16;
    --brand-rust-dark: #6E2005;
    --brand-rust-translucent: rgba(139, 46, 11, 0.1);
    
    /* Transitions */
    --transition-speed: 0.3s;
    
    /* Light Theme Variables */
    --bg-app: #f4f6f8;
    --bg-surface: #ffffff;
    --bg-input: #ffffff;
    --text-main: #212529;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* Dark Theme Variables */
[data-bs-theme="dark"] {
    --bg-app: #121212;
    --bg-surface: #1e1e1e;
    --bg-input: #2a2a2a;
    --text-main: #f8f9fa;
    --text-muted: #a0a0a0;
    --border-color: #383838;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Card Styling */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition-speed), border-color var(--transition-speed), box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* Rust color utilities (badges, text) — these were referenced in the markup
   but never defined, so they silently fell back to Bootstrap defaults. */
.bg-rust { background-color: var(--brand-rust) !important; color: #fff !important; }
.text-rust { color: var(--brand-rust) !important; }

/* Custom Buttons */
.btn-rust {
    background-color: var(--brand-rust);
    color: #ffffff;
    border: none;
    transition: background-color 0.2s, transform 0.1s;
    font-weight: 500;
}

.btn-rust:hover, .btn-rust:focus {
    background-color: var(--brand-rust-light);
    color: #ffffff;
}

.btn-rust:active {
    background-color: var(--brand-rust-dark);
    transform: scale(0.98);
}

.btn-outline-rust {
    border: 2px solid var(--brand-rust);
    color: var(--brand-rust);
    background-color: transparent;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-outline-rust:hover {
    background-color: var(--brand-rust);
    color: #ffffff;
}

/* Navigation items */
.nav-tabs .nav-link {
    color: var(--text-muted);
    border: none;
    border-bottom: 3px solid transparent;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-tabs .nav-link:hover {
    color: var(--brand-rust);
    border-bottom-color: var(--border-color);
}

.nav-tabs .nav-link.active {
    color: var(--brand-rust) !important;
    background-color: transparent !important;
    border: none !important;
    border-bottom: 3px solid var(--brand-rust) !important;
    font-weight: 600;
}

/* Input Fields */
.form-control, .form-select {
    background-color: var(--bg-input);
    color: var(--text-main);
    border-color: var(--border-color);
    transition: background-color var(--transition-speed), color var(--transition-speed), border-color 0.2s;
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-input);
    color: var(--text-main);
    border-color: var(--brand-rust);
    box-shadow: 0 0 0 0.25rem var(--brand-rust-translucent);
}

/* Top Navbar Style */
.rust-header {
    background-color: var(--brand-rust);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

/* Theme Switcher Button */
.theme-toggle-btn {
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.theme-toggle-btn:hover {
    background-color: rgba(255,255,255,0.1);
}

/* Table customizations */
.table {
    color: var(--text-main);
    border-color: var(--border-color);
}

.table th {
    background-color: var(--brand-rust-translucent);
    color: var(--text-main);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

/* Access Style Grid Cards */
.menu-card {
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    height: 100%;
}

.menu-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.menu-card-icon {
    font-size: 2.5rem;
    color: var(--brand-rust);
    margin-bottom: 1rem;
}

/* Synthesis Panel style (Tables A to I) */
.synthesis-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

@media (max-width: 992px) {
    .synthesis-grid {
        grid-template-columns: 1fr;
    }
}

.synthesis-box {
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.synthesis-box-title {
    background-color: var(--brand-rust);
    color: #ffffff;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
}

.synthesis-box-body {
    padding: 1rem;
}

.synthesis-value {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    color: var(--brand-rust-light);
}

[data-bs-theme="dark"] .synthesis-value {
    color: #ff8e63;
}

/* Print View optimization */
@media print {
    body {
        background-color: #ffffff !important;
        color: #000000 !important;
    }
    
    .no-print {
        display: none !important;
    }
    
    .card, .synthesis-box {
        border: 1px solid #000000 !important;
        box-shadow: none !important;
        background-color: #ffffff !important;
    }
    
    .synthesis-box-title {
        background-color: #f0f0f0 !important;
        color: #000000 !important;
        border-bottom: 1px solid #000000 !important;
    }
    
    .synthesis-value {
        color: #000000 !important;
    }
    
    .table th {
        background-color: #f0f0f0 !important;
        color: #000000 !important;
        border-bottom: 2px solid #000000 !important;
    }
}

/* Dynamic Logo Visibility depending on theme */
.logo-dark-theme {
    display: none;
}
[data-bs-theme="dark"] .logo-light-theme {
    display: none !important;
}
[data-bs-theme="dark"] .logo-dark-theme {
    display: inline-block !important;
}

/* Footer styles */
.footer {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-color) !important;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

/* =========================================================
   APP SHELL — Sidebar layout (collapsible desktop / off-canvas mobile)
   ========================================================= */
:root {
    --sidebar-w: 264px;
    --sidebar-w-collapsed: 76px;
}

.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.app-sidebar {
    width: var(--sidebar-w);
    flex: 0 0 auto;
    color: #fff;
    background-color: var(--brand-rust-dark);
    background-image: linear-gradient(135deg, #7a2a0a 0%, #5c1f08 52%, #341103 100%);
    border-right: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 6px 0 24px rgba(20, 5, 1, 0.35);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width var(--transition-speed) ease;
    z-index: 1040;
}

.sidebar-motif {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.app-sidebar > *:not(.sidebar-motif) { position: relative; z-index: 1; }

.app-shell.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-w-collapsed);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 1.1rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
    min-height: 72px;
    position: relative;
}

.sidebar-brand img { height: 34px; width: auto; flex: none; }

/* The sidebar is always on a dark rust ground, regardless of the app's
   light/dark theme, so it always shows the white logo variant. */
.sidebar-brand .logo-light-theme { display: none !important; }
.sidebar-brand .logo-dark-theme { display: inline-block !important; }

/* Small square mark shown only when collapsed — the full wordmark is too
   wide for a 76px rail and was crowding the expand button out of view. */
.sidebar-brand .brand-mark { display: none; height: 28px; width: 28px; object-fit: contain; }

.sidebar-brand .brand-text {
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand .brand-text small {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.65);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-collapse-btn {
    margin-left: auto;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.75);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    transition: background-color 0.15s, color 0.15s, transform 0.2s;
}

.sidebar-collapse-btn:hover { background-color: rgba(255, 255, 255, 0.16); color: #fff; }

.app-shell.sidebar-collapsed .sidebar-brand .brand-text { display: none; }
.app-shell.sidebar-collapsed .sidebar-brand .logo-light-theme,
.app-shell.sidebar-collapsed .sidebar-brand .logo-dark-theme { display: none !important; }
.app-shell.sidebar-collapsed .sidebar-brand .brand-mark { display: block; }
.app-shell.sidebar-collapsed .sidebar-brand {
    flex-direction: column;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.9rem 0.4rem;
}
.app-shell.sidebar-collapsed .sidebar-collapse-btn { margin-left: 0; transform: rotate(180deg); }

.sidebar-nav {
    flex: 1 1 auto;
    padding: 0.9rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.62rem 0.8rem;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.92rem;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-link i { font-size: 1.05rem; flex: none; width: 1.3rem; text-align: center; }

.sidebar-link:hover { background-color: rgba(255, 255, 255, 0.12); color: #fff; }

.sidebar-link.active {
    background-color: #fff;
    color: var(--brand-rust-dark);
    border-left-color: transparent;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(20, 5, 1, 0.28);
}

.app-shell.sidebar-collapsed .sidebar-link { justify-content: center; padding-left: 0; padding-right: 0; border-left: none; }
.app-shell.sidebar-collapsed .sidebar-link.active { box-shadow: 0 2px 8px rgba(20, 5, 1, 0.28); }
.app-shell.sidebar-collapsed .sidebar-link span { display: none; }

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.16);
    padding: 0.9rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.5rem 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
}

.sidebar-user i { font-size: 1.2rem; flex: none; width: 1.3rem; text-align: center; }
.app-shell.sidebar-collapsed .sidebar-user span { display: none; }
.app-shell.sidebar-collapsed .sidebar-user { justify-content: center; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 1035;
}

.app-shell.sidebar-mobile-open .sidebar-backdrop { display: block; }

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

.app-topbar {
    display: none;
    align-items: center;
    gap: 0.9rem;
    padding: 0.85rem 1.1rem;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar-burger {
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-main);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.topbar-title { font-weight: 700; font-size: 1rem; color: var(--text-main); line-height: 1.2; }
.topbar-title small { display: block; font-size: 0.7rem; font-weight: 500; color: var(--text-muted); }

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 278px;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .app-shell.sidebar-mobile-open .app-sidebar { transform: translateX(0); }
    .app-shell.sidebar-collapsed .app-sidebar { width: 278px; }
    .app-shell.sidebar-collapsed .sidebar-brand .brand-text,
    .app-shell.sidebar-collapsed .sidebar-link span,
    .app-shell.sidebar-collapsed .sidebar-user span { display: block; }
    .app-shell.sidebar-collapsed .sidebar-brand {
        flex-direction: row;
        justify-content: flex-start;
        padding-left: 1.15rem;
        padding-top: 1.1rem;
        padding-bottom: 1.1rem;
    }
    .app-shell.sidebar-collapsed .sidebar-brand .logo-dark-theme { display: inline-block !important; }
    .app-shell.sidebar-collapsed .sidebar-brand .brand-mark { display: none !important; }
    .app-shell.sidebar-collapsed .sidebar-link { justify-content: flex-start; padding-left: 0.8rem; }
    .app-shell.sidebar-collapsed .sidebar-user { justify-content: flex-start; }
    .sidebar-collapse-btn { display: none; }
    .app-topbar { display: flex; }
}

@media print {
    .app-sidebar, .app-topbar, .sidebar-backdrop { display: none !important; }
    .app-main { width: 100%; }
}

/* =========================================================
   Reusable page header (used on the new standalone pages)
   ========================================================= */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--brand-rust);
    margin-bottom: 0.2rem;
}

.page-header p { color: var(--text-muted); margin-bottom: 0; }

/* Menu cards on the dashboard, now real links */
a.menu-card-link { text-decoration: none; color: inherit; display: block; height: 100%; }

.menu-card-icon {
    width: 62px;
    height: 62px;
    border-radius: 16px;
    background-color: var(--brand-rust-translucent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
    color: var(--brand-rust);
    margin: 0 auto 1rem;
    transition: transform 0.2s;
}

.menu-card:hover .menu-card-icon { transform: scale(1.06); }

/* =========================================================
   Fixes: responsive field grid (replaces the rust-label / rounded-corner
   pattern that broke when Bootstrap stacked label+input under 576px)
   ========================================================= */
.field-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.1rem 1.5rem;
}

@media (max-width: 767.98px) {
    .field-grid { grid-template-columns: 1fr; gap: 0.9rem; }
}

.field-grid .field-full { grid-column: 1 / -1; }

.field-label {
    display: block;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.045em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

/* =========================================================
   Synthesis panel — tablet breakpoint + numeric alignment polish
   ========================================================= */
.synthesis-value, .synthesis-box .small { font-variant-numeric: tabular-nums; }

.synthesis-box { transition: transform 0.2s, box-shadow 0.2s; }
.synthesis-box:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

@media (max-width: 991.98px) and (min-width: 768px) {
    .synthesis-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Searchable-select dropdown (Anagrafica / Intestazione fields) */
.searchable-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1070;
    max-height: 230px;
    overflow-y: auto;
    margin-top: 2px;
    box-shadow: var(--shadow-md);
    border-radius: 8px;
    border-color: var(--border-color) !important;
}

.searchable-dropdown .list-group-item {
    cursor: pointer;
    font-size: 0.88rem;
    padding: 0.5rem 0.9rem;
    background-color: var(--bg-surface);
    color: var(--text-main);
    border-color: var(--border-color);
}

.searchable-dropdown .list-group-item.active-highlight,
.searchable-dropdown .list-group-item:hover {
    background-color: #fbe8e1;
    color: #8b2e0b;
}

/* Invoice status pills (clearer than a bare Sì/No badge) */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.76rem;
    font-weight: 700;
    padding: 0.28rem 0.65rem;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.status-pill.is-paid { background-color: rgba(25, 135, 84, 0.12); color: #157347; }
.status-pill.is-due { background-color: rgba(220, 53, 69, 0.12); color: #b02a37; }
[data-bs-theme="dark"] .status-pill.is-paid { background-color: rgba(92, 186, 143, 0.16); color: #5cba8f; }
[data-bs-theme="dark"] .status-pill.is-due { background-color: rgba(226, 105, 90, 0.18); color: #e2695a; }

/* DataTables (anagrafiche/cantieri/archiviati/log) — accent + black/white only,
   overriding Bootstrap's default blue pagination and DataTables' default
   grey sort arrows. Text/surfaces follow the existing black<->white theme
   variables so this still adapts to light/dark mode. */
:root { --dt-accent: #bd6f47; }

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info {
    color: var(--text-main);
}
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    background-color: var(--bg-input) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

table.dataTable thead th {
    color: var(--text-main);
}
table.dataTable thead .sorting:before,
table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:before,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:before,
table.dataTable thead .sorting_desc:after {
    color: var(--dt-accent);
}
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
    color: var(--dt-accent);
}

/* Bootstrap 5.3's pagination component is entirely variable-driven
   (.page-link reads --bs-pagination-bg/--bs-pagination-color etc.) — setting
   background-color/color directly on .page-link only won the `color`
   half of the cascade in testing (Bootstrap's own --bs-pagination-bg kept
   winning for background despite lower specificity, likely due to how the
   CDN stylesheet registers custom properties). Overriding Bootstrap's own
   variables at the .pagination scope sidesteps that entirely: every state
   Bootstrap defines (base/hover/focus/active/disabled) now resolves through
   these instead of its defaults, in one place. */
.dataTables_wrapper .pagination {
    --bs-pagination-color: var(--dt-accent);
    --bs-pagination-bg: var(--bg-surface);
    --bs-pagination-border-color: var(--border-color);
    --bs-pagination-hover-color: #ffffff;
    --bs-pagination-hover-bg: var(--dt-accent);
    --bs-pagination-hover-border-color: var(--dt-accent);
    --bs-pagination-focus-color: #ffffff;
    --bs-pagination-focus-bg: var(--dt-accent);
    --bs-pagination-focus-box-shadow: none;
    --bs-pagination-active-color: #ffffff;
    --bs-pagination-active-bg: var(--dt-accent);
    --bs-pagination-active-border-color: var(--dt-accent);
    --bs-pagination-disabled-color: var(--text-muted);
    --bs-pagination-disabled-bg: var(--bg-surface);
    --bs-pagination-disabled-border-color: var(--border-color);
}

