/**
 * Page and component templates — template-* namespace.
 * Migrated from app.css; all layout/component selectors use template-page-* or template-component-*.
 */

/* ========== Page layout (template-page-*) ========== */

/* Wrapper for all page elements — constrains max-width in one place.
   Flex pass-through keeps the height chain intact from ot-content-body. */
.template-page-content {
    max-width: 1200px;
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.template-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    width: 100%;
}

.template-page-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
}

.template-page-toolbar .template-component-search-box,
.template-page-toolbar .search-box {
    width: 180px;
}

.template-page-toolbar .template-component-search-box .search-box-input,
.template-page-toolbar .search-box .search-box-input {
    height: 28px;
    min-height: 28px;
}

/* Left block: wraps either page title (Type 2) or view switcher (Type 1). Same position/layout. */
.template-page-header-left {
    margin: 0 1rem 0 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.template-page-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

/* View switcher container (Type 1) — same wrapping as title, inside template-page-header-left */
.template-page-view-group {
    display: inline-flex;
    align-items: stretch;
}

.template-page-view-group .ot-button-group {
    border-color: var(--border-color);
    border-radius: 8px;
}

.template-page-view-group .ot-button-group .ot-button:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.template-page-view-group .ot-button-group .ot-button:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

.template-page-view-group .ot-button-group .ot-button:not(:last-child) {
    border-right-color: var(--border-color);
}

/* Body: tabulator list pages */
.template-page-body-tabulator {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.ot-content-body.ot-no-scroll .template-page-body-tabulator {
    flex: 1;
    min-height: 0;
    height: auto;
    max-height: none;
}

/* Body: card-only pages */
.template-page-body-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

/* ========== Component: card (template-component-card) ========== */

.template-component-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Override: remove max-height or max-width (e.g. for cards that need to grow or full width). */
.template-component-card.template-component-card--no-max-height {
    max-height: none;
}

.template-component-card.template-component-card--no-max-width {
    max-width: none;
}

.template-component-card-title {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.9375rem;
    border-bottom: 1px solid var(--border-color);
    background: #fafafa;
}

.template-component-card-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem 1rem;
    min-width: 0;
}

.template-component-card-title-text {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-component-card-title-buttons {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.template-component-card-title-buttons .template-component-filter-chip {
    padding: 0.125rem 0.375rem;
    font-size: 0.6875rem;
    border-radius: 6px;
    gap: 0.1rem;
}
.template-component-card-title-buttons .template-component-filter-chip button {
    width: 14px;
    min-width: 14px;
    height: 14px;
    min-height: 14px;
    margin-left: 0.15rem;
}

/* Icon button styles provided by .ot-icon-button (app.css) */

.template-component-card-body {
    padding: 1rem;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.template-component-card-body ul > li {
    margin: 0;
}

/* Card stack: container and stack layout (body-cards pages) */
.template-component-card-stack-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    max-width: 1200px;
    margin: 0.5rem 0;
}

.template-component-card-stack-container > .template-component-card-stack {
    width: 100%;
    margin: 0.5rem 0;
}

.template-component-card-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}

/* Stack modifiers: .template-component-card-stack--client-row, .template-component-card-stack--contacts (mobile overrides in mobile.css) */

/* Card-grid-entry: flex item that grows to fill the row. Inline flex-basis + min-width
   (from Core.cardGrid) set the wrap breakpoint; flex-grow distributes remaining space
   equally; max-width caps growth. Cards stretch to the tallest in their row. */
.template-component-card-stack > .card-grid-entry {
    flex-grow: 1;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}
.template-component-card-stack > .card-grid-entry > .template-component-card {
    flex: 1 1 auto;
}

/* Legacy: direct card children (pages not yet using card-grid-entry wrappers) */
.template-component-card-stack > .template-component-card {
    flex: 1 1 300px;
    min-width: 300px;
}

.template-component-card-stack > .template-component-card.template-component-card--fit-content {
    flex: 0 0 auto;
    width: max-content;
    min-width: 300px;
}

/* Card modifier: never shrink below content so nothing is clipped */
.template-component-card-stack > .template-component-card.template-component-card--no-clip {
    flex-shrink: 0;
    min-width: max-content;
}

/* Optional: icon before title text (e.g. Client Detail) */
.template-component-card-title-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    margin-right: -0.5rem;
}

/* Card body columns: data-cols="1" | "2" | "3"; stacks to 1 on mobile (see mobile.css) */
.template-component-card-body[data-cols="1"] {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.template-component-card-body[data-cols="2"] {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.template-component-card-body[data-cols="3"] {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.template-component-card-body[data-cols="2"] > *,
.template-component-card-body[data-cols="3"] > * {
    min-width: 0;
}

/* Card column: direct child of card-body when using data-cols */
.template-component-card-col {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Card field: label (icon or text) and value; icon aligns with first line of text */
.template-component-card-field {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    min-height: 1.5rem;
}

.template-component-card-field-label {
    flex-shrink: 0;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: right;
}

.template-component-card-field-label span[class^="icon-"] {
    margin-top: 4px;
}

.template-component-card-field-value {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
}

.template-component-card-field-value .sor-method-select {
    font-size: 0.8125rem;
    padding: 2px 20px 2px 4px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 4px center;
    background-size: 12px 12px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    width: auto;
    min-width: 6rem;
    field-sizing: content;
}

/* Address block: icon on first line only; values left-aligned */
.template-component-card-address-block .template-component-card-field-label {
    width: 1.25rem;
    min-width: 1.25rem;
}

.template-component-card-address-block .template-component-card-field-label .icon-home {
    display: block;
}

/* ========== Filter in card (template-component-card-filter) ========== */
/* Filter button (icon only) + badge in card title; no chips; dropdown with options. */

.template-component-card-filter {
    display: inline-flex;
    align-items: center;
}

.template-component-card-filter .template-component-card-filter-btn {
    position: relative;
}

/* Tight padding for card bodies inside stack (e.g. Client Summary) */

.template-component-card-stack-container .template-component-card-body > .client-summary-stats-content {
    padding: 0;
}

/* Variant: summary chart card — clickable, max height, hover/focus */
.template-component-card--summary-chart {
    max-height: 425px;
    cursor: pointer;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.template-component-card--summary-chart:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: #c0c0c0;
}

.template-component-card--summary-chart:focus {
    outline: 2px solid var(--primary-hover);
    outline-offset: 2px;
}

/* Variant: summary stats card — fit content width, stretch to row height */
.template-component-card-stack-container .template-component-card--summary-stats {
    max-width: 280px;
    align-self: stretch;
    max-height: none;
}

.template-component-card--summary-stats .template-component-card-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Variant: scrollable body — flex column so inner content can scroll (Suicide Risk, Alerts) */
.template-component-card.template-component-card--scroll-body {
    display: flex;
    flex-direction: column;
    max-height: 425px;
}

.template-component-card.template-component-card--scroll-body .template-component-card-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 !important;
}

#clientAlertsCard.template-component-card--scroll-body {
    min-height: 320px;
}

#clientAlertsCard.template-component-card--scroll-body .template-component-card-body {
    padding: 0.25rem !important;
}

/* ========== Tabulator inside card (template-component-card--tabulator) ========== */
/* Card that contains a tabulator: no body padding so tabulator fills the space. */

.template-component-card.template-component-card--tabulator {
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.template-component-card.template-component-card--tabulator .template-component-card-body {
    padding: 0;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Wrapper for the tabulator instance — fills available card body space. */
.template-component-card-tabulator-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
}

.template-component-card-tabulator-wrap .ot-tabulator-wrap,
.template-component-card-tabulator-wrap .ot-tabulator-container {
    flex: 1;
    min-height: 0;
}

/* ========== Series card tabs ========== */

.series-card-tabs {
    display: flex;
    flex-shrink: 0;
    gap: 0;
    border-bottom: 1px solid var(--border-color);
    padding: 0 12px;
    overflow-x: auto;
}

.series-card-tab {
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    background: none;
    border: none;
    border-radius: 0;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.series-card-tab:hover {
    color: var(--text-color);
}

.series-card-tab--active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* No outside borders — card provides the border. */
.template-component-card-tabulator-wrap .ot-tabulator-container {
    border: none !important;
}

.template-component-card-tabulator-wrap .tabulator {
    border: none !important;
    border-radius: 0 !important;
}

/* Compact header: minimal padding/margins; no border-radius. */
.template-component-card-tabulator-wrap .tabulator-header .tabulator-col {
    padding: 0.25rem 0.5rem;
    padding-right: 1.25rem;
    border-radius: 0;
}

.template-component-card-tabulator-wrap .tabulator-header .tabulator-col-content,
.template-component-card-tabulator-wrap .tabulator-header .tabulator-col-title {
    padding: 0;
}

/* Prevent header from compressing when card has max-height; only table body should scroll. */
.template-component-card-tabulator-wrap .tabulator-header {
    flex-shrink: 0;
    min-height: 2.25rem;
}

/* Compact cells to match. */
.template-component-card-tabulator-wrap .tabulator-row .tabulator-cell {
    padding: 0.35rem 0.5rem;
}

/* ========== Settings: event handler rows ========== */

.settings-integration-row {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}
.settings-integration-row:last-child { border-bottom: none; }
.settings-integration-header { display: flex; align-items: center; justify-content: space-between; }
.settings-integration-name { font-weight: 600; font-size: 0.875rem; }
.settings-integration-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.settings-integration-status { display: inline-flex; align-items: center; height: 20px; }
.settings-integration-detail { display: flex; flex-direction: column; gap: 0.15rem; margin-top: 0.15rem; }
.settings-integration-desc { font-size: 0.8rem; color: var(--text-muted); }
.settings-integration-options { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.15rem; }

/* Card list section header (reusable) */
.template-component-card-list-section-header { background: #f5f5f5 !important; cursor: default !important; }
.template-component-card-list-section-title { font-weight: 600; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.settings-nt-template-row { display: flex !important; align-items: center; justify-content: space-between; gap: 0.75rem; }
.settings-nt-template-name { font-weight: 600; font-size: 0.875rem; flex-shrink: 0; }
.settings-nt-template-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; justify-content: flex-end; }

/* Core: Rich text editor (Core.richEditor) */
.core-rte-wrap { border: 1px solid var(--border-color); border-radius: 4px; overflow: hidden; }
.core-rte-toolbar {
    display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
    padding: 4px 6px; background: #f5f5f5; border-bottom: 1px solid var(--border-color);
}
.core-rte-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 28px; height: 26px; padding: 0 6px;
    border: 1px solid transparent; border-radius: 3px; background: none;
    font-size: 0.75rem; color: var(--text-color); cursor: pointer;
}
.core-rte-btn:hover { background: #e0e0e0; }
.core-rte-btn--active { background: #d0d0d0; border-color: #bbb; }
.core-rte-sep { width: 1px; height: 18px; background: #d0d0d0; margin: 0 3px; }
.core-rte-size { min-width: 24px; padding: 0 3px; line-height: 1; }
.core-rte-heading { font-size: 0.6875rem; font-weight: 700; min-width: 26px; padding: 0 4px; }
.core-rte-body {
    min-height: 200px; max-height: 400px; overflow-y: auto;
    padding: 10px 12px; font-size: 1rem; line-height: 1.6;
    outline: none;
}
.core-rte-body:focus { box-shadow: inset 0 0 0 1px var(--primary-color); }
.core-rte-source {
    width: 100%; border: none; resize: vertical;
    padding: 10px 12px; font-family: monospace; font-size: 0.8125rem;
    min-height: 200px; outline: none; box-sizing: border-box;
}
.core-rte-source:focus { box-shadow: inset 0 0 0 1px var(--primary-color); }
.core-rte-insert { position: relative; margin-left: auto; }
.core-rte-insert-trigger {
    display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
    padding: 3px 10px; border: 1px solid var(--border-color); border-radius: 3px;
    background: #fff; font-size: 0.75rem; color: var(--text-color); cursor: pointer;
}
.core-rte-insert-trigger:hover { background: #f0f0f0; }
.core-rte-insert-arrow { display: inline-block; width: 14px; height: 14px; vertical-align: middle; }
.core-rte-insert-menu {
    display: none; position: fixed; z-index: 9999;
    min-width: 180px; max-height: 240px; overflow-y: auto;
    background: #fff; border: 1px solid var(--border-color); border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.core-rte-insert-menu.show { display: block; }
.core-rte-insert-option {
    display: block; width: 100%; padding: 6px 12px; border: none; background: none;
    text-align: left; font-size: 0.8125rem; color: var(--text-color); cursor: pointer;
    white-space: nowrap;
}
.core-rte-insert-option:hover { background: var(--primary-light); }

/* ========== Component: filter group (template-component-filter-group) ========== */

.template-component-filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    overflow: visible;
}

/* Only the filter group/chips with --visible are shown (Type 1: one of two; Type 2: single one has --visible) */
.template-component-filter-group:not(.template-component-filter-group--visible) {
    display: none;
}
.template-component-filter-group.template-component-filter-group--visible {
    display: inline-flex;
}

/* Filter chips */
.template-component-filter-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.15rem;
}
.template-component-filter-chips:not(.template-component-filter-group--visible) {
    display: none;
}
.template-component-filter-chips.template-component-filter-group--visible {
    display: inline-flex;
}

.template-component-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.25rem 0.5rem;
    background: var(--primary-light);
    border: 1px solid #2196f3;
    border-radius: 8px;
    color: var(--primary-hover);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-right: 0.15rem;
}

.template-component-filter-chip:hover {
    background: #bbdefb;
    border-color: var(--primary-hover);
}

.template-component-filter-chip span {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-component-filter-chip button {
    background: var(--primary-light);
    border: none;
    color: var(--primary-hover);
    cursor: pointer;
    padding: 0 !important;
    margin-left: 0.25rem;
    width: 16px;
    min-width: 16px;
    height: 16px;
    min-height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    box-sizing: border-box;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.template-component-filter-chip-remove .icon-close {
    flex-shrink: 0;
}

.template-component-filter-chip-remove:hover {
    background: var(--danger-color);
    color: white;
}

.template-component-filter-chip-remove:hover .icon-close {
    filter: brightness(0) invert(1);
}

.template-component-filter-chip-default {
    background: var(--background-color);
    border-color: var(--border-color);
    color: #666;
}

.template-component-filter-chip-default:hover {
    background: var(--border-color);
    border-color: var(--border-color-hover);
}

/* Filter dropdown button + badge */
.template-component-filter-group .dropdown-button,
.template-component-filter-group button[id$="-filter-btn"] {
    position: relative;
}

.template-component-filter-badge {
    position: absolute;
    top: -0.4rem;
    right: -0.4rem;
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.1rem;
    text-align: center;
    border-radius: 999px;
    background: var(--error-color);
    color: #fff;
    box-sizing: border-box;
}

.template-component-filter-badge.template-component-filter-badge--empty {
    display: none !important;
}

/* Shared filter dropdown content: checkboxes and labels */
.template-component-filter-checkboxes {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
}

.template-component-filter-checkboxes .template-component-filter-label-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    cursor: pointer;
    font-size: 0.875rem;
}

.template-component-filter-checkboxes .template-component-filter-label-inline input[type="checkbox"] {
    margin: 0;
}

/* ========== Inline chips (template-chip) ========== */
/* Small inline chips; type and size variants. Not card/tabulator specific. */

.template-chip {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    gap: 0.2rem;
    font-size: 0.75rem;
    line-height: 1;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    font-weight: 500;
    height: 20px;
    box-sizing: border-box;
    background: var(--chip-bg);
    border: 1px solid var(--chip-border);
    color: var(--chip-color);
    white-space: nowrap;
}

.template-chip--error {
    background: var(--chip-error-bg);
    border-color: var(--chip-error-border);
    color: var(--chip-error-color);
}

.template-chip--warning {
    background: var(--chip-warning-bg);
    border-color: var(--chip-warning-border);
    color: var(--chip-warning-color);
}

.template-chip--success {
    background: var(--chip-success-bg);
    border-color: var(--chip-success-border);
    color: var(--chip-success-color);
}

.template-chip--info {
    background: var(--chip-info-bg);
    border-color: var(--chip-info-border);
    color: var(--chip-info-color);
}

.template-chip--neutral {
    background: var(--chip-neutral-bg);
    border-color: var(--chip-neutral-border);
    color: var(--chip-neutral-color);
}

/* Filled variants */
.template-chip--filled {
    background: var(--chip-filled-bg);
    border-color: var(--chip-filled-border);
    color: var(--chip-filled-color);
}

.template-chip--filled.template-chip--error {
    background: var(--chip-filled-error-bg);
    border-color: var(--chip-filled-error-border);
    color: var(--chip-filled-error-color);
}

.template-chip--filled.template-chip--warning {
    background: var(--chip-filled-warning-bg);
    border-color: var(--chip-filled-warning-border);
    color: var(--chip-filled-warning-color);
}

.template-chip--filled.template-chip--success {
    background: var(--chip-filled-success-bg);
    border-color: var(--chip-filled-success-border);
    color: var(--chip-filled-success-color);
}

.template-chip--filled.template-chip--info {
    background: var(--chip-filled-info-bg);
    border-color: var(--chip-filled-info-border);
    color: var(--chip-filled-info-color);
}

.template-chip--filled.template-chip--neutral {
    background: var(--chip-filled-neutral-bg);
    border-color: var(--chip-filled-neutral-border);
    color: var(--chip-filled-neutral-color);
}

.template-chip--sm {
    font-size: 0.65rem;
    padding: 0.05rem 0.25rem;
    border-radius: 4px;
}

.template-chip--lg {
    font-size: 0.8125rem;
    padding: 0.2rem 0.5rem;
    height: 28px;
    box-sizing: border-box;
    border-radius: 8px;
}

/* Chip icon — re-declare background props since [class^="icon-"] won't match
   when the class attribute starts with "template-chip__icon" */
.template-chip__icon {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: brightness(0.5);
}

.template-chip--sm .template-chip__icon {
    width: 10px;
    height: 10px;
}

.template-chip--lg .template-chip__icon {
    width: 14px;
    height: 14px;
}

/* Icon color filters per chip variant (base SVG stroke is #666) */
.template-chip--error .template-chip__icon {
    filter: sepia(1) saturate(5) hue-rotate(335deg) brightness(0.7);
}

.template-chip--warning .template-chip__icon {
    filter: sepia(1) saturate(5) hue-rotate(10deg) brightness(0.8);
}

.template-chip--success .template-chip__icon {
    filter: sepia(1) saturate(5) hue-rotate(100deg) brightness(0.6);
}

.template-chip--info .template-chip__icon {
    filter: sepia(1) saturate(5) hue-rotate(195deg) brightness(0.7);
}

.template-chip--neutral .template-chip__icon {
    filter: brightness(0.4);
}

.template-chip--filled .template-chip__icon {
    filter: brightness(0) invert(1);
}

/* Chip remove button — circular button with icon-close SVG */
.template-chip__remove {
    all: unset;
    flex-shrink: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    min-width: 16px;
    height: 16px;
    min-height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E");
    background-size: 10px 10px;
    background-repeat: no-repeat;
    background-position: center;
    background-color: rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    margin: -0.05rem -0.25rem -0.05rem 0.1rem;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.template-chip--sm .template-chip__remove {
    width: 14px;
    min-width: 14px;
    height: 14px;
    min-height: 14px;
    background-size: 8px 8px;
}

.template-chip--lg .template-chip__remove {
    width: 18px;
    min-width: 18px;
    height: 18px;
    min-height: 18px;
    background-size: 12px 12px;
}

/* Filled chips: muted white X, transparent bg until hovered */
.template-chip--filled .template-chip__remove {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E");
    background-color: rgba(255, 255, 255, 0.15);
    opacity: 0.6;
}

/* Remove button hover is always red/white regardless of chip variant */
.template-chip__remove:hover,
.template-chip--filled .template-chip__remove:hover {
    filter: none;
    opacity: 1;
    background-color: var(--error-color);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E");
}

/* ========== Chip group (template-chip-group) ========== */
/* Joins multiple template-chip elements into a single button-group-style strip.
   Child chips lose individual border-radius and merge visually via shared borders. */

.template-chip-group {
    display: inline-flex;
    align-items: stretch;
    border-radius: 6px;
    overflow: hidden;
}

.template-chip-group > .template-chip {
    border-radius: 0;
    margin: 0;
}

.template-chip-group > .template-chip:first-child {
    border-radius: 6px 0 0 6px;
}

.template-chip-group > .template-chip:last-child {
    border-radius: 0 6px 6px 0;
}

.template-chip-group > .template-chip:only-child {
    border-radius: 6px;
}

.template-chip-group > .template-chip + .template-chip {
    border-left: none;
}

/* ========== Card list (template-component-card-list) ========== */
/* Full-width rows with bottom border; remove button top right. Used in card body. */

.template-component-card-body:has(> .template-component-card-list) {
    padding: 0;
}

.template-component-card-list {
    width: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
}

.template-component-card-list-row {
    position: relative;
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    min-height: 2.25rem;
    box-sizing: border-box;
}

.template-component-card-list-row:last-child {
    border-bottom: none;
}

.template-component-card-list-row-content {
    display: block;
    min-width: 0;
}

.template-component-card-list-row-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.template-component-card-list-row-desc {
    font-size: 0.8125rem;
    color: #666;
    display: block;
    padding-top: 0.15rem;
}

.template-component-card-list-row-remove {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    margin: 0;
    border: none;
    background: var(--border-color);
    color: var(--text-muted-dark);
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.template-component-card-list-row-remove:hover {
    background: var(--danger-color);
    color: #fff;
}

.template-component-card-list-row-remove:hover .icon-close {
    filter: brightness(0) invert(1);
}

.template-component-card-list-row-remove .icon-close {
    flex-shrink: 0;
}

/* Episode group header row */
.template-component-card-list-row--episode {
    background: var(--primary-bg-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.template-component-card-list-row--episode .template-component-card-list-row-content {
    flex: 1 1 0;
    min-width: 0;
}

.template-component-card-list-row--episode .icon-chevron-down {
    transition: transform 0.2s;
}

.template-component-card-list-row--episode .icon-chevron-down.collapsed {
    transform: rotate(-90deg);
}

.template-component-card-list-empty-msg {
    margin: 0;
    padding: 0.5rem 0;
    font-size: 0.875rem;
    color: #666;
    line-height: 1.4;
}

/* -- Columnar variant (template-component-card-list--columns) -- */

.template-component-card-list-header {
    display: flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: #fafafa;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-muted);
    min-height: 2rem;
    flex-shrink: 0;
}

.template-component-card--scroll-body > .template-component-card-body:has(> .template-component-card-list) {
    overflow-y: auto;
}

.template-component-card-list--columns .template-component-card-list-row {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
}

.template-component-card-list-col {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-component-card-list-row[role="button"] {
    cursor: pointer;
}

.template-component-card-list-row[role="button"]:hover {
    background: var(--hover-bg);
}

.template-component-card-list-row.survey-severity-low {
    background: color-mix(in srgb, var(--ot-yellow) 13%, transparent);
}
.template-component-card-list-row.survey-severity-low:hover {
    background: color-mix(in srgb, var(--ot-yellow) 22%, transparent);
}
.template-component-card-list-row.survey-severity-mid {
    background: color-mix(in srgb, var(--ot-orange) 13%, transparent);
}
.template-component-card-list-row.survey-severity-mid:hover {
    background: color-mix(in srgb, var(--ot-orange) 22%, transparent);
}
.template-component-card-list-row.survey-severity-high {
    background: color-mix(in srgb, var(--ot-red) 13%, transparent);
}
.template-component-card-list-row.survey-severity-high:hover {
    background: color-mix(in srgb, var(--ot-red) 22%, transparent);
}

.template-component-card-list-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    padding: 0.35rem 0.75rem;
    text-align: center;
}

.template-component-card-list-footer-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

.template-component-card-list-footer-btn:hover {
    background: var(--primary-bg-light);
    color: var(--primary-hover);
}

/* ========== Picker list (template-component-picker-list) ========== */
/* Full-width rows with separator; for popupBox picker. Single-select: click saves. Multiselect: checkbox (upper-left) + Save in footer. */

.template-component-picker-list {
    width: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
}

.template-component-picker-intro {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: #666;
    border-bottom: 1px solid var(--border-color);
}

.template-component-picker-list-row {
    position: relative;
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
    min-height: 2.25rem;
    box-sizing: border-box;
    cursor: pointer;
}

.template-component-picker-list-row:hover:not(.template-component-picker-list-row--disabled) {
    background: var(--background-color);
}

.template-component-picker-list-row:last-child {
    border-bottom: none;
}

.template-component-picker-list-row--disabled {
    cursor: default;
    opacity: 0.6;
    background: #fafafa;
}

.template-component-picker-list-row .template-component-picker-list-row-inner {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    min-width: 0;
}

.template-component-picker-list-row-content {
    display: block;
    min-width: 0;
}

.template-component-picker-list-row-title {
    font-weight: 600;
    display: block;
}

.template-component-picker-list-row-desc {
    font-size: 0.8125rem;
    color: #666;
    display: block;
    padding-top: 0.15rem;
}

.template-component-picker-checkbox {
    flex-shrink: 0;
    align-self: flex-start;
    margin: 0;
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
    pointer-events: none;
}

.template-component-picker-list-row--disabled .template-component-picker-checkbox {
    opacity: 0.5;
}

.template-component-picker-list--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 4rem;
}

.template-component-picker-empty-msg {
    margin: 0;
    font-size: 0.875rem;
    color: #666;
}

/* Search box in toolbar uses .template-component-search-box wrapper; inner .search-box/.search-box-input stay in app.css */

/* ── Toggle switch ─────────────────────────────────────────── */

.template-component-switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    flex-shrink: 0;
}

.template-component-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.template-component-switch-slider {
    position: absolute;
    inset: 0;
    background: var(--switch-slider-bg);
    border-radius: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

.template-component-switch-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    bottom: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.template-component-switch input:checked + .template-component-switch-slider {
    background: var(--primary-color);
}

.template-component-switch input:checked + .template-component-switch-slider::before {
    transform: translateX(16px);
}

.template-component-switch input:disabled + .template-component-switch-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== Connection status banner ========== */
/* Persistent global banner injected at app boot by main.connectionStatus.
   Hidden when state is online and no offline queue is pending. */
.connection-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999999;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transform: translateY(0);
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.connection-banner--hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
.connection-banner--offline {
    background: var(--error-color);
}
.connection-banner--degraded {
    background: var(--warning-color);
    color: #1f2937;
}
.connection-banner-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    margin-right: 6px;
    vertical-align: middle;
    animation: connection-banner-pulse 1.4s ease-in-out infinite;
}
@keyframes connection-banner-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.connection-banner-queue {
    opacity: 0.85;
    font-weight: 400;
}

/* ─── Card Grid Customize ─────────────────────────────────────────── */

.card-grid-customize-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-grid-customize-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    background: var(--background-color);
    border: 1px solid var(--border-color);
}

.card-grid-customize-check {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.card-grid-customize-check input[type="checkbox"] {
    margin: 0;
}

.card-grid-customize-pin {
    width: 14px;
    height: 14px;
    opacity: 0.5;
}

.card-grid-customize-label {
    flex: 1;
    font-size: 0.875rem;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-grid-customize-handle {
    cursor: grab;
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    user-select: none;
    padding: 0 2px;
}

.card-grid-customize-handle:active {
    cursor: grabbing;
}

.card-grid-customize-row--dragging {
    opacity: 0.4;
    background: var(--primary-light);
}

.card-grid-customize-locked {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-color);
}
