/* Editor dei referti (app.html) */
body.page-app{ height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.lib-source-editor{ display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); }
.lib-source-editor select{ width: auto; min-height: var(--h-sm); }

/* ---------- Accesso ---------- */
.auth{ position: fixed; inset: 0; z-index: 60; overflow: auto; display: flex; align-items: center; justify-content: center; padding: var(--s-5); background: var(--bg); }
.auth.hidden{ display: none; }
.auth__card{ width: min(420px, 100%); padding: var(--s-8) var(--s-6); }
.auth__card .brand{ margin-bottom: var(--s-5); }
.auth-view{ display: flex; flex-direction: column; gap: var(--s-3); }
.auth-view h1{ font-size: var(--fs-xl); margin-bottom: var(--s-1); }
.auth-links{ display: flex; flex-wrap: wrap; gap: 6px; font-size: var(--fs-sm); color: var(--text-muted); }
.auth-note{ font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.5; }
.auth-error{ font-size: var(--fs-sm); min-height: 1.2em; color: var(--danger); }
.auth-error.ok{ color: var(--success); }
.local-try{ margin-top: var(--s-2); padding-top: var(--s-4); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }

/* ---------- Struttura ---------- */
.app{ flex: 1; min-height: 0; display: flex; flex-direction: column; }
.app.hidden{ display: none; }
.workspace{ flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(380px, 42%) 1fr; }
.builder{ overflow-y: auto; padding: var(--s-4) var(--s-4) var(--s-12); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--s-3); }
.report{ min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: var(--s-4) var(--s-5); gap: var(--s-3); background: var(--bg); }
.mobile-switch{ display: none; }

/* ---------- Blocchi del builder ---------- */
.block{ background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md); }
.block__head{ display: flex; align-items: center; gap: var(--s-2); padding: 10px var(--s-4); border-bottom: 1px solid var(--border); }
.block__num{ font-size: var(--fs-xs); font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.block__title{ font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text); }
.block__hint{ margin-left: auto; font-size: var(--fs-xs); color: var(--text-subtle); }
.block__body{ padding: var(--s-3) var(--s-4) var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.group__label{ font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 6px; }
.empty-hint{ font-size: var(--fs-sm); color: var(--text-subtle); font-style: italic; }
.sample-note{ font-size: var(--fs-xs); color: var(--text-subtle); }

/* ---------- Referto ---------- */
.report__tabs{ display: flex; gap: 6px; flex-wrap: wrap; }
.wtab{
  position: relative; width: 32px; height: 32px; border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-muted); font-weight: 700; font-size: var(--fs-sm); cursor: pointer;
}
.wtab:hover{ border-color: var(--primary); color: var(--text); }
.wtab[aria-selected="true"]{ background: var(--primary-solid); border-color: var(--primary-solid); color: #fff; }
.wtab.has-content::after{ content: ''; position: absolute; top: -3px; right: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); border: 2px solid var(--bg); }
.report__toolbar{ display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.rec-pill{ display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 700; color: var(--danger); }
.rec-pill::before{ content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: mr-pulse 1.2s infinite; }
@keyframes mr-pulse{ 50%{ opacity: .3; } }
.report__doc{ flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.report__meta{ display: flex; align-items: center; gap: var(--s-2); padding: 8px var(--s-4); border-bottom: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); }
.report__meta strong{ color: var(--text); font-weight: 600; }
.report__text{
  flex: 1; min-height: 0; width: 100%; resize: none; border: 0; padding: var(--s-5) var(--s-6);
  background: var(--surface-1); color: var(--text); font-family: var(--font); font-size: 0.9375rem; line-height: 1.65;
}
.report__text:focus{ outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
.report__footer{ padding: 6px var(--s-4); border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: var(--s-2); }
.mini-toggle{ height: 26px; padding: 0 10px; border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: transparent; color: var(--text-muted); font-size: var(--fs-xs); font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.mini-toggle[aria-pressed="true"]{ background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }

/* ---------- Frasi: gruppi di sezione, opzionali, referto negativo ---------- */
.group--section .group__label{ color: var(--primary); }
.phrase--optional{ border-left-color: var(--border-strong); }
.phrase--optional .icon{ color: var(--text-muted); }
.btn-pair{ display: inline-flex; gap: 4px; margin-left: var(--s-2); }
.btn-pair[hidden]{ display: none; }
.negativo-list{ display: flex; flex-direction: column; gap: var(--s-3); }
.negativo-group{ border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-2) var(--s-3) var(--s-3); margin: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.negativo-group legend{ font-size: var(--fs-sm); font-weight: 600; color: var(--text); padding: 0 4px; }

/* ---------- Copia (pulsante diviso) ---------- */
.split{ display: inline-flex; }
.split > .btn:first-child{ border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split__more{ border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255, 255, 255, .28); width: 30px; }

/* ---------- Campi da compilare ---------- */
.field-bar{ display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); padding: 6px var(--s-4); border-bottom: 1px solid var(--border); background: var(--info-bg); }
.field-bar__label{ font-size: var(--fs-xs); font-weight: 700; color: var(--primary); }
.field-bar .chip{ min-height: 28px; padding: 3px 10px; }
.field-bar kbd{ margin-right: 2px; }
.field-bar__hint{ margin-left: auto; font-size: var(--fs-xs); }
#report-stats.has-fields{ color: var(--abnormal); font-weight: 600; }

/* ---------- Ricerca rapida ---------- */
dialog.dialog--palette{ width: min(640px, 94vw); margin-top: 12vh; }
.palette__search{ display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
.palette__search .icon{ color: var(--text-muted); }
.palette__search input{ flex: 1; border: 0; background: none; font-size: var(--fs-lg); color: var(--text); outline: none; }
.palette__list{ list-style: none; margin: 0; padding: var(--s-2); max-height: 52vh; overflow-y: auto; }
.palette__group{ padding: var(--s-2) var(--s-2) 4px; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-subtle); }
.palette__item{ display: flex; align-items: center; gap: var(--s-2); padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-sm); }
.palette__item[aria-selected="true"]{ background: var(--primary-soft); }
.palette__item .icon{ color: var(--text-muted); }
.palette__label{ flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__hint{ color: var(--text-subtle); font-size: var(--fs-xs); white-space: nowrap; }
.palette__empty{ padding: var(--s-4); color: var(--text-muted); text-align: center; }
.palette__foot{ padding: 8px var(--s-4); border-top: 1px solid var(--border); font-size: var(--fs-xs); }
.shortcuts{ display: grid; grid-template-columns: auto 1fr; gap: 8px var(--s-4); margin: 0; align-items: baseline; }
.shortcuts dt{ white-space: nowrap; }
.shortcuts dd{ margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }

/* ---------- Onboarding ---------- */
.onb-step{ display: flex; flex-direction: column; gap: var(--s-3); }

/* ---------- Stampa ---------- */
.print-fieldset{ border: 0; padding: 0; margin: 0; min-width: 0; }
.print-fieldset legend{ margin-bottom: 6px; }
.print-preview iframe{ width: 100%; height: 62vh; border: 1px solid var(--border); border-radius: var(--r-sm); background: #fff; }

/* ---------- Schermi medi: barra compatta ---------- */
@media (max-width: 1100px){
  .topnav a span, #user-badge{ position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .workspace{ grid-template-columns: minmax(320px, 45%) 1fr; }
}

/* ---------- Schermi piccoli: una colonna con selettore Componi / Referto ---------- */
@media (max-width: 860px){
  body.page-app{ height: auto; overflow: auto; }
  .workspace{ display: block; }
  .mobile-switch{ display: flex; position: sticky; top: 52px; z-index: 20; margin: var(--s-2) var(--s-4) 0; }
  .mobile-switch button{ flex: 1; }
  .builder{ border-right: 0; overflow: visible; padding-bottom: var(--s-6); }
  .report{ padding-bottom: 96px; }
  .report__doc{ min-height: 55vh; }
  .workspace[data-pane="compose"] .report{ display: none; }
  .workspace[data-pane="report"] .builder{ display: none; }
  .report__toolbar{ position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: var(--s-2) var(--s-3); background: var(--surface-1); border-top: 1px solid var(--border); }
  .report__toolbar .btn span{ display: none; }
  .topbar{ padding: var(--s-2) var(--s-3); }
}
