/* Tessera module styling.
   Loaded globally from App.razor, following the same convention as
   loopdocs/template-editor.css. Every selector is prefixed `tsr-` so it cannot
   reach another module's markup. */

:root {
    --tsr-border: #e5e7eb;
    --tsr-border-strong: #d1d5db;
    --tsr-muted: #6b7280;
    --tsr-head: #374151;
    --tsr-accent: #1b6ec2;
    --tsr-surface: #f9fafb;
    --tsr-hover: #f3f4f6;
}

/* ---------- toolbar above the table ---------- */

.tsr-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: .5rem;
    font-size: .8125rem;
    color: var(--tsr-muted);
}

.tsr-count {
    font-variant-numeric: tabular-nums;
}

.tsr-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .1rem .5rem;
    border: 1px solid var(--tsr-border);
    border-radius: 999px;
    background: #fff;
    font-size: .75rem;
    color: var(--tsr-head);
}

.tsr-chip-clear {
    border: 0;
    background: none;
    padding: 0;
    line-height: 1;
    color: var(--tsr-muted);
    cursor: pointer;
    font-size: .875rem;
}

.tsr-chip-clear:hover {
    color: #b02a37;
}

/* ---------- table shell ---------- */

.tsr-wrap {
    border: 1px solid var(--tsr-border);
    border-radius: .5rem;
    overflow: auto;
    background: #fff;
}

table.tsr-table {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .875rem;
}

/* ---------- header ---------- */

/* The label row is sticky so a long table keeps its column names while the
   filter row scrolls away with the data — filters are set once, column names
   are read constantly. */
.tsr-table thead tr.tsr-head-row th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--tsr-surface);
    padding: .5rem .625rem;
    border-bottom: 1px solid var(--tsr-border);
    white-space: nowrap;
    text-align: inherit;
}

/* A heading is a label that happens to be clickable, so it carries no button
   chrome at all — the affordance is the chevron and the hover colour. */
.tsr-sort {
    all: unset;
    display: inline-flex;
    align-items: baseline;
    gap: .3rem;
    cursor: pointer;
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--tsr-muted);
    transition: color .12s ease-in-out;
}

.tsr-sort:hover,
.tsr-sort:focus-visible {
    color: var(--tsr-accent);
}

.tsr-sort:focus-visible {
    outline: 2px solid rgba(27, 110, 194, .35);
    outline-offset: 2px;
    border-radius: 2px;
}

.tsr-head-static {
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--tsr-muted);
}

/* Reserve the arrow's width always, so labels do not shift sideways when a
   column becomes sorted. */
.tsr-arrow {
    display: inline-block;
    min-width: .6em;
    font-size: .625rem;
    opacity: 0;
    transition: opacity .12s ease-in-out;
}

.tsr-sort:hover .tsr-arrow {
    opacity: .4;
}

.tsr-sort.is-sorted {
    color: var(--tsr-accent);
}

.tsr-sort.is-sorted .tsr-arrow {
    opacity: 1;
}

.tsr-rank {
    font-size: .5625rem;
    font-weight: 700;
    color: #fff;
    background: var(--tsr-accent);
    border-radius: 999px;
    padding: 0 .3em;
    line-height: 1.4;
}

/* ---------- filter row ---------- */

.tsr-table thead tr.tsr-filter-row th {
    background: #fff;
    padding: .35rem .5rem .5rem;
    border-bottom: 2px solid var(--tsr-border-strong);
}

.tsr-filter {
    width: 100%;
    min-width: 5rem;
    border: 1px solid transparent;
    border-radius: .375rem;
    background: var(--tsr-surface);
    padding: .2rem .45rem;
    font-size: .75rem;
    font-weight: 400;
    color: var(--tsr-head);
    transition: border-color .12s ease-in-out, background-color .12s ease-in-out;
}

.tsr-filter::placeholder {
    color: #b6bcc6;
}

.tsr-filter:hover {
    border-color: var(--tsr-border);
}

.tsr-filter:focus {
    outline: none;
    background: #fff;
    border-color: var(--tsr-accent);
    box-shadow: 0 0 0 3px rgba(27, 110, 194, .12);
}

/* An active filter has to be obvious — otherwise an empty-looking table reads
   as missing data rather than a narrowed view. */
.tsr-filter.is-active {
    background: #fff;
    border-color: var(--tsr-accent);
}

/* ---------- body ---------- */

.tsr-table tbody td {
    padding: .45rem .625rem;
    border-bottom: 1px solid var(--tsr-border);
    vertical-align: middle;
}

.tsr-table tbody tr:last-child td {
    border-bottom: 0;
}

.tsr-table tbody tr:hover td {
    background: var(--tsr-hover);
}

.tsr-table tbody td a {
    text-decoration: none;
}

.tsr-table tbody td a:hover {
    text-decoration: underline;
}

.tsr-empty {
    padding: 1.5rem .625rem;
    text-align: center;
    color: var(--tsr-muted);
}

/* Numbers read wrong ragged; tabular figures keep the columns aligned. */
.tsr-table .text-end {
    font-variant-numeric: tabular-nums;
}

/* ---------- collapsible cards ---------- */

.tsr-card {
    border: 1px solid var(--tsr-border);
    border-radius: .5rem;
    background: #fff;
    margin-bottom: 1rem;
    overflow: hidden;
}

/* The whole header is the toggle, so it must not look like a button — it keeps
   card-header typography and only picks up a hover tint. */
.tsr-card-head {
    all: unset;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .625rem .875rem;
    cursor: pointer;
    background: var(--tsr-surface);
    transition: background-color .12s ease-in-out;
}

.tsr-card-head:hover {
    background: var(--tsr-hover);
}

.tsr-card-head:focus-visible {
    outline: 2px solid rgba(27, 110, 194, .35);
    outline-offset: -2px;
}

.tsr-card-title {
    font-size: .9375rem;
    font-weight: 600;
    color: var(--tsr-head);
}

.tsr-card-count {
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
    color: var(--tsr-muted);
    background: #fff;
    border: 1px solid var(--tsr-border);
    border-radius: 999px;
    padding: 0 .45rem;
}

.tsr-card-badge {
    font-size: .6875rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--tsr-muted);
    border: 1px solid var(--tsr-border-strong);
    border-radius: .25rem;
    padding: 0 .35rem;
}

/* Pushed right by margin rather than a spacer element, so the header stays one
   flat row of real content. */
.tsr-card-chevron {
    margin-left: auto;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--tsr-muted);
    transform: rotate(90deg);
    transition: transform .15s ease-in-out, color .12s ease-in-out;
}

.tsr-card-chevron.is-open {
    transform: rotate(-90deg);
}

.tsr-card-head:hover .tsr-card-chevron {
    color: var(--tsr-accent);
}

.tsr-card-body {
    padding: .875rem;
    border-top: 1px solid var(--tsr-border);
}

.tsr-card-body.is-collapsed {
    display: none;
}

/* ---------- variable model tree ---------- */

.tsr-tree {
    font-size: .8125rem;
    line-height: 1.4;
}

.tsr-tree-children {
    margin-left: .75rem;
    padding-left: .5rem;
    border-left: 1px solid var(--tsr-border);
}

.tsr-tree-row {
    display: flex;
    align-items: center;
    gap: .25rem;
    border-radius: 4px;
    padding: .1rem .25rem;
}

.tsr-tree-row:hover {
    background: var(--tsr-hover);
}

.tsr-tree-row.is-selected {
    background: #e7f1fb;
    box-shadow: inset 2px 0 0 var(--tsr-accent);
}

.tsr-tree-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: none;
    padding: .1rem 0;
    text-align: left;
    color: var(--tsr-head);
    cursor: pointer;
}

.tsr-tree-row.is-leaf .tsr-tree-label {
    color: #111827;
}

.tsr-tree-icon {
    color: var(--tsr-muted);
    width: .9rem;
    flex: none;
    text-align: center;
}

.tsr-tree-alias,
.tsr-tree-type {
    color: var(--tsr-muted);
    font-size: .6875rem;
}

.tsr-tree-count {
    margin-left: auto;
    color: var(--tsr-muted);
    font-size: .6875rem;
    font-variant-numeric: tabular-nums;
}

.tsr-tree-flag {
    color: var(--tsr-accent);
    font-weight: 600;
    font-size: .6875rem;
}

/* Kept out of the flow until the row is hovered or selected so a deep tree
   reads as structure rather than as a wall of buttons. */
.tsr-tree-actions {
    display: flex;
    gap: .15rem;
    flex: none;
    visibility: hidden;
}

.tsr-tree-row:hover .tsr-tree-actions,
.tsr-tree-row.is-selected .tsr-tree-actions {
    visibility: visible;
}

.tsr-tree-actions button {
    border: 1px solid var(--tsr-border);
    background: #fff;
    border-radius: 3px;
    padding: 0 .25rem;
    font-size: .6875rem;
    line-height: 1.3;
    color: var(--tsr-muted);
    cursor: pointer;
}

.tsr-tree-actions button:hover {
    color: var(--tsr-accent);
    border-color: var(--tsr-border-strong);
}

/* ---------- composite segment editor ---------- */

.tsr-seg-row {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .35rem;
}

.tsr-seg-index {
    flex: none;
    width: 1.25rem;
    color: var(--tsr-muted);
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
}

.tsr-preview {
    padding: .4rem .6rem;
    border: 1px dashed var(--tsr-border-strong);
    border-radius: 4px;
    background: var(--tsr-surface);
    font-family: var(--bs-font-monospace, monospace);
    font-size: .8125rem;
    word-break: break-all;
}

.tsr-preview .tsr-preview-slot {
    color: var(--tsr-accent);
}

/* ---------- save bar ---------- */

.tsr-savebar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: 1rem;
    padding: .5rem .75rem;
    border: 1px solid var(--tsr-border);
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 -2px 6px rgba(0, 0, 0, .05);
    font-size: .8125rem;
}

.tsr-savebar.is-busy {
    border-color: var(--tsr-accent);
}

.tsr-savebar-status {
    flex: 1 1 auto;
    color: var(--tsr-head);
}

/* ---------- search results ---------- */

.tsr-hits .list-group-item {
    padding: .55rem .75rem;
}

/* Key beside the title rather than under it — the title is what is read, the
   key is what is recognised. */
.tsr-hit-sub {
    color: var(--tsr-muted);
    font-size: .75rem;
    font-family: var(--bs-font-monospace, monospace);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tsr-hit-facts {
    display: flex;
    flex-wrap: wrap;
    gap: .15rem .9rem;
    margin-top: .2rem;
    font-size: .75rem;
    color: var(--tsr-head);
}

.tsr-hit-fact-label {
    color: var(--tsr-muted);
}

.tsr-hit-desc {
    margin-top: .15rem;
    font-size: .75rem;
    color: var(--tsr-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tsr-hit-tags {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    margin-top: .3rem;
}

/* ---------- occurrence arrived at from search ---------- */

.tsr-occ-highlight {
    background: #fff8e1;
    box-shadow: inset 3px 0 0 #f0ad4e;
}
