/* OWBN territory directory. Colors inherit from the page; borders are a neutral grey that reads on light and dark. */

.owbn-tm-directory {
    --owbn-tm-line: rgba(128, 128, 128, 0.4);
    --owbn-tm-soft: rgba(128, 128, 128, 0.12);
    --owbn-tm-tap: 44px;

    container: owbn-tm / inline-size;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    scroll-margin-top: 7rem;
}

.owbn-tm-directory *,
.owbn-tm-modal * {
    box-sizing: border-box;
}

.owbn-tm-directory [hidden],
.owbn-tm-modal[hidden] {
    display: none !important;
}

/* Controls */

.owbn-tm-directory .owbn-tm-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.75rem 1rem;
    align-items: end;
    margin: 0 0 1rem;
}

.owbn-tm-directory .owbn-tm-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.owbn-tm-directory .owbn-tm-field--sort {
    display: none;
}

.owbn-tm-directory .owbn-tm-field label {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
}

.owbn-tm-directory .owbn-tm-field input.owbn-tm-search,
.owbn-tm-directory .owbn-tm-field select {
    width: 100%;
    min-height: var(--owbn-tm-tap);
    margin: 0;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--owbn-tm-line);
    border-radius: 4px;
    font-size: 1rem;
    line-height: 1.3;
}

/* Buttons share one look; doubled classes keep a theme's own button rules from winning. */

.owbn-tm-directory .owbn-tm-button.owbn-tm-button,
.owbn-tm-modal .owbn-tm-button.owbn-tm-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--owbn-tm-tap);
    min-height: var(--owbn-tm-tap);
    margin: 0;
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--owbn-tm-line);
    border-radius: 4px;
    background: transparent;
    box-shadow: none;
    color: inherit;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    text-transform: none;
    cursor: pointer;
}

.owbn-tm-directory .owbn-tm-button.owbn-tm-button:hover,
.owbn-tm-directory .owbn-tm-button.owbn-tm-button:focus,
.owbn-tm-modal .owbn-tm-button.owbn-tm-button:hover,
.owbn-tm-modal .owbn-tm-button.owbn-tm-button:focus {
    background: var(--owbn-tm-soft);
    border-color: currentcolor;
    color: inherit;
}

.owbn-tm-directory .owbn-tm-button.owbn-tm-button:disabled {
    opacity: 0.45;
    cursor: default;
}

/* Table */

.owbn-tm-directory .owbn-tm-table {
    width: 100%;
    margin: 0;
    border: 0;
    border-collapse: collapse;
    table-layout: auto;
}

.owbn-tm-directory .owbn-tm-table > thead > tr > th,
.owbn-tm-directory .owbn-tm-table > tbody > tr > td {
    padding: 0.65rem 0.75rem;
    border: 0;
    border-bottom: 1px solid var(--owbn-tm-line);
    background: transparent;
    color: inherit;
    text-align: left;
    vertical-align: top;
}

.owbn-tm-directory .owbn-tm-table > thead > tr > th {
    padding: 0;
    border-bottom-width: 2px;
}

.owbn-tm-directory .owbn-tm-table > tbody > tr:hover > td {
    background: var(--owbn-tm-soft);
}

.owbn-tm-directory .owbn-tm-sort.owbn-tm-sort {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    min-height: var(--owbn-tm-tap);
    margin: 0;
    padding: 0.4rem 0.75rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: inherit;
    font-size: 1rem;
    font-weight: 700;
    text-align: left;
    text-transform: none;
    cursor: pointer;
}

.owbn-tm-directory .owbn-tm-sort.owbn-tm-sort:hover,
.owbn-tm-directory .owbn-tm-sort.owbn-tm-sort:focus {
    background: var(--owbn-tm-soft);
    color: inherit;
}

.owbn-tm-directory th[aria-sort="ascending"] .owbn-tm-sort::after {
    content: "\25B2";
    font-size: 0.7em;
}

.owbn-tm-directory th[aria-sort="descending"] .owbn-tm-sort::after {
    content: "\25BC";
    font-size: 0.7em;
}

.owbn-tm-directory .owbn-tm-cell--title {
    width: 62%;
}

.owbn-tm-directory .owbn-tm-open {
    display: inline-block;
    padding: 0.15rem 0;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.owbn-tm-directory .owbn-tm-muted,
.owbn-tm-modal .owbn-tm-muted {
    opacity: 0.7;
}

.owbn-tm-directory .owbn-tm-status {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
}

.owbn-tm-directory .owbn-tm-clear {
    justify-self: start;
}

/* Pager */

.owbn-tm-directory .owbn-tm-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1rem 0 0;
}

.owbn-tm-directory .owbn-tm-page {
    font-size: 0.9rem;
    text-align: center;
}

/* Phone: each row becomes a card, never a sideways scroll. */

@container owbn-tm (max-width: 40rem) {

    .owbn-tm-directory .owbn-tm-field--sort {
        display: flex;
    }

    .owbn-tm-directory .owbn-tm-table > thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .owbn-tm-directory .owbn-tm-table,
    .owbn-tm-directory .owbn-tm-table > tbody,
    .owbn-tm-directory .owbn-tm-table > tbody > tr,
    .owbn-tm-directory .owbn-tm-table > tbody > tr > td {
        display: block;
        width: 100%;
    }

    .owbn-tm-directory .owbn-tm-table > tbody > tr {
        margin: 0 0 0.75rem;
        padding: 0.6rem 0.75rem;
        border: 1px solid var(--owbn-tm-line);
        border-radius: 6px;
    }

    .owbn-tm-directory .owbn-tm-table > tbody > tr > td {
        padding: 0.2rem 0;
        border: 0;
        overflow-wrap: anywhere;
    }

    .owbn-tm-directory .owbn-tm-table > tbody > tr:hover > td {
        background: transparent;
    }

    .owbn-tm-directory .owbn-tm-cell--claimed::before {
        content: attr(data-label);
        display: block;
        font-size: 0.8rem;
        font-weight: 600;
        opacity: 0.7;
    }

    .owbn-tm-directory .owbn-tm-cell--title {
        width: 100%;
    }
}

/* Detail dialog, appended to the page body so no section of the theme can clip or stack over it. */

html.owbn-tm-modal-open {
    overflow: hidden;
}

.owbn-tm-modal {
    --owbn-tm-line: rgba(128, 128, 128, 0.4);
    --owbn-tm-soft: rgba(128, 128, 128, 0.12);
    --owbn-tm-tap: 44px;

    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.owbn-tm-modal .owbn-tm-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.owbn-tm-modal .owbn-tm-modal__panel {
    position: relative;
    width: min(42rem, 100%);
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding: 1.25rem 1.5rem 1.5rem;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    color: #1d2327;
    outline: none;
}

.owbn-tm-modal .owbn-tm-modal__close.owbn-tm-modal__close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--owbn-tm-tap);
    height: var(--owbn-tm-tap);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    box-shadow: none;
    color: inherit;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.owbn-tm-modal .owbn-tm-modal__close.owbn-tm-modal__close:hover,
.owbn-tm-modal .owbn-tm-modal__close.owbn-tm-modal__close:focus {
    background: var(--owbn-tm-soft);
    color: inherit;
}

.owbn-tm-modal .owbn-tm-modal__title {
    margin: 0 2.5rem 1rem 0;
    font-size: 1.35rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.owbn-tm-modal .owbn-tm-modal__subtitle {
    margin: 1.25rem 0 0.5rem;
    font-size: 1.05rem;
}

.owbn-tm-modal .owbn-tm-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.35rem 1rem;
    margin: 0;
}

.owbn-tm-modal .owbn-tm-facts dt {
    margin: 0;
    font-weight: 600;
}

.owbn-tm-modal .owbn-tm-facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.owbn-tm-modal .owbn-tm-prose {
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.owbn-tm-modal .owbn-tm-prose p {
    margin: 0 0 0.75rem;
}

.owbn-tm-modal .owbn-tm-modal__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 1.25rem 0 0;
}

.owbn-tm-modal .owbn-tm-copied {
    font-size: 0.9rem;
}

.owbn-tm-modal .owbn-tm-error {
    color: #b32d2e;
}

@media (max-width: 30rem) {

    .owbn-tm-modal {
        padding: 0.5rem;
    }

    .owbn-tm-modal .owbn-tm-modal__panel {
        max-height: calc(100vh - 1rem);
        max-height: calc(100dvh - 1rem);
        padding: 1rem;
    }

    .owbn-tm-modal .owbn-tm-facts {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .owbn-tm-modal .owbn-tm-facts dd {
        margin: 0 0 0.6rem;
    }
}
