@font-face { font-family: "Public Sans"; src: url("./fonts/public-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("./fonts/public-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("./fonts/public-sans-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --ink: #17202E;
  --muted: #5B6778;
  --rule: #D6DDE6;
  --head: #E4EAF3;
  --blue: #0070C0;
  --blue-dark: #005A9A;
  --yellow: #FFE600;
  --red: #D7261E;
  --np: #7A8594;
  --radius: 6px;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2.125rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.5 "Public Sans", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
button { font: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.wrap { width: min(1240px, 100% - 2.5rem); margin-inline: auto; }

/* ---------- capçalera */
.top { background: var(--surface); border-bottom: 1px solid var(--rule); }
.top-inner { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; padding-block: 1.75rem 1.25rem; flex-wrap: wrap; }
h1 { font-size: var(--step-3); font-weight: 700; letter-spacing: -0.02em; }
.lede { margin: .35rem 0 0; color: var(--muted); max-width: 60ch; }
.engine { margin: 0; display: inline-flex; align-items: center; gap: .5rem; font-size: var(--step--1); color: var(--muted); }
.engine .dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 2px #E8D200 inset; }
.engine.ok .dot { background: var(--blue); box-shadow: none; }
.engine.ko .dot { background: var(--red); box-shadow: none; }

main { padding-block: 2rem 4rem; }

/* ---------- pujar */
.drop {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 2rem;
  padding: 2.25rem 2.5rem;
  background: var(--surface);
  border: 2px dashed #AEBACB;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.drop:hover, .drop.over { border-color: var(--blue); background: #F7FAFE; }
.drop:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-text { display: grid; gap: .3rem; max-width: 52ch; }
.drop-text strong { font-size: var(--step-2); font-weight: 600; letter-spacing: -0.01em; }
.drop-text span { color: var(--muted); }
.drop-grid { display: grid; grid-template-columns: repeat(3, 2.6rem); border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); }
.g { height: 2rem; display: grid; place-items: center; font-size: var(--step--1); border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); background: var(--surface); }
.privacy { margin: 1rem 0 0; color: var(--muted); font-size: var(--step--1); max-width: 75ch; }

/* colors de nota: els mateixos de l'Excel */
.exc { background: var(--blue); color: var(--yellow); }
.prop { background: var(--red); color: var(--yellow); }
.susp { color: var(--red); }
.np { color: var(--np); font-style: italic; }

/* ---------- processant */
.working { display: grid; justify-items: center; gap: .75rem; padding: 4rem 1rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); text-align: center; }
.working p { margin: 0; }
#working-text { font-size: var(--step-1); font-weight: 600; }
.working-file { color: var(--muted); font-size: var(--step--1); }
.loader { display: grid; grid-template-columns: repeat(3, 1rem); gap: 3px; margin-bottom: .5rem; }
.loader span { width: 1rem; height: 1rem; background: var(--head); animation: cell 1.2s infinite ease-in-out; }
.loader span:nth-child(1) { animation-delay: 0.0s; }
.loader span:nth-child(2) { animation-delay: 0.1s; }
.loader span:nth-child(3) { animation-delay: 0.2s; }
.loader span:nth-child(4) { animation-delay: 0.1s; }
.loader span:nth-child(5) { animation-delay: 0.2s; }
.loader span:nth-child(6) { animation-delay: 0.3s; }
.loader span:nth-child(7) { animation-delay: 0.2s; }
.loader span:nth-child(8) { animation-delay: 0.3s; }
.loader span:nth-child(9) { animation-delay: 0.4s; }
@keyframes cell { 0%, 100% { background: var(--head); } 40% { background: var(--blue); } 60% { background: var(--yellow); } }

/* ---------- error */
.error { padding: 1.75rem 2rem; background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--red); border-radius: var(--radius); }
.error h2 { font-size: var(--step-1); }
.error pre { white-space: pre-wrap; font: inherit; font-size: var(--step--1); background: #FBF2F1; padding: .75rem 1rem; border-radius: var(--radius); max-height: 16rem; overflow: auto; }
.error p { color: var(--muted); max-width: 70ch; }

/* ---------- botons */
.btn {
  display: inline-flex; align-items: center; gap: .6rem;
  padding: .65rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--blue); background: var(--blue); color: #fff;
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { border-color: var(--ink); background: transparent; }
.btn small { font-weight: 400; opacity: .85; }

/* ---------- resultat */
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.done { font-size: var(--step-2); font-weight: 700; outline: none; }
.stats { display: flex; flex-wrap: wrap; gap: .25rem 1.75rem; margin: .6rem 0 0; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { color: var(--muted); font-size: var(--step--1); }
.stats dd { margin: 0; font-size: var(--step-1); font-weight: 600; }

.downloads { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.5rem; }
.downloads .btn { padding: .75rem 1.1rem; }

.avisos { margin-top: 1.25rem; background: #FFFBE0; border: 1px solid #EBD64A; border-radius: var(--radius); padding: .75rem 1rem; }
.avisos summary { cursor: pointer; font-weight: 600; }
.avisos-help { margin: .5rem 0; color: var(--muted); font-size: var(--step--1); }
.avisos ul { margin: 0; padding-left: 1.2rem; font-size: var(--step--1); max-height: 14rem; overflow: auto; }
.avisos li + li { margin-top: .25rem; }

/* ---------- preview */
.preview { margin-top: 2rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.campus-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--rule); background: #F8FAFC; overflow-x: auto; }
.campus-tabs button {
  padding: .8rem 1.25rem; border: 0; border-right: 1px solid var(--rule); background: transparent;
  color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; position: relative;
}
.campus-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); }
.campus-tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: var(--blue); }
.campus-tabs small { font-weight: 400; margin-left: .35rem; }

.preview-body { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 30rem; }
.sheets { border-right: 1px solid var(--rule); padding: .75rem; overflow-y: auto; max-height: 75vh; }
.sheets h3 { font-size: var(--step--1); font-weight: 600; color: var(--muted); margin: .9rem .25rem .35rem; }
.sheets h3:first-child { margin-top: .25rem; }
.sheets .chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.sheets button {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 4px;
  padding: .25rem .5rem; font-size: var(--step--1); cursor: pointer; color: var(--ink);
}
.sheets button:hover { border-color: var(--ink); }
.sheets button[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.sheet { padding: 1.25rem 1.5rem 1.75rem; min-width: 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .9rem; }
.sheet-head h3 { font-size: var(--step-1); }
.sheet-head p { margin: .15rem 0 0; color: var(--muted); font-size: var(--step--1); }
.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: var(--step--1); color: var(--muted); margin: 0; padding: 0; list-style: none; }
.legend i { display: inline-block; width: 1.6rem; text-align: center; font-style: normal; margin-right: .3rem; border: 1px solid var(--rule); }

.grid-scroll { overflow: auto; max-height: 60vh; border: 1px solid var(--rule); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: var(--step--1); width: max-content; min-width: 100%; }
.grid th, .grid td { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: .3rem .5rem; }
.grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--head); font-weight: 600;
  vertical-align: bottom; text-align: center; max-width: 9rem; min-width: 5.2rem; white-space: normal; line-height: 1.25;
}
.grid thead th.calc { min-width: 3.4rem; }
.grid .name { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; white-space: nowrap; font-weight: 400; }
.grid thead th.name { z-index: 3; background: var(--head); text-align: left; }
.grid td { text-align: center; }
.grid td.calc { background: #F4F6F9; }
.grid td.med { font-weight: 600; }
.grid td.grp { color: var(--muted); font-size: .72rem; text-align: left; white-space: nowrap; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; }
.grid tbody tr:hover td { box-shadow: inset 0 0 0 9999px rgba(0, 112, 192, .06); }
.grid tbody tr:hover td.exc, .grid tbody tr:hover td.prop { box-shadow: none; }

.lower { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.75rem; margin-top: 1.75rem; }
.stats-table { overflow-x: auto; }
table.est { border-collapse: collapse; font-size: var(--step--1); width: max-content; }
.est th, .est td { border: 1px solid var(--rule); padding: .3rem .6rem; }
.est th { background: var(--head); text-align: left; font-weight: 600; white-space: nowrap; }
.est thead th { text-align: center; max-width: 8rem; white-space: normal; font-weight: 600; }
.est td { text-align: center; min-width: 4.5rem; }
.est tr.np-row th, .est tr.np-row td { background: #FFFBE0; }

.hist { margin: 0; max-width: 30rem; }
.hist h4 { margin: 0 0 .6rem; font-size: var(--step--1); font-weight: 600; }
.hist svg { width: 100%; height: auto; display: block; }
.hist text { font: 500 10px "Public Sans", system-ui, sans-serif; fill: var(--muted); }
.hist text.v { fill: var(--ink); font-weight: 600; }

canvas#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@media (max-width: 820px) {
  .drop { grid-template-columns: 1fr; padding: 1.75rem 1.25rem; gap: 1.25rem; }
  .preview-body { grid-template-columns: 1fr; }
  .sheets { border-right: 0; border-bottom: 1px solid var(--rule); max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
