/* =====================================================================
   DOI Portal — Publications List (page-scoped)
   Redesigned table + header filters + side menu
   Design system: doi.rs (green/teal, soft shadows, Raleway, pill shapes)
   Loaded AFTER portal.css — relies on and overrides global tokens.
   ===================================================================== */

/* ---------------------------------------------------------------------
   Local helper tokens (derived from global brand tokens)
   --------------------------------------------------------------------- */
:root {
    --pub-shadow-rest:   0 0 40px 4px rgba(3, 51, 51, 0.04);
    --pub-shadow-hover:  0 18px 42px -14px rgba(3, 51, 51, 0.22);
    --pub-shadow-menu:   0 18px 44px -12px rgba(3, 51, 51, 0.28);
    --pub-focus-ring:    0 0 0 0.2rem rgba(92, 180, 106, 0.2);
    --pub-green-tint-10: rgba(92, 180, 106, 0.10);
    --pub-green-tint-14: rgba(92, 180, 106, 0.14);
    --pub-green-tint-05: rgba(92, 180, 106, 0.05);
    --pub-teal-tint-07:  rgba(3, 51, 51, 0.07);
}

/* =====================================================================
   RESULT COUNT LINE
   ===================================================================== */
.pub-result-count {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}
.pub-result-count strong {
    color: var(--color-dark);
    font-weight: 700;
}

/* =====================================================================
   HEADER FILTER BAR
   ===================================================================== */
.pub-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    padding: 1rem 1.15rem;
    margin-bottom: 1.75rem;
    box-shadow: var(--pub-shadow-rest);
    /* Bug 1: sit above the results column. The global [data-reveal] rule adds
       will-change:transform to both this bar and the results <section>, each
       creating a stacking context; since the results section comes later in the
       DOM it would otherwise paint above the open dropdown menus. */
    position: relative;
    z-index: 30;
}

/* ---- Search field --------------------------------------------------- */
.pub-search {
    flex: 1 1 240px;
    position: relative;
    display: flex;
    align-items: center;
}
.pub-search .bi-search {
    position: absolute;
    left: 0.95rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-secondary);
    font-size: 0.95rem;
    pointer-events: none;
}
.pub-search input,
.pub-search .form-control {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.4rem;
    border: 2px solid var(--color-border);
    border-radius: 50px;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--color-text-primary);
    background: #fff;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.pub-search input::placeholder,
.pub-search .form-control::placeholder {
    color: var(--placeholder-color, #a3b1b1);
    font-style: italic;
    font-weight: 400;
}
.pub-search input:focus,
.pub-search .form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--pub-focus-ring);
}

/* =====================================================================
   FILTER DROPDOWNS (Bootstrap .dropdown)
   ===================================================================== */
.pub-filter {
    position: relative;
    /* never clip the open dropdown menu */
    overflow: visible;
}

.pub-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #fff;
    border: 2px solid var(--color-border);
    border-radius: 50px;
    padding: 0.5rem 1.1rem;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-text-primary);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.pub-filter-toggle::after {
    content: "";
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    margin-left: 0.15rem;
    border-right: 2px solid var(--color-primary);
    border-bottom: 2px solid var(--color-primary);
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.2s ease;
}
.pub-filter-toggle:hover,
.pub-filter-toggle:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--pub-focus-ring);
}
/* Open state — flip caret (Bootstrap toggles aria-expanded / .show) */
.pub-filter-toggle[aria-expanded="true"]::after,
.pub-filter.show .pub-filter-toggle::after {
    transform: rotate(-135deg) translateY(2px);
}

/* Active-selection count badge */
.pub-filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.4rem;
    border-radius: 50px;
    background: var(--brand-gradient);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

/* ---- Filter menu ---------------------------------------------------- */
.pub-filter-menu {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--pub-shadow-menu);
    padding: 0.5rem;
    min-width: 230px;
    max-height: 320px;
    overflow: auto;
    /* Bug 1: keep the open menu (and its clickable checkboxes) above the table */
    z-index: 1080;
}

.pub-filter-option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--color-text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease;
}
.pub-filter-option:hover {
    background: var(--pub-green-tint-10);
}
.pub-filter-option input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
    flex-shrink: 0;
}
.pub-filter-optlabel {
    flex: 1;
    line-height: 1.3;
}
.pub-filter-optcount {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    padding: 0.1rem 0.45rem;
    border-radius: 50px;
    background: var(--color-surface-base);
    color: var(--color-text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.2;
}

/* =====================================================================
   SORT SELECT (pill styled to match filter toggles)
   ===================================================================== */
.pub-sort {
    flex: 0 0 auto;
}
.pub-sort .form-select {
    border: 2px solid var(--color-border);
    border-radius: 50px;
    padding: 0.5rem 2.4rem 0.5rem 1.1rem;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-text-primary);
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.pub-sort .form-select:hover,
.pub-sort .form-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--pub-focus-ring);
}
.pub-sort .form-select option {
    color: var(--color-text-primary);
}

/* ---- Reset link ----------------------------------------------------- */
.pub-filter-reset {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.9rem;
    border-radius: 50px;
    color: var(--color-primary);
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease;
}
.pub-filter-reset:hover,
.pub-filter-reset:focus {
    background: var(--pub-green-tint-10);
    color: var(--color-primary);
    text-decoration: none;
}

/* =====================================================================
   TYPE NAVIGATION — HORIZONTAL TAB BAR
   ===================================================================== */
.pub-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.25rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1.25rem;
    /* hide scrollbar (Firefox / IE) */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.pub-tabs::-webkit-scrollbar {
    display: none; /* hide scrollbar (WebKit) */
}

.pub-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.1rem;
    color: var(--color-text-secondary);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.16s ease, border-color 0.16s ease;
}
.pub-tab i,
.pub-tab .bi {
    color: var(--color-primary);
    font-size: 1.05rem;
    flex-shrink: 0;
}
.pub-tab:hover,
.pub-tab:focus {
    color: var(--color-dark);
    text-decoration: none;
}

/* Active tab — underline indicator (no vertical line, no dark block) */
.pub-tab.active {
    color: var(--color-dark);
    border-bottom-color: var(--color-primary);
}

/* =====================================================================
   TABLE
   ===================================================================== */
.pub-table-wrap {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--pub-shadow-rest);
}

.pub-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    margin: 0;
}

.pub-table thead th {
    background: var(--color-surface-base);
    color: var(--color-text-secondary);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.pub-row {
    border-bottom: 1px solid var(--color-border-subtle);
    transition: background 0.2s ease;
}
.pub-row:hover {
    background: var(--pub-green-tint-05);
}
.pub-table tbody tr:last-child.pub-row,
.pub-table tbody tr:last-child {
    border-bottom: none;
}

.pub-table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    color: var(--color-text-secondary);
}

/* ---- Name cell ------------------------------------------------------ */
.pub-name-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 240px;
}
.pub-row-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.pub-row-icon img {
    object-fit: contain;
    width: 100%;
    height: 100%;
}
.pub-row-icon i,
.pub-row-icon .bi {
    color: var(--color-primary);
    font-size: 1.1rem;
}
.pub-row-name {
    font-weight: 700;
    color: var(--color-dark);
    text-decoration: none;
    line-height: 1.3;
    transition: color 0.16s ease;
}
.pub-row-name:hover,
.pub-row-name:focus {
    color: var(--color-primary);
    text-decoration: none;
}

/* ---- Type tag ------------------------------------------------------- */
.pub-type-tag {
    display: inline-block;
    background: var(--pub-teal-tint-07);
    color: var(--color-dark);
    border-radius: 6px;
    padding: 0.2rem 0.55rem;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ---- Access pill ---------------------------------------------------- */
.access-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 20px;
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}
.access-open {
    background: var(--pub-green-tint-14);
    color: var(--color-primary);
}
.access-restricted {
    background: var(--color-surface-base);
    color: var(--color-text-secondary);
}

/* ---- Publisher link ------------------------------------------------- */
.pub-publisher-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.16s ease;
}
.pub-publisher-link:hover,
.pub-publisher-link:focus {
    color: var(--color-primary-light);
    text-decoration: underline;
}

/* ---- ID cell (ISSN/eISSN, ISBN/ISSN, ISBN) — stacked labelled values -- */
.pub-idcell {
    line-height: 1.35;
    white-space: nowrap;
}
.pub-idrow {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}
.pub-idlabel {
    display: inline-block;
    min-width: 3.1rem;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
}
.pub-idval {
    font-family: "SFMono-Regular", ui-monospace, "Menlo", "Consolas", monospace;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-dark);
}

/* ---- Year cell ------------------------------------------------------- */
.pub-year-cell {
    font-variant-numeric: tabular-nums;
    color: var(--color-text-primary);
    white-space: nowrap;
}

/* ---- Count pill (Broj radova) — green pill look ---------------------- */
.pub-count-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.85rem;
    padding: 0.15rem 0.55rem;
    border-radius: 20px;
    background: var(--pub-green-tint-14);
    color: var(--color-primary);
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

/* ---- Subject / language cells --------------------------------------- */
.pub-subject-cell,
.pub-lang-cell {
    color: var(--color-text-secondary);
}
.pub-subject-cell:empty::after,
.pub-lang-cell:empty::after {
    content: "—";
    color: var(--color-border);
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

/* On narrow screens the tab bar keeps its horizontal-scroll behaviour
   (defined on .pub-tabs above) so tabs never wrap or dominate the screen. */

/* Under 768px: compact filter bar, side-scrolling table */
@media (max-width: 767.98px) {
    .pub-filter-bar {
        gap: 0.5rem;
        padding: 0.75rem;
    }
    /* Search takes its own full-width row */
    .pub-search {
        flex: 1 1 100%;
    }
    /* Four dropdown toggles + sort wrap two-per-row instead of stacking */
    .pub-filter {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
    }
    .pub-filter-toggle,
    .pub-sort .form-select {
        width: 100%;
        justify-content: space-between;
        padding: 0.45rem 0.8rem;
        font-size: 0.85rem;
    }
    .pub-filter-reset {
        flex: 1 1 100%;
        justify-content: center;
    }
    /* Anchor the menu to its toggle instead of forcing full page width */
    .pub-filter-menu {
        min-width: 220px;
        max-width: 90vw;
    }

    /* Keep table horizontally scrollable inside its card */
    .pub-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .pub-table {
        min-width: 720px;
    }
    .pub-table thead th,
    .pub-table td {
        padding: 0.6rem 0.7rem;
    }
    /* Keep the Naziv column readable while other columns scroll */
    .pub-name-cell {
        min-width: 200px;
    }
}

/* =====================================================================
   MOBILE FILTER COLLAPSE (search stays visible; filters behind a toggle)
   ===================================================================== */
/* Toggle button is hidden everywhere except on narrow screens */
.pub-filter-toggle-mobile {
    display: none;
}

/* DESKTOP & TABLET (>= 641px): the collapse wrapper is always open and inline,
   so the filter bar looks and behaves exactly as before. */
@media (min-width: 641px) {
    .pub-filter-collapse {
        display: flex !important;
        height: auto !important;
        visibility: visible !important;
        overflow: visible;
        gap: 0.75rem;
        align-items: center;
        flex-wrap: wrap;
    }
    .pub-filter-toggle-mobile {
        display: none !important;
    }
}

/* MOBILE (<= 640px): show the toggle, let Bootstrap collapse the filters. */
@media (max-width: 640px) {
    .pub-filter-toggle-mobile {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.45rem;
        flex: 1 1 100%;
        width: 100%;
        background: #fff;
        border: 2px solid var(--color-border);
        border-radius: 50px;
        padding: 0.5rem 1.1rem;
        font-family: inherit;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--color-text-primary);
        cursor: pointer;
        transition: border-color 0.18s ease, box-shadow 0.18s ease;
    }
    .pub-filter-toggle-mobile:hover,
    .pub-filter-toggle-mobile:focus,
    .pub-filter-toggle-mobile[aria-expanded="true"] {
        outline: none;
        border-color: var(--color-primary);
        box-shadow: var(--pub-focus-ring);
    }
    .pub-filter-toggle-mobile .bi {
        color: var(--color-primary);
    }

    /* The collapse spans full width and stacks its filters; never clip menus. */
    .pub-filter-collapse {
        flex: 1 1 100%;
        width: 100%;
        overflow: visible;
    }
    .pub-filter-collapse.show,
    .pub-filter-collapse.collapsing {
        margin-top: 0.5rem;
    }
    .pub-filter-collapse .pub-filter,
    .pub-filter-collapse .pub-sort {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    .pub-filter-collapse .pub-filter:last-child,
    .pub-filter-collapse .pub-sort:last-child {
        margin-bottom: 0;
    }
    .pub-filter-collapse .pub-filter-toggle,
    .pub-filter-collapse .pub-sort .form-select {
        width: 100%;
        justify-content: space-between;
    }
    .pub-filter-collapse .pub-filter-reset {
        width: 100%;
        justify-content: center;
        margin-top: 0.25rem;
    }
    /* Dropdown menu drops full-width under its toggle instead of overflowing. */
    .pub-filter-collapse .pub-filter-menu {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }
}

/* =====================================================================
   MOBILE (<= 640px): TABLE → STACKED CARDS (label-per-cell)
   ===================================================================== */
@media (max-width: 640px) {
    .pub-table-wrap { overflow: visible; border: none; background: transparent; box-shadow: none; border-radius: 0; }
    .pub-table { min-width: 0; width: 100%; }
    .pub-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .pub-table tbody, .pub-table tr, .pub-table td { display: block; width: 100%; }
    .pub-table tr.pub-row { background: #fff; border: 1px solid var(--color-border); border-radius: 12px; margin-bottom: 0.85rem; padding: 0.85rem 1rem; box-shadow: 0 0 30px 3px rgba(3,51,51,0.04); }
    /* keep the last card's full border + bottom padding (base removes them) */
    .pub-table tbody tr:last-child.pub-row { border-bottom: 1px solid var(--color-border); margin-bottom: 0; }
    .pub-table td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.4rem 0; border: none; text-align: right; }
    .pub-table td::before { content: attr(data-label); font-weight: 700; font-size: 0.78rem; color: var(--color-text-secondary); text-align: left; flex-shrink: 0; }
    /* Naziv becomes the card header: icon + name, no label */
    .pub-table td.pub-name-cell { justify-content: flex-start; min-width: 0; border-bottom: 1px solid var(--color-border-subtle); padding-bottom: 0.7rem; margin-bottom: 0.4rem; text-align: left; }
    .pub-table td.pub-name-cell::before { display: none; }
    .pub-table td:last-child { padding-bottom: 0; }
    /* the empty-state row must span normally */
    .pub-table td[colspan] { display: block; text-align: center; }
    .pub-table td[colspan]::before { display: none; }
}
