/**
 * Viewport Containment CSS Classes
 *
 * Reusable classes to prevent horizontal overflow and ensure
 * content stays within viewport bounds.
 *
 * See docs/ui/tlt-ui-standards.md for usage guidelines.
 */

/* ==========================================================================
   Page-Level Containment
   ========================================================================== */

/**
 * .viewport-safe
 * Apply to page-level containers to prevent horizontal overflow.
 * This is the primary safeguard against content spilling off-screen.
 */
.viewport-safe {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

/**
 * .viewport-scroll-y
 * Page container that allows vertical scroll but prevents horizontal.
 */
.viewport-scroll-y {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

/* ==========================================================================
   Flexbox Shrinking
   ========================================================================== */

/**
 * .flex-shrinkable
 * Apply to flex children that should shrink below their content size.
 * This is critical for preventing overflow in flex layouts.
 */
.flex-shrinkable {
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}

/**
 * .flex-no-shrink
 * Flex child that maintains its size (won't shrink).
 */
.flex-no-shrink {
  flex-shrink: 0;
}

/* ==========================================================================
   Multi-Pane Layouts
   ========================================================================== */

/**
 * .pane-layout
 * Container for multi-pane (2-3 column) layouts.
 * Handles overflow and provides consistent gap.
 */
.pane-layout {
  display: flex;
  gap: 1rem;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

/**
 * .pane-layout--vertical
 * Modifier for vertical (stacked) pane layout.
 */
.pane-layout--vertical {
  flex-direction: column;
}

/**
 * .pane-fixed
 * Fixed-width pane with responsive sizing using clamp().
 * Default: 48px min, 20vw preferred, 320px max.
 */
.pane-fixed {
  flex: 0 1 auto;
  width: clamp(48px, 20vw, 320px);
  min-width: 0;
  overflow: hidden;
}

/**
 * .pane-fixed--narrow
 * Narrower fixed pane (max 240px).
 */
.pane-fixed--narrow {
  width: clamp(48px, 18vw, 240px);
}

/**
 * .pane-fixed--wide
 * Wider fixed pane (max 400px).
 */
.pane-fixed--wide {
  width: clamp(48px, 25vw, 400px);
}

/**
 * .pane-flexible
 * Fills remaining space and shrinks as needed.
 */
.pane-flexible {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

/**
 * .pane-collapsed
 * Collapsed pane state (fixed narrow width).
 */
.pane-collapsed {
  width: 48px !important;
  min-width: 48px !important;
  flex-shrink: 0;
}

/* Responsive: stack panes on smaller screens */
@media (max-width: 1024px) {
  .pane-layout {
    flex-direction: column;
  }

  .pane-fixed,
  .pane-fixed--narrow,
  .pane-fixed--wide {
    width: 100%;
    max-height: 40vh;
  }

  .pane-collapsed {
    width: 100% !important;
    min-width: 100% !important;
    max-height: 48px !important;
  }
}

/* ==========================================================================
   Table Overflow Handling
   ========================================================================== */

/**
 * .table-scroll
 * Wrapper for tables that may overflow horizontally.
 * Provides smooth horizontal scrolling.
 */
.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

/**
 * .table-scroll--fade
 * Adds fade indicator when content is scrollable.
 * Requires JavaScript to add .has-overflow class.
 */
.table-scroll--fade {
  position: relative;
}

.table-scroll--fade::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to right, transparent, white);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.dark .table-scroll--fade::after {
  background: linear-gradient(to right, transparent, #1f2937);
}

.table-scroll--fade.has-overflow::after {
  opacity: 1;
}

/**
 * .table-no-squish
 * Prevents table columns from being squished too small.
 */
.table-no-squish {
  min-width: max-content;
}

/* ==========================================================================
   Text Truncation
   ========================================================================== */

/**
 * .text-truncate
 * Single-line text truncation with ellipsis.
 */
.text-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/**
 * .text-truncate-2
 * Two-line text truncation (requires -webkit).
 */
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/**
 * .text-truncate-3
 * Three-line text truncation.
 */
.text-truncate-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Adaptive Text (Dynamic Font Sizing Support)
   ========================================================================== */

/**
 * .text-adaptive
 * Text that uses clamp() for responsive sizing.
 * Works well with dynamic font sizing feature.
 */
.text-adaptive {
  font-size: clamp(10px, 1.2vw, 14px);
}

.text-adaptive--sm {
  font-size: clamp(9px, 1vw, 12px);
}

.text-adaptive--lg {
  font-size: clamp(12px, 1.5vw, 16px);
}

/* ==========================================================================
   Content Containment
   ========================================================================== */

/**
 * .contain-content
 * CSS containment for performance and isolation.
 * Prevents layout shifts from affecting parent.
 */
.contain-content {
  contain: content;
}

/**
 * .contain-layout
 * Layout containment only.
 */
.contain-layout {
  contain: layout;
}

/**
 * .contain-paint
 * Paint containment - creates new stacking context.
 */
.contain-paint {
  contain: paint;
}

/* ==========================================================================
   Overflow Utilities
   ========================================================================== */

/**
 * Overflow control utilities
 */
.overflow-hidden {
  overflow: hidden;
}

.overflow-x-hidden {
  overflow-x: hidden;
}

.overflow-y-auto {
  overflow-y: auto;
}

.overflow-x-auto {
  overflow-x: auto;
}

/* ==========================================================================
   Scrollbar Styling
   ========================================================================== */

/**
 * .scrollbar-thin
 * Thin, subtle scrollbar styling.
 */
.scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.scrollbar-thin::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Dark mode scrollbar */
.dark .scrollbar-thin {
  scrollbar-color: #475569 transparent;
}

.dark .scrollbar-thin::-webkit-scrollbar-thumb {
  background: #475569;
}

.dark .scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

/**
 * .scrollbar-hidden
 * Hides scrollbar but keeps scroll functionality.
 */
.scrollbar-hidden {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scrollbar-hidden::-webkit-scrollbar {
  display: none;
}
