/* ============================================================
   HRSTE Design System - Base (reset + tipografia + layout root)
   ============================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-1);
  font-family: var(--font-family);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--sp-3);
  color: var(--text-1);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
}

h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }

p {
  margin: 0 0 var(--sp-3);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

code, pre {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  background: var(--border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

pre {
  padding: var(--sp-3);
  overflow-x: auto;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

/* ---- Layout root ---- */

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-inv);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: width 180ms ease, transform 200ms ease;
}

/* ==== Backdrop mobile drawer ==== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
  opacity: 0;
  transition: opacity 180ms;
}

/* ==== Bottone hamburger mobile ==== */
.sidebar-mobile-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 25;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--bg-sidebar);
  color: #fff;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ==== SIDEBAR BRAND (stile BACHECA: logo tondo + titolo + sub) ==== */

.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand-primary, #d10000);   /* multi-tenant da bucket brand-hub */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 22px;
  box-shadow: 0 2px 8px var(--brand-primary-shadow, rgba(209, 0, 0, 0.3));
}
.brand-logo img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.brand-text {
  min-width: 0;    /* per truncate corretto */
}

.brand-title {
  color: white;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.brand-sub {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  margin-top: 3px;
  line-height: 1.3;
}

/* ==== Sidebar SEARCH ==== */
.sidebar-search {
  position: relative;
  padding: 12px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-30%);
  color: rgba(255,255,255,0.4);
  pointer-events: none;
}
.sidebar-search input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 120ms, background 120ms;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,0.35); }
.sidebar-search input:focus {
  border-color: var(--brand-primary, #d10000);
  background: rgba(255,255,255,0.08);
}
.sidebar-collapse-all {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-30%);
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  transition: color 120ms, background 120ms;
}
.sidebar-collapse-all:hover { color: #fff; background: rgba(255,255,255,0.08); }
.sidebar.is-compact .sidebar-collapse-all { display: none; }

/* ==== NAVIGATION ==== */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 12px;
  display: flex;
  flex-direction: column;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); border-radius: 3px; }

.nav-spacer { flex: 1; min-height: 8px; }

/* ==== Gruppi collapsibili ==== */
.nav-group { }
.nav-group { margin-top: 4px; }
.nav-group + .nav-group,
.nav-item-standalone { border-top: 1px solid rgba(255,255,255,0.07); }
.nav-item-standalone { padding-top: 12px; margin-top: 6px; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 16px 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.92);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-transform: none;
  cursor: pointer;
  text-align: left;
  transition: color 120ms, background 120ms;
  border-radius: 0;
}
.nav-group-toggle:hover { color: #fff; background: rgba(255,255,255,0.04); }
.nav-group[data-open="true"] .nav-group-toggle { color: #fff; }
.nav-group-toggle .chevron {
  width: 12px; height: 12px; flex-shrink: 0;
  transition: transform 180ms ease;
  color: rgba(255,255,255,0.55);
}
.nav-group-toggle:hover .chevron { color: #fff; }
.nav-group[data-open="true"] .nav-group-toggle .chevron { transform: rotate(90deg); color: #fff; }
.nav-group-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 200ms ease;
}
.nav-group[data-open="true"] .nav-group-items { max-height: 500px; }

/* ==== Voce di menu ==== */
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 16px 8px 20px;
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 100ms, color 100ms, border-color 100ms;
  position: relative;
}
.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: var(--brand-primary-soft, rgba(209, 0, 0, 0.18));
  color: #fff;
  border-left-color: var(--brand-primary, #d10000);
}
.nav-item.hide-search { display: none; }

.nav-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.85;
}
.nav-item.active .icon { opacity: 1; }
.nav-item .label { line-height: 1.3; }
/* Emoji dinamiche configurate dal cliente: filtro monocromatico per uniformita' */
.nav-emoji-icon {
  font-size: 15px; line-height: 1;
  filter: grayscale(1) brightness(1.8) contrast(1.1);
  opacity: 0.75;
  transition: opacity 100ms, filter 100ms;
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
}
.nav-item:hover .nav-emoji-icon,
.nav-item.active .nav-emoji-icon { opacity: 1; }
.sidebar.is-compact .nav-emoji-icon,
html.sidebar-preload-compact .sidebar .nav-emoji-icon { filter: none; opacity: 0.95; font-size: 18px; }

/* Voci "standalone" (senza gruppo, es. Dashboard/Manuale) allineate al padding delle voci di gruppo */
.nav-item-standalone { padding-left: 20px; }
.sidebar-nav > .nav-item { padding-left: 20px; }

/* ==== FOOTER con collapse toggle ==== */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  color: rgba(255,255,255,0.62);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.sidebar-collapse-btn:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.sidebar-version {
  font-size: 10.5px;
  color: rgba(255,255,255,0.35);
  padding: 0 4px;
  line-height: 1.4;
}
.sidebar-version strong { color: rgba(255,255,255,0.55); }

/* ==== Modalità COMPACT (icon rail) ==== */
/* html.sidebar-preload-compact è impostato inline nell'head PRIMA del CSS
   per evitare il flash di sidebar espansa al load quando l'utente ha scelto compact */
.sidebar.is-compact,
html.sidebar-preload-compact .sidebar { width: 60px; }
html.sidebar-preload-compact .main { margin-left: 60px; }
html.sidebar-preload-compact .sidebar .brand-text,
html.sidebar-preload-compact .sidebar .sidebar-search,
html.sidebar-preload-compact .sidebar .nav-group-toggle,
html.sidebar-preload-compact .sidebar .nav-item .label,
html.sidebar-preload-compact .sidebar .sidebar-version,
html.sidebar-preload-compact .sidebar .compact-label { display: none; }
html.sidebar-preload-compact .sidebar .sidebar-brand { justify-content: center; padding: 16px 8px; }
html.sidebar-preload-compact .sidebar .brand-logo { width: 38px; height: 38px; font-size: 18px; }
html.sidebar-preload-compact .sidebar .nav-item { padding: 10px 0; justify-content: center; }
html.sidebar-preload-compact .sidebar .nav-item .icon { width: 20px; height: 20px; }
html.sidebar-preload-compact .sidebar .sidebar-footer { padding: 10px 6px; align-items: center; }
html.sidebar-preload-compact .sidebar .sidebar-collapse-btn { padding: 8px; justify-content: center; }
html.sidebar-preload-compact .sidebar .nav-group + .nav-group { border-top: 1px solid rgba(255,255,255,0.06); margin-top: 6px; padding-top: 6px; }
.sidebar.is-compact .brand-text,
.sidebar.is-compact .sidebar-search,
.sidebar.is-compact .nav-group-toggle span,
.sidebar.is-compact .nav-item .label,
.sidebar.is-compact .sidebar-version,
.sidebar.is-compact .compact-label { display: none; }
.sidebar.is-compact .sidebar-brand { justify-content: center; padding: 16px 8px; }
.sidebar.is-compact .brand-logo { width: 38px; height: 38px; font-size: 18px; }
/* In modalità compact: nasconde intestazioni gruppo (niente più click strano);
   le voci del gruppo restano visibili come icone impilate */
.sidebar.is-compact .nav-group-toggle { display: none; }
.sidebar.is-compact .nav-group[data-open="true"] .nav-group-items,
.sidebar.is-compact .nav-group-items { max-height: none; }
/* Piccola separazione visiva tra gruppi */
.sidebar.is-compact .nav-group + .nav-group { border-top: 1px solid rgba(255,255,255,0.06); margin-top: 6px; padding-top: 6px; }
.sidebar.is-compact .nav-item { padding: 10px 0; justify-content: center; }
.sidebar.is-compact .nav-item .icon { width: 20px; height: 20px; }
.sidebar.is-compact .sidebar-footer { padding: 10px 6px; align-items: center; }
.sidebar.is-compact .sidebar-collapse-btn { padding: 8px; }
.sidebar.is-compact .sidebar-collapse-btn { justify-content: center; }
.sidebar.is-compact + .sidebar-backdrop ~ .main,
.app-shell:has(.sidebar.is-compact) .main { margin-left: 60px; }

/* Tooltip fluttuante JS (body-scoped, non tagliato dallo scroll della sidebar) */
.sidebar-tooltip {
  position: fixed;
  transform: translateY(-50%);
  background: #1e293b;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.sidebar-tooltip.visible { opacity: 1; }
.sidebar-tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: #1e293b;
}

/* ==== RESPONSIVE ==== */
/* Tablet portrait / small laptop: auto-compact */
@media (max-width: 1023px) {
  .sidebar { width: 60px; }
  .sidebar .brand-text,
  .sidebar .sidebar-search,
  .sidebar .nav-group-toggle span,
  .sidebar .nav-item .label,
  .sidebar .sidebar-version,
  .sidebar .compact-label { display: none; }
  .sidebar .sidebar-brand { justify-content: center; padding: 16px 8px; }
  .sidebar .brand-logo { width: 38px; height: 38px; font-size: 18px; }
  .sidebar .nav-group-toggle { display: none; }
  .sidebar .nav-group-items { max-height: none; }
  .sidebar .nav-group + .nav-group { border-top: 1px solid rgba(255,255,255,0.06); margin-top: 6px; padding-top: 6px; }
  .sidebar .nav-item { padding: 10px 0; justify-content: center; }
  .sidebar .nav-item .icon { width: 20px; height: 20px; }
  .sidebar .sidebar-footer { padding: 10px 6px; align-items: center; }
  .sidebar .sidebar-collapse-btn { padding: 8px; justify-content: center; }
  .main { margin-left: 60px !important; }
  /* tooltip via JS (vedi window.hrsteSidebar) */
}

/* Mobile: sidebar nascosta + hamburger + drawer */
@media (max-width: 767px) {
  .sidebar-mobile-toggle { display: flex; }
  .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }
  .sidebar .brand-text,
  .sidebar .sidebar-search,
  .sidebar .nav-group-toggle span,
  .sidebar .nav-item .label,
  .sidebar .sidebar-version,
  .sidebar .compact-label { display: block; }
  .sidebar .nav-item { justify-content: flex-start; padding: 8px 16px 8px 20px; }
  .sidebar .nav-item .icon { width: 18px; height: 18px; }
  .sidebar .sidebar-brand { padding: 20px 16px 16px; justify-content: flex-start; }
  .sidebar .nav-group-toggle { justify-content: flex-start; padding: 10px 16px 6px; }
  .sidebar .nav-group-toggle .chevron { display: block; }
  .sidebar .nav-group-toggle span { display: inline; }
  .sidebar .nav-item::after { display: none; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; opacity: 1; }
  .main { margin-left: 0 !important; }
  .topbar { padding-left: 60px; }
}

/* Su ≥1400px tutti i gruppi aperti di default */
@media (min-width: 1400px) {
  .sidebar-nav[data-mode="auto-expanded"] .nav-group-items {
    max-height: 500px;
  }
}

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

.topbar {
  height: 56px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: var(--sp-4);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}
.topbar-title a {
  color: var(--text-2);
  text-decoration: none;
  transition: color 120ms;
  font-weight: 500;
}
.topbar-title a:hover {
  color: var(--brand-primary, #d10000);
  text-decoration: underline;
}
.topbar-title .crumb-sep {
  opacity: 0.4;
  margin: 0 8px;
  font-weight: 400;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15,23,42,0.06);
  color: var(--text-2);
}

.user-avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(15,23,42,0.15);
}

.user-avatar-txt {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary, #d10000), var(--brand-primary-dark, #7f1d1d));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(209,0,0,0.25);
}

.user-info {
  line-height: 1.25;
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: 0.1px;
}

.user-role {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 3px;
  align-self: flex-start;
  background: #dbeafe;
  color: #1e40af;
}
/* Badge ruolo colorato in base al ruolo */
.user-role[data-ruolo="SUPER_ADMIN"] { background: #fee2e2; color: #991b1b; }
.user-role[data-ruolo="ADMIN"]        { background: #ffedd5; color: #9a3412; }
.user-role[data-ruolo="EDITOR"]       { background: #dcfce7; color: #166534; }
.user-role[data-ruolo="DATA_ENTRY"]   { background: #ede9fe; color: #5b21b6; }
.user-role[data-ruolo="VIEWER"]       { background: #f1f5f9; color: #475569; }

.btn-logout {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  transition: all 120ms;
  margin-left: 8px;
}
.btn-logout:hover {
  background: var(--bg-app);
  color: var(--text-1);
  text-decoration: none;
}

.content {
  flex: 1;
  padding: var(--sp-5);
  overflow-y: auto;
}

/* ---- Login page fullscreen ---- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--sp-7);
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-brand {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  color: var(--primary-dark);
  margin: 0 0 var(--sp-2);
}

.login-subtitle {
  color: var(--text-2);
  margin: 0 0 var(--sp-6);
}
