/* ==========================================================================
   Hedger Pro TIX ticket builder (standalone, no build).

   Extracted from wp-content/plugins/tix. All page styles are nested under #app
   (native CSS nesting) so they only touch the app root
   (<div class="tix-container" id="app">) and its descendants - never the shared
   header (#hp-ext-header) or the page frame. Shared layers load first:
     - lib/theme.css      :root tokens (--font, palette, sizes, ...)
     - lib/page-frame.css body backdrop + centred .hp-page column
     - lib/ui.css         base #app typography
     - lib/icons.css      Font Awesome 5

   Neutral greys/whites/borders/text are sourced from the shared palette so a
   change at :root cascades here. TIX brand + semantic colours (the #007cba
   action blue, the success/secondary button gradients, back/lay odds colours,
   the cadetblue link and the error banner) are kept literal on purpose.
   ========================================================================== */

:root {
    /* Type: pull the family from the shared theme; keep the TIX size scale. */
    --tix-font-family: var(--font);
    --tix-font-size: 14px;
    --tix-font-weight: 400;
    --tix-font-header-size: 24px;
    --tix-font-header-weight: 600;
}

/* Mobile fade (keyframes can't be nested, so it stays at the top level). */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

#app {
    &, & table th, & table td {
        font-family: var(--tix-font-family);
        font-size: var(--tix-font-size);
        padding: 1px;
    }

    & table th {
        font-weight: 500;
    }

    &.tix-container {
        margin: 0 auto;
        padding: 20px 0;
        background: var(--white);
        border-radius: 4px;
        font-family: var(--tix-font-family);
        width: 1000px;
    }

    .tix-header {
        display: flex;
        align-items: center;
    }

    .fa-link {
        font-size: 20px;
        margin: 0 0 0 10px;
        color: cadetblue;
    }

    .tix-header h2 {
        margin: 0;
        padding: 0;
        color: var(--gray-darker);
        font-size: var(--tix-font-header-size);
        font-weight: var(--tix-font-header-weight);
    }

    .tix-controls {
        display: flex;
        gap: 10px;
    }

    /* ---- Buttons ------------------------------------------------------- */
    .btn {
        padding: 8px 16px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: var(--tix-font-size);
        transition: all 0.3s ease;
        border: 1px solid var(--gray-bright);
        background: #e34040;
        color: var(--white);
        font-weight: var(--tix-font-header-weight);
        text-transform: uppercase;
    }

    .btn-primary {
        background: #007cba;
        color: var(--white);
    }

    .btn-primary:hover:not(:disabled) {
        background: #005a87;
    }

    .btn-primary:disabled {
        background: var(--gray-light);
        cursor: not-allowed;
    }

    .btn-secondary {
        background: var(--white);
        color: var(--gray-dark);
        border: 1px solid var(--gray-bright);
        font-weight: 500;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    }

    .btn-secondary:hover {
        background: var(--gray-brightest);
        border-color: #007cba;
        color: #007cba;
        box-shadow: 0 2px 4px rgba(0, 124, 186, 0.15);
        transform: translateY(-1px);
    }

    .btn-secondary:active {
        transform: translateY(0);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }

    .btn-success {
        background: #28a745;
        color: var(--white);
    }

    .btn-success:hover:not(:disabled) {
        background: #218838;
    }

    .btn-success:disabled {
        background: var(--gray-light);
        cursor: not-allowed;
    }

    /* ---- States -------------------------------------------------------- */
    .tix-error {
        background: #f8d7da;
        color: #721c24;
        padding: 6px;
        border-radius: 4px;
        margin: 4px auto;
        border: 1px solid #f5c6cb;
        max-height: 100px;
        overflow: auto;
        max-width: 800px;
    }

    .tix-loading,
    .tix-empty {
        text-align: center;
        padding: 40px;
        color: var(--gray-dark);
        font-size: var(--tix-font-size);
    }

    /* ---- Two-column layout --------------------------------------------- */
    .tix-main-content {
        display: flex;
        gap: 10px;
        margin-top: 10px;
        flex: 1;
        min-height: 0;
        width: 100%;
    }

    .tix-shortlists-column {
        background: var(--gray-brightest);
        border-radius: 4px;
        padding: 10px;
        font-family: var(--tix-font-family);
        display: flex;
        flex-direction: column;
        min-height: 0;
        width: 300px;
    }

    .tix-shortlists-column .tix-controls {
        width: 100%;
        justify-content: space-between;
        margin: 0 0 7px 0;
        gap: 5px;
    }

    .tix-shortlists-column .tix-controls .btn {
        flex: 1;
        min-width: 0;
        padding: 10px 12px;
        font-size: 12px;
    }

    .tix-controls .btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .tix-controls .btn i {
        font-size: var(--tix-font-size);
        flex-shrink: 0;
    }

    .tix-controls .btn .fa-spinner {
        margin-right: 6px;
    }

    .tix-qualifiers-column {
        background: var(--white);
        border: 1px solid var(--gray-bright);
        border-radius: 4px;
        padding: 6px;
        font-family: var(--tix-font-family);
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .tix-summary {
        background: var(--white);
        padding: 10px 15px;
        border-radius: 3px;
        margin-bottom: 10px;
        font-weight: 500;
        color: var(--gray-dark);
        border: 1px solid var(--gray-bright);
        flex-shrink: 0;
    }

    .tix-list-compact {
        display: flex;
        flex-direction: column;
        gap: 2px;
        overflow-y: auto;
        flex: 1;
    }

    .tix-item-compact {
        display: flex;
        align-items: center;
        padding: 6px;
        border: 1px solid var(--gray-bright);
        border-radius: 3px;
        transition: all 0.3s ease;
        background: var(--white);
        cursor: pointer;
    }

    .tix-item-compact:hover {
        border-color: #007cba;
        box-shadow: 0 1px 4px rgba(0, 124, 186, 0.1);
    }

    .tix-item-compact.selected {
        border-color: #007cba;
        background: #f8f9ff;
    }

    /* ---- Checkbox ------------------------------------------------------ */
    .tix-checkbox {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    .tix-list-compact .tix-checkbox {
        margin: 0 8px 0 0;
    }

    .tix-checkbox input[type="checkbox"] {
        display: none;
    }

    .checkmark {
        width: 20px;
        height: 20px;
        border: 2px solid var(--gray-lightest);
        border-radius: 3px;
        position: relative;
        transition: all 0.3s ease;
    }

    .tix-checkbox input[type="checkbox"]:checked + .checkmark {
        background: #007cba;
        border-color: #007cba;
    }

    .tix-checkbox input[type="checkbox"]:checked + .checkmark::after {
        content: '';
        position: absolute;
        left: 6px;
        top: 2px;
        width: 6px;
        height: 10px;
        border: solid white;
        border-width: 0 2px 2px 0;
        transform: rotate(45deg);
    }

    .tix-content-compact {
        flex: 1;
        display: flex;
        justify-content: space-between;
    }

    .tix-name-compact {
        font-weight: 500;
        color: var(--gray-darker);
        font-size: var(--tix-font-size);
        line-height: 1.3;
    }

    .tix-side-compact {
        color: var(--gray-dark);
        font-size: var(--tix-font-size);
        font-style: italic;
    }

    /* ---- Qualifiers ---------------------------------------------------- */
    .tix-qualifiers-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 10px;
        border-bottom: 2px solid var(--gray-brighter);
        flex-shrink: 0;
    }

    .tix-qualifiers-header h3 {
        margin: 0;
        color: var(--gray-darker);
        font-size: var(--tix-font-header-size);
    }

    .tix-qualifiers-count {
        background: #007cba;
        color: var(--white);
        padding: 4px 12px;
        border-radius: 12px;
        font-size: var(--tix-font-size);
        font-weight: 500;
    }

    /* ---- Qualifiers table ---------------------------------------------- */
    .tix-qualifiers-table-container {
        border: 1px solid var(--gray-bright);
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: auto;
    }

    .tix-qualifiers-table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        background: var(--white);
        font-size: var(--tix-font-size);
        font-family: var(--tix-font-family);
        min-height: 0;
    }

    .tix-qualifiers-table thead {
        background: var(--gray-brightest);
        z-index: 10;
    }

    .tix-qualifiers-table thead tr {
        display: table-row;
        width: 100%;
    }

    .tix-qualifiers-product-table tr {
        height: 42px;
    }

    .tix-qualifiers-product-table thead tr th {
        background-color: var(--gray-brighter);
    }

    table .center {
        text-align: center;
    }

    table .left {
        text-align: left;
    }

    table .right {
        text-align: right;
    }

    .tix-qualifiers-table th {
        padding: 10px 8px;
        font-weight: var(--tix-font-header-weight);
        color: var(--gray-dark);
        font-size: var(--tix-font-size);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .tix-qualifiers-table td {
        padding: 4px;
        border-bottom: 1px solid var(--gray-brighter);
        vertical-align: middle;
        font-size: var(--tix-font-size);
        font-weight: 500;
    }

    .tix-qualifier-row:hover {
        background: #f8f9ff;
    }

    .tix-qualifier-row:hover td {
        border-bottom-color: #007cba;
    }

    /* ---- Column-specific cells ----------------------------------------- */
    .tix-time-cell {
        color: #007cba;
        white-space: nowrap;
        width: 60px;
        font-variant-numeric: tabular-nums;
    }

    .tix-course-cell {
        color: var(--gray-dark);
        white-space: nowrap;
        width: 100px;
    }

    .tix-checkbox-cell {
        text-align: center;
        width: 30px;
    }

    .tix-number-cell {
        text-align: center;
        width: 30px;
    }

    .runner-number {
        background: #007cba;
        color: var(--white);
        width: 26px;
        height: 24px;
        border-radius: 3px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-variant-numeric: tabular-nums;
    }

    .tix-silk-cell {
        text-align: center;
        width: 40px;
    }

    .silk-image-small {
        padding: 1px;
        width: 34px;
        margin-top: 4px;
    }

    .tix-runner-cell {
        color: var(--gray-darker);
        min-width: 120px;
    }

    .tix-back-cell {
        text-align: center;
        color: #285ca7;
        width: 60px;
        font-variant-numeric: tabular-nums;
    }

    .tix-lay-cell {
        text-align: center;
        color: #dc35b1;
        width: 60px;
        font-variant-numeric: tabular-nums;
    }

    /* ---- Tabs ---------------------------------------------------------- */
    .tix-tabs-container {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .tix-tabs {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        margin-bottom: 8px;
        gap: 7px;
    }

    .tix-tab {
        background: var(--gray-brightest);
        border: 1px solid var(--gray-bright);
        padding: 8px;
        cursor: pointer;
        font-size: var(--tix-font-size);
        font-weight: var(--tix-font-header-weight);
        color: var(--gray-dark);
        border-radius: 3px;
        transition: all 0.2s ease;
        white-space: nowrap;
        text-transform: uppercase;
        flex: 1;
    }

    .tix-tab:hover {
        background: var(--gray-bright);
        color: var(--black);
    }

    .tix-tab.active {
        background: #007cba;
        color: var(--white);
        border-color: #007bff;
        position: relative;
        z-index: 1;
    }

    .tix-tab-content {
        flex: 1;
        overflow: auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .tix-meeting-content {
        padding: 0;
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow: auto;
    }

    .tix-meeting-actions {
        padding: 0 0 8px 0;
        background: var(--white);
        position: sticky;
        top: 0px;
        z-index: 1000;
    }

    .tix-meeting-check-controls {
        display: flex;
        gap: 8px;
        margin-bottom: 8px;
        display: none;
    }

    .btn-check-all,
    .btn-check-none {
        flex: 1;
        padding: 9px 16px;
        border: none;
        border-radius: 3px;
        cursor: pointer;
        font-size: var(--tix-font-size);
        font-weight: var(--tix-font-header-weight);
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .btn-check-all {
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        color: white;
        box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
    }

    .btn-check-all:hover {
        background: linear-gradient(135deg, #218838 0%, #1aa179 100%);
        box-shadow: 0 4px 8px rgba(40, 167, 69, 0.4);
        transform: translateY(-1px);
    }

    .btn-check-all:active {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
    }

    .btn-check-none {
        background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
        color: white;
        box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
    }

    .btn-check-none:hover {
        background: linear-gradient(135deg, #5a6268 0%, #495057 100%);
        box-shadow: 0 4px 8px rgba(108, 117, 125, 0.4);
        transform: translateY(-1px);
    }

    .btn-check-none:active {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
    }

    .btn-check-all i,
    .btn-check-none i {
        font-size: 14px;
    }

    /* ---- Shortlists column buttons ------------------------------------- */
    .btn-select-all,
    .btn-select-none,
    .btn-refresh {
        padding: 10px 12px;
        border: none;
        border-radius: 3px;
        cursor: pointer;
        font-size: var(--tix-font-size);
        font-weight: var(--tix-font-header-weight);
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .btn-select-all {
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        color: white;
        box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
    }

    .btn-select-all:hover {
        background: linear-gradient(135deg, #218838 0%, #1aa179 100%);
        box-shadow: 0 4px 8px rgba(40, 167, 69, 0.4);
        transform: translateY(-1px);
    }

    .btn-select-all:active {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
    }

    .btn-select-none {
        background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
        color: white;
        box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
    }

    .btn-select-none:hover {
        background: linear-gradient(135deg, #5a6268 0%, #495057 100%);
        box-shadow: 0 4px 8px rgba(108, 117, 125, 0.4);
        transform: translateY(-1px);
    }

    .btn-select-none:active {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
    }

    .btn-refresh {
        background: linear-gradient(135deg, #007cba 0%, #0056b3 100%);
        color: white;
        box-shadow: 0 2px 4px rgba(0, 124, 186, 0.3);
    }

    .btn-refresh:hover:not(:disabled) {
        background: linear-gradient(135deg, #005a87 0%, #004085 100%);
        box-shadow: 0 4px 8px rgba(0, 124, 186, 0.4);
        transform: translateY(-1px);
    }

    .btn-refresh:active:not(:disabled) {
        transform: translateY(0);
        box-shadow: 0 2px 4px rgba(0, 124, 186, 0.3);
    }

    .btn-refresh:disabled {
        background: var(--gray-light);
        color: var(--gray-dark);
        cursor: not-allowed;
        box-shadow: none;
        transform: none;
    }

    .btn-select-all i,
    .btn-select-none i,
    .btn-refresh i {
        font-size: 14px;
    }

    /* ---- Race sections ------------------------------------------------- */
    .tix-race-section {
        margin-bottom: 10px;
        border: 1px solid var(--gray-bright);
        border-radius: 4px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    .tix-race-header {
        background: var(--gray-brightest);
        margin: 0;
        padding: 12px 15px;
        font-size: var(--tix-font-size);
        font-weight: var(--tix-font-header-weight);
        color: var(--gray-dark);
        border-bottom: 1px solid var(--gray-bright);
    }

    .tix-race-count {
        font-size: var(--tix-font-size);
        font-weight: 400;
        color: var(--gray-mid);
        margin-left: 8px;
    }

    .tix-empty-race {
        padding: 20px;
        text-align: center;
        color: var(--gray-mid);
        font-style: italic;
    }

    .tix-race-cell {
        text-align: center;
        font-weight: var(--tix-font-header-weight);
        color: #007bff;
    }

    .tix-race-section .tix-qualifiers-table-container {
        flex: 1;
        overflow: hidden;
        min-height: 0;
        max-height: 100%;
    }

    .tix-race-section .tix-qualifiers-table thead {
        z-index: 5;
    }

    .tix-race-section .tix-qualifiers-table thead tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    /* ---- Scrollbars ---------------------------------------------------- */
    .tix-qualifiers-table tbody::-webkit-scrollbar,
    .tix-tab-content::-webkit-scrollbar {
        width: 8px;
    }

    .tix-qualifiers-table tbody::-webkit-scrollbar-track,
    .tix-tab-content::-webkit-scrollbar-track {
        background: var(--gray-brighter);
        border-radius: 4px;
    }

    .tix-qualifiers-table tbody::-webkit-scrollbar-thumb,
    .tix-tab-content::-webkit-scrollbar-thumb {
        background: var(--gray-lightest);
        border-radius: 4px;
    }

    .tix-qualifiers-table tbody::-webkit-scrollbar-thumb:hover,
    .tix-tab-content::-webkit-scrollbar-thumb:hover {
        background: var(--gray-light);
    }

    /* ---- Bet type tabs ------------------------------------------------- */
    .tix-bet-type-tabs-container {
        margin-bottom: 7px;
        display: flex;
    }

    .tix-bet-type-tabs {
        display: flex;
        gap: 6px;
        flex: 1;
        flex-wrap: wrap;
    }

    .tix-bet-type-tab {
        padding: 7px;
        background: var(--white);
        border-radius: 4px;
        cursor: pointer;
        font-weight: var(--tix-font-header-weight);
        font-size: var(--tix-font-size);
        color: var(--gray-dark);
        transition: all 0.2s ease;
        min-width: 120px;
        text-align: center;
        border: 1px solid var(--gray-bright);
    }

    .tix-bet-type-tab:hover {
        background: var(--gray-brightest);
        border-color: #007bff;
        color: #007bff;
    }

    .tix-bet-type-tab.active {
        background: #007cba;
        border-color: #007cba;
        color: var(--white);
        box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
    }

    .tix-bet-type-tab .count {
        font-size: var(--tix-font-size);
        opacity: 0.8;
        margin-left: 4px;
    }

    /* ---- Responsive visibility (desktop defaults) ---------------------- */
    .tix-mobile-element {
        display: none !important;
    }

    .tix-desktop-element {
        display: flex;
    }

    .tix-desktop-element-table-cell {
        display: table-cell;
    }

    @media (max-width: 1000px) {
        .tix-mobile-element {
            display: flex !important;
        }

        .tix-desktop-element,
        .tix-summary {
            display: none;
        }

        .tix-desktop-element-table-cell {
            display: none;
        }

        .tix-bet-type-tabs {
            justify-content: space-between;
        }

        .tix-bet-type-tab {
            flex: 1;
        }

        .send-all-button {
            width: 100%;
        }

        .tix-mobile-tabs {
            display: flex;
            background: var(--gray-brightest);
            border-radius: 8px;
            margin-bottom: 10px;
            padding: 4px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .tix-mobile-tab {
            flex: 1;
            padding: 8px;
            text-align: center;
            background: transparent;
            border: none;
            border-radius: 6px;
            font-weight: 600;
            transition: all 0.3s ease;
            cursor: pointer;
            text-transform: uppercase;
        }

        .tix-mobile-tab.active {
            background: #007cba;
            color: var(--white);
            box-shadow: 0 2px 4px rgba(0, 124, 186, 0.3);
        }

        .tix-mobile-tab:not(.active):hover {
            background: var(--gray-bright);
            color: var(--gray-dark);
        }

        .tix-shortlists-column.tix-mobile-active,
        .tix-qualifiers-column.tix-mobile-active {
            display: flex;
            animation: fadeIn 0.3s ease-in-out;
            width: 100%;
            padding: 0px;
            border: none;
        }

        &.tix-container {
            display: flex;
            padding: 10px;
            width: 100%;
            min-width: 400px;
            max-width: 600px;
        }

        .tix-main-content {
            flex-direction: column;
            width: 100%;
            gap: 0;
            margin-top: 0;
        }

        .tix-header {
            border: none;
            margin: 0;
            padding: 0;
            text-align: center;
            justify-content: center;
        }

        .tix-header h2,
        .fa-link {
            text-align: center;
            font-size: 17px;
        }

        .tix-header .tix-controls {
            justify-content: center;
            flex-wrap: wrap;
            display: none;
        }
    }
}
