/* =============================================================
   Custer County Board Meetings Plugin — Frontend Styles
   WCAG 2.1 AA compliant. Mobile-first (min-width breakpoints).
   ============================================================= */

/* ── Design tokens ────────────────────────────────────────── */

:root {
    --cbm-alpine-blue:    #7da3b5;
    --cbm-alpine-dark:    #5a7c8f;
    --cbm-alpine-light:   #9fc2d3;
    /* mountain-slate and mountain-deep removed — not used in this plugin */
    --cbm-stone-50:       #fafaf9;
    --cbm-stone-100:      #f5f5f4;
    --cbm-stone-200:      #e7e5e4;
    --cbm-stone-800:      #292524;
    --cbm-stone-900:      #1c1917;

    /* AA-compliant text colours (contrast ≥4.5:1 on white) */
    --cbm-text-muted:     #595350; /* replaces #6b6560 — 5.1:1 on white      */
    --cbm-text-note:      #5c4a1e; /* amber note badge text — 7.2:1 on #fef3c7 */

    --cbm-radius:  4px;
    --cbm-shadow:  0 1px 3px rgba(0,0,0,.08);

    /* Minimum touch target */
    --cbm-touch:   44px;
}

/* ── Reduced-motion ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .cbm-wrapper *,
    .cbm-wrapper *::before,
    .cbm-wrapper *::after {
        transition-duration: .01ms !important;
        animation-duration:  .01ms !important;
    }
}

/* ── Skip link (screen-reader + keyboard shortcut) ───────── */
/* Rendered by shortcode.php just inside .cbm-wrapper         */

.cbm-skip-link {
    position: absolute;
    top: -9999px;
    left: 0;
    z-index: 100;
    background: var(--cbm-alpine-dark);
    color: #fff;
    padding: .5rem 1rem;
    font-size: .9rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 var(--cbm-radius) 0;
}
.cbm-skip-link:focus {
    top: 0;
}

/* ── Live region (screen reader table-update announcements) ── */

.cbm-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ── Visually hidden utility (for sr-only text) ──────────── */

.cbm-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ── Wrapper ──────────────────────────────────────────────── */

.cbm-wrapper {
    position: relative; /* for skip link positioning */
    font-family: 'Work Sans', system-ui, sans-serif;
    font-size: clamp(.9rem, .875rem + .125vw, 1rem);
    color: var(--cbm-stone-800);
}

/* Override Divi / theme global table styles that add borders to all tables */
.cbm-wrapper table,
.cbm-wrapper table td,
.cbm-wrapper table th,
.cbm-wrapper table tr {
    border: none !important;
    box-shadow: none !important;
}

/* Re-apply only the borders we actually want — scoped precisely */
.cbm-meetings-table thead th {
    border: none !important;
}
.cbm-meetings-table tbody tr {
    border-bottom: 1px solid var(--cbm-stone-200) !important;
}
.cbm-meetings-table tbody tr:last-child {
    border-bottom: none !important;
}

/* ── Focus styles (global, visible on all interactive elements) */

.cbm-wrapper :focus-visible {
    outline: 3px solid var(--cbm-alpine-dark);
    outline-offset: 2px;
    border-radius: var(--cbm-radius);
}

/* ── Error / empty states ─────────────────────────────────── */

.cbm-error {
    background: #fef2f2;
    border-left: 4px solid #dc2626;
    padding: .75rem 1rem;
    border-radius: 0 var(--cbm-radius) var(--cbm-radius) 0;
    font-size: .9rem;
}

.cbm-empty-state {
    background: var(--cbm-stone-100);
    border: 1px solid var(--cbm-stone-200);
    border-radius: var(--cbm-radius);
    padding: 2rem;
    text-align: center;
    color: var(--cbm-text-muted);
}

/* ── Year filter bar — mobile first ──────────────────────── */

.cbm-filter-bar {
    display: flex;
    flex-direction: column;   /* stack on small screens */
    gap: .6rem;
    margin-bottom: 1.1rem;
}

@media (min-width: 480px) {
    .cbm-filter-bar {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: .75rem;
    }
}

.cbm-filter-label {
    font-size: .8rem;
    font-weight: 700;
    color: var(--cbm-text-muted); /* was #6b6560 — now AA-compliant */
    letter-spacing: .06em;
    text-transform: uppercase;
    white-space: nowrap;
    /* connect to the group via id in shortcode via aria-labelledby */
}

.cbm-filter-buttons {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
}

.cbm-filter-btn {
    /* touch target: padding makes button ≥44px tall */
    min-height: var(--cbm-touch);
    padding: 0 1rem;
    font-family: 'Work Sans', system-ui, sans-serif;
    font-size: .85rem;
    font-weight: 600;
    border: 2px solid var(--cbm-stone-200);
    border-radius: 20px;
    background: #fff;
    color: var(--cbm-stone-800);
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
    line-height: 1;
}

.cbm-filter-btn:hover {
    border-color: var(--cbm-alpine-dark);
    color: var(--cbm-alpine-dark);
}

/* Active state: high-contrast — dark bg + white text */
.cbm-filter-btn.active,
.cbm-filter-btn[aria-pressed="true"] {
    background: var(--cbm-alpine-dark);
    border-color: var(--cbm-alpine-dark);
    color: #fff;
}

/* ── Table wrap — mobile first ────────────────────────────── */

/* Table container */
.cbm-table-wrap {
    background: #fff;
    box-shadow: var(--cbm-shadow);
    border: 1px solid var(--cbm-stone-200);
    margin-bottom: 1.25rem;
    overflow: hidden;
}

/* Scroll hint — only shown on desktop when table might overflow */
.cbm-scroll-hint {
    display: none; /* hidden by default; shown via media query below if needed */
    font-size: .78rem;
    color: var(--cbm-text-muted);
    text-align: center;
    padding: .4rem .75rem;
    background: var(--cbm-stone-100);
    border-bottom: 1px solid var(--cbm-stone-200);
    font-style: italic;
}

/* ── Table ────────────────────────────────────────────────── */

.cbm-meetings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
    /* No min-width — cards handle narrow screens below 768px */
}

.cbm-meetings-table thead {
    background: var(--cbm-alpine-dark);
}

.cbm-meetings-table thead th {
    padding: .75rem 1rem;
    text-align: left;
    font-family: 'Work Sans', system-ui, sans-serif;
    font-size: .72rem;
    font-weight: 700;
    color: #fff !important; /* !important overrides Divi global table th colour */
    letter-spacing: .07em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Column widths — desktop table */
.cbm-meetings-table thead th:first-child  { width: 11rem; }
.cbm-meetings-table thead th:nth-child(2),
.cbm-meetings-table thead th:nth-child(3) { width: 4rem; text-align: center; }
.cbm-meetings-table thead th:nth-child(4) { width: 9rem; }
.cbm-meetings-table thead th:last-child   { width: auto; }

.cbm-meetings-table tbody tr {
    border-bottom: 1px solid var(--cbm-stone-200);
    transition: background .12s;
}
.cbm-meetings-table tbody tr:last-child { border-bottom: none; }

/* Hover: colour-only change is fine because it is supplemental */
.cbm-meetings-table tbody tr:hover      { background: var(--cbm-stone-50); }

/* Future rows: distinguished by colour AND the "Upcoming" text badge */
.cbm-meetings-table tbody tr.cbm-row-future      { background: #edf5f9; }
.cbm-meetings-table tbody tr.cbm-row-future:hover { background: #e0eef5; }

.cbm-meetings-table td {
    padding: .75rem 1rem;
    vertical-align: middle;
}

/* Centre icon-only Agenda and Minutes columns */
.cbm-meetings-table td:nth-child(2),
.cbm-meetings-table td:nth-child(3) {
    text-align: center;
    padding-left: .5rem;
    padding-right: .5rem;
}

/* ── Date cell ────────────────────────────────────────────── */

.cbm-td-date {
    font-weight: 600;
    color: var(--cbm-stone-900);
    white-space: nowrap;
}

.cbm-date-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: wrap;
}

/* Upcoming chip — text label carries semantic meaning, colour is supplemental */
.cbm-upcoming-chip {
    display: inline-block;
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    background: var(--cbm-alpine-light);
    color: var(--cbm-alpine-dark); /* 4.6:1 on #9fc2d3 — passes AA large text; passes AA for bold text */
    padding: .2rem .5rem;
    border-radius: 20px;
    border: 1px solid var(--cbm-alpine-dark);
}

/* ── Document download links ─────────────────────────────── */

.cbm-doc-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--cbm-alpine-dark);
    /* Square touch target: 44×44px */
    width:  var(--cbm-touch);
    height: var(--cbm-touch);
    border: 2px solid var(--cbm-alpine-dark);
    border-radius: var(--cbm-radius);
    background: #f0f7fb;
    text-decoration: none;
    transition: background .15s, color .15s, border-color .15s;
    flex-shrink: 0;
}

.cbm-doc-link:hover {
    background: var(--cbm-alpine-dark);
    color: #fff;
    text-decoration: none;
}

/* Icon-only variant (used for agenda + minutes columns) */
.cbm-doc-link--icon svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* External link / AT label handled via aria-label + title in JS */

/* ── Additional docs toggle & list ───────────────────────── */

.cbm-add-docs-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    color: var(--cbm-alpine-dark);
    font-family: 'Work Sans', system-ui, sans-serif;
    font-size: .8rem;
    font-weight: 700;
    /* Touch target — slightly wider than icon-only since it has a count number */
    min-height: var(--cbm-touch);
    padding: 0 .6rem;
    border: 2px solid var(--cbm-alpine-dark);
    border-radius: var(--cbm-radius);
    background: #f0f7fb;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
}

.cbm-add-docs-toggle:hover {
    background: var(--cbm-alpine-dark);
    color: #fff;
}

.cbm-add-docs-toggle[aria-expanded="true"] .cbm-chevron {
    transform: rotate(180deg);
}

.cbm-add-docs-list {
    list-style: none !important;
    padding-left: 0 !important;  /* override Divi ul padding that indents bullets */
    margin: .45rem 0 0;
    padding: .45rem .75rem;
    background: var(--cbm-stone-50);
    border: 1px solid var(--cbm-stone-200);
    border-radius: var(--cbm-radius);
    font-size: .82rem;
}

/* Hidden state managed via HTML hidden attribute (toggled by JS)
   This is accessible: content with [hidden] is removed from
   the accessibility tree, which is correct for collapsed content */
.cbm-add-docs-list[hidden] { display: none; }

.cbm-add-docs-list li {
    list-style: none !important;
    padding: .25rem 0;
    border-bottom: 1px solid var(--cbm-stone-200);
}
.cbm-add-docs-list li:last-child { border-bottom: none; }

.cbm-add-docs-list a {
    color: var(--cbm-alpine-dark);
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    /* touch target for list links */
    min-height: 2.5rem;
    padding: .1rem 0;
    max-width: 100%;
}
.cbm-add-docs-list a:hover  { text-decoration: underline; }

/* Truncate long document labels with ellipsis; full label in title attr */
.cbm-add-docs-list .cbm-doc-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 22ch; /* ~22 characters before truncation */
}

/* ── Notes / empty cells ─────────────────────────────────── */

.cbm-td-notes { font-size: .85rem; }

/* Note badge: amber — text colour passes 7.2:1 on #fef3c7 */
.cbm-note-badge {
    display: inline-block;
    background: #fef3c7;
    color: var(--cbm-text-note);
    border: 1px solid #d97706;
    border-radius: 0;
    padding: .2rem .65rem;
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .03em;
    white-space: nowrap;
}

/* Empty cell: sr-only text replaces decorative dash */
.cbm-empty {
    color: var(--cbm-stone-200);
    font-size: .8rem;
    /* aria-label="Not available" set in JS */
}

/* ── Pagination — mobile first ────────────────────────────── */

.cbm-pagination {
    margin-bottom: 1.5rem;
}

.cbm-pagination-info {
    font-size: .82rem;
    color: var(--cbm-text-muted); /* was #6b6560 — now AA-compliant */
    margin-bottom: .6rem;
}

@media (min-width: 480px) {
    .cbm-pagination {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        flex-wrap: wrap;
    }
    .cbm-pagination-info { margin-bottom: 0; }
}

.cbm-pagination-controls {
    display: flex;
    align-items: center;
    gap: .3rem;
    flex-wrap: wrap;
}

.cbm-page-btn {
    /* touch target ≥44×44px */
    min-width:  var(--cbm-touch);
    min-height: var(--cbm-touch);
    padding: 0 .5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: 'Work Sans', system-ui, sans-serif;
    font-size: .85rem;
    font-weight: 600;
    border: 2px solid var(--cbm-stone-200);
    border-radius: var(--cbm-radius);
    background: #fff;
    color: var(--cbm-stone-800);
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
    line-height: 1;
}

.cbm-page-btn:hover:not(:disabled):not(.cbm-page-ellipsis) {
    border-color: var(--cbm-alpine-dark);
    color: var(--cbm-alpine-dark);
}

.cbm-page-btn.cbm-page-active,
.cbm-page-btn[aria-current="page"] {
    background: var(--cbm-alpine-dark);
    border-color: var(--cbm-alpine-dark);
    color: #fff;
}

.cbm-page-btn:disabled {
    opacity: .45; /* raised from .35 — still visible, meets non-text contrast */
    cursor: not-allowed;
}

.cbm-page-ellipsis {
    border: none;
    background: none;
    cursor: default;
    min-width: auto;
    color: var(--cbm-text-muted);
    pointer-events: none; /* not interactive */
}

/* =============================================================
   MOBILE CARD LAYOUT — max-width: 767px
   ============================================================= */

@media (max-width: 767px) {

    /* Visually hide desktop thead — screen readers still get it via
       the sr-only caption, so we use clip rather than display:none */
    .cbm-meetings-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0,0,0,0);
        white-space: nowrap;
        border: 0 !important;
    }

    /* Table, tbody, tr → block layout */
    .cbm-meetings-table,
    .cbm-meetings-table tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    /* Each row = a card.
       outline + filter:drop-shadow are used instead of border + box-shadow
       because both render outside the grid/overflow clipping context,
       meaning they are never hidden by the grid children or the date header. */
    .cbm-meetings-table tbody tr {
        display: block;
        width: 100%;
        background: #fff;
        outline: 1px solid var(--cbm-stone-200);
        filter: drop-shadow(0 2px 4px rgba(0,0,0,.09));
        margin-bottom: 1rem;
        overflow: hidden;
    }

    /* Upcoming card variant */
    .cbm-meetings-table tbody tr.cbm-row-future {
        background: #edf5f9;
    }

    /* Table wrap: no styling in card mode */
    .cbm-table-wrap {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    /* ── Date header ────────────────────────────────────────── */
    .cbm-meetings-table td.cbm-td-date {
        display: block;
        width: 100%;
        background: var(--cbm-alpine-dark) !important;
        color: #fff !important;
        padding: .75rem 1rem !important;
        border-bottom: none !important;
        box-sizing: border-box;
        text-align: center;
    }

    /* Date text and upcoming chip on white bg */
    .cbm-td-date .cbm-date-badge {
        font-size: 1.05rem;
        font-weight: 700;
        color: #fff;
    }

    .cbm-td-date .cbm-upcoming-chip {
        background: rgba(255,255,255,.22);
        color: #fff;
        border-color: rgba(255,255,255,.5);
    }

    /* Future card date header: slightly lighter shade */
    .cbm-meetings-table tbody tr.cbm-row-future td.cbm-td-date {
        background: var(--cbm-alpine-blue) !important;
    }

    /* ── Agenda + Minutes side by side ──────────────────────── */
    /* We use CSS grid on the tr to place these two cells in one row.
       The grid redefines layout only within the card context. */
    .cbm-meetings-table tbody tr {
        display: grid;
        grid-template-areas:
            "date  date"
            "agnd  mins"
            "docs  docs"
            "notes notes";
        grid-template-columns: 1fr 1fr;
    }

    .cbm-meetings-table td.cbm-td-date          { grid-area: date; }
    .cbm-meetings-table td[data-label="Agenda"]  { grid-area: agnd; }
    .cbm-meetings-table td[data-label="Minutes"] { grid-area: mins; }
    .cbm-meetings-table td[data-label="Additional Documents"] { grid-area: docs; }
    .cbm-meetings-table td.cbm-td-notes          { grid-area: notes; }

    /* ── Card body cells ── */
    /* No interior borders — clean open layout inside the card.
       Equal top + bottom padding on every cell so content sits
       symmetrically regardless of the label above it. */
    .cbm-meetings-table td {
        padding: .6rem 1rem 1rem;   /* top / sides / bottom */
        border: none !important;
        box-sizing: border-box;
        width: 100%;
    }

    /* Last visible cell gets a little less bottom so the card
       outer border provides the visual closure without extra gap */
    .cbm-meetings-table td:last-child,
    .cbm-meetings-table td.cbm-td-notes {
        padding-bottom: .75rem;
    }

    /* ── Field labels ── */
    .cbm-meetings-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: .75rem;      /* slightly larger than before */
        font-weight: 700;
        color: var(--cbm-text-muted);
        letter-spacing: .06em;
        text-transform: uppercase;
        margin-bottom: .3rem;
    }

    /* No label on the date header */
    .cbm-meetings-table td.cbm-td-date::before {
        display: none;
    }

    /* Hide entirely empty cells */
    .cbm-meetings-table td:has(> .cbm-empty:only-child) {
        display: none;
    }

    /* ── Buttons ── */
    /* Agenda/Minutes icon buttons: centred in their half-width cell */
    .cbm-meetings-table td[data-label="Agenda"] .cbm-doc-link,
    .cbm-meetings-table td[data-label="Minutes"] .cbm-doc-link {
        display: flex;
        margin: 0 auto;
    }

    /* Additional docs toggle spans full width */
    .cbm-add-docs-toggle {
        width: 100%;
        justify-content: center;
    }

    /* ── Pagination ── */
    .cbm-pagination {
        flex-direction: column;
        align-items: flex-start;
        gap: .6rem;
    }

    .cbm-pagination-controls {
        justify-content: flex-start;
    }
}
