:root{
  --sidebar-w: 270px;
  --accent: #2563eb;      /* blu */
  --accent-2: #06b6d4;    /* ciano */
  --accent-soft: rgba(37,99,235,.14);
  --ink: #0f172a;
  --page-bg: #f6f7fb;
  --content-bg: #f3f6fb;
  --card-bg: #fafbfd;
  --card-header-bg-1: #e6ebf2;
  --card-header-bg-2: #dde4ee;
  --table-head-bg-1: #e6ebf2;
  --table-head-bg-2: #dde4ee;
  --table-row-even: #e7edf5;
  --table-row-hover: #dde6f1;
  --input-bg: #f8f9fc;
  --sidebar-grad-1: #0b1220;
  --sidebar-grad-2: #0b1b3a;
  --sidebar-grad-3: #06223a;
}

/* Table sorting indicators */
th.th-sortable{position:relative; padding-right:1.1rem;}
th.th-sortable .sort-indicator{
  position:absolute;
  right:.35rem;
  top:50%;
  transform:translateY(-50%);
  color:var(--bs-secondary-color, #6c757d);
  opacity:.7;
}
th.th-sortable .sort-indicator i{
  font-size:.75rem;
  line-height:1;
  display:block;
}
th.th-sorted .sort-indicator{opacity:1;}

/* ===== Theme variants (set via html[data-theme="..."]) ===== */
html[data-theme="ocean"]{
  --accent:#2563eb;
  --accent-2:#06b6d4;
  --accent-soft: rgba(37,99,235,.14);
  --page-bg:#f6f7fb;
  --content-bg:#f3f6fb;
  --card-bg:#fafbfd;
  --card-header-bg-1:#e6ebf2;
  --card-header-bg-2:#dde4ee;
  --table-head-bg-1:#e6ebf2;
  --table-head-bg-2:#dde4ee;
  --table-row-even:#e7edf5;
  --table-row-hover:#dde6f1;
  --input-bg:#f8f9fc;
  --sidebar-grad-1:#071827;
  --sidebar-grad-2:#0b2a4a;
  --sidebar-grad-3:#0a3b52;
}
html[data-theme="bootstrap"]{
  --accent:#2563eb;
  --accent-2:#06b6d4;
  --accent-soft: rgba(37,99,235,.14);
  --page-bg:#f6f7fb;
  --content-bg:#f3f6fb;
  --card-bg:#fafbfd;
  --card-header-bg-1:#e6ebf2;
  --card-header-bg-2:#dde4ee;
  --table-head-bg-1:#e6ebf2;
  --table-head-bg-2:#dde4ee;
  --table-row-even:#e7edf5;
  --table-row-hover:#dde6f1;
  --input-bg:#f8f9fc;
  --sidebar-grad-1:#0b1220;
  --sidebar-grad-2:#0b1b3a;
  --sidebar-grad-3:#06223a;
}
html[data-theme="lux"]{
  --accent:#1f2937;
  --accent-2:#111827;
  --accent-soft: rgba(31,41,55,.12);
  --page-bg:#f6f6f6;
  --content-bg:#f1f1f1;
  --card-bg:#fafafa;
  --card-header-bg-1:#e6e6e6;
  --card-header-bg-2:#dcdcdc;
  --table-head-bg-1:#e6e6e6;
  --table-head-bg-2:#dcdcdc;
  --table-row-even:#efefef;
  --table-row-hover:#e3e3e3;
  --input-bg:#f5f5f5;
  --sidebar-grad-1:#111827;
  --sidebar-grad-2:#1f2937;
  --sidebar-grad-3:#0f172a;
}
html[data-theme="sunset"]{
  --accent:#f97316;
  --accent-2:#ef4444;
  --accent-soft: rgba(249,115,22,.14);
  --page-bg:#f7f4f1;
  --content-bg:#f2ede8;
  --card-bg:#fbf7f4;
  --card-header-bg-1:#eee3d9;
  --card-header-bg-2:#e6d7c9;
  --table-head-bg-1:#eee3d9;
  --table-head-bg-2:#e6d7c9;
  --table-row-even:#f0e7df;
  --table-row-hover:#e8dccf;
  --input-bg:#f8f2ec;
  --sidebar-grad-1:#1a0b1f;
  --sidebar-grad-2:#3b0f2b;
  --sidebar-grad-3:#4a1515;
}
html[data-theme="forest"]{
  --accent:#16a34a;
  --accent-2:#22c55e;
  --accent-soft: rgba(22,163,74,.14);
  --page-bg:#f2f6f3;
  --content-bg:#eaf1ec;
  --card-bg:#f6faf7;
  --card-header-bg-1:#e0ece5;
  --card-header-bg-2:#d7e4dc;
  --table-head-bg-1:#e0ece5;
  --table-head-bg-2:#d7e4dc;
  --table-row-even:#e6efe9;
  --table-row-hover:#dce8e1;
  --input-bg:#f1f7f3;
  --sidebar-grad-1:#07150f;
  --sidebar-grad-2:#0a2a19;
  --sidebar-grad-3:#0b3a1f;
}
html[data-theme="grape"]{
  --accent:#7c3aed;
  --accent-2:#a78bfa;
  --accent-soft: rgba(124,58,237,.14);
  --page-bg:#f4f3f8;
  --content-bg:#efecf6;
  --card-bg:#f8f7fb;
  --card-header-bg-1:#e5e0f2;
  --card-header-bg-2:#dcd6ee;
  --table-head-bg-1:#e5e0f2;
  --table-head-bg-2:#dcd6ee;
  --table-row-even:#e9e4f4;
  --table-row-hover:#dfd7ef;
  --input-bg:#f4f2fa;
  --sidebar-grad-1:#0e0b1f;
  --sidebar-grad-2:#1f1242;
  --sidebar-grad-3:#2a1657;
}
html[data-theme="slate"]{
  --accent:#0ea5e9;
  --accent-2:#64748b;
  --accent-soft: rgba(14,165,233,.14);
  --page-bg:#f4f6f9;
  --content-bg:#eef1f5;
  --card-bg:#f8fafc;
  --card-header-bg-1:#e2e8f0;
  --card-header-bg-2:#d7dde6;
  --table-head-bg-1:#e2e8f0;
  --table-head-bg-2:#d7dde6;
  --table-row-even:#e8edf3;
  --table-row-hover:#dde3ec;
  --input-bg:#f4f7fb;
  --sidebar-grad-1:#0b1220;
  --sidebar-grad-2:#0f172a;
  --sidebar-grad-3:#111827;
}
html[data-theme="sand"]{
  --accent:#b45309;
  --accent-2:#f59e0b;
  --accent-soft: rgba(180,83,9,.14);
  --page-bg:#f6f1e9;
  --content-bg:#efe7dc;
  --card-bg:#fbf7f0;
  --card-header-bg-1:#eadcc9;
  --card-header-bg-2:#e1d2bb;
  --table-head-bg-1:#eadcc9;
  --table-head-bg-2:#e1d2bb;
  --table-row-even:#efe3d3;
  --table-row-hover:#e5d6c1;
  --input-bg:#f6efe4;
  --sidebar-grad-1:#1a120a;
  --sidebar-grad-2:#2a1a0e;
  --sidebar-grad-3:#3a2311;
}
html[data-theme="mint"]{
  --accent:#0f766e;
  --accent-2:#14b8a6;
  --accent-soft: rgba(15,118,110,.14);
  --page-bg:#f2f7f6;
  --content-bg:#e9f1ef;
  --card-bg:#f7fbfa;
  --card-header-bg-1:#dfece9;
  --card-header-bg-2:#d4e4e0;
  --table-head-bg-1:#dfece9;
  --table-head-bg-2:#d4e4e0;
  --table-row-even:#e6f0ee;
  --table-row-hover:#dbe9e6;
  --input-bg:#f2f8f7;
  --sidebar-grad-1:#071616;
  --sidebar-grad-2:#0a1f1f;
  --sidebar-grad-3:#0b2a2a;
}
html[data-theme="charcoal"]{
  --accent:#22c55e;
  --accent-2:#94a3b8;
  --accent-soft: rgba(148,163,184,.16);
  --page-bg:#1f2430;
  --content-bg:#1f2430;
  --card-bg:#262b36;
  --card-header-bg-1:#2b313d;
  --card-header-bg-2:#242a35;
  --table-head-bg-1:#2b313d;
  --table-head-bg-2:#242a35;
  --table-row-even:#262c38;
  --table-row-hover:#2f3643;
  --input-bg:#2a303c;
  --sidebar-grad-1:#0b0f16;
  --sidebar-grad-2:#121826;
  --sidebar-grad-3:#151b2a;
}
html[data-theme="midnight"]{
  --accent:#38bdf8;
  --accent-2:#6366f1;
  --accent-soft: rgba(56,189,248,.16);
  --page-bg:#0f172a;
  --content-bg:#0f172a;
  --card-bg:#111827;
  --card-header-bg-1:#151c2b;
  --card-header-bg-2:#111827;
  --table-head-bg-1:#151c2b;
  --table-head-bg-2:#111827;
  --table-row-even:#131b2c;
  --table-row-hover:#172033;
  --input-bg:#141c2b;
  --sidebar-grad-1:#05070c;
  --sidebar-grad-2:#0b1020;
  --sidebar-grad-3:#0f172a;
}
html[data-theme="steel"]{
  --accent:#1f2937;
  --accent-2:#64748b;
  --accent-soft: rgba(100,116,139,.16);
  --page-bg:#eef1f5;
  --content-bg:#e7edf3;
  --card-bg:#f5f7fb;
  --card-header-bg-1:#dfe6ee;
  --card-header-bg-2:#d3dbe5;
  --table-head-bg-1:#dfe6ee;
  --table-head-bg-2:#d3dbe5;
  --table-row-even:#e3e9f1;
  --table-row-hover:#d8e0ea;
  --input-bg:#f0f3f8;
  --sidebar-grad-1:#111827;
  --sidebar-grad-2:#1f2937;
  --sidebar-grad-3:#334155;
}
/* body background set by theme */
.app-shell{
  min-height: 100vh;
  display:flex;
}
.sidebar{
  width: var(--sidebar-w);
  /* Un po' pi? "vivo" del nero pieno */
  background: linear-gradient(180deg, var(--sidebar-grad-1) 0%, var(--sidebar-grad-2) 55%, var(--sidebar-grad-3) 100%);
  color:#fff;
  position: sticky;
  top:0;
  height:100vh;
  overflow-y:auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sidebar .brand{
  padding: 1rem 1rem 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .brand-logo{
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255,255,255,.9);
  padding: 3px;
}
.sidebar .brand .title{ font-weight:700; letter-spacing:.2px; }
.sidebar .nav-section-title{
  font-size:.72rem;
  text-transform: uppercase;
  letter-spacing:.08em;
  color: rgba(255,255,255,.55);
  padding: .9rem 1rem .35rem 1rem;
}
.sidebar .nav-link{
  color: rgba(255,255,255,.84);
  padding: .55rem 1rem;
  border-radius: .65rem;
  margin: .15rem .6rem;
  display:flex;
  align-items:center;
  gap:.6rem;
}
.sidebar .nav-link:hover{ background: rgba(255,255,255,.08); color:#fff; }
.sidebar .nav-link.active{
  background: linear-gradient(90deg, rgba(37,99,235,.28), rgba(6,182,212,.18));
  color:#fff;
  border: 1px solid rgba(37,99,235,.35);
 }
.sidebar .nav-link i{ font-size: 1.05rem; opacity:.95; }

.main{
  flex:1;
  display:flex;
  flex-direction:column;
  min-width:0;
}
.topbar{
  background:#fff;
  border-bottom:1px solid rgba(17,24,39,.08);
  padding:.75rem 1rem;
  position: sticky;
  top:0;
  z-index:10;
}
.topbar:before{
  content:"";
  display:block;
  height:3px;
  margin:-.75rem -1rem .75rem -1rem;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.content{
  padding: 1rem;
}
.card{
  border: 1px solid rgba(17,24,39,.08);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(15,23,42,.10);
}
.card::before{
  content:"";
  display:block;
  height:3px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(90deg, #93c5fd, #c7d2fe);
}
.card .card-header{
  border-bottom: 1px solid rgba(17,24,39,.10);
  font-weight: 600;
}
.table thead th{ color:#111827; font-weight:700; }
.table{
  border-color: rgba(17,24,39,.08);
}
.table thead{
}
.table thead th{
  border-bottom: 1px solid rgba(17,24,39,.08);
}
/* table row colors controlled by theme */
.table tbody tr{
  border-bottom: 1px solid rgba(17,24,39,.06);
}
.badge-soft{
  background: var(--accent-soft);
  color: var(--accent);
  border:1px solid rgba(37,99,235,.22);
}

/* Persona picker (search + list dropdown) */
.persona-picker{ position:relative; }
.persona-picker .persona-list{
  position:absolute;
  left:0;
  right:0;
  top:100%;
  z-index:1050;
  max-height:260px;
  overflow:auto;
}
.persona-picker .list-group-item{
  font-size:1rem;
  padding:.5rem .75rem;
  color:#111827;
}
.persona-picker .list-group-item:hover{
  background:rgba(13,110,253,.08);
}

/* Ensure inline edit selects show text clearly */
.form-select,
.form-control{
  color:#111827 !important;
  -webkit-text-fill-color:#111827 !important;
  border: 1px solid rgba(17,24,39,.15) !important;
}
.form-select option{
  color:#111827;
}
.form-select{
  background-image: var(--bs-form-select-bg-img) !important;
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
}

/* Enterprise tabs */
.tabs{
  --tab-bg: #e3eaf3;
  --tab-border: rgba(15,23,42,.08);
  --tab-active: #2563eb;
  --tab-active-soft: rgba(37,99,235,.10);
}
.tabs .tabs-row{
  border-bottom: 1px solid var(--tab-border) !important;
  background: #e3eaf3;
  border-radius: 12px;
  padding: 6px;
  box-shadow: inset 0 0 0 1px rgba(17,24,39,.06);
  flex-wrap: wrap;
  row-gap: 6px;
}
.tabs .tab-link{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px !important;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: none;
  color: #334155 !important;
  position: relative;
  border: 1px solid transparent;
}
.tabs .tab-link.active{
  color: #0f172a !important;
  background: #ffffff;
  border-bottom: 2px solid transparent !important;
  box-shadow: inset 0 0 0 1px rgba(37,99,235,.25), 0 4px 10px rgba(15,23,42,.10);
  border-color: rgba(37,99,235,.25);
}
.tabs .tab-link.active::after{
  content:"";
  position:absolute;
  left:10px;
  right:10px;
  bottom:-6px;
  height:2px;
  background: #93c5fd;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(147,197,253,.35);
}
.tabs .tab-link[data-tab="budget"],
.tabs .tab-link[data-tab="budget_voci"],
.tabs .tab-link[data-tab="budget_spese"],
.tabs .tab-link[data-tab="budget_pagamenti"],
.tabs .tab-link[data-tab="budget_entrate"],
.tabs .tab-link[data-tab="budget_incassi"]{
  color: #0b4f7a !important;
}
.tabs .tab-link[data-tab="operatori"]{ color:#7a4e0b !important; }
.tabs .tab-link[data-tab="tasks"]{ color:#6b21a8 !important; }
.tabs .tab-link[data-tab="documenti"]{ color:#0f766e !important; }
.tabs .tab-link:hover{
  background: rgba(15,23,42,.06);
  text-decoration: none;
  border-color: rgba(15,23,42,.10);
}

/* Compact action buttons in table rows */
td.text-end .btn,
.cell-actions .btn{
  margin-left: 0;
}
.cell-actions{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  white-space: nowrap;
}
td.text-end form{
  display: inline-flex;
  margin: 0;
}

/* Tab "cards" separation */
.tabs .tabs-row .tab-link{
  margin: 2px 4px;
}
.tabs .tabs-row::after{
  content:"";
  display:block;
  height:1px;
  width:100%;
  background: linear-gradient(90deg, transparent, rgba(15,23,42,.08), transparent);
  margin-top: 6px;
}

/* Larger primary/secondary action buttons */
.btn{
  border-radius: 10px;
}
.btn.btn-primary,
.btn.btn-secondary,
.btn.btn-outline-primary,
.btn.btn-outline-secondary{
  padding: .55rem 1.1rem;
  font-size: .95rem;
}
.page-header .btn,
.topbar .btn{
  padding: .6rem 1.2rem;
  font-size: .98rem;
}

/* Premium buttons */
.btn-primary{
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  border: none;
  box-shadow: 0 6px 14px rgba(37,99,235,.18);
}
.btn-outline-primary{
  border-color: rgba(29,78,216,.45);
  color: #1d4ed8;
}
.btn-outline-primary:hover{
  background: rgba(29,78,216,.08);
}

/* Dark themes readability */
html[data-theme="charcoal"],
html[data-theme="midnight"]{
  color-scheme: dark;
}
html[data-theme="charcoal"] body,
html[data-theme="midnight"] body{
  color:#e5e7eb;
}
html[data-theme="charcoal"] .text-muted,
html[data-theme="midnight"] .text-muted{
  color: rgba(229,231,235,.65) !important;
}
html[data-theme="charcoal"] .table thead th,
html[data-theme="midnight"] .table thead th{
  color:#e5e7eb;
}
html[data-theme="charcoal"] .form-control,
html[data-theme="charcoal"] .form-select,
html[data-theme="midnight"] .form-control,
html[data-theme="midnight"] .form-select{
  color:#e5e7eb !important;
  -webkit-text-fill-color:#e5e7eb !important;
  border-color: rgba(148,163,184,.35) !important;
}
/* Inline table selects: avoid full-width layout that hides text */
.table .form-select,
.js-metodo.form-select,
.js-tipo.form-select,
.js-tipo-ref.form-select,
.js-corso.form-select,
.js-corso-sel.form-select{
  width: auto;
  min-width: 8rem;
  max-width: 100%;
  padding-right: 2.25rem;
  background-position: right .5rem center;
}
/* Avoid duplicate arrows on inline selects */
.js-metodo.form-select,
.js-tipo.form-select,
.js-tipo-ref.form-select,
.js-corso.form-select,
.js-corso-sel.form-select{
  background-image: none !important;
  -webkit-appearance: auto;
  -moz-appearance: auto;
  appearance: auto;
}

/* KPI cards / report */
.kpi-card{
  border: 1px solid rgba(15,23,42,.08);
  box-shadow: 0 8px 22px rgba(2,6,23,.04);
}
.kpi-card .kpi-label{ color: rgba(15,23,42,.62); font-size: .8rem; }
.kpi-card .kpi-value{ font-size: 1.45rem; font-weight: 800; color: var(--ink); }
.kpi-card .kpi-sub{ color: rgba(15,23,42,.58); font-size: .78rem; }
.kpi-accent{
  background: linear-gradient(135deg, rgba(37,99,235,.10), rgba(6,182,212,.08));
}
.bar-incassi{ background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar-pagamenti{ background: linear-gradient(90deg, rgba(239,68,68,.85), rgba(245,158,11,.75)); }

/* Print: report pulito */
@media print{
  .topbar, .sidebar, .btn, select, .app-overlay{ display:none !important; }
  body{ background:#fff; }
  .content{ padding:0; }
  .card{ box-shadow:none !important; }
}
@media (max-width: 992px){
  .sidebar{
    position: fixed;
    left:-280px;
    transition: left .2s ease;
    z-index:20;
    width: min(var(--sidebar-w), 88vw);
    height: 100dvh;
    max-height: 100dvh;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .sidebar.open{ left:0; }
  .app-overlay{ display:none; position: fixed; inset:0; background: rgba(0,0,0,.35); z-index:15; }
  .app-overlay.show{ display:block; }
  body.mobile-menu-open{ overflow: hidden; }
}

/* Sidebar collassabile */
body.sidebar-collapsed{ --sidebar-w: 78px; }
body.sidebar-collapsed .sidebar .brand .title,
body.sidebar-collapsed .sidebar .brand .small{ display:none; }
body.sidebar-collapsed .sidebar .nav-section-title{ display:none; }
body.sidebar-collapsed .sidebar .nav-link{ justify-content:center; }
body.sidebar-collapsed .sidebar .nav-link .lbl{ display:none; }
body.sidebar-collapsed .sidebar .brand .toggle-btn{ margin-left:auto; }
body.sidebar-collapsed .sidebar .brand .brand-logo{ display:none; }

.login-logo{
  width: 44px;
  height: 44px;
  object-fit: contain;
}

/* When collapsed, hide plain-text labels too (not only .lbl). */
body.sidebar-collapsed .sidebar .nav-link{ font-size:0; padding-left:.75rem; padding-right:.75rem; }
body.sidebar-collapsed .sidebar .nav-link i{ font-size:1.2rem; }

/* Task picker: make the remove "x" always visible on colored badges */
.task-picker .picker-chip button{
  color: rgba(255,255,255,.95);
  font-weight: 800;
  font-size: 1.05rem;
  opacity: .9;
}
.task-picker .picker-chip button:hover{ opacity:1; }

/* FK picker (campi collegati / chiavi esterne) */
.fk-picker{ position: relative; }
.fk-list{
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 260px;
  overflow: auto;
  background: #fff;
  border: 1px solid rgba(17,24,39,.18);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.08);
  z-index: 1000;
  display: none;
}
.fk-picker.open .fk-list{ display:block; }

/* Generic scheda form: robust responsive layout */
.scheda-fields-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:18px;
}
.scheda-fields-grid .field{
  min-width:0;
}
.scheda-fields-grid .form-control,
.scheda-fields-grid .form-select,
.scheda-fields-grid .input-group{
  max-width:100%;
}
.scheda-actions{
  margin-top:16px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}

@media (max-width: 992px){
  .scheda-fields-grid{
    grid-template-columns: 1fr;
    gap:14px;
  }
  .scheda-actions .btn{
    width:100%;
  }
}
.fk-item{ padding: .45rem .65rem; cursor:pointer; }
.fk-item:hover{ background: rgba(59,130,246,.10); }
.fk-item.muted{ color: rgba(17,24,39,.55); cursor: default; }
