/* ==========================================================================
   FECATRA — Administració d'enquestes
   Loaded after app.css: reuses its tokens and components (.container, .btn,
   .field/.input, .alert, .callout) and only adds what the panel needs —
   dark top bar, sober tables and status/position badges. Same editorial
   direction: hairlines, no shadows.
   ========================================================================== */

/* ------------------------------ Shell ------------------------------------ */
.admin-body { background: var(--bg-alt); }

.admin-main { padding: 40px 0 80px; }

/* ------------------------------ Top bar ----------------------------------- */
.admin-topbar {
    background: var(--bg-dark);
    color: var(--on-dark);
    border-bottom: 3px solid var(--red);
}
.admin-topbar__inner {
    display: flex;
    align-items: center;
    gap: 26px;
    flex-wrap: wrap;
    min-height: 62px;
    padding-top: 8px;
    padding-bottom: 8px;
}

.admin-brand {
    font-family: var(--font-head);
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: .05em;
    color: #fff;
    white-space: nowrap;
}
.admin-brand:hover { color: #fff; }
.admin-brand__sep { color: var(--red); }

.admin-nav { display: flex; align-items: center; gap: 2px; }
.admin-nav a {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: .88rem;
    color: var(--on-dark);
    padding: 8px 12px;
    border-bottom: 2px solid transparent;
}
.admin-nav a:hover { color: #fff; }
.admin-nav a.is-active { color: #fff; border-bottom-color: var(--red); }

.admin-topbar__meta {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.admin-lang { display: flex; align-items: center; }
.admin-lang a {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .74rem;
    letter-spacing: .08em;
    color: #8c9399;
    padding: 4px 8px;
}
.admin-lang a + a { border-left: 1px solid rgba(255, 255, 255, .18); }
.admin-lang a:hover { color: #fff; }
.admin-lang a.is-current { color: #fff; }

.admin-user { font-size: .86rem; color: var(--on-dark); }

.admin-logout {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: .8rem;
    color: var(--on-dark);
    background: none;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: var(--radius);
    padding: 6px 14px;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease;
}
.admin-logout:hover { color: #fff; border-color: #fff; }

/* ---------------------------- Page header --------------------------------- */
.admin-page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin: 0 0 26px;
}
.admin-page-head h1 { font-size: clamp(1.45rem, 2.6vw, 1.9rem); margin: 0; }
.admin-page-head .eyebrow { margin-bottom: 6px; }
.admin-page-head__actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ------------------------------ Panels ------------------------------------ */
.admin-panel {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px 28px;
    margin-bottom: 24px;
}
.admin-panel > h2 { font-size: 1.08rem; margin-bottom: 16px; }
.admin-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.admin-panel__head h2 { margin: 0; font-size: 1.08rem; }
.admin-panel__help { color: var(--muted); font-size: .92rem; max-width: 72ch; }

.admin-panel--table { padding: 0; overflow: hidden; }

.admin-form { max-width: 640px; }

.admin-empty {
    background: var(--bg);
    border: 1px dashed var(--line-2);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
    padding: 40px 24px;
}

.admin-error-list { margin: 0; padding-left: 18px; }

/* ------------------------------ Tables ------------------------------------ */
/* Positioned so it also clips the .sr-only headers, which are absolute and
   would otherwise widen the whole page on a phone. */
.table-wrap { position: relative; overflow-x: auto; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
    background: var(--bg);
}
.admin-table th {
    background: var(--bg-alt);
    text-align: left;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink);
    padding: 11px 14px;
    border-bottom: 1px solid var(--line-2);
    white-space: nowrap;
}
.admin-table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    color: var(--ink-2);
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .cell-code {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .82rem;
    color: var(--ink);
    white-space: nowrap;
}

.admin-table--results { margin-bottom: 8px; }

.link-strong { font-weight: 600; color: var(--ink); }
.link-strong:hover { color: var(--red-ink); }

.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    white-space: nowrap;
}
.row-actions form { margin: 0; display: inline; }
.row-actions a { font-weight: 600; font-size: .88rem; }

.link-danger {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-weight: 600;
    font-size: .88rem;
    color: var(--red-ink);
    cursor: pointer;
}
.link-danger:hover { color: var(--red); }

/* ------------------------------ Badges ------------------------------------ */
.badge {
    display: inline-block;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .68rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-status-draft { background: var(--bg-alt); color: var(--ink-2); border-color: var(--line-2); }
.badge-status-active { background: #eef6f1; color: #2e7d32; border-color: #cbe3d5; }
.badge-status-closed { background: var(--ink-2); color: #fff; }

.badge-role-admin { background: var(--ink); color: #fff; }
.badge-role-monitor { background: var(--bg-alt); color: var(--ink-2); border-color: var(--line-2); }

.badge-you { background: var(--bg-alt); color: var(--muted); border-color: var(--line-2); }

.badge-tier { text-align: center; min-width: 34px; font-variant-numeric: tabular-nums; }

/* ------------------------------ Login ------------------------------------- */
.admin-login { max-width: 430px; margin: 48px auto 0; }
.admin-login__title { font-size: 1.3rem; margin-bottom: .35em; }
.admin-login__intro { color: var(--muted); font-size: .93rem; margin-bottom: 22px; }
.admin-login__submit { margin-top: 18px; }
.admin-login__back { display: inline-block; margin-top: 16px; color: var(--muted); font-size: .86rem; }
.admin-login__back:hover { color: var(--ink); }

/* --------------------------- Survey detail -------------------------------- */
.admin-facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 18px 28px;
    margin: 0;
}
.admin-facts dt {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .68rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 5px;
}
.admin-facts dd { margin: 0; color: var(--ink); font-weight: 600; font-size: .96rem; }

.status-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 22px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}
.status-actions form { margin: 0; }

/* Public link rows */
.copy-row {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}
.copy-row label {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}
.copy-row .input {
    min-width: 0;
    font-size: .88rem;
    color: var(--ink-2);
    background: var(--bg-alt);
}

.btn-sm { padding: 9px 16px; font-size: .84rem; }

.js-copy.is-copied { border-color: #2e7d32; color: #2e7d32; }

.regenerate-form { margin-top: 16px; }

/* ------------------------------ Results ----------------------------------- */
.results-total { color: var(--muted); font-size: .93rem; }
.results-subtitle { font-size: 1rem; margin: 26px 0 8px; }

.group-title {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .84rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink);
    margin: 24px 0 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line-2);
}

/* Overall ranking: most important action first. */
.ranking {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    counter-reset: none;
}
.ranking__item {
    display: grid;
    grid-template-columns: 46px auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}
.ranking__item:last-child { border-bottom: 0; }
.ranking__item:nth-child(even) { background: var(--bg-alt); }

.ranking__pos {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .84rem;
    color: var(--muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.ranking__code { align-self: center; }
.ranking__name { font-size: .9rem; color: var(--ink); line-height: 1.35; }
.ranking__avg {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .78rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
    min-width: 52px;
    padding: 3px 8px;
    border-radius: var(--radius);
}
.ranking__avg--none {
    background: var(--bg-alt);
    color: var(--muted);
    border: 1px solid var(--line-2);
    font-weight: 600;
    white-space: nowrap;
}
.ranking__n { font-size: .76rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--ink-2);
    font-size: .8rem;
    line-height: 1.35;
    padding: 3px 10px 3px 3px;
}
.chip__code {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: .68rem;
    letter-spacing: .04em;
    color: #fff;
    background: var(--ink);
    border-radius: 2px;
    padding: 2px 6px;
    white-space: nowrap;
}

/* ---------------------------- Responsive ---------------------------------- */
@media (max-width: 760px) {
    .admin-main { padding: 26px 0 60px; }
    .admin-topbar__inner { gap: 12px 18px; }
    /* More links than a phone is wide: the row scrolls instead of wrapping. */
    .admin-nav { order: 3; width: 100%; border-top: 1px solid rgba(255, 255, 255, .12); padding-top: 4px; overflow-x: auto; scrollbar-width: none; }
    .admin-nav::-webkit-scrollbar { display: none; }
    .admin-nav a { white-space: nowrap; }
    .admin-user { display: none; }

    .admin-panel { padding: 20px 18px; }

    .ranking__item {
        grid-template-columns: 34px auto minmax(0, 1fr);
        row-gap: 4px;
    }
    /* Average and response count drop under the name, still in reading order. */
    .ranking__avg { grid-column: 2; justify-self: start; }
    .ranking__n { grid-column: 3; }

    .copy-row { grid-template-columns: 1fr; gap: 6px; }
    .copy-row .btn { justify-self: start; }

    .row-actions { justify-content: flex-start; }
}

/* ============================== News panel ================================ */

/* ------------------------------- Filters ---------------------------------- */
.admin-filters {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 22px;
}
.admin-filters fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 0 18px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; }
.admin-filters .field { margin-bottom: 0; }
.admin-filters__actions { display: flex; align-items: center; gap: 14px; padding-bottom: 2px; }
.admin-filters__actions a { font-size: .86rem; font-weight: 600; }
/* Four filters instead of three; the mobile rule below still collapses it. */
.admin-filters--wide fieldset { grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)) auto; }

/* --------------------------- Table additions ------------------------------ */
/* Secondary language under the primary one, so a missing translation is
   visible from the listing instead of only on opening the record. */
.admin-table__sub {
    display: block;
    font-size: .82rem;
    color: var(--muted);
    margin-top: 2px;
}

.admin-table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.admin-table th a:hover { color: var(--red-ink); }
.admin-table th[aria-sort="ascending"] a::after { content: "\2191"; }
.admin-table th[aria-sort="descending"] a::after { content: "\2193"; }
.admin-table th[aria-sort="none"] a::after { content: "\2195"; opacity: .35; }

.badge-status-published { background: #eef6f1; color: #2e7d32; border-color: #cbe3d5; }
/* Published, but dated ahead: saved and correct, simply not live yet. */
.badge-status-scheduled { background: #fff8e6; color: #8a6100; border-color: #efdca8; }

/* ------------------------- Bilingual content -------------------------- */
.admin-i18n-card {
    border: 1px solid var(--line);
    border-left: 3px solid var(--line-2);
    border-radius: var(--radius);
    padding: 20px;
}
.admin-i18n-card + .admin-i18n-card { margin-top: 20px; }
.admin-i18n-card__title {
    font-size: .78rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink);
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}
.admin-i18n-card__title span { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }

.field--check > label { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: .92rem; }
.field--check input { width: 16px; height: 16px; }

.form-actions__group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.admin-image-preview { margin-bottom: 16px; }
.admin-image-preview img {
    max-width: 420px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.admin-image-preview p { margin: 8px 0 0; }

/* ------------------------------ Editor ------------------------------------ */
/* Quill's snow theme, retinted with the project's own tokens: square corners,
   hairline rules, no lifts. */
.admin-editor { margin-top: 2px; }
.admin-editor .ql-toolbar.ql-snow,
.admin-editor .ql-container.ql-snow {
    border-color: var(--line-2);
    border-radius: 0;
}
.admin-editor .ql-toolbar.ql-snow { background: var(--bg-alt); }
.admin-editor .ql-container.ql-snow { background: var(--bg); }
.admin-editor .ql-editor {
    min-height: 320px;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.62;
    color: var(--ink-2);
}
.admin-editor .ql-editor h2,
.admin-editor .ql-editor h3 { font-family: var(--font-head); color: var(--ink); }
.admin-editor .ql-editor img { max-width: 100%; height: auto; }
.admin-editor .ql-snow .ql-stroke { stroke: var(--ink-2); }
.admin-editor .ql-snow .ql-fill { fill: var(--ink-2); }
.admin-editor .ql-snow .ql-picker { color: var(--ink-2); }
.admin-editor .ql-snow.ql-toolbar button:hover .ql-stroke,
.admin-editor .ql-snow.ql-toolbar button.ql-active .ql-stroke { stroke: var(--red); }
.admin-editor .ql-snow.ql-toolbar button:hover .ql-fill,
.admin-editor .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--red); }
.admin-editor .ql-editor.ql-blank::before { color: var(--muted); font-style: normal; }

/* ============================ Denuncies panel ============================= */

/* A report is read, never edited, so its detail page is plain blocks of text:
   the checked irregularities, the free-text fields as they were typed, and the
   files as a download list. */
.admin-bullets { margin: 0; padding-left: 20px; color: var(--ink-2); }
.admin-bullets li { padding: 3px 0; }

.admin-longtext {
    background: var(--bg-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 0;
    color: var(--ink-2);
    /* Kept as typed: line breaks in a report are often the reporter's own
       structure. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.admin-files { list-style: none; margin: 0; padding: 0; }
.admin-files li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.admin-files li:last-child { border-bottom: 0; }
.admin-files a { font-weight: 600; overflow-wrap: anywhere; }
.admin-files__action { font-size: .82rem; color: var(--muted); white-space: nowrap; }

/* Reports may be filed without contact details, and the list has to say so
   rather than leave the column blank. */
.badge-anonymous { background: var(--bg-alt); color: var(--muted); border-color: var(--line-2); }

/* The files panel puts a download list and a fact side by side in one block. */
.admin-facts + .admin-files,
.admin-files + .admin-facts { margin-top: 18px; }

@media (max-width: 760px) {
    .admin-filters fieldset { grid-template-columns: 1fr; gap: 0; }
    .admin-filters .field { margin-bottom: 14px; }
    .admin-filters__actions { padding-bottom: 0; }

    .admin-i18n-card { padding: 16px; }
    .admin-editor .ql-editor { min-height: 240px; }
}
