/*
 * Styles for everything the plugin renders.
 *
 * Written to survive an unknown theme. Every rule is scoped under a .pphib- class, lists get their
 * bullets and padding reset explicitly rather than assuming the theme did it, and no rule reaches
 * outside the widget. Colours come from custom properties so a site can restyle the lot from
 * Additional CSS without touching the plugin or losing the changes on upgrade.
 */

.pphib-list,
.pphib-grid {
    --pphib-accent: #17884f;
    --pphib-accent-dark: #0e6339;
    --pphib-ink: #1a2420;
    --pphib-ink-2: #5c6b63;
    --pphib-ink-3: #8a978f;
    --pphib-surface: #ffffff;
    --pphib-rule: #e0e6e1;
    --pphib-wash: #f4f7f4;
    --pphib-closed: #9a7b4f;
    --pphib-radius: 10px;

    margin: 0 0 1.75rem;
    padding: 0;
    list-style: none;
}

.pphib-list *,
.pphib-grid * {
    box-sizing: border-box;
}

/*
 * No prefers-color-scheme block, deliberately.
 *
 * It was here, and it was wrong: it followed the VISITOR'S operating system, not the site. A light
 * WordPress theme viewed by someone whose laptop is set to dark mode got dark cards on a white
 * page, which reads as broken rather than as a dark theme. The site's own appearance is not
 * something CSS here can detect, so the safe default is light, matching the overwhelming majority
 * of themes.
 *
 * A genuinely dark site can turn it on in Appearance > Customise > Additional CSS:
 *
 *   .pphib-list, .pphib-grid {
 *       --pphib-ink: #e6ede7; --pphib-ink-2: #a9b8ae; --pphib-ink-3: #7e8e84;
 *       --pphib-surface: #161e1a; --pphib-rule: #2a352e; --pphib-wash: #1b241f;
 *       --pphib-accent: #4fbe85; --pphib-accent-dark: #7fd3a6; --pphib-closed: #c9a875;
 *   }
 */

/* ------------------------------------------------------------------ *
 * Document grid - syllabi and reference books
 * ------------------------------------------------------------------ */

.pphib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 22px;
}

.pphib-card {
    display: flex;
    flex-direction: column;
    background: var(--pphib-surface);
    border: 1px solid var(--pphib-rule);
    border-radius: var(--pphib-radius);
    overflow: hidden;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.pphib-card:hover,
.pphib-card:focus-within {
    transform: translateY(-3px);
    border-color: var(--pphib-accent);
    box-shadow: 0 10px 28px rgba(23, 55, 38, .13);
}

@media (prefers-reduced-motion: reduce) {
    .pphib-card { transition: none; }
    .pphib-card:hover, .pphib-card:focus-within { transform: none; }
}

/*
 * The thumbnail.
 *
 * The portal holds no cover image for a syllabus or a book - only a filename - so the tile is
 * generated from the file type instead of left blank. Drawn in CSS rather than shipped as images:
 * it stays crisp at any size, needs no HTTP request, and a file type the plugin has never seen
 * still gets a sensible tile rather than a broken image.
 */
.pphib-thumb {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    aspect-ratio: 3 / 4;
    padding: 14px;
    background: linear-gradient(150deg, var(--pphib-tint-1, #4b5a68), var(--pphib-tint-2, #2f3b46));
    text-decoration: none;
    overflow: hidden;
}

/*
 * The rendered cover, over the generated tile.
 *
 * A background layer, not an <img>, laid over the tile rather than replacing it. Both parts matter.
 * When the portal cannot supply a cover the request 404s, and a failed <img> does not quietly
 * vanish - it draws a broken-image glyph exactly where the picture should be, which is the hole
 * this arrangement was meant to avoid. A background that 404s renders nothing at all, so the tile
 * underneath is simply what shows. No JavaScript needed for any of it.
 */
.pphib-cover {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: block;
    background-size: cover;
    background-position: top center;
    background-repeat: no-repeat;
}

.pphib-ext {
    /* Sits under the cover deliberately: it labels the tile, and once a real cover loads the file
       type is no longer the most useful thing on the card. */
    z-index: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .1em;
    color: rgba(255, 255, 255, .92);
    background: rgba(255, 255, 255, .16);
    border-radius: 100px;
    padding: 4px 12px;
    text-transform: uppercase;
    line-height: 1;
}

.pphib-size {
    position: absolute;
    z-index: 2;
    /* Legible over a rendered cover as well as over the tile. Bottom right, because the cover
       carries its own file-type chip top left and the two collided there. */
    background: rgba(0, 0, 0, .42);
    border-radius: 100px;
    padding: 2px 9px;
    bottom: 13px;
    right: 14px;
    font-size: .68rem;
    letter-spacing: .05em;
    color: rgba(255, 255, 255, .82);
    font-variant-numeric: tabular-nums;
}

/*
 * File-type tints, drawn from the same eight palettes the portal renders its covers with.
 *
 * These were the bright office-suite colours - pillarbox red for PDF, Word blue - on the reasoning
 * that a familiar association makes a grid scannable. On the page they were garish, and worse, they
 * are what shows while a cover is still loading or when the portal cannot be reached: the moment
 * the API went down the whole library turned red and blue. Muted tones sit under a real cover
 * without the swap being jarring, and read as deliberate when they are all you get.
 */
.pphib-card.is-pdf   { --pphib-tint-1: #7a2e24; --pphib-tint-2: #42160f; }
.pphib-card.is-doc   { --pphib-tint-1: #1e3a5f; --pphib-tint-2: #0f1e33; }
.pphib-card.is-xls   { --pphib-tint-1: #1b4d3e; --pphib-tint-2: #0d2b22; }
.pphib-card.is-ppt   { --pphib-tint-1: #6b4518; --pphib-tint-2: #38230b; }
.pphib-card.is-img   { --pphib-tint-1: #3b2e6b; --pphib-tint-2: #1d1638; }
.pphib-card.is-other { --pphib-tint-1: #2c3e2c; --pphib-tint-2: #152015; }

.pphib-card-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 15px 16px 16px;
    flex: 1 1 auto;
}

.pphib-card .pphib-title {
    font-size: .96rem;
    font-weight: 600;
    line-height: 1.34;
    color: var(--pphib-ink);
    text-decoration: none;
    /* Two lines, so every card in a row lines up regardless of title length. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pphib-card .pphib-subject {
    font-size: .8rem;
    color: var(--pphib-ink-2);
    line-height: 1.4;
}

.pphib-card .pphib-download {
    margin-top: auto;
    padding-top: 12px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--pphib-accent-dark);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pphib-card .pphib-download:hover {
    text-decoration: underline;
}

.pphib-card .pphib-download::before {
    content: "\2193";
    font-weight: 700;
}

/* ------------------------------------------------------------------ *
 * Row lists - jobs, advertisements, trainings
 * ------------------------------------------------------------------ */

.pphib-list .pphib-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    background: var(--pphib-surface);
    border: 1px solid var(--pphib-rule);
    border-radius: var(--pphib-radius);
    padding: 16px 20px;
    margin: 0 0 10px;
    list-style: none;
}

.pphib-list .pphib-item::before,
.pphib-list .pphib-item::marker {
    content: none;
}

.pphib-list .pphib-item:hover {
    border-color: var(--pphib-accent);
}

.pphib-list .pphib-title {
    flex: 1 1 260px;
    font-size: 1.02rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--pphib-ink);
    text-decoration: none;
}

.pphib-list .pphib-title:hover {
    color: var(--pphib-accent-dark);
}

.pphib-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 8px;
    align-items: center;
}

.pphib-meta > span {
    font-size: .78rem;
    color: var(--pphib-ink-2);
    background: var(--pphib-wash);
    border-radius: 100px;
    padding: 3px 11px;
    white-space: nowrap;
}

.pphib-meta .pphib-deadline {
    font-variant-numeric: tabular-nums;
}

/* Closed items stay visible - the archive is part of what the site shows - but must not be
   mistaken for something still open. */
.pphib-status {
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    border-radius: 100px;
    padding: 3px 11px;
    white-space: nowrap;
}

.pphib-status.is-open {
    color: #fff;
    background: var(--pphib-accent);
}

.pphib-status.is-closed {
    color: var(--pphib-closed);
    background: transparent;
    border: 1px solid currentColor;
}

.pphib-item.is-closed .pphib-title {
    color: var(--pphib-ink-2);
}

.pphib-apply {
    flex: 0 0 auto;
    font-size: .85rem;
    font-weight: 600;
    color: #fff;
    background: var(--pphib-accent);
    border-radius: 6px;
    padding: 8px 18px;
    text-decoration: none;
    white-space: nowrap;
}

.pphib-apply:hover,
.pphib-apply:focus {
    background: var(--pphib-accent-dark);
    color: #fff;
}

/* ------------------------------------------------------------------ *
 * Expandable advertisements
 *
 * Built on <details>, so it opens with no JavaScript, from the keyboard, and is searchable by the
 * browser's own find-in-page even while shut.
 * ------------------------------------------------------------------ */

.pphib-item.is-accordion {
    display: block;
    padding: 0;
}

.pphib-details > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 16px 20px;
    cursor: pointer;
    list-style: none;
}

.pphib-details > summary::-webkit-details-marker,
.pphib-details > summary::marker {
    display: none;
    content: none;
}

.pphib-details > summary:hover .pphib-title {
    color: var(--pphib-accent-dark);
}

.pphib-details > summary:focus-visible {
    outline: 2px solid var(--pphib-accent);
    outline-offset: -2px;
    border-radius: var(--pphib-radius);
}

.pphib-caret {
    margin-left: auto;
    flex: 0 0 auto;
    width: 11px;
    height: 11px;
    border-right: 2px solid var(--pphib-ink-3);
    border-bottom: 2px solid var(--pphib-ink-3);
    transform: rotate(45deg);
    transform-origin: center;
    transition: transform .18s ease;
}

.pphib-details[open] .pphib-caret {
    transform: rotate(-135deg);
}

@media (prefers-reduced-motion: reduce) {
    .pphib-caret { transition: none; }
}

.pphib-panel {
    padding: 4px 20px 18px;
    border-top: 1px solid var(--pphib-rule);
    margin-top: 2px;
}

.pphib-posts {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 2px 20px;
}

.pphib-posts li {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 10px 0;
    border-bottom: 1px solid var(--pphib-rule);
    list-style: none;
}

.pphib-post-title {
    font-weight: 600;
    font-size: .93rem;
    color: var(--pphib-ink);
}

.pphib-post-meta {
    font-size: .78rem;
    color: var(--pphib-ink-2);
}

.pphib-panel-link {
    display: inline-block;
    margin-top: 14px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--pphib-accent-dark);
    text-decoration: none;
}

.pphib-panel-link:hover {
    text-decoration: underline;
}

/* ------------------------------------------------------------------ *
 * Shared
 * ------------------------------------------------------------------ */

.pphib-empty {
    color: var(--pphib-ink-3, #8a978f);
    background: var(--pphib-wash, #f4f7f4);
    border: 1px dashed var(--pphib-rule, #e0e6e1);
    border-radius: 10px;
    padding: 22px;
    text-align: center;
    margin: 0 0 1.75rem;
}

.pphib-list a:focus-visible,
.pphib-grid a:focus-visible {
    outline: 2px solid var(--pphib-accent);
    outline-offset: 2px;
    border-radius: 3px;
}

@media (max-width: 480px) {
    .pphib-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 14px;
    }
    .pphib-list .pphib-item {
        padding: 14px 16px;
    }
    .pphib-apply {
        flex: 1 1 100%;
        text-align: center;
    }
}

/* ------------------------------------------------------------------ *
 * Archive pages
 *
 * The plugin renders /advertisements, /syllabi and the rest itself; the theme still supplies the
 * header, navigation and footer around this.
 * ------------------------------------------------------------------ */

.pphib-archive {
    max-width: 1180px;
    margin: 0 auto;
    padding: 48px 22px 72px;
}

.pphib-archive-head {
    margin-bottom: 30px;
}

.pphib-archive-head h1 {
    margin: 0 0 8px;
    line-height: 1.15;
}

.pphib-archive-intro {
    margin: 0;
    max-width: 65ch;
    opacity: .75;
}
