/* CAS Shared Styling - Used by CAS.Client and CAS.Admin */

/* Tint-derived border color (darker shade of the theme tint) */
.border-cas-tint-dark {
    border-color: color-mix(in srgb, var(--cas-tint), black 40%);
}

/* CSS Variables for consistent theming */
:root {
    --border-color: 229 231 235; /* gray-200 RGB values */

    /* Syntax highlighting palette - uses --cas-tint as accent for keys */
    --syntax-key: rgb(var(--cas-tint, 37 99 235));      /* tint - property names */
    --syntax-string: #16a34a;      /* green-600 - string values */
    --syntax-number: #d97706;      /* amber-600 - number values */
    --syntax-literal: #7c3aed;     /* violet-600 - true, false, null */
    --syntax-punctuation: #64748b; /* slate-500 - { } [ ] : , */
    --syntax-comment: #94a3b8;     /* slate-400 - comments */
    --syntax-link: rgb(var(--cas-tint, 37 99 235));
    --syntax-quote: #64748b;       /* slate-500 - blockquotes */
    --syntax-text: #1e293b;        /* slate-800 - base text */
}

.dark {
    --border-color: 55 65 81; /* gray-700 RGB values */

    --syntax-key: rgb(var(--cas-tint-dark, 96 165 250));    /* tint - property names */
    --syntax-string: #4ade80;      /* green-400 - string values */
    --syntax-number: #fbbf24;      /* amber-400 - number values */
    --syntax-literal: #a78bfa;     /* violet-400 - true, false, null */
    --syntax-punctuation: #94a3b8; /* slate-400 - { } [ ] : , */
    --syntax-comment: #64748b;     /* slate-500 */
    --syntax-link: rgb(var(--cas-tint-dark, 96 165 250));
    --syntax-quote: #94a3b8;       /* slate-400 */
    --syntax-text: #e5e7eb;        /* gray-200 */
}

/* Form controls */
.form-control {
    @apply block w-full px-3 py-2 text-gray-900 dark:text-gray-50 bg-white dark:bg-gray-800 placeholder:text-gray-400 dark:placeholder:text-gray-500 border border-gray-300 dark:border-gray-600 focus:outline-none focus:border-cas-tint focus:ring-2 focus:ring-cas-tint/20 transition-colors rounded-md;
}

/* Fixed height for single-line inputs and selects (not textareas) */
input.form-control,
select.form-control,
.form-control-select {
    @apply h-[38px];
}

/* Invalid state styling */
.invalid.form-control {
    @apply text-red-600 border-red-500 dark:border-red-400 bg-red-50 dark:bg-red-900/20 focus:border-red-500 focus:ring-red-500/20;
}

/* Disabled/Readonly state styling */
.form-control:disabled,
.form-control[readonly] {
    @apply bg-gray-100 dark:bg-gray-900 text-gray-500 dark:text-gray-500 border-gray-200 dark:border-gray-700 cursor-not-allowed opacity-75;
}

.form-control:disabled:focus,
.form-control[readonly]:focus {
    @apply outline-none border-gray-200 dark:border-gray-700 ring-0;
}

/* Compact form controls for inline/tree editing */
.form-control-compact {
    @apply block w-full px-2 py-0.5 text-xs text-gray-900 dark:text-gray-50
           bg-white dark:bg-gray-800 placeholder:text-gray-400 dark:placeholder:text-gray-500
           border border-gray-300 dark:border-gray-600 rounded
           focus:outline-none focus:border-cas-tint focus:ring-1 focus:ring-cas-tint/20
           transition-colors h-[26px];
}

input.form-control-compact,
select.form-control-compact {
    @apply h-[26px];
}

.form-control-compact:disabled {
    @apply bg-gray-100 dark:bg-gray-900 text-gray-500 dark:text-gray-500 cursor-not-allowed opacity-75;
}

/* Inline dropdown trigger - inherits font from parent context */
.dropdown-inline-trigger {
    @apply inline-flex items-center gap-0.5 cursor-pointer whitespace-nowrap;
    font: inherit;
    line-height: inherit;
}

.dropdown-inline-trigger.disabled {
    @apply opacity-50 cursor-not-allowed;
}

/* Hidden sizer: stacked item labels set the trigger's min-width */
.dropdown-sizer {
    @apply flex flex-col overflow-hidden pointer-events-none;
    height: 0;
    visibility: hidden;
}

/* Remove focus outline from non-interactive elements (headings, divs, table rows, etc.) */
*:focus:not(input):not(select):not(textarea):not(button):not(a):not([role="button"]):not(summary) {
    @apply outline-none;
}

/* Universal scrollbar styling for all elements */
* {
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
    border: 1px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
    background-clip: content-box;
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* Dark mode universal scrollbar */
.dark * {
    scrollbar-color: #4b5563 transparent;
}

.dark *::-webkit-scrollbar-thumb {
    background: #4b5563;
    background-clip: content-box;
}

.dark *::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
    background-clip: content-box;
}

/* Panel System */
.panel {
    @apply bg-surface border border-default;
}

.panel-header {
    @apply flex items-center justify-between px-4 py-4 border-b border-default bg-surface-secondary;
}

.panel-title {
    @apply text-lg font-medium text-body;
}

.panel-header-actions {
    @apply flex items-center space-x-2;
}

.panel-header-lg {
    @apply px-6 py-6 border-b border-default bg-surface-secondary;
}

.panel-body {
    @apply p-4;
}

.panel-body-lg {
    @apply p-6;
}

/* Fix for table border conflicts within panels */
.panel .table {
    @apply divide-y-0;
}

/* Table System */
.table-container {
    @apply panel;
}

.table {
    @apply w-full leading-6;
}

/* Table header - gray background */
.table-header {
    @apply bg-surface-secondary;
}

/* Sticky header separator — an inset 1px bottom line, drawn at [bottom-1, bottom] just like
   each body row's border-bottom separator. An outset shadow (0 1px) would paint the line one
   pixel *below* the header (over the first body row's top edge), making it sit 1px lower than
   the inter-row separators — which knocked the JobPipelinePopover 1px out of alignment on the
   first row only. Inset keeps the line attached to the sticky element and consistent. */
.sticky-header-shadow {
    box-shadow: inset 0 -1px 0 0 rgb(var(--border-color));
}

/* Header cell styling - used for th elements */
.table-header-cell {
    @apply px-4 py-3 text-left text-xs font-medium text-muted uppercase tracking-wider;
}

/* The header's bottom divider lives on the <tr> (.divider / .sticky-header-shadow), but the
   table uses collapsed borders, so a hovered sortable cell's .hover-default background paints
   over that line and erases it. Redraw the separator as an inset shadow on the hovered cell —
   painted above its own background — using the same color as the divider/sticky-header line.
   Keyed off .table-header-cell (never @apply'd) rather than .hover-default so the rule isn't
   dragged into every `@apply hover-default` expansion. */
.table-header-cell:hover {
    box-shadow: inset 0 -1px 0 0 rgb(var(--border-color));
}

/* Bordered table container - standalone use with outer border */
.table-bordered {
    @apply border border-default;
}

/* Cell borders - vertical lines between columns */
.table-cell-borders .table-header-cell,
.table-cell-borders .table-cell {
    @apply border-r border-default last:border-r-0;
}

/* Column resize handle - thin hit area at the right edge of a header cell.
   The ::after element is the visible indicator line on hover/drag. */
.col-resize-handle {
    position: absolute;
    top: 0;
    right: -4px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 1;
    touch-action: none;
}

.col-resize-handle::after {
    content: "";
    position: absolute;
    top: 0;
    left: 3px;
    width: 2px;
    height: 100%;
}

.col-resize-handle:hover::after,
.col-resize-handle.col-resize-active::after {
    background-color: var(--cas-tint, rgb(37 99 235));
}

.table-body {
    @apply bg-surface;
}

.table-row {
    @apply border-b border-default hover-default;
}

.table-row-focused {
    @apply bg-cas-tint/15;
    box-shadow: inset 3px 0 0 0 var(--cas-tint);
}
.table-row-selected {
    @apply bg-cas-tint/10;
}

/* Keyboard shortcuts modal */
.kbd {
    @apply inline-flex items-center justify-center min-w-[24px] h-6 px-1.5 text-xs font-medium rounded border;
    @apply bg-surface-secondary text-secondary border-default shadow-sm;
}

.shortcut-section-title {
    @apply text-sm font-semibold text-heading uppercase tracking-wider mb-3 pb-2 border-b border-default;
}

.shortcut-list {
    @apply space-y-0;
}

.shortcut-row {
    @apply flex items-center justify-between py-1.5;
}

.shortcut-row dt {
    @apply text-sm text-secondary;
}

.shortcut-row dd {
    @apply flex items-center gap-1 ml-2 flex-shrink-0;
}

.table-body-flush > :last-child {
    @apply border-b-0;
}

/* Restore last-row border inside DefinitionTable (section headers follow field tables) */
.dt-panel .table-body-flush > :last-child {
    @apply border-b border-default;
}

/* Table view (`dt-flat`, HideHierarchy): nothing follows the single field table, so the
   restored border would float in the air whenever the table ends above the panel bottom —
   the resize-handle divider is the separator there. */
.dt-panel.dt-flat .table-body-flush > :last-child {
    @apply border-b-0;
}

.table-cell {
    @apply px-4 py-1.5 text-body;
}

/* Compact table variants */
.table-compact .table-header-cell {
    @apply px-3 py-2.5;
}

.table-compact .table-cell {
    @apply px-3 py-1;
}

.table-compact thead .form-control,
.table-compact thead select.form-control {
    @apply h-8 py-0 px-2 text-xs leading-tight font-normal;
}

/* Table cell content layouts */
.table-cell-icon-text {
    @apply flex items-center gap-2 overflow-hidden min-w-0;
}

.table-cell-logo {
    @apply flex-shrink-0 flex items-center justify-center relative;
    height: 1lh;
    width: 2.5rem;
}

.table-cell-logo img {
    @apply max-w-full max-h-full object-contain relative;
}

/* Table cell padding overrides - work with both normal and compact tables */
.table-cell.table-cell-p-0 {
    @apply p-0;
}

.table-cell.table-cell-pl-0 {
    @apply pl-0;
}

.table-cell.table-cell-pl-1 {
    @apply pl-1;
}

/* Table cell horizontal padding override */
.table-cell.table-cell-px-1 {
    @apply px-1;
}

/* Table header padding overrides */
.table-header-cell.table-cell-pl-0 {
    @apply pl-0;
}

.table-header-cell.table-cell-pl-1 {
    @apply pl-1;
}

.table-header-cell.table-cell-px-1 {
    @apply px-1;
}

/* Loading States */
.table-loading-row {
    @apply border-b border-default animate-pulse;
}

.loading-skeleton {
    @apply h-4 bg-gray-200 dark:bg-gray-700;
}

.loading-skeleton-sm {
    @apply h-3 bg-gray-200 dark:bg-gray-700;
}

.loading-skeleton-lg {
    @apply h-6 bg-gray-200 dark:bg-gray-700;
}

.loading-spinner {
    @apply animate-spin h-5 w-5 text-gray-400;
}

.loading-spinner svg {
    @apply text-cas-tint;
}

/* Modal System */
.modal-overlay {
    @apply fixed inset-0 bg-gray-500 bg-opacity-75 dark:bg-black dark:bg-opacity-75 transition-opacity;
}

.modal-container {
    @apply fixed inset-0 z-50 overflow-y-auto;
}

.modal-content {
    @apply bg-surface shadow-xl;
}

.modal-header {
    @apply px-4 py-4 sm:px-6 bg-surface-secondary border-b border-default;
}

.modal-body {
    @apply px-4 py-4 sm:px-6;
}

.modal-footer {
    @apply px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse sm:gap-3 bg-surface-secondary border-t border-default;
}

/* Button System */
.btn {
    @apply inline-flex items-center px-4 py-2 text-sm font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2;
}

.btn-primary {
    @apply btn bg-cas-tint text-white hover:bg-opacity-90 focus:ring-cas-tint;
}

.btn-secondary {
    @apply btn bg-surface text-secondary border border-input hover:bg-gray-50 dark:hover:bg-gray-700 focus:ring-cas-tint;
}

.btn-danger {
    @apply btn bg-red-600 text-white hover:bg-red-700 focus:ring-red-500;
}

.btn-warning {
    @apply btn bg-amber-600 text-white hover:bg-amber-700 focus:ring-amber-500;
}

/* Icon Buttons - Round buttons with icons */
.icon-btn {
    @apply w-8 h-8 rounded-full flex items-center justify-center transition-colors;
}

.icon-btn-sm {
    @apply w-7 h-7 rounded-full flex items-center justify-center transition-colors;
}

.icon-btn-xs {
    @apply w-5 h-5 rounded-full flex items-center justify-center transition-colors;
}

/* Solid icon buttons - using semantic colors */
.icon-btn-primary {
    @apply icon-btn bg-cas-tint/70 hover:bg-cas-tint/80 text-white;
}

.icon-btn-success {
    @apply icon-btn bg-green-600/70 hover:bg-green-600/80 dark:bg-green-500/70 dark:hover:bg-green-500/80 disabled:bg-gray-400 text-white;
}

.icon-btn-warning {
    @apply icon-btn bg-amber-600/70 hover:bg-amber-600/80 dark:bg-amber-500/70 dark:hover:bg-amber-500/80 text-white;
}

.icon-btn-danger {
    @apply icon-btn bg-red-600/70 hover:bg-red-600/80 dark:bg-red-500/70 dark:hover:bg-red-500/80 text-white;
}

/* Ghost icon buttons (transparent background) */
.icon-btn-ghost {
    @apply icon-btn text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700;
}

.icon-btn-ghost-primary {
    @apply icon-btn color-primary hover:bg-cas-tint/10;
}

.icon-btn-ghost-success {
    @apply icon-btn color-success hover:bg-green-600/10 dark:hover:bg-green-500/10;
}

.icon-btn-ghost-warning {
    @apply icon-btn color-warning hover:bg-amber-600/10 dark:hover:bg-amber-500/10;
}

.icon-btn-ghost-danger {
    @apply icon-btn color-error hover:bg-red-600/10 dark:hover:bg-red-500/10;
}

/* Logo delete button - small circular delete overlay on images */
.logo-delete-btn {
    @apply w-5 h-5 bg-red-500 hover:bg-red-600 text-white rounded-full text-xs flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity;
}

/* Small variants */
.icon-btn-sm-primary {
    @apply icon-btn-sm bg-cas-tint/70 hover:bg-cas-tint/80 text-white;
}

.icon-btn-sm-success {
    @apply icon-btn-sm bg-green-600/70 hover:bg-green-600/80 dark:bg-green-500/70 dark:hover:bg-green-500/80 text-white;
}

/* Small ghost variants */
.icon-btn-sm-ghost {
    @apply icon-btn-sm text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700;
}

.icon-btn-sm-ghost-success {
    @apply icon-btn-sm color-success hover:bg-green-600/10 dark:hover:bg-green-500/10;
}

.icon-btn-sm-ghost-warning {
    @apply icon-btn-sm color-warning hover:bg-amber-600/10 dark:hover:bg-amber-500/10;
}

.icon-btn-sm-ghost-danger {
    @apply icon-btn-sm color-error hover:bg-red-600/10 dark:hover:bg-red-500/10;
}

/* Extra small variants */
.icon-btn-xs-success {
    @apply icon-btn-xs bg-green-600/70 hover:bg-green-600/80 dark:bg-green-500/70 dark:hover:bg-green-500/80 text-white;
}

.icon-btn-xs-danger {
    @apply icon-btn-xs bg-red-600/70 hover:bg-red-600/80 dark:bg-red-500/70 dark:hover:bg-red-500/80 text-white;
}

/* Avatar/initials circle */
.avatar {
    @apply w-7 h-7 rounded-full bg-cas-tint/70 flex items-center justify-center text-white text-xs font-medium;
}

/* ===========================================
   SEMANTIC COLOR SYSTEM
   Use these classes everywhere for consistent colors
   =========================================== */

/* Text colors - for icons, text */
.color-primary {
    @apply text-cas-tint;
}
.color-success {
    @apply text-green-600 dark:text-green-500;
}
.color-warning {
    @apply text-amber-600 dark:text-amber-500;
}
.color-error {
    @apply text-red-600 dark:text-red-500;
}
.color-info {
    @apply text-blue-600 dark:text-blue-400;
}
.color-purple {
    @apply text-purple-600 dark:text-purple-400;
}

/* Semantic borders */
.border-error {
    @apply border-red-500 dark:border-red-400;
}

/* Solid backgrounds - for buttons, indicators, progress bars */
.bg-primary {
    @apply bg-cas-tint/70;
}
.bg-success {
    @apply bg-green-600/70 dark:bg-green-500/70;
}
.bg-warning {
    @apply bg-amber-600/70 dark:bg-amber-500/70;
}
.bg-error {
    @apply bg-red-600/70 dark:bg-red-500/70;
}
.bg-info {
    @apply bg-blue-600/70 dark:bg-blue-500/70;
}

/* Light backgrounds - for subtle backgrounds, badges */
.bg-primary-light {
    @apply bg-cas-tint/20 dark:bg-cas-tint/30;
}
.bg-success-light {
    @apply bg-green-600/20 dark:bg-green-500/30;
}
.bg-warning-light {
    @apply bg-yellow-200/30 dark:bg-yellow-500/10;
}
.bg-error-light {
    @apply bg-red-600/20 dark:bg-red-500/30;
}
.bg-info-light {
    @apply bg-blue-600/20 dark:bg-blue-500/30;
}

/* Status indicator dot */
.status-dot {
    @apply w-3 h-3 rounded-full;
}
.status-dot-success {
    @apply status-dot bg-success;
}
.status-dot-warning {
    @apply status-dot bg-warning;
}
.status-dot-danger {
    @apply status-dot bg-error;
}

/* Alert styles - consistent background, border, and text colors */
.alert-success {
    @apply bg-green-50 border-green-200 text-green-700 dark:bg-green-900/20 dark:border-green-800 dark:text-green-400;
}
.alert-warning {
    @apply bg-amber-50 border-amber-200 text-amber-700 dark:bg-amber-900/20 dark:border-amber-800 dark:text-amber-400;
}
.alert-error {
    @apply bg-red-50 border-red-200 text-red-700 dark:bg-red-900/20 dark:border-red-800 dark:text-red-400;
}
.alert-info {
    @apply bg-cas-tint/10 border-cas-tint/20 text-cas-tint dark:bg-cas-tint/20 dark:border-cas-tint/30 dark:text-white;
}

/* Badge styles - for pills and tags */
.badge-success {
    @apply bg-green-100 text-green-700 dark:bg-green-500/20 dark:text-green-400;
}
.badge-warning {
    @apply bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400;
}
.badge-error {
    @apply bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400;
}
.badge-primary {
    @apply bg-cas-tint/15 text-cas-tint dark:bg-cas-tint/20 dark:text-white;
}

/* Toast styles */
.toast-success {
    @apply bg-green-50 text-green-800 border-green-200 dark:bg-green-900/30 dark:text-green-200 dark:border-green-700;
}
.toast-warning {
    @apply bg-amber-50 text-amber-800 border-amber-200 dark:bg-amber-900/30 dark:text-amber-200 dark:border-amber-700;
}
.toast-error {
    @apply bg-red-50 text-red-800 border-red-200 dark:bg-red-900/30 dark:text-red-200 dark:border-red-700;
}
.toast-info {
    @apply bg-cas-tint/10 text-cas-tint border-cas-tint/20 dark:bg-cas-tint/20 dark:text-white dark:border-cas-tint/30;
}

/* Button solid backgrounds - for primary action buttons */
.btn-bg-success {
    @apply bg-green-600/70 hover:bg-green-600/80 focus:ring-green-500;
}
.btn-bg-warning {
    @apply bg-amber-600/70 hover:bg-amber-600/80 focus:ring-amber-500;
}
.btn-bg-error {
    @apply bg-red-600/70 hover:bg-red-600/80 focus:ring-red-500;
}
.btn-bg-primary {
    @apply bg-cas-tint hover:bg-cas-tint-dark focus:ring-cas-tint;
}

/* Icon background - subtle background for icon containers */
.icon-bg-success {
    @apply bg-green-100 dark:bg-green-900/20;
}
.icon-bg-warning {
    @apply bg-amber-100 dark:bg-amber-900/20;
}
.icon-bg-error {
    @apply bg-red-100 dark:bg-red-900/20;
}
.icon-bg-primary {
    @apply bg-cas-tint/10 dark:bg-cas-tint/20;
}

/* Chip Input - inline tag editor with chips + input in one container */
.chip-input {
    @apply flex flex-wrap items-center gap-1.5 px-2 py-1.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700/50 min-h-[38px];
}

.chip-input:focus-within {
    @apply ring-1 ring-cas-tint border-cas-tint;
}

.chip-input-field {
    @apply flex-1 min-w-[100px] bg-transparent border-none outline-none text-sm text-gray-900 dark:text-white p-0;
}

.chip-input-field::placeholder {
    @apply text-gray-400 dark:text-gray-500;
}

.chip {
    @apply inline-flex items-center gap-1 px-2 py-0.5 rounded text-sm;
}

.chip-blue {
    @apply bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-300;
}

.chip-purple {
    @apply bg-purple-100 dark:bg-purple-900/30 text-purple-800 dark:text-purple-300;
}

.chip-green {
    @apply bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300;
}

.chip-orange {
    @apply bg-orange-100 dark:bg-orange-900/30 text-orange-800 dark:text-orange-300;
}

.chip-remove {
    @apply opacity-60 hover:opacity-100 transition-opacity;
}

/* Empty State */
.empty-state {
    @apply text-center py-8 text-muted;
}

/* Log Parameter Highlighting - colored parameters in structured log messages */
.log-param {
    @apply text-sky-600 dark:text-sky-400;
}

/* Log Flash Animation - subtle highlight for new logs */
@keyframes log-flash {
    0% {
        background-color: rgb(254 240 138 / 0.5); /* yellow-200 with transparency */
    }
    100% {
        background-color: transparent;
    }
}

.log-flash-animation {
    animation: log-flash 1.2s ease-out forwards;
    will-change: auto; /* Don't retain will-change after animation */
}

/* Dark mode flash animation */
.dark .log-flash-animation {
    animation: log-flash-dark 1.2s ease-out forwards;
}

@keyframes log-flash-dark {
    0% {
        background-color: rgb(133 77 14 / 0.4); /* yellow-800 with transparency */
    }
    100% {
        background-color: transparent;
    }
}

/* SVG Icon Color Matching */
.svg-icon {
    /* Match text-gray-600 (#4B5563 = rgb(75, 85, 99)) */
    filter: brightness(0) saturate(100%) invert(31%) sepia(7%) saturate(684%) hue-rotate(185deg) brightness(96%) contrast(91%);
    flex-shrink: 0;
}

.dark .svg-icon {
    /* Match text-gray-300 (#D1D5DB = rgb(209, 213, 219)) */
    filter: brightness(0) saturate(100%) invert(87%) sepia(4%) saturate(349%) hue-rotate(185deg) brightness(95%) contrast(88%);
}

/* ===========================================
   DESIGN SYSTEM - Text Colors
   Semantic text color classes for consistent light/dark mode
   =========================================== */

.text-heading {
    @apply text-gray-900 dark:text-white;
}
.text-body {
    @apply text-gray-900 dark:text-gray-50;
}
.text-secondary {
    @apply text-gray-700 dark:text-gray-300;
}
.text-tertiary {
    @apply text-gray-600 dark:text-gray-400;
}
.text-muted {
    @apply text-gray-500 dark:text-gray-400;
}
.text-placeholder {
    @apply text-gray-400 dark:text-gray-500;
}
.text-disabled {
    @apply text-gray-500 dark:text-gray-500;
}

/* ===========================================
   DESIGN SYSTEM - Surface / Background Colors
   =========================================== */

.bg-surface {
    @apply bg-white dark:bg-gray-800;
}
.bg-surface-secondary {
    @apply bg-gray-50 dark:bg-gray-800;
}
.bg-surface-header {
    @apply bg-gray-50 dark:bg-gray-700;
}
.bg-surface-hover {
    @apply bg-gray-100 dark:bg-gray-700;
}
.bg-surface-muted {
    @apply bg-gray-100 dark:bg-gray-800;
}
.bg-surface-inset {
    @apply bg-gray-50 dark:bg-gray-900;
}

/* ===========================================
   DESIGN SYSTEM - Borders
   =========================================== */

.border-default {
    @apply border-gray-200 dark:border-gray-700;
}
.border-input {
    @apply border-gray-300 dark:border-gray-600;
}
.divide-default > :not([hidden]) ~ :not([hidden]) {
    @apply border-gray-200 dark:border-gray-700;
}
.divider {
    @apply border-b border-gray-200 dark:border-gray-700;
}
.divider-t {
    @apply border-t border-gray-200 dark:border-gray-700;
}

/* ===========================================
   DESIGN SYSTEM - Hover States
   =========================================== */

.hover-default {
    @apply hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors;
}
.hover-subtle {
    @apply hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors;
}

/* ===========================================
   DESIGN SYSTEM - Form Classes
   =========================================== */

.form-label {
    @apply block text-sm font-medium text-secondary mb-1;
}
.form-help {
    @apply mt-1 text-sm text-muted;
}
.form-error {
    @apply mt-1 text-sm text-red-600 dark:text-red-400;
}
.form-control-select {
    @apply form-control appearance-none cursor-pointer pr-10;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.25rem;
}
:is(.dark .form-control-select) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
}
.form-control-textarea {
    @apply form-control resize-y;
}

/* ===========================================
   DESIGN SYSTEM - Typography
   =========================================== */

.section-title {
    @apply text-lg font-semibold text-heading;
}
.section-title-sm {
    @apply text-base font-semibold text-heading;
}
.stat-title {
    @apply text-xs font-medium text-tertiary uppercase tracking-wider;
}
.stat-value {
    @apply text-2xl font-bold text-heading;
}

/* Status filter pills */
.status-pill {
    @apply relative inline-flex items-center gap-1.5 px-2.5 py-1 text-xs font-medium text-muted bg-surface-secondary border border-default rounded-full cursor-pointer transition-colors;
}
.status-pill i {
    @apply text-xs;
}
.status-pill:hover {
    @apply bg-gray-200 dark:bg-gray-600;
}
.status-pill-active {
    @apply bg-cas-tint/10 border-cas-tint/30 text-heading;
}

/* Status pill popover */
.status-pill-popover {
    @apply absolute z-50 text-xs hidden;
    top: 100%;
    left: 0;
    padding-top: 4px;
    pointer-events: none;
}
.status-pill:hover .status-pill-popover {
    @apply block;
}
.status-pill-popover-inner {
    @apply bg-surface border border-default rounded-lg shadow-lg py-1.5 px-2.5;
    min-width: 140px;
    pointer-events: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 1rem;
}
.status-pill-popover-row {
    @apply items-center py-0.5 text-left;
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
}
.status-pill-popover-row-clickable {
    @apply rounded-sm cursor-pointer px-1.5 -mx-1.5 transition-colors;
    background: transparent;
    border: none;
}
.status-pill-popover-row-clickable:hover {
    @apply bg-surface-hover;
}
.status-pill-popover-row-clickable.status-pill-popover-row-active {
    background-color: rgba(var(--color-cas-tint-rgb, 59 130 246) / 0.1);
}
.status-pill-popover-label {
    @apply text-muted whitespace-nowrap;
}
.status-pill-popover-value {
    @apply font-mono text-heading font-medium whitespace-nowrap text-right tabular-nums;
    min-width: 1.75rem;
}

/* ===========================================
   DESIGN SYSTEM - Containers
   =========================================== */

.card {
    @apply bg-surface border border-default;
}
.card-padded {
    @apply card p-4;
}
.card-section {
    @apply bg-surface-inset border border-default rounded-md p-4;
}

/* ===========================================
   DESIGN SYSTEM - Page Layout
   =========================================== */

.page-header {
    @apply p-2 px-5 flex items-center justify-between border-b border-default;
}
.page-title {
    @apply section-title my-2;
}

/* ===========================================
   DESIGN SYSTEM - Menu / Dropdown
   =========================================== */

.dropdown-menu {
    @apply bg-surface border border-default rounded-md shadow-lg z-50 overflow-hidden;
}
.dropdown-item {
    @apply w-full text-left px-4 py-2 text-sm text-secondary hover-default;
}
.dropdown-item-danger {
    @apply dropdown-item text-red-600 dark:text-red-500;
}
.dropdown-header {
    @apply px-3 py-1 text-[11px] font-medium text-placeholder uppercase tracking-wide;
}
.context-menu {
    @apply absolute right-0 top-full mt-2 w-56 bg-surface shadow-xl ring-1 ring-black ring-opacity-5 dark:ring-gray-700 z-50;
}

/* ===========================================
   DESIGN SYSTEM - Badges (additions)
   =========================================== */

.badge {
    @apply inline-flex items-center px-2 py-0.5 text-xs font-medium rounded-full;
}
.badge-default {
    @apply bg-gray-100 text-gray-700 dark:bg-gray-600 dark:text-gray-200;
}
.badge-info {
    @apply bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400;
}

/* ===========================================
   DESIGN SYSTEM - Buttons (additions)
   =========================================== */

.btn-success {
    @apply btn bg-green-600/70 hover:bg-green-600/80 text-white shadow-sm focus:ring-green-500;
}
.btn-ghost {
    @apply btn text-secondary hover:bg-gray-100 dark:hover:bg-gray-800 focus:ring-gray-500;
}
.btn-link {
    @apply btn text-cas-tint hover:text-cas-tint-dark focus:ring-cas-tint underline underline-offset-4;
}
.btn-sm {
    @apply px-3 py-1.5 h-[30px] text-sm;
}
.btn-lg {
    @apply px-6 py-3 h-[46px] text-base;
}

/* Easter egg: button runs away on mouseenter */
.btn-runaway-away {
    position: fixed !important;
    z-index: 9999;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.25);
    transition: left 0.3s cubic-bezier(0.2, 0, 0, 1), top 0.3s cubic-bezier(0.2, 0, 0, 1);
}

/* ===========================================
   DESIGN SYSTEM - Table Cell Editing
   =========================================== */

.table-cell-input {
    @apply w-full px-2 py-1 text-sm font-mono bg-transparent text-gray-900 dark:text-gray-50 placeholder:text-gray-400 dark:placeholder:text-gray-500 border-0 focus:outline-none focus:bg-blue-50 dark:focus:bg-blue-900/20;
}
.table-cell-select {
    @apply w-full px-2 py-1 text-sm bg-transparent border-0 focus:outline-none focus:bg-blue-50 dark:focus:bg-blue-900/20 appearance-none cursor-pointer;
}

/* ===========================================
   DESIGN SYSTEM - Overlay / Backdrop
   =========================================== */

.backdrop {
    @apply fixed inset-0 z-40;
}
.overlay {
    @apply fixed inset-0 bg-gray-500/75 dark:bg-black/75;
}

/* ===========================================
   DESIGN SYSTEM - Slide-in Panel
   =========================================== */

/* Resizable document detail panel layout — DefinitionTable + PDF on top, NormalizedSamples
   below. Two CSS variables drive sizes; JS handles drag and persistence to localStorage. */
.cas-resizable-panel {
    --panel-h: 40%;
    --panel-v: 60%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.cas-panel-top {
    display: flex;
    flex-basis: var(--panel-v);
    flex-shrink: 0;
    min-height: 0;
}
.cas-panel-left {
    flex-basis: var(--panel-h);
    flex-shrink: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.cas-panel-right {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
}
.cas-panel-bottom {
    flex: 1 1 0;
    min-height: 0;
}
.cas-resize-handle {
    flex-shrink: 0;
    background: transparent;
    transition: background-color 100ms ease;
    user-select: none;
    position: relative;
}
.cas-resize-handle-h {
    width: 5px;
    cursor: col-resize;
    margin: 0 -2px;
    z-index: 1;
}
.cas-resize-handle-v {
    height: 5px;
    cursor: row-resize;
    margin: -2px 0;
    z-index: 1;
}
/* The -2px margins above enlarge the grab area, which means a border on the handle
   itself would paint 2px INSIDE the neighbouring panel (z-index 1), over its content —
   e.g. across the bottom edge of the definition table's last row. Draw the divider
   line with a pseudo-element at the true panel boundary instead. */
.cas-resize-handle-h::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2px;
    width: 1px;
    background-color: rgb(var(--border-color));
}
.cas-resize-handle-v::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 2px;
    height: 1px;
    background-color: rgb(var(--border-color));
}
.cas-resize-handle:hover,
body.cas-resizing .cas-resize-handle {
    background-color: rgb(var(--cas-tint) / 0.4);
}

.slide-panel-backdrop {
    @apply fixed inset-0 z-40 bg-black/50 dark:bg-black/70;
    animation: fade-in 200ms ease-out;
}
.slide-panel-backdrop-closing {
    animation: fade-out 200ms ease-in forwards;
}
.slide-panel {
    @apply fixed top-0 right-0 z-50 h-full bg-surface shadow-2xl flex flex-col;
    animation: slide-in-right 250ms cubic-bezier(0.2, 0, 0, 1);
}
.slide-panel-closing {
    animation: slide-out-right 200ms cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes slide-in-right {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}
@keyframes slide-out-right {
    from { transform: translateX(0); }
    to { transform: translateX(100%); }
}
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ===========================================
   DESIGN SYSTEM - Navigation
   =========================================== */

.nav-item {
    @apply flex items-center px-4 py-2.5 text-secondary hover-default rounded-md;
}
.nav-item-active {
    @apply bg-cas-tint/10 text-cas-tint font-medium;
}
.sidebar-item-active {
    @apply bg-surface-hover text-heading font-medium;
}

/* ===========================================
   DESIGN SYSTEM - Logo
   =========================================== */

/* Self-hosted brand font (was fonts.cdnfonts.com/css/smush) so the app
   works fully offline. Font file lives in the RCL wwwroot/fonts folder.
   Absolute URL: this rule is inlined into the apps' app.css by postcss-import,
   so a relative path would resolve against the wrong base there. */
@font-face {
    font-family: 'Smush';
    src: url('/_content/CAS.Blazor.Core/fonts/Smush.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

.logo {
    font-family: 'Smush', sans-serif;
}

.logo-collapsed {
    font-family: 'Smush', sans-serif;
    font-size: 3.5rem;
    line-height: 2.5rem;
    @apply font-bold text-cas-tint;
}

/* Required field asterisk */
.text-required { @apply text-red-500; }

/* Input icon positioning */
.input-icon-left { @apply absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none; }
.input-icon-right { @apply absolute inset-y-0 right-0 pr-3 flex items-center; }

/* Link styling */
.link { @apply text-cas-tint hover:underline; }

/* Progress bar track */
.progress-track { @apply bg-gray-200 dark:bg-gray-700 rounded-full; }

/* Job pipeline — bar and click-triggered popover.
   The bar is a <button popovertarget> that toggles a native Popover-API popover
   (light-dismiss: click outside / Esc closes). The cell is the positioning anchor —
   exactly as the old hover popover, but :has(:popover-open) sets the anchor-name only
   on the cell whose popover is open (one at a time), where :hover used to. */
/* Fills the whole cell so a click anywhere in the pipeline cell — not just the 6px bar —
   opens the popover. The bar stays vertically centred. */
.job-pipeline-bar-trigger {
    @apply flex items-center w-full h-full cursor-pointer border-0 bg-transparent p-0 text-left;
}

.job-pipeline-cell:has(.job-pipeline-popover:popover-open) {
    anchor-name: --pipeline-cell;
}

.job-pipeline-bar {
    @apply flex gap-px w-full overflow-hidden rounded-full;
    height: 6px;
}


.job-pipeline-bar .pipeline-pulse {
    animation: pipeline-pulse 1.5s ease-in-out infinite;
}

@keyframes pipeline-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.job-pipeline-popover {
    @apply z-50 text-xs;
    position: fixed;
    inset: auto;
    margin: 0;
    border: 0;
    padding: 0;
    overflow: visible;
    background: transparent;
    min-width: 280px;
    position-anchor: --pipeline-cell;
    left: anchor(right);
    top: calc(anchor(top) - 1px);
    position-try-fallbacks: flip-block;
}
.job-pipeline-popover-inner {
    @apply bg-surface border border-default shadow-lg px-3 py-2;
}

/* Generic CSS-only hover tooltip — used by <FieldLabel> for renamed certificate fields */
.field-tooltip-trigger {
    @apply relative inline-flex items-center;
}

.field-tooltip {
    @apply absolute z-50 text-xs hidden;
    bottom: 100%;
    left: 0;
    padding-bottom: 4px;
    pointer-events: none;
}

.field-tooltip-trigger:hover > .field-tooltip {
    @apply block;
}

.field-tooltip-inner {
    @apply block bg-surface border border-default rounded-lg py-1.5 px-2.5 text-body whitespace-nowrap;
    max-width: 320px;
    white-space: normal;
}

/* Normalization factor popover — CSS-only hover tooltip for chemical factor info */
.dt-has-normalization-popover:hover {
    anchor-name: --normpop;
}

.dt-normalization-popover {
    @apply text-xs hidden z-50;
    position: fixed;
    position-anchor: --normpop;
    bottom: calc(anchor(top) + 4px);
    left: anchor(left);
    pointer-events: none;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
}

.dt-has-normalization-popover:hover > .dt-normalization-popover {
    @apply block;
}

.dt-normalization-popover-inner {
    @apply bg-surface border border-default rounded-lg shadow-lg py-1.5 px-2.5;
    min-width: 160px;
}

.dt-normalization-row {
    @apply flex justify-between items-center gap-4 py-0.5;
}

.dt-normalization-label {
    @apply text-muted whitespace-nowrap;
}

.dt-normalization-value {
    @apply font-mono text-heading font-medium whitespace-nowrap;
}

.dt-normalization-result {
    @apply border-t border-default mt-0.5 pt-1;
}

/* Definition table keyboard focus */
.dt-keyboard-focus {
    @apply bg-cas-tint/15 !important;
}

/* Table inline input */
.table-inline-input { @apply w-full h-[36px] px-4 bg-transparent text-body focus:outline-none focus:bg-gray-50 dark:focus:bg-gray-700/50; }

/* Table validation error input */
.table-inline-input-error { @apply w-full h-[36px] px-4 bg-red-50 dark:bg-red-900/20 text-body focus:outline-none border-y border-red-500 dark:border-red-400; }

/* Checkbox styling (for forms and tables) */
.form-checkbox { @apply w-4 h-4 text-cas-tint bg-surface-muted border-input rounded focus:ring-cas-tint; }

/* SortableJS drag and drop styling */
.sortable-ghost {
    @apply opacity-40;
    background-color: rgb(var(--cas-tint-rgb, 59 130 246) / 0.1);
}

.sortable-chosen {
    background-color: rgb(var(--cas-tint-rgb, 59 130 246) / 0.05);
}

.sortable-drag {
    @apply opacity-100 bg-white shadow-md;
}

.dark .sortable-drag {
    @apply bg-gray-800;
}

/* netstack.js - .NET stack trace formatting */
.st-frame {
    @apply py-0.5;
}

.st-type {
    @apply text-gray-400;
}

.st-method {
    @apply text-green-400;
}

.st-param-type {
    @apply text-blue-400;
}

.st-param-name {
    @apply text-gray-500;
}

.st-file {
    @apply text-cyan-400;
}

.st-line {
    @apply text-yellow-400;
}

/* ===========================================
   DESIGN SYSTEM - Compact UI Components
   For dense/tool-like interfaces (sidebars, panels, toolbars)
   =========================================== */

/* Sidebar tree item — factory/location/certificate navigation */
.sidebar-item {
    @apply w-full text-left px-3 py-1 text-sm flex items-center gap-1.5 select-none;
}

.sidebar-item-child {
    @apply sidebar-item text-muted;
    padding-left: 34px;
}

.sidebar-item-grandchild {
    @apply sidebar-item text-body;
    padding-left: 56px;
}

/* Collapsible section header — details/summary */
.collapsible-header {
    @apply px-4 py-2 text-sm font-medium text-muted bg-surface-secondary cursor-pointer hover-subtle select-none;
}

.collapsible-body {
    @apply px-4 py-2 text-sm text-body bg-surface;
}

/* Toolbar — horizontal bar with actions */
.toolbar {
    @apply px-4 py-2 text-sm bg-surface-secondary flex-shrink-0 flex items-center;
}

.toolbar-divider {
    @apply toolbar divider;
}

.toolbar-divider-t {
    @apply toolbar divider-t;
}

/* Tab button — underlined tab in a toolbar */
.tab-btn {
    @apply text-sm font-medium h-full border-b-2 transition-colors border-transparent text-placeholder;
}
.tab-btn:hover {
    @apply text-heading;
}

.tab-btn-active {
    @apply text-sm font-medium h-full border-b-2 transition-colors border-cas-tint text-heading;
}

/* Pill toggle button — small rounded toggle in a group */
.pill-btn {
    @apply px-2 py-0.5 rounded text-sm transition-colors text-muted;
}
.pill-btn:hover {
    @apply text-body;
}

.pill-btn-active {
    @apply px-2 py-0.5 rounded text-sm transition-colors bg-cas-tint/70 text-white;
}

/* Run history chip — clickable extraction run in horizontal list */
.run-chip {
    @apply flex items-center gap-1.5 px-2 py-0.5 rounded text-[11px] transition-colors text-muted border border-transparent cursor-pointer flex-shrink-0;
}
.run-chip:hover {
    @apply text-body bg-surface;
}
.run-chip-active {
    @apply flex items-center gap-1.5 px-2 py-0.5 rounded text-[11px] transition-colors border border-cas-tint/40 bg-cas-tint/10 text-heading cursor-pointer flex-shrink-0;
}

/* Inline action link */
.action-link {
    @apply text-sm font-medium transition-colors text-cas-tint;
}
.action-link:hover {
    @apply opacity-80;
}

/* Upload button — outlined tint button for file upload */
.btn-upload {
    @apply inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-cas-tint border border-cas-tint/30 rounded hover:bg-cas-tint/10 transition-colors cursor-pointer;
}

/* Stats bar — monospace info bar */
.stats-bar {
    @apply px-4 py-2 text-sm text-muted bg-surface-secondary divider-t flex-shrink-0 flex items-center gap-6 font-mono;
}

/* Compact select — small inline select for toolbars */
.select-compact {
    @apply text-sm bg-surface border border-default rounded px-2 py-1 text-body;
}

/* Inline form label — small label above input in compact contexts */
.label-compact {
    @apply block text-sm font-medium text-muted mb-1;
}


/* ===========================================
   DEFINITION TABLE (.dt-*)
   Styles for DefinitionTable and DtSection components.
   --dt-cell-py / --dt-header-py / --dt-px on .dt-panel are the single
   source of truth for all internal spacing.
   =========================================== */

/* ── Panel wrapper ────────────────────────────────────────────────── */

.dt-panel {
    --dt-cell-py: 4px;
    --dt-header-py: 8px;
    --dt-px: 12px;
    @apply text-xs bg-surface border-r border-default;
}

.dt-panel .table {
    table-layout: fixed;
}

.dt-panel .table-row:hover {
    --tw-bg-opacity: 0;
}

/* All td cells inside the panel use cell padding */
.dt-panel .table-cell {
    padding: var(--dt-cell-py) var(--dt-px);
}

/* ── Empty state ──────────────────────────────────────────────────── */

.dt-no-data {
    @apply flex-1 flex items-center justify-center text-muted;
}

/* ── Sticky header wrapper ────────────────────────────────────────── */

.dt-sticky-header {
    @apply sticky top-0 z-10;
}

/* ── Toolbar (summary bar) ────────────────────────────────────────── */

.dt-toolbar {
    @apply flex items-center gap-4 border-b border-default min-w-0 flex-wrap;
}

.dt-summary-correct {
    @apply color-success font-medium;
}

.dt-summary-btn {
    @apply font-medium cursor-pointer hover:underline;
}

/* ── Column header row (Property / Saved / Now) ──────────────────── */

.dt-column-header {
    @apply flex font-medium text-muted uppercase tracking-wide bg-surface border-b border-default;
    font-size: 0.625rem;
}

.dt-column-header > div {
    padding: var(--dt-cell-py) var(--dt-px);
}

.dt-column-header > div + div {
    @apply border-l border-default;
}

/* ── Run selector dropdown ────────────────────────────────────────── */

.dt-run-select {
    @apply uppercase tracking-wide font-medium -my-0.5;
    font-size: inherit;
}

/* ── Section (collapsible header) ─────────────────────────────────── */

.dt-section-header {
    padding: var(--dt-header-py) var(--dt-px);
    @apply w-full font-medium text-heading bg-surface-secondary border-y border-default cursor-pointer hover-subtle select-none flex items-center justify-between;
}

.dt-section {
    margin-top: -1px;
}

.dt-section > div > table {
    margin-top: -1px;
}

.dt-section-chevron {
    @apply transition-transform duration-150;
    width: 10px;
    font-size: 0.5em;
}

.dt-section-chevron.open {
    transform: rotate(90deg);
}

.dt-section-content {
    @apply bg-surface;
}

.dt-section-title-group {
    @apply flex items-center gap-1.5;
}

.dt-section-title {
    @apply font-mono;
}

.dt-section-subtitle {
    @apply font-mono color-primary;
}


/* ── Add button + dropdown ────────────────────────────────────────── */

.dt-add-wrapper {
    position: relative;
}

.dt-add-btn {
    border: none;
    background: none;
    color: var(--syntax-string);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 150ms;
}
.dt-add-root:hover .dt-add-btn,
.dt-section-header:hover .dt-add-btn {
    opacity: 0.7;
}
.dt-add-btn:hover {
    opacity: 1;
}

.dt-add-root {
    display: flex;
    justify-content: flex-end;
    padding: 4px var(--dt-px);
    border-bottom: 1px solid var(--border-default);
}

.dt-add-overlay {
    position: fixed;
    inset: 0;
    z-index: 49;
}

.dt-add-dropdown {
    position: fixed;
    z-index: 50;
    min-width: 200px;
    max-height: 360px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--border-default);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
    padding: 6px;
    @apply bg-surface;
}

.dt-add-dropdown-divider {
    height: 1px;
    margin: 4px 0;
    background: var(--border-default);
}

.dt-add-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    padding: 6px 10px;
    font-size: var(--dt-font-size);
    color: var(--text-body);
    background: none;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
}
.dt-add-dropdown-item:hover {
    @apply bg-surface-secondary;
}

.dt-add-dropdown-action {
    color: var(--syntax-string);
    @apply font-medium;
}

.dt-add-dropdown-indent {
    padding-left: 26px;
}

.dt-add-dropdown-group {
    padding: 10px 10px 3px;
    font-size: calc(var(--dt-font-size) - 1px);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    @apply text-muted font-semibold select-none;
}

/* ── Dropdown cell ────────────────────────────────────────────────── */
/* Negative margin stretches container to td edges (+ 1px for the td
   border) so the fixed-position panel aligns with the cell borders.
   Padding on the trigger restores the normal cell spacing. */

.dt-dropdown-cell {
    margin: calc(-1 * var(--dt-cell-py)) calc(-1 * var(--dt-px)) calc(-1 * var(--dt-cell-py)) calc(-1 * var(--dt-px) - 1px);
}

.dt-dropdown-cell [role="button"] {
    padding: var(--dt-cell-py) var(--dt-px) var(--dt-cell-py) calc(var(--dt-px) + 1px);
}

/* ── File dropdown (toolbar) ──────────────────────────────────────── */
/* Stretch trigger to toolbar edges so the dropdown panel aligns with
   the toolbar's bottom border, matching dt-dropdown-cell behaviour. */

.dt-file-dropdown {
    @apply self-stretch;
}

.dt-file-dropdown [role="button"] {
    @apply h-full border-l border-default px-3 gap-2;
}

.dt-file-dropdown [role="option"].text-secondary {
    @apply text-body;
}

/* ── Editable cell ────────────────────────────────────────────────── */

.dt-cell-editable {
    @apply w-full h-full flex items-center relative;
}

.dt-cell-editable input {
    @apply flex-1 min-w-0 bg-transparent outline-none border-0 text-body;
    padding: 0 16px 0 0;
    font: inherit;
    line-height: inherit;
}

/* DefinitionTable validation styling — `dt-cell-invalid` / `dt-cell-valid`
   live on an inner div (`dt-cell-display` / `dt-cell-editable`) inside the
   `<td>`. The visual cell-level border + bg is hoisted onto the parent <td>
   via `:has()` so the styling sits flush with the cell edges instead of
   appearing as a small box inside the td padding. The inner div keeps only
   the text colour.

   This is the bridge for DefinitionTable until it migrates to the unified
   `ValidatedDataTable` (which puts the class on the <td> directly). */
/* Hoist the validation styling to the parent <td> so it sits flush with the
   cell edges (and so the colour beats per-syntax classes like .dt-json-string).
   The :has() rule has higher specificity than .dt-json-* so the red wins. */
.dt-panel td:has(> .dt-cell-invalid),
.dt-panel td:has(> .dt-cell-display.dt-cell-invalid),
.dt-panel td:has(> .dt-cell-editable.dt-cell-invalid) {
    /* Same red as the samples-table invalid cells and the low-confidence tint —
       one attention colour across both tables. */
    @apply text-red-600 dark:text-red-500 bg-red-50 dark:bg-red-900/20;
    border: 1px solid theme('colors.red.400');
}

.dark .dt-panel td:has(> .dt-cell-invalid) {
    border-color: theme('colors.red.600');
}

/* Force red on every descendant — overrides .dt-json-string / .dt-json-number
   syntax colours that would otherwise win on specificity ties. */
.dt-panel td:has(> .dt-cell-invalid) *,
.dt-panel td:has(> .dt-cell-display.dt-cell-invalid) *,
.dt-panel td:has(> .dt-cell-editable.dt-cell-invalid) * {
    color: inherit;
}

.dt-panel td:has(> .dt-cell-valid),
.dt-panel td:has(> .dt-cell-display.dt-cell-valid),
.dt-panel td:has(> .dt-cell-editable.dt-cell-valid) {
    @apply text-green-600 dark:text-green-500 bg-green-50 dark:bg-green-900/20;
    border: 1px solid theme('colors.green.400');
}

.dark .dt-panel td:has(> .dt-cell-valid) {
    border-color: theme('colors.green.600');
}

.dt-panel td:has(> .dt-cell-valid) *,
.dt-panel td:has(> .dt-cell-display.dt-cell-valid) *,
.dt-panel td:has(> .dt-cell-editable.dt-cell-valid) * {
    color: inherit;
}

/* Last row of a section table: under border-collapse the winning cell border is centered
   on the table's OUTER bottom edge, so its lower half paints beyond the table box and
   bleeds over the section divider below. `hidden` suppresses the collapsed edge entirely
   (it wins every border conflict); an inset shadow then draws the bottom line fully
   inside the cell so the coloured box closes above the divider. */
.dt-panel .table-body-flush > tr:last-child > td:has(> .dt-cell-invalid) {
    border-bottom-style: hidden;
    box-shadow: inset 0 -1px 0 0 theme('colors.red.400');
}

.dark .dt-panel .table-body-flush > tr:last-child > td:has(> .dt-cell-invalid) {
    box-shadow: inset 0 -1px 0 0 theme('colors.red.600');
}

.dt-panel .table-body-flush > tr:last-child > td:has(> .dt-cell-valid) {
    border-bottom-style: hidden;
    box-shadow: inset 0 -1px 0 0 theme('colors.green.400');
}

.dark .dt-panel .table-body-flush > tr:last-child > td:has(> .dt-cell-valid) {
    box-shadow: inset 0 -1px 0 0 theme('colors.green.600');
}

/* ==========================================================================
   ValidatedDataTable (vdt-*) — unified table primitive used by both
   DefinitionTable and NormalizedSamplesTable.

   Border strategy: `border-collapse: collapse` so adjacent invalid cells
   share a single 1px red border. Column separators live on <col> elements
   (col-level border, lower precedence than cell). Row separators live on
   <tr> (row-level, lower precedence than cell). Validation borders sit on
   the <td> itself (cell-level, highest precedence) so they win against
   neighbouring gray separators on every side.

   Cell layout: <td> has zero padding. The single inner element
   (`.vdt-cell-content` or `.vdt-cell-input`) carries the padding and fills
   the cell, so the validation border sits flush at the cell edge and the
   click-area is the full cell.
   ========================================================================== */

.vdt-table {
    /* Cell spacing — vertical bigger than horizontal for legibility. Single
       source of truth shared by both DefinitionTable and NormalizedSamplesTable. */
    --vdt-cell-py: 6px;
    --vdt-header-py: 4px;
    --vdt-px: 8px;
    border-collapse: collapse;
    width: 100%;
    @apply font-mono text-xs;
}

.vdt-table > colgroup > col + col {
    @apply border-l border-default;
}

.vdt-table > thead > tr {
    @apply border-b border-default;
}

.vdt-table > tbody > tr.vdt-row {
    @apply border-b border-default;
}

.vdt-table > tbody > tr.vdt-row:last-child {
    border-bottom: 0;
}

.vdt-table > thead > tr > th,
.vdt-table > tbody > tr > td {
    padding: 0;
    vertical-align: middle;
    /* Lower bound so columns can't shrink to 1-char widths and force-truncate
       data on focus. Matches the old `.normalized-samples-table` min-width. */
    min-width: 70px;
}

/* Body cells use the smaller cell padding. */
.vdt-cell-content {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    height: 100%;
    padding: var(--vdt-cell-py) var(--vdt-px);
    min-width: 0;
    /* Anchor for the per-cell hover tooltip below. */
    position: relative;
}

/* Per-cell hover tooltip — used for validation error messages. CSS-only, no JS,
   no per-render cost. Solid red, white text, shadow + arrow for clarity.
   Uses CSS Anchor Positioning (position: fixed + anchor()) so the tooltip escapes
   overflow:hidden / overflow:auto containers and flips above the cell when there's
   no room below. Same pattern as .dt-normalization-popover. */
.vdt-cell-content:hover {
    anchor-name: --vdtcellpop;
}

.vdt-cell-tooltip {
    @apply text-xs hidden z-50;
    position: fixed;
    position-anchor: --vdtcellpop;
    top: calc(anchor(bottom) + 6px);
    left: anchor(left);
    pointer-events: none;
    /* Browser tries below first; flips to above (with the arrow flipping too) when the
       tooltip wouldn't fit at the bottom of the viewport. */
    position-try-fallbacks: flip-block;
}

.vdt-cell-content:hover > .vdt-cell-tooltip {
    @apply block;
}

.vdt-cell-tooltip-inner {
    @apply block rounded-md py-1.5 px-2.5 font-medium leading-snug;
    background: theme('colors.red.600');
    color: white;
    max-width: 320px;
    white-space: normal;
    box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.25), 0 2px 6px -2px rgba(220, 38, 38, 0.4);
}

.dark .vdt-cell-tooltip-inner {
    background: theme('colors.red.500');
    box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.6), 0 2px 6px -2px rgba(248, 113, 113, 0.5);
}

/* Dropdown cell — the whole cell is the click target. Cursor: pointer is the affordance;
   chevron darkens on hover (see .vdt-cell-dropdown-chevron rule below). No bg-tint on hover
   because uncertain cells already carry a red-50 background — stacking a cas-tint tint
   on top produced a muddy color and looked like "weird hover" feedback. */
.vdt-cell-content-has-dd {
    cursor: pointer;
}

/* The CURRENT uncertain cell/row (navigation cursor). Same red background as every other
   uncertain cell — the cursor is the ring, not a second shade (two shades read as two
   different states). red-500 ring at 75% keeps contrast in light and dark mode. */
.vdt-cell-current {
    box-shadow: inset 0 0 0 2px rgb(239 68 68 / 0.75);
}

tr.dt-row-current {
    outline: 2px solid rgb(239 68 68 / 0.75);
    outline-offset: -2px;
}

/* The value display sits where the editable input would; same monospace + padding so the
   visual position is identical to plain cells. */
.vdt-cell-dropdown-trigger {
    pointer-events: none;
    user-select: none;
    /* Reserve room on the right so the value never slides under the chevron. */
    padding-right: 14px;
}

/* Chevron at the right edge — visual hint that the cell is a dropdown. pointer-events:
   none so the cell-content's onclick owns every click. */
.vdt-cell-dropdown-chevron {
    @apply text-secondary;
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    line-height: 1;
    pointer-events: none;
}

.vdt-cell-content-has-dd:hover .vdt-cell-dropdown-chevron {
    @apply text-body;
}

/* Anchor name applied to the cell when its dropdown is open. The popover (a sibling of the
   truncate div) anchors to it. */
.vdt-cell-dd-open {
    anchor-name: --vdtcelldd;
}

/* Invisible backdrop — covers the viewport and closes the dropdown when clicked. Lives below
   the popover (sibling order: backdrop first, popover second) so a click on a popover item
   doesn't bubble to the backdrop. */
.vdt-cell-dropdown-backdrop {
    position: fixed;
    inset: 0;
    z-index: 95;
    background: transparent;
}

/* Popover with the alternatives. Top layer (HTML `popover="manual"` + showPopover) so it
   escapes any ancestor overflow / containing block; positioning is set inline by JS in
   OnAfterRenderAsync — pixel-perfect aligned to the cell, no border-radius, butts up
   against the cell's bottom edge. Same monospace + text-xs as the table cells so the
   alternatives read as a continuation of the cell. */
.vdt-cell-dropdown-popover {
    @apply bg-surface border border-default overflow-y-auto font-mono text-xs;
    min-width: 160px;
    max-width: 280px;
    max-height: 320px;
    z-index: 100;
    /* HTML [popover] elements get user-agent default padding (0.25em) + margin which created
       a white gap around the items inside the popover. Reset them so items butt against the
       popover border with no inner whitespace. */
    padding: 0;
    margin: 0;
}

/* Items: roomier than table cells — the popover is a focused interaction, items get
   their own padding so they're easy to read and click. Inherits the popover's monospace
   font + text-xs but bumps padding generously. */
.vdt-cell-dropdown-item {
    @apply w-full flex items-center justify-between cursor-pointer;
    gap: 16px;
    padding: 8px 12px;
    background: transparent;
    border: 0;
    text-align: left;
    color: inherit;
    font: inherit;
}

.vdt-cell-dropdown-item + .vdt-cell-dropdown-item {
    @apply border-t border-default;
}

.vdt-cell-dropdown-item:hover {
    @apply bg-cas-tint/10;
}

.vdt-cell-dropdown-item-current {
    @apply bg-surface-secondary font-medium;
}

.vdt-cell-dropdown-item-value {
    @apply text-body;
}

.vdt-cell-dropdown-item-suffix {
    @apply text-muted whitespace-nowrap;
    font-variant-numeric: tabular-nums;
}


.vdt-cell-content-truncate {
    @apply flex-1 min-w-0 truncate;
}

.vdt-cell-input {
    width: 100%;
    height: 100%;
    /* Input elements have a browser-default min-width that would push the
       column wider on focus. min-width: 0 keeps the cell width fixed. */
    min-width: 0;
    /* No internal padding — .vdt-cell-input always lives inside .vdt-cell-content which
       already provides the cell padding via --vdt-cell-py/--vdt-px. Setting padding here
       would double up (visible as: input text drifting ~6-8px inward when a read-only
       span shows at the cell's content edge, or in advanced-mode JSON-quoted spans the
       value appearing visually higher/inset compared to editable rows). */
    padding: 0;
    background: transparent;
    border: 0;
    outline: 0;
    margin: 0;
    font: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    text-align: inherit;
    text-indent: 0;
    color: inherit;
    box-sizing: border-box;
}

/* Header background and slightly taller padding (matches dt-header-py). */
.vdt-table > thead {
    @apply bg-surface-secondary;
}

.vdt-table > thead > tr > th .vdt-cell-content {
    padding: var(--vdt-header-py) var(--vdt-px);
}

.vdt-table > thead > tr > th {
    @apply font-medium text-muted text-xs;
    text-transform: none;
}

/* Validation: cell-level borders win precedence under collapse, so the
   red/green outline shows on all 4 sides regardless of neighbouring gray.
   ONE attention colour everywhere: validation problems and low-confidence
   cells share the same red — different colours for the same "needs your
   attention" read as different states. */
.vdt-cell-invalid {
    @apply text-red-600 dark:text-red-500 bg-red-50 dark:bg-red-900/20;
    border: 1px solid theme('colors.red.400');
}

.dark .vdt-cell-invalid {
    border-color: theme('colors.red.600');
}

.vdt-cell-valid {
    @apply color-success bg-green-50 dark:bg-green-900/20;
    border: 1px solid theme('colors.green.500');
}

.dark .vdt-cell-valid {
    border-color: theme('colors.green.400');
}

/* Depth indentation: the first cell on a row pads left proportional to
   `--vdt-depth` (set inline by the table primitive). Indented inside the
   content wrapper so it doesn't shift the validation border. */
.vdt-row > td:first-child > .vdt-cell-content {
    padding-left: calc(0.75rem + var(--vdt-depth, 0) * 16px);
}

/* Section header rendered as a tr-with-colspan inside the table. */
.vdt-section-row > .vdt-section-cell {
    padding: 0;
}

.vdt-section-header {
    padding: var(--dt-header-py, 8px) var(--dt-px, 12px);
    @apply w-full font-medium text-heading bg-surface-secondary border-y border-default cursor-pointer hover-subtle select-none flex items-center justify-between;
}

.vdt-section-title-group {
    @apply flex items-center gap-1.5;
}

.vdt-section-title {
    @apply font-mono;
}

.vdt-section-subtitle {
    @apply font-mono color-primary;
}

.vdt-section-chevron {
    @apply transition-transform duration-150;
    width: 10px;
    font-size: 0.5em;
}

.vdt-section-chevron.open {
    transform: rotate(90deg);
}

/* Custom rows: full-width slots for stats, remarks, link rows, add-buttons. */
.vdt-custom-row > .vdt-custom-cell {
    padding: 0;
}

/* Outer wrapper. Flex column so toolbar + scroll viewport + footer share parent height
   correctly. `min-height: 0` lets the wrapper shrink inside a flex parent — without it
   the table sizes to its content (6000+ px on big certs) and Virtualize "sees" a huge
   viewport, defeating row virtualization. */
.vdt {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

/* Sticky-header wrapper: the table sits inside a scroll container so a sticky <thead> can pin.
   `flex: 1 1 0` + `min-height: 0` makes this the actual scroll viewport, bounded by `.vdt`. */
.vdt-scroll {
    @apply overflow-auto;
    flex: 1 1 0;
    min-height: 0;
    overscroll-behavior: contain;
}

/* ==========================================================================
   DataTable<T> — unified table component (greenfield, replaces Vdt* over time)
   See CAS.Blazor.Core/Components/DataTable/.
   ========================================================================== */

.datatable {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.datatable-scroll {
    @apply overflow-auto;
    flex: 1 1 0;
    min-height: 0;
    overscroll-behavior: contain;
}

.datatable-table {
    --datatable-cell-py: 5px;
    --datatable-px: 10px;
    /* Mirror the legacy vdt-* custom properties onto datatable-table so cell templates that
       still use `.vdt-cell-content` / `.vdt-cell-content-truncate` (NormalizedSamplesTable
       hasn't fully migrated its inner markup yet) inherit the right padding. */
    /* Body cells: roomier than the tight 3px/6px the legacy override used — the read view
       was too cramped. Headers: tighter than the 8px override so the column titles don't
       dominate vertically over the data. */
    --vdt-cell-py: 7px;
    --vdt-px: 10px;
    --vdt-header-py: 5px;
    /* Inherit the same monospace + size as .vdt-table / DefinitionTable so cell text and
       inputs render in the project's standard mono — without this, descendants fall back
       to the body's sans-serif default. */
    @apply font-mono text-xs;
    border-collapse: collapse;
    /* Fixed layout makes <col width> values authoritative — auto layout treats them as
       hints and shrinks columns containing inputs (which have no intrinsic width) below
       what the content actually needs. */
    table-layout: fixed;
    width: 100%;
}

.datatable-table > colgroup > col + col {
    @apply border-l border-default;
}

.datatable-table > thead > tr {
    @apply border-b border-default;
}

.datatable-table > tbody > tr.datatable-row {
    @apply border-b border-default;
}

.datatable-table > tbody > tr.datatable-row:last-child {
    border-bottom: 0;
}

.datatable-table > thead > tr > th,
.datatable-table > tbody > tr > td {
    padding: 0;
    vertical-align: middle;
    min-width: 70px;
}

.datatable-table > thead {
    @apply bg-surface-secondary;
}

.datatable-table > thead > tr > th {
    @apply font-medium text-muted text-xs;
    text-transform: none;
}

/* Header cells delegate padding to the inner .datatable-cell, with a tighter vertical
   value than body cells (matches the vdt-table convention exactly). */
.datatable-table > thead > tr > th .datatable-cell {
    padding: var(--vdt-header-py) var(--vdt-px);
}

.datatable-thead-sticky {
    @apply sticky top-0 z-10;
}

/* Body cell wrapper. Same metrics for display and editing-input states so the swap doesn't
   shift content — the input replaces the div in place with matching padding/line-height. */
.datatable-cell,
.datatable-cell-input {
    width: 100%;
    height: 100%;
    padding: var(--datatable-cell-py) var(--datatable-px);
    line-height: 1.25;
    font: inherit;
    box-sizing: border-box;
    min-width: 0;
}

.datatable-cell {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.datatable-cell-clickable {
    cursor: pointer;
}

.datatable-cell-input {
    background: transparent;
    border: 0;
    outline: 0;
    text-indent: 0;
    color: inherit;
}

.datatable-cell-input:focus {
    background: transparent;
}

/* First-column inset scales with row depth so nested sections indent without a separate
   class per level. */
.datatable-row > td:first-child > .datatable-cell {
    padding-left: calc(var(--datatable-px) + var(--datatable-depth, 0) * 16px);
}

/* Section headers + custom rows render as full-width tr (colspan handled inline). */
.datatable-section-row > .datatable-section-cell,
.datatable-custom-row > .datatable-custom-cell {
    padding: 0;
}

.datatable-section-header {
    @apply flex items-center gap-2 cursor-pointer;
    padding: 6px var(--datatable-px);
}

.datatable-section-title {
    @apply font-medium;
}

.datatable-section-subtitle {
    @apply text-muted text-xs;
}

.datatable-section-actions {
    margin-left: auto;
}

.datatable-custom-cell {
    padding: 6px var(--datatable-px);
}

/* Validation classes — adapter sets these on td via CellClassProvider. */
.datatable-cell-invalid {
    box-shadow: inset 0 0 0 2px rgba(239, 68, 68, 0.85);
}

.datatable-cell-valid {
    box-shadow: inset 0 0 0 2px rgba(34, 197, 94, 0.85);
}

.datatable-cell-corrected {
    background: rgba(34, 197, 94, 0.10);
}

.datatable-cell-uncertain {
    background: rgba(251, 191, 36, 0.18);
}

.datatable-cell-focused {
    background: rgba(255, 220, 0, 0.35);
    box-shadow: inset 0 0 0 2px rgba(220, 180, 0, 1);
}

.vdt-thead-sticky {
    @apply sticky top-0 z-10;
}

.dt-cell-overlay {
    @apply absolute flex items-center gap-1 pointer-events-none;
    right: 0;
    top: 0;
    bottom: 0;
}

.dt-cell-overlay > * {
    pointer-events: auto;
}

.dt-delete-field {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    margin-left: 4px;
    opacity: 0;
    transition: opacity 150ms;
    @apply text-red-600 dark:text-red-500;
}

.dt-cell-display:hover .dt-delete-field {
    opacity: 1;
}

.dt-cell-reset {
    @apply text-placeholder transition-colors;
    font-size: 0.625rem;
}

.dt-cell-reset:hover {
    @apply text-heading;
}

/* ── Display cell ─────────────────────────────────────────────────── */

.dt-cell-display {
    @apply w-full h-full flex items-center cursor-pointer;
}


.dt-status-dot {
    @apply w-2 h-2 rounded-full flex-shrink-0 mr-1;
}

/* ── JSON syntax colours ──────────────────────────────────────────── */

.dt-json-null {
    color: var(--syntax-literal);
    @apply italic;
}

.dt-json-string {
    color: var(--syntax-string);
}

.dt-json-number {
    color: var(--syntax-number);
}

.dt-json-boolean {
    color: var(--syntax-literal);
}

.dt-json-value {
    @apply flex-1 min-w-0 break-all;
}

.dt-now-value {
    @apply break-all;
}

/* ── Stats table ──────────────────────────────────────────────────── */

.dt-stats-table {
    @apply w-full;
    table-layout: fixed;
}

.dt-stats-body {
    @apply divide-y divide-default;
}

.dt-stats-label {
    @apply py-1 pr-2 font-mono text-muted align-top border-r border-default text-right;
    padding-left: var(--dt-px);
}

.dt-stats-value {
    @apply py-1 px-2 align-top font-mono;
}

/* ── Remarks section ──────────────────────────────────────────────── */

.dt-remarks {
    @apply divider-t px-4 py-3;
}

/* ===========================================
   NORMALIZED SAMPLES TABLE
   =========================================== */

.normalized-samples-table {
    @apply font-mono text-xs;
    table-layout: auto;
    /* `separate` lets per-cell borders (notably the validation indicator)
       render on all four sides without competing against neighbouring cells.
       `border-spacing: 0` keeps the visual layout flush like collapse. */
    border-collapse: separate;
    border-spacing: 0;
}

.normalized-samples-table .table-header-cell {
    @apply px-3 py-1.5 normal-case text-xs;
    min-width: 70px;
}

.normalized-samples-table .table-cell {
    @apply px-3 py-1.5 text-xs;
}

/* Vertical separators between every column. The `:not(.dt-cell-invalid)`
   guard keeps the gray border off invalid cells so the red validation
   border doesn't compete with column-separator gray. */
.normalized-samples-table .table-header-cell:not(:last-child),
.normalized-samples-table .table-cell:not(:last-child):not(.dt-cell-invalid):not(.dt-cell-valid) {
    @apply border-r border-default;
}

/* Horizontal separators per row. In `separate` mode the existing
   `tr.table-row { border-b }` is ignored, so the line is moved to each body
   cell. The header gets its bottom line from `sticky-header-shadow` already,
   so it's intentionally excluded here. The last row drops its border so the
   table edge stays clean. */
.normalized-samples-table tbody .table-cell:not(.dt-cell-invalid):not(.dt-cell-valid) {
    @apply border-b border-default;
}

.normalized-samples-table tbody tr:last-child .table-cell {
    border-bottom: 0;
}

.normalized-level-prefix {
    @apply font-semibold mr-2;
}

.normalized-level-heat {
    @apply text-blue-500;
}

.normalized-level-product {
    @apply text-amber-600;
}

.normalized-level-sample {
    @apply text-emerald-600;
}

.normalized-samples-table .table-cell.dt-cell-corrected {
    @apply text-amber-600 dark:text-amber-400 font-semibold;
}

.normalized-samples-table .normalized-cell-input {
    @apply w-full bg-transparent outline-none border-0 text-body p-0 m-0;
    font: inherit;
}

/* Source cell highlight when linked to a bounding box.
   Two shapes:
   - On a single <td> (NormalizedSamplesTable cell click): highlight that cell directly.
   - On a <tr> (DefinitionTable row whose id matches the field path): highlight only the
     value cell (last column), never the property/label cell. */
td.field-source-active,
tr.field-source-active > td:last-child,
.vdt-cell-content.field-source-active {
    box-shadow: inset 0 0 0 2px rgba(220, 180, 0, 1) !important;
}

/* ── Segmented control (radio-group as pill row) ────────────────── */

.segmented-control {
    @apply inline-flex flex-wrap rounded-md border border-default bg-surface overflow-hidden;
}

.segmented-control-segment {
    @apply px-3 py-1.5 text-sm font-medium text-secondary bg-transparent;
    @apply border-l border-default;
    @apply transition-colors;
    @apply flex items-center gap-1.5;
    cursor: pointer;
}

.segmented-control-segment:first-child {
    border-left: 0;
}

.segmented-control-segment:hover:not(:disabled):not(.selected) {
    @apply bg-surface-hover text-heading;
}

.segmented-control-segment.selected,
.segmented-control-segment.selected:hover {
    @apply bg-cas-tint text-white;
}

.segmented-control-segment:disabled {
    @apply cursor-not-allowed;
}

/* ApexCharts legend labels: ApexCharts inlines the text colour, which defaults to a
   washed-out grey that's hard to read on our surfaces. Override it (needs !important to
   beat the inline style) with a theme-aware readable tone. */
.apexcharts-legend-text {
    color: #374151 !important; /* gray-700 */
}
.dark .apexcharts-legend-text {
    color: #d1d5db !important; /* gray-300 */
}