:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f8f9ff;
  --text: #1f2937;
  --muted: #667085;
  --border: #d9deea;
  --shadow: 0 8px 24px rgba(12, 18, 28, 0.08);
  --brand: #3b82f6;
  --brand-strong: #1d4ed8;
  --nav-bg: #243447;
  --nav-hover: #1a2737;
}

html.dark-mode,
body.dark-mode {
  --bg: #0f1624;
  --surface: #172131;
  --surface-soft: #1f2a3d;
  --text: #e5edf9;
  --muted: #b6c3dc;
  --border: #2a3851;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --brand: #60a5fa;
  --brand-strong: #3b82f6;
  --nav-bg: #111a29;
  --nav-hover: #0e1522;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.container {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.nav {
  list-style: none;
  margin: 0;
  padding: 0 12px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  background: var(--nav-bg);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
}

.nav-mobile-toggle {
  display: none;
  width: 100%;
  border: 0;
  background: var(--nav-bg);
  color: #eef4ff;
  font-weight: 700;
  text-align: left;
  padding: 12px 14px;
  align-items: center;
  gap: 10px;
}

.nav-mobile-icon {
  width: 18px;
  height: 2px;
  background: #eef4ff;
  display: inline-block;
  position: relative;
  border-radius: 2px;
  transition: transform 0.2s ease;
}

.nav-mobile-icon::before,
.nav-mobile-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: #eef4ff;
  transition: transform 0.2s ease, top 0.2s ease, opacity 0.2s ease;
}

.nav-mobile-icon::before {
  top: -6px;
}

.nav-mobile-icon::after {
  top: 6px;
}

.nav-item {
  position: relative;
}

.nav-item a {
  display: block;
  padding: 12px 18px;
  text-decoration: none;
  color: #eef4ff;
  font-weight: 600;
  transition: background-color 0.2s ease;
}

.nav-item a:hover {
  background: var(--nav-hover);
}

.dropdown-content {
  display: none;
  list-style: none;
  margin: 2px 0 0 0;
  padding: 6px 0;
  position: absolute;
  background: var(--surface);
  min-width: 220px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 8px;
  z-index: 1000;
}

.dropdown-content-right {
  right: 0;
  left: auto;
}

.dropdown-content li a {
  color: var(--text);
  padding: 10px 14px;
}

.dropdown-content li a:hover {
  background: var(--surface-soft);
}

.nav-item.dropdown:hover .dropdown-content {
  display: block;
}

.nav-theme-item {
  margin-left: 10px;
}

.nav-account-item {
  margin-left: auto;
}

.theme-toggle {
  margin: 6px 0 6px 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #eef4ff;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.theme-toggle-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffd166;
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.25);
}

html.dark-mode .theme-toggle-dot,
body.dark-mode .theme-toggle-dot {
  background: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
}

label {
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

input,
select,
textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.05);
}

table {
  color: var(--text);
}

table th,
table td {
  border-color: var(--border) !important;
}

table thead th {
  background: var(--surface-soft);
}

table.table-striped > tbody > tr:nth-of-type(odd) > * {
  background: var(--surface-soft);
}

table.table-striped > tbody > tr:nth-of-type(even) > * {
  background: var(--surface);
}

.report-wrap {
  max-width: 1160px;
  margin: 0 auto;
}

.report-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.report-table-wrap .table {
  margin-bottom: 0;
  min-width: 840px;
}

.report-table-wrap .table th,
.report-table-wrap .table td {
  white-space: nowrap;
  vertical-align: middle;
}

.report-muted {
  color: var(--muted) !important;
}

.btn-light {
  border-color: var(--border);
  background: var(--surface-soft);
  color: var(--text);
}

html.dark-mode a,
body.dark-mode a {
  color: #9bc2ff;
}

html.dark-mode .text-muted,
body.dark-mode .text-muted {
  color: #c0cbe0 !important;
}

html.dark-mode .btn-light,
body.dark-mode .btn-light {
  background: #223049;
  color: #e5edf9;
  border-color: #344867;
}

html.dark-mode .btn-outline-primary,
body.dark-mode .btn-outline-primary {
  color: #9bc2ff;
  border-color: #5f8fda;
}

html.dark-mode .btn-outline-primary:hover,
body.dark-mode .btn-outline-primary:hover {
  background: #2a4470;
  color: #f2f7ff;
}

html.dark-mode .btn-outline-secondary,
body.dark-mode .btn-outline-secondary {
  color: #d2dcef;
  border-color: #5a6b88;
}

html.dark-mode .btn-outline-secondary:hover,
body.dark-mode .btn-outline-secondary:hover {
  background: #2a3448;
  color: #f2f7ff;
}

html.dark-mode .form-control,
html.dark-mode .form-select,
html.dark-mode input,
html.dark-mode select,
html.dark-mode textarea,
body.dark-mode .form-control,
body.dark-mode .form-select,
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background: #1b2740;
  color: #f2f7ff;
  border-color: #496084;
}

html.dark-mode .form-control:disabled,
html.dark-mode .form-control[readonly],
html.dark-mode .form-select:disabled,
body.dark-mode .form-control:disabled,
body.dark-mode .form-control[readonly],
body.dark-mode .form-select:disabled {
  background: #1f2d46;
  color: #d8e4fb;
  opacity: 1;
}

html.dark-mode .table,
body.dark-mode .table {
  color: #edf3ff;
}

html.dark-mode .table thead th,
body.dark-mode .table thead th {
  background: #26344f;
  color: #f7fbff;
}

html.dark-mode .table-striped > tbody > tr:nth-of-type(odd) > *,
body.dark-mode .table-striped > tbody > tr:nth-of-type(odd) > * {
  background: #1c2a43;
}

html.dark-mode .table-striped > tbody > tr:nth-of-type(even) > *,
body.dark-mode .table-striped > tbody > tr:nth-of-type(even) > * {
  background: #1a253b;
}

html.dark-mode .badge,
body.dark-mode .badge {
  border: 1px solid rgba(255, 255, 255, 0.12);
}

html.dark-mode .form-control::placeholder,
html.dark-mode input::placeholder,
body.dark-mode .form-control::placeholder,
body.dark-mode input::placeholder {
  color: #95a4c4;
}

html.dark-mode .alert,
body.dark-mode .alert {
  border-color: var(--border);
}

html.dark-mode .alert-success,
body.dark-mode .alert-success {
  background: #1f3a2e;
  color: #d0ffe5;
}

html.dark-mode .alert-danger,
body.dark-mode .alert-danger {
  background: #4b2323;
  color: #ffdede;
}

html.dark-mode h1,
html.dark-mode h2,
html.dark-mode h3,
html.dark-mode h4,
html.dark-mode h5,
html.dark-mode h6,
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
  color: #f5f9ff;
}

html.dark-mode .container p,
html.dark-mode .container li,
html.dark-mode .container small,
body.dark-mode .container p,
body.dark-mode .container li,
body.dark-mode .container small {
  color: #d8e4fb;
}

html.dark-mode strong,
body.dark-mode strong {
  color: #f5f9ff;
}

html.dark-mode .text-dark,
body.dark-mode .text-dark,
html.dark-mode .text-body,
body.dark-mode .text-body,
html.dark-mode .text-black,
body.dark-mode .text-black {
  color: #f5f9ff !important;
}

html.dark-mode .text-primary,
body.dark-mode .text-primary {
  color: #8fc2ff !important;
}

html.dark-mode .text-success,
body.dark-mode .text-success {
  color: #86efac !important;
}

html.dark-mode .text-danger,
body.dark-mode .text-danger {
  color: #ffb4b1 !important;
}

html.dark-mode .text-warning,
body.dark-mode .text-warning {
  color: #ffd78f !important;
}

html.dark-mode .text-info,
body.dark-mode .text-info {
  color: #a5f3fc !important;
}

html.dark-mode .badge.text-bg-success,
body.dark-mode .badge.text-bg-success {
  background: #14532d !important;
  color: #dcfce7 !important;
}

html.dark-mode .badge.text-bg-danger,
body.dark-mode .badge.text-bg-danger {
  background: #7f1d1d !important;
  color: #fee2e2 !important;
}

html.dark-mode .badge.text-bg-primary,
body.dark-mode .badge.text-bg-primary {
  background: #1e3a8a !important;
  color: #dbeafe !important;
}

html.dark-mode .btn-outline-success,
body.dark-mode .btn-outline-success {
  color: #86efac;
  border-color: #4ade80;
}

html.dark-mode .btn-outline-success:hover,
body.dark-mode .btn-outline-success:hover {
  background: #14532d;
  color: #ecfdf5;
}

html.dark-mode .btn-outline-danger,
body.dark-mode .btn-outline-danger {
  color: #ffb4b1;
  border-color: #f87171;
}

html.dark-mode .btn-outline-danger:hover,
body.dark-mode .btn-outline-danger:hover {
  background: #7f1d1d;
  color: #fff5f5;
}

html.dark-mode .btn-outline-warning,
body.dark-mode .btn-outline-warning {
  color: #ffd78f;
  border-color: #fbbf24;
}

html.dark-mode .btn-outline-warning:hover,
body.dark-mode .btn-outline-warning:hover {
  background: #78350f;
  color: #fffbeb;
}

html.dark-mode .container,
body.dark-mode .container,
html.dark-mode .card,
body.dark-mode .card {
  background: #172131;
  border-color: #2f4060;
}

html.dark-mode .btn-primary,
body.dark-mode .btn-primary {
  background: #2563eb;
  border-color: #3b82f6;
  color: #f6faff;
}

html.dark-mode .btn-primary:hover,
body.dark-mode .btn-primary:hover {
  background: #1d4ed8;
  border-color: #3b82f6;
}

html.dark-mode .btn-secondary,
body.dark-mode .btn-secondary {
  background: #334155;
  border-color: #475569;
  color: #eff6ff;
}

html.dark-mode .btn-success,
body.dark-mode .btn-success {
  background: #15803d;
  border-color: #16a34a;
  color: #f3fff8;
}

html.dark-mode .btn-danger,
body.dark-mode .btn-danger {
  background: #b91c1c;
  border-color: #dc2626;
  color: #fff5f5;
}

html.dark-mode .btn-close,
body.dark-mode .btn-close {
  filter: invert(1) grayscale(100%) brightness(180%);
}

html.dark-mode .dropdown-menu,
body.dark-mode .dropdown-menu {
  background: #1a2436;
  border-color: #33455f;
}

html.dark-mode .dropdown-item,
html.dark-mode .dropdown-menu a,
body.dark-mode .dropdown-item,
body.dark-mode .dropdown-menu a {
  color: #e6edff;
}

html.dark-mode .dropdown-item:hover,
html.dark-mode .dropdown-menu a:hover,
body.dark-mode .dropdown-item:hover,
body.dark-mode .dropdown-menu a:hover {
  background: rgba(96, 165, 250, 0.16);
  color: #f5f9ff;
}

html.dark-mode .table-wrap,
body.dark-mode .table-wrap {
  background: #18243a;
}

html.dark-mode .report-table-wrap,
body.dark-mode .report-table-wrap {
  background: #18243a;
  border-color: #344867;
}

html.dark-mode .report-table-wrap .table td,
html.dark-mode .report-table-wrap .table th,
body.dark-mode .report-table-wrap .table td,
body.dark-mode .report-table-wrap .table th {
  color: #edf3ff;
}

html.dark-mode .report-muted,
body.dark-mode .report-muted {
  color: #d8e4fb !important;
}

html.dark-mode table.table-hover > tbody > tr:hover > *,
body.dark-mode table.table-hover > tbody > tr:hover > * {
  background: #22334f !important;
}

html.dark-mode .form-check-input,
body.dark-mode .form-check-input {
  background-color: #1b2740;
  border-color: #496084;
}

html.dark-mode .form-check-input:checked,
body.dark-mode .form-check-input:checked {
  background-color: #3b82f6;
  border-color: #60a5fa;
}

.val-pos {
  color: #157347;
  font-weight: 700;
}

.val-neg {
  color: #b42318;
  font-weight: 700;
}

body.dark-mode .val-pos {
  color: #7cf3a8;
}

body.dark-mode .val-neg {
  color: #ff9f9a;
}

.home-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(120deg, var(--surface), var(--surface-soft));
  padding: 14px;
}

.home-hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.home-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.home-kpi-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 12px;
}

.home-kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.home-kpi-card strong {
  display: block;
  margin-top: 3px;
  font-size: 1.15rem;
}

.home-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
}

.home-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px;
}

.home-card h2 {
  margin: 0 0 6px 0;
  font-size: 1.02rem;
}

.home-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 190px;
  margin-top: 8px;
}

.home-chart-col {
  text-align: center;
}

.home-chart-bars {
  height: 155px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
}

.home-chart-bars span {
  width: 11px;
  min-height: 3px;
  border-radius: 6px 6px 2px 2px;
}

.home-chart-bars .bar-tab {
  background: #2563eb;
}

.home-chart-bars .bar-bar {
  background: #0f766e;
}

.home-chart-bars .neg {
  background: #b42318;
}

.home-legend {
  margin-top: 8px;
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.home-legend .dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
  margin-right: 5px;
}

.home-legend .dot.tab {
  background: #2563eb;
}

.home-legend .dot.bar {
  background: #0f766e;
}

.home-list {
  margin: 6px 0 0 0;
  padding: 0;
  list-style: none;
}

.home-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}

.home-list li.total {
  border-bottom: 0;
  padding-bottom: 0;
}

body.dark-mode .home-hero {
  background: linear-gradient(120deg, #1a2539, #22314a);
  border-color: #3a4f70;
}

body.dark-mode .home-hero p,
body.dark-mode .home-card p,
body.dark-mode .home-kpi-card span,
body.dark-mode .home-legend,
body.dark-mode .home-list li span {
  color: #d8e4fb !important;
}

body.dark-mode .home-card,
body.dark-mode .home-kpi-card {
  background: #1a2436;
  border-color: #33455f;
}

body.dark-mode .home-card h2,
body.dark-mode .home-kpi-card strong,
body.dark-mode .home-chart-col small {
  color: #f5f9ff;
}

@media (max-width: 992px) {
  .container {
    margin-top: 12px !important;
    border-radius: 10px;
    padding: 14px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .nav-mobile-toggle {
    display: inline-flex;
  }

  .nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
  }

  .navbar.nav-open .nav {
    display: flex;
  }

  .navbar:not(.nav-open) .nav {
    display: none !important;
  }

  .navbar.nav-open .nav {
    display: flex !important;
  }

  .navbar.nav-open .nav-mobile-icon {
    transform: rotate(45deg);
  }

  .navbar.nav-open .nav-mobile-icon::before {
    top: 0;
    transform: rotate(90deg);
  }

  .navbar.nav-open .nav-mobile-icon::after {
    top: 0;
    opacity: 0;
  }

  .nav-item,
  .nav-theme-item,
  .nav-account-item {
    width: 100%;
    margin-left: 0 !important;
  }

  .nav-item a {
    padding: 11px 14px;
  }

  .theme-toggle {
    margin: 8px 12px 10px 12px;
    justify-content: center;
    width: calc(100% - 24px);
  }

  .dropdown-content {
    position: static;
    display: none;
    min-width: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    padding: 0 0 6px 0;
    background: transparent;
  }

  .dropdown-content li a {
    color: #d7e6ff;
    padding: 8px 22px;
    font-size: 0.93rem;
  }

  .dropdown-content li a:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .nav-item.dropdown.is-open .dropdown-content {
    display: block;
  }

  .nav-item.dropdown:hover .dropdown-content {
    display: none;
  }

  .nav-item.dropdown.is-open:hover .dropdown-content {
    display: block;
  }

  .nav-item.dropdown > .dropbtn {
    position: relative;
    padding-right: 34px;
  }

  .nav-item.dropdown > .dropbtn::after {
    content: "▾";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.9;
    font-size: 0.85rem;
  }

  .nav-item.dropdown.is-open > .dropbtn::after {
    content: "▴";
  }

  .row {
    --bs-gutter-x: 0.75rem;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 40px;
  }

  .chiusura-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .chiusura-actions .btn,
  .chiusura-actions .form-select {
    width: 100% !important;
  }

  .modal-content,
  .bar-modal-card {
    max-width: calc(100vw - 20px) !important;
    margin: 10px auto !important;
    padding: 14px !important;
  }

  .home-hero {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .home-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 0.94rem;
  }

  .container {
    padding: 10px;
  }

  table {
    font-size: 0.82rem;
  }

  .report-table-wrap .table {
    min-width: 680px;
    font-size: 0.8rem;
  }

  .alert {
    padding: 0.55rem 0.75rem;
  }

  .home-kpi-grid {
    grid-template-columns: 1fr;
  }

  .home-chart {
    min-height: 150px;
  }

  .home-chart-bars {
    height: 120px;
  }
}
