/* Bilancio Metodyca - stile base */
:root {
    --navy: #2c3f59;
    --navy-dark: #1e2b3f;
    --navy-light: #eef2f7;
    --teal: #0f766e;
    --teal-dark: #0b5852;
    --teal-light: #f0fdfa;
    --ink: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --bg: #f1f5f9;
    --white: #ffffff;
    --green: #16a34a;
    --red: #dc2626;
    --amber: #d97706;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar { background: var(--navy); border-bottom: 1px solid var(--navy-dark); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1980px; margin: 0; padding: 0 16px; height: 64px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-logo { display: block; height: 24px; width: auto; }
.mainnav { display: flex; gap: 4px; margin-left: 8px; }
.mainnav a { padding: 8px 14px; border-radius: 8px; color: rgba(255,255,255,.75); font-weight: 600; font-size: 14px; }
.mainnav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.15); color: #fff; }

/* Dropdown nel menu di navigazione */
.nav-dropdown { position: relative; display: inline-block; }
.nav-dropdown-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 8px;
    background: transparent; border: 0; cursor: pointer;
    color: rgba(255,255,255,.75); font-weight: 600; font-size: 14px; font-family: inherit;
}
.nav-dropdown-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-dropdown-toggle.active { background: rgba(255,255,255,.15); color: #fff; }
.nav-dropdown-toggle .caret { font-size: 10px; opacity: .7; }
.nav-dropdown-menu {
    position: absolute; top: calc(100% + 6px); left: 0; min-width: 200px;
    background: var(--white); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15,23,42,.10);
    padding: 6px; display: none; z-index: 30;
}
.nav-dropdown.open .nav-dropdown-menu,
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
    display: block; padding: 8px 12px; border-radius: 6px;
    color: var(--ink); font-size: 14px; font-weight: 500;
}
.nav-dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.nav-dropdown-menu a.active { background: var(--navy-light); color: var(--navy); font-weight: 600; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.anno-switch { margin-left: auto; }
.anno-switch + .userbox { margin-left: 0; }
.anno-switch .nav-dropdown-toggle { border: 1px solid rgba(255,255,255,.35); }
.anno-switch .nav-dropdown-menu { left: auto; right: 0; min-width: 120px; }
.username { font-size: 14px; color: rgba(255,255,255,.85); }
.userbox .btn-ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.userbox .btn-ghost:hover { background: rgba(255,255,255,.10); color: #fff; }
@media (max-width: 960px) {
    .topbar-inner { gap: 12px; }
    .mainnav a, .nav-dropdown-toggle { padding: 8px 10px; font-size: 13px; }
    .username { display: none; }
}

/* ---------- Layout ---------- */
.container { max-width: 1980px; margin: 0; padding: 24px 16px; }
.footer { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }

/* ---------- Card ---------- */
.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 20px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 16px; }

/* ---------- Form ---------- */
.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
input, select, textarea {
    width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(44,63,89,.15); }
textarea { resize: vertical; min-height: 44px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; font-size: 14px; font-weight: 600; border-radius: 8px; border: 1px solid transparent; cursor: pointer; font-family: inherit; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--red); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.flash-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-info { background: var(--teal-light); color: var(--teal-dark); border-color: #99f6e4; }

/* ---------- Tabella ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; }
table.data tbody tr:hover, table.data tr:hover { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-entrata { background: #f0fdf4; color: var(--green); }
.badge-uscita { background: #fef2f2; color: var(--red); }
.badge-nat { background: var(--bg); color: var(--muted); font-weight: 600; }
.badge-nat-operativa    { background: #eff6ff; color: #1d4ed8; }
.badge-nat-finanziaria  { background: #fef3c7; color: #92400e; }
.badge-nat-patrimoniale { background: #f3e8ff; color: #6d28d9; }
.badge-nat-non_monetaria{ background: #f1f5f9; color: #475569; }

/* Filtri a pillole (tasti a pressione) */
.filters-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 20px 28px; margin-top: 8px; }
.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.pill-group { display: inline-flex; flex-wrap: wrap; gap: 6px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; }
.pill {
    display: inline-block; padding: 6px 14px; border-radius: 999px;
    font-size: 13px; font-weight: 600; color: var(--muted); background: transparent;
    text-decoration: none; border: 1px solid transparent; transition: background .12s, color .12s;
    cursor: pointer;
}
.pill:hover { background: var(--white); color: var(--ink); text-decoration: none; }
.pill.is-active { background: var(--navy); color: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.15); }
.pill.is-active:hover { background: var(--navy-dark); color: #fff; }
.amount-in { color: var(--green); font-weight: 600; }
.amount-out { color: var(--red); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
/* Tabella pivot bilancio (voci x mesi) */
table.pivot { font-size: 13px; white-space: nowrap; }
table.pivot th, table.pivot td { padding: 8px 10px; }
table.pivot .sticky { position: sticky; left: 0; background: var(--white); z-index: 1; min-width: 200px; box-shadow: 2px 0 0 var(--border); }
table.pivot thead th.sticky { background: #f8fafc; }
table.pivot .dim { color: #cbd5e1; }
table.pivot .strong { font-weight: 700; }
table.pivot tr.row-section td { background: var(--navy-light); color: var(--navy); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.pivot tr.row-subtotal td { background: #f8fafc; font-weight: 600; color: var(--muted); }
table.pivot tr.row-subtotal td.sticky { background: #f8fafc; }
table.pivot tr.row-total td { background: var(--navy); color: #fff; font-weight: 700; border-bottom: 0; }
table.pivot tr.row-total td.sticky { background: var(--navy); }
table.pivot tr.row-total .amount-in { color: #86efac; }
table.pivot tr.row-total .amount-out { color: #fca5a5; }
table.pivot tr.row-total .dim { color: rgba(255,255,255,.4); }
table.pivot tbody tr:hover td { background: #f8fafc; }
table.pivot tbody tr.row-total:hover td { background: var(--navy); }

tr.row-sofferenza td { background: #fef2f2 !important; }
tr.row-sofferenza td:first-child { border-left: 3px solid var(--red); }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.in { color: var(--green); }
.stat .value.out { color: var(--red); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal.is-open { display: flex; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.modal-dialog { position: relative; width: 100%; max-width: 640px; background: var(--white); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(15, 23, 42, .25); border: 1px solid var(--border); animation: modalIn .18s ease-out; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 700; margin: 0; }
.modal-close { background: transparent; border: 0; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 10px; border-radius: 8px; }
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-body { padding: 22px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
body.modal-lock { overflow: hidden; }
@keyframes modalIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--white); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 10px 40px rgba(15,23,42,.10); overflow: hidden; }
.auth-head { padding: 28px 32px 8px; text-align: center; }
.auth-head .brand-mark {
    width: 48px; height: 48px; font-size: 22px; border-radius: 12px; margin: 0 auto 12px;
    background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800;
}
.auth-head h1 { font-size: 20px; margin: 0 0 4px; }
.auth-head p { color: var(--muted); font-size: 14px; margin: 0; }
.auth-body { padding: 24px 32px 32px; }
.code-input input { text-align: center; font-size: 26px; letter-spacing: 12px; font-weight: 700; }
.auth-alt { text-align: center; margin-top: 16px; font-size: 14px; }
