.tag-management { min-inline-size: 0; padding-block: 1.5rem 3rem; }
.tm-page-header { display: flex; align-items: center; justify-content: space-between; gap: 2rem; margin-block-end: 1.25rem; padding-block-end: 1rem; border-block-end: 1px solid var(--line); }
.tm-page-header h1 { flex: none; margin: 0; font-size: 1.5rem; }
.tm-page-actions { display: flex; align-items: center; justify-content: flex-end; gap: .75rem; flex: 1; min-inline-size: 0; }
.tm-page-actions button { flex: none; block-size: 2.25rem; min-height: 2.25rem; padding: .375rem .875rem; font-size: .8125rem; white-space: nowrap; }
.tm-search { flex: 0 1 22rem; min-inline-size: 10rem; }
.tm-search input { inline-size: 100%; min-inline-size: 0; block-size: 2.25rem; padding: .4rem .65rem; border: 1px solid var(--line); border-radius: .375rem; background: var(--surface); color: var(--ink); font-size: .8125rem; }
.tm-status { margin: 0 0 .75rem; color: var(--muted); font-size: .8125rem; }
.tm-status[data-error="true"], .tm-form-error { color: var(--error); }
.tm-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 1.5rem; }
.tm-type { min-inline-size: 0; }
.tm-type-header, .tm-type-header > div { display: flex; align-items: center; gap: .5rem; }
.tm-type-header { justify-content: space-between; margin-block-end: .75rem; }
.tm-type-header > div:first-child { flex: 1; min-inline-size: 0; }
.tm-type-header h2 { min-inline-size: 0; margin: 0; font-size: .875rem; line-height: 1.5; }
.tm-toggle { display: flex; align-items: center; gap: .5rem; inline-size: 100%; min-inline-size: 0; min-height: 2rem; padding: 0; border: 0; border-radius: .25rem; background: transparent; color: var(--ce-tag-light-text, var(--ink)); font: inherit; font-weight: 700; text-align: start; cursor: pointer; }
.tm-type-icon { display: grid; place-items: center; flex: none; inline-size: 1.5rem; block-size: 1.5rem; border-radius: .375rem; background: var(--ce-tag-light-background, var(--subtle)); }
.tm-type-icon svg { inline-size: 1rem; block-size: 1rem; }
.tm-type-name { min-inline-size: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tm-toggle-chevron { flex: none; inline-size: .875rem; block-size: .875rem; }
.tm-toggle[aria-expanded="false"] .tm-toggle-chevron { rotate: -90deg; }
.tm-toggle:hover .tm-type-name { text-decoration: underline; text-underline-offset: .2em; }
.tm-toggle:disabled { cursor: default; opacity: .5; }
html[data-theme="dark"] .tm-toggle { color: var(--ce-tag-dark-text, var(--ink)); }
html[data-theme="dark"] .tm-type-icon { background: var(--ce-tag-dark-background, var(--subtle)); }
.tm-type-count { flex: none; font-size: .6875rem; color: var(--muted); white-space: nowrap; }
.tm-type-actions { flex: none; }
.tm-type-actions button { display: inline-flex; align-items: center; gap: .25rem; min-height: 1.875rem; padding: .25rem .5rem; font-size: .75rem; white-space: nowrap; }
.tm-type-actions svg { inline-size: 1rem; block-size: 1rem; }
.tm-type table { inline-size: 100%; table-layout: fixed; border-collapse: collapse; background: var(--surface); font-size: .8125rem; line-height: 1.5; }
.tm-name-column { inline-size: 26%; }
.tm-count-column { inline-size: 3.5rem; }
.tm-actions-column { inline-size: 5.5rem; }
.tm-type th, .tm-type td { min-inline-size: 0; padding: .375rem .5rem; text-align: start; border-block-end: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.tm-type thead th { padding-block: .5rem; color: var(--muted); background: var(--subtle); font-size: .6875rem; font-weight: 500; border-block-start: 1px solid var(--line); }
.tm-type tbody th { font-weight: 500; }
.tm-type .tm-number { text-align: end; font-variant-numeric: tabular-nums; }
.tm-term { display: inline-block; max-inline-size: 100%; padding: .0625rem .375rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; vertical-align: middle; font-size: .75rem; }
.tm-description { color: var(--muted); }
.tm-description > span { display: block; min-inline-size: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tm-row-actions { display: flex; align-items: center; gap: .5rem; }
.tm-row-actions button { flex: none; padding: .125rem 0; min-height: 1.5rem; border: 0; background: transparent; color: var(--ink); font-size: .75rem; white-space: nowrap; }
.tm-row-actions button:hover { color: var(--accent); }
html[data-theme] .tm-danger { color: var(--error); }
.tm-empty { padding: 2rem 1rem !important; color: var(--muted); text-align: center !important; font-size: .875rem; }
.tm-dialog { inline-size: 31rem; max-inline-size: calc(100vw - 4rem); max-block-size: calc(100vh - 4rem); box-sizing: border-box; padding: 1.5rem; border: 1px solid var(--line); border-radius: .75rem; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); overflow: auto; }
.tm-dialog:modal { overscroll-behavior: contain; }
.tm-dialog::backdrop { background: #080b1466; overflow: hidden; overscroll-behavior: contain; }
.tm-dialog > header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-end: 1.5rem; }
.tm-dialog h2 { margin: 0; font-size: 1.125rem; }
.tm-dialog .icon-button { display: grid; place-items: center; min-height: 2rem; inline-size: 2rem; block-size: 2rem; padding: .375rem; border: 0; background: transparent; color: var(--muted); }
.tm-field { display: grid; gap: .5rem; margin-block-end: 1.25rem; }
.tm-field label, .tm-color-fields legend, .tm-color-inputs label { color: var(--ink); font-size: .8125rem; font-weight: 500; }
.tm-field input, .tm-field textarea, .tm-field select { inline-size: 100%; box-sizing: border-box; font: inherit; font-size: .875rem; }
.tm-field textarea { min-block-size: 6rem; resize: vertical; padding: .625rem .75rem; border: 1px solid var(--line); border-radius: .375rem; background: var(--surface); color: var(--ink); line-height: 1.7; }
.tm-description-tools { display: flex; align-items: center; gap: .75rem; }
.tm-description-tools button { min-height: 2rem; padding: .375rem .625rem; font-size: .8125rem; }
.tm-description-tools [data-tm-optimize] { color: var(--accent); }
.tm-description-undo { border: 0; background: transparent; color: var(--muted); }
.tm-optimize-status { min-block-size: 1.6em; margin: 0; color: var(--muted); font-size: .75rem; line-height: 1.6; }
.tm-optimize-status[data-error="true"] { color: var(--error); }
.tm-color-fields { min-inline-size: 0; padding: 0; border: 0; margin: 0 0 1.25rem; }
.tm-color-fields legend { padding: 0; margin-block-end: .75rem; }
.tm-color-inputs { display: grid; grid-template-columns: 6rem 1fr; gap: 1rem; }
.tm-color-inputs > div { display: grid; gap: .5rem; }
.tm-color-inputs input[type="color"] { inline-size: 100%; block-size: 2.5rem; box-sizing: border-box; padding: .25rem; cursor: pointer; }
.tm-color-inputs input[name="hex"] { inline-size: 100%; font-family: "Cascadia Mono", Consolas, monospace; }
.tm-color-fields p, .tm-dialog-note { margin: .75rem 0; color: var(--muted); font-size: .8125rem; line-height: 1.7; }
.tm-preview { display: flex; align-items: center; gap: .75rem; margin-block-start: 1rem; color: var(--muted); font-size: .8125rem; }
.tm-preview .ce-tag { padding: .2rem .5rem; overflow-wrap: anywhere; }
.tm-delete-copy { font-size: .875rem; line-height: 1.8; overflow-wrap: anywhere; }
.tm-form-error { min-block-size: 1.5em; font-size: .8125rem; line-height: 1.6; margin: .5rem 0 1rem; }
.tm-dialog footer { display: flex; align-items: center; justify-content: flex-end; gap: .75rem; }
.tm-dialog footer button { min-height: 2.25rem; font-size: .875rem; }
.tm-dialog .tm-type-delete { margin-inline-end: auto; border: 0; background: transparent; padding-inline: 0; }
.tm-dialog .tm-type-delete:disabled { opacity: .45; }
html[data-theme] .tm-delete-submit { background: var(--error); color: white; border: 1px solid var(--error); }
html[data-theme] :is(.tm-dialog, .tag-management) :is(input, textarea):focus-visible { outline: none; outline-offset: 0; box-shadow: none; border-color: var(--ink); }
.tm-dialog :is(button, select):focus-visible, .tag-management button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (forced-colors: active) {
  .tm-dialog, .tm-term, .tm-type-icon { color: CanvasText; background: Canvas; border: 1px solid CanvasText; }
  html[data-theme] .tm-toggle { color: ButtonText; }
  html[data-theme] :is(.tm-dialog, .tag-management) :is(input, textarea):focus-visible { outline: 2px solid Highlight; }
}
