/* ==========================================================================
   Gesthes — base: reset, tipografia, struttura (menu, barra in alto, contenuto)
   ========================================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body.modal-open {
  overflow: hidden;
}

/* I codici (commesse, dipendenti, pratiche) restano in Archivo: cifre a larghezza
   fissa e un filo più larghi, senza un secondo carattere monospaziato. */
code,
.mono {
  font-family: var(--font);
  font-variant-numeric: tabular-nums slashed-zero;
  font-stretch: 106%;
  letter-spacing: .01em;
}
a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}
a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}
::selection {
  background: var(--accent-soft);
  color: var(--text);
}
h1 {
  font-size: 26px;
  font-weight: 760;
  font-stretch: var(--wide);
  letter-spacing: -.012em;
  line-height: 1.15;
  text-wrap: balance;
}
h2 {
  font-size: 15px;
  font-weight: 650;
  line-height: 1.3;
}
h3 {
  font-size: 13.5px;
  font-weight: 650;
}
input,
select,
textarea,
button {
  font-family: inherit;
}
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* barre di scorrimento sottili */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 99px;
  background-clip: padding-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ---- Struttura ------------------------------------------------------------- */
.layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.content {
  flex: 1;
  padding: 28px 32px 64px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.logo-dark {
  display: none;
}
:root[data-theme="dark"] .logo-light {
  display: none;
}
:root[data-theme="dark"] .logo-dark {
  display: block;
}

/* ---- Menu laterale (blu THES in entrambi i temi) ------------------------------ */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--side-bg);
  color: var(--side-ink2);
  border-right: 1px solid var(--side-line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  scrollbar-color: rgba(255, 255, 255, .2) transparent;
  transition: width var(--t-med) var(--ease);
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .2);
  background-clip: padding-box;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding: 22px 20px 18px;
}
.brand-link {
  display: block;
  line-height: 0;
  border-radius: var(--radius-xs);
}
.brand-logo {
  height: 30px;
  width: auto;
}
.brand-mark {
  display: none;
  height: 30px;
  width: auto;
}
.brand .name {
  font-size: 17px;
  font-weight: 760;
  font-stretch: var(--wider);
  letter-spacing: .005em;
  line-height: 1.1;
  color: var(--side-ink);
}
.brand .sub {
  font-size: 12.5px;
  color: var(--side-ink3);
  line-height: 1.35;
  margin-top: 3px;
}
.brand-text {
  min-width: 0;
}

.topbar-brand {
  display: none;
  flex-shrink: 0;
  line-height: 0;
}
.topbar-brand img {
  height: 24px;
  width: auto;
}

/* solo le voci scorrono: logo e utente restano sempre visibili */
.nav {
  padding: 4px 12px 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 10px;
}
.nav-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--side-ink3);
  padding: 6px 12px 6px;
  white-space: nowrap;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--side-ink2);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item:hover {
  background: var(--side-hover);
  color: var(--side-ink);
  text-decoration: none;
}
.nav-item.active {
  background: var(--side-active);
  color: var(--side-ink);
  font-weight: 650;
}
/* La voce attiva è «collegata» al bordo del menu da una traccia rossa che finisce
   in un nodo ad anello: lo stesso segno dei circuiti nel logo THES. */
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 12px;
  height: 2px;
  margin-top: -1px;
  background: var(--side-trace);
}
.nav-item.active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 9px;
  height: 9px;
  border: 2px solid var(--side-trace);
  border-radius: 50%;
  background: var(--side-bg);
  transform: translate(-50%, -50%);
}
.nav-item:focus-visible {
  outline-color: #FFFFFF;
}
.nav-ico {
  display: inline-flex;
  flex: none;
}
.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item .nav-badge {
  margin-left: auto;
  min-width: 22px;
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 20px;
  background: rgba(255, 255, 255, .16);
  color: var(--side-ink);
  border-radius: var(--radius-pill);
  padding: 0 7px;
  text-align: center;
}
.side-toggle {
  margin: 0 12px 10px;
  width: auto;
  color: var(--side-ink3);
  font-size: 13px;
}
.side-toggle svg {
  transition: transform var(--t-med) var(--ease);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--side-line);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.side-user {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-xs);
}
a.side-user:hover {
  text-decoration: none;
}
a.side-user:hover .uname {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.side-user .uname {
  font-size: 13.5px;
  font-weight: 650;
  color: var(--side-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-user .urole {
  font-size: 12px;
  color: var(--side-ink3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  font-stretch: var(--wide);
  letter-spacing: .02em;
}
.sidebar .avatar {
  background: #FFFFFF;
  color: var(--brand-navy);
  text-decoration: none;
}
.sidebar .iconbtn {
  border-color: transparent;
  color: var(--side-ink3);
  background: none;
}
.sidebar .iconbtn:hover {
  background: var(--side-hover);
  color: var(--side-ink);
}

/* Menu ridotto a sole icone (preferenza salvata nel browser) */
@media (min-width: 901px) {
  .layout.side-mini .sidebar {
    width: var(--sidebar-w-mini);
  }
  .layout.side-mini .brand {
    align-items: center;
    padding: 22px 0 18px;
  }
  .layout.side-mini .brand-logo,
  .layout.side-mini .brand-text,
  .layout.side-mini .nav-label,
  .layout.side-mini .side-user,
  .layout.side-mini .side-key {
    display: none;
  }
  .layout.side-mini .brand-mark {
    display: block;
  }
  .layout.side-mini .nav-group-label {
    height: 1px;
    padding: 0;
    margin: 6px 10px 12px;
    background: var(--side-line);
    color: transparent;
    overflow: hidden;
  }
  .layout.side-mini .nav-item {
    justify-content: center;
    padding: 9px 0;
  }
  .layout.side-mini .nav-item .nav-badge {
    position: absolute;
    top: 2px;
    right: 3px;
    min-width: 18px;
    line-height: 16px;
    font-size: 10.5px;
    padding: 0 4px;
    background: var(--side-trace);
  }
  .layout.side-mini .side-toggle {
    margin: 0 12px 10px;
  }
  .layout.side-mini .side-toggle svg {
    transform: rotate(180deg);
  }
  .layout.side-mini .sidebar-footer {
    flex-direction: column;
    padding: 14px 0;
  }
}

/* ---- Barra in alto ----------------------------------------------------------- */
.topbar {
  min-height: var(--topbar-h);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-spacer {
  flex: 1;
}

/* percorso: sezione > pagina corrente */
.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13.5px;
  color: var(--text2);
}
.crumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text2);
  font-weight: 550;
  white-space: nowrap;
  padding: 4px 6px;
  margin-left: -6px;
  border-radius: var(--radius-xs);
}
a.crumb:hover {
  color: var(--text);
  background: var(--surface2);
  text-decoration: none;
}
.crumb svg {
  width: 16px;
  height: 16px;
  color: var(--text3);
}
.crumb-sep {
  display: inline-flex;
  color: var(--text3);
}
.crumb-sep svg {
  width: 14px;
  height: 14px;
}
.crumb-current {
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.searchbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--control-h);
  flex: 0 1 300px;
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 8px 0 11px;
  color: var(--text3);
  background: var(--surface);
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.searchbox:hover {
  border-color: var(--border-strong);
  color: var(--text2);
}
.searchbox svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.searchbox-label {
  flex: 1;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.searchbox kbd,
kbd {
  font: 600 11px/1 var(--font);
  color: var(--text3);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 6px;
  white-space: nowrap;
}

.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--control-h);
  font: 550 13px/1 var(--font);
  color: var(--text2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tbtn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border-strong);
}
.tbtn-ico {
  display: inline-flex;
  flex: none;
}
.tbtn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}
.tbtn svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.iconbtn {
  width: var(--control-h);
  height: var(--control-h);
  flex: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.iconbtn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border-strong);
}
.iconbtn svg {
  width: 16px;
  height: 16px;
}
.iconbtn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}

.company-switcher {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 6px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--t-fast) var(--ease);
}
.company-switcher:hover {
  border-color: var(--border-strong);
}
.company-switcher:focus-within {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.company-switcher .cs-ico,
.company-chip .cs-ico {
  display: inline-flex;
  color: var(--text3);
}
.company-switcher .cs-ico svg,
.company-chip .cs-ico svg {
  width: 16px;
  height: 16px;
}
.company-select {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  padding: 4px 2px;
  cursor: pointer;
  outline: none;
  max-width: 200px;
}
.company-select option {
  background: var(--surface);
  color: var(--text);
}
.company-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--control-h);
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text2);
}

/* ---- Notifiche --------------------------------------------------------------- */
.notif-wrap {
  position: relative;
  display: inline-flex;
}
.notif-btn {
  position: relative;
}
.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--brand-red);
  color: #FFFFFF;
  font: 700 11px/18px var(--font);
  font-variant-numeric: tabular-nums;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.notif-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - 24px);
  max-height: 72vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 120;
}
.notif-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  font-size: 15px;
  font-weight: 650;
  z-index: 1;
}
.notif-empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--text3);
  font-size: 13.5px;
}
.notif-item {
  position: relative;
  display: block;
  padding: 12px 18px 12px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.notif-item:last-child {
  border-bottom: none;
}
.notif-item:hover {
  background: var(--row-hover);
  text-decoration: none;
  color: var(--text);
}
.notif-item.unread {
  background: var(--accent-soft);
  background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface));
}
.notif-item.unread::after {
  content: "";
  position: absolute;
  right: 18px;
  top: 18px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.notif-item.unread:hover {
  background: var(--accent-soft);
}
.notif-item-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  font-weight: 650;
  padding-right: 18px;
}
.notif-item-title .notif-ico {
  display: inline-flex;
  color: var(--warn);
  flex-shrink: 0;
}
.notif-item-title .notif-ico svg {
  width: 16px;
  height: 16px;
}
.notif-item-body {
  font-size: 13px;
  color: var(--text2);
  margin: 3px 0 0 25px;
}
.notif-item-time {
  font-size: 12px;
  color: var(--text3);
  margin: 4px 0 0 25px;
}
.linkbtn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  padding: 0;
  transition: color var(--t-fast) var(--ease);
}
.linkbtn:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

/* ---- Intestazione di pagina --------------------------------------------------- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 14px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head .grow {
  flex: 1;
  min-width: 240px;
}
.page-head h1 + .page-sub {
  margin-top: 6px;
}
.page-sub {
  color: var(--text2);
  font-size: 14px;
  margin-top: 4px;
}

/* importi oscurati */
body[data-mask="1"] [data-amt] {
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
}

/* ---- Telefono e tablet ---------------------------------------------------------- */
#menuBtn {
  display: none;
}
.scrim {
  display: none;
}
@media (max-width: 900px) {
  #menuBtn {
    display: inline-flex;
  }
  .topbar-brand {
    display: block;
  }
  .crumbs {
    display: none;
  }
  .sidebar {
    position: fixed;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--t-med) var(--ease);
  }
  .sidebar.open {
    transform: none;
    box-shadow: var(--shadow-lg);
  }
  .side-toggle {
    display: none;
  }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-med) var(--ease);
  }
  .sidebar.open + .scrim {
    opacity: 1;
    pointer-events: auto;
  }
  .topbar {
    padding: 10px 16px;
  }
  .content {
    padding: 20px 16px 40px;
  }
  .tbtn .tbtn-label {
    display: none;
  }
  .tbtn {
    width: var(--control-h);
    padding: 0;
    justify-content: center;
  }
  .searchbox {
    min-width: 0;
  }
}
@media (max-width: 720px) {
  .company-select {
    max-width: 120px;
  }
  .searchbox {
    flex: none;
    width: var(--control-h);
    min-width: 0;
    padding: 0;
    justify-content: center;
  }
  .searchbox .searchbox-label,
  .searchbox kbd {
    display: none;
  }
  h1 {
    font-size: 22px;
  }
}
/* sul telefono il tema si cambia dalla ricerca (Ctrl K) e il logo resta nel menu */
@media (max-width: 520px) {
  .topbar {
    gap: 6px;
  }
  .topbar-brand,
  .theme-btn {
    display: none;
  }
  .company-select {
    max-width: 104px;
  }
  .company-chip {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
