/*
 * jaraidFilterSort.css
 * Styling for the filter/sort toolbar injected by jaraidFilterSort.js
 * above the chronology table (#t1). Kept self-contained so it can be
 * dropped into chrono.html and fihris.html without touching the
 * existing teiChrono.css / teiFihris.css rules.
 */

#jaraidToolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 10px 14px;
    margin: 20px 0 10px 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    font-family: Georgia, serif;
    font-size: 14px;
}

#jaraidToolbar .jaraid-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
    margin-bottom: 8px;
}

#jaraidToolbar .jaraid-row:last-child {
    margin-bottom: 0;
}

#jaraidToolbar .jaraid-field {
    display: flex;
    flex-direction: column;
    min-width: 120px;
}

#jaraidToolbar .jaraid-decades-row {
      align-items: center;
      padding-bottom: 8px;
      margin-bottom: 8px;
      border-bottom: 1px solid #e5e5e5;
}

#jaraidToolbar .jaraid-decades-label {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      color: #555;
      flex: 0 0 auto;
}

#jaraidToolbar .jaraid-decades {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      flex: 1 1 auto;
}

#jaraidToolbar .jaraid-decade-link {
      display: inline-block;
      padding: 3px 9px;
      border: 1px solid #ccc;
      border-radius: 12px;
      background: #f7f7f7;
      color: #333;
      font-size: 12px;
      text-decoration: none;
      line-height: 1.6;
}

#jaraidToolbar .jaraid-decade-link:hover {
      background: #333;
      color: #fff;
      border-color: #333;
}

#jaraidToolbar .jaraid-field-search {
    flex: 1 1 260px;
}

#jaraidToolbar label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #555;
    margin-bottom: 3px;
}

#jaraidToolbar input[type="text"],
#jaraidToolbar input[type="number"],
#jaraidToolbar select {
    font-family: inherit;
    font-size: 14px;
    padding: 5px 8px;
    border: 1px solid #bbb;
    border-radius: 4px;
    background: #fff;
}

#jaraidToolbar input[type="number"] {
    width: 90px;
}

#jaraidToolbar .jaraid-field-lang {
    min-width: 160px;
}

#jaraidToolbar details {
    border: 1px solid #bbb;
    border-radius: 4px;
    padding: 4px 8px;
    background: #fff;
}

#jaraidToolbar summary {
    cursor: pointer;
    font-size: 14px;
    padding: 2px 0;
}

#jaraidToolbar .jaraid-lang-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(110px, 1fr));
    gap: 2px 10px;
    padding-top: 6px;
    max-height: 160px;
    overflow-y: auto;
}

#jaraidToolbar .jaraid-lang-list label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    text-transform: none;
    letter-spacing: normal;
    color: #222;
    font-weight: normal;
    margin: 0;
}

#jaraidToolbar .jaraid-field-reset {
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
}

#jaraidToolbar .jaraid-btn {
        padding: 6px 12px;
        border: 1px solid #888;
        border-radius: 4px;
        background: #f2f2f2;
        cursor: pointer;
        font-size: 13px;
        white-space: nowrap;
}

#jaraidToolbar .jaraid-btn:hover {
        background: #e2e2e2;
}

/* Small "view details" button at the start of each row's Year cell --
   opens the modal for that entry. The row itself is also clickable (see
   jaraidFilterSort.js), but this button gives keyboard/screen-reader
   users an explicit, focusable target. */
.jaraid-row-view-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        margin-right: 6px;
        border: 1px solid #999;
        border-radius: 3px;
        background: #fafafa;
        color: #333;
        font-size: 13px;
        line-height: 1;
        cursor: pointer;
        vertical-align: middle;
}

.jaraid-row-view-btn:hover {
        background: #e8e8e8;
}

.jaraid-row-view-btn:focus {
        outline: 2px solid #6ab0f3;
        outline-offset: 1px;
}

tr[role="data"] {
        cursor: pointer;
}

#jaraidToolbar .jaraid-status {
    font-size: 12px;
    color: #444;
    justify-content: space-between;
    gap: 8px;
}

#jaraidToolbar .jaraid-hint {
    color: #888;
    font-style: italic;
}

/* Sortable column headers */
tr[role="label"] td.jaraid-sortable {
    cursor: pointer;
    position: sticky;
    top: 0;
    background: #efefef;
    z-index: 10;
    user-select: none;
}

tr[role="label"] td.jaraid-sortable:hover {
    background: #e0e0e0;
}

tr[role="label"] td.jaraid-sortable::after {
    content: "sort";
    opacity: 0.35;
    font-size: 11px;
    margin-left: 5px;
}

tr[role="label"] td.jaraid-sort-asc::after {
    content: "asc";
    opacity: 1;
}

tr[role="label"] td.jaraid-sort-desc::after {
    content: "desc";
    opacity: 1;
}

/* Table itself scrolls sideways in its own box; the toolbar above stays
   full width so filters are always reachable without side-scrolling. */
.jaraid-table-scroll {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
}

/* ---- Full data table, laid out for comfortable reading ----
 * Every column that this page's base stylesheet (teiChrono.css /
 * teiFihris.css) already renders for its language is shown directly in
 * the row -- so links to online holdings, comments, source notes, etc.
 * are all one glance away instead of hidden behind a click. Each row
 * (and the header above it) lays out on a shared CSS Grid template so
 * values line up into true vertical columns like a real table, rather
 * than a flexbox line whose items size to their own content and never
 * align from row to row.
 *
 * The two languages don't expose the same columns (teiFihris.css hides
 * the English fields 4/5/6/7 (Title/Place/Owners/Comments), keeping
 * Comments off the Arabic page entirely; teiChrono.css hides the
 * Arabic-only fields 10/11/12) and their natural DOM order puts
 * Source/Holdings ahead of the Arabic title/editor/place cells --
 * visually backwards compared to the English row's Title-first
 * reading order. The "order" rules below reshuffle the Arabic page's
 * columns into the same conceptual sequence as the English page
 * (chronology, then title/place/editor, then source/holdings) without
 * touching the underlying markup, which stays in its original TEI
 * column order for the modal and for screen readers.
 *
 * Clicking a row (or its small view-details button) still opens the
 * full-entry popup -- handy for a large-type, single-record view or
 * for copying a citation -- it's just no longer the only way to see a
 * field.
 */
tr[role="label"],
tr[role="data"] {
        display: grid;
        align-items: start;
        column-gap: 18px;
        row-gap: 3px;
}

tr[role="label"] {
        padding: 10px 12px !important;
        background: #efefef;
        border-bottom: 2px solid #999;
}

tr[role="data"] {
        padding: 9px 12px;
        border-bottom: 1px solid #ddd;
        font-size: 13px;
        line-height: 1.5;
}

/* A light divider on the trailing edge of every visible cell reads as
   column separation without needing to single out "the last column" --
   DOM order (used by :last-of-type) doesn't match the visual order
   after the Arabic reorder below, and hidden n=10-12 (English) /
   n=4-7 (Arabic) cells never paint a border anyway since they're
   display:none, so this never produces a stray line past the real
   edge of the row. */
tr[role="label"] td,
tr[role="data"] td {
        min-width: 0;
        border: none !important;
        border-inline-end: 1px solid #e4e4e4 !important;
        padding: 0 12px 0 0 !important;
        overflow-wrap: break-word;
}

/* English page (pages/chrono.html): teiChrono.css already hides n=10-12,
   so the 9 remaining columns are in the desired reading order as-is. */
body#chrono tr[role="label"],
body#chrono tr[role="data"] {
        grid-template-columns:
                64px 84px 84px
                minmax(200px, 2.1fr) minmax(100px, 1fr) minmax(140px, 1.3fr)
                minmax(170px, 1.6fr) minmax(100px, 1fr) minmax(120px, 1.1fr);
}

/* Arabic page (pages/fihris.html): teiFihris.css hides n=4-7, leaving
   Source (8) and Holdings (9) ahead of the Arabic title/editor/place
   cells (10/11/12) in raw DOM order -- reorder them here so the row
   still reads chronology, then title/place/editor, then source/holdings. */
body#fihris tr[role="label"],
body#fihris tr[role="data"] {
        grid-template-columns:
                64px 84px 84px
                minmax(200px, 2.1fr) minmax(100px, 1fr) minmax(140px, 1.3fr)
                minmax(100px, 1fr) minmax(120px, 1.1fr);
}

body#fihris td[n="10"] { order: 4; } /* Arabic title */
body#fihris td[n="12"] { order: 5; } /* Arabic place */
body#fihris td[n="11"] { order: 6; } /* Arabic editor/publisher */
body#fihris td[n="8"]  { order: 7; } /* Source */
body#fihris td[n="9"]  { order: 8; } /* Holdings */

/* The trailing " ID:t1r123" fragment jaraidFilterSort.js wraps in a
   span (see tagIdSuffix()) -- hidden from the row itself so a title
   doesn't force a second line for what's really reference metadata,
   but this selector only matches inside an actual table row, so the
   same span still shows normally inside the modal. */
tr[role="label"] .jaraid-id-tag,
tr[role="data"] .jaraid-id-tag {
        display: none;
}

/* ---- Row detail modal ---- */
.jaraid-modal-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 20px;
        z-index: 1000;
}

.jaraid-modal-overlay[hidden] {
        display: none;
}

.jaraid-modal {
        position: relative;
        background: #ffffff;
        border-radius: 8px;
        width: 100%;
        max-width: 640px;
        max-height: 85vh;
        overflow-y: auto;
        padding: 28px 30px 24px 30px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
        font-family: Georgia, serif;
}

.jaraid-modal-close {
        position: absolute;
        top: 10px;
        inset-inline-end: 12px;
        width: 30px;
        height: 30px;
        border: none;
        border-radius: 4px;
        background: transparent;
        color: #555;
        font-size: 22px;
        line-height: 1;
        cursor: pointer;
}

.jaraid-modal-close:hover {
        background: #eee;
}

.jaraid-modal-close:focus {
        outline: 2px solid #6ab0f3;
        outline-offset: 1px;
}

.jaraid-modal-title {
        margin: 0 30px 16px 0;
        font-size: 20px;
        line-height: 1.4;
}

.jaraid-modal-field {
        margin-bottom: 14px;
        line-height: 1.5;
        font-size: 14px;
}

.jaraid-modal-field:last-child {
        margin-bottom: 0;
}

.jaraid-modal-value {
        margin-top: 2px;
}

.jaraid-field-label {
        display: block;
        font-weight: 600;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: #777;
}


@media (max-width: 700px) {
    #jaraidToolbar .jaraid-row {
          flex-direction: column;
          align-items: stretch;
    }
    #jaraidToolbar .jaraid-field-reset {
          justify-content: flex-start;
    }
        #jaraidToolbar .jaraid-field-search,
        #jaraidToolbar .jaraid-field-lang,
        #jaraidToolbar .jaraid-field {
                    min-width: 0;
                    width: 100%;
        }
        #jaraidToolbar input[type="text"],
        #jaraidToolbar input[type="number"],
        #jaraidToolbar select {
                    width: 100%;
                    box-sizing: border-box;
        }
        #jaraidToolbar {
                    padding: 8px 10px;
                    font-size: 13px;
        }
        #jaraidToolbar .jaraid-btn {
                    padding: 8px 12px;
                    font-size: 14px;
        }
        body#chrono,
        body#fihris {
                    margin-left: 10px;
                    margin-right: 10px;
        }
        #t1 table {
                    font-size: 11px;
        }
        .jaraid-row-view-btn {
                    width: 24px;
                    height: 24px;
                    font-size: 15px;
        }
        .jaraid-modal {
                    padding: 22px 20px 18px 20px;
        }
        tr[role="label"],
        tr[role="data"] {
                    column-gap: 8px;
                    padding: 8px !important;
                    font-size: 12px;
        }
        body#chrono tr[role="label"],
        body#chrono tr[role="data"] {
                    grid-template-columns:
                                44px 60px 60px
                                minmax(120px, 2.1fr) minmax(70px, 1fr) minmax(90px, 1.3fr)
                                minmax(100px, 1.6fr) minmax(70px, 1fr) minmax(80px, 1.1fr);
        }
        body#fihris tr[role="label"],
        body#fihris tr[role="data"] {
                    grid-template-columns:
                                44px 60px 60px
                                minmax(120px, 2.1fr) minmax(70px, 1fr) minmax(90px, 1.3fr)
                                minmax(70px, 1fr) minmax(80px, 1.1fr);
        }
}
