:root {
  --page: #E4E7EA;        /* alumini de disc extern */
  --surface: #FFFFFF;
  --ink: #1B1F27;
  --ink-2: #5E6573;
  --line: #CDD2D8;
  --line-soft: #E9ECEF;
  --accent: #2B45D9;      /* accions */
  --accent-ink: #FFFFFF;
  --tape: #F4D35E;        /* cinta d'etiquetar discs */
  --tape-ink: #2A2410;
  --warn: #B8430F;
  --warn-bg: #FBE9DF;
  --ok: #1E7A4E;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #16191E; --surface: #1F242B; --ink: #E8EAED; --ink-2: #9AA2AE;
    --line: #353C46; --line-soft: #2A3038; --accent: #7C8CFF; --accent-ink: #0F1330;
    --warn: #F0955E; --warn-bg: #3A2418; --ok: #5CC894;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barra superior */
.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 750; font-stretch: 112%; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 18px; border-radius: 3px; background: var(--ink); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 4px; right: 9px; top: 6px; height: 6px; background: var(--tape); border-radius: 1px; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 8px 12px; border-radius: var(--radius-s); cursor: pointer; color: var(--ink-2); font-weight: 550; }
.tab:hover { color: var(--ink); background: var(--line-soft); }
.tab.is-active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); border-radius: 0; }
.user { margin-left: auto; display: flex; gap: 14px; align-items: center; color: var(--ink-2); font-size: 14px; }

main { padding: 24px; max-width: 1480px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
h1 { font-size: 30px; font-stretch: 118%; font-weight: 780; letter-spacing: -0.02em; margin: 0; line-height: 1.1; }
h2 { font-size: 15px; font-weight: 700; margin: 0 0 10px; }

/* Botons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-s); border: 1px solid transparent; cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 14px; }
.link.danger { color: var(--warn); }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 99px; cursor: pointer; font-size: 14px; }
.chip.is-active { background: var(--ink); color: var(--page); border-color: var(--ink); }
.pill { font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill:empty { display: none; }
.spacer { flex: 1; }

/* Cercador: l'element protagonista */
.search-row { display: flex; gap: 12px; align-items: stretch; margin-bottom: 20px; }
.search { flex: 1; position: relative; display: block; }
.search input { width: 100%; font-size: 24px; font-stretch: 105%; font-weight: 500; padding: 14px 56px 14px 18px; border: 2px solid var(--ink); border-radius: var(--radius-m); background: var(--surface); letter-spacing: -0.01em; }
.search input::placeholder { color: var(--ink-2); opacity: .7; }
.search input:focus { outline: none; border-color: var(--accent); }
.search kbd { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); border: 1px solid var(--line); border-radius: 4px; padding: 0 7px; color: var(--ink-2); font-family: var(--font); font-size: 13px; }
.search-row .btn { padding: 0 20px; }

/* Etiquetes de disc (cinta) */
.tape { display: inline-block; background: var(--tape); color: var(--tape-ink); font-stretch: 82%; font-weight: 700; font-size: 13px; padding: 2px 8px 2px 9px; border-radius: 1px; white-space: nowrap; clip-path: polygon(0 4%, 3px 0, 100% 3%, calc(100% - 2px) 50%, 100% 97%, 3px 100%, 0 96%, 2px 50%); }
.tape.none { background: var(--line-soft); color: var(--ink-2); clip-path: none; }
.tape.preview { font-size: 16px; padding: 5px 12px; }
.tape-list { display: flex; flex-direction: column; gap: 6px; }
.tape-list.horizontal { flex-direction: row; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.tape-btn { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid transparent; background: none; padding: 6px 8px; border-radius: var(--radius-s); cursor: pointer; text-align: left; }
.tape-btn:hover { background: var(--line-soft); }
.tape-btn.is-active { border-color: var(--ink); background: var(--surface); }
.tape-btn .who { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tape-btn .n { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tape-list.horizontal .tape-btn { border-color: var(--line); background: var(--surface); padding: 10px 12px; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 150px; }
.tape-list.horizontal .tape-btn.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Projectes */
.layout { display: grid; grid-template-columns: 250px 1fr; gap: 24px; align-items: start; }
.filters { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 22px; }
.filter-block { display: flex; flex-direction: column; gap: 10px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.filters select { padding: 7px 8px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); }
label.check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--ink) !important; font-size: 14px !important; }
.result-count { margin: 0 0 8px; color: var(--ink-2); font-size: 14px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 13px; font-weight: 650; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
table.data th[data-sort] { cursor: pointer; }
table.data th[data-sort]:hover { color: var(--ink); }
table.data th.sorted::after { content: " ↓"; }
table.data th.sorted.asc::after { content: " ↑"; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.data tbody tr:last-child td { border-bottom: 0; }
#rows tr { cursor: pointer; }
#rows tr:hover td { background: var(--line-soft); }
#rows td.client { font-weight: 600; }
#rows td.agency { color: var(--ink-2); }
#rows td.year { font-variant-numeric: tabular-nums; white-space: nowrap; }
#rows .flag { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-left: 6px; vertical-align: middle; }
mark { background: color-mix(in srgb, var(--tape) 70%, transparent); color: inherit; padding: 0 1px; border-radius: 2px; }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-2); }
#more { margin-top: 12px; }

/* Discs */
.disk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.disk-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.disk-card .tape { align-self: flex-start; font-size: 15px; }
.disk-card .name { font-size: 20px; font-weight: 700; font-stretch: 108%; margin: 0; line-height: 1.2; }
.disk-card .stats { display: flex; gap: 16px; color: var(--ink-2); font-size: 14px; }
.disk-card .stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.disk-card .actions { display: flex; gap: 14px; margin-top: auto; }
.disk-card .notes { font-size: 14px; color: var(--ink-2); margin: 0; white-space: pre-line; }

/* Arxivar */
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; display: flex; flex-direction: column; gap: 16px; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 20px 20px 20px 64px; position: relative; counter-increment: step; }
.step::before { content: counter(step); position: absolute; left: 20px; top: 16px; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 750; font-size: 15px; }
.step.is-done::before { background: var(--ink); color: var(--surface); }
.step.is-locked { opacity: .55; }
.step.is-locked > *:not(h2) { pointer-events: none; }
.source-switch { display: flex; gap: 8px; margin-bottom: 14px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius-m); padding: 28px; text-align: center; background: var(--page); }
.drop p { margin: 0 0 6px; }
.drop.is-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--page)); }
.drop .btn { margin-top: 10px; }
.img-queue { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 10px; }
.img-queue li { display: flex; gap: 10px; align-items: center; background: var(--page); border-radius: var(--radius-s); padding: 6px 12px 6px 6px; font-size: 14px; }
.img-queue img { width: 64px; height: 44px; object-fit: cover; object-position: top left; border-radius: 3px; border: 1px solid var(--line); }
.img-queue .st-work { color: var(--ink-2); }
.img-queue .st-ok { color: var(--ok); }
.img-queue .st-err { color: var(--warn); }
textarea, .form-grid input, .form-grid select, .review-tools input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }
#paste-text { font-size: 14px; margin-bottom: 10px; }
.help { margin-bottom: 12px; font-size: 14px; }
.help summary { cursor: pointer; color: var(--accent); }
pre { background: var(--page); padding: 10px 12px; border-radius: var(--radius-s); overflow-x: auto; font-size: 13px; }
.review-tools { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.review-tools label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); min-width: 230px; }
.review-table td { padding: 4px 6px; }
.review-table td:first-child { padding-left: 12px; width: 36px; vertical-align: middle; }
.review-table input[type=text] { width: 100%; border: 1px solid transparent; background: transparent; padding: 6px; border-radius: 3px; }
.review-table input[type=text]:hover { border-color: var(--line); }
.review-table input[type=text]:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.review-table .c-year { width: 90px; }
.review-table .status { font-size: 13px; color: var(--ink-2); white-space: nowrap; vertical-align: middle; padding-right: 12px; }
.review-table .status.warn { color: var(--warn); }
.review-table tr.off td:not(:first-child):not(.status) { opacity: .45; }
.review-table .suggested { font-style: italic; }
.review-foot { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

/* Eines */
.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 20px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.tool p { margin: 0; }
.tool.wide { grid-column: 1 / -1; }
.tool form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
body:not(.is-admin) .admin-only { display: none; }
.plain-list { list-style: none; padding: 0; margin: 0; width: 100%; font-size: 14px; }
.plain-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line-soft); }
.activity { list-style: none; padding: 0; margin: 0; width: 100%; font-size: 14px; max-height: 360px; overflow: auto; }
.activity li { display: grid; grid-template-columns: 140px 120px 130px 1fr; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line-soft); }
.activity time, .activity .who { color: var(--ink-2); }

/* Banner i avisos */
.banner { background: var(--tape); color: var(--tape-ink); padding: 10px 24px; display: flex; gap: 16px; align-items: center; font-weight: 550; }
.banner .btn { padding: 5px 12px; background: var(--tape-ink); color: var(--tape); }
.msg { padding: 10px 12px; border-radius: var(--radius-s); background: var(--line-soft); margin: 10px 0; }
.msg.error { background: var(--warn-bg); color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--page); padding: 10px 18px; border-radius: var(--radius-s); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--warn); color: #fff; }

/* Diàlegs */
.dialog { border: 0; border-radius: var(--radius-m); padding: 0; width: min(520px, 94vw); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(10, 14, 20, .35); }
.dialog::backdrop { background: rgba(20, 24, 30, .45); }
.dialog form { padding: 22px; }
.form-grid { display: flex; flex-direction: column; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.form-grid .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.meta { font-size: 13px; margin: 0; }

/* Pàgines simples (login, instal·lació) */
.page-simple { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.simple-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 32px; width: min(400px, 100%); }
.simple-card.wide { width: min(620px, 100%); }
.brand-title { font-size: 34px; font-stretch: 120%; margin-bottom: 4px; }
.lead { color: var(--ink-2); margin: 0 0 20px; }
.simple-card fieldset { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.simple-card legend { font-weight: 700; padding: 0 6px; }
textarea.code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 14px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 14px; }
  .layout { grid-template-columns: 1fr; }
  .filters { position: static; }
  .tape-list:not(.horizontal) { flex-direction: row; flex-wrap: wrap; }
  .search input { font-size: 18px; }
  .search-row { flex-direction: column; }
  .search-row .btn { padding: 10px; }
  .step { padding: 56px 14px 14px; }
  .step::before { top: 14px; left: 14px; }
  .activity li { grid-template-columns: 1fr; gap: 0; }
  #rows td.agency, table.data thead th[data-sort=agency] { display: none; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* Ajustos */
.form-grid input[type=checkbox], .tool input[type=checkbox] { width: auto; }
.tape-list:not(.horizontal) .tape-btn { display: grid; grid-template-columns: auto 1fr auto; text-align: left; }
.filter-block .link { align-self: flex-start; }
.tool form .btn, .form-grid .btn { align-self: flex-start; }
.dialog-foot .btn { align-self: auto; }
.review-table th:nth-child(2) { width: 22%; }
.review-table th:nth-child(3) { width: 18%; }
.review-table th:nth-child(4) { width: 40%; }
.layout > * { min-width: 0; }
@media (max-width: 860px) {
  .tape-list:not(.horizontal) .tape-btn { grid-template-columns: auto auto; }
  .tape-list:not(.horizontal) .tape-btn .who { display: none; }
  .filters select { width: 100%; }
}
