/**
 * Optimized Panel Layout Styles
 * Using CSS variables for consistency and performance
 */

/* ============================================
   RESIZABLE PANEL BASE
   ============================================ */
.resizable-panel {
  position: relative;
  background: white;
  box-shadow: var(--shadow-lg);
  transition: width var(--transition-base), 
              height var(--transition-base), 
              left var(--transition-base), 
              right var(--transition-base);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  will-change: width, height;
  contain: layout style paint;
}

.resizable-panel-left {
  position: fixed;
  left: 0;
  top: var(--header-height);
  bottom: var(--footer-height);
  z-index: var(--z-panels);
}

.resizable-panel-right {
  position: fixed;
  right: 0;
  top: var(--header-height);
  bottom: var(--footer-height);
  z-index: var(--z-panels);
}

.resizable-panel-bottom {
  position: fixed;
  bottom: var(--footer-height);
  top: var(--header-height);
  z-index: var(--z-panels);
}

.resizable-panel.collapsed {
  transition: width var(--transition-base), height var(--transition-base);
}

/* ============================================
   RESIZE HANDLES
   ============================================ */
.resize-handle {
  position: absolute;
  background: transparent;
  cursor: col-resize;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.resize-handle:focus {
  outline: 2px solid var(--color-primary-500);
  outline-offset: -2px;
}

.resize-handle-left {
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
}

.resize-handle-right {
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
}

.resize-handle-bottom {
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: row-resize;
}

.resize-handle:hover {
  background: rgba(59, 130, 246, 0.3);
}

.resize-handle-indicator {
  width: 2px;
  height: 40px;
  background: var(--color-primary-500);
  border-radius: 1px;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.resize-handle:hover .resize-handle-indicator {
  opacity: 1;
}

.resize-handle-bottom .resize-handle-indicator {
  width: 40px;
  height: 2px;
}

/* ============================================
   COLLAPSE TOGGLE BUTTONS
   ============================================ */
.collapse-toggle {
  position: absolute;
  background: var(--color-primary-500);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.collapse-toggle:hover {
  background: var(--color-primary-600);
  transform: scale(1.1);
}

.collapse-toggle:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.collapse-toggle:active {
  transform: scale(0.95);
}

.collapse-toggle-left {
  right: -16px;
  top: 50%;
  transform: translateY(-50%);
}

.collapse-toggle-right {
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
}

.collapse-toggle-bottom {
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
}

.resizable-panel.collapsed .collapse-toggle-left {
  right: -16px;
}

.resizable-panel.collapsed .collapse-toggle-right {
  left: -16px;
}

.resizable-panel.collapsed .collapse-toggle-bottom {
  top: -16px;
}

.panel-content {
  flex: 1;
  overflow: auto;
  padding: var(--spacing-md);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   HEADER - 100% WIDTH
   ============================================ */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: var(--header-height);
  min-height: var(--header-height); /* Prevent collapse */
  max-height: var(--header-height); /* Prevent expansion */
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-md);
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  contain: layout style paint;
  /* Ensure header doesn't cause layout shifts */
  box-sizing: border-box;
  /* Improve text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Skip Navigation Link - Accessibility Best Practice */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  z-index: calc(var(--z-header) + 1);
  padding: var(--spacing-md);
  background: var(--color-primary-600);
  color: white;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 var(--radius-md) 0;
  transition: top var(--transition-base);
}

.skip-link:focus {
  top: 0;
  outline: 2px solid white;
  outline-offset: 2px;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  padding: 0 var(--spacing-lg);
  height: 100%;
  margin: 0 auto;
}

.header-left {
  flex: 0 0 auto;
  min-width: 0;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 500px;
  margin: 0 var(--spacing-xl);
  min-width: 0;
}

.header-search {
  position: relative;
  width: 100%;
  max-width: 400px;
}

.header-search i {
  position: absolute;
  left: var(--spacing-md);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-gray-400);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md) var(--spacing-sm) 2.5rem;
  border: none;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 0.875rem;
  outline: none;
  transition: background var(--transition-base);
  -webkit-appearance: none;
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.search-input:focus {
  background: rgba(255, 255, 255, 0.3);
}

.header-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  min-width: 0;
}

.header-btn {
  position: relative;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  /* WCAG 2.1 Level AAA: Minimum 44x44px touch target */
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  width: var(--touch-target-comfortable);
  height: var(--touch-target-comfortable);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-base), transform var(--transition-fast);
  outline: none;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  /* Improve touch interaction */
  touch-action: manipulation;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.header-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.4);
}

.header-btn:focus {
  outline: 3px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
  /* High contrast for focus visibility */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.header-btn:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--color-error);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 1.2;
}

.header-user {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background var(--transition-base);
  flex-shrink: 0;
}

.header-user:hover {
  background: rgba(255, 255, 255, 0.2);
}

.user-avatar {
  /* Ensure touch target meets WCAG standards */
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  width: var(--touch-target-comfortable);
  height: var(--touch-target-comfortable);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  opacity: 0.8;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   NAVIGATION PANEL
   ============================================ */
.navigation-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.navigation-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-gray-200);
  background: var(--gradient-primary);
  color: white;
  flex-shrink: 0;
}

.navigation-menu {
  flex: 1;
  padding: var(--spacing-sm);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-md);
  margin-bottom: var(--spacing-xs);
  border-radius: var(--radius-md);
  color: var(--color-gray-700);
  text-decoration: none;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-900);
}

.nav-item.active {
  background: var(--gradient-primary);
  color: white;
  font-weight: 600;
}

/* ============================================
   AI PANEL
   ============================================ */
.ai-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.ai-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-gray-200);
  background: var(--gradient-ai);
  color: white;
  flex-shrink: 0;
}

.ai-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.ai-chat {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.ai-message {
  display: flex;
  gap: var(--spacing-md);
  align-items: flex-start;
}

.ai-message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--color-gray-200);
  color: var(--color-gray-500);
}

.ai-message.user .message-avatar {
  background: var(--color-primary-500);
  color: white;
}

.message-content {
  flex: 1;
  max-width: 80%;
  min-width: 0;
}

.message-text {
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  background: var(--color-gray-100);
  color: var(--color-gray-900);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-message.user .message-text {
  background: var(--color-primary-500);
  color: white;
}

.message-time {
  font-size: 0.75rem;
  color: var(--color-gray-500);
  margin-top: var(--spacing-xs);
  padding: 0 var(--spacing-sm);
}

.ai-input-area {
  display: flex;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  border-top: 1px solid var(--color-gray-200);
  background: white;
  flex-shrink: 0;
}

.ai-input {
  flex: 1;
  padding: var(--spacing-md);
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-base);
  -webkit-appearance: none;
  min-width: 0;
}

.ai-input:focus {
  border-color: var(--color-primary-500);
}

.ai-send-btn {
  padding: var(--spacing-md) var(--spacing-md);
  background: var(--color-primary-500);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-base);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.ai-send-btn:hover {
  background: var(--color-primary-600);
}

/* ============================================
   BOTTOM PANEL
   ============================================ */
.bottom-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-gray-800);
  color: var(--color-gray-50);
}

.bottom-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-md);
  border-bottom: 1px solid var(--color-gray-700);
  background: var(--color-gray-900);
  flex-shrink: 0;
}

.bottom-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.action-btn {
  padding: var(--spacing-sm);
  background: var(--color-gray-700);
  color: var(--color-gray-50);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-base);
  outline: none;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:hover {
  background: var(--color-gray-600);
}

.action-btn:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.bottom-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-sm);
  font-family: var(--font-family-mono);
  font-size: 0.875rem;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.log-entry {
  display: flex;
  gap: var(--spacing-md);
  padding: var(--spacing-xs) 0;
  border-bottom: 1px solid var(--color-gray-700);
  transition: background-color var(--transition-fast);
}

.log-entry:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.log-time {
  color: var(--color-gray-400);
  min-width: 80px;
  flex-shrink: 0;
}

.log-level {
  min-width: 60px;
  font-weight: 600;
  flex-shrink: 0;
}

.log-level.log-info {
  color: #60a5fa;
}

.log-level.log-warning {
  color: #fbbf24;
}

.log-level.log-error {
  color: #f87171;
}

.log-message {
  flex: 1;
  color: var(--color-gray-50);
  word-break: break-word;
  overflow-wrap: break-word;
}

.log-empty {
  text-align: center;
  color: var(--color-gray-500);
  padding: var(--spacing-xl);
  font-style: italic;
}

/* ============================================
   APP LAYOUT
   ============================================ */
.app-layout {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--color-gray-50);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: var(--footer-height);
  background: var(--gradient-primary);
  z-index: var(--z-footer);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--spacing-md);
  contain: layout style paint;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 100%;
  font-size: 0.625rem;
  color: rgba(255, 255, 255, 0.8);
}

.footer-text {
  font-weight: 500;
}

.footer-links {
  display: flex;
  gap: var(--spacing-md);
}

.footer-link {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: color var(--transition-base);
}

.footer-link:hover {
  color: white;
}

.footer-link:focus {
  outline: 1px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* ============================================
   ACCESSIBILITY UTILITIES
   ============================================ */
/* Screen reader only - visually hidden but accessible to assistive tech */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Ensure sr-only is available globally */
#app .sr-only,
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border-width: 0 !important;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1024px) {
  .header-center {
    max-width: 300px;
    margin: 0 var(--spacing-md);
  }
  
  .header-search {
    max-width: 250px;
  }
  
  .user-info {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-header {
    height: var(--header-height-mobile);
    min-height: var(--header-height-mobile);
    max-height: var(--header-height-mobile);
  }
  
  .header-center {
    display: none;
  }
  
  .header-title {
    font-size: 1rem;
  }
  
  .header-user {
    padding: var(--spacing-xs);
  }
  
  /* Maintain touch target size on mobile */
  .user-avatar {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    width: var(--touch-target-comfortable);
    height: var(--touch-target-comfortable);
  }
}

@media (max-width: 640px) {
  .header-content {
    padding: 0 var(--spacing-md);
  }
  
  .header-right {
    gap: var(--spacing-sm);
  }
  
  /* Maintain minimum touch target on small screens */
  .header-btn {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    width: var(--touch-target-min);
    height: var(--touch-target-min);
  }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* GPU acceleration for smooth animations */
.resizable-panel,
.app-header,
.app-footer {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Optimize scrolling */
.panel-content,
.ai-chat,
.bottom-content,
.main-content,
.navigation-menu {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.panel-content::-webkit-scrollbar,
.ai-chat::-webkit-scrollbar,
.bottom-content::-webkit-scrollbar,
.main-content::-webkit-scrollbar,
.navigation-menu::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.panel-content::-webkit-scrollbar-track,
.ai-chat::-webkit-scrollbar-track,
.bottom-content::-webkit-scrollbar-track,
.main-content::-webkit-scrollbar-track,
.navigation-menu::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb,
.ai-chat::-webkit-scrollbar-thumb,
.bottom-content::-webkit-scrollbar-thumb,
.main-content::-webkit-scrollbar-thumb,
.navigation-menu::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.panel-content::-webkit-scrollbar-thumb:hover,
.ai-chat::-webkit-scrollbar-thumb:hover,
.bottom-content::-webkit-scrollbar-thumb:hover,
.main-content::-webkit-scrollbar-thumb:hover,
.navigation-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}
