:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3fb;
  --text: #1d2433;
  --muted: #69788f;
  --primary: #3b63ff;
  --primary-soft: #e7edff;
  --border: #dbe3f1;
  --danger: #d63f61;
  --success: #1f9d6a;
  --shadow: 0 10px 30px rgba(18, 35, 79, 0.08);
  --chart-invest: #3b63ff;
  --chart-transfer: #4db6ff;
  --chart-cash: #35c985;
  --chart-other: #f2a654;
}

html[data-theme="dark"] {
  --bg: #0a0d14;
  --surface: #11151d;
  --surface-2: #171c26;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #7f97d6;
  --primary-soft: #242e42;
  --border: #252b36;
  --danger: #c26a7f;
  --success: #4da584;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
  --chart-invest: #8ca2d8;
  --chart-transfer: #78a9c4;
  --chart-cash: #66b197;
  --chart-other: #b39a6d;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; font-weight: 400; font-size: 15px; line-height: 1.45; background: var(--bg); color: var(--text); overflow-x: hidden; }
img, iframe { max-width: 100%; }
.login-body { min-height: 100vh; background: radial-gradient(circle at 10% 10%, #8fa9ff44, transparent 45%), radial-gradient(circle at 80% 80%, #77ffd733, transparent 45%), var(--bg); }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.login-card { width: min(420px, 100%); padding: 2rem; }
.brand-kicker, .muted { color: var(--muted); margin: 0; }
.subtitle { margin-top: .25rem; color: var(--muted); }
.login-form, .stack-form { display: grid; gap: .8rem; }
input, select, textarea { width: 100%; padding: .72rem .85rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); }
.stack-form label { display: grid; gap: .4rem; font-weight: 500; }

.primary-btn, .ghost-btn, .danger-btn {
  border: 0;
  border-radius: 11px;
  padding: .65rem .95rem;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}
.primary-btn { background: var(--primary); color: #fff; }
.ghost-btn { background: var(--surface-2); color: var(--text); }
.danger-btn { background: var(--danger); color: #fff; }
.danger-link { line-height: 1.2; }
.icon-btn i { font-size: 1rem; }

.alert, .toast { padding: .7rem .8rem; border-radius: 10px; margin: .5rem 0 1rem; }
.alert { border: 1px solid #ef94a6; background: #ffe3ea; color: #7f1d33; }
.toast { border: 1px solid #65d5aa; background: #e6fff4; color: #126b47; }
html[data-theme="dark"] .alert { background: #3a1d27; color: #ffd9e2; border-color: #7b3142; }
html[data-theme="dark"] .toast { background: #173126; color: #c4ffe5; border-color: #2f7c5c; }

.dashboard-shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; transition: grid-template-columns .2s ease; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1.3rem .9rem; overflow-y: auto; }
.sidebar-brand { font-size: 1.05rem; font-weight: 600; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .5rem .6rem; }
.sidebar-brand-title { display: inline-flex; align-items: center; gap: .6rem; min-width: 0; }
.sidebar-brand i { font-size: 1.25rem; color: var(--primary); }
.sidebar-collapse-btn { width: 30px; height: 30px; border-radius: 8px; padding: 0; justify-content: center; }
.nav-section { font-size: .74rem; text-transform: uppercase; color: var(--muted); margin: 1rem .6rem .4rem; letter-spacing: .04em; }
.nav-link { display: flex; align-items: center; gap: .65rem; text-decoration: none; color: var(--text); padding: .68rem .75rem; border-radius: 12px; margin-bottom: .3rem; border-left: 3px solid transparent; }
.nav-link i { font-size: 1.06rem; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--primary-soft); border-left-color: var(--primary); color: var(--primary); }

.main-area { padding: 1rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: .9rem 1rem; box-shadow: var(--shadow); }
.topbar-title h1 { margin: 0; font-size: 1.22rem; font-weight: 600; }
.topbar-title p { margin-top: .2rem; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.content { margin-top: 1rem; display: grid; gap: 1rem; }
.sidebar-overlay { display: none; }
.sidebar-close-btn { display: none; }
.page-documenti { background: #f6f7fb; }
html[data-theme="dark"] .page-documenti { background: #121a2b; }
.card { padding: 1rem; }
.narrow { max-width: 760px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
.inline-form { display: flex; gap: .5rem; margin: .8rem 0; flex-wrap: wrap; }
.filter-date-field { display: flex; flex-direction: column; gap: 4px; }
.filter-date-field span { font-size: 12px; color: var(--muted); }
.inline-actions { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }
.inline-actions form { margin: 0; }

.table-wrap { overflow: auto; max-width: 100%; }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
.truncate-ellipsis { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.muted-subtext { color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.grid-two { display: grid; grid-template-columns: 1fr 2fr; gap: 1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.stats-grid-overview { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stats-grid-historical { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.overview-top {
  display: grid;
  gap: 1rem;
}

.overview-left {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.overview-left .stat-wide {
  grid-column: 1 / -1;
}

.overview-right {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 1rem;
}
.stat-card h2 { margin: .2rem 0 0; font-size: 1.4rem; font-weight: 600; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); display: grid; gap: .8rem; }
.two-cols .full { grid-column: 1 / -1; }

.three-cols-desktop { grid-template-columns: repeat(2, minmax(0, 1fr)); display: grid; gap: .8rem; }
.three-cols-desktop .full,
.three-cols-desktop .full-span { grid-column: 1 / -1; }

.table-total-row td { font-weight: 600; background: color-mix(in srgb, var(--surface-2) 65%, transparent); }
.table-total-row td:first-child { color: var(--muted); }

.inline-status-filters .ghost-btn.filter-carico { border-color: #fca5a5; color: #b91c1c; background: #fef2f2; }
.inline-status-filters .ghost-btn.filter-scarico { border-color: #86efac; color: #166534; background: #ecfdf3; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.mobile-menu-btn { display: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); width: 38px; height: 38px; border-radius: 10px; }

.dashboard-breakdown-card h2 { margin: 0; }
.semi-layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; align-items: center; margin-top: 1rem; }
.semi-chart-wrap { display: flex; justify-content: center; }
.semi-chart {
  width: min(420px, 100%);
  aspect-ratio: 2 / 1;
  border-radius: 220px 220px 0 0;
  background: var(--semi-gradient);
  position: relative;
  overflow: hidden;
}
.semi-chart::after {
  content: "";
  position: absolute;
  left: 13%;
  right: 13%;
  top: 26%;
  bottom: 0;
  background: var(--surface);
  border-radius: 160px 160px 0 0;
}
.semi-chart-inner {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: .9rem;
  text-align: center;
}
.semi-chart-inner strong { font-size: 1.25rem; }
.breakdown-list { display: grid; gap: .7rem; }
.breakdown-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .75rem; display: grid; gap: .15rem; }
.breakdown-item p { margin: 0; display: flex; align-items: center; gap: .45rem; font-weight: 500; }
.breakdown-title-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.breakdown-title-row p { margin: 0; }
.breakdown-item strong { font-size: 1.1rem; }
.breakdown-item small { color: var(--muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 999px; display: inline-block; }
.legend-invest { background: var(--chart-invest); }
.legend-transfer { background: var(--chart-transfer); }
.legend-cash { background: var(--chart-cash); }
.legend-other { background: var(--chart-other); }

.inline-delete { display: inline-flex; margin: 0; }

.status-pill { display: inline-flex; align-items: center; justify-content: center; max-width: 100%; font-weight: 500; border-radius: 999px; padding: .1rem .42rem; font-size: .78rem; border: 1px solid transparent; gap: .28rem; overflow: visible; }
.status-pill .status-dot { display: inline-block; flex: 0 0 auto; width: 7px; height: 7px; border-radius: 999px; margin: 0; }
.dot-green { background: #16a34a; }
.dot-red { background: #dc2626; }
.status-carico { color: #b91c1c; background: #fef2f2; border-color: #fca5a5; }
.status-scarico { color: #166534; background: #ecfdf3; border-color: #86efac; }
.status-carico .status-dot { background: #dc2626; }
.status-scarico .status-dot { background: #16a34a; }
.inline-status-filters { display: flex; gap: .5rem; margin: 0 0 .8rem; flex-wrap: wrap; }
.inline-status-filters .ghost-btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.ghost-btn[disabled] { opacity: .55; cursor: not-allowed; }

.soft-badge { display: inline-flex; align-items: center; border: 1px solid var(--primary); color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: .1rem .5rem; font-size: .78rem; white-space: nowrap; }
.movement-type-in { color: #166534; border-color: #86efac; background: #ecfdf3; }
.movement-type-out { color: #9f1239; border-color: #f9a8d4; background: #fff1f2; }
.movement-amount-in { color: #166534; font-weight: 600; }
.movement-amount-out { color: #be123c; font-weight: 600; }
.movement-total { margin: 0 0 .85rem; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-wrap { white-space: normal; overflow-wrap: anywhere; }
.account-movements-table { table-layout: fixed; width: 100%; }
.account-movements-table .mov-col-id { width: 58px; text-align: center; }
.account-movements-table .mov-col-date { width: 98px; }
.account-movements-table .mov-col-type { width: 90px; }
.account-movements-table .mov-col-amount { width: 115px; white-space: nowrap; }
.account-movements-table .mov-col-description { width: 28%; min-width: 170px; }
.account-movements-table .mov-col-ref { width: 30%; min-width: 0; }
.account-movements-table .mov-col-actions { width: 106px; min-width: 106px; white-space: nowrap; }
.movement-ref { display: grid; gap: .2rem; }
.movement-ref-link { justify-content: flex-start; max-width: 100%; }
.ref-car-btn {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.movement-ref-subtext {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
html[data-theme="dark"] .movement-type-in { color: #86efac; border-color: #2d7a53; background: #183327; }
html[data-theme="dark"] .movement-type-out { color: #fda4af; border-color: #7f3a4d; background: #3b1f29; }
html[data-theme="dark"] .movement-amount-in { color: #86efac; }
html[data-theme="dark"] .movement-amount-out { color: #fda4af; }
.inline-options { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: .75rem; }
.inline-options legend { padding: 0 .3rem; color: var(--muted); }
.inline-options label { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; font-weight: 500; }
.inline-options input { width: auto; }
.hidden { display: none !important; }


.documents-table { table-layout: fixed; width: 100%; }
.documents-table .doc-col-file { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.documents-table .doc-col-vehicle { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.documents-table .doc-col-note { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.documents-table .doc-col-party { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.documents-table .doc-col-date,
.documents-table .doc-col-type,
.documents-table .doc-col-plate,
.cars-table .car-col-id,
.cars-table .car-col-date,
.cars-table .car-col-status,
.cars-table .car-col-plate,
.cars-table .car-col-price,
.cars-table .car-col-money-date,
.cars-table .car-col-info,
.cars-table .car-col-actions { white-space: nowrap; }
.cars-table { table-layout: fixed; width: 100%; min-width: 1500px; font-size: .86rem; }
.cars-table th,
.cars-table td { overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.cars-table .car-col-id { width: 45px; min-width: 45px; text-align: center; }
.cars-table .car-col-vehicle { width: 200px; min-width: 200px; }
.cars-table .car-col-status { width: 45px; min-width: 45px; text-align: center; }
.cars-table .car-col-info { width: 45px; min-width: 45px; max-width: 45px; text-align: center; }
.cars-table .car-col-plate { width: 85px; min-width: 85px; max-width: 85px; overflow: visible; text-overflow: clip; }
.cars-table .car-col-plate .car-plate-full { display: inline-block; max-width: none; overflow: visible; text-overflow: clip; white-space: nowrap; }
.cars-table .car-col-date { width: 8%; font-size: .78rem; font-style: italic; color: var(--muted); }
.cars-table .car-col-money-date { width: 125px; min-width: 125px; }
.cars-table .car-col-price { width: 100px; min-width: 100px; }
.cars-table .car-col-investor { width: 112px; min-width: 112px; }
.cars-table .car-col-tax { width: 110px; min-width: 110px; text-align: left; }
.cars-table .car-col-other-revenue { width: 80px; min-width: 80px; }
.cars-table .car-col-actions { width: 45px; min-width: 45px; overflow: visible; }
.cars-table .car-cost-price { color: #d97706; }
.cars-table .car-sale-price { color: var(--text); font-weight: 600; }
.car-money-date-stack{display:flex;flex-direction:column;align-items:flex-start;gap:2px;min-width:0;max-width:100%;line-height:1.15;overflow:visible}
.car-stack-price{display:block;max-width:100%;font-weight:700;font-size:.86rem;font-variant-numeric:tabular-nums;overflow:visible;text-overflow:clip;white-space:nowrap}
.car-stack-date{display:block;max-width:100%;font-size:.72rem;color:var(--muted);font-style:italic;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.car-money-date-stack .money-with-info{max-width:100%;gap:.32rem}
.car-money-date-stack .money-with-info > span:first-child{overflow:visible;text-overflow:clip;white-space:nowrap}
.car-mobile-money-date{display:inline-flex;vertical-align:middle;margin-left:.2rem}
.car-tax-placeholder { color: var(--muted); }
.investor-shares-list{display:flex;flex-direction:column;gap:3px;font-size:.71rem;line-height:1.12;text-align:left}
.investor-share-row{display:flex;gap:6px;align-items:center;min-width:0;white-space:nowrap}
.investor-share-initial{display:inline-flex;align-items:center;justify-content:center;flex:0 0 28px;min-width:28px;height:18px;padding:0 4px;border-radius:999px;background:var(--primary-soft);color:var(--primary);font-weight:700;font-size:.62rem}
.investor-share-values{display:flex;flex-direction:column;gap:1px;min-width:0}
.investor-share-amount,.investor-share-net{font-variant-numeric:tabular-nums;overflow:hidden;text-overflow:ellipsis;max-width:118px}
.investor-share-net{color:var(--muted)}
.investor-share-value-label{font-size:.64rem;font-weight:700;color:var(--muted)}
.investor-share-tax-detail{display:none}
.investor-detail-button{appearance:none;-webkit-appearance:none;display:inline-flex;flex-direction:column;align-items:flex-start;gap:2px;max-width:100%;padding:.28rem .45rem;border:1px solid var(--border);border-radius:10px;background:var(--surface);color:var(--text);font:inherit;font-size:.74rem;line-height:1.08;text-align:left;cursor:pointer;box-shadow:0 1px 2px rgba(15,23,42,.05)}
.investor-detail-button:hover{border-color:var(--primary);background:var(--primary-soft);color:var(--primary)}
.investor-detail-button:focus-visible{outline:2px solid var(--primary);outline-offset:2px}
.investor-detail-count{font-weight:700;white-space:nowrap}
.investor-detail-summary{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted);font-size:.66rem;font-variant-numeric:tabular-nums}
.investor-detail-modal-dialog{max-width:980px;width:min(980px,calc(100vw - 2rem))}
.investor-detail-table-wrap{margin-top:.75rem;overflow:auto}
.investor-detail-table{min-width:760px}
.investor-detail-table th,.investor-detail-table td{vertical-align:top}
.investor-detail-table th:not(:first-child),.investor-detail-table .numeric-cell{text-align:right;font-variant-numeric:tabular-nums}
.investor-quota-mode{display:flex;flex-direction:column;gap:2px;line-height:1.15}
.investor-quota-mode small{color:var(--muted);font-variant-numeric:tabular-nums}
.investor-unexpected-row td{background:rgba(245,158,11,.08);font-weight:700}
.investor-row{display:grid;grid-template-columns:minmax(180px,1fr) 150px 120px 120px auto;gap:.45rem;margin:.35rem 0;align-items:center}
.investor-row .hidden{display:none}
.tax-badge{display:inline-flex;align-items:center;justify-content:center;min-width:2.6rem;padding:.15rem .45rem;border-radius:999px;font-size:.75rem;font-weight:700;background:#eef2f7;color:#334155}
.tax-badge-margin{background:#ecfdf3;color:#166534}
.tax-badge-exposed{background:#eff6ff;color:#1d4ed8}
.tax-badge-empty{background:#f1f5f9;color:#64748b}
.tax-cell-stack{display:flex;flex-direction:column;gap:4px;align-items:flex-start;min-width:0}
.tax-amount-line{display:inline-flex;align-items:center;max-width:100%}
.tax-amount-row{display:inline-flex;align-items:center;gap:6px;white-space:nowrap;max-width:100%}
.tax-amount{font-size:.84rem;font-weight:600;line-height:1.15;color:var(--text);font-variant-numeric:tabular-nums}
.tax-info-btn{flex:0 0 auto}
.tax-paid-toggle{display:inline-flex;align-items:center;gap:4px;font-size:.7rem;color:var(--muted);line-height:1;white-space:nowrap}
.tax-paid-toggle input{width:14px;height:14px;margin:0;accent-color:var(--primary)}
.tax-total-stack{display:flex;flex-direction:column;gap:3px;min-width:0;font-size:.7rem;line-height:1.15}
.tax-total-line{display:flex;align-items:center;justify-content:space-between;gap:5px;white-space:nowrap}
.tax-total-line strong{font-size:.72rem;font-variant-numeric:tabular-nums}
.tax-total-paid{color:#15803d}
.tax-total-due{color:#9a6a16}
.investor-total-button{display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:100%;padding:5px 6px;border:1px solid var(--border);border-radius:8px;background:var(--surface);color:var(--text);font:inherit;font-size:.69rem;line-height:1.15;text-align:left;cursor:pointer}
.investor-total-button:hover{background:var(--surface-2);border-color:var(--primary)}
.investor-total-button:focus-visible{outline:2px solid var(--primary);outline-offset:1px}
.investor-total-title{font-weight:700;color:var(--primary)}
.investor-total-empty{font-size:.72rem;color:var(--muted);white-space:nowrap}
.investor-totals-modal-dialog{width:min(920px,calc(100vw - 2rem));max-width:920px}
.investor-modal-summary{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px 18px;margin:1rem 0}
.investor-modal-summary-line{display:flex;justify-content:space-between;gap:12px;padding:7px 0;border-bottom:1px solid var(--border);font-size:.84rem}
.investor-modal-summary-line strong{white-space:nowrap;font-variant-numeric:tabular-nums}
.investor-modal-table-wrap{max-height:min(52vh,520px)}
.investor-modal-table-wrap table{min-width:700px}
.investor-modal-table-wrap th:not(:first-child),.investor-modal-table-wrap td:not(:first-child){text-align:right;white-space:nowrap}
.investor-share-row-warning{color:#b91c1c;font-weight:600}
@media (max-width: 900px){
  .investor-row{grid-template-columns:1fr 1fr auto}
  .investor-row select[name="investor_ids[]"]{grid-column:1 / -1}
  .investor-modal-summary{grid-template-columns:1fr}
}

@media (max-width: 900px){
  .cars-table .car-col-tax{width:112px;min-width:112px}
  .tax-amount{font-size:.79rem}
  .tax-amount-row{gap:5px}
}
.money-with-info {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  white-space: nowrap;
}
.info-mini-btn {
  padding: 0;
  min-width: 0;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: .82rem;
}
.cars-mobile-list { display: none; gap: .75rem; }
.car-mobile-card { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: .75rem; display: grid; gap: .6rem; }
.car-mobile-card-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.car-mobile-card p { margin: 0; color: var(--muted); }
.car-mobile-card strong { color: var(--text); }
.car-mobile-actions { display: flex; justify-content: flex-end; gap: .4rem; flex-wrap: wrap; }
.doc-cards { display: none; gap: .75rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.image-upload-field { display: grid; gap: .55rem; }
.image-dropzone {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: .9rem;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease;
}
.image-dropzone p { margin: 0 0 .2rem; font-weight: 500; }
.image-dropzone small { color: var(--muted); }
.image-dropzone.is-active,
.image-dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: .55rem;
}
.image-preview-grid-single { grid-template-columns: minmax(170px, 220px); }
.image-preview-item {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  display: grid;
}
.image-preview-item img { width: 100%; height: 100px; object-fit: cover; display: block; }
.image-preview-item figcaption {
  display: grid;
  gap: .3rem;
  padding: .4rem;
}
.image-badge {
  display: inline-flex;
  width: fit-content;
  font-size: .72rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: .04rem .42rem;
  color: var(--muted);
}
.image-file-name { font-size: .73rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-remove-btn { justify-content: center; }

.doc-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .75rem; display: grid; gap: .7rem; }
.doc-card p { margin: 0; word-break: break-word; }
.doc-card-grid { display: grid; gap: .35rem; }
.doc-card-line { display: grid; gap: .2rem; }
.doc-file-link { max-width: 100%; }
.note-clamp-2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

@media (max-width: 980px) {
  body { font-size: 14px; }
  .grid-two, .stats-grid, .detail-grid, .two-cols, .three-cols-desktop, .semi-layout { grid-template-columns: 1fr; }
  .overview-top { grid-template-columns: 1fr; }
  .dashboard-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 0; left: 0; height: 100%; width: min(84vw, 292px); z-index: 60; transform: translateX(-104%); transition: transform .25s ease; box-shadow: var(--shadow); padding-bottom: 1.4rem; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(6, 13, 26, 0.48); z-index: 55; }
  .sidebar-overlay.open { display: block; }
  .sidebar nav { max-height: calc(100vh - 76px); overflow-y: auto; padding-right: .2rem; }
  .sidebar-close-btn { display: inline-grid; place-items: center; position: absolute; right: .65rem; top: .65rem; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
  .mobile-menu-btn { display: inline-grid; place-items: center; }
  .topbar { padding: .65rem .75rem; }
  .topbar-title h1 { font-size: 1rem; }
  .topbar-title .muted { display: none; }
  .topbar-actions .icon-btn span { display: none; }
  .main-area { padding: .75rem; }
  .card { padding: .8rem; }
  .stat-card h2 { font-size: 1.08rem; }
  .semi-chart { width: 100%; max-width: 360px; margin-inline: auto; }
  .breakdown-list { grid-template-columns: 1fr; }
  #docPreviewFrame, #docPreviewImage { height: 70vh; }
  .cars-table-wrap { overflow-x: auto; }
  .cars-table { min-width: 1080px; }

}

@media (max-width: 768px) {
  .account-movements-table thead { display: none; }
  .account-movements-table,
  .account-movements-table tbody,
  .account-movements-table tr,
  .account-movements-table td { display: block; width: 100%; }
  .account-movements-table tr { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: .55rem .65rem; margin-bottom: .6rem; }
  .account-movements-table td { border: 0; padding: .16rem 0; white-space: normal; }
  .account-movements-table td::before { content: attr(data-label); display: block; color: var(--muted); font-size: .73rem; margin-bottom: .05rem; }
  .account-movements-table .mov-col-actions .inline-delete { margin-top: .35rem; }
  .account-movements-table .mov-col-actions { display: flex; gap: .4rem; align-items: center; }
  .account-movements-table .mov-col-actions::before { width: 100%; }
  .movement-ref-link, .ref-car-btn { width: 100%; justify-content: flex-start; }
  .cars-table-wrap { display: none; }
  .cars-mobile-list { display: grid; }
  .documents-table-wrap { display: none; }
  .doc-cards { display: grid; }
  .inline-actions { flex-wrap: wrap; }
  .actions-col { width: auto; }
  .main-area { padding: .6rem; }
  .topbar { border-radius: 12px; }
  .card { padding: .7rem; border-radius: 14px; }
  .stats-grid { gap: .55rem; }
  .stat-card { padding: .65rem; }
  .stat-card .muted { font-size: .78rem; }
  .stat-card h2 { font-size: 1rem; line-height: 1.2; }
}

@media (min-width: 981px) {
  .overview-top {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .overview-left { grid-column: 1 / span 2; }
  .overview-right { grid-column: 3; }

  .breakdown-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .three-cols-desktop { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-shell.sidebar-collapsed { grid-template-columns: 66px 1fr; }
  .dashboard-shell.sidebar-collapsed .sidebar-label { display: none; }
  .dashboard-shell.sidebar-collapsed .sidebar { padding-inline: .35rem; }
  .dashboard-shell.sidebar-collapsed .sidebar-brand { justify-content: center; }
  .dashboard-shell.sidebar-collapsed .sidebar-brand-title { justify-content: center; }
  .dashboard-shell.sidebar-collapsed .nav-link { justify-content: center; padding-inline: .25rem; position: relative; }
  .dashboard-shell.sidebar-collapsed .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--text);
    color: var(--surface);
    border-radius: 8px;
    font-size: .74rem;
    padding: .28rem .42rem;
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
    transition: opacity .15s ease;
    z-index: 30;
  }
  .dashboard-shell.sidebar-collapsed .nav-link:hover::after,
  .dashboard-shell.sidebar-collapsed .nav-link:focus-visible::after { opacity: 1; }
}


h1, h2, h3 { font-weight: 600; letter-spacing: 0; }
h2 { font-size: 1.1rem; }
th { font-weight: 600; }
tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 35%, transparent); }
tr:hover td { background: color-mix(in srgb, var(--primary-soft) 30%, transparent); }

.ghost-btn, .danger-btn {
  background: transparent;
  border: 1px solid transparent;
}
.ghost-btn:hover { border-color: var(--border); background: var(--surface-2); }
.danger-btn { color: var(--text); }
.danger-btn:hover { border-color: color-mix(in srgb, var(--danger) 65%, var(--border)); color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, transparent); }
.primary-btn { font-weight: 500; }

.actions-col { text-align: right; width: 168px; }
.inline-actions { justify-content: flex-end; flex-wrap: nowrap; }
.action-row { display: inline-flex; gap: .3rem; align-items: center; min-width: 0; flex-wrap: nowrap; }
.action-icon { width: 32px; height: 32px; padding: 0; justify-content: center; }
.action-icon i { font-size: 1rem; }

.tooltip-trigger { position: relative; }
.app-tooltip {
  position: fixed;
  z-index: 120;
  max-width: min(280px, calc(100vw - 16px));
  background: var(--text);
  color: var(--surface);
  border-radius: 9px;
  padding: .42rem .55rem;
  font-size: .76rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
}
.app-tooltip[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: none;
  z-index: 9999; /* Mantiene ogni modale sopra sidebar, header e dropdown globali */
}
.modal.open { display: block; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(6, 13, 26, 0.45);
}
.modal-container {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}
.modal-dialog {
  position: relative;
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .9rem;
  pointer-events: auto;
}
.modal-body { max-height: calc(100vh - 170px); overflow: auto; display: flex; align-items: center; justify-content: center; }

/* Altro modal: più grande e body non centrato */
.modal-dialog.altro-modal{
  width: min(1100px, calc(100vw - 32px));
}

.modal-body.modal-body-normal{
  display: block;
  align-items: initial;
  justify-content: initial;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

/* Tabelle dentro modale: rendi fruibile */
.altro-modal .table-wrap{
  overflow: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.altro-modal td.col-desc{
  max-width: 420px;
}

.altro-modal td.col-desc .truncate-ellipsis{
  max-width: 420px;
}

.altro-modal td.col-ref{
  max-width: 180px;
}

.altro-modal td.col-ref .truncate-ellipsis{
  max-width: 180px;
}

.altro-modal thead th{
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-close { position: absolute; top: .5rem; right: .5rem; }
#docPreviewFrame, #docPreviewImage { width: 100%; height: min(70vh, 520px); border: 0; display: none; }
#docPreviewImage { object-fit: contain; }
.modal-frame-body {
  margin: 0;
  padding: 0;
  background: transparent;
}
.modal-frame-body .card,
.modal-frame-body .card.narrow {
  margin: 0;
  width: 100%;
  max-width: none;
  border: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
}

.search-select { position: relative; }
.search-dropdown { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; max-height: 260px; overflow: auto; display: none; z-index: 20; }
.search-dropdown.open { display: block; }
.search-item { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); padding: .55rem .7rem; display: grid; gap: .2rem; }
.search-item:last-child { border-bottom: 0; }
.search-item:hover { background: var(--surface-2); }
.search-item small { color: var(--muted); }

.profit-pos { color: #15803d; background: rgba(34, 197, 94, 0.08); }
.profit-neg { color: #b91c1c; background: rgba(239, 68, 68, 0.08); }
.profit-zero { color: var(--muted); }

.notes-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}

.notes-grid {
  display: grid;
  gap: .85rem;
  grid-template-columns: 1fr;
}

.note-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .8rem;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
  display: grid;
  gap: .55rem;
}

.note-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .45rem;
}

.note-done-toggle {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .9rem;
}


.note-head-main {
  display: flex;
  align-items: flex-start;
  gap: .4rem;
  min-width: 0;
  flex: 1;
}

.note-head-side {
  display: grid;
  justify-items: end;
  gap: .25rem;
  flex: 0 0 auto;
}

.note-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-drag-handle {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 1.7rem;
  height: 1.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  flex: 0 0 auto;
}

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

.note-card.dragging {
  opacity: .45;
}

.note-card.drop-target {
  border-color: #3b82f6;
  border-style: dashed;
}

.note-content {
  margin: 0;
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-category-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: .1rem .45rem;
  font-size: .72rem;
  background: rgba(59, 130, 246, .12);
  color: #1d4ed8;
  max-width: 100%;
}

#noteViewCategory.is-empty {
  background: rgba(148, 163, 184, .14);
  color: var(--muted);
}

.note-view-meta {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
  margin-bottom: .45rem;
}

.note-view-color {
  font-size: .78rem;
  color: var(--muted);
}

.note-view-content {
  margin: .35rem 0;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.note-view-dates {
  border-top: 1px solid var(--border);
  padding-top: .55rem;
  margin-top: .2rem;
  display: grid;
  gap: .2rem;
}

.note-view-dates .muted {
  margin: 0;
  font-size: .85rem;
}

.note-color-yellow { background: #fff8c7; }
.note-color-white { background: #fffef8; }
.note-color-blue { background: #eaf5ff; }
.note-color-red { background: #ffecef; }

.note-done {
  opacity: .65;
}

.note-done .note-content {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.note-color-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .45rem;
}

.note-color-option {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .4rem .5rem;
  cursor: pointer;
}

.note-category-list {
  display: grid;
  gap: .45rem;
}

.note-category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .45rem .55rem;
}

@media (min-width: 700px) {
  .notes-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1100px) {
  .notes-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 1450px) {
  .notes-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.note-card .js-note-toggle {
  width: 1rem;
  height: 1rem;
  margin-top: .2rem;
  flex: 0 0 auto;
}


.car-note-preview{appearance:none;-webkit-appearance:none;border:0;background:transparent;color:inherit;cursor:pointer;width:100%;max-width:100%;display:inline-flex;align-items:center;justify-content:flex-start;padding:.1rem .25rem;border-radius:6px;text-align:left;overflow:hidden}
.car-note-preview:hover{background:var(--surface-2)}
.car-note-preview:focus-visible{outline:2px solid var(--primary);outline-offset:1px}
.car-note-preview .truncate-ellipsis{width:100%}
.car-note-modal-dialog{max-width:560px;width:min(560px,calc(100vw - 2rem))}
.car-note-modal-dialog textarea{width:100%}
.car-status-stack{display:flex;flex-direction:column;align-items:center;gap:3px}
.status-pill-compact{font-size:.7rem;padding:.05rem .34rem;gap:.25rem}
.cars-table .status-pill-dot-only{width:18px;height:18px;padding:0;gap:0}
.cars-table .status-pill-dot-only .status-text-desktop{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
.cars-table .status-pill-dot-only .status-dot{width:8px;height:8px}
.status-pill-mini{font-size:.64rem;padding:.02rem .28rem}
.info-icon-mini{padding:0;min-width:0;width:18px;height:18px;border-radius:999px;font-size:.78rem;margin:0 1px}
.cars-table .car-col-status{width:45px;min-width:45px;text-align:center}
.cars-table .car-col-info{width:45px;min-width:45px;max-width:45px;text-align:center}
.cars-table .car-col-investor{width:112px;min-width:112px;text-align:left}
.cars-table .car-col-date{width:72px;min-width:72px;font-size:.75rem}
.cars-table .car-col-money-date{width:125px;min-width:125px}
.cars-table .car-col-tax{width:110px;min-width:110px;text-align:left}
.cars-table .car-col-other-revenue{width:80px;min-width:80px}
.cars-table .car-col-note{width:160px;min-width:160px}
.cars-table .car-col-actions{width:45px;min-width:45px;overflow:visible}
.cars-table{min-width:1500px}
.row-actions{position:relative;display:flex;justify-content:center}
.row-actions-popover{position:absolute;right:0;top:calc(100% + 6px);z-index:1200;min-width:180px;background:var(--surface);border:1px solid var(--border);border-radius:10px;box-shadow:var(--shadow);padding:.3rem}
.row-actions-menu-item{display:flex;align-items:center;gap:.45rem;width:100%;text-decoration:none;color:var(--text);background:transparent;border:0;padding:.42rem .5rem;border-radius:8px;text-align:left;font:inherit;cursor:pointer}
.row-actions-menu-item:hover{background:var(--surface-2)}

html[data-theme="dark"] .topbar,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .card { background: var(--surface); border-color: var(--border); }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { background: var(--surface-2); border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .ghost-btn { background: #1c2330; border: 1px solid var(--border); color: var(--text); }
html[data-theme="dark"] .nav-link.active,
html[data-theme="dark"] .filter-pill.active,
html[data-theme="dark"] .inline-status-filters .ghost-btn.active { color: #c8d4f3; }
html[data-theme="dark"] .cars-table tbody tr:hover td { background: rgba(255,255,255,.02); }
.cars-table .car-col-date { white-space: nowrap; overflow: hidden; text-overflow: clip; min-width: 72px; width: 72px; }
.cars-table .car-col-money-date { white-space: nowrap; overflow: visible; text-overflow: clip; }
.car-vehicle-link { color: inherit; text-decoration: none; display: inline-block; max-width: 100%; }
.car-vehicle-link:hover { text-decoration: underline; text-underline-offset: 2px; }
.car-vehicle-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
html[data-theme="dark"] .car-vehicle-link { color: #d2d8e5; }

html[data-theme="dark"] .note-color-yellow { background: #3a3320; border-color: #5b5130; color: #f3e6be; }
html[data-theme="dark"] .note-color-white { background: #20242c; border-color: #3a414d; color: #e5e7eb; }
html[data-theme="dark"] .note-color-blue { background: #1f2e43; border-color: #33506f; color: #dbeafe; }
html[data-theme="dark"] .note-color-red { background: #3f2329; border-color: #6a3a45; color: #ffd9e1; }
html[data-theme="dark"] .note-card .note-title,
html[data-theme="dark"] .note-card .note-content { color: inherit; }
html[data-theme="dark"] .note-card .note-category-badge { background: rgba(255,255,255,.12); color: inherit; border: 1px solid rgba(255,255,255,.18); }
html[data-theme="dark"] .note-card .note-drag-handle { border-color: rgba(255,255,255,.22); color: inherit; }
html[data-theme="dark"] .note-card .ghost-btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.2); color: inherit; }
html[data-theme="dark"] .note-card .danger-btn { background: #8b3a4b; color: #ffe9ee; }

.cars-table .car-col-label{max-width:65px;width:65px;min-width:65px}
.car-label-chip,.car-label-empty{display:inline-flex;max-width:58px;padding:2px 7px;border-radius:999px;border:1px solid var(--line);background:var(--panel-soft);color:var(--text);font-size:11px;overflow:hidden}
.car-label-empty{opacity:.75}
.car-label-chip .truncate-ellipsis{max-width:44px}
