/**
 * Glossary Module - Front Office CSS
 * Version: 1.0.0
 */

/* CSS Variables from Configuration */
:root {
    --glossary-primary: #2c3e50;
    --glossary-secondary: #3498db;
    --glossary-font-size: 16px;
    --glossary-border-radius: 8px;
    --glossary-shadow: 0 2px 8px rgba(0,0,0,0.1);
    --glossary-hover-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

/* Main Container */
.glossary-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-size: var(--glossary-font-size);
}

/* Page Title */
.glossary-page-title {
    color: var(--glossary-primary);
    font-size: 2.5rem;
    margin-bottom: 30px;
    text-align: center;
    font-weight: 700;
}

/* Search Box */
.glossary-search-box {
    margin-bottom: 30px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.glossary-search-form .input-group {
    box-shadow: var(--glossary-shadow);
    border-radius: var(--glossary-border-radius);
    overflow: hidden;
}

.glossary-search-input {
    border: none;
    padding: 15px 20px;
    font-size: 1rem;
}

.glossary-search-btn {
    background-color: var(--glossary-secondary);
    border: none;
    padding: 15px 30px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.glossary-search-btn:hover {
    background-color: var(--glossary-primary);
}

/* Alphabet Filter */
.glossary-alphabet {
    margin-bottom: 40px;
    background: #f8f9fa;
    padding: 20px;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
}

.alphabet-letters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.letter-link {
    display: inline-block;
    padding: 10px 15px;
    background: white;
    color: var(--glossary-primary);
    text-decoration: none;
    border-radius: 5px;
    font-weight: 600;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.letter-link:hover:not(.disabled) {
    background: var(--glossary-secondary);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--glossary-shadow);
}

.letter-link.active {
    background: var(--glossary-primary);
    color: white;
    border-color: var(--glossary-primary);
}

.letter-link.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Terms Display - Card Mode */
.glossary-display-card .glossary-term-card-wrapper {
    margin-bottom: 30px;
}

.glossary-term-card {
    background: white;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glossary-term-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--glossary-hover-shadow);
}

.glossary-term-card .term-image {
    width: 100%;
    height: 200px;
    overflow: hidden;
    background: #f8f9fa;
}

.glossary-term-card .term-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.glossary-term-card .term-content {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.glossary-term-card .term-name {
    font-size: 1.3rem;
    margin-bottom: 15px;
    color: var(--glossary-primary);
    font-weight: 700;
}

.glossary-term-card .term-name a {
    color: var(--glossary-primary);
    text-decoration: none;
    transition: color 0.3s ease;
}

.glossary-term-card .term-name a:hover {
    color: var(--glossary-secondary);
}

.glossary-term-card .term-excerpt {
    color: #666;
    margin-bottom: 15px;
    flex-grow: 1;
    line-height: 1.6;
}

.glossary-term-card .term-read-more {
    background-color: var(--glossary-secondary);
    color: white;
    border: none;
    align-self: flex-start;
    transition: background-color 0.3s ease;
}

.glossary-term-card .term-read-more:hover {
    background-color: var(--glossary-primary);
}

/* Terms Display - List Mode */
.glossary-terms-list .glossary-term-list-item {
    background: white;
    margin-bottom: 20px;
    padding: 25px;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    transition: box-shadow 0.3s ease;
}

.glossary-terms-list .glossary-term-list-item:hover {
    box-shadow: var(--glossary-hover-shadow);
}

.glossary-terms-list .term-image {
    width: 100%;
    height: 150px;
    overflow: hidden;
    border-radius: 5px;
}

.glossary-terms-list .term-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.glossary-terms-list .term-name {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: var(--glossary-primary);
    font-weight: 700;
}

.glossary-terms-list .term-name a {
    color: var(--glossary-primary);
    text-decoration: none;
}

.glossary-terms-list .term-name a:hover {
    color: var(--glossary-secondary);
}

.glossary-terms-list .term-description {
    color: #666;
    margin-bottom: 10px;
    line-height: 1.6;
}

.glossary-terms-list .term-link {
    color: var(--glossary-secondary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.glossary-terms-list .term-link:hover {
    color: var(--glossary-primary);
}

/* Terms Display - Accordion Mode */
.glossary-accordion {
    margin-top: 20px;
}

.glossary-accordion .accordion-item {
    background: white;
    margin-bottom: 10px;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    overflow: hidden;
}

.glossary-accordion .accordion-header {
    margin: 0;
}

.glossary-accordion .accordion-button {
    background: white;
    color: var(--glossary-primary);
    padding: 20px;
    font-size: 1.2rem;
    font-weight: 600;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.glossary-accordion .accordion-button:hover {
    background-color: #f8f9fa;
}

.glossary-accordion .accordion-button:not(.collapsed) {
    background-color: var(--glossary-secondary);
    color: white;
}

.glossary-accordion .accordion-body {
    padding: 20px;
    border-top: 1px solid #e9ecef;
}

.glossary-accordion .term-image {
    max-width: 300px;
}

.glossary-accordion .term-image img {
    width: 100%;
    border-radius: 5px;
}

/* Term Detail Page */
.glossary-term-detail {
    /* max-width: 900px; */
    margin: 0 auto;
    padding: 20px;
}

.glossary-term-title {
    color: var(--glossary-primary);
    font-size: 2.5rem;
    margin-bottom: 20px;
    font-weight: 700;
}

.glossary-breadcrumb {
    margin-bottom: 30px;
}

.back-to-list {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--glossary-secondary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.back-to-list:hover {
    color: var(--glossary-primary);
}

.term-content-wrapper {
    background: white;
    padding: 40px;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
}

.term-image-container {
    margin-bottom: 30px;
    text-align: center;
}

.term-main-image {
    max-width: 100%;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
}

.term-description-full {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #333;
    margin-bottom: 30px;
}

.term-description-full p {
    margin-bottom: 15px;
}

.term-meta-info {
    padding: 20px 0;
    border-top: 1px solid #e9ecef;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 30px;
}

.term-related-links {
    margin-bottom: 30px;
}

.term-related-links h3 {
    color: var(--glossary-primary);
    font-size: 1.5rem;
    margin-bottom: 15px;
}

.related-links-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.related-link-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.related-link-item:hover {
    background-color: #e9ecef;
}

.related-link-item i {
    color: var(--glossary-secondary);
}

.related-link {
    color: var(--glossary-primary);
    text-decoration: none;
    font-weight: 600;
}

.related-link:hover {
    color: var(--glossary-secondary);
}

.term-related-products {
    margin-top: 40px;
}

.term-related-products h3 {
    color: var(--glossary-primary);
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.related-product-card {
    background: white;
    padding: 20px;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.related-product-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--glossary-hover-shadow);
}

.related-product-card img {
    margin-bottom: 15px;
    border-radius: 5px;
}

.related-product-card .product-name {
    font-size: 1.1rem;
    color: var(--glossary-primary);
    margin-bottom: 10px;
}

.related-product-card .product-price {
    font-size: 1.3rem;
    color: var(--glossary-secondary);
    font-weight: 700;
    margin-bottom: 15px;
}

/* Back to Top Button */
.glossary-back-to-top {
    text-align: center;
    margin-top: 40px;
}

.glossary-back-to-top button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .glossary-page-title,
    .glossary-term-title {
        font-size: 2rem;
    }

    .alphabet-letters {
        gap: 5px;
    }

    .letter-link {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .glossary-term-card .term-name {
        font-size: 1.1rem;
    }

    .term-content-wrapper {
        padding: 20px;
    }

    .glossary-terms-list .term-name {
        font-size: 1.2rem;
    }
}

@media (max-width: 576px) {
    .glossary-container {
        padding: 10px;
    }

    .glossary-page-title,
    .glossary-term-title {
        font-size: 1.5rem;
    }

    .glossary-term-card .term-image {
        height: 150px;
    }

    .term-content-wrapper {
        padding: 15px;
    }
}

/* Print Styles */
@media print {
    .glossary-search-box,
    .glossary-alphabet,
    .glossary-back-to-top,
    .back-to-list {
        display: none;
    }

    .glossary-term-card {
        box-shadow: none;
        border: 1px solid #ddd;
        break-inside: avoid;
    }
}

/* =============================================================================
   DISPLAY MODE: LETTERS
   Inspired by the "by letters" theme — each letter gets a coloured badge,
   terms are displayed in a 4-column grid with name + short excerpt.
   ============================================================================= */

.glossary-letters-view {
    margin-top: 10px;
}

.letters-group {
    margin-bottom: 36px;
    background: #fff;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    overflow: hidden;
}

.letters-group-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

/* Coloured letter badges — 8-colour palette cycling per letter group */
.letters-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 6px;
    color: #fff;
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -1px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0,0,0,.18);
    user-select: none;
}

.letters-color-0 { background: #c0392b; }   /* crimson   */
.letters-color-1 { background: #6B7A1A; }   /* olive     */
.letters-color-2 { background: #d68910; }   /* amber     */
.letters-color-3 { background: #1a6b82; }   /* teal      */
.letters-color-4 { background: #7b2fa1; }   /* purple    */
.letters-color-5 { background: #2e5c27; }   /* forest    */
.letters-color-6 { background: #2e4482; }   /* navy      */
.letters-color-7 { background: #8a3325; }   /* rust      */

.letters-group-count {
    font-size: 0.8rem;
    color: #888;
    font-weight: 500;
}

.letters-group-body {
    padding: 20px;
}

.letters-term-item {
    padding: 10px 6px 14px;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color .2s;
}

.letters-term-item:hover {
    background: #f9f9f9;
    border-radius: 4px;
}

.letters-term-name {
    margin: 0 0 6px;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.3;
}

.letters-term-name a {
    color: var(--glossary-primary);
    text-decoration: none;
    transition: color .2s;
}

.letters-term-name a:hover {
    color: var(--glossary-secondary);
    text-decoration: underline;
}

.letters-term-excerpt {
    margin: 0;
    font-size: 0.8rem;
    color: #777;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .letters-badge {
        width: 42px;
        height: 42px;
        font-size: 1.4rem;
    }
    .letters-group-body .row > [class*="col-"] {
        margin-bottom: 8px;
    }
}

/* =============================================================================
   DISPLAY MODE: TABLE
   Compact, alternating-row table with a client-side live filter bar.
   Sortable Term column, highlight on filter match.
   ============================================================================= */

.glossary-table-wrapper {
    margin-top: 10px;
}

.table-live-filter-box {
    margin-bottom: 16px;
    max-width: 520px;
}

.table-live-filter-box .input-group {
    box-shadow: var(--glossary-shadow);
    border-radius: var(--glossary-border-radius);
    overflow: hidden;
}

.table-filter-icon {
    background: #fff;
    border: none;
    padding: 0 14px;
    display: flex;
    align-items: center;
    color: #aaa;
}

.glossary-table-filter-input {
    border: none;
    padding: 12px 16px;
    font-size: 0.95rem;
}

.glossary-table-filter-input:focus {
    outline: none;
    box-shadow: none;
}

.glossary-filter-clear {
    background: #fff;
    border: none;
    color: #aaa;
    transition: color .2s;
    display: flex;
    align-items: center;
    padding: 0 12px;
}

.glossary-filter-clear:hover {
    color: var(--glossary-primary);
    background: #fff;
}

.table-filter-count {
    margin: 6px 0 0 4px;
    font-size: 0.8rem;
    color: #888;
}

.table-filter-count span {
    font-weight: 700;
    color: var(--glossary-secondary);
}

/* Table */
.glossary-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    overflow: hidden;
}

.glossary-table thead th {
    background: var(--glossary-primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 14px 16px;
    border: none;
    white-space: nowrap;
}

.glossary-table thead th.sortable-col {
    cursor: pointer;
    user-select: none;
}

.glossary-table thead th.sortable-col:hover {
    background: var(--glossary-secondary);
}

.glossary-table .sort-icon {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 4px;
    opacity: .7;
}

.glossary-table .sort-icon .material-icons {
    font-size: 1rem;
    line-height: 1;
}

.glossary-table .col-term { width: 22%; }
.glossary-table .col-desc { width: 64%; }
.glossary-table .col-action { width: 14%; text-align: right; }

.glossary-table tbody tr {
    transition: background-color .15s;
}

.glossary-table tbody tr:nth-child(even) {
    background: #f9fafb;
}

.glossary-table tbody tr:hover {
    background: #eef4fb;
}

.glossary-table tbody td {
    padding: 12px 16px;
    vertical-align: top;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
    color: #444;
}

.glossary-table .cell-term strong a {
    color: var(--glossary-primary);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color .2s;
}

.glossary-table .cell-term strong a:hover {
    color: var(--glossary-secondary);
    text-decoration: underline;
}

.glossary-table .cell-desc {
    color: #666;
    line-height: 1.55;
}

.glossary-table .cell-action {
    vertical-align: middle;
}

/* Highlight matched text from live filter */
.glossary-table mark {
    background: #fff3cd;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

/* Hidden row when filtered out */
.glossary-table-row.hidden-row {
    display: none;
}

@media (max-width: 768px) {
    .glossary-table .col-desc,
    .glossary-table .cell-desc {
        display: none;
    }
    .glossary-table .col-term { width: 70%; }
    .glossary-table .col-action { width: 30%; }
}

/* =============================================================================
   DISPLAY MODE: TIMELINE
   Vertical timeline grouped by year (date_upd / date_add).
   Left rail with year labels + dots; cards float right.
   ============================================================================= */

.glossary-timeline {
    position: relative;
    padding: 10px 0 30px 0;
    margin-top: 10px;
}

/* The vertical spine line */
.timeline-spine {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 68px;
    width: 3px;
    background: linear-gradient(
        to bottom,
        var(--glossary-secondary) 0%,
        var(--glossary-primary) 100%
    );
    border-radius: 3px;
}

.timeline-year-block {
    position: relative;
    display: flex;
    margin-bottom: 40px;
    padding-left: 110px;
}

/* Year marker: dot on the spine + label to the left */
.timeline-year-marker {
    position: absolute;
    left: 0;
    top: 4px;
    width: 110px;
    display: flex;
    align-items: center;
    gap: 0;
}

.timeline-year-label {
    position: absolute;
    left: 0;
    width: 56px;
    text-align: right;
    font-size: 1rem;
    font-weight: 800;
    color: var(--glossary-primary);
    line-height: 1;
    padding-right: 8px;
}

.timeline-year-dot {
    position: absolute;
    left: 59px;
    top: -3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--glossary-secondary);
    border: 3px solid #fff;
    box-shadow: 0 0 0 3px var(--glossary-secondary);
    z-index: 1;
}

.timeline-first .timeline-year-dot {
    background: var(--glossary-primary);
    box-shadow: 0 0 0 3px var(--glossary-primary);
}

/* Terms area to the right of the spine */
.timeline-year-terms {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.timeline-term-card {
    background: #fff;
    border-radius: var(--glossary-border-radius);
    box-shadow: var(--glossary-shadow);
    overflow: hidden;
    width: calc(33.33% - 12px);
    min-width: 200px;
    transition: transform .25s ease, box-shadow .25s ease;
    display: flex;
    flex-direction: column;
}

.timeline-term-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--glossary-hover-shadow);
}

.timeline-term-image {
    width: 100%;
    height: 120px;
    overflow: hidden;
}

.timeline-term-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.timeline-term-content {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.timeline-term-name {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--glossary-primary);
}

.timeline-term-name a {
    color: var(--glossary-primary);
    text-decoration: none;
    transition: color .2s;
}

.timeline-term-name a:hover {
    color: var(--glossary-secondary);
}

.timeline-term-excerpt {
    font-size: 0.83rem;
    color: #777;
    line-height: 1.55;
    flex: 1;
    margin: 0 0 12px;
}

.timeline-term-link {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--glossary-secondary);
    text-decoration: none;
    transition: color .2s;
    margin-top: auto;
}

.timeline-term-link:hover {
    color: var(--glossary-primary);
}

@media (max-width: 992px) {
    .timeline-term-card {
        width: calc(50% - 8px);
    }
}

@media (max-width: 600px) {
    .timeline-spine { left: 46px; }
    .timeline-year-label { width: 36px; font-size: 0.8rem; }
    .timeline-year-dot { left: 38px; }
    .timeline-year-block { padding-left: 70px; }
    .timeline-year-marker { width: 70px; }
    .timeline-term-card { width: 100%; }
}

/* Timeline card fade-in triggered by IntersectionObserver (JS adds .timeline-visible) */
.timeline-term-card.timeline-visible {
    opacity: 1 !important;
    transform: translateY(0) !important;
}

/* ============================================================
   Cover Image
   ============================================================ */
.glossary-cover-image {
    width: 100%;
    margin-bottom: 24px;
    border-radius: var(--glossary-border-radius);
    overflow: hidden;
    line-height: 0;
}

.glossary-cover-img {
    width: 100%;
    max-height: 360px;
    object-fit: cover;
    display: block;
}

/* ============================================================
   Intro Text
   ============================================================ */
.glossary-intro-text {
    font-size: 1.05rem;
    color: #555;
    text-align: center;
    max-width: 760px;
    margin: 0 auto 28px;
    line-height: 1.7;
}

/* ============================================================
   Pagination
   ============================================================ */
.glossary-pagination {
    margin-top: 40px;
    text-align: center;
}

.glossary-pagination .pagination {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    list-style: none;
    padding: 0;
    margin: 0 0 10px;
    justify-content: center;
}

.glossary-pagination .page-item .page-link {
    display: inline-block;
    min-width: 40px;
    padding: 8px 14px;
    border: 1px solid #dee2e6;
    border-radius: var(--glossary-border-radius);
    color: var(--glossary-secondary);
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
    font-size: 0.9rem;
}

.glossary-pagination .page-item.active .page-link {
    background-color: var(--glossary-secondary);
    border-color: var(--glossary-secondary);
    color: #fff;
    font-weight: 700;
    pointer-events: none;
}

.glossary-pagination .page-item.disabled .page-link {
    color: #aaa;
    pointer-events: none;
    border-color: #eee;
}

.glossary-pagination .page-item .page-link:hover:not(.disabled) {
    background-color: var(--glossary-secondary);
    color: #fff;
    border-color: var(--glossary-secondary);
}

.pagination-info {
    font-size: 0.85rem;
    color: #888;
    margin-top: 6px;
}

/* Auto-linked term mentions (inside descriptions/CMS content, and now also
   client-side-linked product feature values — see front.js) */
a.glossary-autolink {
    text-decoration: underline;
    text-decoration-style: dotted;
}
