/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

body.db-modal-open {
    overflow: hidden;
}

/* 树形结构样式 */
.tree {
    min-height: 20px;
    padding: 19px;
    margin-bottom: 20px;
    background-color: #f5f5f5;
    border: 1px solid #e3e3e3;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
}

.tree ul {
    padding-left: 20px;
    list-style: none;
}

.tree li {
    margin: 0;
    padding: 5px 0 5px 0;
    list-style: none;
    white-space: nowrap;
}

.tree li.parent_li > span {
    cursor: pointer;
}

.tree li.parent_li > span > span {
    cursor: pointer;
}

.tree li.parent_li > span > span:hover {
    background-color: #eee;
    border-radius: 3px;
    padding: 2px;
}

.tree li.parent_li > span > span i {
    margin-right: 5px;
}

.tree a {
    text-decoration: none;
    color: #333;
    padding: 3px 5px;
    border-radius: 3px;
    transition: all 0.2s;
}

.tree a:hover,
.tree a.active {
    background-color: #667eea;
    color: white;
}

.category-count-small {
    font-size: 12px;
    color: #999;
    margin-left: 5px;
}

/* 主布局容器 */
.main-layout {
    display: flex;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* 左侧边栏 */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 容器 */
.container {
    flex: 1;
    min-width: 0;
}

/* 头部卡片 */
.header-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 30px 40px;
    margin-bottom: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.header-title {
    font-size: 32px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 8px;
}

.header-subtitle {
    color: #666;
    font-size: 14px;
}

/* 侧边栏卡片 */
.sidebar-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.sidebar-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 分类树形列表 */
.category-tree {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tree-item {
    margin-bottom: 4px;
}

.tree-children {
    list-style: none;
    padding-left: 20px;
    margin: 4px 0;
}

.category-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: #333;
    transition: all 0.2s;
    cursor: pointer;
}

.category-link:hover,
.category-link.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.category-link.disabled {
    color: #999;
    cursor: not-allowed;
}

.category-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 12px;
}

.expand-icon {
    font-size: 10px;
    color: #667eea;
    transition: transform 0.2s;
}

.category-link:hover .expand-icon,
.category-link.active .expand-icon {
    color: white;
}

.category-link.expanded .expand-icon {
    transform: rotate(90deg);
}

.category-name {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
}

.category-count {
    font-size: 12px;
    background: #e5e7eb;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
}

.category-link:hover .category-count,
.category-link.active .category-count {
    background: rgba(255, 255, 255, 0.2);
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.tables {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.stat-icon.engine {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.stat-info {
    flex: 1;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #1a1a2e;
}

.stat-label {
    font-size: 13px;
    color: #888;
    margin-top: 4px;
}

/* 表列表 */
.tables-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 30px 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

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

.search-box {
    display: flex;
    gap: 8px;
}

.search-box input {
    padding: 10px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    min-width: 260px;
    transition: border-color 0.3s;
}

.search-box input:focus {
    border-color: #667eea;
}

.tables-list {
    max-height: 500px;
    overflow-y: auto;
}

.table-memo {
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.5;
    color: #64748b;
    word-break: break-word;
}

.table-status-missing {
    display: inline-flex;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #fff7ed;
    color: #c2410c;
    font-size: 11px;
    font-weight: 700;
    vertical-align: middle;
}

.tables-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.pager-btn {
    border: 1px solid #dbe2f0;
    background: #fff;
    color: #334155;
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.pager-btn:hover:not(:disabled),
.pager-btn.is-active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: #fff;
}

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

.pager-summary {
    font-size: 13px;
    color: #64748b;
    margin-left: 6px;
}

.db-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0.18s ease;
    z-index: 9999;
}

.db-modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.db-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.56);
    backdrop-filter: blur(6px);
}

.db-modal__dialog {
    position: relative;
    width: min(1100px, 96vw);
    height: min(760px, 88vh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(245,247,255,0.98) 100%);
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.32);
    transform: translateY(14px) scale(0.98);
    transition: transform 0.18s ease;
}

.db-modal__dialog--wide {
    width: min(1280px, 98vw);
    height: min(860px, 92vh);
}

.db-modal.is-open .db-modal__dialog {
    transform: translateY(0) scale(1);
}

.db-modal__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 26px 18px;
    color: #111827;
    background:
        radial-gradient(circle at top left, rgba(99, 102, 241, 0.18), transparent 34%),
        radial-gradient(circle at top right, rgba(168, 85, 247, 0.16), transparent 28%),
        linear-gradient(135deg, rgba(255,255,255,0.98) 0%, rgba(244,247,255,0.98) 100%);
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}

.db-modal__eyebrow {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6366f1;
    margin-bottom: 6px;
}

.db-modal__title {
    font-size: 24px;
    font-weight: 800;
    margin: 0 0 6px;
}

.db-modal__desc {
    margin: 0;
    font-size: 13px;
    color: #6b7280;
}

.db-modal__close {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    color: #4338ca;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.18s ease;
}

.db-modal__close:hover {
    background: rgba(99, 102, 241, 0.18);
    transform: rotate(90deg);
}

.db-modal__body {
    flex: 1;
    padding: 0;
    background: #f8fafc;
}

.db-modal__frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.table-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 8px;
    background: #f8f9fa;
    transition: all 0.2s;
    cursor: pointer;
}

.table-item:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.table-item:hover .table-name {
    color: white;
}

.table-item:hover .table-meta {
    color: rgba(255, 255, 255, 0.8);
}

.table-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    font-size: 18px;
}

.table-item:hover .table-icon {
    background: rgba(255, 255, 255, 0.2);
}

.table-info {
    flex: 1;
    min-width: 0;
}

.table-name {
    font-weight: 600;
    font-size: 15px;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-meta {
    font-size: 12px;
    color: #888;
    margin-top: 4px;
    display: flex;
    gap: 12px;
}

.table-actions {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.table-item:hover .table-actions {
    opacity: 1;
}

.table-actions a {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
}

.table-actions a:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #888;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

/* 响应式 */
@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
    }
    
    .sidebar-card {
        flex-shrink: 0;
        min-width: 240px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 12px;
    }
    
    .header-card, .tables-card {
        padding: 20px;
    }
    
    .header-title {
        font-size: 24px;
    }
    
    .sidebar {
        flex-direction: column;
        overflow-x: visible;
    }
    
    .sidebar-card {
        min-width: 100%;
    }

    .db-modal {
        padding: 12px;
    }

    .db-modal__dialog {
        width: 100%;
        height: 92vh;
        border-radius: 18px;
    }

    .db-modal__header {
        padding: 18px 18px 14px;
    }

    .db-modal__title {
        font-size: 20px;
    }
}

/* 滚动条美化 */
.tables-list::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.tables-list::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.tables-list::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.tables-list::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}
