/**
 * API接口管理对话框样式
 * ===========================================
 * 用于配置和管理各种API接口的对话框样式
 */

/* 对话框遮罩层 */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.dialog-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.dialog-overlay .dialog-content {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.dialog-overlay.show .dialog-content {
    opacity: 1;
}

/* 对话框内容容器 */
.dialog-content {
    background: var(--color-bg-primary, #ffffff);
    border: 1px solid var(--color-border-light, #ddd);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    color: var(--color-text-primary, #333);
    position: relative;
}

/* API接口管理对话框特定样式 */
.api-interface-dialog {
    width: 700px;
    max-width: 90vw;
    max-height: 80vh;
    /* 改为内部滚动容器以配合标题粘滞 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 对话框头部 */
.api-interface-dialog > .dialog-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border-light, #eee);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: 8px 8px 0 0;
    /* 顶部标题固定 */
    position: sticky;
    top: 0;
    z-index: 2;
}

.dialog-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-primary, #333);
}

/* 关闭按钮 */
.dialog-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-secondary, #666);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.dialog-close:hover {
    background: var(--color-bg-hover, #e9ecef);
    color: var(--color-text-primary, #333);
}

/* 对话框主体 */
.api-interface-dialog > .dialog-body {
    padding: 24px;
    flex: 1;
    overflow: auto;
}

/* 对话框底部 */
.dialog-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--color-border-light, #eee);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: 0 0 8px 8px;
}

.interface-config-section,
.available-units-section,
.connection-test-section {
    margin-bottom: 24px;
    padding: 16px;
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    background: var(--color-bg-secondary);
}

.interface-config-section h4,
.available-units-section h4,
.connection-test-section h4 {
    margin: 0 0 16px 0;
    color: var(--color-text-primary);
    font-size: 16px;
    font-weight: 600;
}

.interface-config-grid {
    display: grid;
    gap: 16px;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.config-item label {
    font-weight: 500;
    color: var(--color-text-secondary);
    font-size: 14px;
}

.config-item .form-input {
    padding: 8px 12px;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.config-item .form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-alpha);
}

.units-config {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.units-config label {
    font-weight: 500;
    color: var(--color-text-secondary);
    font-size: 14px;
    min-width: 100px;
}

.form-select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: 14px;
}

.units-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    background: var(--color-bg-primary);
}

.unit-item {
    padding: 12px;
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.unit-item:last-child {
    border-bottom: none;
}

.unit-info {
    flex: 1;
}

.unit-name {
    font-weight: 500;
    color: var(--color-text-primary);
    margin-bottom: 4px;
}

.unit-details {
    font-size: 12px;
    color: var(--color-text-secondary);
    display: flex;
    gap: 16px;
}

.unit-type {
    background: var(--color-primary-alpha);
    color: var(--color-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
}

.test-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.connection-status {
    font-size: 14px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 4px;
}

.connection-status.success {
    background: var(--color-success-alpha);
    color: var(--color-success);
}

.connection-status.error {
    background: var(--color-danger-alpha);
    color: var(--color-danger);
}

.connection-status.testing {
    background: var(--color-warning-alpha);
    color: var(--color-warning);
}

.test-results {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-radius: 4px;
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    color: var(--color-text-secondary);
}

.test-results:empty {
    display: none;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

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

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

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

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

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .api-interface-dialog {
        width: 95vw;
        margin: 20px auto;
    }
    
    .units-config {
        flex-direction: column;
        align-items: stretch;
    }
    
    .units-config label {
        min-width: auto;
    }
    
    .test-controls {
        flex-direction: column;
        align-items: stretch;
    }
}

/* API类型管理区域样式 */
.api-types-management-section {
    margin-bottom: 24px;
    padding: 20px;
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: 8px;
    border: 1px solid var(--color-border-light, #dee2e6);
}

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

.section-header h4 {
    margin: 0;
    color: var(--color-text-primary, #333);
    font-size: 16px;
    font-weight: 600;
}

.api-types-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.overview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--color-bg-primary, #ffffff);
    border: 1px solid var(--color-border-light, #dee2e6);
    border-radius: 4px;
}

.overview-label {
    font-size: 13px;
    color: var(--color-text-secondary, #666);
}

.overview-value {
    font-weight: 600;
    color: var(--color-text-primary, #333);
}

.api-types-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--color-bg-primary, #ffffff);
    border-radius: 4px;
    border: 1px solid var(--color-border-light, #dee2e6);
}

.api-types-loading .loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 123, 255, 0.2);
    border-top: 2px solid var(--color-primary, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.api-types-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.preview-section h5 {
    margin: 0 0 8px 0;
    color: var(--color-text-primary, #333);
    font-size: 14px;
    font-weight: 600;
}

.types-preview-list {
    max-height: 150px;
    overflow-y: auto;
    background: var(--color-bg-primary, #ffffff);
    border: 1px solid var(--color-border-light, #dee2e6);
    border-radius: 4px;
    padding: 8px;
}

.type-preview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    border-radius: 3px;
    margin-bottom: 2px;
    font-size: 12px;
    line-height: 1.4;
}

.type-preview-item:hover {
    background: var(--color-bg-tertiary, #f0f0f0);
}

.type-preview-chinese {
    font-weight: 500;
    color: var(--color-text-primary, #333);
}

.type-preview-english {
    font-family: 'Monaco', 'Consolas', monospace;
    color: var(--color-text-secondary, #666);
    font-size: 11px;
}

/* API类型来源信息区域 */
.api-types-source-info {
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--color-bg-primary, #ffffff);
    border: 1px solid var(--color-border-light, #dee2e6);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.source-info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.source-label {
    color: var(--color-text-secondary, #666);
    font-weight: 500;
    min-width: 80px;
}

.source-value {
    color: var(--color-text-primary, #333);
    font-weight: 600;
    text-align: right;
    flex: 1;
}

/* 连接测试区域样式增强 */
.connection-test-section .section-header {
    flex-wrap: wrap;
    gap: 12px;
}

.test-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.test-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.test-result-item {
    padding: 12px;
    background: var(--color-bg-primary, #ffffff);
    border: 1px solid var(--color-border-light, #dee2e6);
    border-radius: 4px;
}

.test-result-item.success {
    border-left: 4px solid #28a745;
}

.test-result-item.error {
    border-left: 4px solid #dc3545;
}

.test-result-item.testing {
    border-left: 4px solid #ffc107;
}

.test-result-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--color-text-primary, #333);
}

.test-result-status {
    font-size: 12px;
    color: var(--color-text-secondary, #666);
}

.detailed-test-results {
    margin-top: 16px;
    padding: 16px;
    background: var(--color-bg-primary, #ffffff);
    border: 1px solid var(--color-border-light, #dee2e6);
    border-radius: 4px;
}

/* 配置项表单帮助文本 */
.config-item .form-help {
    display: block;
    font-size: 11px;
    color: var(--color-text-muted, #999);
    margin-top: 4px;
}

/* 亮色主题适配 */
[data-theme="light"] .api-types-management-section {
    background: #f8f9fa;
    border-color: #dee2e6;
}

/* 亮色主题下的按钮样式 */
[data-theme="light"] .btn-secondary {
    background: #f8f9fa;
    color: #495057;
    border-color: #6c757d;
}

[data-theme="light"] .btn-secondary:hover {
    background: #e9ecef;
    color: #495057;
    border-color: #5a6268;
}

[data-theme="light"] .btn-primary {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

[data-theme="light"] .btn-primary:hover {
    background: #0069d9;
    border-color: #0062cc;
}

/* 确保SVG图标颜色继承文本颜色 */
[data-theme="light"] .btn-secondary svg {
    color: #495057;
}

[data-theme="light"] .btn-secondary:hover svg {
    color: #495057;
}

[data-theme="light"] .btn-primary svg {
    color: white;
}

[data-theme="light"] .overview-item,
[data-theme="light"] .api-types-loading,
[data-theme="light"] .types-preview-list,
[data-theme="light"] .test-result-item,
[data-theme="light"] .detailed-test-results,
[data-theme="light"] .api-types-source-info {
    background: #ffffff;
    border-color: #dee2e6;
}

[data-theme="light"] .type-preview-item:hover {
    background: #f0f0f0;
}

/* 暗色主题适配 */
[data-theme="dark"] .api-types-management-section {
    background: #2d3748;
    border-color: #4a5568;
}

[data-theme="dark"] .overview-item,
[data-theme="dark"] .api-types-loading,
[data-theme="dark"] .types-preview-list,
[data-theme="dark"] .test-result-item,
[data-theme="dark"] .detailed-test-results,
[data-theme="dark"] .api-types-source-info {
    background: #1a202c;
    border-color: #4a5568;
}

[data-theme="dark"] .type-preview-item:hover {
    background: #4a5568;
}

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

/* 亮色主题下的loading-spinner优化 */
[data-theme="light"] .loading-spinner {
    border: 2px solid rgba(108, 117, 125, 0.3);
    border-top-color: var(--color-primary);
}

/* 暗色主题下的loading-spinner优化 */
[data-theme="dark"] .loading-spinner {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--color-primary);
}

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

/* 错误状态样式 */
.config-item.error .form-input {
    border-color: var(--color-danger);
    background: var(--color-danger-alpha);
}

.error-message {
    color: var(--color-danger);
    font-size: 12px;
    margin-top: 4px;
}

/* 成功状态样式 */
.config-item.success .form-input {
    border-color: var(--color-success);
}

.success-message {
    color: var(--color-success);
    font-size: 12px;
    margin-top: 4px;
}
