﻿:root {
    --bg: #f5f8fb;
    --card: #ffffff;
    --line: #dfe6ee;
    --text: #1d2a3a;
    --muted: #5f6f82;
    --primary: #0f6cbd;
    --warn: #b75d00;
    --ok: #207245;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
    font-family: "Segoe UI", Tahoma, sans-serif;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

form {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.dev-banner {
    position: sticky;
    top: 0;
    z-index: 120;
    width: 100%;
    padding: 8px 28px;
    background: #b42318;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0;
    border-bottom: 1px solid #7f1d1d;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(280px, 370px) minmax(245px, auto) minmax(0, 1fr);
    align-items: center;
    gap: 18px;
    min-height: 98px;
    padding: 18px 28px;
    border-bottom: 1px solid #de8500;
    background: #fa9708;
    position: sticky;
    top: 0;
    z-index: 100;
}

.dev-banner + .topbar {
    top: 31px;
}

.brand {
    display: flex;
    align-items: center;
}

.brand-logo {
    height: 58px;
    width: auto;
    display: block;
}

.brand-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1;
}

.brand-claim {
    margin-top: 4px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0;
    white-space: nowrap;
}

.main-nav {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: visible;
}

.topbar .main-nav .nav-list {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
    margin: 0;
    padding: 0;
    list-style: none !important;
    white-space: nowrap;
}

.topbar .main-nav .nav-list,
.topbar .main-nav .nav-list > li,
.topbar .main-nav .nav-submenu,
.topbar .main-nav .nav-submenu > li {
    list-style: none !important;
    list-style-type: none !important;
}

.topbar .main-nav .nav-list > li {
    position: relative;
    margin: 0;
    padding: 0;
}

.topbar .main-nav .nav-list > li::marker,
.topbar .main-nav .nav-submenu > li::marker {
    content: "";
}

.session-box {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.session-user {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
    white-space: normal;
    max-width: 150px;
}

.session-link {
    text-decoration: none;
    color: #fff;
    font-size: 12px;
    padding: 8px 11px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.55);
}

.session-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

.main-nav a {
    text-decoration: none;
    color: #fff;
    font-size: 14px;
    padding: 6px 7px;
    border-radius: 999px;
}

.main-nav a:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-alert {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 999px;
    background: #b42318;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 18px;
    vertical-align: super;
}

.main-nav a.sim-link {
    border: 1px solid rgba(255, 255, 255, 0.55);
    color: #fff;
}

.main-nav a.sim-link:hover {
    background: rgba(255, 255, 255, 0.28);
}

.nav-has-submenu > a::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-left: 8px;
    border-right: 2px solid rgba(255, 255, 255, 0.92);
    border-bottom: 2px solid rgba(255, 255, 255, 0.92);
    transform: translateY(-2px) rotate(45deg);
}

.topbar .main-nav .nav-has-submenu > .nav-submenu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 150;
    min-width: 230px;
    padding: 8px;
    gap: 0;
    margin: 0;
    list-style: none !important;
    background: #fa9708;
    border: 1px solid rgba(255, 255, 255, 0.42);
    box-shadow: 0 12px 26px rgba(10, 32, 48, 0.22);
}

.topbar .main-nav .nav-has-submenu:hover > .nav-submenu,
.topbar .main-nav .nav-has-submenu:focus-within > .nav-submenu {
    display: block;
}

.topbar .main-nav .nav-has-submenu > .nav-submenu li {
    display: block;
}

.topbar .main-nav .nav-has-submenu > .nav-submenu a {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    white-space: nowrap;
}

.main {
    flex: 1 0 auto;
    padding: 20px 24px 28px;
}

.site-footer {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
    align-items: center;
    gap: 18px;
    padding: 8px 18px;
    border-top: 1px solid #d7e0ea;
    background: #f5f8fb;
    color: #52677c;
}

.footer-copyright {
    justify-self: start;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.footer-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.footer-links a {
    color: #31516f;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
}

.footer-links a:hover {
    color: #0f6cbd;
    text-decoration: underline;
}

.footer-brand {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.footer-brand a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 18px;
}

.footer-logo-pill {
    padding: 0;
    border-radius: 0;
    background: #fff;
}

.footer-logo-pill img {
    display: block;
    max-height: 16px;
    width: auto;
}

.footer-logo-dark img {
    display: block;
    max-height: 16px;
    width: auto;
}

.page-shell {
    display: grid;
    gap: 16px;
}

.page-hero {
    min-height: 238px;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(520px, 0.65fr);
    gap: 18px;
    align-items: stretch;
    padding: 28px;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(110deg, #123d5f, #2f786a);
    box-shadow: 0 18px 42px rgba(20, 42, 65, 0.16);
    overflow: hidden;
}

.page-hero h1 {
    margin: 0 0 14px;
    font-size: 40px;
    line-height: 1.08;
}

.page-hero p {
    margin: 0;
    max-width: 1040px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 20px;
    line-height: 1.42;
}

.page-hero-panel {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
}

.page-hero-panel img {
    width: 212px;
    max-width: 100%;
    padding: 8px;
    background: #fff;
    border-radius: 8px;
}

.page-hero-kicker {
    font-size: 16px;
    opacity: 0.82;
}

.page-hero-title {
    font-size: 30px;
    font-weight: 750;
    line-height: 1.12;
}

.page-note {
    border-left: 4px solid #0f6cbd;
    background: #f4f9ff;
    padding: 12px;
    border-radius: 8px;
    color: #17324e;
    line-height: 1.45;
}

.section-jumpbar,
.org-tabs {
    position: sticky;
    top: 88px;
    z-index: 20;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 8px 22px rgba(20, 42, 65, 0.08);
}

.section-jumpbar a,
.org-tab {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid #c9d8e8;
    border-radius: 6px;
    background: #f7fbff;
    color: #073c72;
    font-weight: 650;
    text-decoration: none;
    font: inherit;
    cursor: pointer;
}

.section-jumpbar a:hover,
.org-tab:hover {
    background: #e8f3ff;
    border-color: #8dbbe8;
}

.org-tab.is-active {
    background: #0f6cbd;
    border-color: #0f6cbd;
    color: #fff;
}

.org-tab-panel[hidden] {
    display: none;
}

.section-anchor {
    scroll-margin-top: 154px;
}

h1 {
    margin: 0 0 10px;
    font-size: 24px;
}

h2 {
    margin: 24px 0 10px;
    font-size: 18px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 14px;
}

.legal-policy {
    max-width: 980px;
    line-height: 1.6;
}

.legal-policy h3 {
    margin: 22px 0 8px;
    font-size: 17px;
    color: var(--text);
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.kpi {
    min-width: 180px;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
}

.kpi .value {
    font-size: 24px;
    font-weight: 700;
}

.kpi .label {
    color: var(--muted);
    font-size: 12px;
}

.grid {
    width: 100%;
    border-collapse: collapse;
}

.grid th,
.grid td {
    border: 1px solid var(--line);
    padding: 8px;
    font-size: 13px;
    text-align: left;
}

.grid th {
    background: #f0f5fa;
}

.grid tr:nth-child(even) td {
    background: #fbfdff;
}

.payable-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 8px;
    border: 1px solid #b8c7d7;
    border-radius: 50%;
    background: #ffffff;
    color: var(--brand);
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.payable-detail-row > td {
    background: #f8fbff !important;
    padding: 10px 14px;
}

.payable-lines-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.payable-lines-table th,
.payable-lines-table td {
    border: 1px solid var(--line);
    padding: 7px 8px;
    font-size: 12px;
}

.payable-lines-table th {
    background: #eef5fb;
}

.empty-state {
    padding: 12px;
    border: 1px solid var(--line);
    border-top: 0;
    background: #fbfdff;
    color: var(--muted);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 210px;
}

.field input,
.field select,
.field textarea {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px;
    font-size: 13px;
    background: #fff;
}

.field textarea {
    min-height: 80px;
}

.field-help {
    max-width: 300px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.tolerance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 10px;
    align-items: stretch;
}

.tolerance-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 132px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdff;
}

.tolerance-card label {
    font-weight: 700;
    color: var(--ink);
}

.tolerance-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tolerance-input input {
    width: 96px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px;
    font-size: 13px;
    background: #fff;
}

.tolerance-input span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.tolerance-card p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.tolerance-check label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tolerance-check input {
    margin: 0;
}

.tolerance-actions {
    display: flex;
    align-items: end;
    min-height: 132px;
}

.btn {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-warn {
    background: var(--warn);
    border-color: var(--warn);
    color: #fff;
}

.state {
    font-weight: 600;
}

.state-APPROVED,
.state-MATCHED,
.state-RESOLVED,
.state-FULLY_INVOICED,
.state-READY_FOR_PAYMENT {
    color: var(--ok);
}

.state-ON_HOLD,
.state-BLOCKING,
.state-OVER_INVOICED,
.state-REJECTED,
.state-BLOCKED,
.state-EXCEPTION {
    color: var(--danger);
}

.state-IN_REVIEW,
.state-WAITING_INFO,
.state-SUGGESTED,
.state-MATCHED_WITH_TOLERANCE,
.state-IN_WORK,
.state-NORMALIZED {
    color: var(--warn);
}

.state-RAW {
    color: var(--muted);
}

.global-message {
    display: block;
    margin-bottom: 12px;
    padding: 10px;
    border-radius: 8px;
    background: #eaf4ff;
    border: 1px solid #c9e1ff;
    color: #0d3f78;
}

.notice-error {
    background: #fff0f0;
    border-color: #ffc8c8;
    color: #6f1a1a;
}

.notice-ok {
    background: #eefdf2;
    border-color: #c8f1d4;
    color: #12562e;
}

.link {
    color: var(--primary);
    text-decoration: none;
}

.small {
    font-size: 12px;
    color: var(--muted);
}

.dash-chart {
    margin: 6px 0 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fbfdff;
}

.dash-bar-row {
    display: grid;
    grid-template-columns: 230px 1fr 140px;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.dash-bar-label {
    font-size: 12px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-bar-track {
    background: #e8eef6;
    border-radius: 999px;
    height: 14px;
    overflow: hidden;
}

.dash-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #0f6cbd 0%, #3ca8ff 100%);
}

.dash-bar-fill-neg {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #b42318 0%, #ef6a61 100%);
}

.dash-bar-value {
    font-size: 12px;
    text-align: right;
    color: #1f4368;
    font-weight: 600;
}

.bi-modal-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1200;
}

.bi-modal-card {
    width: min(1080px, 96vw);
    max-height: 88vh;
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--line);
    padding: 14px;
    box-shadow: 0 14px 42px rgba(18, 35, 56, 0.3);
}

.bi-table-wrap {
    width: 100%;
    overflow: auto;
    margin-top: 8px;
}

.bi-chart-wrap {
    width: 100%;
    min-height: 340px;
    margin: 8px 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    padding: 10px;
}

.bi-chart-wrap canvas {
    width: 100% !important;
    height: 320px !important;
}

.ai-prompt-field {
    min-width: min(820px, 100%);
    flex: 1 1 720px;
}

.ai-provider-row {
    margin-bottom: 8px;
    align-items: center;
}

.ai-provider-label {
    font-weight: 600;
    color: #0d3f78;
}

.ai-prompt-input {
    width: 100%;
}

.ai-sql-box {
    margin-top: 8px;
    border: 1px solid var(--line);
    background: #f5f9ff;
    border-radius: 8px;
    padding: 10px;
    white-space: pre-wrap;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    color: #1c3554;
}

.ai-risposta-box {
    margin-top: 8px;
    border: 1px solid #c9e1ff;
    background: #eef6ff;
    border-radius: 8px;
    padding: 10px;
    color: #0d3f78;
    font-weight: 600;
}

.ai-risposta-warning {
    margin-top: 8px;
    border: 1px solid #ffd8b1;
    background: #fff5e9;
    border-radius: 8px;
    padding: 10px;
    color: #804400;
    font-weight: 600;
}

.ai-chiarimento-box {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #cfe3fb;
    border-radius: 8px;
    background: #f6faff;
}

.ai-instructions-readonly {
    width: 100%;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    background: #f5f9ff;
    color: #1c3554;
}

.ai-instructions-edit {
    width: 100%;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    background: #fff;
    color: #18324f;
}

.row-sezioni {
    gap: 8px;
}

.user-switch-row {
    gap: 8px;
    align-items: center;
}

.user-switch-row .btn {
    min-width: 170px;
}

.btn-sezione {
    min-width: 180px;
}

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

.workflow-history {
    margin-top: 14px;
    border: 1px solid #d6e4f0;
    border-radius: 8px;
    background: #f8fbff;
    padding: 12px;
}

.workflow-history h3 {
    margin: 0 0 10px;
}

.workflow-history-item {
    border-top: 1px solid #dce8f3;
    padding: 10px 0;
}

.workflow-history-item:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.workflow-history-item strong,
.workflow-history-item span {
    display: block;
}

.workflow-history-item span {
    color: #52677a;
    margin-top: 3px;
}

.workflow-history-item p {
    margin: 6px 0 0;
    white-space: pre-line;
}

@media (max-width: 900px) {
    .page-hero {
        grid-template-columns: 1fr;
    }

    .topbar {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .session-box {
        width: 100%;
        margin: 0;
        flex-wrap: wrap;
    }

    .topbar .main-nav .nav-list {
        gap: 6px;
        flex-wrap: wrap;
        white-space: normal;
    }

    .topbar .main-nav .nav-has-submenu > .nav-submenu {
        position: static;
        min-width: 100%;
        margin-top: 4px;
        box-shadow: none;
    }

    .brand-logo {
        height: 34px;
    }

    .site-footer {
        grid-template-columns: 1fr;
        justify-items: flex-start;
    }

    .footer-links,
    .footer-brand {
        justify-content: flex-start;
    }

    .field {
        min-width: 100%;
    }

    .dash-bar-row {
        grid-template-columns: 1fr;
    }

    .dash-bar-value {
        text-align: left;
    }

    .bi-modal-card {
        width: 98vw;
        max-height: 92vh;
    }

    .bi-chart-wrap {
        min-height: 290px;
    }

    .bi-chart-wrap canvas {
        height: 260px !important;
    }
}
