/* ==========================================================
   Design tokens
   ========================================================== */
:root {
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-rgb: 37, 99, 235;
    --surface: #ffffff;
    --surface-muted: #f4f6fb;
    --border-color: #e3e7ef;
    --text: #1c2333;
    --text-muted: #6b7280;

    --sidebar-bg: #12172b;
    --sidebar-bg-hover: rgba(255, 255, 255, .06);
    --sidebar-bg-active: rgba(var(--brand-rgb), .35);
    --sidebar-text: #9aa4bf;
    --sidebar-border: rgba(255, 255, 255, .08);

    --radius-sm: 8px;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, .10);

    --sidebar-width: 264px;
    --topbar-height: 68px;

    --bs-body-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bs-body-bg: var(--surface-muted);
    --bs-body-color: var(--text);
    --bs-link-color-rgb: var(--brand-rgb);
    --bs-link-hover-color-rgb: 29, 78, 216;
    --bs-border-radius: var(--radius-sm);
    --bs-border-radius-lg: var(--radius);
    --bs-border-radius-sm: 6px;
    --bs-border-color: var(--border-color);
    --bs-emphasis-color: var(--text);
}

body {
    letter-spacing: -.01em;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    font-weight: 600;
}

a {
    color: var(--brand);
    text-decoration: none;
}

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

/* ==========================================================
   Buttons
   ========================================================== */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: var(--brand-rgb);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand);
    --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand);
    --bs-btn-active-border-color: var(--brand);
    --bs-btn-focus-shadow-rgb: var(--brand-rgb);
}

.btn-outline-secondary {
    --bs-btn-color: var(--text-muted);
    --bs-btn-border-color: var(--border-color);
}

.table-actions {
    display: inline-flex;
    gap: .35rem;
}

/* ==========================================================
   Forms
   ========================================================== */
.form-control, .form-select {
    border-color: var(--border-color);
    border-radius: var(--radius-sm);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .15);
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.form-label {
    font-weight: 500;
    font-size: .8125rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

/* ==========================================================
   Badges / tabs / alerts
   ========================================================== */
.badge.bg-primary {
    background-color: var(--brand) !important;
}

.nav-tabs .nav-link {
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
}

.nav-tabs .nav-link.active {
    color: var(--brand);
    font-weight: 500;
    border-bottom-color: var(--brand);
    background: none;
}

.nav-tabs {
    border-bottom: 1px solid var(--border-color);
}

.alert {
    border: none;
    border-radius: var(--radius);
}

.alert-success {
    background: #ecfdf3;
    color: #027a48;
}

.alert-danger {
    background: #fef3f2;
    color: #b42318;
}

/* ==========================================================
   Cards / tables / modals
   ========================================================== */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-surface-white {
    background: var(--surface);
}

.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1.1rem 1.4rem;
    font-weight: 600;
}

.card-body {
    padding: 0;
}

.card-body-form {
    background: var(--surface);
    padding: 1.4rem;
}

.table {
    --bs-table-striped-bg: #f8f9fc;
    margin-bottom: 0;
}

.table thead th {
    text-transform: uppercase;
    font-size: .72rem;
    letter-spacing: .05em;
    color: var(--text-muted);
    font-weight: 600;
    background: var(--surface-muted);
    border-bottom-width: 1px;
    padding: .85rem 1.4rem;
}

.table tbody td {
    padding: .8rem 1.4rem;
    vertical-align: middle;
}

.table tbody tr:hover {
    background-color: rgba(var(--brand-rgb), .035);
}

.modal-content {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.modal-header, .modal-footer {
    border-color: var(--border-color);
}

/* ==========================================================
   App shell (sidebar + topbar layout)
   ========================================================== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    --bs-offcanvas-width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
}

.app-sidebar .offcanvas-header {
    border-bottom: 1px solid var(--sidebar-border);
}

.app-sidebar .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.4rem 1.4rem 1.1rem;
    color: #fff;
    font-weight: 600;
    font-size: 1.05rem;
}

.sidebar-brand img {
    height: 30px;
    width: auto;
}

.sidebar-nav {
    padding: .5rem .9rem;
    flex: 1;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    padding: .62rem .8rem;
    margin-bottom: .15rem;
    font-size: .9rem;
    font-weight: 500;
}

.sidebar-nav .nav-link i {
    font-size: 1.05rem;
    width: 1.1rem;
    text-align: center;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-bg-hover);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-bg-active);
    color: #fff;
}

.sidebar-nav-toggle {
    position: relative;
}

.sidebar-nav-caret {
    margin-left: auto;
    font-size: .85rem !important;
    transition: transform .2s ease;
}

.sidebar-nav-toggle[aria-expanded="true"] .sidebar-nav-caret {
    transform: rotate(180deg);
}

.sidebar-nav-sub {
    padding-left: 1.7rem;
    padding-top: .1rem;
}

.sidebar-nav-sub .nav-link {
    font-size: .85rem;
    padding-top: .5rem;
    padding-bottom: .5rem;
}

.sidebar-footer {
    padding: 1rem 1.4rem;
    border-top: 1px solid var(--sidebar-border);
    font-size: .78rem;
    color: var(--sidebar-text);
}

@media (min-width: 992px) {
    .app-sidebar.offcanvas {
        position: static;
        visibility: visible;
        transform: none;
        width: var(--sidebar-width);
        flex-shrink: 0;
        height: auto;
        box-shadow: none;
        border: none;
    }

    .app-sidebar .offcanvas-header {
        display: none;
    }
}

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

.app-topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.6rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-toggle {
    border: 1px solid var(--border-color);
    background: var(--surface);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .6rem;
    border: 1px solid var(--border-color);
    background: var(--surface);
    border-radius: 999px;
    padding: .3rem .9rem .3rem .3rem;
}

.topbar-user .user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.topbar-user::after {
    display: none;
}

.app-main {
    flex: 1;
    padding: 1.75rem;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header .eyebrow {
    display: block;
    text-transform: uppercase;
    font-size: .72rem;
    letter-spacing: .07em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: .25rem;
}

.page-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.page-header .btn {
  white-space: nowrap;
}

.stat-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 1.3rem 1.4rem;
}

.stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: rgba(var(--brand-rgb), .1);
    color: var(--brand);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-bottom: .8rem;
}

.stat-card .stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: .85rem;
}

/* ==========================================================
   Auth pages (login / reset password)
   ========================================================== */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-muted);
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.25rem 2rem;
}

.auth-card .auth-logo {
    display: block;
    margin: 0 auto 1.5rem;
    height: 36px;
}

.auth-card h4 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.badge-num-def-fisso {
    width: 65px;
}

.drag-handle {
    cursor: grab;
    color: var(--text-muted);
}

.drag-handle:active {
    cursor: grabbing;
}

tr[draggable="true"].dragging {
    opacity: .4;
}

.opzione-value-row.dragging {
    opacity: .4;
}

/* ==========================================================
   Elenco RES (vista documento)
   ========================================================== */
.res-doc {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 2.5rem 3rem;
    font-family: Georgia, 'Times New Roman', serif;
    color: var(--text);
}

.res-doc-sezione {
    padding-top: 1.75rem;
    border-top: 1px solid var(--border-color);
}

.res-doc-sezione:first-child {
    padding-top: 0;
    border-top: none;
}

.res-doc-sezione > h3 {
    font-family: 'Inter', sans-serif;
    text-transform: uppercase;
    font-size: 1.05rem;
    letter-spacing: .03em;
    color: var(--brand-dark);
    margin-bottom: 1.25rem;
}

.res-doc-sottosezione {
    margin: 1.25rem 0 1.5rem 0;
}

.res-doc-sottosezione > h4 {
    font-family: 'Inter', sans-serif;
    font-size: .95rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.res-doc-item {
    margin-bottom: 1.25rem;
}

.res-doc-item-head {
    margin-bottom: .35rem;
}

.res-doc-item-code {
    display: inline-block;
    min-width: 3.5rem;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    color: var(--brand);
    margin-right: .5rem;
}

.res-doc-item-desc {
    margin: 0;
    line-height: 1.65;
    text-align: justify;
}

/* ==========================================================
   Componenti - Documenti
   ========================================================== */
.componenti-doc-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.componenti-doc-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .75rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.componenti-doc-item.dragging {
    opacity: .4;
}

.componenti-doc-drag-handle {
    cursor: grab;
    color: var(--text-muted);
}

.componenti-doc-drag-handle:active {
    cursor: grabbing;
}

.componenti-doc-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    color: var(--text-muted);
}

.componenti-doc-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.componenti-doc-info {
    flex: 1 1 auto;
    min-width: 0;
}

.componenti-doc-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.componenti-doc-actions {
    display: flex;
    gap: .35rem;
    flex: 0 0 auto;
}