/* Mecum — base i components. Només tokens de themes.css; res de colors literals.
   Vocabulari de classes documentat a docs/DISSENY.md (secció «Components»). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--page-bg, var(--bg)); background-attachment: fixed; color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5; font-optical-sizing: auto;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
::selection { background: var(--accent); color: var(--accent-ink); }
[hidden] { display: none !important; }
hr { border: 0; border-top: var(--bw) solid var(--line); margin: 20px 0; }

/* ─── tipografia ─── */
h1, h2, h3, h4, .display {
  font-family: var(--font-display); font-weight: var(--display-wght); letter-spacing: var(--display-track);
  font-stretch: var(--display-stretch); line-height: 1.08; margin: 0 0 .4em; text-wrap: balance;
  font-variation-settings: var(--display-vars, normal);
}
h1 { font-size: clamp(26px, 4.6vw, 34px); line-height: 1.12; }
h2 { font-size: clamp(21px, 3.4vw, 26px); line-height: 1.18; }
h3 { font-size: 18px; line-height: 1.25; }
h4 { font-size: 16px; line-height: 1.25; }
.display { font-size: clamp(34px, 6vw, 56px); line-height: 1.02; }
p { margin: 0 0 .8em; text-wrap: pretty; }
.lede { font-size: 17px; color: var(--ink-2); line-height: 1.45; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: var(--eyebrow-wght, 700); letter-spacing: var(--eyebrow-track, .09em);
  font-family: var(--eyebrow-font, inherit); text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px;
}
kbd { font-family: var(--font-mono); font-size: 11.5px; padding: 1px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; color: var(--ink-2); }

/* secció → color (data-sec a qualsevol contenidor) */
[data-sec="eines"] { --sec: var(--c-eines); --sec-ink: var(--c-eines-ink); }
[data-sec="casos"] { --sec: var(--c-casos); --sec-ink: var(--c-casos-ink); }
[data-sec="comu"]  { --sec: var(--c-comu);  --sec-ink: var(--c-comu-ink); }
[data-sec="acad"]  { --sec: var(--c-acad);  --sec-ink: var(--c-acad-ink); }
[data-sec="docs"]  { --sec: var(--c-docs);  --sec-ink: var(--c-docs-ink); }
[data-sec="med"]   { --sec: var(--c-med);   --sec-ink: var(--c-med-ink); }
[data-sec="glia"]  { --sec: var(--accent);  --sec-ink: var(--accent-ink); }

/* ─── maquetació ─── */
.page { max-width: var(--maxw); margin: 0 auto; padding: 20px 16px 120px; }
.page.wide { max-width: var(--maxw-wide); }
.stack { display: flex; flex-direction: column; gap: var(--gap, 14px); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, 10px); }
.row.nowrap { flex-wrap: nowrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.grid-2, .grid-3, .grid-auto { display: grid; gap: var(--gap, 14px); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.section { margin: 30px 0 12px; display: flex; align-items: baseline; gap: 10px; }
.section h2, .section h3 { margin: 0; }
.section .spacer + a, .section > a:last-child { font-size: 14px; font-weight: 600; color: var(--ink-2); text-decoration: none; }
.section > a:last-child:hover { color: var(--ink); }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ─── icones (icons.js): Material Symbols, monocromes (currentColor) ─── */
.ic { flex: none; }
.ic .f { display: none; }
/* element actiu: la variant plena */
[aria-current="page"] > .ic .o, [aria-pressed="true"] > .ic .o, .ic.on .o { display: none; }
[aria-current="page"] > .ic .f, [aria-pressed="true"] > .ic .f, .ic.on .f { display: inline; }

/* ─── botons ─── */
.btn {
  --b-bg: var(--surface); --b-ink: var(--ink); --b-line: var(--line-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border: var(--bw) solid var(--b-line); border-radius: var(--r-md); background: var(--b-bg); color: var(--b-ink);
  font-weight: 600; font-size: var(--btn-fs, 15px); line-height: 1; cursor: pointer; text-decoration: none; white-space: nowrap;
  text-transform: var(--btn-case, none); letter-spacing: var(--btn-track, 0); font-stretch: var(--btn-stretch, normal);
  box-shadow: var(--btn-shadow, none);
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background-color var(--dur-1) var(--ease);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn .ic { width: 20px; height: 20px; }
.btn:hover { background: var(--surface-2); transform: var(--btn-lift-h, none); box-shadow: var(--btn-shadow-h, none); }
.btn:active { transform: var(--btn-press, translateY(1px)); box-shadow: var(--btn-shadow-p, none); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn.primary { --b-bg: var(--accent); --b-ink: var(--accent-ink); --b-line: var(--accent); box-shadow: var(--btnp-shadow, none); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); box-shadow: var(--btnp-shadow-h, none); }
.btn.sec { --b-bg: var(--sec, var(--accent)); --b-ink: var(--sec-ink, var(--accent-ink)); --b-line: var(--sec, var(--accent)); box-shadow: var(--btnp-shadow, none); }
.btn.sec:hover { background: color-mix(in srgb, var(--sec, var(--accent)) 88%, var(--ink)); box-shadow: var(--btnp-shadow-h, none); }
.btn.ghost { --b-bg: transparent; --b-line: transparent; box-shadow: none; }
.btn.ghost:hover, .btn.ghost:active { background: var(--surface-2); box-shadow: none; transform: none; }
.btn.danger { --b-ink: var(--ko); --b-line: var(--ko); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: var(--r-sm); }
.btn.lg { min-height: 52px; padding: 0 22px; font-size: 17px; border-radius: var(--r-lg); }
.btn.icon { padding: 0; width: 42px; }
.btn.icon.sm { width: 34px; }
.btn.block { width: 100%; }
.btn.pill { border-radius: var(--r-pill); }

/* ─── targetes ─── */
.card {
  position: relative; background: var(--surface); border: var(--bw) solid var(--card-line, var(--line)); border-radius: var(--r-card);
  padding: 16px; box-shadow: var(--card-shadow, none);
}
.card.flat { box-shadow: none; }
.card.tight { padding: 12px; }
.card.hover { cursor: pointer; text-decoration: none; color: inherit; display: block;
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), border-color var(--dur-2); }
.card.hover:hover { transform: var(--card-lift-h, none); box-shadow: var(--card-shadow-h, none); border-color: var(--line-2); }
.card.band { border-top: var(--band-w, 6px) solid var(--sec, var(--accent)); }
.card > :last-child { margin-bottom: 0; }

.tile { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--r-md); background: var(--surface-2); }
.tile .v { font-family: var(--tile-font, var(--font-display)); font-weight: var(--tile-wght, var(--display-wght)); font-size: 28px; line-height: 1; letter-spacing: -0.02em; color: var(--ink); }
.tile .l { font-size: 13px; color: var(--ink-2); }

/* ─── formularis ─── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12.5px; }
.input, .field input:not([type="checkbox"]):not([type="radio"]), .field textarea, .field select {
  width: 100%; min-height: 44px; padding: 10px 12px; background: var(--input-bg, var(--surface)); color: var(--ink);
  border: var(--bw) solid var(--line-2); border-radius: var(--r-md); font-size: 16px; outline: none;
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
.field textarea, textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .field :is(input, textarea, select):focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .field ::placeholder { color: var(--ink-3); }

.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: var(--r-md); border: var(--bw) solid var(--line); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: var(--r-sm); font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--seg-on-bg, var(--surface)); color: var(--seg-on-ink, var(--ink)); box-shadow: var(--seg-on-shadow, none); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; min-height: 36px; border-radius: var(--r-pill);
  border: var(--bw) solid var(--line-2); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none; transition: background-color var(--dur-1), transform var(--dur-1);
}
.chip .ic { width: 18px; height: 18px; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"], .chip.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.chip .n { font-family: var(--font-mono); font-size: 12px; opacity: .7; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; font-weight: 500; text-decoration: none; }
a.tag:hover { color: var(--ink); background: var(--surface-3); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--surface-3); position: relative; cursor: pointer; transition: background-color var(--dur-2); margin: 0; flex: none; border: var(--bw) solid var(--line-2); }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform var(--dur-2) var(--ease-spring); }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

.tabs { display: flex; gap: 4px; border-bottom: var(--bw) solid var(--line); overflow-x: auto; scrollbar-width: none; margin-bottom: 16px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs a { border: 0; background: none; padding: 10px 12px; font-weight: 600; font-size: 15px; color: var(--ink-3); cursor: pointer; position: relative; white-space: nowrap; text-decoration: none; }
.tabs [aria-selected="true"] { color: var(--ink); }
.tabs [aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: calc(-1 * var(--bw)); height: 2px; border-radius: 2px 2px 0 0; background: var(--accent); }

/* ─── llistes ─── */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, button.list-item:hover { background: var(--surface-2); }
button.list-item { width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; cursor: pointer; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; line-height: 1.3; }
.list-item .s { font-size: 14px; color: var(--ink-2); }
.list-item .meta { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }

/* ─── insígnies, avisos, buits ─── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); letter-spacing: .01em; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ko { background: var(--ko-soft); color: var(--ko); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.sec { background: var(--accent-soft); color: var(--accent); }
.badge.premium { background: var(--ink); color: var(--bg); letter-spacing: .02em; }
.badge .ic { width: 14px; height: 14px; }
.verified { display: inline-flex; vertical-align: -3px; color: var(--accent); }
.verified .ic { width: 16px; height: 16px; }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); border: var(--bw) solid var(--line); font-size: 14.5px; }
.notice .ic { width: 20px; height: 20px; margin-top: 1px; }
.notice.warn { background: var(--warn-soft); border-color: transparent; }
.notice.ko { background: var(--ko-soft); border-color: transparent; }
.notice.ok { background: var(--ok-soft); border-color: transparent; }
.notice.legal { font-size: 13px; color: var(--ink-2); background: transparent; border-style: dashed; }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .ic { width: 44px; height: 44px; color: var(--ink-3); }
.empty h3 { margin: 4px 0 0; color: var(--ink); }

.skel { background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: skel 1.3s linear infinite; border-radius: var(--r-sm); min-height: 14px; }
@keyframes skel { to { background-position: -200% 0; } }
.spin { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: rot .8s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ─── avatar (avatar.js) ─── */
.avatar { display: inline-block; vertical-align: middle; flex: none; border-radius: var(--avatar-r, 50%); overflow: hidden; width: 40px; height: 40px; background: var(--surface-2); }
.avatar.xs { width: 24px; height: 24px; } .avatar.sm { width: 32px; height: 32px; }
.avatar.lg { width: 64px; height: 64px; } .avatar.xl { width: 104px; height: 104px; }
.avatar svg { width: 100%; height: 100%; }
.avatar text { font-family: var(--font-display); font-weight: 600; }

/* ─── markdown (core.md) ─── */
.md { line-height: 1.6; overflow-wrap: anywhere; }
.md p { margin: 0 0 .75em; }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.3em; }
.md li { margin: .2em 0; }
.md h3, .md h4 { margin: 1em 0 .4em; }
.md code { font-family: var(--font-mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; margin: .5em 0 1em; display: block; overflow-x: auto; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
.md th { font-weight: 600; color: var(--ink-2); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.md blockquote { margin: 0 0 .8em; padding: 4px 0 4px 14px; border-left: 2px solid var(--line-2); color: var(--ink-2); }
.md a { color: var(--accent); }
.md mark, mark.hl { background: var(--warn-soft); color: inherit; padding: 0 2px; border-radius: 3px; }

/* ─── full inferior / modal (core.sheet) ─── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 900; background: color-mix(in srgb, var(--ink) 34%, transparent); display: flex; align-items: flex-end; justify-content: center; animation: fade var(--dur-2) var(--ease); }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--surface); color: var(--ink); border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); box-shadow: var(--shadow-float); animation: up var(--dur-3) var(--ease); }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 0 auto 14px; opacity: .5; }
.sheet h2 { font-size: 22px; }
@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--r-xl); padding: 22px 24px 24px; }
  .sheet::before { display: none; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 1001; background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: var(--r-md); font-weight: 500; font-size: 14.5px; box-shadow: var(--shadow-float); animation: up var(--dur-2) var(--ease); max-width: calc(100vw - 32px); }
@media (min-width: 1000px) { .toast { bottom: 28px; } }

/* ─── porta Premium ─── */
.premium-gate { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 26px 18px; border-radius: var(--r-card); border: var(--bw) dashed var(--line-2); background: var(--surface); }
.premium-gate .glia { width: 84px; height: 84px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ─── frontera de privacitat (privacitat.js) ─── */
.pv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.pv-item { padding: 12px 14px; border-radius: var(--r-md); border: var(--bw) solid var(--line); background: var(--surface); }
.pv-item[data-g="directa"] { border-left: 3px solid var(--ko); }
.pv-item[data-g="indirecta"] { border-left: 3px solid var(--warn); }
.pv-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 6px; }
.pv-cat { font-weight: 600; font-size: 14px; }
.pv-camp { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.pv-frag { display: block; font-size: 14.5px; margin: 2px 0 6px; padding: 4px 8px; border-radius: var(--r-sm); background: var(--surface-2); quotes: "«" "»"; }
.pv-why { margin: 0 0 4px; font-size: 14px; color: var(--ink-2); }
.pv-fix { display: flex; gap: 6px; align-items: flex-start; margin: 0; font-size: 14px; color: var(--ink); }
.pv-fix .ic { margin-top: 2px; color: var(--accent); }
