/* ============================================================
   app.css - 全局样式（元素 + 组件 + 布局）
   ============================================================ */

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

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--text-primary);
    background: var(--bg-main);
}

/* ============================================================
   一、通用元素
   ============================================================ */

/* --- 按钮 --- */
button {
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    outline: none;
    color: inherit;
    background: none;
    height: var(--btn-height);
    min-width: var(--btn-height);
    padding: 0 12px;
    font-size: var(--font-size-sm);
    border-radius: var(--border-radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--transition-base), border-color var(--transition-base),
                color var(--transition-base), box-shadow var(--transition-base);
}
button:hover { background: var(--bg-hover); border-color: var(--border); }
button:active { transform: scale(0.98); }
button:disabled { cursor: not-allowed; opacity: 0.6; }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

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

/* --- 输入 --- */
input, textarea, select {
    font-family: inherit;
    outline: none;
    border: 1px solid var(--border);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    background: var(--bg-subtle);
    height: 36px;
    padding: 0 12px;
    transition: border-color var(--transition-base), box-shadow var(--transition-base),
                background var(--transition-base);
}
textarea {
    height: auto;
    min-height: 36px;
    padding: 8px 12px;
    line-height: var(--line-height-base);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
    background: var(--bg-white);
}

/* --- 链接 --- */
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- 滚动条 --- */
* { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.15) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ============================================================
   二、图标（SVG mask）
   ============================================================ */
.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: inline-block;
    background: currentColor;
    -webkit-mask: var(--icon-svg) no-repeat center / contain;
    mask: var(--icon-svg) no-repeat center / contain;
}

.icon-folder {
    --icon-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z'/%3E%3C/svg%3E");
}
.icon-db {
    --icon-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cellipse cx='12' cy='5' rx='9' ry='3'/%3E%3Cpath d='M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5'/%3E%3Cpath d='M3 12c0 1.66 4 3 9 3s9-1.34 9-3'/%3E%3C/svg%3E");
}
.icon-file,
.icon-code,
.icon-css,
.icon-json {
    --icon-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2h9l5 5v13a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z'/%3E%3Cpath d='M14 2v5h5'/%3E%3C/svg%3E");
}
.icon-html,
.icon-md {
    --icon-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2h9l5 5v13a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z'/%3E%3Cpath d='M14 2v5h5'/%3E%3Cpath d='M8 13h8M8 17h5'/%3E%3C/svg%3E");
}

/* ============================================================
   三、列表项 + 下拉菜单
   ============================================================ */
.list-item,
.file-item,
.project-item,
.db-table-item,
.version-item {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    width: 100%;
    height: 32px;
    padding: 4px 8px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    user-select: none;
    gap: 6px;
    background: transparent;
    position: relative;
    transition: background var(--transition-base), color var(--transition-base);
}
.list-item:hover,
.file-item:hover,
.project-item:hover,
.db-table-item:hover,
.version-item:hover { background: var(--bg-hover); }

.list-item.active,
.file-item.active,
.project-item.active,
.db-table-item.active { background: var(--primary-light); }
.list-item.active .item-name,
.file-item.active .item-name,
.project-item.active .item-name,
.db-table-item.active .item-name {
    color: var(--primary-hover);
    font-weight: 500;
}

.item-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.item-name {
    flex: 1 1 0;
    min-width: 0;
    font-size: var(--font-size-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- ⋮ 下拉菜单 --- */
.item-menu {
    flex-shrink: 0;
    position: relative;
    display: inline-flex;
    align-items: center;
}
.item-more-btn {
    width: 24px;
    height: 24px;
    min-width: 24px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    color: var(--text-tertiary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.item-more-btn:hover,
.item-menu:hover .item-more-btn {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.item-menu .item-actions {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 120px;
    padding: 4px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity var(--transition-fast), transform var(--transition-fast),
                visibility var(--transition-fast);
}
.item-menu:hover .item-actions,
.item-menu:focus-within .item-actions {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}
.item-actions button {
    height: 28px;
    min-width: 0;
    padding: 0 10px;
    font-size: var(--font-size-xs);
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    justify-content: flex-start;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.item-actions button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ============================================================
   四、标签
   ============================================================ */
.detail-tabs {
    display: flex;
    gap: 0;
    padding: 0;
    margin: 0;
    border-bottom: 1px solid var(--border-light);
}
.detail-tab {
    height: 32px;
    padding: 0 14px;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    gap: 4px;
    transition: color var(--transition-base), border-color var(--transition-base),
                background var(--transition-base);
}
.detail-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.detail-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.file-tabs { display: flex; gap: 4px; margin-left: 8px; }
.file-tab {
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-hover);
    cursor: pointer;
    transition: all var(--transition-base);
}
.file-tab:hover { background: var(--bg-active); }
.file-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.ext-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    line-height: 1.4;
    font-weight: 500;
    letter-spacing: 0.3px;
}
.ext-tag-html { background: var(--tag-html-bg); color: var(--tag-html-text); }
.ext-tag-md   { background: var(--tag-md-bg);   color: var(--tag-md-text); }

/* ============================================================
   五、模态框
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-card {
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    width: 600px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.modal-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
    font-size: 18px;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-card-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.modal-card-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-card-footer button {
    padding: 6px 16px;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    transition: all var(--transition-fast);
}

/* ============================================================
   六、编辑器
   ============================================================ */
.editor-wrapper {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    overflow: hidden;
    height: 100%;
    min-height: 200px;
    width: 100%;
    flex: 1;
}
.editor-textarea {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 15px;
    line-height: var(--line-height-editor);
    resize: none;
    height: 100%;
    width: 100%;
    background: var(--bg-white);
}

/* ============================================================
   七、表格 / 空状态
   ============================================================ */
.table-wrapper { overflow-x: auto; }
.table-wrapper table { width: 100%; border-collapse: collapse; font-size: var(--font-size-sm); }
.table-wrapper th {
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    text-align: left;
    font-weight: 600;
}
.table-wrapper td { padding: var(--space-2) var(--space-3); border: 1px solid var(--border-light); }
.table-wrapper tbody tr:nth-child(even) { background: var(--bg-subtle); }
.table-wrapper tbody tr:hover { background: var(--bg-hover); }

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
}

/* 文件卡片（renderFileCard 用） */
.file-card { cursor: pointer; }
.file-card .file-tags { display: inline-flex; gap: 4px; margin-left: 6px; flex-shrink: 0; }

/* ============================================================
   八、拖拽
   ============================================================ */
.resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background var(--transition-fast);
}
.resize-handle:hover,
.resize-handle.active { background: var(--primary); }

.detail-resize-handle {
    height: 4px;
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.detail-resize-handle .handle-bar {
    width: 40px;
    height: 3px;
    background: var(--border-strong);
    border-radius: 2px;
    transition: background var(--transition-fast);
}
.detail-resize-handle:hover .handle-bar { background: var(--primary); }

.drag-line {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    background: var(--primary);
    opacity: 0.5;
}
.drag-line--v { width: 2px; height: 100vh; top: 0; }
.drag-line--h { height: 2px; width: 100vw; left: 0; }

/* ============================================================
   九、布局
   ============================================================ */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-main);
}

/* --- 侧边栏 --- */
.sidebar {
    width: 240px;
    min-width: 160px;
    max-width: 450px;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header,
.panel-header {
    height: var(--header-height);
    padding: 0 14px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
}
.sidebar-header {
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
}
.sidebar-header button {
    padding: 6px 12px;
    background: var(--primary);
    color: white;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    border: none;
    transition: background var(--transition-fast);
}
.sidebar-header button:hover { background: var(--primary-hover); }

.project-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

/* --- 详情区 --- */
.detail-section {
    display: flex;
    flex-direction: column;
    height: 40vh;
    max-height: 65vh;
    border-top: 1px solid var(--border);
    background: var(--bg-subtle);
    flex-shrink: 0;
}
.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
    white-space: nowrap;
    gap: 8px;
}
.file-list,
.db-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

/* --- 三栏 --- */
.middle-left,
.middle-right,
.right {
    background: var(--bg-white);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}
.right { padding: 0; }

#chatFrame {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* --- Panel 头部 --- */
.panel-header {
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
    background: var(--bg-subtle);
    white-space: nowrap;
    gap: 8px;
    overflow: hidden;
}
.panel-header span:first-child { flex-shrink: 0; }

#previewFileLabel,
#prdFileLabel {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 400;
}

#prdSaveBtn {
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border-radius: var(--border-radius-sm);
    font-size: 12px;
    border: none;
    white-space: nowrap;
    transition: background var(--transition-fast);
}
#prdSaveBtn:hover { background: var(--primary-hover); }

#previewFrame { flex: 1; border: none; background: white; }

.prd-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.prd-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 14px;
}

/* ============================================================
   十、全局加载遮罩
   ============================================================ */
#globalLoadingOverlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--overlay-bg-loading);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}
.global-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: global-spin 0.8s linear infinite;
}
@keyframes global-spin { to { transform: rotate(360deg); } }

.btn-reload {
    padding: 4px 10px;
    background: var(--bg-white);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--border-radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.btn-reload:hover { background: var(--bg-hover); color: var(--text-primary); }