/* ─── PDF Document Library – Public Styles ──────────────────── */
:root {
    --pdl-primary:   #04189A;
    --pdl-primary-h: #030F6B;
    --pdl-accent:    #CE3030;
    --pdl-accent-h:  #A82626;
    --pdl-bg:        #f4f6f9;
    --pdl-white:     #ffffff;
    --pdl-border:    #d5d8dc;
    --pdl-text:      #23272e;
    --pdl-muted:     #6b7280;
    --pdl-row-even:  #f7f8fb;
    --pdl-row-hover: #eef1fb;
    --pdl-link:      #04189A;
    --pdl-shadow:    0 2px 12px rgba(0,0,0,.08);
    --pdl-radius:    6px;
}

.pdl-wrap { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: var(--pdl-text); max-width: 1200px; margin: 0 auto; }

/* Header */
.pdl-header { text-align: center; margin-bottom: 28px; }
.pdl-title  { font-size: clamp(1.6rem, 4vw, 2.4rem); color: var(--pdl-accent); margin: 0 0 6px; font-weight: 700; }
.pdl-subtitle { color: var(--pdl-muted); font-style: italic; margin: 0; }

/* Visually hidden but available to screen readers */
.pdl-sr-only {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ─── Category tabs ─────────────────────────────────────────────
   A wrapping row of 6 tabs collapses into ragged multi-line blocks on
   narrow screens. A single scroll-snapped row keeps the control one
   predictable height at every width. */
.pdl-cat-tabs {
    display: flex; gap: 4px; margin-bottom: 20px;
    border-bottom: 2px solid var(--pdl-border);
    overflow-x: auto; overflow-y: hidden;
    scrollbar-width: thin; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
}
.pdl-cat-tabs::-webkit-scrollbar { height: 3px; }
.pdl-cat-tabs::-webkit-scrollbar-thumb { background: var(--pdl-border); border-radius: 3px; }
.pdl-cat-tab {
    background: none; border: none; padding: 10px 18px; cursor: pointer;
    font-size: .9rem; font-weight: 600;
    /* Explicit colour: the host theme sets button text to white, which would
       render these invisible against the light tab strip. */
    color: var(--pdl-link) !important;
    border-bottom: 3px solid transparent; margin-bottom: -2px;
    transition: color .18s, background .18s, border-color .18s;
    border-radius: var(--pdl-radius) var(--pdl-radius) 0 0;
    white-space: nowrap; flex: 0 0 auto; scroll-snap-align: center;
    line-height: 1.35;
}
.pdl-cat-tab:hover { background: var(--pdl-row-hover); color: var(--pdl-primary) !important; }
.pdl-cat-tab:focus-visible { outline: 2px solid var(--pdl-primary); outline-offset: -2px; }
.pdl-cat-tab.active {
    color: var(--pdl-primary) !important;
    border-bottom-color: var(--pdl-primary);
    background: var(--pdl-row-hover);
}

/* ─── Toolbar ───────────────────────────────────────────────────
   Grid rather than a flex free-for-all: search owns the flexible track,
   the filter cluster sits in an auto track, and at narrow widths the two
   simply stack. */
.pdl-toolbar {
    display: grid; grid-template-columns: minmax(240px, 1fr) auto;
    gap: 10px 14px; margin-bottom: 14px; align-items: end;
}

.pdl-search-wrap { position: relative; min-width: 0; }
.pdl-search-icon {
    position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
    width: 17px; height: 17px; color: var(--pdl-muted); pointer-events: none; z-index: 2;
}
.pdl-search-input {
    width: 100%; padding: 11px 38px 11px 42px !important;
    border: 1px solid var(--pdl-border); border-radius: var(--pdl-radius);
    font-size: .9rem; box-sizing: border-box; line-height: 1.3;
    background: var(--pdl-white); color: var(--pdl-text) !important;
    transition: border-color .2s, box-shadow .2s;
    -webkit-appearance: none; appearance: none;
}
.pdl-search-input::placeholder { color: var(--pdl-muted); opacity: 1; }
.pdl-search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.pdl-search-input:focus {
    outline: none; border-color: var(--pdl-primary);
    box-shadow: 0 0 0 3px rgba(4,24,154,.12);
}
.pdl-search-clear {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--pdl-muted) !important; font-size: 20px; line-height: 1;
    width: 30px; height: 30px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
}
.pdl-search-clear.is-visible { display: flex; }
.pdl-search-clear:hover { background: var(--pdl-row-hover); color: var(--pdl-text) !important; }

/* Filter cluster */
.pdl-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.pdl-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pdl-field-label {
    font-size: .7rem; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase; color: var(--pdl-muted);
    line-height: 1; padding-left: 2px;
}
.pdl-sort-pair { display: flex; gap: 6px; align-items: stretch; }

.pdl-select {
    padding: 9px 10px; border: 1px solid var(--pdl-border);
    border-radius: var(--pdl-radius); font-size: .85rem;
    background: var(--pdl-white); color: var(--pdl-text) !important;
    line-height: 1.3; box-sizing: border-box; max-width: 100%;
    -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 8px center; background-size: 15px;
    padding-right: 28px;
}
/* Date inputs get no chevron — they carry the browser's own picker icon. */
input.pdl-select { background-image: none; padding-right: 10px; }
.pdl-select:focus {
    outline: none; border-color: var(--pdl-primary);
    box-shadow: 0 0 0 3px rgba(4,24,154,.12);
}

.pdl-btn-ghost {
    padding: 9px 12px; border: 1px solid var(--pdl-border);
    border-radius: var(--pdl-radius); background: var(--pdl-white);
    color: var(--pdl-text) !important; cursor: pointer; font-size: .85rem;
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    transition: background .2s, border-color .2s; white-space: nowrap; line-height: 1.3;
}
.pdl-btn-ghost:hover { background: var(--pdl-row-hover); border-color: var(--pdl-primary); }
.pdl-btn-ghost:focus-visible { outline: 2px solid var(--pdl-primary); outline-offset: 1px; }
.pdl-btn-ghost svg { flex: 0 0 auto; }

.pdl-btn-clear {
    align-self: end; padding: 9px 12px; border: 1px solid transparent;
    border-radius: var(--pdl-radius); background: none;
    color: var(--pdl-accent) !important; cursor: pointer;
    font-size: .82rem; font-weight: 600; white-space: nowrap; line-height: 1.3;
}
.pdl-btn-clear:hover { background: rgba(206,48,48,.08); border-color: rgba(206,48,48,.25); }
.pdl-btn-clear[hidden] { display: none; }

/* Info bar */
.pdl-info-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.pdl-results-info { font-size: .85rem; color: var(--pdl-muted); }

/* Table */
.pdl-table-wrap { overflow-x: auto; border-radius: var(--pdl-radius); box-shadow: var(--pdl-shadow); }
.pdl-table { width: 100%; border-collapse: collapse; background: var(--pdl-white); font-size: .875rem; }
.pdl-table thead tr { background: var(--pdl-primary); }
.pdl-table thead th { color: #fff; padding: 12px 14px; text-align: left; font-weight: 600; white-space: nowrap; }
.pdl-table tbody tr:nth-child(even) { background: var(--pdl-row-even); }
.pdl-table tbody tr:hover { background: var(--pdl-row-hover); }
.pdl-table td { padding: 10px 14px; vertical-align: middle; border-bottom: 1px solid var(--pdl-border); }
.pdl-table tr:last-child td { border-bottom: none; }

/* Column widths */
.pdl-th-doc  { width: 130px; }
.pdl-th-desc { }
.pdl-th-cat  { width: 140px; }
.pdl-th-date { width: 100px; }
.pdl-th-size { width: 80px; }
.pdl-th-actions { width: 120px; }

/* Cells */
.pdl-doc-num  { font-weight: 700; color: var(--pdl-link); font-family: 'Courier New', monospace; font-size: .82rem; }
.pdl-doc-title { font-weight: 600; color: var(--pdl-text); }
.pdl-doc-desc  { color: var(--pdl-muted); font-size: .82rem; margin-top: 2px; }
.pdl-cat-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; background: var(--pdl-primary); color: #fff; font-size: .75rem; font-weight: 600; }
.pdl-date-cell { color: var(--pdl-muted); font-size: .82rem; white-space: nowrap; }
.pdl-size-cell { color: var(--pdl-muted); font-size: .78rem; white-space: nowrap; }

/* Action buttons */
.pdl-action-btns { display: flex; gap: 6px; }
.pdl-btn-view, .pdl-btn-dl {
    padding: 5px 10px; border-radius: 4px; font-size: .78rem; font-weight: 600;
    cursor: pointer; border: 1px solid transparent; text-decoration: none; display: inline-flex; align-items: center; gap: 3px;
    transition: all .15s;
}
.pdl-btn-view { background: var(--pdl-primary); color: #fff !important; border-color: var(--pdl-primary); }
.pdl-btn-view:hover { background: var(--pdl-primary-h); color: #fff !important; }
.pdl-btn-dl   { background: var(--pdl-white); color: var(--pdl-primary) !important; border-color: var(--pdl-primary); }
.pdl-btn-dl:hover { background: var(--pdl-row-hover); }

/* Loading / empty states */
.pdl-loading { text-align: center; padding: 40px; color: var(--pdl-muted); }
.pdl-empty   { text-align: center; padding: 40px; color: var(--pdl-muted); }
.pdl-spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--pdl-border); border-top-color: var(--pdl-primary); border-radius: 50%; animation: pdl-spin .7s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes pdl-spin { to { transform: rotate(360deg); } }

/* Pagination */
.pdl-pagination-bottom { margin-top: 16px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: center; }
.pdl-pagination-top    { display: flex; gap: 4px; flex-wrap: wrap; }
.pdl-page-btn {
    padding: 6px 12px; border: 1px solid var(--pdl-border); background: var(--pdl-white);
    color: var(--pdl-primary) !important; border-radius: var(--pdl-radius); cursor: pointer;
    font-size: .82rem; line-height: 1.2; transition: all .15s;
}
.pdl-page-btn:hover        { background: var(--pdl-row-hover); border-color: var(--pdl-primary); color: var(--pdl-primary) !important; }
.pdl-page-btn.active       { background: var(--pdl-primary); color: #fff !important; border-color: var(--pdl-primary); }
.pdl-page-btn:disabled     { opacity: .4; cursor: default; }
.pdl-page-ellipsis         { padding: 6px 4px; font-size: .82rem; color: var(--pdl-muted); }
.pdl-per-page-select       { padding: 6px 10px; border: 1px solid var(--pdl-border); border-radius: var(--pdl-radius); font-size: .82rem; background: var(--pdl-white); color: var(--pdl-text); }

/* Modal */
.pdl-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 99999; align-items: center; justify-content: center; }
.pdl-modal.open { display: flex; }
.pdl-modal-inner { background: var(--pdl-white); border-radius: 8px; width: 90vw; max-width: 1000px; height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.pdl-modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--pdl-border); gap: 12px; }
.pdl-modal-title  { font-weight: 700; font-size: 1rem; color: var(--pdl-text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdl-modal-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pdl-modal-btn { padding: 6px 12px; border-radius: 4px; font-size: .8rem; font-weight: 600; text-decoration: none; border: 1px solid var(--pdl-primary); color: var(--pdl-primary); background: var(--pdl-white); white-space: nowrap; transition: all .15s; }
.pdl-modal-btn:hover { background: var(--pdl-row-hover); }
.pdl-modal-close  { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--pdl-muted); line-height: 1; padding: 0 4px; }
.pdl-modal-close:hover { color: var(--pdl-accent); }
.pdl-modal-body   { flex: 1; overflow: hidden; position: relative; }
.pdl-modal-body iframe { width: 100%; height: 100%; border: none; position: relative; z-index: 2; background: #fff; }
.pdl-modal-fallback { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 30px; color: var(--pdl-muted); }
.pdl-modal-fallback p { margin: 0; max-width: 420px; }

/* ─── Responsive ────────────────────────────────────────────────
   Three deliberate steps: wide (search + filters share a row), tablet
   (search takes the full width, filters flow beneath), phone (everything
   stacks, controls reach the 44px touch target). */

/* Tablet and below: search gets its own row. */
@media (max-width: 1024px) {
    .pdl-toolbar { grid-template-columns: 1fr; align-items: stretch; }
    .pdl-filters { justify-content: flex-start; }
    .pdl-field-date { flex: 1 1 150px; }
    .pdl-field-sort { flex: 1 1 220px; }
    .pdl-field-date .pdl-select, .pdl-field-sort .pdl-select { width: 100%; }
    .pdl-sort-pair .pdl-select { flex: 1 1 auto; min-width: 0; }
}

@media (max-width: 768px) {
    .pdl-th-cat, .pdl-th-size { display: none; }
    .pdl-table td:nth-child(3), .pdl-table td:nth-child(5) { display: none; }
    .pdl-cat-tabs { margin-bottom: 16px; gap: 2px; }
    .pdl-cat-tab  { padding: 11px 15px; font-size: .86rem; }
    .pdl-btn-clear { width: 100%; margin-top: 2px; }
    .pdl-modal-inner { width: 98vw; height: 95vh; }
}

/* Phones: full-width stacked controls, 44px minimum touch targets, and a
   16px font on inputs so iOS Safari does not zoom the page on focus. */
@media (max-width: 560px) {
    .pdl-filters { flex-direction: column; align-items: stretch; gap: 12px; }
    .pdl-field, .pdl-field-date, .pdl-field-sort { width: 100%; flex: 1 1 auto; }
    .pdl-select, .pdl-btn-ghost, .pdl-btn-clear { width: 100%; min-height: 44px; }
    /* 16px is the threshold below which iOS Safari zooms the page on focus.
       !important because the host theme targets input[type="search"] directly,
       which outranks a single class selector. */
    .pdl-search-input { min-height: 44px; font-size: 16px !important; }
    .pdl-select { font-size: 16px !important; }
    .pdl-sort-pair { gap: 8px; }
    .pdl-sort-pair .pdl-select { flex: 1 1 60%; }
    .pdl-btn-ghost { flex: 0 0 auto; width: auto; min-width: 96px; }
    .pdl-search-clear { width: 34px; height: 34px; }
    .pdl-cat-tab { padding: 12px 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .pdl-cat-tab, .pdl-select, .pdl-btn-ghost, .pdl-search-input { transition: none; }
}
