/* =============================================================================
   ABP Table Chart Section Styles  v4.0
   Uses the same CSS variables and design tokens as abp-styles.css
   ============================================================================= */

/* ── Shared width wrapper: controls + table/chart size together ───────────── */
/*
   TABLE MODE (default): the wrapper is sized to its content (fit-content) and
   capped at 100% of the section. A table with few columns therefore stays
   compact and centred; a table with many columns grows until it reaches the
   section width, after which .abp-ts-table-pane scrolls horizontally.
   min-width keeps very small tables (e.g. 2 short columns) from looking tiny.
*/
.abp-ts-content-wrap {
    width: fit-content;
    min-width: min(100%, 420px);
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    flex-direction: column;
}

/* CHART / BOTH modes: the wrapper constrains both the controls bar and the
   chart card to the same 800 px max-width, centred. */
.abp-ts-section[data-ts-display-mode="chart"] .abp-ts-content-wrap,
.abp-ts-section[data-ts-display-mode="both"]  .abp-ts-content-wrap {
    width: 100%;
    min-width: 0;
    max-width: 800px;
}

/* ── Controls bar ─────────────────────────────────────────────────────────── */
.abp-ts-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    padding: 0.65rem 1rem;
    background: var(--table-sub-bg, #f0f7f5);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    margin-bottom: 0.4rem;
    font-size: 0.875rem;
    /* Fill the wrapper — table width drives it, controls follow */
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.abp-ts-date-range {
    display: flex;
    align-items: center;
    gap: 0.4rem 0.5rem;
    flex-wrap: wrap;
}

.abp-ts-date-range label {
    font-weight: 600;
    color: var(--text-dark, #333);
    white-space: nowrap;
    font-size: 0.8125rem;
}

.abp-ts-sep {
    color: var(--text-light, #666);
    font-size: 0.75rem;
    padding: 0 0.1rem;
}

/* ── Picker trigger button ────────────────────────────────────────────────── */
.abp-ts-picker-wrap {
    position: relative;
    display: inline-flex;
}

.abp-ts-picker-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.32rem 0.65rem;
    font-size: 0.8125rem;
    font-weight: 500;
    background: #fff;
    color: var(--text-dark, #333);
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.4;
    min-width: 110px;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    text-align: left;
}
.abp-ts-picker-btn:hover,
.abp-ts-picker-btn.abp-picker-open {
    border-color: var(--primary-color, #26a69a);
    box-shadow: 0 0 0 2px rgba(38,166,154,0.18);
    outline: none;
}
.abp-ts-picker-btn svg {
    flex-shrink: 0;
    color: var(--primary-color, #26a69a);
}
.abp-ts-picker-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Picker popup ─────────────────────────────────────────────────────────── */
.abp-ts-picker-popup {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    z-index: 9999;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.13);
    min-width: 220px;
    padding: 0.65rem;
    animation: abp-picker-in 0.12s ease;
}
.abp-ts-picker-popup[hidden] { display: none; }

@keyframes abp-picker-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Year navigation row */
.abp-picker-year-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.55rem;
    gap: 0.3rem;
}
.abp-picker-yr-prev,
.abp-picker-yr-next {
    background: none;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-dark, #00897b);
    transition: background 0.12s, border-color 0.12s;
    padding: 0;
    font-family: inherit;
}
.abp-picker-yr-prev:hover:not(:disabled),
.abp-picker-yr-next:hover:not(:disabled) {
    background: #e0f2f0;
    border-color: var(--primary-color, #26a69a);
}
.abp-picker-yr-prev:disabled,
.abp-picker-yr-next:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.abp-picker-yr-display {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-dark, #333);
    min-width: 44px;
    text-align: center;
    letter-spacing: 0.02em;
}

/* Month grid (3 columns) */
.abp-picker-months {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}
.abp-picker-mo {
    background: #f5f5f5;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.35rem 0.2rem;
    text-align: center;
    color: var(--text-dark, #333);
    transition: background 0.1s, border-color 0.1s, color 0.1s;
    font-family: inherit;
    line-height: 1.3;
}
.abp-picker-mo:hover:not(:disabled):not(.abp-picker-mo-disabled) {
    background: #e0f2f0;
    border-color: var(--primary-color, #26a69a);
    color: var(--primary-dark, #00897b);
}
.abp-picker-mo.abp-picker-mo-active {
    background: linear-gradient(135deg, var(--primary-color, #26a69a) 0%, var(--primary-dark, #00897b) 100%);
    color: #fff !important;
    border-color: transparent;
}
.abp-picker-mo.abp-picker-mo-disabled,
.abp-picker-mo:disabled {
    opacity: 0.28;
    cursor: not-allowed;
    background: #efefef;
}
/* Full-width year-only select button */
.abp-picker-yr-select {
    grid-column: 1 / -1;
    padding: 0.45rem;
    font-size: 0.82rem;
}

/* Buttons — match .abp-section-box action button feel */
.abp-ts-apply-btn,
.abp-ts-all-btn,
.abp-ts-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.9rem;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    line-height: 1.4;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.abp-ts-apply-btn {
    background: var(--primary-color, #26a69a);
    color: #fff;
    border-color: var(--primary-color, #26a69a);
}
.abp-ts-apply-btn:hover {
    background: var(--primary-dark, #00897b);
    border-color: var(--primary-dark, #00897b);
}

.abp-ts-all-btn {
    background: #fff;
    color: var(--text-dark, #333);
    border-color: #b2dfdb;
}
.abp-ts-all-btn:hover {
    background: #e0f2f0;
    border-color: var(--primary-color, #26a69a);
    color: var(--primary-dark, #00897b);
}

.abp-ts-export-btn {
    background: #fff;
    color: var(--accent-color, #5c6bc0);
    border-color: #c5cae9;
    margin-left: auto;
}
.abp-ts-export-btn:hover {
    background: #e8eaf6;
    border-color: var(--accent-color, #5c6bc0);
}

/* ── View toggle — Table | Chart ──────────────────────────────────────────── */
.abp-ts-view-toggle {
    display: inline-flex;
    border: 1px solid #b2dfdb;
    border-radius: 5px;
    overflow: hidden;
}

.abp-ts-view-toggle button {
    padding: 0.35rem 0.85rem;
    font-size: 0.8125rem;
    font-weight: 600;
    background: #fff;
    color: var(--text-dark, #333);
    border: none;
    cursor: pointer;
    line-height: 1.4;
    transition: background 0.12s, color 0.12s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.abp-ts-view-toggle button + button {
    border-left: 1px solid #b2dfdb;
}
.abp-ts-view-toggle button:hover {
    background: #e0f2f0;
    color: var(--primary-dark, #00897b);
}
.abp-ts-view-toggle button.active {
    background: linear-gradient(135deg, var(--primary-color, #26a69a) 0%, var(--primary-dark, #00897b) 100%);
    color: #fff;
}

/* ── Table pane ───────────────────────────────────────────────────────────── */
/* Outer wrapper: shrinks to table content width, centers in the section */
/* ── Table layout ──────────────────────────────────────────────────────────
   Strategy:
   · outer  : inline-block so it shrinks to table width and centers with margin:auto.
              Also caps at 100% so it never overflows the section box.
   · pane   : overflow-x:auto so wide tables scroll inside the outer container.
   · table  : max-content width — columns size to their content exactly.
              min-width:100% fills the pane when content is narrower (e.g. 2 cols).
   ────────────────────────────────────────────────────────────────────────── */
.abp-ts-table-outer {
    /*
       Width is driven by .abp-ts-content-wrap (fit-content + centered).
       table-outer fills 100% of that wrapper so the border/radius wrap the
       table exactly. overflow:visible lets the pane scrollbar render correctly.
    */
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color, #e0e0e0);
    overflow: visible;
}

/* Inner scroll wrapper — this is what actually scrolls horizontally */
.abp-ts-table-pane {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Scroll-shadow gradients to hint scrollability */
    background:
        linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
        linear-gradient(to left,  #fff 30%, rgba(255,255,255,0)) 100% 0,
        radial-gradient(farthest-side at 0   50%, rgba(0,0,0,.10), transparent),
        radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.10), transparent) 100% 0;
    background-repeat: no-repeat;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

.abp-ts-table,
.abp-article-content .abp-ts-table {
    /* max-content: each column is exactly as wide as its widest cell, so the
       table (and its wrapper) shrinks to fit few columns and only fills the
       section when there are many. The .abp-article-content selector is needed
       to out-rank the generic ".abp-article-content table { width:100%;
       min-width:100% }" rule in abp-styles.css. min-width:100% still makes the
       table fill its (already content-sized) wrapper, so there are no gaps. */
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.abp-ts-table thead tr {
    background: linear-gradient(135deg, var(--primary-color, #26a69a) 0%, var(--primary-dark, #00897b) 100%);
}

.abp-ts-table thead th {
    padding: 11px 14px;
    text-align: left;
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #fff;
    border-bottom: none;
    /* Wrap at word boundaries only — never break mid-character */
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
    min-width: 70px;
    max-width: 200px;
}

/* Outer wrapper handles border-radius; no need on individual th cells */
.abp-ts-table thead th:first-child { border-radius: 0; }
.abp-ts-table thead th:last-child  { border-radius: 0; }

.abp-ts-table thead th.abp-ts-num { text-align: right; }

.abp-ts-table thead th.abp-ts-chart-col {
    border-bottom: 2px solid rgba(255,255,255,0.5);
}

.abp-ts-table tbody tr {
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    transition: background 0.1s;
}
.abp-ts-table tbody tr:nth-child(even) {
    background: var(--table-sub-bg, #f0f7f5);
}
.abp-ts-table tbody tr:hover {
    background: #e0f2f0;
}
.abp-ts-table td {
    padding: 10px 14px;
    font-size: 0.88rem;
    color: var(--text-dark, #333);
    white-space: nowrap;   /* keep values on one line */
    border-bottom: 1px solid var(--border-color, #e0e0e0);
}
.abp-ts-table td:first-child {
    font-weight: 600;
    color: var(--primary-dark, #00897b);
}
.abp-ts-table td.abp-ts-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.abp-ts-table td.abp-ts-chart-col {
    background: rgba(38, 166, 154, 0.04);
}
.abp-ts-table tbody tr:hover td.abp-ts-chart-col {
    background: rgba(38, 166, 154, 0.1);
}

.abp-ts-table tbody .abp-ts-no-rows td {
    text-align: center;
    padding: 2rem;
    color: var(--text-light, #666);
    font-style: italic;
    background: #fafafa;
}

@media (max-width: 600px) {
    .abp-ts-table-pane::after {
        content: "← Scroll to see more →";
        display: block;
        text-align: center;
        font-size: 0.72rem;
        color: var(--text-light, #888);
        padding: 4px 0 2px;
        pointer-events: none;
    }
    .abp-ts-table-pane.abp-no-scroll::after { display: none; }
}

/* ── Chart pane ───────────────────────────────────────────────────────────── */
.abp-ts-chart-pane {
    position: relative;
    height: 350px;
    margin-top: 0.5rem;
}

.abp-ts-chart-legend-note {
    font-size: 0.78rem;
    color: var(--text-light, #666);
    margin-bottom: 0.4rem;
    font-style: italic;
}

.abp-ts-chart-canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .abp-ts-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .abp-ts-export-btn { margin-left: 0; }
    .abp-ts-chart-pane { height: 280px; }
}

@media (max-width: 480px) {
    .abp-ts-chart-pane { height: 240px; }
    .abp-ts-controls { padding: 0.6rem 0.75rem; }
    .abp-ts-table thead th,
    .abp-ts-table td { padding: 8px 10px; font-size: 0.82rem; }
    .abp-ts-picker-popup { min-width: 190px; }
    .abp-picker-months { grid-template-columns: repeat(3,1fr); gap: 3px; }
}

/* ── Pagination bar ───────────────────────────────────────────────────────── */
.abp-ts-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border-color, #e0e0e0);
    background: var(--table-sub-bg, #f0f7f5);
    /* Fills the outer wrapper width — always aligned with the table above */
    width: 100%;
}

.abp-ts-prev-btn,
.abp-ts-next-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    background: #fff;
    color: var(--primary-color, #26a69a);
    border: 1px solid var(--primary-color, #26a69a);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.13s, color 0.13s;
    line-height: 1.4;
}
.abp-ts-prev-btn:hover:not(:disabled),
.abp-ts-next-btn:hover:not(:disabled) {
    background: var(--primary-color, #26a69a);
    color: #fff;
}
.abp-ts-prev-btn:disabled,
.abp-ts-next-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: var(--border-color, #e0e0e0);
    color: var(--text-light, #666);
}

.abp-ts-page-info {
    font-size: 0.8rem;
    color: var(--text-light, #666);
    min-width: 80px;
    text-align: center;
}

/* =============================================================================
   Options menus
   • .abp-ts-action-data  — "Download" button in the table toolbar (data exports)
   • .abp-ts-action-chart — compact ⋮ button in each chart card header
   ============================================================================= */

.abp-ts-action-wrap {
    position: relative;
    display: inline-flex;
    margin-left: auto;   /* push to the right edge of the controls bar */
    flex-shrink: 0;
}
.abp-ts-chart-card-header .abp-ts-action-wrap,
.abp-ts-table-options-bar .abp-ts-action-wrap {
    margin-left: 0;
}

/* ── Labelled trigger ("Download") — same teal family as the view toggle ── */
.abp-ts-action-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1;
    border-radius: 6px;
    border: 1px solid #b2dfdb;
    background: #fff;
    color: #00796b;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: background 0.14s, border-color 0.14s, color 0.14s, box-shadow 0.14s;
}
.abp-ts-action-trigger:hover,
.abp-ts-action-open .abp-ts-action-trigger {
    background: #e0f2f1;
    border-color: #26a69a;
}
.abp-ts-action-trigger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(38, 166, 154, 0.35);
    border-color: #26a69a;
}
.abp-ts-action-caret {
    transition: transform 0.18s ease;
    flex-shrink: 0;
}
.abp-ts-action-open .abp-ts-action-caret {
    transform: rotate(180deg);
}

/* ── Icon-only trigger (⋮) on chart cards — quiet until hovered ── */
.abp-ts-action-trigger.abp-ts-action-icon {
    width: 32px;
    padding: 0;
    justify-content: center;
    border-color: transparent;
    background: transparent;
    color: #6b7280;
}
.abp-ts-action-trigger.abp-ts-action-icon:hover,
.abp-ts-action-open .abp-ts-action-trigger.abp-ts-action-icon {
    background: #e0f2f1;
    border-color: #b2dfdb;
    color: #00796b;
}

/* ── Menu panel ── */
.abp-ts-action-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 9998;
    list-style: none;
    margin: 0;
    padding: 6px;
    min-width: 232px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
    text-align: left;
    animation: abp-action-menu-in 0.12s ease;
}
.abp-ts-action-menu[hidden] { display: none; }

/* Flipped placements, set by abp-tablechart.js when there is no room */
.abp-ts-menu-up .abp-ts-action-menu   { top: auto; bottom: calc(100% + 6px); }
.abp-ts-menu-left .abp-ts-action-menu { right: auto; left: 0; }

@keyframes abp-action-menu-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Group heading + what the download will contain */
.abp-ts-menu-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
}
.abp-ts-menu-hint {
    font-size: 0.74rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: #94a3b8;
}
.abp-ts-menu-hint:empty { display: none; }

/* ── Items ── */
.abp-ts-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #1f2937;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    line-height: 1.35;
    white-space: nowrap;
    transition: background 0.1s, color 0.1s;
}
.abp-ts-menu-item svg {
    flex-shrink: 0;
    color: #64748b;
    transition: color 0.1s;
}
.abp-ts-menu-label { flex: 1; }
.abp-ts-menu-fmt {
    flex-shrink: 0;
    padding: 2px 6px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 4px;
}
.abp-ts-menu-item:hover,
.abp-ts-menu-item:focus-visible {
    background: #e0f2f1;
    color: #00695c;
    outline: none;
}
.abp-ts-menu-item:hover svg,
.abp-ts-menu-item:focus-visible svg { color: #00796b; }
.abp-ts-menu-item:hover .abp-ts-menu-fmt,
.abp-ts-menu-item:focus-visible .abp-ts-menu-fmt { background: #fff; color: #00796b; }

.abp-ts-menu-divider {
    height: 1px;
    background: #eef2f6;
    margin: 6px 4px;
}

/* Narrow screens: icon-only Download button, menu never wider than the screen */
@media (max-width: 480px) {
    .abp-ts-action-data .abp-ts-action-label,
    .abp-ts-action-data .abp-ts-action-caret { display: none; }
    .abp-ts-action-data .abp-ts-action-trigger { width: 32px; padding: 0; justify-content: center; }
    .abp-ts-action-menu { min-width: 210px; max-width: calc(100vw - 24px); }
}

/* Chart card header: title left, ⋮ right (all display modes) */
.abp-ts-chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.abp-ts-chart-card-header .abp-ts-chart-title {
    margin: 0;
    flex: 1;
    min-width: 0;
}

/* Fullscreen header actions + source line */
.abp-ts-fs-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.abp-ts-fs-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 6px;
    border: 1px solid #b2dfdb;
    background: #fff;
    color: #00796b;
    cursor: pointer;
}
.abp-ts-fs-btn:hover { background: #e0f2f1; border-color: #26a69a; }
.abp-ts-fs-btn:focus-visible { outline: 2px solid #26a69a; outline-offset: 2px; }
.abp-ts-fs-source {
    margin: 0;
    padding: 0 24px 16px;
    font-size: 0.78rem;
    color: #718096;
}
@media (max-width: 600px) {
    .abp-ts-fs-btn span { display: none; }
    .abp-ts-fs-btn { width: 32px; padding: 0; justify-content: center; }
}

/* =============================================================================
   Fullscreen Overlay
   ============================================================================= */

body.abp-ts-fs-open {
    overflow: hidden;
}

/* ── Backdrop ── */
#abp-ts-fs-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    animation: abp-fs-in 0.18s ease;
}

@keyframes abp-fs-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Panel ── */
.abp-ts-fs-panel {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 16px 60px rgba(0,0,0,0.35);
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px;
    height: min(760px, calc(100vh - 48px));   /* definite height so the chart can fill it */
    max-height: calc(100vh - 48px);
    overflow: hidden;
    animation: abp-fs-panel-in 0.18s ease;
}

@keyframes abp-fs-panel-in {
    from { transform: scale(0.96); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

/* ── Panel header ── */
.abp-ts-fs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--border-color, #e0e0e0);
    flex-shrink: 0;
}

.abp-ts-fs-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-dark, #1a1a1a);
    margin: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Close button ── */
.abp-ts-fs-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    color: var(--text-dark, #444);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.13s, border-color 0.13s, color 0.13s;
    padding: 0;
    font-family: inherit;
}

.abp-ts-fs-close:hover {
    background: #fce4e4;
    border-color: #e57373;
    color: #c62828;
}

.abp-ts-fs-close:focus-visible {
    outline: 2px solid var(--primary-color, #26a69a);
    outline-offset: 2px;
}

/* ── Canvas wrapper ── */
.abp-ts-fs-canvas-wrap {
    flex: 1;
    position: relative;
    padding: 20px 24px 24px;
    min-height: 0;
}

.abp-ts-fs-canvas {
    width: 100%  !important;
    height: 100% !important;
    display: block;
}

@media (max-width: 600px) {
    #abp-ts-fs-overlay        { padding: 10px; }
    .abp-ts-fs-panel          { border-radius: 8px; max-height: calc(100vh - 20px); }
    .abp-ts-fs-header         { padding: 10px 12px 9px; }
    .abp-ts-fs-canvas-wrap    { padding: 12px 12px 16px; }
}

/* =============================================================================
   Table-only mode: inline options bar (no separate controls bar)
   ============================================================================= */

/* The table-outer becomes the positioning context */
.abp-ts-table-has-inline-options {
    position: relative;
}

/* Slim bar that sits flush above the table, right-aligned */
.abp-ts-table-options-bar {
    display: flex;
    justify-content: flex-end;
    padding: 6px 10px 6px 10px;
    background: transparent;
}

/* When the dropdown is inside the table-options-bar, reset the auto-margin
   (margin-left:auto is only needed inside the flex controls bar) */
.abp-ts-table-options-bar .abp-ts-action-wrap {
    margin-left: 0;
}

/* ── Duplicate chart title ────────────────────────────────────────────────
   abp-tablechart.js adds .abp-ts-title-dup when the card heading is identical
   to an axis title, so the text is shown once (as the axis title) instead of
   twice. The Options button stays right-aligned in the card header. */
.abp-ts-chart-card.abp-ts-title-dup .abp-ts-chart-title {
    display: none;
}
.abp-ts-chart-card.abp-ts-title-dup .abp-ts-chart-card-header {
    justify-content: flex-end;
}
/* ── Source citation ──────────────────────────────────────────────────────
   Optional "Source Name / Source URL" from the builder, shown under the
   table/charts. Same block on report sections and in Malawi Map tabs. */
.abp-ts-source {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
    font-size: 0.78rem;
    color: #718096;
}
.abp-ts-source-prefix {
    font-weight: 600;
}
.abp-ts-source a {
    color: #26a69a;
    font-weight: 600;
    text-decoration: none;
    word-break: break-word;
}
.abp-ts-source a:hover,
.abp-ts-source a:focus {
    text-decoration: underline;
}

/* Balance the ⋮ button so centred chart titles stay visually centred */
.abp-ts-chart-card-header::before {
    content: '';
    width: 32px;
    flex-shrink: 0;
}
.abp-ts-chart-card.abp-ts-title-dup .abp-ts-chart-card-header::before {
    display: none;
}
