/* Encounter explorer — scoped to .ee-page */

/*
 * scrollbar-gutter: stable on html reserves space when the main scrollbar
 * toggles. Avoid 100vw in this file — it ignores the scrollbar and causes
 * horizontal reflow when content height crosses the viewport.
 */
html {
    scrollbar-gutter: stable;
}

body.dm-tools-tool-body {
    scrollbar-gutter: stable;
    overflow-x: clip;
}

.ee-page {
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    overflow-x: clip;
    box-sizing: border-box;
}

.ee-page > .header {
    text-align: left;
    margin-bottom: 1.5rem;
}

.ee-page .title {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    text-align: left;
}

.ee-lead {
    color: var(--mg-gray);
    line-height: 1.55;
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    text-align: left;
    max-width: 52rem;
}

.ee-status {
    padding: 1rem 1.25rem;
    border: 1px dashed var(--mg-gray-light);
    border-radius: 12px;
    color: var(--mg-gray);
    background: #fff;
    margin-bottom: 1.5rem;
}

.ee-status[data-state="error"] {
    border-color: var(--mg-red);
    color: var(--mg-red);
    background: #fff6f8;
}

/* ----- Three-column grid ----- */
/* minmax(0, Nfr) so tracks size purely by available space and never by content.
   This keeps the columns from jittering when monsters are added/removed. */
.ee-grid {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr);
    gap: 1.25rem;
    align-items: start;
    min-width: 0;
}

@media (max-width: 1100px) {
    .ee-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
    .ee-col-browser {
        grid-column: 1 / -1;
    }
}

@media (max-width: 720px) {
    .ee-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    .ee-col-browser {
        grid-column: auto;
    }
}

.ee-col {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* Inline-size container so dropdown sizing can use cqw (column width), not 100vw. */
.ee-col-browser {
    container-type: inline-size;
    container-name: ee-browser;
    min-width: 0;
    width: 100%;
    overflow-x: clip;
}

/* ----- Cards ----- */
.ee-card {
    border: 1px solid var(--mg-gray-light);
    border-radius: 12px;
    padding: 1rem 1.1rem 1.1rem;
    background: #fff;
}

.ee-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}

.ee-card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--mg-black);
    margin: 0 0 0.75rem;
    letter-spacing: -0.01em;
}

.ee-card-head .ee-card-title {
    margin-bottom: 0;
}

/* ----- Buttons ----- */
.ee-btn {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--mg-gray-light);
    background: #fff;
    color: var(--mg-black);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ee-btn:hover:not(:disabled) {
    border-color: var(--mg-green);
    color: var(--mg-green);
}

.ee-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ee-btn-ghost {
    background: transparent;
}

.ee-btn-small {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

.ee-btn-primary {
    background: var(--mg-green);
    color: #fff;
    border-color: var(--mg-green);
}

.ee-btn-primary:hover:not(:disabled) {
    background: var(--mg-green-dark);
    border-color: var(--mg-green-dark);
    color: #fff;
}

/* ----- Party rows ----- */
.ee-party-rows {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.ee-party-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.5rem;
    align-items: center;
}

.ee-party-row select,
.ee-party-row input[type="number"] {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--mg-gray-light);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--mg-black);
    background: #fff;
}

.ee-party-row select:focus,
.ee-party-row input:focus {
    outline: 2px solid var(--mg-green);
    outline-offset: 1px;
    border-color: var(--mg-green);
}

.ee-party-remove {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--mg-gray-light);
    background: #fff;
    color: var(--mg-gray);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.ee-party-remove:hover {
    color: var(--mg-red);
    border-color: var(--mg-red);
}

.ee-stepper {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.ee-stepper button {
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border-radius: 6px;
    border: 1px solid var(--mg-gray-light);
    background: #fff;
    color: var(--mg-black);
    font-size: 1rem;
    cursor: pointer;
    line-height: 1;
}

.ee-stepper button:hover:not(:disabled) {
    border-color: var(--mg-green);
    color: var(--mg-green);
}

.ee-stepper button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ee-stepper-value {
    min-width: 1.7rem;
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ----- Budget card ----- */
.ee-budget-list {
    list-style: none;
    padding: 0;
    margin: 0 0 0.9rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
}

.ee-budget-list li {
    border: 1px solid var(--mg-gray-light);
    border-radius: 8px;
    padding: 0.45rem 0.5rem;
    text-align: center;
    background: #fff;
    margin: 0;
}

.ee-budget-list li[data-selected="true"] {
    border-color: var(--mg-green);
    background: #e6f4f5;
}

.ee-budget-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--mg-gray);
    font-weight: 500;
}

.ee-budget-xp {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--mg-black);
    font-variant-numeric: tabular-nums;
}

.ee-budget-math {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin: 0;
    font-size: 0.85rem;
}

.ee-budget-math > div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
}

.ee-budget-math dt {
    color: var(--mg-gray);
}

.ee-budget-math dd {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--mg-black);
}

.ee-budget-remaining dd {
    font-size: 1rem;
}

.ee-budget-remaining[data-over="true"] dd {
    color: var(--mg-red);
}

.ee-realized {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--mg-gray-light);
}

.ee-realized-label {
    font-size: 0.85rem;
    color: var(--mg-gray);
}

.ee-realized-pill {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--mg-gray-light);
    color: var(--mg-black);
}

.ee-realized-pill[data-level="trivial"] {
    background: var(--mg-gray-light);
    color: var(--mg-gray);
}

.ee-realized-pill[data-level="low"] {
    background: #d9f0ef;
    color: var(--mg-green-dark);
}

.ee-realized-pill[data-level="moderate"] {
    background: #fef1d6;
    color: #a86b1a;
}

.ee-realized-pill[data-level="high"] {
    background: #fadbca;
    color: #b0531d;
}

.ee-realized-pill[data-level="lethal"] {
    background: #f5c9d4;
    color: #923253;
}

/* ----- Current encounter picks ----- */
.ee-col-picks {
    /* Grid item default min-width:auto can use content min-size; lock so fr tracks stay stable. */
    min-width: 0;
    width: 100%;
}

.ee-col-picks .ee-card {
    width: 100%;
    min-width: 0;
}

.ee-picks {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    width: 100%;
    min-width: 0;
}

.ee-pick {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 0.6rem;
    row-gap: 0.35rem;
    align-items: center;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--mg-gray-light);
    border-radius: 8px;
    background: #fafcf0;
    min-width: 0;
    box-sizing: border-box;
}

.ee-pick-name {
    grid-column: 1;
    grid-row: 1;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--mg-black);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.ee-pick .ee-stepper {
    grid-column: 2;
    grid-row: 1;
}

.ee-pick-meta-row {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem 0.75rem;
    min-width: 0;
}

.ee-pick-meta {
    font-size: 0.78rem;
    color: var(--mg-gray);
    font-variant-numeric: tabular-nums;
    flex: 1 1 auto;
    min-width: 0;
}

.ee-pick-subtotal {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    max-width: 100%;
}

/* Empty state uses the same grid as .ee-pick (name | stepper slot + meta row). */
.ee-pick--empty {
    border-style: dashed;
}

.ee-pick--empty .ee-pick-name {
    color: var(--mg-gray);
    font-weight: 500;
    white-space: normal;
}

/* Reserves the same horizontal space as a real − / n / + stepper in this column. */
.ee-pick-stepper-slot {
    grid-column: 2;
    grid-row: 1;
    width: 6.75rem;
    min-width: 6.75rem;
    box-sizing: border-box;
}

/* ----- Monster browser ----- */
.ee-browser-card {
    padding-bottom: 0.85rem;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.ee-browser-head {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding-bottom: 0.85rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--mg-gray-light);
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.ee-browser-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 0.75rem;
    min-width: 0;
    width: 100%;
}

.ee-browser-search-main {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--mg-gray-light);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--mg-black);
    background: #fff;
}

.ee-browser-search-main:focus {
    outline: 2px solid var(--mg-green);
    outline-offset: 1px;
    border-color: var(--mg-green);
}

.ee-browser-sort {
    flex: 0 0 auto;
    min-width: 6.5rem;
}

.ee-filter-dropdown {
    flex: 0 0 auto;
    position: relative;
}

.ee-filter-dropdown > summary {
    list-style: none;
}

.ee-filter-dropdown > summary::-webkit-details-marker {
    display: none;
}

.ee-filter-dropdown-summary {
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--mg-gray-light);
    background: #fff;
    color: var(--mg-black);
    transition: border-color 0.15s ease, color 0.15s ease;
}

.ee-filter-dropdown-summary:hover {
    border-color: var(--mg-green);
    color: var(--mg-green);
}

.ee-filter-dropdown[open] > .ee-filter-dropdown-summary {
    border-color: var(--mg-green);
    color: var(--mg-green);
}

.ee-filter-dropdown-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    z-index: 30;
    width: 22rem;
    padding: 0.75rem 0.85rem 0.85rem;
    background: #fff;
    border: 1px solid var(--mg-gray-light);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(23, 51, 63, 0.12);
    box-sizing: border-box;
}

@supports (width: 1cqw) {
    .ee-filter-dropdown-panel {
        width: min(22rem, 100cqw);
        min-width: min(17rem, 100cqw);
    }
}


.ee-filter-dropdown-panel .ee-filter-row {
    display: grid;
    gap: 0.5rem;
    min-width: 0;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ee-filter {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: var(--mg-gray);
    font-weight: 500;
}

.ee-filter-grow {
    grid-column: span 2;
}

@media (max-width: 600px) {
    .ee-filter-grow {
        grid-column: auto;
    }
}

/* Habitat stays full width inside the 2-col filter dropdown. */
.ee-filter-dropdown-panel .ee-filter-grow {
    grid-column: span 2;
}

.ee-filter select,
.ee-filter input {
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--mg-gray-light);
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--mg-black);
    background: #fff;
}

.ee-filter select:focus,
.ee-filter input:focus {
    outline: 2px solid var(--mg-green);
    outline-offset: 1px;
    border-color: var(--mg-green);
}

.ee-filter-dropdown-budget {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--mg-gray-light);
    font-size: 0.8rem;
    color: var(--mg-gray);
    cursor: pointer;
    line-height: 1.4;
}

.ee-filter-dropdown-panel .ee-filter-actions {
    margin-top: 0.65rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--mg-gray-light);
}

.ee-filter-actions {
    display: flex;
    justify-content: flex-end;
}

.ee-browser-meta {
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: var(--mg-gray);
    min-width: 0;
}

/* Inline spans ignore min-width — use a fixed slot so result counts don’t reflow the grid when typing. */
.ee-browser-count-strip {
    display: block;
    box-sizing: border-box;
    width: min(100%, 52ch);
    max-width: 100%;
    font-variant-numeric: tabular-nums;
    white-space: normal;
    word-break: break-word;
}

.ee-budget-toggle {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.35rem;
    cursor: pointer;
    max-width: 100%;
}

.ee-monster-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 720px;
    /* scroll (not auto) keeps scrollbar track width stable when row count changes */
    overflow-y: scroll;
    overflow-x: hidden;
    overflow-x: clip;
    scrollbar-gutter: stable;
    min-width: 0;
    min-height: 0;
}

.ee-monster {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem 0.75rem;
    align-items: center;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--mg-gray-light);
    border-radius: 8px;
    background: #fff;
    transition: border-color 0.1s ease, background 0.1s ease;
    min-width: 0;
}

.ee-monster:hover {
    border-color: var(--mg-green);
    background: #f7fbfb;
}

.ee-monster-main {
    min-width: 0;
}

.ee-monster-name {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--mg-black);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ee-monster-sub {
    display: flex;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--mg-gray);
    margin-top: 0.15rem;
    flex-wrap: wrap;
}

.ee-monster-sub .ee-chip {
    font-variant-numeric: tabular-nums;
}

.ee-chip {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: var(--mg-gray-light);
    color: var(--mg-gray);
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
}

.ee-chip-cr {
    background: #e6f4f5;
    color: var(--mg-green-dark);
}

.ee-chip-xp {
    background: #fef1d6;
    color: #8c571c;
}

.ee-chip-legendary {
    background: #f5c9d4;
    color: #923253;
}

.ee-monster-actions {
    justify-self: end;
    /* Fixed slot: rows always use − / n / + (no Add ↔ stepper swap). */
    width: 7rem;
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

/* First + (count 0) uses primary styling so “add” is still obvious. */
.ee-stepper-monster .ee-stepper-plus-first {
    background: var(--mg-green);
    border-color: var(--mg-green);
    color: #fff;
}

.ee-stepper-monster .ee-stepper-plus-first:hover:not(:disabled) {
    background: var(--mg-green-dark);
    border-color: var(--mg-green-dark);
    color: #fff;
}

.ee-monster-empty {
    padding: 1.5rem 0.75rem;
    border: 1px dashed var(--mg-gray-light);
    border-radius: 10px;
    color: var(--mg-gray);
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.5;
}

.ee-load-more {
    margin-top: 0.75rem;
    width: 100%;
}
