/* Portal de clients — sistema visual comu.
   El color corporatiu (--brand) es defineix per instal·lacio des de Configuracio. */

:root {
    --brand: #1d4ed8;
    --brand-strong: color-mix(in srgb, var(--brand) 82%, #000);
    --brand-soft: var(--brand-tint, color-mix(in srgb, var(--brand) 10%, #fff));
    --brand-text: var(--brand-ink, var(--brand));
    --on-brand: #fff;
    --brand-ring: color-mix(in srgb, var(--brand) 28%, transparent);

    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --border-strong: #cfd6e1;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #7b8799;

    --sidebar: #0f172a;
    --sidebar-2: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #64748b;
    --sidebar-strong: #fff;
    --sidebar-border: rgba(255, 255, 255, .07);

    --success: #15803d; --success-soft: #e8f6ee;
    --warning: #b45309; --warning-soft: #fdf3e2;
    --danger: #b91c1c;  --danger-soft: #fdecec;
    --info: #1e40af;    --info-soft: #eaf0fd;
    --danger-text: #8f1d1d;  --danger-border: #f5cfcf;
    --success-text: #14532d; --success-border: #c9e8d4;
    --warning-text: #7c3d0b; --warning-border: #f2dcb5;
    --info-text: #1e3a8a;    --info-border: #cfdcf9;
    --chip: #eef1f5;
    --row-hover: #fafbfd;
    --mark: #fff0a6;
    --input-bg: #fff;

    --radius: 10px;
    --radius-sm: 7px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 6px 16px rgba(15, 23, 42, .05);
    --font: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .92em; }
.icon { flex-shrink: 0; vertical-align: middle; }

/* ---------- Estructura de l'aplicacio ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 252px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px 18px;
    color: var(--sidebar-strong);
    text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-logo {
    width: 40px; height: 40px;
    border-radius: 9px;
    background: #fff;
    display: grid; place-items: center;
    overflow: hidden;
    flex-shrink: 0;
}
.brand-logo img { max-width: 34px; max-height: 34px; object-fit: contain; }
.brand-mark {
    width: 40px; height: 40px;
    border-radius: 9px;
    background: var(--brand);
    color: var(--on-brand);
    font-weight: 700;
    font-size: 15px;
    display: grid; place-items: center;
    flex-shrink: 0;
    letter-spacing: .02em;
}
.brand-name { font-weight: 650; font-size: 14.5px; line-height: 1.25; }
.brand-sub { font-size: 12px; color: var(--sidebar-muted); }

.nav { padding: 6px 10px 16px; flex: 1; }
.nav-section {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--sidebar-muted);
    padding: 16px 10px 6px;
}
.nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 10px;
    margin: 1px 0;
    border-radius: 7px;
    color: var(--sidebar-text);
    font-size: 14px;
    text-decoration: none;
}
.nav a:hover { background: var(--sidebar-2); color: var(--sidebar-strong); text-decoration: none; }
.nav a.active { background: var(--brand); color: var(--on-brand); }
.nav a .icon { opacity: .9; }
/* Comptador de documents nous (menu i campaneta del mobil) */
.nav-count {
    margin-left: auto;
    min-width: 20px; height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #dc2626;
    color: #fff;
    font-size: 11.5px; font-weight: 650;
    display: inline-grid; place-items: center;
    line-height: 1;
}
.topbar-bell { display: none; }
tr.is-vist { opacity: .55; }

.sidebar-user {
    border-top: 1px solid var(--sidebar-border);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--sidebar-2);
    color: var(--sidebar-text);
    display: grid; place-items: center;
    font-size: 12.5px;
    font-weight: 600;
    flex-shrink: 0;
}
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .name { color: var(--sidebar-strong); font-size: 13.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .role { font-size: 12px; color: var(--sidebar-muted); }
.sidebar-user a { color: var(--sidebar-muted); display: grid; place-items: center; padding: 6px; border-radius: 6px; }
.sidebar-user a:hover { color: var(--sidebar-strong); background: var(--sidebar-2); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 30px 36px 48px; max-width: 1240px; width: 100%; }

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.page-head h1 { font-size: 23px; font-weight: 680; }
.page-head .subtitle { color: var(--text-2); margin-top: 4px; font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--text-3); font-size: 13px; margin-bottom: 10px; }
.back-link:hover { color: var(--brand-text); text-decoration: none; }

.footer { margin-top: auto; padding: 18px 36px; color: var(--text-3); font-size: 12px; }

/* ---------- Components ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card + .card, .card + .grid, .grid + .card { margin-top: 20px; }
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15.5px; font-weight: 640; }
.card-head a { font-size: 13px; }
.card-body { padding: 20px; }
.card-narrow { max-width: 640px; }

.grid { display: grid; gap: 20px; }
.grid > .card { margin-top: 0; }
.form > .grid { margin: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    gap: 14px;
    align-items: center;
    box-shadow: var(--shadow-sm);
    color: inherit;
}
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow); text-decoration: none; }
.stat-icon {
    width: 40px; height: 40px;
    border-radius: 9px;
    display: grid; place-items: center;
    background: var(--brand-soft);
    color: var(--brand-text);
    flex-shrink: 0;
}
.stat-value { display: block; font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 3px; line-height: 1.3; }
.stat.is-alert .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.is-alert .stat-value { color: var(--danger); }

/* Taules */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-3);
    background: var(--surface-2);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--row-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--text-3); font-size: 13px; }
.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions > * { margin-left: 4px; }
.cell-actions form { display: inline; }
.empty { text-align: center; padding: 36px 16px !important; color: var(--text-3); }

/* Etiquetes */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-neutral { background: var(--chip); color: var(--text-2); }
.badge-brand { background: var(--brand-soft); color: var(--brand-text); }
.badge-plain::before { display: none; }
.tag { font-size: 12px; color: var(--text-2); background: var(--chip); padding: 1px 7px; border-radius: 5px; }

/* Botons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-border); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--chip); color: var(--text); }
.btn-block { width: 100%; height: 42px; font-size: 15px; }

/* Formularis */
.form { display: grid; gap: 18px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field label { display: block; font-size: 13.5px; font-weight: 560; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12.5px; color: var(--text-3); margin-top: 5px; }
.input, .field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=date], .field input[type=file], .field select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font: inherit;
    font-size: 14.5px;
    color: var(--text);
    transition: border-color .12s, box-shadow .12s;
}
.field input[type=file] { padding: 7px 10px; height: auto; }
.field input[type=color] { width: 56px; height: 40px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--input-bg); cursor: pointer; }
.input:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.form-actions { display: flex; gap: 10px; align-items: center; padding-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.password-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--text-3);
    width: 34px; height: 32px; border-radius: 6px; cursor: pointer;
    display: grid; place-items: center;
}
.password-toggle:hover { color: var(--text); background: var(--chip); }

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 170px; flex: 1; }
.filters .field label { font-size: 12.5px; color: var(--text-2); }

/* Avisos */
.alert {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border); }
.alert-success { background: var(--success-soft); color: var(--success-text); border-color: var(--success-border); }
.alert-warning { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning-border); }
.alert-info { background: var(--info-soft); color: var(--info-text); border-color: var(--info-border); }
.secret {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    margin-top: 8px;
}
.secret code {
    background: var(--input-bg);
    border: 1px dashed var(--border-strong);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    color: var(--text);
    word-break: break-all;
}

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-2); }

.dl { display: grid; grid-template-columns: 170px 1fr; gap: 12px 16px; margin: 0; }
.dl dt { color: var(--text-3); font-size: 13.5px; }
.dl dd { margin: 0; }

.logo-preview {
    display: flex; align-items: center; gap: 16px;
    padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
    margin-bottom: 10px;
}
.logo-preview img { max-height: 56px; max-width: 200px; object-fit: contain; }

/* ---------- Pantalles d'acces (login, recuperacio) ---------- */
.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    background: var(--surface);
}
.auth-aside {
    position: relative;
    overflow: hidden;
    background: linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 55%, #0b1224 130%);
    color: var(--on-brand);
    padding: 48px 56px;
    display: flex;
    flex-direction: column;
}
.auth-aside::after {
    content: "";
    position: absolute;
    width: 520px; height: 520px;
    right: -180px; bottom: -200px;
    border-radius: 50%;
    border: 70px solid rgba(255, 255, 255, .06);
}
/* Logo gran de l'empresa: targeta blanca (els logos solen estar pensats per a fons blanc) que "sura" sobre el color corporatiu */
.auth-hero { position: relative; z-index: 1; margin-top: auto; }
.auth-hero::before {
    content: "";
    position: absolute;
    left: -60px; top: -70px;
    width: 420px; height: 300px;
    background: radial-gradient(closest-side, color-mix(in srgb, var(--on-brand) 16%, transparent), transparent);
    pointer-events: none;
    z-index: -1;
}
.auth-logo {
    display: inline-grid;
    place-items: center;
    min-width: 132px; min-height: 132px;
    padding: 26px 34px;
    background: #fff;
    border-radius: 26px;
    box-shadow: 0 0 0 10px color-mix(in srgb, var(--on-brand) 9%, transparent), 0 28px 60px -18px rgba(0, 0, 0, .55);
    animation: auth-logo-in .6s cubic-bezier(.2, .8, .2, 1) both;
}
.auth-logo img { display: block; max-width: 100%; height: auto; }
.auth-logo-initials { font-size: 44px; font-weight: 800; letter-spacing: .02em; color: var(--brand-ink, var(--brand)); line-height: 1; }
.auth-company { margin-top: 26px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; animation: auth-logo-in .6s .08s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes auth-logo-in { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .auth-logo, .auth-company { animation: none; } }
.auth-pitch { position: relative; z-index: 1; max-width: 440px; margin: 44px 0 auto; padding-top: 30px; border-top: 1px solid color-mix(in srgb, var(--on-brand) 18%, transparent); }
.auth-pitch h2 { font-size: 28px; font-weight: 700; line-height: 1.2; margin-bottom: 12px; letter-spacing: -0.02em; }
.auth-pitch p { color: color-mix(in srgb, var(--on-brand) 82%, transparent); font-size: 15.5px; margin: 0 0 24px; }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.auth-points li { display: flex; align-items: center; gap: 10px; color: color-mix(in srgb, var(--on-brand) 90%, transparent); font-size: 14.5px; }
.auth-points .icon { background: color-mix(in srgb, var(--on-brand) 14%, transparent); border-radius: 50%; padding: 4px; width: 26px; height: 26px; }
.auth-foot { position: relative; z-index: 1; margin-top: 40px; font-size: 12.5px; color: color-mix(in srgb, var(--on-brand) 60%, transparent); }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.auth-card .lead { color: var(--text-2); margin: 0 0 26px; }
.auth-links { margin-top: 20px; text-align: center; font-size: 14px; }
.auth-mobile-brand { display: none; }

/* ---------- Pagina d'error ---------- */
.error-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; text-align: center; }
.error-page .code { font-size: 64px; font-weight: 800; color: var(--brand-text); letter-spacing: -0.03em; line-height: 1; }
.error-page h1 { font-size: 22px; margin: 12px 0 8px; }
.error-page p { color: var(--text-2); margin: 0 0 24px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        z-index: 40;
        left: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
    .nav-backdrop { display: none; }
    .nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 30; }
    .topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 16px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky; top: 0; z-index: 20;
    }
    .topbar .brand-mark, .topbar .brand-logo { width: 32px; height: 32px; font-size: 12px; border-radius: 8px; }
    .topbar .brand-logo { border: 1px solid var(--border); }
    .topbar .brand-logo img { max-width: 26px; max-height: 26px; }
    .topbar .title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar-bell { display: grid; place-items: center; position: relative; margin-left: auto; width: 38px; height: 38px; color: var(--text); border-radius: 8px; flex-shrink: 0; }
    .topbar-bell .nav-count { position: absolute; top: 1px; right: -2px; margin: 0; min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 5px; }
    .menu-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
    .content { padding: 22px 16px 36px; }
    .footer { padding: 16px; }
    .auth { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .auth-mobile-brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 30px; text-align: center; }
    .auth-mobile-brand .auth-logo { min-width: 96px; min-height: 96px; padding: 16px 22px; border-radius: 20px; border: 1px solid var(--border); box-shadow: 0 0 0 6px var(--brand-soft), 0 14px 32px -16px rgba(15, 23, 42, .35); }
    .auth-mobile-brand .auth-logo-initials { font-size: 32px; }
    .auth-mobile-brand .name { font-weight: 700; font-size: 18px; }
}
@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; }
    .page-head h1 { font-size: 20px; }
    .page-actions, .page-actions .btn { width: 100%; }
    .dl { grid-template-columns: 1fr; gap: 2px 0; }
    .dl dd { margin-bottom: 10px; }
    td, th { padding: 10px 12px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 12px; gap: 10px; }
    .stat-icon { width: 34px; height: 34px; }
    .stat-value { font-size: 19px; }
}

@media print {
    .sidebar, .topbar, .page-actions, .cell-actions { display: none !important; }
    .content { padding: 0; }
}

/* ---------- Cercadors i llistes llargues ---------- */
.card .filters { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.filters .field { margin: 0; }
.filters .field-wide { flex: 2; min-width: 220px; }
.filters .actions { display: flex; gap: 8px; }
.filter-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; background: var(--brand-soft); color: var(--brand-text); border-radius: 999px; padding: 3px 6px 3px 12px; }
.filter-chip a { color: inherit; font-weight: 600; padding: 0 6px; }
.pagination .page-actions { width: auto; }

/* Accessos de la fitxa del client: les accions baixen a sota si no hi caben */
.access-list { list-style: none; margin: 0; padding: 0; }
.access-item { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.access-item:last-child { border-bottom: none; }
.access-item .who { flex: 1 1 200px; min-width: 0; }
.access-item .who .cell-muted { overflow-wrap: anywhere; }
.access-item .acts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.access-item .acts form { margin: 0; }

/* Al mobil, les taules marcades amb .table-cards es mostren com a targetes */
@media (max-width: 700px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
    .table-cards tbody tr:last-child { border-bottom: none; }
    .table-cards td { border: none; padding: 3px 0; }
    .table-cards td[data-label] { display: flex; justify-content: space-between; gap: 12px; text-align: right; }
    .table-cards td[data-label]::before { content: attr(data-label); color: var(--text-3); font-size: 12.5px; text-align: left; font-weight: 500; }
    .table-cards td.card-title { font-size: 15.5px; padding-bottom: 6px; }
    .table-cards td.cell-actions { text-align: left; white-space: normal; padding-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
    .table-cards td.cell-actions form { margin: 0; }
    .table-cards td.cell-actions > * { margin-left: 0; }
    .table-cards td.empty { text-align: center; }
    .table-cards tbody tr:hover td { background: none; }
    /* Variant compacta: numero i data a la mateixa linia, botons a sota */
    .table-compact tr { display: grid; grid-template-columns: 1fr auto; align-items: baseline; column-gap: 12px; }
    .table-compact td.card-title { padding-bottom: 0; }
    .table-compact td.cell-muted { text-align: right; }
    .table-compact td.cell-actions, .table-compact td.empty { grid-column: 1 / -1; }
    .card .filters { padding: 14px; }
    .filters .actions { width: 100%; }
    .filters .actions .btn { flex: 1; }
}

/* ---------- Contacte i pagina legal ---------- */
.contact-card { margin-top: 20px; }
.contact-card .card-body { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 20px; }
.contact-card h2 { font-size: 15.5px; font-weight: 640; }
.contact-card p { margin: 4px 0 0; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.auth-foot a { color: inherit; text-decoration: underline; }
.auth-legal { margin-top: 28px; text-align: center; font-size: 12.5px; color: var(--text-3); }
.auth-legal a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.footer a { color: inherit; }

.legal { max-width: 760px; margin: 0 auto; padding: 32px 16px 48px; }
.legal .legal-brand { color: var(--text); padding: 0 0 24px; }
.legal .legal-brand .brand-sub { color: var(--text-3); }
.legal .legal-brand .brand-logo { border: 1px solid var(--border); }
.legal h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.legal > .cell-muted { margin: 0 0 20px; }
.legal section { margin-top: 32px; scroll-margin-top: 16px; }
.legal h2 { font-size: 19px; font-weight: 660; margin-bottom: 10px; }
.legal .card h2 { font-size: 15.5px; }
.legal h3 { font-size: 15px; font-weight: 640; margin: 18px 0 6px; }
.legal p, .legal li { color: var(--text-2); line-height: 1.6; }
.legal ul { padding-left: 20px; }
.legal-dades { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 10px 0 0; }
.legal-dades dt { color: var(--text-3); }
.legal-dades dd { margin: 0; overflow-wrap: anywhere; }
.legal-peu { margin-top: 36px; font-size: 13px; }
@media (max-width: 600px) {
    .legal-dades { grid-template-columns: 1fr; gap: 0; }
    .legal-dades dd { margin-bottom: 8px; }
    .contact-actions, .contact-actions .btn { width: 100%; }
}

/* ---------- Cataleg d'articles ---------- */
.article-search { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card .article-search .filters { padding: 0; border: none; margin-top: 12px; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-box input { width: 100%; height: 48px; font: inherit; font-size: 16px; padding: 0 14px 0 44px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.search-box input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.filters .field-price { min-width: 200px; }
.price-range { display: flex; align-items: center; gap: 6px; color: var(--text-3); }
.price-range input { min-width: 0; }
.results-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 12px 20px; border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text-2); }
.results-count strong { color: var(--text); }
.results-clear { font-size: 13px; margin-left: auto; }
.brand-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 10px 20px; border-bottom: 1px solid var(--border); font-size: 13px; background: var(--surface-2); }
.brand-pill { display: inline-flex; gap: 6px; align-items: center; padding: 3px 10px; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); background: var(--surface); text-decoration: none; }
.brand-pill span { color: var(--text-3); font-size: 12px; }
.brand-pill:hover { border-color: var(--brand); color: var(--brand-text); }
.article-table td { vertical-align: top; }
.article-code { white-space: nowrap; }
.code-wrap { display: inline-flex; align-items: center; gap: 2px; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.copy-btn { display: inline-flex; align-items: center; gap: 4px; border: none; background: none; color: var(--text-3); cursor: pointer; padding: 3px 5px; border-radius: 5px; font: inherit; font-size: 12px; }
.copy-btn span { display: none; }
.copy-btn:hover { color: var(--brand-text); background: var(--brand-soft); }
.copy-btn.is-copied, .copy-btn.is-copied:hover { color: var(--success); background: var(--success-soft); }
.copy-btn.is-copied span { display: inline; }
.article-name .cell-strong, .article-desc, .article-meta { display: block; }
.article-desc { font-size: 13px; color: var(--text-2); }
.article-meta { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.article-price { white-space: nowrap; }
.price-box { display: block; }
.price-box .price { display: block; font-weight: 600; }
.price-box small { font-weight: 400; color: var(--text-3); }
.price-detail { display: block; font-size: 12px; color: var(--text-3); }
mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 2px; }
.article-note { font-size: 12.5px; margin: 10px 2px 0; }
[data-live-region="resultats"] { transition: opacity .15s; }
[data-live-region="resultats"].is-loading { opacity: .5; }

@media (max-width: 700px) {
    .article-search { padding: 14px; }
    .results-bar, .brand-suggest { padding: 10px 14px; }
    .article-table tr { display: flex; flex-direction: column; }
    .article-table td.card-title { order: -1; }
    .article-table td.article-price { white-space: normal; }
    .price-box { text-align: right; }
    .filters .field-price { min-width: 100%; }
}
.home-search { display: flex; flex-direction: column; gap: 10px; border-bottom: none; margin-bottom: 20px; }
.filters-toggle { display: none; }
@media (max-width: 700px) {
    .filters-toggle { display: inline-flex; margin-top: 10px; }
    .article-search.filters-closed .filters { display: none; }
}

/* ---------- Temes (Configuracio > Imatge corporativa) ----------
   L'atribut data-tema de <html> el posa el servidor. "clar" es el d'abans (:root). */
html[data-tema="menu-clar"] {
    --sidebar: #ffffff;
    --sidebar-2: #f1f4f8;
    --sidebar-text: #334155;
    --sidebar-muted: #8792a4;
    --sidebar-strong: #0f172a;
    --sidebar-border: var(--border);
}
html[data-tema="menu-clar"] .sidebar { border-right: 1px solid var(--border); }

html[data-tema="menu-color"] {
    --sidebar: var(--brand);
    --sidebar-2: color-mix(in srgb, var(--on-brand) 13%, transparent);
    --sidebar-text: color-mix(in srgb, var(--on-brand) 86%, transparent);
    --sidebar-muted: color-mix(in srgb, var(--on-brand) 62%, transparent);
    --sidebar-strong: var(--on-brand);
    --sidebar-border: color-mix(in srgb, var(--on-brand) 14%, transparent);
}
html[data-tema="menu-color"] .nav a.active { background: color-mix(in srgb, var(--on-brand) 20%, transparent); color: var(--on-brand); font-weight: 600; }
html[data-tema="menu-color"] .sidebar .brand-mark { background: color-mix(in srgb, var(--on-brand) 18%, transparent); }

/* Fosc: el mateix bloc serveix per a "fosc" i per a "auto" quan el dispositiu esta en mode fosc. */
html[data-tema="fosc"] {
    color-scheme: dark;
    --brand-soft: color-mix(in srgb, var(--brand) 24%, #151d2c);
    --brand-text: color-mix(in srgb, var(--brand) 50%, #fff);
    --bg: #0d1321; --surface: #151d2c; --surface-2: #1a2334;
    --border: #263247; --border-strong: #35435c;
    --text: #e6eaf1; --text-2: #aab4c3; --text-3: #7f8a9c;
    --sidebar: #090e19; --sidebar-2: #1b2537; --sidebar-text: #c3cbd8; --sidebar-muted: #6b778a;
    --sidebar-strong: #fff; --sidebar-border: rgba(255, 255, 255, .06);
    --success: #4ade80; --success-soft: rgba(74, 222, 128, .12);
    --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .12);
    --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .12);
    --info: #93b4fb;    --info-soft: rgba(96, 140, 250, .14);
    --danger-text: #fecaca;  --danger-border: rgba(248, 113, 113, .32);
    --success-text: #bbf7d0; --success-border: rgba(74, 222, 128, .3);
    --warning-text: #fde68a; --warning-border: rgba(251, 191, 36, .3);
    --info-text: #c7d7fe;    --info-border: rgba(96, 140, 250, .34);
    --chip: #222c3f; --row-hover: #182133; --mark: rgba(250, 204, 21, .32); --input-bg: #10172480;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 6px 16px rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) {
    html[data-tema="auto"] {
        color-scheme: dark;
        --brand-soft: color-mix(in srgb, var(--brand) 24%, #151d2c);
        --brand-text: color-mix(in srgb, var(--brand) 50%, #fff);
        --bg: #0d1321; --surface: #151d2c; --surface-2: #1a2334;
        --border: #263247; --border-strong: #35435c;
        --text: #e6eaf1; --text-2: #aab4c3; --text-3: #7f8a9c;
        --sidebar: #090e19; --sidebar-2: #1b2537; --sidebar-text: #c3cbd8; --sidebar-muted: #6b778a;
        --sidebar-strong: #fff; --sidebar-border: rgba(255, 255, 255, .06);
        --success: #4ade80; --success-soft: rgba(74, 222, 128, .12);
        --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .12);
        --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .12);
        --info: #93b4fb;    --info-soft: rgba(96, 140, 250, .14);
        --danger-text: #fecaca;  --danger-border: rgba(248, 113, 113, .32);
        --success-text: #bbf7d0; --success-border: rgba(74, 222, 128, .3);
        --warning-text: #fde68a; --warning-border: rgba(251, 191, 36, .3);
        --info-text: #c7d7fe;    --info-border: rgba(96, 140, 250, .34);
        --chip: #222c3f; --row-hover: #182133; --mark: rgba(250, 204, 21, .32); --input-bg: #10172480;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 6px 16px rgba(0, 0, 0, .3);
    }
}

/* Selector de tema de Configuracio: miniatures de cada tema */
.tema-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tema-option { position: relative; display: block; cursor: pointer; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 8px; background: var(--surface); }
.tema-option input { position: absolute; opacity: 0; pointer-events: none; }
.tema-option:hover { border-color: var(--brand); }
.tema-option:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.tema-option:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--brand-ring); }
.tema-name { display: block; font-size: 13.5px; font-weight: 600; margin-top: 8px; }
.tema-desc { display: block; font-size: 12px; color: var(--text-3); line-height: 1.35; }
.tema-mini { display: grid; grid-template-columns: 30% 1fr; height: 64px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.tema-mini i { display: block; }
.tema-mini .m-side { padding: 8px 5px; display: grid; align-content: start; gap: 4px; }
.tema-mini .m-side::before, .tema-mini .m-side::after { content: ""; height: 5px; border-radius: 2px; }
.tema-mini .m-main { padding: 8px; display: grid; align-content: start; gap: 5px; }
.tema-mini .m-main::before { content: ""; height: 6px; width: 60%; border-radius: 2px; }
.tema-mini .m-main::after { content: ""; height: 22px; border-radius: 3px; }
.tm-clar .m-side { background: #0f172a; } .tm-clar .m-side::before { background: var(--brand); } .tm-clar .m-side::after { background: #334155; }
.tm-clar .m-main { background: #f4f6fa; } .tm-clar .m-main::before { background: #cbd5e1; } .tm-clar .m-main::after { background: #fff; }
.tm-menu-clar .m-side { background: #fff; border-right: 1px solid #e3e8ef; } .tm-menu-clar .m-side::before { background: var(--brand); } .tm-menu-clar .m-side::after { background: #e2e8f0; }
.tm-menu-clar .m-main { background: #f4f6fa; } .tm-menu-clar .m-main::before { background: #cbd5e1; } .tm-menu-clar .m-main::after { background: #fff; }
.tm-menu-color .m-side { background: var(--brand); } .tm-menu-color .m-side::before { background: rgba(255, 255, 255, .45); } .tm-menu-color .m-side::after { background: rgba(255, 255, 255, .22); }
.tm-menu-color .m-main { background: #f4f6fa; } .tm-menu-color .m-main::before { background: #cbd5e1; } .tm-menu-color .m-main::after { background: #fff; }
.tm-fosc .m-side { background: #090e19; } .tm-fosc .m-side::before { background: var(--brand); } .tm-fosc .m-side::after { background: #1b2537; }
.tm-fosc .m-main { background: #0d1321; } .tm-fosc .m-main::before { background: #35435c; } .tm-fosc .m-main::after { background: #151d2c; }
.tm-auto { grid-template-columns: 1fr 1fr; }
.tm-auto .m-side { background: #f4f6fa; } .tm-auto .m-side::before { background: var(--brand); } .tm-auto .m-side::after { background: #fff; }
.tm-auto .m-main { background: #0d1321; } .tm-auto .m-main::before { background: var(--brand); } .tm-auto .m-main::after { background: #151d2c; }

/* ---------- Visor de documents (PDF dins del portal) ---------- */
.doc-viewer {
    width: min(1100px, 94vw);
    height: 92vh;
    max-width: none; max-height: none;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5);
    overflow: hidden;
}
.doc-viewer[open] { display: flex; flex-direction: column; animation: visor-in .22s cubic-bezier(.2, .8, .2, 1); }
.doc-viewer::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px); }
.doc-viewer-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 20px; border-bottom: 1px solid var(--border); }
.doc-viewer-title { font-size: 15px; font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-viewer-actions { display: flex; gap: 8px; flex-shrink: 0; }
.doc-viewer-frame { flex: 1; width: 100%; border: 0; background: #525659; }
html.visor-obert { overflow: hidden; }
@keyframes visor-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .doc-viewer[open] { animation: none; } }

/* ---------- Pagina 404 ---------- */
.error-page { background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent 70%), var(--bg); }
.error-card { max-width: 460px; }
.error-illustration { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; }
.error-digit { font-size: 88px; font-weight: 800; line-height: 1; letter-spacing: -0.04em; color: var(--brand-text); }
.error-zero {
    width: 78px; height: 78px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brand);
    color: var(--on-brand);
    box-shadow: 0 0 0 8px var(--brand-soft), 0 16px 34px -14px var(--brand);
    animation: error-buscant 2.6s ease-in-out infinite;
}
@keyframes error-buscant { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .error-zero { animation: none; } }
.error-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.error-brand { margin-top: 34px; font-size: 12.5px; color: var(--text-3); }
@media (max-width: 600px) { .error-digit { font-size: 64px; } .error-zero { width: 58px; height: 58px; } }

/* ---------- Instal·lar com una app ---------- */
.nav-install {
    display: flex; align-items: center; gap: 11px;
    margin: 0 10px 12px;
    padding: 10px 12px;
    border: 1px dashed var(--sidebar-border);
    border-radius: 9px;
    background: transparent;
    color: var(--sidebar-text);
    font: inherit; text-align: left;
    cursor: pointer;
}
.nav-install[hidden] { display: none; }
.nav-install:hover { background: var(--sidebar-2); color: var(--sidebar-strong); border-style: solid; }
.nav-install strong { display: block; font-size: 13.5px; font-weight: 600; }
.nav-install small { display: block; font-size: 11.5px; color: var(--sidebar-muted); }
/* Obert com a app (sense barra del navegador): un pel mes d'aire a dalt a l'iPhone */
@media (display-mode: standalone) { .topbar { padding-top: max(10px, env(safe-area-inset-top)); } }
