/* --- Theme Variables --- */
:root {
    /* Main brand colors */
    --pf-gold: #f4874c;
    --pf-title: #7a3c00;
    --pf-source: #4c2c91;
    --pf-secondary: #666;

    /* Derived colors - fixed values for better compatibility and performance */
    --pf-gold-dark: #c96a36;
    --pf-gold-hover: #ff9b66;
    --pf-gold-hover-dark: #ffb185;
    --pf-title-dark: #f4b942;
    --pf-source-dark: #d1b2ff;
    --pf-title-light: #7a3c00;
    --pf-source-light: #4c2c91;

    /* Table head and border colors */
    --pf-table-head-light: #f8f9fa;
    --pf-table-head-dark: #23272b;
    --pf-table-head-border-light: #dee2e6;
    --pf-table-head-border-dark: #343a40;
    --pf-table-head-color-light: #212529;
    --pf-table-head-color-dark: #f8f9fa;
}

[data-bs-theme="light"] {
    --bs-primary: var(--pf-gold);
    --bs-btn-primary-bg: var(--pf-gold);
    --bs-btn-primary-border-color: var(--pf-gold);
    --bs-btn-primary-hover-bg: var(--pf-gold-hover);
    --bs-btn-primary-hover-border-color: var(--pf-gold-hover);
    --bs-btn-primary-active-bg: var(--pf-gold-hover);
    --bs-btn-primary-active-border-color: var(--pf-gold-hover);
    --bs-btn-primary-color: #222;
    --pf-title: var(--pf-title-light);
    --pf-source: var(--pf-source-light);
    --pf-table-head-bg: var(--pf-table-head-light);
    --pf-table-head-color: var(--pf-table-head-color-light);
    --pf-table-head-border: var(--pf-table-head-border-light);
}

[data-bs-theme="dark"] {
    --bs-primary: var(--pf-gold-dark);
    --bs-btn-primary-bg: var(--pf-gold-dark);
    --bs-btn-primary-border-color: var(--pf-gold-dark);
    --bs-btn-primary-hover-bg: var(--pf-gold-hover-dark);
    --bs-btn-primary-hover-border-color: var(--pf-gold-hover-dark);
    --bs-btn-primary-active-bg: var(--pf-gold-hover-dark);
    --bs-btn-primary-active-border-color: var(--pf-gold-hover-dark);
    --bs-btn-primary-color: #222;
    --pf-title: var(--pf-title-dark);
    --pf-source: var(--pf-source-dark);
    --pf-table-head-bg: var(--pf-table-head-dark);
    --pf-table-head-color: var(--pf-table-head-color-dark);
    --pf-table-head-border: var(--pf-table-head-border-dark);
}

/* --- Minimal, Flat, Clean Look --- */
.checkbox-matrix {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    font-size: 0.9rem;
    max-width: 110px;
    width: 100%;
}

.checkbox-matrix label {
    white-space: nowrap;
    font-weight: 400;
    font-size: 0.85rem;
    margin-bottom: 0.1rem;
}

@media (max-width: 991px) {
    .checkbox-matrix {
        max-width: 100% !important;
        gap: 0.15rem;
        align-items: flex-start;
    }

    .checkbox-matrix label {
        display: flex;
        align-items: center;
        width: auto;
        white-space: normal;
        text-align: left;
        gap: 0.5em;
        margin-bottom: 0;
    }

    .checkbox-matrix input[type="checkbox"] {
        margin-right: 0.5em;
        margin-left: 0;
    }
    .checkbox-matrix {
        margin-left: 1rem;
        width: calc(75vw - 2rem);
        max-width: 600px;
    }
}

/* --- Item Details --- */
.item-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 600;
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
    color: var(--pf-title);
    border-top: 3px solid var(--bs-primary);
    padding-top: 0.25rem;
}

.item-source {
    color: var(--pf-source);
    font-size: 0.95rem;
}

.item-type {
    font-style: italic;
    margin-bottom: 0.5rem;
    color: var(--pf-secondary);
}

.item-desc {
    background: var(--bs-tertiary-bg, #f8f9fa);
    padding: 0.5rem 1rem;
    margin-top: 0.5rem;
    font-size: 0.96rem;
    line-height: 1.5;
    border-bottom: 3px solid var(--bs-primary);
    border-radius: 0.25rem;
}

.item-desc h5 {
    font-size: 1.08rem;
    margin-top: 1.1em;
    margin-bottom: 0.4em;
}

.item-desc ul,
.item-desc ol {
    font-size: 0.95em;
}

/* --- Copyable --- */
.copyable {
    cursor: pointer;
    border-bottom: 1px dashed var(--bs-link-color, #0d6efd);
    display: inline-block;
    transition: background 0.2s;
    padding: 0 2px;
}

.copyable:hover {
    background: var(--bs-border-color, #dee2e6);
}

.copy-toast {
    position: absolute;
    background: #222;
    color: #fff;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 10000;
}

/* --- Details Panel --- */
#details {
    min-width: 340px;
    max-width: 600px;
    margin-right: 1rem;
    padding: 1rem;
    background: var(--bs-tertiary-bg, #f8f9fa);
    border-left: 1px solid var(--bs-border-color, #dee2e6);
    height: fit-content;
    position: sticky;
    top: 0.625rem;
    max-height: calc(65vh - 250px);
    overflow-y: auto;
    border-radius: 0.5rem;
    box-sizing: border-box;
    display: block;
}

@media (min-width: 992px) {
    .row {
        display: flex;
        flex-wrap: nowrap;
    }

    #tableWrapper {
        flex: 1 1 0%;
        min-width: 0;
    }

    #details {
        flex: 0 0 370px;
        min-width: 340px;
        max-width: 600px;
        margin-left: 1.5rem;
        margin-top: 0;
        position: sticky;
        top: 0.625rem;
    }
}

@media (max-width: 1200px) {
    #details {
        min-width: 280px;
    }
}

@media (max-width: 991px) {
    #details {
        min-width: 100% !important;
        max-width: 100% !important;
        margin-left: 0;
        border-left: none;
        border-top: 1px solid var(--bs-border-color, #dee2e6);
        margin-top: 1rem;
        position: relative;
        top: auto;
    }
}

/* --- Filters --- */
.filters {
    background: var(--bs-tertiary-bg, #f8f9fa);
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    padding: 0.5rem 0.25rem 0.25rem 0.25rem;
    /* border-radius: 0.5rem; */
    /* margin-bottom: 1rem; */
    font-size: 0.92rem;
}

.filters .form-label,
.filters label {
    font-size: 0.85rem;
    margin-bottom: 0.1rem;
}

.filters .form-control,
.filters .form-select {
    font-size: 0.85rem;
    padding: 0.12rem 0.4rem;
    min-height: 1.4rem;
}

.filters .col-md-2 {
    max-width: 170px;
    min-width: 120px;
    flex: 0 0 14.2857%;
    padding-right: 0.5rem;
}

@media (max-width: 991px) {
    .filters {
        flex-direction: column !important;
        display: flex !important;
        align-items: stretch !important;
    }

    .filters .col-md-2 {
        max-width: 100%;
        min-width: 0;
        flex: 1 1 100%;
        width: 100%;
        margin-bottom: 0.5rem;
        padding-right: 0;
    }

    .filters .form-label {
        display: block;
        text-align: center;
        width: 100%;
        margin-bottom: 0.25rem;
        font-weight: 600;
    }
}

/* --- Mobile Filter Panel Tweaks --- */
@media (max-width: 575.98px) {
    .filters form.row {
        display: block !important;
        padding: 0.5rem 0.2rem;
    }
    .filters .col-md-2 {
        margin-bottom: 0.5rem;
        padding: 0.2rem 0;
        border-bottom: 1px solid #eee;
    }
    .filters .col-md-2:last-child {
        border-bottom: none;
    }
    .filters label.form-label {
        font-size: 0.95em;
        margin-bottom: 0.1em;
        font-weight: 600;
    }
    .filters input.form-control,
    .filters select.form-select {
        font-size: 0.95em;
        padding: 0.18em 0.5em;
        min-height: 1.8em;
        margin-bottom: 0.2em;
    }
    .checkbox-matrix {
        max-width: 100% !important;
        gap: 0.1rem;
        font-size: 0.95em;
    }
}

/* Remove filter section borders on mobile */
@media (max-width: 575.98px) {
    .filters .col-md-2 {
        /* border-bottom: 1px solid #eee; */ /* Remove or comment out this line */
        border-bottom: none !important;
    }
}

/* Instantly show/hide the filter collapse on mobile (no animation) */
@media (max-width: 991px) {
    #mobileFilters.collapse,
    #mobileFilters.collapsing {
        transition: none !important;
        height: auto !important;
    }
}

/* Always show filters on desktop, regardless of collapse state */
@media (min-width: 992px) {
    #mobileFilters.collapse {
        display: block !important;
        height: auto !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* --- Table --- */
.table {
    font-size: 0.75rem;
}

.table th,
.table td {
    padding: 0.18rem 0.3rem;
    vertical-align: middle;
}

.table th:not(.action-col) {
    cursor: pointer;
}

.table > :not(caption) > * > * {
    background: none;
    border-bottom-width: 1px;
}

tr.item-row {
    cursor: pointer;
    transition: background 0.15s;
}

tr.item-row:hover {
    background: var(--bs-secondary-bg, #f1f3f5);
    color: var(--bs-body-color, #111);
}

.table th[data-col="0"],
.table td:nth-child(2),
.table th[data-col="1"],
.table td:nth-child(3) {
    white-space: nowrap;
}

.selected-row,
tr.item-row:hover.selected-row,
tr.selected-row:hover {
    background: grey !important;
}

.table thead th,
.table-light th {
    background-color: var(--pf-table-head-bg) !important;
    color: var(--pf-table-head-color) !important;
    border-color: var(--pf-table-head-border) !important;
}

/* --- Responsive Table --- */
.table-responsive-custom {
    overflow-x: auto !important;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

#tableWrapper {
    width: 100vw !important;
    max-width: 100vw !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
}

.table-responsive-custom table {
    min-width: 100% !important;
    width: max-content;
}

html,
body {
    overflow-x: hidden !important;
}
.row,
#tableWrapper,
.table-responsive-custom {
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box;
}
/* .table-responsive-custom{overflow-x:hidden!important;} */
.sticky-table-scrollbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 22px;
    background: var(--bs-body-bg, #fff);
    z-index: 1050;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.07);
    display: block !important;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100vw;
}
.sticky-table-scrollbar > div {
    height: 1px;
}

/* --- Cart/Buttons --- */
#cart-count {
    font-size: 0.65rem !important;
    min-width: 1.1em !important;
    padding: 0.15em 0.4em !important;
    line-height: 1;
}

#cartModal .modal-body {
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

.cart-qty,
.cart-base,
.cart-custom-name {
    max-width: 60px;
    min-width: 40px;
    display: inline-block;
}

.cart-custom-name {
    max-width: 100px;
    min-width: 60px;
}

.action-col {
    width: 7.8rem;
    min-width: 7.8rem;
}

.cart-btn,
.theme-btn {
    font-size: 1.5rem;
}

.cart-count {
    font-size: 0.8rem;
    min-width: 1.5em;
}

.btn-primary,
.btn-primary:active,
.btn-primary:focus,
.btn-primary:visited {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #222 !important;
}

.btn-primary:hover,
.btn-primary:active:hover,
.btn-primary:focus:hover {
    background-color: var(--bs-btn-primary-hover-bg) !important;
    border-color: var(--bs-btn-primary-hover-border-color) !important;
    color: #222 !important;
}

/* --- Disabled Add to Cart Button --- */
.btn.disabled,
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn.disabled:hover,
.btn:disabled:hover {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #222 !important;
}

/* --- Misc --- */
a {
    color: var(--bs-link-color, #0d6efd);
    text-decoration: underline;
}

input.form-control,
select.form-select {
    min-height: 2.25rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    padding: 0.375rem 0.75rem;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #111);
    border: 1px solid var(--bs-border-color, #dee2e6);
    box-shadow: none;
    transition: border-color 0.2s;
    /* No margin or width here for desktop */
}

@media (max-width: 991px) {
    input.form-control,
    select.form-select {
        margin-left: 1rem;
        margin-right: 1rem;
        width: 75vw;
        max-width: 600px;
        display: block;
        margin-right: auto;
        margin-left: auto;
    }
}

/* --- Return to Top Button --- */
#return-to-top-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1050;
    display: none;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
    border-radius: 2rem;
    font-size: 1rem;
    padding: 0.5rem 1.2rem;
    opacity: 0.92;
    transition: opacity 0.2s, background 0.2s;
}

#return-to-top-btn:hover {
    opacity: 1;
    background: var(--bs-primary-dark, #0a58ca);
}

/* --- Tag Colors --- */
.parsed-5etools-tag,
.parsed-BatchedJson-tag {
    color: #ff9800;
    font-weight: bold;
}

/* --- Item Details Modal Tweaks --- */
#itemDetailsModal .modal-content {
    margin: 0 auto !important;
    border-radius: 0.5rem;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.18);
    width: 100%;
    max-width: 600px;
}

#itemDetailsModal .modal-body {
    padding: 1rem !important;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0 auto !important; /* Center the body if it has a width */
    font-size: 0.97rem;
}

#itemDetailsModal .item-desc {
    max-width: 100%;
    overflow-x: auto;
    padding: 0.5rem 0.75rem;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

#itemDetailsModal table {
    width: 100% !important;
    table-layout: fixed;
    word-break: break-word;
}

#itemDetailsModal th,
#itemDetailsModal td {
    white-space: normal !important;
    word-break: break-word;
    overflow-wrap: break-word;
}

#itemDetailsModal .modal-dialog {
    top: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

#itemDetailsModal .modal-content {
    margin: 0 auto !important;
    border-radius: 0.5rem;
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.18);
    width: 100%;
    max-width: 600px;
}

/* --- Details Panel Table --- */
#details .item-desc {
    max-height: none;
    overflow: visible;
}

#details .item-desc table {
    width: 100%;
    table-layout: fixed;
}

#details .item-desc table th,
#details .item-desc table td {
    white-space: normal !important;
    word-break: break-word;
}

/* --- Mobile Tweaks --- */
@media (max-width: 575.98px) {
    html,
    body {
        overflow-x: hidden !important;
    }

    .filters,
    .navbar,
    .container,
    .container-fluid,
    .row,
    #tableWrapper {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .filters {
        border-radius: 0 !important;
    }

    input.form-control,
    select.form-select {
        margin-left: 1rem;
        margin-right: 1rem;
        width: 75vw;
        max-width: 600px;
        display: block;
        margin-right: auto;
        margin-left: auto;
    }
}

html {
    will-change: background-color, color;
    backface-visibility: hidden;
}

/* --- Sticky Header --- */
header.navbar,
.navbar {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    width: 100vw;
    min-width: 100vw;
    max-width: 100vw;
    z-index: 2000;
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}
body {
    padding-top: 70px; /* adjust to your header height */
}

.item-notes {
    background: #fffbe6;
    color: #7a3c00;
    border-left: 5px solid var(--pf-gold, #f4874c);
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    font-size: 1.05rem;
    font-weight: 500;
    border-radius: 0.25rem;
    box-shadow: 0 1px 4px rgba(244, 135, 76, 0.08);
    display: flex;
    align-items: center;
    gap: 0.5em;
}
[data-bs-theme="dark"] .item-notes {
    background: #2a1a00;
    color: #ffb185;
    border-left: 5px solid var(--pf-gold-dark, #c96a36);
}

.pf-green-check {
    color: green !important;
}

/* --- Help Modal Styles --- */
.help-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.help-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.help-section h6 {
    color: var(--bs-primary);
    font-weight: 600;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.help-section p {
    margin-bottom: 0.5rem;
    color: var(--bs-body-color);
}

.help-section ol,
.help-section ul {
    margin-bottom: 0.5rem;
    padding-left: 1.25rem;
}

.help-section li {
    margin-bottom: 0.25rem;
    line-height: 1.4;
}

.help-section code {
    background-color: var(--bs-secondary-bg);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.9em;
    color: var(--bs-emphasis-color);
}

.help-section .alert {
    font-size: 0.9rem;
}

#helpModal .modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

#helpModal .modal-dialog {
    max-height: 80vh;
}

#helpModal .modal-content {
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

#helpModal .modal-title {
    color: var(--bs-primary);
}

/* Prevent background scroll when help modal is open */
body.modal-open {
    overflow: hidden;
}
