/* ==========================================================================
   Orangy Tables — frontend styles (v1.0.1)
   Fixes: horizontal scroll for wide tables, mobile layout, font isolation.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Isolate our styling from the parent theme.
   Astra / Elementor / theme.json all inject typography that leaks into
   arbitrary <table> markup. Reset it at our own wrapper so what the user
   sees is always our design, not the theme's serif default.
   -------------------------------------------------------------------------- */
.orangy-tables-wrap,
.orangy-tables-wrap * {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-style: normal;
}

.orangy-tables-wrap {
    margin: 24px 0;
    max-width: 100%;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.5;
}

.orangy-tables-title {
    font-size: 1.4em;
    margin: 0 0 6px;
    font-weight: 600;
}

.orangy-tables-desc {
    color: #555;
    margin: 0 0 14px;
    font-size: 0.95em;
}

.orangy-tables-error {
    background: #fff8e1;
    border: 1px solid #f6d97a;
    padding: 10px 14px;
    color: #8a6d3b;
    border-radius: 4px;
}

/* Toolbar / export buttons */
.orangy-tables-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
    flex-wrap: wrap;
    gap: 6px;
}
.orangy-tables-export-btn {
    background: #f6f7f7;
    border: 1px solid #d1d5db;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    color: #1f2937;
}
.orangy-tables-export-btn:hover { background: #e5e7eb; }

/* --------------------------------------------------------------------------
   HORIZONTAL SCROLL CONTAINER
   Table sits inside .orangy-tables-scroll (added by JS on old markup),
   giving overflow-x. Scroll shadow indicates more content off-screen.
   -------------------------------------------------------------------------- */
.orangy-tables-wrap .orangy-tables-scroll {
    position: relative;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    background:
        linear-gradient(to right, #ffffff 30%, rgba(255, 255, 255, 0)) 0 0,
        linear-gradient(to right, rgba(255, 255, 255, 0), #ffffff 70%) 100% 0,
        radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0)) 0 0,
        radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0)) 100% 0;
    background-repeat: no-repeat;
    background-color: transparent;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
    scrollbar-width: thin;
}
.orangy-tables-scroll::-webkit-scrollbar { height: 8px; }
.orangy-tables-scroll::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; }
.orangy-tables-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.orangy-tables-scroll::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --------------------------------------------------------------------------
   Base table — force sensible layout even when the theme fights us
   -------------------------------------------------------------------------- */
.orangy-tables-wrap table.orangy-tables {
    border-collapse: collapse;
    font-size: 14px;
    color: #1f2937;
    background: transparent;
    /* When inside the scroll wrapper, let the table take its natural width
       so columns aren't forced narrow. Everywhere else, fill the container. */
    width: 100%;
}
.orangy-tables-scroll > table.orangy-tables {
    width: auto;
    min-width: 100%;
}
.orangy-tables-wrap table.orangy-tables th,
.orangy-tables-wrap table.orangy-tables td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
    color: #1f2937;
    /* Prevent aggressive word-splitting that stacks each word on its own line */
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    line-height: 1.5;
}
.orangy-tables-wrap table.orangy-tables thead th {
    background: #f6f7f7;
    font-weight: 600;
    color: #1f2937;
    border-bottom: 2px solid #d1d5db;
    white-space: nowrap;
    vertical-align: middle;
}
.orangy-tables-wrap table.orangy-tables tbody tr:hover {
    background: #fafafa;
}

/* Give text columns a comfortable minimum so a "Description" cell like
   "Distance from spindle nose to table center" doesn't stack one word per
   line. The scroll wrapper still lets the whole table extend beyond the
   viewport if needed. */
.orangy-tables-wrap table.orangy-tables td {
    min-width: 90px;
}
.orangy-tables-wrap table.orangy-tables td.orangy-col-text,
.orangy-tables-wrap table.orangy-tables td.orangy-col-html {
    min-width: 180px;
}
.orangy-tables-wrap table.orangy-tables td.orangy-col-image { min-width: 100px; }
.orangy-tables-wrap table.orangy-tables td.orangy-col-boolean,
.orangy-tables-wrap table.orangy-tables td.orangy-col-number { min-width: 70px; }

/* Alignment */
.orangy-tables-wrap .align-left   { text-align: left; }
.orangy-tables-wrap .align-center { text-align: center; }
.orangy-tables-wrap .align-right  { text-align: right; }

/* Cell renderers */
.orangy-tables-wrap .orangy-tables-img {
    max-width: 80px;
    height: auto;
    border-radius: 4px;
    display: inline-block;
}
.orangy-tables-wrap .orangy-tables-bool.yes { color: #16a34a; font-weight: 700; }
.orangy-tables-wrap .orangy-tables-bool.no  { color: #dc2626; font-weight: 700; }

/* Formula cells: KaTeX will replace them on init. If it doesn't run (e.g.
   the value isn't actually a formula), the raw text stays in the same
   sans-serif as the rest of the table — no accidental italic serif. */
.orangy-tables-wrap .orangy-tables-formula {
    font-family: inherit;
    font-style: normal;
}
.orangy-tables-wrap .katex,
.orangy-tables-wrap .katex * {
    font-family: KaTeX_Main, "Times New Roman", serif;
}

/* ==========================================================================
   Themes
   ========================================================================== */
.theme-default {}

.orangy-tables-wrap .theme-minimal thead th {
    background: transparent;
    border-bottom: 2px solid #111;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.05em;
}
.orangy-tables-wrap .theme-minimal td { border-bottom: 1px dashed #e5e7eb; }
.orangy-tables-wrap .theme-minimal tbody tr:hover { background: transparent; }

.orangy-tables-wrap .theme-boxed {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.orangy-tables-wrap .theme-boxed thead th {
    background: linear-gradient(180deg, #fff, #f3f4f6);
}

.orangy-tables-wrap .theme-dark {
    background: #111827;
    color: #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
}
.orangy-tables-wrap .theme-dark thead th {
    background: #1f2937;
    color: #f9fafb;
    border-bottom: 2px solid #374151;
}
.orangy-tables-wrap .theme-dark tbody td {
    border-bottom: 1px solid #1f2937;
    color: #e5e7eb;
}
.orangy-tables-wrap .theme-dark tbody tr:hover { background: #1e2432; }

/* Stripe */
.orangy-tables-wrap table.orangy-tables.stripe tbody tr:nth-child(odd) { background: #fbfbfc; }
.orangy-tables-wrap table.orangy-tables.stripe.theme-dark tbody tr:nth-child(odd) { background: #161e2e; }

/* Compact */
.orangy-tables-wrap table.orangy-tables.compact th,
.orangy-tables-wrap table.orangy-tables.compact td { padding: 6px 8px; font-size: 13px; }

/* ==========================================================================
   MOBILE (v1.0.1)
   Default = horizontal scroll (better for spec/data tables — user swipes
   sideways instead of seeing broken stacked cards).
   Card stacking is OPT-IN via class="orangy-mobile-stack" in the shortcode.
   ========================================================================== */
@media (max-width: 782px) {
    .orangy-tables-wrap { margin: 16px 0; }
    .orangy-tables-wrap table.orangy-tables { font-size: 13px; }
    .orangy-tables-wrap table.orangy-tables th,
    .orangy-tables-wrap table.orangy-tables td { padding: 8px 10px; }
    .orangy-tables-wrap .orangy-tables-img { max-width: 56px; }

    /* DataTables controls: stop the search box and pagination from bursting
       out of the container. */
    .orangy-tables-wrap .dataTables_wrapper .dataTables_length,
    .orangy-tables-wrap .dataTables_wrapper .dataTables_filter,
    .orangy-tables-wrap .dataTables_wrapper .dataTables_info,
    .orangy-tables-wrap .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: left;
        width: 100%;
        margin: 6px 0;
        box-sizing: border-box;
    }
    .orangy-tables-wrap .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-top: 4px;
        box-sizing: border-box;
    }
    .orangy-tables-wrap .dataTables_wrapper .dataTables_length select {
        max-width: 120px;
    }
    .orangy-tables-wrap .dataTables_wrapper .dataTables_paginate { text-align: center; }
    .orangy-tables-wrap .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 4px 8px;
        margin: 2px;
    }
    /* Keep headers on one line so column widths stay readable while scrolling */
    .orangy-tables-wrap table.orangy-tables thead th { white-space: nowrap; }
}

/* Opt-in card stacking (narrow phones only) — for tables where cards
   read better than scroll (e.g. member directories with few columns). */
@media (max-width: 560px) {
    .orangy-mobile-stack thead { display: none; }
    .orangy-mobile-stack tbody tr {
        display: block;
        margin-bottom: 10px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        overflow: hidden;
        background: #fff;
    }
    .orangy-mobile-stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border-bottom: 1px solid #f0f0f1;
        padding: 8px 10px;
        min-width: 0;
    }
    .orangy-mobile-stack tbody td:last-child { border-bottom: none; }
    .orangy-mobile-stack tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #4b5563;
        flex: 0 0 40%;
        text-align: left;
    }
}

/* DataTables control styling (all sizes) */
.orangy-tables-wrap .dataTables_wrapper .dataTables_filter input {
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px 8px;
    font-family: inherit;
}
.orangy-tables-wrap .dataTables_wrapper .dataTables_paginate .paginate_button.current,
.orangy-tables-wrap .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: #d97706 !important;
    color: #fff !important;
    border: 1px solid #d97706 !important;
}
.orangy-tables-wrap .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #fef3c7 !important;
    color: #92400e !important;
    border-color: #fbbf24 !important;
}

/* --------------------------------------------------------------------------
   Merged cells (v1.0.5)
   Center-align merged cells vertically; borders stay intact.
   -------------------------------------------------------------------------- */
.orangy-tables-wrap table.orangy-tables td[rowspan],
.orangy-tables-wrap table.orangy-tables td[colspan] {
    vertical-align: middle;
    text-align: center;
}
.orangy-tables-wrap table.orangy-tables td[rowspan]:not([colspan]) {
    /* Rowspan-only cells (like a "Capacity" category label) look best
       with the text slightly bolder so the grouping reads at a glance. */
    font-weight: 600;
    background: #fafafa;
}
.theme-dark .orangy-tables-wrap table.orangy-tables td[rowspan]:not([colspan]),
.orangy-tables-wrap .theme-dark table.orangy-tables td[rowspan]:not([colspan]) {
    background: #1a2233;
}
