.header-main-title {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text-main);
}

.header-main-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

header .header-right {
  margin-left: auto;
}

.portal-launcher {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  margin-right: 2px;
}

.portal-hamburger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  box-shadow: none;
  color: #ffffff;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}

.portal-hamburger-button:hover {
  background: rgba(255,255,255,0.15);
}

.portal-hamburger-button:focus-visible {
  outline: 2px solid var(--interactive);
  outline-offset: 2px;
}

.portal-hamburger-icon {
  position: relative;
  width: 18px;
  height: 2px;
  background: #ffffff;
  border-radius: 999px;
  transition: background 0.18s ease;
}

.portal-hamburger-icon::before,
.portal-hamburger-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: #ffffff;
  border-radius: 999px;
  transition: transform 0.2s ease, top 0.2s ease;
}

.portal-hamburger-icon::before {
  top: -5px;
}

.portal-hamburger-icon::after {
  top: 5px;
}

body.portal-drawer-open .portal-hamburger-icon {
  background: transparent;
}

body.portal-drawer-open .portal-hamburger-icon::before {
  top: 0;
  transform: rotate(45deg);
}

body.portal-drawer-open .portal-hamburger-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

.portal-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.3);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 3000;
}

.portal-drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.portal-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: clamp(300px, 30vw, 380px);
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.28s ease,
    opacity 0.18s ease;
  z-index: 3100;
}

.portal-drawer.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.portal-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.portal-drawer-title {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.portal-drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.portal-drawer-close:hover {
  background: var(--border);
}

.portal-tabs.portal-tabs-drawer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: transparent;
  border-bottom: none;
  box-shadow: none;
  overflow-y: auto;
}

.portal-drawer-item {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.portal-tabs.portal-tabs-drawer .portal-tab-button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  border: none;
  background: var(--surface);
  color: var(--text-main);
  border-radius: 0;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  text-align: left;
  border-left: 3px solid transparent;
}

.portal-tabs.portal-tabs-drawer .portal-tab-button::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: 14px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.portal-drawer-item.no-children .portal-tab-button::after {
  display: none;
}

.portal-tabs.portal-tabs-drawer .portal-tab-button:hover {
  background: var(--surface-alt);
}

.portal-drawer-item.active > .portal-tab-button {
  color: var(--interactive);
  background: var(--interactive-light);
  border-left-color: var(--interactive);
}

.portal-drawer-item.open > .portal-tab-button::after {
  transform: rotate(-135deg) translate(-1px, 1px);
  border-color: var(--interactive);
}

.portal-drawer-item.open > .portal-tab-button {
  border-left-color: var(--border-strong);
  background: var(--surface-alt);
}

.portal-drawer-subtabs {
  display: none;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--surface-alt);
  border-top: none;
}

.portal-drawer-item.open .portal-drawer-subtabs {
  display: flex;
}

.portal-drawer-subtab {
  width: 100%;
  margin: 0;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 16px 10px 40px;
  border-radius: 0;
  cursor: pointer;
  border-top: 1px solid var(--border);
  transition: background 0.15s ease, color 0.15s ease;
}

.portal-drawer-subtab:first-child {
  border-top: none;
}

.portal-drawer-subtab:hover {
  background: var(--border);
  color: var(--text-main);
}

.portal-drawer-subtab.active {
  background: var(--interactive-light);
  color: var(--interactive);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--interactive);
}

.legend-menu {
  position: relative;
  z-index: 3300;
}

.legend-menu-panel {
  z-index: 3400;
  max-width: min(92vw, 480px);
}

.legend-menu.legend-map-float {
  position: absolute;
  top: 14px;
  left: 56px;
  margin: 0 !important;
  z-index: 8;
  align-items: flex-start;
}

.legend-menu.legend-map-float .legend-menu-button {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text-main);
  font-weight: 500;
  box-shadow: var(--shadow-md);
  padding: 7px 10px;
}

.legend-menu.legend-map-float .legend-menu-panel {
  right: auto;
  left: 0;
  top: calc(100% + 8px);
  max-width: min(86vw, 460px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.brand-logo-right {
  height: 36px;
  width: auto;
  flex: 0 0 auto;
}

.layout {
  gap: 0;
  padding: 0;
}

.sidebar {
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  box-shadow: none;
}

.sidebar-toggle {
  width: 14px;
  height: 30px;
  right: -14px;
  border-radius: 0 6px 6px 0;
}

.tabs,
.fonti-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: transparent;
}

.tabs {
  margin: 0 12px;
  border-bottom: 1px solid var(--border);
}

.fonti-tabs {
  margin: 0 12px;
  padding: 0;
  gap: 0;
  width: calc(100% - 24px);
  box-sizing: border-box;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  overflow: visible;
}

.tabs.fonti-parent-active .tab-button {
  border-bottom-color: transparent;
}

.tab-button,
.fonti-tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
  box-shadow: none;
  cursor: pointer;
  position: relative;
}

.tab-button {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 10px 8px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 13px;
  text-align: center;
}

.fonti-tab-button {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 10px 6px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent !important;
}

.tab-button:hover {
  color: var(--text-main);
}

.fonti-tab-button:hover {
  background: transparent !important;
  color: var(--text-main);
}

.tab-button:focus-visible,
.fonti-tab-button:focus-visible {
  outline: 2px solid var(--interactive);
  outline-offset: -2px;
  z-index: 1;
}

.tab-button.active,
.fonti-tab-button.active {
  color: var(--interactive);
  font-weight: 600;
}

.tab-button.active {
  border-bottom-color: var(--interactive);
  background: transparent;
}

.fonti-tab-button.active {
  border: none;
  border-bottom: 2px solid var(--interactive);
  background: transparent !important;
  box-shadow: none;
}

.sidebar-content,
.fonti-scroll {
  padding: 12px 12px 18px 12px;
}

.section,
.risk-card,
.fastmap-job-card,
.table-wrap,
.management-popup,
.perizia-details-popup,
.calendar-popup {
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.section {
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.section h2,
.management-popup-title,
.management-sheet-title {
  color: var(--text-main);
  font-weight: 600;
  letter-spacing: 0;
}

label {
  color: var(--text-secondary);
  letter-spacing: 0;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="password"],
textarea,
select,
gmp-place-autocomplete {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--interactive);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-weight: 500;
  letter-spacing: 0;
  background: var(--interactive);
  box-shadow: var(--shadow-xs);
}

.btn.sec {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  box-shadow: none;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.simple-table th,
.omi-table th,
.ntn-table th,
.cap-table th,
.surface-groups-table th {
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.map-container {
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--bg);
}

body.portal-gestione .layout {
  display: flex;
}

body.portal-gestione .sidebar {
  width: 100%;
  max-width: none;
  flex: 1 1 auto;
  border-right: none;
}

body.portal-gestione .sidebar-toggle {
  display: none;
}

body.portal-gestione .map-container {
  display: none;
}

/* ---- Repository: nasconde mappa, espande pannello file manager ---- */
body.portal-repository .layout {
  display: flex;
}
body.portal-repository .sidebar {
  width: 100%;
  max-width: none;
  flex: 1 1 auto;
  border-right: none;
}
body.portal-repository .sidebar-toggle {
  display: none;
}
body.portal-repository .map-container {
  display: none;
}

.gestione-content {
  padding: 16px 24px 20px;
  overflow-y: auto;
  direction: ltr;
  scrollbar-gutter: auto;
}

.gestione-shell {
  min-height: 0;
  border: none;
  background: none;
  box-shadow: none;
  padding: 0;
}

.gestione-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}

.gestione-nav-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.gestione-nav-btn:hover {
  background: var(--surface-alt);
  color: var(--text-main);
}

.gestione-nav-btn.active {
  background: var(--interactive-light);
  border-color: var(--interactive);
  color: var(--interactive);
  font-weight: 600;
}

.gestione-workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

body.portal-gestione .management-popup.gestione-inline-panel {
  position: static;
  inset: auto;
  transform: none;
  width: 100%;
  max-width: 860px;
  min-height: 0;
  height: auto;
  max-height: none;
  z-index: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  padding: 16px 18px 18px;
  overflow: visible;
  background: var(--surface);
}

body.portal-gestione .management-popup.gestione-inline-panel .management-popup-close {
  display: none;
}

body.portal-gestione .management-popup.gestione-inline-panel .management-tab-panel {
  overflow: visible;
  padding-right: 0;
}

body.portal-gestione .gestione-inline-panel.gestione-compact {
  max-width: 720px;
}

body.portal-gestione .gestione-inline-panel#configLynxPopup {
  max-width: 100%;
}

body.portal-gestione .gestione-inline-panel#defaultsCatastoPopup {
  max-width: 100%;
}

body.portal-gestione .gestione-inline-panel .section {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 8px;
}

/* Constrain form field widths in Gestione panels */
body.portal-gestione .gestione-inline-panel .section > input,
body.portal-gestione .gestione-inline-panel .section > select {
  max-width: 360px;
}
body.portal-gestione .gestione-inline-panel .section > .row {
  max-width: 540px;
}
body.portal-gestione .gestione-inline-panel .management-search {
  max-width: 480px;
}

.perito-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}

.perito-form-col > label:first-child {
  margin-top: 0;
}

.perito-form-col > label {
  margin-top: 6px;
  display: block;
}

.perito-form-col > .row {
  margin-top: 6px;
}

.perito-form-col > .multi-check {
  margin-top: 4px;
}

.perito-form-full {
  grid-column: 1 / -1;
}

@media (max-width: 680px) {
  .perito-form-grid {
    grid-template-columns: 1fr;
  }
}

/* Gestione panel utilities */
.gestione-panel-hint {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted, #888);
  line-height: 1.4;
}

.gestione-panel-footer {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border, #e5e7eb);
}

/* Table group header rows */
.simple-table .tbl-group-hdr td {
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 8px 4px;
  color: var(--text-muted, #888);
  border-bottom: none;
}

/* Permessi matrix */
.permessi-matrix {
  width: auto;
}
.permessi-matrix th:not(:first-child),
.permessi-matrix td:not(:first-child) {
  text-align: center;
  width: 72px;
  min-width: 72px;
}

/* Gruppi */
.gruppi-card {
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius-md, 8px);
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--surface, #fff);
}
.gruppi-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-inline-danger {
  background: none;
  border: none;
  color: var(--danger, #dc2626);
  cursor: pointer;
  font-size: 0.85em;
  padding: 2px 6px;
}
.btn-inline-danger:hover { text-decoration: underline; }
.btn-sm { font-size: 0.85em; padding: 4px 10px; }
.grp-svc-matrix { font-size: 0.9em; }
.grp-svc-matrix th:not(:first-child),
.grp-svc-matrix td:not(:first-child) {
  text-align: center;
  width: 60px;
  min-width: 60px;
}

/* Produzione table — two-column flow */
.produzione-table {
  display: block;
  width: 100%;
}
.produzione-table thead {
  display: none;
}
.produzione-table tbody {
  display: block;
  columns: 2;
  column-gap: 32px;
}
.produzione-table tbody tr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  break-inside: avoid;
}
.produzione-table tbody tr td {
  padding: 0;
  border: none;
}
.produzione-table tbody tr td:first-child {
  font-size: 13px;
  color: var(--text-main);
}
.produzione-table tbody tr td:last-child {
  text-align: center;
  width: auto;
  flex-shrink: 0;
}
.produzione-table .tbl-group-hdr {
  break-inside: avoid;
  break-after: avoid;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 6px 10px !important;
  margin-top: 6px;
  border-bottom: none;
}
.produzione-table .tbl-group-hdr:first-child {
  margin-top: 0;
}
.produzione-table .tbl-group-hdr td {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
}
body.portal-gestione #produzionePopup.gestione-inline-panel {
  max-width: none;
}

.map-controls-stack {
  top: 14px;
  right: 14px;
  bottom: 34px;
}

.map-controls-topright,
.map-nav-window {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
}

.map-nav-window .nav-window-title {
  color: var(--text-main);
}

header {
  animation: ui-fade-in 450ms ease both;
}

.portal-tabs {
  animation: ui-fade-in 550ms ease both;
}

.sidebar {
  animation: ui-rise-in 620ms ease both;
}

.map-container {
  animation: ui-rise-in 700ms ease both;
}

@keyframes ui-fade-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes ui-rise-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
