/* =========================================================================
   HubLEM - stile applicativo
   Estende Bootstrap 5 senza sovrascriverne i componenti.
   ========================================================================= */

:root {
  --app-sidebar-width: 17.5rem;
  --app-navbar-height: 3.5rem;
  --app-sidebar-bg: #10233c;
  --app-sidebar-fg: #d6e1f0;
  --app-sidebar-fg-active: #ffffff;
  --app-sidebar-active-bg: rgba(255, 255, 255, .1);
}

body.app-body {
  background-color: var(--bs-tertiary-bg);
  min-height: 100vh;
}

/* --- Struttura ---------------------------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: var(--app-sidebar-width);
}

.app-content {
  flex: 1 1 auto;
}

.app-footer {
  border-top: 1px solid var(--bs-border-color);
  padding: .75rem 0;
  font-size: .8125rem;
  background-color: var(--bs-body-bg);
}

/* --- Sidebar ------------------------------------------------------------ */
.app-sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--app-sidebar-width);
  background-color: var(--app-sidebar-bg);
  color: var(--app-sidebar-fg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
}

.app-sidebar__brand {
  flex-shrink: 0;
  height: var(--app-navbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.app-sidebar__brand a { color: #fff; }

.app-sidebar__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: .5rem;
  background: linear-gradient(135deg, var(--bs-primary), #4dabf7);
  color: #fff;
}

.app-sidebar__title {
  font-weight: 600;
  letter-spacing: .02em;
}

.app-sidebar__company {
  padding: .85rem 1.15rem .5rem;
  flex-shrink: 0;
}

.app-sidebar__company .small { color: rgba(255, 255, 255, .55); }
.app-sidebar__company .fw-semibold { color: #fff; }

.app-sidebar__nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #52647c transparent;
  padding: .2rem .65rem .8rem;
}

.app-sidebar .nav-link {
  color: var(--app-sidebar-fg);
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  border-radius: .5rem;
  padding: .6rem .75rem;
  font-size: .875rem;
  line-height: 1.45;
  margin: .1rem 0;
}
.app-sidebar .nav-link i { width: 1.1rem; flex-shrink: 0; opacity: .8; }
.app-sidebar .nav-link span { overflow-wrap: anywhere; }

.app-sidebar .nav-link:hover { background-color: rgba(255, 255, 255, .06); color: #fff; }

.app-sidebar .nav-link.active {
  background-color: #214c70;
  color: var(--app-sidebar-fg-active);
  box-shadow: inset .1875rem 0 0 #70d6ca;
  font-weight: 600;
}

/* Moduli non ancora implementati: visibili ma non cliccabili. */
.app-sidebar .nav-link.disabled-item {
  opacity: .45;
  pointer-events: none;
}

.app-sidebar__footer {
  flex-shrink: 0;
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, .08);
  color: rgba(255, 255, 255, .55);
}

.app-sidebar__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 1035;
}

/* --- Navbar ------------------------------------------------------------- */
.app-navbar {
  height: var(--app-navbar-height);
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 1rem;
  background-color: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  position: sticky;
  top: 0;
  z-index: 1030;
}

.app-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background-color: var(--bs-primary);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
}

/* --- Card metriche ------------------------------------------------------ */
.metric-card { position: relative; transition: box-shadow .15s ease-in-out; }
.metric-card:hover { box-shadow: var(--bs-box-shadow-sm); }
.metric-card--pending { opacity: .7; }

.metric-card__icon { font-size: 1.5rem; line-height: 1; }
.metric-card__value { font-size: 1.75rem; font-weight: 600; line-height: 1.2; margin-top: .5rem; }
.metric-card__label { color: var(--bs-secondary-color); font-size: .875rem; }

/* --- Elementi comuni ---------------------------------------------------- */
.detail-list dt { font-weight: 500; color: var(--bs-secondary-color); }
.detail-list dd { margin-bottom: .5rem; }

.empty-state__icon { font-size: 3rem; color: var(--bs-secondary-color); line-height: 1; }

.audit-json {
  background-color: var(--bs-tertiary-bg);
  border-radius: .375rem;
  padding: .75rem;
  font-size: .8125rem;
  max-height: 18rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.flash-stack .alert:last-child { margin-bottom: 1rem; }

/* --- Mappa clienti ----------------------------------------------------- */
.customer-map {
  position: relative;
  min-height: 34rem;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background-color: #e9ecef;
  background-image:
    linear-gradient(rgba(108, 117, 125, .12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108, 117, 125, .12) 1px, transparent 1px);
  background-size: 32px 32px;
}

.customer-map.is-dragging { cursor: grabbing; }
.customer-map__tiles,
.customer-map__markers { position: absolute; inset: 0; }
.customer-map__tile { position: absolute; width: 256px; height: 256px; user-select: none; }

.customer-map__marker {
  position: absolute;
  transform: translate(-50%, -100%);
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  rotate: -45deg;
  background: var(--bs-primary);
  color: #fff;
  box-shadow: 0 .15rem .4rem rgba(0, 0, 0, .35);
  font-size: .7rem;
  font-weight: 700;
  cursor: pointer;
}

.customer-map__marker > span { rotate: 45deg; }
.customer-map__marker:focus-visible { outline: .2rem solid rgba(var(--bs-primary-rgb), .45); outline-offset: .15rem; }

.customer-map__controls { position: absolute; top: 1rem; left: 1rem; z-index: 3; }
.customer-map__controls .btn { width: 2.5rem; box-shadow: var(--bs-box-shadow-sm); }

.customer-map__detail {
  position: absolute;
  z-index: 3;
  left: 1rem;
  bottom: 1rem;
  max-width: min(24rem, calc(100% - 2rem));
  padding: .75rem;
  border: 1px solid var(--bs-border-color);
  border-radius: .5rem;
  background: var(--bs-body-bg);
}

.customer-map__attribution {
  position: absolute;
  right: .25rem;
  bottom: .25rem;
  z-index: 2;
  padding: .1rem .3rem;
  background: rgba(255, 255, 255, .9);
  color: #333;
  font-size: .68rem;
}

.raee-zone-map { min-height: 30rem; cursor: crosshair; }
.raee-zone-map__overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.raee-zone-map__existing { fill: rgba(108, 117, 125, .10); stroke: #6c757d; stroke-width: 1.5; }
.raee-zone-map__draft { fill: rgba(var(--bs-primary-rgb), .18); stroke: var(--bs-primary); stroke-width: 2.5; }
.raee-zone-map__vertex { fill: var(--bs-primary); stroke: #fff; stroke-width: 2; }

/* --- Login -------------------------------------------------------------- */
.app-public {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #10233c 0%, #1c3f66 100%);
}

.login-wrapper { width: 100%; max-width: 26rem; }
.login-card { border: none; border-radius: .75rem; }

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: .875rem;
  background: linear-gradient(135deg, var(--bs-primary), #4dabf7);
  color: #fff;
  font-size: 1.5rem;
}

/* --- Pagine di errore --------------------------------------------------- */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.error-page__icon { font-size: 3.5rem; }
.error-page__code { font-size: 3rem; font-weight: 700; line-height: 1; }

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 991.98px) {
  .app-main { margin-left: 0; }

  .app-sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease-in-out;
  }

  .app-sidebar.is-open { transform: translateX(0); }
}

@media (min-width: 992px) {
  .app-sidebar__backdrop { display: none !important; }

  /* Menu ridimensionabile e richiudibile (2026-10-22): larghezza e stato
     restano sul dispositivo; nascosto, riappare portando il mouse a sinistra. */
  .app-sidebar { transition: transform .18s ease, box-shadow .18s ease; }
  .app-main { transition: margin-left .18s ease; }
  body.sidebar-collapsed .app-main { margin-left: 0; }
  body.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
  body.sidebar-collapsed .app-sidebar.is-peek { transform: translateX(0); box-shadow: 0 0 40px rgba(15, 23, 42, .22); }
  body.sidebar-collapsed .app-sidebar__hotzone { display: block; }
  body.sidebar-resizing { cursor: col-resize; user-select: none; }
  body.sidebar-resizing .app-main,
  body.sidebar-resizing .app-sidebar { transition: none; }
  .app-sidebar__resizer {
    position: absolute; top: 0; right: 0; bottom: 0; width: 6px;
    cursor: col-resize; z-index: 2; background: transparent;
  }
  .app-sidebar__resizer:hover,
  .app-sidebar__resizer:focus-visible,
  .app-sidebar__resizer.is-dragging { background: rgba(37, 99, 235, .35); outline: none; }
  body.sidebar-collapsed .app-sidebar__resizer { display: none; }
}
.app-sidebar__hotzone { display: none; position: fixed; top: 0; bottom: 0; left: 0; width: 12px; z-index: 1039; }
@media (max-width: 991.98px) { .app-sidebar__resizer { display: none; } }

/* --- Stampa ------------------------------------------------------------- */
@media print {
  .app-sidebar,
  .app-navbar,
  .app-footer,
  .btn { display: none !important; }

  .app-main { margin-left: 0; }
}
/* Native details keep section navigation operable with keyboard and without JS. */
.app-sidebar__eyebrow { color: #a5b8cf; font-size: .66rem; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; margin-bottom: .25rem; }
.app-sidebar__home { padding-bottom: .6rem; margin-bottom: .45rem; border-bottom: 1px solid #ffffff15; }
.app-sidebar__home > .app-sidebar__eyebrow { padding: .4rem .75rem; }
.app-sidebar__section { margin: .15rem 0; }
.app-sidebar__section > summary { display: flex; align-items: center; gap: .65rem; cursor: pointer; border-radius: .5rem; padding: .7rem .75rem; font-size: .82rem; font-weight: 600; list-style: none; color: #e2ebf7; }
.app-sidebar__section > summary::-webkit-details-marker { display: none; }
.app-sidebar__section > summary > span { flex: 1; }
.app-sidebar__section > summary > i:first-child { color: #a6bdd8; width: 1.1rem; }
.app-sidebar__section > summary:hover { background: #ffffff09; }
.app-sidebar__section[open] > summary, .app-sidebar__section.is-current > summary { color: #8ee3d8; }
.app-sidebar__section > ul { border-left: 1px solid #ffffff1f; margin: .15rem 0 .6rem 1.25rem; padding-left: .4rem; }
.app-sidebar__chevron { font-size: .65rem; transition: transform .15s ease; }
.app-sidebar__section[open] > summary .app-sidebar__chevron { transform: rotate(180deg); }
.app-sidebar :is(a, button, summary):focus-visible { outline: 2px solid #8ee3d8; outline-offset: -2px; }
.app-sidebar__search { display: flex; align-items: center; gap: .5rem; margin: .55rem 1rem .8rem; padding: .5rem .6rem; border: 1px solid #465b76; border-radius: .55rem; color: #acc0d8; background: #0b1b30; flex-shrink: 0; }
.app-sidebar__search:focus-within { border-color: #8ee3d8; box-shadow: 0 0 0 2px #8ee3d833; }
.app-sidebar__search input { width: 100%; min-width: 0; border: 0; outline: none; color: #fff; background: transparent; font-size: .82rem; }
.app-sidebar__search input::placeholder { color: #b6c4d6; opacity: 1; }
.app-sidebar__search input::-webkit-search-cancel-button { display: none; }
.app-sidebar__search button { border: 0; padding: .1rem; background: transparent; color: #d6e1f0; }
.app-sidebar__search kbd { white-space: nowrap; font-size: .6rem; background: #263c58; color: #c3d1e2; padding: .15rem .25rem; }
.app-sidebar__empty { font-size: .85rem; padding: 1rem; color: #c3d1e2; }
.app-sidebar [hidden] { display: none !important; }
body.sidebar-open { overflow: hidden; }
@media (max-width: 991.98px) { .app-sidebar { width: min(var(--app-sidebar-width), calc(100vw - 3rem)); } }
@media (prefers-reduced-motion: reduce) { .app-sidebar, .app-sidebar__chevron { transition: none; } }

/* Pannelli di sezione (ADR-259) */
.section-panel-card { transition: box-shadow .15s ease, transform .15s ease; }
.section-panel-card:hover, .section-panel-card:focus-visible { box-shadow: 0 .35rem 1rem rgba(15, 35, 70, .12); transform: translateY(-1px); }
.section-panel-card__icon { flex: 0 0 2.5rem; height: 2.5rem; border-radius: .6rem; display: inline-flex; align-items: center; justify-content: center; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); font-size: 1.15rem; }

/* Pagine pubbliche (login): gli avvisi stanno sopra il riquadro, non al suo fianco (2026-10-06). */
.app-public { flex-direction: column; }
.app-public > .flash-stack { width: 100%; max-width: 26rem; }
.app-public > .flash-stack .alert { box-shadow: 0 10px 25px -5px rgba(0, 0, 0, .25); }
.password-group > .form-control { border-right: 0; }
.password-group > .password-toggle { border-color: var(--bs-border-color); background: #fff; min-width: 2.75rem; }

/* --- Assistente di supporto (2026-10-06) -------------------------------- */
.assistant-launcher {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 1045;
  display: inline-flex; align-items: center; gap: .5rem;
  border: 0; border-radius: 999px; padding: .65rem 1.1rem;
  background: #198754; color: #fff; font-weight: 600;
  box-shadow: 0 .5rem 1.25rem rgba(0, 0, 0, .25);
}
.assistant-launcher:hover, .assistant-launcher:focus-visible { background: #157347; color: #fff; }
.assistant-launcher .bi { font-size: 1.2rem; }
.assistant-launcher.is-open { display: none; }
.assistant-panel {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 1046;
  width: min(400px, calc(100vw - 2rem)); height: min(620px, calc(100vh - 2rem));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bs-body-bg); color: var(--bs-body-color);
  border-radius: 1rem; box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, .3);
}
.assistant-panel[hidden] { display: none; }
.assistant-panel__header {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .75rem .9rem; background: #198754; color: #fff;
}
.assistant-panel__avatar {
  width: 2.2rem; height: 2.2rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .2); font-size: 1.15rem;
}
.assistant-panel__messages { flex: 1 1 auto; overflow-y: auto; padding: .9rem; display: flex; flex-direction: column; gap: .6rem; }
.assistant-msg { max-width: 88%; padding: .55rem .8rem; border-radius: .9rem; font-size: .92rem; line-height: 1.4; overflow-wrap: anywhere; }
.assistant-msg p { margin: 0 0 .4rem; }
.assistant-msg p:last-child, .assistant-msg ul:last-child { margin-bottom: 0; }
.assistant-msg ul { padding-left: 1.1rem; margin: 0 0 .4rem; }
.assistant-msg--bot { align-self: flex-start; background: var(--bs-tertiary-bg); border-bottom-left-radius: .25rem; }
.assistant-msg--user { align-self: flex-end; background: #198754; color: #fff; border-bottom-right-radius: .25rem; white-space: pre-wrap; }
.assistant-msg--waiting { opacity: .7; font-style: italic; }
.assistant-msg--unanswered { border-left: 3px solid var(--bs-warning); }
.assistant-msg--error { background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); }
.assistant-panel__form { display: flex; gap: .5rem; padding: .6rem .75rem; border-top: 1px solid var(--bs-border-color); }
.assistant-panel__form textarea {
  flex: 1 1 auto; resize: none; border: 1px solid var(--bs-border-color); border-radius: .6rem; padding: .45rem .6rem;
  background: var(--bs-body-bg); color: var(--bs-body-color); font-size: .95rem;
}
.assistant-panel__note { padding: 0 .9rem .6rem; font-size: .72rem; color: var(--bs-secondary-color); }
@media (max-width: 575.98px) {
  .assistant-launcher { right: .75rem; bottom: .75rem; padding: .6rem .9rem; }
  .assistant-launcher span { display: none; }
  .assistant-panel { right: 0; bottom: 0; width: 100vw; height: 100dvh; border-radius: 0; }
}
@media print { .assistant-launcher, .assistant-panel { display: none !important; } }
body.app-body .assistant-panel, body.app-body .assistant-panel *, body.app-body .assistant-launcher { text-transform: none; letter-spacing: normal; }
