/* Layout: sidebar + top bar + content. Phone and tablet: the sidebar becomes a menu button. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs)/1.45 var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--fs-xl); } h2 { font-size: var(--fs-lg); } h3 { font-size: var(--fs-md); }
.ic { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; vertical-align: -0.25em; }
.muted { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { min-height: 100vh; }

/* ---- sidebar: white, 200 px, grey section bands, orange selection (mockup) ---- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--side); color: var(--side-text);
  border-right: 1px solid var(--side-line); box-shadow: 0 4px 6px rgba(0,0,0,.06);
  display: flex; flex-direction: column; z-index: 40; transition: width .15s ease; overflow: hidden; }
.sidebar-brand { min-height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 12px; border-bottom: 1px solid var(--surface-2); text-align: center; }
.sidebar-brand img { max-height: 48px; width: auto; max-width: 160px; }
.sidebar-brand .logo { font-weight: 900; font-size: var(--fs-2xl); letter-spacing: .01em; color: var(--link); white-space: nowrap; }
.sidebar-brand .who { font-size: var(--fs-2xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.nav { flex: 1; overflow-y: auto; padding: 4px 0 12px; }
.nav-title { margin-top: 8px; padding: 5px 16px; font-size: var(--fs-xs); font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  color: var(--side-head); background: var(--side-band); border-top: 1px solid var(--side-line); white-space: nowrap; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 16px; color: var(--side-text); font-size: var(--fs-sm); font-weight: 500;
  border-left: 3px solid transparent; white-space: nowrap; text-decoration: none; }
.nav-item .ic { color: var(--side-icon); font-size: var(--fs-lg); }
.nav-item:hover { background: var(--sel-hover); border-left-color: var(--sel); text-decoration: none; }
.nav-item.is-active { background: var(--sel-bg); border-left-color: var(--sel); font-weight: 700; }
.nav-item:hover .ic, .nav-item.is-active .ic { color: var(--sel); }
.nav-item.is-disabled { color: var(--text-3); cursor: default; }
.nav-item.is-disabled .ic { color: var(--text-3); }
.nav-item.is-disabled:hover { background: transparent; border-left-color: transparent; }
.nav-soon { margin-left: auto; font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.sidebar-foot { border-top: 1px solid var(--surface-2); padding: 6px; }
.sidebar-foot button { width: 100%; display: flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--text-2);
  font: 400 var(--fs-sm) var(--font); padding: 6px 8px; cursor: pointer; white-space: nowrap; }
.sidebar-foot button:hover { background: var(--alarm-bg); color: var(--alarm); }

/* ---- main ---- */
.main { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .15s ease; }
.side-collapsed .sidebar { width: var(--side-w-collapsed); }
.side-collapsed .main { margin-left: var(--side-w-collapsed); }
.side-collapsed .nav-label, .side-collapsed .nav-title, .side-collapsed .nav-soon,
.side-collapsed .sidebar-brand .who, .side-collapsed .sidebar-brand .logo { display: none; }
.side-collapsed .nav-item { padding: 9px 0; justify-content: center; }
.side-collapsed .sidebar-brand { min-height: var(--top-h); }

.topbar { position: sticky; top: 0; z-index: 30; height: var(--top-h); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 var(--gap); }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; background: transparent;
  color: var(--text-2); border-radius: var(--r); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; color: var(--text-2); }
.crumbs { font-size: var(--fs-sm); flex: 1 1 auto; }
.crumbs a { max-width: 180px; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; }
.crumbs a { color: var(--link); font-weight: 600; } .crumbs .sep { color: var(--text-3); }
.crumbs .here { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.top-spacer { flex: 1; }
.top-tools { display: flex; align-items: center; gap: 10px; flex: none; white-space: nowrap; }
.lang { display: inline-flex; }
.lang-select { width: auto; min-width: 96px; padding-top: 5px; padding-bottom: 5px; font-size: var(--fs-base); }
.select-company { max-width: 220px; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; cursor: pointer; padding: 4px 6px;
  border-radius: var(--r); color: var(--text); font: inherit; text-align: left; }
.user-btn:hover { background: var(--surface-2); }
.user-btn .who { line-height: 1.2; } .user-btn .who small { display: block; color: var(--text-2); font-size: var(--fs-xs); }
.user-btn .who { text-align: right; font-size: var(--fs-sm); font-weight: 600; }
.user-btn .who small { font-weight: 400; color: var(--text-3); font-size: var(--fs-2xs); }
.role-badge { font-family: var(--mono); font-size: var(--fs-2xs); letter-spacing: .06em; padding: 2px 7px; text-transform: uppercase; white-space: nowrap;
  border: 1px solid var(--brand-line); background: var(--brand-bg); color: var(--link); }
.role-badge.role-super { background: var(--role-super-bg); color: var(--role-super); border-color: var(--role-super-line); }
.role-badge.role-tecnico { background: var(--role-tec-bg); color: var(--role-tec); border-color: var(--role-tec-line); }
.role-badge.role-cliente { background: var(--role-cli-bg); color: var(--role-cli); border-color: var(--role-cli-line); }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); box-shadow: var(--pop-shadow); padding: 6px 0; display: none; z-index: 50; }
.dropdown.is-open { display: block; }
.dropdown a, .dropdown button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 8px 14px; border: 0; background: none;
  color: var(--text); font: inherit; cursor: pointer; text-align: left; text-decoration: none; }
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); }

.content { padding: 16px 16px 48px; max-width: 1320px; width: 100%; }
/* page header = the white ".top" bar of the mockup */
.page-h { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; margin-bottom: var(--gap);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 9px 14px; }
.page-h h1 { font-size: var(--fs-md); font-weight: 800; }
.page-h .sub { font-size: var(--fs-sm); }
.page-h .grow { flex: 1; min-width: 220px; }
.page-h .sub { color: var(--text-2); margin-top: 2px; }
.page-h .summary { display: flex; flex-wrap: wrap; gap: 6px; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; flex-wrap: wrap; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px 24px; }
.grid-3 h3 { margin-bottom: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--gap); }


/* ---- bare pages (login, errors) ---- */
.bare { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.bare-card { width: 100%; max-width: 380px; }
.bare-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; font-weight: 600; font-size: var(--fs-lg); }

/* ---- tablet and phone ---- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: var(--side-w) !important; transition: transform .18s ease; box-shadow: none; }
  .side-open .sidebar { box-shadow: 4px 0 18px rgba(0,0,0,.3); }
  .main, .side-collapsed .main { margin-left: 0; }
  .side-open .sidebar { transform: none; }
  .side-open::after { content: ""; position: fixed; inset: 0; background: var(--overlay); z-index: 35; }
  .side-collapsed .nav-label, .side-collapsed .nav-soon,
  .side-collapsed .sidebar-brand .who, .side-collapsed .sidebar-brand .logo { display: initial; }
  .side-collapsed .nav-title { display: block; }
  .side-collapsed .nav-item { padding: 8px 16px; justify-content: flex-start; }
  .user-btn .who, .select-company { display: none; }
  .content { padding: 12px 12px 32px; }
}
@media (max-width: 640px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .content { padding: 10px 10px 28px; }
  .icon-btn { width: 40px; height: 40px; }
  .top-tools { gap: 6px; min-width: 0; }
  .role-badge { display: none; }
  .crumbs { flex: 1 1 auto; }
  .top-spacer { display: none; }
}
.main { min-width: 0; }
@media (max-width: 520px) { .crumbs .sep, .crumbs a { display: none; } .lang { display: none; } }

/* 16/11: loghi dei marchi (spesso scuri) leggibili nel tema scuro */
:root[data-theme="dark"] .sidebar-brand img { background: var(--logo-bg); padding: 4px 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]):not([data-theme="dark"]) .sidebar-brand img { background: var(--logo-bg); padding: 4px 6px; } }

/* ---- 17/11: barra in alto più curata (stessi comandi, aspetto unico; angoli retti, solo colori del tema) ---- */
:root { --top-h: 54px; }
.topbar { gap: 16px; padding: 0 18px; box-shadow: 0 1px 3px rgba(15, 23, 42, .05); }
.crumbs { font-size: var(--fs-base); }
.top-tools { gap: 8px; }
.tb-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; flex: none; }
.top-spacer { display: none; }
.crumbs a { max-width: 220px; }
.topbar .qs-open { height: 34px; min-width: 230px; justify-content: flex-start; gap: 8px; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-3); font-weight: 400; padding: 0 8px 0 10px; }
.qs-open:hover { border-color: var(--input-line); color: var(--text-2); background: var(--surface); }
.qs-open kbd { margin-left: auto; background: var(--surface); }
.tb-field { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 0 0 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-3); }
.tb-field:hover { border-color: var(--input-line); }
.tb-field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); }
.tb-field > svg, .tb-field .icon { width: 16px; height: 16px; flex: none; }
.tb-select { appearance: none; -webkit-appearance: none; border: 0; outline: none; height: 32px; padding: 0 28px 0 0; cursor: pointer;
  font: 500 var(--fs-sm) var(--font); color: var(--text); background: transparent no-repeat right 9px center / 12px 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a93a2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.tb-select option, .tb-select optgroup { background: var(--surface); color: var(--text); }
.select-company { max-width: 230px; min-width: 150px; }
.lang-select { min-width: 0; width: auto; }
.tb-static { padding-right: 12px; }
.tb-static span { font-size: var(--fs-sm); font-weight: 500; color: var(--text); max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
.tb-icon { width: 34px; height: 34px; border: 1px solid transparent; }
.tb-icon:hover { border-color: var(--line); }
.tb-icon.is-active { background: var(--brand-bg); color: var(--link); border-color: var(--brand-line); }
.user-btn { gap: 10px; padding: 3px 8px 3px 3px; border: 1px solid transparent; }
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--surface-2); border-color: var(--line); }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: none; font: 700 var(--fs-xs) var(--font); letter-spacing: .04em;
  background: var(--brand-bg); color: var(--link); border: 1px solid var(--brand-line); }
.avatar.role-super { background: var(--role-super-bg); color: var(--role-super); border-color: var(--role-super-line); }
.avatar.role-tecnico { background: var(--role-tec-bg); color: var(--role-tec); border-color: var(--role-tec-line); }
.avatar.role-cliente { background: var(--role-cli-bg); color: var(--role-cli); border-color: var(--role-cli-line); }
.user-btn .who { text-align: left; font-size: var(--fs-sm); line-height: 1.25; }
.user-btn .who small { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: var(--fs-2xs); color: var(--text-3); }
.user-btn .who .role-badge { padding: 0 5px; line-height: 15px; font-size: var(--fs-2xs); }
.tb-chev { display: inline-flex; color: var(--text-3); } .tb-chev svg { width: 14px; height: 14px; }
.dropdown { top: calc(100% + 8px); min-width: 250px; }
.dd-head { padding: 8px 14px 10px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.dd-head strong { display: block; font-size: var(--fs-sm); }
.dd-head small { display: block; color: var(--text-3); font-size: var(--fs-xs); margin-top: 2px; }
@media (max-width: 1100px) { .topbar .qs-open { min-width: 0; } .qs-open .qs-label { display: none; } }
@media (max-width: 900px) { .tb-company, .tb-chev { display: none; } .user-btn { padding: 3px; } }
@media (max-width: 640px) { .tb-sep { display: none; } .topbar { padding: 0 8px; gap: 6px; } .topbar .qs-open { height: 40px; width: 40px; padding: 0; justify-content: center; } .avatar { width: 36px; height: 36px; } }
@media (max-width: 520px) { .lang.tb-field { display: none; } }
