﻿: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;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #de8500;
    background: #fa9708;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

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

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

.brand-claim {
    margin-top: 2px;
    font-size: 10px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    letter-spacing: 0.2px;
    white-space: nowrap;
}

nav {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.session-box {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    margin-right: 18px;
}

.session-user {
    color: #fff;
    font-size: 12px;
    font-weight: 600;
}

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

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

nav a {
    text-decoration: none;
    color: #fff;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 999px;
}

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

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

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

.main {
    padding: 16px 20px 28px;
}

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;
}

.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;
}

.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;
}

.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;
}

@media (max-width: 900px) {
    .topbar {
        gap: 10px;
    }

    .session-box {
        order: 3;
        width: 100%;
        margin: 0;
    }

    nav {
        gap: 6px;
    }

    .brand-logo {
        height: 34px;
    }

    .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;
    }
}
