/* Design system HM52 Play (come PlayClima, PlayAudit, PlayStrati): carta, verde, Georgia per i titoli */
:root {
  --verde: #3A6B5E;
  --verde-scuro: #27493F;
  --verde-chiaro: #E8EFEA;
  --carta: #F6F4EE;
  --bianco: #FFFFFF;
  --ink: #1E2421;
  --grigio: #6B7370;
  --linea: #DDD9CE;
  --linea-2: #ECE9E1;
  --giallo: #D9A441;
  --giallo-chiaro: #FBF3E4;
  --giallo-testo: #7A5E1C;
  --rosso: #B23B3B;
  --rosso-chiaro: #F7E4E2;
  --ok: #3A8C5C;
  --ok-chiaro: #E4F1E8;

  /* nomi storici usati nel resto del foglio */
  --bg: var(--carta);
  --surface: var(--bianco);
  --surface-2: var(--linea-2);
  --border: var(--linea);
  --text: var(--ink);
  --muted: var(--grigio);
  --accent: var(--verde);
  --accent-text: #ffffff;
  --fail: var(--rosso);
  --fail-bg: var(--rosso-chiaro);
  --ok-bg: var(--ok-chiaro);
  --warn: var(--giallo-testo);
  --warn-bg: var(--giallo-chiaro);

  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04);
  --font: "Helvetica Neue", Arial, system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2, h4 { font-family: var(--serif); font-weight: 400; }

.muted { color: var(--muted); }

/* ---------- testata HM52 ---------- */

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header.top .brand { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 700; letter-spacing: .04em; }
header.top .brand img { height: 26px; }
header.top .brand em { font-weight: 400; color: var(--grigio); }
header.top .brand .app-name { font-weight: 400; letter-spacing: 0; color: var(--ink); padding-left: 10px; border-left: 1px solid var(--linea); }
header.top .brand .app-name i { color: var(--verde); font-family: var(--serif); }

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid var(--verde);
  background: var(--verde);
  color: #fff;
  font: 14px var(--font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.button:hover { background: var(--verde-scuro); }
.button.secondary { background: var(--surface); color: var(--verde); border-color: var(--verde); }
.button.secondary:hover { background: var(--verde-chiaro); }
.button:focus-visible, button:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- layout ---------- */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.layout.is-empty { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 0 24px 40px; overflow-y: auto; }
.layout.is-empty .file-list, .layout.is-empty .detail { display: none; }
.layout:not(.is-empty) .dropzone, .layout:not(.is-empty) .hero { display: none; }

/* hero della schermata iniziale, come nelle utility Play */
.hero { width: min(1080px, 100%); padding: 44px 0 26px; }
.hero-int { display: flex; justify-content: space-between; align-items: center; gap: 30px; }
.kicker { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--grigio); margin-bottom: 10px; }
h1.titolo { font-family: var(--serif); font-size: clamp(2.1rem, 5vw, 3.2rem); font-weight: 400; line-height: 1.1; }
h1.titolo em { color: var(--verde); }
.hero .sub { margin: 12px 0 0; max-width: 680px; color: var(--grigio); }
.hero .firma { margin-top: 10px; font-size: .85rem; }
.hero-logo img { width: 120px; display: block; }

.dropzone {
  width: min(1080px, 100%);
  padding: 52px 24px;
  border: 2px dashed var(--linea);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--verde); background: #FBFCFB; }
.dropzone svg {
  width: 44px;
  height: 44px;
  fill: none;
  stroke: var(--verde);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.dropzone-title { margin: 12px 0 4px; font-family: var(--serif); font-size: 1.35rem; }
.dropzone-hint { margin: 0; color: var(--muted); font-size: 14px; }

.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--verde) 12%, transparent);
  border: 3px dashed var(--verde);
  pointer-events: none;
}
.drag-overlay[hidden] { display: none; }
.drag-overlay p {
  padding: 14px 24px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--linea);
  font-family: var(--serif);
  font-size: 20px;
}

/* ---------- elenco file ---------- */

.file-list {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 16px 10px;
  overflow-y: auto;
}
.list-title {
  font-family: var(--font);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--verde);
  padding: 0 8px 10px;
}

.file-item { display: flex; align-items: stretch; border-radius: 8px; }
.file-item.selected { background: var(--verde-chiaro); box-shadow: inset 3px 0 0 var(--verde); }
.file-item:hover { background: var(--carta); }
.file-item.selected:hover { background: var(--verde-chiaro); }

.file-select {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 8px 10px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.file-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-remove {
  width: 30px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
}
.file-remove:hover { color: var(--rosso); }

.badge {
  font-size: .74rem;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--linea-2);
  color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }
.badge.unknown { background: var(--warn-bg); color: var(--warn); }

/* ---------- dettaglio ---------- */

.detail { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.detail-heading { min-width: 0; }
.detail-title { font-family: var(--serif); font-weight: 400; font-size: 1.35rem; overflow-wrap: anywhere; }
.detail-header p { margin: 2px 0 0; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.detail-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.preview { min-width: 0; min-height: 0; display: flex; background: var(--linea-2); }
.preview-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.preview-image { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; overflow: auto; }
.preview-image img { max-width: 100%; height: auto; border: 1px solid var(--linea); }
.preview-text { flex: 1; min-width: 0; overflow: auto; padding: 16px 24px; background: var(--surface); }
.preview-text pre { margin: 0; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-empty { margin: auto; padding: 24px; text-align: center; }

.preview-tabs { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tab-bar { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.tab {
  padding: 7px 16px;
  border: 1px solid var(--linea);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font: 13px var(--font);
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--verde); border-color: var(--verde); color: #fff; }
.tab-pane { flex: 1; min-height: 0; display: flex; }
.tab-action { margin-left: auto; color: var(--verde); border-color: var(--verde); }

.signatures-slot { overflow-y: auto; border-left: 1px solid var(--border); background: var(--bg); }
.signatures { padding: 18px 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.signatures h2 { font-size: 1.2rem; }
.layer { display: flex; flex-direction: column; gap: 10px; }
.layer-title { font-family: var(--font); font-size: .7rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--verde); }

.signer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.signer h4 { font-size: 1.1rem; margin-bottom: 8px; }

.fields { margin: 0; display: grid; gap: 6px; }
.field { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 8px; font-size: 13px; }
.field dt { color: var(--muted); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; padding-top: 2px; }
.field dd { margin: 0; overflow-wrap: anywhere; }

.checks {
  list-style: none;
  margin: 12px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 6px;
  font-size: 13px;
}
.check { display: flex; gap: 8px; align-items: flex-start; }
.check-icon {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--linea-2);
  color: var(--muted);
}
.check.ok .check-icon { background: var(--ok-bg); color: var(--ok); }
.check.fail .check-icon { background: var(--fail-bg); color: var(--fail); }
.check.fail { color: var(--fail); }
.check-note { font-size: 12px; }

.disclaimer {
  font-size: .8rem;
  margin: 0;
  background: var(--giallo-chiaro);
  border-left: 3px solid var(--giallo);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--giallo-testo);
}

.error-card {
  margin: 32px auto;
  width: min(560px, calc(100% - 32px));
  padding: 20px 24px;
  border-radius: var(--radius);
  background: var(--fail-bg);
  border-left: 3px solid var(--rosso);
  color: var(--fail);
}
.error-card h2 { font-size: 1.2rem; overflow-wrap: anywhere; }
.error-card p { margin: 8px 0 0; }

footer.piede { border-top: 1px solid var(--linea); padding: 10px 24px; text-align: center; font-size: .78rem; color: var(--grigio); background: var(--surface); }

/* ---------- schermi stretti ---------- */

@media (max-width: 900px) {
  .detail-body { grid-template-columns: 1fr; grid-template-rows: minmax(420px, 60vh) auto; overflow-y: auto; }
  .signatures-slot { border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
  .detail { overflow-y: auto; }
}

@media (max-width: 680px) {
  header.top { padding: 12px 16px; }
  header.top .brand .app-name { display: none; }
  .hero-logo img { width: 72px; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .file-list { border-right: 0; border-bottom: 1px solid var(--border); max-height: 160px; }
  .detail-header { padding: 14px 16px; }
  .field { grid-template-columns: 1fr; gap: 0; }
}
