/**
 * MedPinAI Web标注工具 - 样式文件
 */

/* ===== 全局样式 ===== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
}

/* ===== 主容器 ===== */

.app-container, #app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== 工具栏 ===== */

.toolbar, #toolbar {
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

.toolbar-left, #toolbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.app-title, #app-title {
    font-size: 18px;
    font-weight: 600;
    color: #4A9EFF;
    margin-right: 30px;
}

.toolbar-right, #toolbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* ===== 按钮 ===== */

.toolbar-btn {
    background: #3d3d3d;
    border: 1px solid #505050;
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background: #4d4d4d;
    border-color: #606060;
}

.toolbar-btn:active {
    background: #2d2d2d;
}

.toolbar-btn:disabled {
    background: #2d2d2d;
    color: #666666;
    cursor: not-allowed;
    border-color: #3d3d3d;
}

.toolbar-btn.primary {
    background: #4A9EFF;
    border-color: #4A9EFF;
    font-weight: 500;
}

.toolbar-btn.primary:hover {
    background: #5AAEFF;
}

.toolbar-btn.primary:active {
    background: #3A8EEF;
}

/* ===== 统计信息 ===== */

#stats {
    font-size: 13px;
    color: #aaaaaa;
    padding: 0 15px;
}

/* ===== 主内容区 ===== */

.main-content, #main-content {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* ===== 加载屏幕 ===== */

.loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 26, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.loading-content {
    text-align: center;
    color: #ffffff;
}

.spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
    border: 4px solid #3d3d3d;
    border-top: 4px solid #4A9EFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.progress-bar {
    width: 300px;
    height: 8px;
    background: #3d3d3d;
    border-radius: 4px;
    overflow: hidden;
    margin: 20px auto 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4A9EFF, #5AAEFF);
    width: 0;
    transition: width 0.3s ease;
}

/* ===== 面板网格 ===== */

#panelsContainer, .panels-container {
    flex: 1;
    display: grid;
    gap: 8px;
    padding: 8px;
    background: #1a1a1a;
    overflow: auto;
    /* 固定每行3列，自动创建新行 */
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: auto;
}

/* ===== 面板 ===== */

.panel {
    background: #252525;
    border: 1px solid #3d3d3d;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    height: 100%;
}

.panel-header {
    background: #2d2d2d;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #e0e0e0;
    border-bottom: 1px solid #3d3d3d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-image {
    flex: 1;
    position: relative;
    background: #000000;
    overflow: hidden;
    cursor: crosshair;
    min-height: 300px;
}

.panel-image canvas {
    /* 让Cornerstone控制canvas尺寸，保持正确的aspect ratio */
}

.panel-slider {
    padding: 10px 12px;
    background: #2d2d2d;
    border-top: 1px solid #3d3d3d;
    display: flex;
    align-items: center;
    min-height: 40px;
}

.panel-slider input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #404040;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.panel-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #4A9EFF;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.2);
}

.panel-slider input[type="range"]::-webkit-slider-thumb:hover {
    background: #5AAEFF;
    box-shadow: 0 0 0 6px rgba(74, 158, 255, 0.3);
}

.panel-slider input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #4A9EFF;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.2);
    transition: all 0.2s;
}

.panel-slider input[type="range"]::-moz-range-thumb:hover {
    background: #5AAEFF;
    box-shadow: 0 0 0 6px rgba(74, 158, 255, 0.3);
}

/* ===== 模态框通用样式 ===== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: -1;
}

.modal-content {
    background: #2d2d2d;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 1;
}

.modal-header {
    background: #3d3d3d;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #505050;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
    margin: 0;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.modal-footer {
    background: #3d3d3d;
    padding: 16px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid #505050;
}

/* ===== 按钮通用样式 ===== */

.btn {
    background: #3d3d3d;
    border: 1px solid #505050;
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.btn:hover {
    background: #4d4d4d;
    border-color: #606060;
}

.btn:active {
    background: #2d2d2d;
}

.btn:disabled {
    background: #2d2d2d;
    color: #666666;
    cursor: not-allowed;
    border-color: #3d3d3d;
}

.btn-primary {
    background: #4A9EFF;
    border-color: #4A9EFF;
    font-weight: 500;
}

.btn-primary:hover {
    background: #5AAEFF;
}

.btn-primary:active {
    background: #3A8EEF;
}

.btn-secondary {
    background: #3d3d3d;
    border-color: #505050;
}

/* ===== 结构选择器模态框 ===== */

#structure-selector-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.structure-selector {
    max-width: 650px;
}

/* 已选择结构的显示框 */
.selector-selected {
    padding: 16px;
    background: #2d2d2d;
    border-bottom: 2px solid #4A9EFF;
}

.selector-selected input {
    width: 100%;
    background: #1a1a1a;
    border: 2px solid #4A9EFF;
    color: #ffffff;
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 8px;
    cursor: default;
}

.selector-selected input:focus {
    outline: none;
}

.selector-selected input::placeholder {
    color: #666666;
    font-weight: normal;
}

/* 搜索框 */
.selector-search {
    padding: 12px 16px;
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
}

.selector-search input {
    width: 100%;
    background: #252525;
    border: 1px solid #404040;
    color: #ffffff;
    padding: 10px 14px;
    font-size: 14px;
    border-radius: 6px;
}

.selector-search input:focus {
    outline: none;
    border-color: #4A9EFF;
}

.selector-search input::placeholder {
    color: #666666;
}

.selector-filters {
    padding: 12px 16px;
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.selector-filters label {
    color: #aaa;
}

.selector-filters select {
    flex: 1;
    background: #252525;
    border: 1px solid #404040;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
}

.selector-filters select:focus {
    outline: none;
    border-color: #4A9EFF;
}

.structure-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    max-height: 400px;
}

.loading-text {
    text-align: center;
    color: #666;
    padding: 40px 20px;
}

.structure-item {
    padding: 12px 16px;
    background: #252525;
    border: 1px solid #3d3d3d;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.structure-item:hover {
    background: #3d3d3d;
    border-color: #4A9EFF;
    transform: translateX(4px);
}

.structure-item:active {
    background: #2d2d2d;
}

.structure-item.selected {
    background: #3d3d3d;
    border-color: #4A9EFF;
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.3);
}

.structure-name-ch {
    font-weight: 500;
    color: #ffffff;
    font-size: 14px;
    flex: 1;
    text-align: left;
}

.structure-name-en {
    font-size: 13px;
    color: #aaa;
    flex: 1;
    text-align: right;
}

.structure-category {
    font-size: 12px;
    color: #aaa;
}

/* 删除按钮样式 */
.btn-danger {
    background: #d32f2f;
    border-color: #d32f2f;
    color: #ffffff;
}

.btn-danger:hover {
    background: #f44336;
    border-color: #f44336;
}

.btn-danger:active {
    background: #c62828;
}

/* ===== 帮助模态框 ===== */

.help-content {
    max-width: 700px;
}

.help-content h3 {
    font-size: 16px;
    color: #4A9EFF;
    margin: 20px 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #404040;
}

.help-content h3:first-child {
    margin-top: 0;
}

.help-content h4 {
    font-size: 14px;
    color: #ffffff;
    margin: 16px 0 8px 0;
}

.help-content ul {
    list-style: none;
    padding: 0;
    margin: 0 0 16px 0;
}

.help-content li {
    padding: 6px 0;
    padding-left: 20px;
    position: relative;
}

.help-content li:before {
    content: "•";
    position: absolute;
    left: 8px;
    color: #4A9EFF;
}

.help-content p {
    margin: 8px 0;
    line-height: 1.6;
    color: #ddd;
}

.help-content code {
    background: #1a1a1a;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    color: #4A9EFF;
}

#structure-selector {
    background: #2d2d2d;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#structure-selector-header {
    background: #3d3d3d;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #505050;
}

#structure-selector-title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
}

#structure-selector-close {
    background: transparent;
    border: none;
    color: #aaaaaa;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

#structure-selector-close:hover {
    background: #505050;
    color: #ffffff;
}

#structure-search {
    width: 100%;
    background: #252525;
    border: 1px solid #404040;
    color: #ffffff;
    padding: 12px 16px;
    font-size: 15px;
    border-radius: 0;
}

#structure-search:focus {
    outline: none;
    border-color: #4A9EFF;
}

#structure-search::placeholder {
    color: #666666;
}

#structure-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* ===== 侧边栏 ===== */

.sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 350px;
    height: 100%;
    background: #2d2d2d;
    border-left: 1px solid #404040;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
}

.sidebar-header {
    padding: 16px 20px;
    background: #3d3d3d;
    border-bottom: 1px solid #505050;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 16px;
}

.btn-close {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
}

.btn-close:hover {
    color: #fff;
}

.sidebar-search {
    padding: 12px;
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    background: #1a1a1a;
    border: 1px solid #404040;
    color: #fff;
    border-radius: 4px;
}

.sidebar-search input:focus {
    outline: none;
    border-color: #4A9EFF;
}

.annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.empty-state {
    text-align: center;
    color: #666;
    padding: 40px 20px;
}

.sidebar-footer {
    padding: 16px 20px;
    background: #3d3d3d;
    border-top: 1px solid #505050;
}

.stats {
    display: flex;
    justify-content: space-around;
}

.stat-item {
    text-align: center;
}

.stat-label {
    font-size: 12px;
    color: #aaa;
    display: block;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 20px;
    font-weight: 600;
    color: #4A9EFF;
}

/* ===== 状态栏 ===== */

.statusbar {
    background: #2d2d2d;
    border-top: 1px solid #404040;
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #aaa;
}

.statusbar-left {
    display: flex;
    gap: 20px;
}

.statusbar-left span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.statusbar-left strong {
    color: #4A9EFF;
}

.crosshair-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.indicator {
    width: 8px;
    height: 8px;
    background: #00ff00;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
}

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

.btn-text {
    background: transparent;
    border: none;
    color: #4A9EFF;
    cursor: pointer;
    padding: 4px 8px;
    text-decoration: underline;
}

.btn-text:hover {
    color: #5AAEFF;
}

/* ===== 加载动画 ===== */

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== 滚动条 ===== */

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

::-webkit-scrollbar-track {
    background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
    background: #404040;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #505050;
}

/* ===== 响应式设计 ===== */

@media (max-width: 768px) {
    #toolbar {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    #toolbar-left,
    #toolbar-right {
        justify-content: center;
    }

    #app-title {
        margin-right: 0;
        text-align: center;
    }

    #panel-grid[data-panel-count="3"],
    #panel-grid[data-panel-count="4"],
    #panel-grid[data-panel-count="5"],
    #panel-grid[data-panel-count="6"],
    #panel-grid[data-panel-count="7"],
    #panel-grid[data-panel-count="8"],
    #panel-grid[data-panel-count="9"],
    #panel-grid[data-panel-count="10"],
    #panel-grid[data-panel-count="11"],
    #panel-grid[data-panel-count="12"],
    #panel-grid[data-panel-count="13"],
    #panel-grid[data-panel-count="14"],
    #panel-grid[data-panel-count="15"],
    #panel-grid[data-panel-count="16"] {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    #panel-grid {
        grid-template-columns: 1fr !important;
    }

    .toolbar-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

/* ===== 打印样式 ===== */

@media print {
    #toolbar {
        display: none;
    }

    body {
        background: white;
    }

    .panel {
        page-break-inside: avoid;
    }
}

/* ===== 调试面板 ===== */

.debug-panel {
    position: fixed;
    bottom: 40px;
    right: 20px;
    width: 450px;
    max-height: 400px;
    background: #1a1a1a;
    border: 2px solid #4A9EFF;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.debug-header {
    background: #2d2d2d;
    padding: 10px 12px;
    border-bottom: 1px solid #4A9EFF;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
    color: #4A9EFF;
}

.btn-close-debug {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
}

.btn-close-debug:hover {
    color: #fff;
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.4;
    color: #e0e0e0;
}

.debug-content p {
    margin: 0 0 6px 0;
    padding: 4px 6px;
    background: #252525;
    border-left: 3px solid #4A9EFF;
    border-radius: 3px;
}

.debug-content .debug-zoom {
    border-left-color: #00ff00;
}

.debug-content .debug-error {
    border-left-color: #ff4444;
    color: #ff8888;
}

.debug-content .debug-warning {
    border-left-color: #ffaa00;
    color: #ffcc66;
}

.debug-content .debug-success {
    border-left-color: #00ff00;
    color: #88ff88;
}

/* ===== 辅助类 ===== */

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.p-1 { padding: 8px; }
.p-2 { padding: 16px; }
.p-3 { padding: 24px; }

/* ===== 反馈未读红点 ===== */

.feedback-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid #2d2d2d;
}

.feedback-badge:empty {
    display: none;
}

/* ===== 同步状态指示器（按钮风格） ===== */

.sync-indicator.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    transition: all 0.3s ease;
}

.sync-text {
    transition: all 0.3s ease;
}

/* 已保存状态 - 绿色圆点 */
.sync-indicator.saved .sync-dot {
    background: #4caf50;
}

/* 有未保存更改 - 橙色圆点 */
.sync-indicator.unsaved .sync-dot {
    background: #ff9800;
}

/* 正在同步 - 蓝色闪烁 */
.sync-indicator.syncing .sync-dot {
    background: #2196f3;
    animation: sync-pulse 1s infinite;
}

/* 同步失败 - 红色 */
.sync-indicator.error .sync-dot {
    background: #f44336;
}

/* 已锁定状态 - 灰色 */
.sync-indicator.locked .sync-dot {
    background: #9e9e9e;
}

.sync-indicator.locked {
    opacity: 0.6;
    cursor: not-allowed;
}

@keyframes sync-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* ===== 锁定状态横幅 ===== */
.lock-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
    z-index: 1000;
}

.lock-banner .lock-icon {
    font-size: 16px;
}

.lock-banner .lock-text {
    letter-spacing: 0.5px;
}
