/* ScolioVis 风格的现代化样式 */
:root {
  --primary-color: #0073f5;
  --primary-dark: #0056b3;
  --primary-light: #4da3ff;
  --secondary-color: #f8fafc;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: #ffffff;
}

/* 动画背景 */
.animated-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* 导航栏样式 */
.navbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-link {
  position: relative;
  transition: all 0.3s ease;
}

.nav-link:hover {
  color: var(--primary-color);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary-color);
}

/* 按钮样式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.3s ease;
  cursor: pointer;
  border: none;
  font-size: 0.875rem;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary {
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--secondary-color);
  border-color: var(--primary-color);
}

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

.btn-success:hover {
  background: #059669;
}

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

.btn-danger:hover {
  background: #dc2626;
}

/* 卡片样式 */
.card {
  background: white;
  border-radius: 1rem;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-xl);
  transform: translateY(-2px);
}

.card-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--secondary-color);
}

.card-body {
  padding: 1.5rem;
}

/* 上传区域样式 */
.upload-area {
  border: 2px dashed var(--border-color);
  border-radius: 1rem;
  padding: 3rem 2rem;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
  background: var(--secondary-color);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary-color);
  background: rgba(0, 115, 245, 0.05);
}

.upload-area.dragover {
  transform: scale(1.02);
}

.upload-icon {
  font-size: 3rem;
  color: var(--primary-color);
  margin-bottom: 1rem;
}

/* 图像容器样式 */
.image-container {
  position: relative;
  border-radius: 1rem;
  overflow: hidden;
  background: #f8fafc;
  box-shadow: var(--shadow-md);
}

.image-canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

/* 控制面板样式 */
.controls-panel {
  background: white;
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.control-group {
  margin-bottom: 1.5rem;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-item input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--primary-color);
}

/* 结果显示样式 */
.results-section {
  background: white;
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary-color);
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--secondary-color);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.result-item:last-child {
  margin-bottom: 0;
}

.result-label {
  font-weight: 500;
  color: var(--text-primary);
}

.result-value {
  font-weight: 600;
  color: var(--primary-color);
  font-size: 1.125rem;
}

/* 加载动画 */
.loading-spinner {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border-color);
  border-radius: 50%;
  border-top-color: var(--primary-color);
  animation: spin 1s ease-in-out infinite;
}

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

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  border-radius: 1rem;
}

/* 消息提示样式 */
.message {
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
}

.message-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success-color);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.message-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error-color);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.message-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning-color);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* 特性卡片样式 */
.feature-card {
  text-align: center;
  padding: 2rem;
  background: white;
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl);
}

.feature-icon {
  font-size: 2.5rem;
  color: var(--primary-color);
  margin-bottom: 1rem;
}

.feature-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.feature-description {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* 响应式网格布局 */
.analysis-grid {
    display: grid;
    gap: 1.5rem;
    width: 100%;
}

/* 面板基础样式 */
.image-panel,
.cobb-panel,
.classification-panel,
.settings-panel {
    display: flex;
    flex-direction: column;
}

/* 图像面板特殊样式 */
.image-panel {
    position: relative;
}

/* 状态面板样式 - 只在加载/错误时显示 */
.states-panel {
    display: none;  /* 默认隐藏 */
}

/* 当有加载或错误状态时显示 */
.states-panel.active {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* 右侧面板容器 - 支持滚动 */
.right-panels {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* 桌面布局 (≥768px): 左右双列 */
@media (min-width: 768px) {
    .analysis-grid {
        display: grid;
        grid-template-columns: 1.2fr 1fr;
        gap: 1.5rem;
        align-items: start;
    }
    
    .image-panel {
        min-height: 500px;
    }
    
    .right-panels {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .cobb-panel,
    .classification-panel,
    .settings-panel {
        flex-shrink: 0;
    }
    
    /* 状态面板在桌面模式下覆盖图像区域 - 只在active时 */
    .states-panel.active {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        background: rgba(255, 255, 255, 0.95);
        z-index: 10;
        border-radius: 1rem;
    }
    
    /* 桌面端隐藏移动端浮动按钮和弹窗 */
    .settings-fab,
    .mobile-new-analysis-fab {
        display: none !important;
    }

    .settings-modal-overlay {
        display: none !important;
    }
    
    /* 桌面端设置面板正常显示 */
    .settings-panel {
        display: flex !important;
    }
}

/* 大屏幕优化 (≥1200px) */
@media (min-width: 1200px) {
    .analysis-grid {
        grid-template-columns: 1.5fr 1fr;
        gap: 2rem;
    }
    
    .image-panel {
        min-height: 600px;
    }
    
    .right-panels {
        gap: 1.5rem;
    }
}

/* 手机布局 (<768px): 单列垂直堆叠 */
@media (max-width: 767px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .controls-panel {
        padding: 1rem;
    }
    
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.8125rem;
    }
    
    .analysis-grid {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .image-panel {
        min-height: 280px;
        padding: 1rem;
    }
    
    .right-panels {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    .cobb-panel,
    .classification-panel,
    .settings-panel {
        padding: 1rem;
    }
    
    .states-panel.active {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        background: rgba(255, 255, 255, 0.95);
        z-index: 10;
    }
    
    /* 移动端：隐藏设置面板，显示设置按钮 */
    .settings-panel {
        display: none !important;
    }
    
    /* 移动端浮动按钮 */
    .settings-fab,
    .mobile-new-analysis-fab {
        display: flex !important;
        position: fixed;
        width: 56px;
        height: 56px;
        color: white;
        border: none;
        border-radius: 50%;
        font-size: 1.25rem;
        cursor: pointer;
        z-index: 100;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .settings-fab {
        bottom: 20px;
        right: 20px;
        background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
        box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
    }

    .mobile-new-analysis-fab {
        bottom: 88px;
        right: 20px;
        background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }

    .settings-fab:hover,
    .mobile-new-analysis-fab:hover {
        transform: scale(1.1);
    }

    .settings-fab:hover {
        box-shadow: 0 6px 16px rgba(245, 158, 11, 0.5);
    }

    .mobile-new-analysis-fab:hover {
        box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
    }

    .settings-fab:active,
    .mobile-new-analysis-fab:active {
        transform: scale(0.95);
    }
    
    /* 设置弹窗遮罩 */
    .settings-modal-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 200;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .settings-modal-overlay.active {
        display: block;
        opacity: 1;
    }
    
    /* 设置弹窗 */
    .settings-modal {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-radius: 1.5rem 1.5rem 0 0;
        max-height: 85vh;
        overflow-y: auto;
        z-index: 201;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    }
    
    .settings-modal-overlay.active .settings-modal {
        transform: translateY(0);
    }
    
    /* 弹窗拖动条 */
    .settings-modal-handle {
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 0 auto 1rem;
    }
    
    /* 弹窗标题栏 */
    .settings-modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .settings-modal-title {
        display: flex;
        align-items: center;
        font-size: 1.125rem;
        font-weight: 600;
        color: #1f2937;
    }
    
    .settings-modal-title i {
        margin-right: 0.5rem;
        color: #f59e0b;
    }
    
    .settings-modal-close {
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #f3f4f6;
        border: none;
        border-radius: 50%;
        color: #6b7280;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .settings-modal-close:hover {
        background: #e5e7eb;
        color: #374151;
    }
    
    /* 弹窗内容优化 */
    .settings-modal .settings-group {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        background: #f9fafb;
        border-radius: 0.75rem;
    }

    .settings-modal .mobile-detection-settings,
    .settings-modal .mobile-cobb-algorithm-settings {
        display: none !important;
    }

    .settings-modal .control-item {
        padding: 0.5rem 0;
    }
    
    /* 移动端椎体样式按钮优化 */
    .settings-modal .vertebrae-style-buttons {
        gap: 2px;
        padding: 2px;
        flex-wrap: wrap;
    }
    
    .settings-modal .style-btn {
        padding: 6px 8px;
        font-size: 10px;
        min-width: 48px;
        gap: 2px;
    }
    
    .settings-modal .style-btn i {
        font-size: 12px;
    }
}

/* 隐藏未使用的bottom-panels */
.bottom-panels {
    display: none;
}

/* 隐藏类 */
.hidden {
  display: none !important;
}

/* 设置分组样式 */
.settings-group {
  padding: 1rem;
  background: #f8fafc;
  border-radius: 0.75rem;
  border: 1px solid #e2e8f0;
}

.settings-group h4 {
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

/* 淡入动画 */
.fade-in {
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 滑入动画 */
.slide-in {
  animation: slideIn 0.6s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* 脉冲动画 */
.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

/* 自定义滚动条 */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--secondary-color);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ============================================================================
   示例X光片画廊样式（内联横向列表）
   ============================================================================ */

.sample-gallery-inline {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
  text-align: center;
}

.sample-gallery-scroll {
  display: flex;
  gap: 0.875rem;
  justify-content: center;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
}

/* 小屏幕左对齐可滚动 */
@media (max-width: 540px) {
  .sample-gallery-scroll {
    justify-content: flex-start;
    padding-left: 0.25rem;
  }
}

.sample-gallery-item {
  flex: 0 0 auto;
  width: 120px;
  border-radius: 0.625rem;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  background: #f9fafb;
}

.sample-gallery-item:hover,
.sample-gallery-item:focus-visible {
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(0, 115, 245, 0.15);
  transform: translateY(-3px);
}

.sample-gallery-item:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.sample-gallery-thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #1e293b;
}

.sample-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.sample-gallery-item:hover .sample-gallery-thumb img {
  transform: scale(1.06);
}

.sample-gallery-thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sample-gallery-item:hover .sample-gallery-thumb-overlay {
  opacity: 1;
}

.sample-gallery-label {
  padding: 0.375rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sample-gallery-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sample-gallery-desc {
  font-size: 0.625rem;
  color: var(--text-secondary);
}

/* ===== 图片裁剪模态框 ===== */
#image-cropper-modal {
    backdrop-filter: blur(4px);
    z-index: 999 !important;
}

#image-cropper-modal > div:first-child {
    min-height: 100dvh;
    width: 100%;
}

/* 手机模式 (<768px) */
@media (max-width: 767px) {
    #image-cropper-modal > div:first-child {
        padding: 0 !important;
    }
    #image-cropper-modal > div > div {
        border-radius: 0;
        max-width: 100%;
        margin: 0 !important;
    }
    #crop-viewport {
        height: clamp(260px, 55vh, 380px);
    }
    #image-cropper-modal .flex.flex-col {
        gap: 0.75rem;
    }
    #image-cropper-modal .flex.flex-col button {
        justify-content: center;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }
    #image-cropper-modal .flex.gap-3 button {
        flex: 1;
    }
    #image-cropper-modal .flex.gap-2 button {
        padding: 0.625rem 0.875rem;
    }
}

/* 平板模式 (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    #crop-viewport {
        height: clamp(340px, 55vh, 460px);
    }
}

/* 桌面模式 (>=1024px) */
@media (min-width: 1024px) {
    #crop-viewport {
        height: clamp(400px, 60vh, 580px);
    }
}
