:root {
    --orange: #FC5000;
    --black: #000000;
    --white: #FFFFFF;
    --gray: #D9D9D9;
    --text: #1a1a1a;
    --muted: #666666;
    --danger: #b00020;
    --ok: #0f7a3a;
    --font-title: "Playfair Display", Georgia, serif;
    --font-body: "Open Sans", system-ui, sans-serif;
    --space: 1rem;
    --radius: 8px;
}

* { box-sizing: border-box; }
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-body);
    color: var(--text);
    background: linear-gradient(180deg, #fff 0%, #fafafa 100%);
    min-height: 100vh;
    line-height: 1.45;
    overflow-x: hidden;
}
img, video { max-width: 100%; height: auto; }
a { color: var(--orange); }
h1, h2, h3 {
    font-family: var(--font-title);
    font-weight: 600;
    margin: 0 0 .5rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
h1 { font-size: clamp(1.45rem, 4vw, 2rem); }
h2 { font-size: clamp(1.15rem, 3vw, 1.45rem); }

.container {
    width: min(1100px, calc(100% - 1.5rem));
    margin-inline: auto;
}
.skip-link {
    position: absolute; left: -9999px; top: auto;
}
.skip-link:focus { left: 1rem; top: 1rem; background: #fff; padding: .5rem 1rem; z-index: 10; }

.site-header {
    border-bottom: 1px solid var(--gray);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .85rem 0;
    flex-wrap: wrap;
}
.brand { text-decoration: none; color: var(--black); display: grid; gap: .15rem; min-width: 0; align-content: center; }
.brand-logo {
    display: block;
    height: 34px;
    width: auto;
    max-width: min(180px, 55vw);
    object-fit: contain;
    object-position: left center;
}
.brand-mark { font-family: var(--font-title); font-size: 1.45rem; color: var(--orange); }
.brand-sub { font-size: .8rem; color: var(--muted); }
.header-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem .65rem;
    align-items: center;
    width: 100%;
}
.header-nav a {
    text-decoration: none;
    color: var(--black);
    font-weight: 600;
    padding: .35rem .15rem;
    font-size: .95rem;
}
.header-nav a:hover { color: var(--orange); }
.header-nav form { margin: 0; }
.user-chip {
    font-size: .85rem;
    color: var(--muted);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.main { padding: 1.25rem 0 2.5rem; }
.site-footer {
    border-top: 1px solid var(--gray);
    padding: 1rem 0 1.5rem;
    color: var(--muted);
    font-size: .9rem;
}

.auth-card, .panel, .stat, .action-card, .notice {
    background: #fff;
    border: 1px solid var(--gray);
    border-radius: var(--radius);
}
.auth-card {
    max-width: 460px;
    margin: 1.25rem auto;
    padding: 1.25rem;
    width: 100%;
}
.auth-brand {
    display: flex;
    justify-content: center;
    margin-bottom: .75rem;
}
.auth-logo {
    display: block;
    height: 48px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}
.lead { color: var(--muted); margin-top: 0; font-size: .95rem; }
.form-stack { display: grid; gap: 1rem; margin-top: 1rem; }
.field { display: grid; gap: .35rem; min-width: 0; }
.field label { font-weight: 600; font-size: .95rem; }

/* 16px evita zoom automàtic a iOS */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="date"],
input[type="file"],
select,
textarea {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--gray);
    border-radius: 6px;
    padding: .75rem .85rem;
    font: inherit;
    font-size: 16px;
    background: #fff;
    min-height: 2.75rem;
}
input[type="file"] {
    padding: .65rem;
    min-height: auto;
}
textarea { min-height: 5.5rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus {
    outline: 2px solid var(--orange);
    outline-offset: 2px;
}
.error { color: var(--danger); margin: 0; font-size: .9rem; }
.check {
    display: flex;
    gap: .6rem;
    align-items: flex-start;
    font-size: .95rem;
    line-height: 1.4;
}
.check input {
    margin-top: .2rem;
    width: 1.15rem;
    height: 1.15rem;
    flex-shrink: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 6px;
    padding: .8rem 1.1rem;
    min-height: 2.75rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
.btn-primary { background: var(--orange); color: #fff; }
.btn-ghost { background: transparent; color: var(--black); border: 1px solid var(--gray); }
.alert { padding: .85rem 1rem; border-radius: 6px; margin: 1rem 0; }
.alert-success { background: #e8f6ee; color: var(--ok); border: 1px solid #bfe5cd; }

.page-head { margin-bottom: 1.15rem; }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.stat { padding: 1rem; }
.stat-label { display: block; color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.stat strong { font-size: 1.45rem; }
.panel { padding: 1rem; }
.list-row {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    align-items: flex-start;
    padding: .85rem 0;
    border-bottom: 1px solid var(--gray);
}
.list-row:last-child { border-bottom: 0; }
.muted { color: var(--muted); display: block; font-size: .9rem; }
.badge {
    background: #fff4ef; color: var(--orange); border: 1px solid #ffd5c2;
    border-radius: 999px; padding: .2rem .65rem; font-size: .8rem; white-space: nowrap;
}
.badge-warn {
    background: #fff8e6; color: #9a6b00; border-color: #f0d48a; margin-left: .35rem;
}
.stats-grid a.stat { text-decoration: none; color: inherit; display: block; }
.stats-grid a.stat:hover { border-color: var(--orange); }
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
    margin-bottom: .5rem;
    flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
.split-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stack-form { display: grid; gap: .65rem; }
.stack-form label { font-size: .85rem; color: var(--muted); }
.filters-form {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    width: 100%;
}
.filters-form select,
.filters-form input[type="search"] {
    min-width: 0;
    flex: 1 1 100%;
}
.check-inline { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; }
.alert-error {
    background: #fff1f0; border: 1px solid #f5c2c0; color: #8a1f11;
    padding: .85rem 1rem; border-radius: 6px; margin-bottom: 1rem;
}
.alert-error ul { margin: 0; padding-left: 1.1rem; }
.note-row p { margin: .35rem 0 0; }
.small { font-size: .85rem; }
.action-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.action-card {
    padding: 1.1rem 1.15rem;
    text-decoration: none;
    color: var(--black);
    font-weight: 600;
    transition: border-color .15s ease, transform .15s ease;
}
.action-card:hover { border-color: var(--orange); transform: translateY(-1px); }
.notice {
    margin: 1rem 0;
    padding: .9rem 1rem;
    border-left: 4px solid var(--orange);
}
.notice p { margin: 0; }
.notice-error {
    border-left-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, transparent);
}
.notice-error ul {
    margin: .4rem 0 0;
    padding-left: 1.2rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    justify-content: space-between;
    align-items: stretch;
    margin-bottom: 1rem;
}
.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    width: 100%;
}
.toolbar-actions .btn { flex: 1 1 calc(50% - .5rem); }
.search-form {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    width: 100%;
}
.search-form input {
    flex: 1 1 100%;
    min-width: 0;
}
.search-form .btn { width: 100%; }

.form-wide {
    max-width: 760px;
    width: 100%;
    padding: 1rem;
    margin: 0;
}
.form-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: .6rem;
    margin-top: .5rem;
}
.form-actions .btn { width: 100%; }
.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -.25rem;
    padding: 0 .25rem;
}
.data-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.data-table th, .data-table td {
    text-align: left;
    padding: .7rem .45rem;
    border-bottom: 1px solid var(--gray);
    vertical-align: top;
    font-size: .9rem;
}
.data-table th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
}
.details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: .85rem;
}
.details-grid dt { font-size: .8rem; color: var(--muted); }
.details-grid dd { margin: .2rem 0 0; overflow-wrap: anywhere; }
.field-subtitle { margin: 1rem 0 .35rem; font-size: 1.05rem; }
.form-section {
    padding: 1.1rem 0;
    border-bottom: 1px solid var(--gray);
}
.form-section:last-child { border-bottom: 0; padding-bottom: 0; }
.form-section h2 { margin-top: 0; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.pager { margin-top: 1rem; }
.pager-nav {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}
.pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
    min-width: 6.5rem;
    padding: .55rem 1rem;
    border: 1px solid var(--gray);
    border-radius: 6px;
    background: #fff;
    color: var(--black);
    text-decoration: none;
    font-weight: 600;
    font-size: .95rem;
}
.pager-btn:hover:not(.is-disabled) {
    border-color: var(--orange);
    color: var(--orange);
}
.pager-btn-primary {
    background: var(--orange);
    border-color: var(--orange);
    color: #fff;
}
.pager-btn-primary:hover:not(.is-disabled) {
    filter: brightness(.95);
    color: #fff;
}
.pager-btn.is-disabled {
    opacity: .45;
    cursor: not-allowed;
    background: #f5f5f5;
}
.pager a, .pager span {
    display: inline-flex; padding: .4rem .7rem; border: 1px solid var(--gray);
    border-radius: 4px; text-decoration: none; color: var(--black);
}
.results-list { display: grid; gap: .35rem; margin-top: .5rem; }
.result-item {
    text-align: left;
    border: 1px solid var(--gray);
    background: #fff;
    border-radius: 6px;
    padding: .75rem .85rem;
    cursor: pointer;
    font: inherit;
    font-size: 16px;
    width: 100%;
}
.result-item:hover { border-color: var(--orange); }
code { overflow-wrap: anywhere; }

.member-search-row {
    display: flex;
    gap: .5rem;
    align-items: stretch;
}
.member-search-row input[type="search"] {
    flex: 1 1 auto;
    min-width: 0;
}
.member-search-row .btn {
    flex: 0 0 auto;
    min-width: 3rem;
    font-size: 1.4rem;
    line-height: 1;
    padding-left: .85rem;
    padding-right: .85rem;
}
.member-selected-wrap {
    margin-top: .85rem;
    border: 1px solid var(--gray);
    border-radius: 6px;
    padding: .75rem .9rem;
    background: #fafafa;
}
.member-selected-title {
    margin: 0 0 .5rem;
    font-weight: 600;
}
.member-selected-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: .45rem;
}
.member-selected-item {
    display: flex;
    gap: .75rem;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border: 1px solid var(--gray);
    border-radius: 6px;
    padding: .65rem .75rem;
}
.btn-small {
    padding: .35rem .65rem;
    font-size: .85rem;
    white-space: nowrap;
}

/* Tablet+ */
@media (min-width: 640px) {
    .container { width: min(1100px, calc(100% - 2rem)); }
    .main { padding: 2rem 0 3rem; }
    .header-nav { width: auto; }
    .header-inner { flex-wrap: nowrap; }
    .action-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .details-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
    .split-grid { grid-template-columns: repeat(2, 1fr); }
    .form-wide { padding: 1.25rem; }
    .form-actions {
        flex-direction: row;
        justify-content: flex-end;
    }
    .form-actions .btn { width: auto; }
    .toolbar-actions { width: auto; }
    .toolbar-actions .btn { flex: 0 0 auto; }
    .search-form input { flex: 1 1 auto; min-width: 220px; }
    .search-form .btn { width: auto; }
    .filters-form select,
    .filters-form input[type="search"] {
        flex: 1 1 auto;
        min-width: 140px;
    }
    .panel { padding: 1.25rem; }
    .auth-card { padding: 1.75rem; margin: 2rem auto; }
}

/* Desktop */
@media (min-width: 900px) {
    .action-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
    .details-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
}
