/* Main Fault Analysis Application Styles */

:root {
  /* Primary Colors */
  --primary-color: #2196F3;
  --primary-dark: #1976D2;
  --primary-light: #64B5F6;
  
  /* Neutral Colors */
  --neutral-50: #FAFAFA;
  --neutral-100: #F5F5F5;
  --neutral-200: #EEEEEE;
  --neutral-300: #E0E0E0;
  --neutral-500: #9E9E9E;
  --neutral-700: #616161;
  --neutral-900: #212121;
  
  /* Analysis Type Colors */
  --sem-color: #2E7D32;
  --afm-color: #F57C00;
  
  /* Status Colors */
  --success-color: #4CAF50;
  --warning-color: #FF9800;
  --error-color: #F44336;
  
  /* Shadows */
  --shadow-1: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  --shadow-2: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}

/* Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--neutral-100);
  color: var(--neutral-900);
  line-height: 1.5;
}

/* Layout */
.main-container {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
  position: relative;
}

/* Header */
.app-header {
  background: white;
  border-bottom: 1px solid var(--neutral-200);
  box-shadow: var(--shadow-1);
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  height: 32px;
}

/* Playground Panel */
.playground-panel {
  width: 320px;
  min-width: 280px;
  max-width: 400px;
  background: white;
  border-right: 1px solid var(--neutral-200);
  display: flex;
  flex-direction: column;
  overflow: visible;
  position: relative;
  transition: width 0.3s ease, margin-left 0.3s ease;
  z-index: 50;
}

.playground-panel.collapsed {
  width: 12px;
  min-width: 12px;
  overflow: visible !important;
}

.playground-panel.collapsed .playground-header,
.playground-panel.collapsed .playground-content {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Ensure toggle remains accessible when collapsed */
.playground-panel.collapsed .panel-toggle-wrapper {
  opacity: 1;
  right: -12px;
}

/* Subtle Center Toggle */
.panel-toggle-wrapper {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.playground-panel:hover .panel-toggle-wrapper,
.panel-toggle-wrapper:hover,
.playground-panel.collapsed .panel-toggle-wrapper {
  opacity: 1;
}

.panel-toggle-center {
  width: 24px;
  height: 48px;
  padding: 0;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--neutral-200);
  border-radius: 0 12px 12px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: all 0.2s ease;
  box-shadow: 2px 0 8px rgba(0,0,0,0.08);
}

.panel-toggle-center:hover {
  background: white;
  box-shadow: 2px 0 12px rgba(0,0,0,0.12);
  width: 28px;
}

.toggle-line {
  width: 12px;
  height: 2px;
  background: var(--neutral-400);
  transition: all 0.2s ease;
  border-radius: 1px;
}

.panel-toggle-center:hover .toggle-line {
  background: var(--primary-color);
  width: 14px;
}

/* Rotate lines when collapsed */
.playground-panel.collapsed .toggle-line:nth-child(1) {
  transform: rotate(45deg) translate(3px, 3px);
}

.playground-panel.collapsed .toggle-line:nth-child(2) {
  opacity: 0;
}

.playground-panel.collapsed .toggle-line:nth-child(3) {
  transform: rotate(-45deg) translate(3px, -3px);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .playground-panel {
    width: 280px;
    min-width: 240px;
  }
}

@media (max-width: 992px) {
  .playground-panel {
    width: 260px;
    min-width: 220px;
  }
  
  .panel-toggle-wrapper {
    opacity: 0.7;
  }
  
  .playground-panel:hover .panel-toggle-wrapper {
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .playground-panel {
    position: fixed;
    left: 0;
    top: 60px;
    z-index: 100;
    height: calc(100vh - 60px);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    transform: translateX(0);
    width: 280px;
  }
  
  .playground-panel.collapsed {
    transform: translateX(-268px); /* Leave 12px visible */
    margin-left: 0;
  }
  
  .panel-toggle-wrapper {
    opacity: 1;
    right: -16px;
  }
  
  .panel-toggle-center {
    width: 32px;
    height: 56px;
  }
  
  .content-area {
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .playground-panel {
    width: 100%;
    max-width: 100%;
  }
  
  .panel-toggle-wrapper {
    right: -20px;
  }
}

.playground-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--neutral-200);
}

.playground-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}


.context-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--neutral-700);
}

.context-badge {
  padding: 4px 12px;
  border-radius: 16px;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
}

.context-badge.sem {
  background: var(--sem-color);
  color: white;
}

.context-badge.afm {
  background: var(--afm-color);
  color: white;
}

.context-badge.all {
  background: var(--primary-color);
  color: white;
}

.playground-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
}

/* Content Area */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left 0.3s ease;
}

/* Action Bar */
.action-bar {
  background: white;
  padding: 16px 20px;
  border-bottom: 1px solid var(--neutral-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:hover {
  background: var(--primary-dark);
}

.action-btn:disabled {
  background: var(--neutral-300);
  color: var(--neutral-500);
  cursor: not-allowed;
}

/* Tab Navigation */
.tab-container {
  background: white;
  border-bottom: 1px solid var(--neutral-200);
}

.tab-nav {
  display: flex;
  gap: 8px;
  padding: 0 20px;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.tab-nav::-webkit-scrollbar {
  height: 4px;
}

.tab-nav::-webkit-scrollbar-track {
  background: var(--neutral-100);
}

.tab-nav::-webkit-scrollbar-thumb {
  background: var(--neutral-400);
  border-radius: 2px;
}

@media (max-width: 768px) {
  .tab-nav {
    padding: 0 10px;
  }
  
  .tab-btn {
    padding: 10px 12px;
    font-size: 13px;
  }
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--neutral-700);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  background: var(--neutral-50);
  color: var(--neutral-900);
}

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

.tab-btn:disabled {
  color: var(--neutral-400);
  cursor: not-allowed;
}

.tab-type-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  color: white;
}

.tab-type-icon.sem {
  background: var(--sem-color);
}

.tab-type-icon.afm {
  background: var(--afm-color);
}

.tab-type-icon.summary {
  background: var(--primary-color);
}

/* Tab Content */
.tab-content-area {
  flex: 1;
  overflow-y: auto;
  background: var(--neutral-50);
}

#tab-content {
  padding: 20px;
  min-height: 100%;
}

/* Loading States */
.loading-overlay,
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--neutral-500);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--neutral-200);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* File Status */
.file-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--neutral-50);
  border-radius: 20px;
  font-size: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neutral-400);
}

.status-dot.processing {
  background: var(--warning-color);
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* Tab disabled state */
.tab-btn.tab-disabled,
.analysis-tab-btn.tab-disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
    position: relative;
}

.tab-btn.tab-disabled::after,
.analysis-tab-btn.tab-disabled::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(0, 0, 0, 0.05) 10px,
        rgba(0, 0, 0, 0.05) 20px
    );
    border-radius: inherit;
    pointer-events: none;
}

.tab-btn.tab-disabled:hover,
.analysis-tab-btn.tab-disabled:hover {
    background-color: inherit !important;
    transform: none !important;
}

/* Operation indicator */
.operation-indicator {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #f59e0b;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateX(-50%) translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.operation-indicator .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Tab Preload Overlay */
.tab-preload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.preload-content {
    background: white;
    border-radius: 12px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.preload-header h2 {
    margin: 0 0 10px 0;
    color: #1f2937;
    font-size: 24px;
}

.preload-header p {
    margin: 0 0 30px 0;
    color: #6b7280;
    font-size: 16px;
}

.preload-progress {
    margin-bottom: 30px;
}

.preload-progress .progress-bar-container {
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 15px;
}

.preload-progress .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6 0%, #2563eb 100%);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.preload-progress .progress-text {
    font-size: 14px;
    color: #4b5563;
    font-weight: 500;
}

.loading-animation {
    display: flex;
    justify-content: center;
}

.loading-animation .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Tab loading state */
.tab-btn.tab-loading {
    opacity: 0.6;
    cursor: wait !important;
    position: relative;
}

.tab-btn.tab-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 50%,
        transparent 100%
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 56px;
  height: 56px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 99;
  font-size: 24px;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Adjust main container for mobile */
  .main-container {
    padding-left: 0;
  }
  
  /* Header adjustments */
  .app-header {
    padding: 0 10px;
  }
  
  .header-content {
    gap: 10px;
  }
  
  .logo {
    height: 24px;
  }
  
  /* Content area adjustments */
  #tab-content {
    padding: 15px;
  }
  
  /* Form adjustments */
  .form-control {
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Button adjustments */
  .btn {
    padding: 12px 20px;
    font-size: 16px;
  }
  
  /* Analysis section adjustments */
  .analysis-section {
    padding: 16px;
    margin-bottom: 16px;
  }
  
  .section-title {
    font-size: 18px;
  }
}

/* Responsive utilities */
.d-none-mobile {
  display: block;
}

@media (max-width: 768px) {
  .d-none-mobile {
    display: none;
  }
}

/* Overlay for mobile menu */
.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 98;
}

@media (max-width: 768px) {
  .mobile-overlay.open {
    display: block;
  }
}

/* Alerts */
.alert {
  padding: 16px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.alert.alert-success {
  background: #E8F5E9;
  color: #1B5E20;
  border: 1px solid #4CAF50;
}

.alert.alert-warning {
  background: #FFF3E0;
  color: #E65100;
  border: 1px solid #FF9800;
}

.alert.alert-danger {
  background: #FFEBEE;
  color: #B71C1C;
  border: 1px solid #F44336;
}

/* Upload Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  max-width: 90vw;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  margin: 1rem;
}

@media (min-width: 576px) {
  .modal {
    max-width: 500px;
    width: 90%;
  }
}

@media (min-width: 992px) {
  .modal {
    max-width: 800px;
  }
}

/* Bootstrap modal overrides */
.modal-dialog {
  max-width: 90vw !important;
  margin: 1.75rem auto;
}

.modal-lg {
  max-width: 90vw !important;
}

@media (min-width: 576px) {
  .modal-dialog {
    max-width: 500px !important;
  }
  .modal-lg {
    max-width: 800px !important;
  }
}

@media (min-width: 992px) {
  .modal-lg {
    max-width: 900px !important;
  }
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--neutral-200);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

@media (max-width: 576px) {
  .modal-body {
    padding: 15px;
    max-height: calc(90vh - 120px);
  }
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--neutral-200);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--neutral-700);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--neutral-300);
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: white;
  color: var(--neutral-700);
  border: 1px solid var(--neutral-300);
}

.btn-secondary:hover {
  background: var(--neutral-50);
}

/* Analysis Results */
.analysis-section {
  background: white;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-1);
}

/* Fix for nested tab clickability */
.analysis-tab-btn {
  position: relative;
  z-index: 10;
  pointer-events: auto !important;
}

.analysis-tabs {
  position: relative;
  z-index: 5;
}

.analysis-content {
  position: relative;
  z-index: 1;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--neutral-900);
}

/* Image Comparison */
.image-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .image-comparison {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

.image-container {
  background: var(--neutral-50);
  border-radius: 8px;
  overflow: hidden;
}

.image-header {
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid var(--neutral-200);
  font-weight: 500;
}

.image-header.control {
  color: var(--success-color);
}

.image-header.failure {
  color: var(--error-color);
}

.image-wrapper {
  position: relative;
  padding: 16px;
}

.image-wrapper img {
  width: 100%;
  height: auto;
  border-radius: 4px;
}

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

@media (max-width: 576px) {
  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.metric-card {
  background: var(--neutral-50);
  padding: 16px;
  border-radius: 8px;
  text-align: center;
}

.metric-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 4px;
}

.metric-label {
  font-size: 14px;
  color: var(--neutral-600);
}

/* Progress Bar & Analysis Spinner */
.analysis-spinner {
  display: none;
}

.htmx-request.analysis-spinner {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.spinner-container {
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  min-width: 280px;
  max-width: 90vw;
  width: 100%;
}

@media (min-width: 576px) {
  .spinner-container {
    min-width: 400px;
    max-width: 500px;
  }
}

.progress-details {
  text-align: center;
  padding: 20px;
}

#progress-text {
  display: block;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 16px;
}

.progress-bar-container {
  width: 100%;
  height: 20px;
  background-color: #f0f0f0;
  border-radius: 10px;
  overflow: hidden;
  margin: 10px 0;
  position: relative;
}

.progress-bar {
  height: 100%;
  background-color: #4a90e2;
  width: 0%;
  transition: width 0.5s ease;
  border-radius: 10px;
  position: absolute;
  top: 0;
  left: 0;
}

#progress-stats {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  color: #666;
}

/* Notification System */
.notification {
  position: fixed;
  top: 80px;
  right: 20px;
  max-width: 400px;
  width: 100%;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  z-index: 9000;
  animation: slideIn 0.3s ease-out;
}

@media (max-width: 576px) {
  .notification {
    top: 70px;
    right: 10px;
    left: 10px;
    max-width: none;
    width: auto;
  }
}

.notification-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}

.notification-message {
  flex: 1;
  margin-right: 16px;
}

.notification-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--neutral-500);
  line-height: 1;
  padding: 0;
  width: 24px;
  height: 24px;
}

.notification-info {
  border-left: 4px solid var(--primary-color);
}

.notification-success {
  border-left: 4px solid var(--success-color);
}

.notification-error {
  border-left: 4px solid var(--error-color);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}