/* Plataforma de retoque · requiere tokens.css */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--surface-alt); color: var(--text); font: 400 15px/24px var(--font-body); -webkit-font-smoothing: antialiased; }
a { color: var(--link); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; color: var(--ink); text-wrap: balance; margin: 0; }
h1 { font-size: 32px; line-height: 38px; letter-spacing: -.8px; }
h2 { font-size: 24px; line-height: 30px; letter-spacing: -.4px; }
h3 { font-size: 18px; line-height: 24px; letter-spacing: -.2px; }
p { text-wrap: pretty; }
.overline { font: 500 11px/16px var(--font-mono); letter-spacing: 2.4px; text-transform: uppercase; color: var(--text-secondary); margin: 0 0 12px; }
.mono { font: 500 13px/20px var(--font-mono); }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; line-height: 20px; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--night); padding: 24px 12px; display: flex; flex-direction: column; gap: 4px; }
.sidebar .logo { padding: 0 12px 24px; }
.sidebar .logo img { height: 28px; display: block; }
.sidebar .logo span { display: block; margin-top: 8px; font: 500 10px/14px var(--font-mono, monospace); letter-spacing: 1.4px; text-transform: uppercase; color: #a2a5a7; }
.login .form img.proof { height: 34px; width: auto; display: block; margin-bottom: 28px; }
.sidebar a.nav { display: block; padding: 8px 12px; border-radius: 8px; color: #e7e8e8; text-decoration: none; font-weight: 500; }
.sidebar a.nav:hover { background: #162024; }
.sidebar a.nav.active { background: #162024; color: #fff; font-weight: 600; }
.sidebar .pend { color: #a2a5a7; padding: 8px 12px; font-size: 13px; }
.sidebar .spacer { flex: 1; }
.sidebar .who { color: #a2a5a7; font-size: 13px; line-height: 20px; padding: 12px; border-top: 1px solid #202b2e; }
.sidebar .who b { color: #fff; font-weight: 600; display: block; }
.sidebar .who button { margin-top: 8px; background: none; border: 0; color: var(--brand-light); padding: 0; font: inherit; cursor: pointer; }
.main { min-width: 0; }
.topbar { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }
.crumbs { font: 500 13px var(--font-mono); color: var(--text-secondary); }
.crumbs a { color: var(--text-secondary); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.tag-ejemplo { font: 500 10px var(--font-mono); letter-spacing: 1.4px; text-transform: uppercase; color: var(--warning); }
.content { padding: 24px; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: 12px; padding: 24px; min-width: 0; }
.card h3 { margin-bottom: 12px; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent; font: 600 15px/20px var(--font-body); text-decoration: none; cursor: pointer; white-space: nowrap; transition: background var(--duration-fast) var(--ease-brand); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.btn-primary { background: var(--action); color: var(--on-action); } .btn-primary:hover { background: var(--action-hover); }
.btn-secondary { background: var(--surface-raised); color: var(--ink); border-color: var(--border-control); } .btn-secondary:hover { background: var(--surface-muted); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.lbl { display: block; font-weight: 600; font-size: 14px; color: var(--ink); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font: 400 15px/24px var(--font-body); color: var(--ink); background: var(--surface-raised);
  border: 1px solid var(--border-control); border-radius: 8px; padding: 7px 12px; }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 16px; }
.hint { font-size: 13px; line-height: 20px; color: var(--text-secondary); margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline { display: inline; }

/* Drop zone */
.drop { border: 1px dashed var(--border-control); border-radius: 8px; padding: 20px; text-align: center; transition: background var(--duration-fast); }
.drop.over { background: var(--brand-wash); border-color: var(--brand); }
.drop b { display: block; color: var(--ink); font-weight: 600; }
.drop input[type=file] { display: none; }

/* Flash */
.flash { border-radius: 8px; padding: 10px 14px; display: flex; gap: 8px; align-items: flex-start; }
.flash.ok { background: var(--success-bg); color: var(--success); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash svg { flex: none; margin-top: 2px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: 999px; font: 600 12px/16px var(--font-body); white-space: nowrap; }
.badge svg { width: 14px; height: 14px; }
.b-pendiente { background: var(--surface-muted); color: var(--text); }
.b-en_retoque { background: var(--brand-wash); color: var(--brand-text); }
.b-en_revision { background: var(--warning-bg); color: var(--warning); }
.b-cambios { background: var(--danger-bg); color: var(--danger); }
.b-aprobada, .b-ok { background: var(--success-bg); color: var(--success); }
.b-error { background: var(--danger-bg); color: var(--danger); }
.b-aviso { background: var(--warning-bg); color: var(--warning); }
.b-pendiente-check { background: var(--surface-muted); color: var(--text-secondary); }

/* Filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border: 1px solid var(--border-control); border-radius: 8px; background: var(--surface-raised); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; }
.chip.active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

/* Justified grid: les miniatures mai es retallen */
.jgrid { display: flex; flex-wrap: wrap; gap: 24px 16px; }
.jgrid::after { content: ""; flex-grow: 999999; }
.jitem { min-width: 0; text-decoration: none; color: inherit; }
.jframe { position: relative; background: var(--surface-muted); }
.jframe img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; border-radius: 2px; display: block; }
.jframe .nopreview { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 8px; font: 500 10px/14px var(--font-mono); letter-spacing: 1.4px; color: var(--text-secondary); background: repeating-linear-gradient(135deg, var(--border) 0 1px, transparent 1px 12px), var(--surface-muted); }
.jmeta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font: 500 12px/16px var(--font-mono); color: var(--text-secondary); }
.jmeta .name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jmeta2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; font: 500 11px var(--font-mono); color: var(--text-secondary); }

/* Table */
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.tbl th { text-align: left; font: 500 11px var(--font-mono); letter-spacing: 1.4px; text-transform: uppercase; color: var(--text-secondary); padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl a.rowlink { color: var(--ink); font-weight: 600; text-decoration: none; }
.tbl a.rowlink:hover { color: var(--link); }

/* Instructions */
.instr p { margin: 0 0 8px; }
.instr b { color: var(--ink); }
.refs { display: flex; gap: 12px; flex-wrap: wrap; }
.refs figure { margin: 0; width: 120px; }
.refs img { width: 120px; height: 120px; object-fit: contain; background: var(--surface-muted); border-radius: 2px; display: block; }
.refs figcaption { font: 500 11px/14px var(--font-mono); color: var(--text-secondary); margin-top: 4px; overflow-wrap: anywhere; }

/* Checks */
ul.checks { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
ul.checks li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 20px; }
ul.checks li .badge { flex: none; }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login .photo { background: var(--night); position: relative; overflow: hidden; }
.login .photo img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.login .photo img.logo { position: absolute; left: 40px; top: 40px; height: 28px; }
.login .form { display: grid; place-items: center; padding: 24px; background: var(--surface); }
.login .form > div { width: 100%; max-width: 360px; }

.navtoggle, .navbtn { display: none; }
.navlinks { display: contents; }
.cards.two { grid-template-columns: 2fr 1fr; }

/* Mòbil i tauleta: barra superior compacta amb menú desplegable; tot en una columna; taules amb desplaçament propi */
@media (max-width: 900px) {
  /* la barra amb la seva alçada; l'espai que sobra és per al contingut (si no, a les pàgines curtes s'estira) */
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 50; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 10px 16px; gap: 0; }
  .sidebar .logo { padding: 0; }
  .sidebar .logo img { height: 24px; }
  .sidebar .logo span { margin-top: 4px; font-size: 8px; line-height: 10px; letter-spacing: 1.2px; }
  .navbtn { display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border: 1px solid #2c393d; border-radius: 8px; color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; }
  .navtoggle:focus-visible + .navbtn { outline: 2px solid var(--brand-bright, #22c9dd); outline-offset: 2px; }
  .navlinks { display: none; flex-basis: 100%; flex-direction: column; gap: 4px; padding-top: 12px; }
  .navtoggle:checked ~ .navlinks { display: flex; }
  .sidebar .spacer, .sidebar .pend { display: none; }
  .sidebar .who { margin-top: 8px; padding-top: 12px; border-top: 1px solid #202b2e; }
  .topbar { height: auto; min-height: 44px; padding: 8px 16px; }
  .crumbs { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .tag-ejemplo { display: none; }
  .content { padding: 16px; gap: 16px; }
  .cards, .cards.two { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 28px; line-height: 34px; }
  table.tbl { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .login { grid-template-columns: 1fr; }
  .login .photo { display: none; }
}
}

/* Etiquetas de color (tipo Bridge) */
.labelbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lbtn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border: 1px solid var(--border-control); border-radius: 8px; background: var(--surface-raised); color: var(--ink); font: 600 13px var(--font-body); cursor: pointer; }
.lbtn:hover { background: var(--surface-muted); }
.lbtn i, .ldot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.ldot { margin-right: 6px; }
.lbtn kbd { font: 500 10px var(--font-mono); color: var(--text-secondary); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.jgrid.selectable .sel { position: absolute; z-index: 2; top: 6px; left: 6px; width: 20px; height: 20px; border-radius: 4px; border: 1.5px solid #fff; background: rgba(10, 19, 21, .35); box-shadow: 0 0 0 1px rgba(10, 19, 21, .3); cursor: pointer; opacity: 0; transition: opacity var(--duration-fast); }
.jgrid.selectable .jitem:hover .sel, .jgrid.selectable .jitem.selected .sel, .jgrid.selectable .sel:focus-visible { opacity: 1; }
.jgrid.selectable .jitem.selected .sel { background: var(--brand); border-color: var(--brand); }
.jgrid.selectable .jitem.selected .sel::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.jgrid.selectable .jitem.selected .jframe { outline: 3px solid var(--brand); outline-offset: 2px; }
.clabel { position: absolute; z-index: 2; top: 8px; right: 8px; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px #fff; }
.clabel:not([style*="background"]) { display: none; }
.b-cambios_cliente { background: var(--danger-bg); color: var(--danger); }
.b-en_acabado { background: var(--brand-wash); color: var(--brand-text); }

/* Orbe de espera (respaldo sin React del sistema de diseño) */
.orb { display: inline-block; width: 20px; height: 20px; border-radius: 50%; vertical-align: middle; background: radial-gradient(circle, var(--brand-text) 1.2px, transparent 1.6px) 0 0 / 5px 5px; -webkit-mask: radial-gradient(circle, #000 55%, transparent 70%); mask: radial-gradient(circle, #000 55%, transparent 70%); animation: orb 1.6s ease-in-out infinite; }
@keyframes orb { 50% { opacity: .55; transform: scale(.85); } }
@media (prefers-reduced-motion: reduce) { .orb { animation: none; } }

/* Cifras de tiempos */
.kpi-card { padding: 16px 20px; display: flex; flex-direction: column; gap: 2px; }
.kpi-card .overline { margin: 0 0 4px; }
.kpi-v { font: 500 28px/34px var(--font-display); letter-spacing: -.5px; color: var(--ink); }

/* Cercador de la biblioteca: graella fixa, cap camp trepitja l'altre */
.libsearch { display: grid; grid-template-columns: minmax(200px, 2fr) 80px minmax(180px, 1.5fr) minmax(150px, 1fr) minmax(150px, 1fr); gap: 12px; align-items: end; }
.libsearch .field { margin: 0; min-width: 0; }
.libsearch input, .libsearch select { width: 100%; box-sizing: border-box; height: 42px; margin: 0; }
@media (max-width: 1100px) { .libsearch { grid-template-columns: 1fr 80px 1fr; } .libsearch .f-q { grid-column: 1 / -1; } }
@media (max-width: 640px) { .libsearch { grid-template-columns: 1fr; } }

/* Filtres sense recarregar (live_filters.js) */
.js .js-hide { display: none; }
.live-results { transition: opacity .15s ease; }
.live-results.is-loading { opacity: .45; pointer-events: none; }
.live-more { height: 1px; }
.jitem.skel .jframe { background: var(--surface-muted); border-radius: 2px; animation: skel 1.2s ease-in-out infinite; }
@keyframes skel { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .live-results { transition: none; } .jitem.skel .jframe { animation: none; } }
.liblist { margin-top: 12px; }
.liblist summary { cursor: pointer; color: var(--brand-text); font-weight: 600; }
.liblist textarea { width: 100%; box-sizing: border-box; margin-top: 8px; font-size: 13px; }

/* Biblioteca: barra de selecció fixa a baix (galeria = selecció) */
.selbar { position: sticky; bottom: 0; z-index: 40; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--surface-raised); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(18, 24, 27, 0.12); }
.selbar[hidden] { display: none; }
.selbar .selcount { font-size: 14px; color: var(--ink); }
.selbar .selspacer { flex: 1; }
@media (max-width: 640px) { .selbar .selspacer { flex-basis: 100%; height: 0; } .selbar { border-radius: 12px 12px 0 0; margin: 16px -16px -16px; } }
/* Exportar: miniatures de la selecció i formats amb avisos */
.selthumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.selthumbs figure { margin: 0; width: 84px; position: relative; }
.selthumbs img { width: 84px; height: 105px; object-fit: contain; background: var(--surface-muted); border-radius: 2px; display: block; }
.selthumbs figcaption { font-size: 10px; line-height: 14px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selthumbs .vbadge { position: absolute; top: 4px; left: 4px; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: rgba(10, 19, 21, .8); color: #fff; }
.notice { background: var(--warning-bg); color: var(--warning); border-radius: 8px; padding: 12px 16px; font-size: 14px; }
label.fmt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border); margin: 0; cursor: pointer; }
label.fmt input { margin-top: 3px; }
label.fmt b { color: var(--ink); }
label.fmt .fmt-lines { display: block; margin-top: 4px; }
label.fmt.fmt-off { cursor: default; opacity: .75; }

/* Graelles: un fill amb una taula o text llarg no pot eixamplar la columna (ni la pàgina al mòbil) */
.cards > * { min-width: 0; }
.morefilt, .morefilt-btn { display: none; }
@media (max-width: 640px) {
  /* Biblioteca al mòbil: el cercador a la vista; els altres filtres, a «Más filtros» */
  .morefilt-btn { display: inline-flex; align-items: center; height: 36px; padding: 0 12px; margin-top: 10px; border: 1px solid var(--border-control); border-radius: 8px; color: var(--ink); font-weight: 600; cursor: pointer; }
  .morefilt:checked + .morefilt-btn { background: var(--surface-muted); }
  .libsearch .field:not(.f-q), .liblist { display: none; }
  .libsearch-opts label.small { display: none; }
  .morefilt:checked ~ .libsearch .field, .morefilt:checked ~ .liblist { display: block; }
  .morefilt:checked ~ .libsearch-opts label.small { display: flex; }
  .libsearch { order: -1; }
  form[data-live] { display: flex; flex-direction: column; }
  .morefilt-btn { align-self: flex-start; order: 0; }
  .libsearch-opts { order: 1; justify-content: flex-end; }
  /* fitxes de la galeria: menys text */
  .jitem .jlot { display: none; }  /* lot i data: al visor */
  .jmeta, .jmeta2 { font-size: 11px; }
  .page-head .actions .btn { height: 34px; }
}
