/* ===========================
   Capture Templates Styles
   =========================== */

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
}

.template-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    display: flex;
    flex-direction: column;
    position: relative;
}

.template-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.add-template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    cursor: pointer;
    border: 2px dashed var(--border-color);
    background: transparent;
    transition: border-color 0.25s ease, background 0.25s ease, transform 0.2s ease;
}

.add-template-card:hover {
    border-color: var(--primary-color);
    background: rgba(33, 150, 243, 0.05);
    box-shadow: none;
    transform: translateY(-2px);
}

.add-template-icon {
    font-size: 2.5rem;
    font-weight: 300;
    color: var(--text-secondary);
    line-height: 1;
    transition: color 0.2s;
}

.add-template-card:hover .add-template-icon {
    color: var(--primary-text-color);
}

.add-template-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 8px;
    font-weight: 500;
}

.template-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    overflow: hidden;
    min-width: 0;
}

.template-card .template-card-header {
    padding-right: 24px;
}

.template-name {
    font-size: 1.05rem;
    font-weight: bold;
    color: var(--text-color);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 100%;
}

.template-name > .icon {
    color: var(--primary-text-color);
    vertical-align: middle;
    margin-right: 6px;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.template-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 12px;
    line-height: 1.4;
}

.template-config {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.filter-chain {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.filter-chain-item {
    font-size: 0.7rem;
    background: var(--border-color);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 10px;
}

.filter-chain-arrow {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.template-config-collapse {
    margin-top: 4px;
}
.template-config-toggle {
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: none;
    padding: 0;
    border: none;
    font-family: inherit;
}
.template-config-toggle::before {
    content: '▸ ';
}
.template-config-collapse.open .template-config-toggle::before {
    content: '▾ ';
}
.template-config-toggle:hover {
    text-decoration: underline;
}
.template-config-animate {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.25s ease;
}
.template-config-collapse.open .template-config-animate {
    grid-template-rows: 1fr;
}
.template-config-inner {
    overflow: hidden;
}

.template-no-config {
    margin: 12px 0;
    font-size: 0.8125rem;
    color: var(--primary-text-color);
    font-weight: 500;
    padding: 4px 0;
}

.config-table {
    width: 100%;
    margin-top: 8px;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.config-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-color);
}

.config-table tr:last-child td {
    border-bottom: none;
}

.config-key {
    color: var(--text-secondary);
    white-space: nowrap;
    width: 1%;
}

.config-value {
    color: var(--text-primary);
    font-family: monospace;
}

/* Engine config grid (property name left, input right) */
.config-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    align-items: center;
    margin-top: 12px;
}

.config-grid-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    text-align: right;
}

.config-grid-value input,
.config-grid-value select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.85rem;
}

.template-card-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    align-items: center;
}

.template-card-actions .btn:not(.btn-icon) {
    flex: 1;
}

.template-card-actions .btn-icon {
    flex-shrink: 0;
}

.text-muted {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.8125rem;
}

/* PP Filter List in Template Modal */
.pp-filter-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.pp-filter-empty {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-align: center;
    padding: 16px;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
}

.pp-filter-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    padding: 10px 12px;
}

.pp-filter-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.pp-filter-card.expanded .pp-filter-card-header {
    margin-bottom: 8px;
}

.pp-filter-card-chevron {
    font-size: 10px;
    color: var(--text-secondary);
    flex-shrink: 0;
    width: 12px;
}

.pp-filter-card-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.pp-filter-card-summary {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-right: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pp-filter-card-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}

.btn-filter-action {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    padding: 0;
}

.btn-filter-action:hover:not(:disabled) {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-filter-action:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-filter-remove:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

.pp-filter-card-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pp-filter-option {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pp-filter-option label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.pp-filter-option input[type="range"] {
    width: 100%;
}

.pp-filter-text-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: monospace;
}

/* Bool option row: label text on left, .settings-toggle on right */
.pp-filter-option-bool {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.pp-filter-option-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ── PP filter drag-and-drop ── */

.pp-filter-drag-handle {
    cursor: grab;
    opacity: 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    transition: opacity 0.2s ease;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
}

.pp-filter-card:hover .pp-filter-drag-handle {
    opacity: 0.5;
}

.pp-filter-drag-handle:hover {
    opacity: 1 !important;
    background: var(--border-color);
}

.pp-filter-drag-handle:active {
    cursor: grabbing;
}

.pp-filter-drag-clone {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.92;
    transform: scale(1.02);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
    will-change: top;
}

.pp-filter-drag-placeholder {
    border: 2px dashed var(--primary-color);
    border-radius: 8px;
    background: rgba(33, 150, 243, 0.04);
    min-height: 42px;
    transition: height 0.15s ease;
}

body.pp-filter-dragging .pp-filter-card {
    transition: none !important;
}

body.pp-filter-dragging .pp-filter-drag-handle {
    opacity: 0 !important;
}

.pp-add-filter-row {
    margin-bottom: 4px;
}

.pp-add-filter-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.8125rem;
}

.pp-add-filter-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.pp-add-filter-btn:hover {
    background: var(--border-color);
}

/* Template Test Section */
.template-test-section {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
}

.template-test-section h3 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 1rem;
}

.test-results-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
}

.test-preview-section,
.test-performance-section {
    margin-bottom: 20px;
}

.test-preview-section:last-child,
.test-performance-section:last-child {
    margin-bottom: 0;
}

.test-preview-section h4,
.test-performance-section h4 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.test-preview-image {
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.test-preview-image img {
    display: block;
    width: 100%;
    height: auto;
}

.test-performance-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-item span {
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-item strong {
    color: var(--text-color);
    font-weight: 600;
    font-family: monospace;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Stream type badges */
.badge-raw {
    background: #1976d2;
    color: white;
}

.badge-processed {
    background: #7b1fa2;
    color: white;
}

/* Stream info panel in stream selector modal */
.stream-info-panel {
    padding: 4px 0 0 0;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* Stream sub-tabs */
.stream-tab-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 16px;
}

.stream-tab-btn {
    background: none;
    border: none;
    padding: 8px 14px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease, border-color 0.25s ease;
}

.stream-tab-btn:hover {
    color: var(--text-color);
}

.stream-tab-btn.active {
    color: var(--primary-text-color);
    border-bottom-color: var(--primary-color);
}

.stream-tab-count {
    background: var(--border-color);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
}

.stream-tab-btn.active .stream-tab-count {
    background: var(--primary-color);
    color: var(--primary-contrast);
}

.cs-expand-collapse-group {
    margin-left: auto;
    display: flex;
    gap: 2px;
}

.btn-expand-collapse {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    padding: 0;
}

.btn-expand-collapse:hover {
    color: var(--text-color);
    background: var(--border-color);
}

.stream-tab-panel {
    display: none;
}

.stream-tab-panel.active {
    display: block;
    animation: tabFadeIn 0.2s ease-out;
}

/* Sub-tab content sections */
.subtab-section {
    margin-bottom: 24px;
    scroll-margin-top: var(--sticky-top, 90px);
}

.subtab-section:last-child {
    margin-bottom: 0;
}

.subtab-section-header {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
}

.subtab-section-header.cs-header {
    margin-bottom: 0;
    padding-bottom: 8px;
}

/* ── Collapsible card sections (cs-*) ── */

.cs-header {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: default;
    user-select: none;
    padding: 8px 0;
}

.cs-header:has(.cs-chevron) {
    cursor: pointer;
}

/* Prevent sticky header from clipping cards that lift on hover */
[data-cs-content] {
    padding-top: 4px;
}

.cs-chevron {
    font-size: 0.65rem;
    color: var(--text-secondary);
    width: 12px;
    display: inline-block;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.cs-title {
    flex-shrink: 0;
}

.cs-count {
    background: var(--border-color);
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 0 7px;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.cs-collapsed .cs-filter-wrap,
.cs-collapsed .cs-header-extra {
    display: none;
}

.cs-header-extra {
    display: flex;
    align-items: center;
}

.cs-header-extra .btn {
    padding: 2px 8px;
    font-size: 0.75rem;
    line-height: 1;
}

.cs-filter-wrap {
    position: relative;
    width: 180px;
    max-width: 40%;
    flex-shrink: 0;
}

.cs-filter-wrap .cs-filter {
    width: 100%;
    padding: 4px 26px 4px 10px;
    font-size: 0.78rem;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-secondary);
    color: var(--text-color);
    outline: none;
    box-shadow: none;
    box-sizing: border-box;
    transition: border-color 0.2s, background 0.2s, width 0.2s;
}

.cs-filter-wrap .cs-filter:focus {
    border-color: var(--primary-color);
    background: var(--bg-color);
}

.cs-filter::placeholder {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.cs-filter-reset {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
    display: none;
}

.cs-filter-reset:hover {
    color: var(--text-color);
    background: var(--border-color);
}

/* Empty state for CardSection */
.cs-empty-state {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    text-align: center;
}

.cs-empty-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .templates-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .stream-tab-bar {
        flex-wrap: wrap;
    }

    .stream-tab-btn {
        padding: 6px 10px;
        font-size: 0.85rem;
    }
}
