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

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial,
        sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #303133;
    background-color: #f0f2f5;
    -webkit-font-smoothing: antialiased;
}

/* Vue 初始化完成前隐藏内容，避免闪烁 */
[v-cloak] {
    display: none !important;
}

.mono {
    font-family: Consolas, Monaco, "Courier New", monospace;
}

.muted {
    color: #c0c4cc;
}

.ml4 {
    margin-left: 4px;
}

.hint {
    font-size: 12px;
    color: #c0c4cc;
}

.grid-spacer {
    flex: 1;
}

/* ==========================================================================
   顶部
   ========================================================================== */

.layout {
    height: 100vh;
}

.layout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 16px;
    background-color: #ffffff;
    border-bottom: 1px solid #e4e7ed;
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.06);
    flex: 0 0 52px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #409eff;
}

.brand-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.conn-tag {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: #303133;
    cursor: pointer;
    transition: background-color 0.2s;
}

.user-name:hover {
    background-color: #f5f7fa;
}

.user-arrow {
    font-size: 12px;
    color: #909399;
}

/* ==========================================================================
   主体布局
   ========================================================================== */

.layout-body {
    height: calc(100vh - 52px);
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    border-right: 1px solid #e4e7ed;
    overflow: hidden;
}

.sidebar-head {
    padding: 10px 10px 6px;
    flex: 0 0 auto;
}

.conn-search {
    width: 100%;
}

.tree-scroll {
    flex: 1;
    min-height: 0;
}

.tree-tip {
    padding: 30px 16px;
    text-align: center;
    font-size: 13px;
    line-height: 1.9;
    color: #a8abb2;
}

.tree-tip.small {
    padding: 6px 16px 6px 48px;
    text-align: left;
    font-size: 12px;
    color: #c0c4cc;
}

.tree-node {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding-right: 8px;
    margin: 1px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #303133;
    cursor: pointer;
    user-select: none;
}

.tree-node:hover {
    background-color: #f5f7fa;
}

.tree-node.active {
    background-color: #ecf5ff;
    color: #409eff;
}

.conn-node {
    padding-left: 4px;
    font-weight: 500;
}

/* 已断开的连接：置灰显示 */
.conn-node.dim {
    color: #a8abb2;
}

.conn-node.dim .node-icon,
.conn-node.dim .arrow {
    color: #c0c4cc;
}

.db-node {
    padding-left: 18px;
}

.table-node {
    padding-left: 38px;
    height: 28px;
}

.arrow {
    font-size: 12px;
    color: #909399;
    transition: transform 0.15s ease;
}

.arrow.open {
    transform: rotate(90deg);
}

.node-icon {
    font-size: 14px;
    color: #909399;
}

.node-icon.db {
    color: #e6a23c;
}

.node-icon.table {
    color: #909399;
}

.node-icon.view {
    color: #909399;
}

.node-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-label.system {
    color: #a8abb2;
}

.node-meta {
    font-size: 11px;
    color: #c0c4cc;
}

.node-tag {
    transform: scale(0.8);
    transform-origin: right center;
}

/* ==========================================================================
   工作区
   ========================================================================== */

.workspace {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    background-color: #f0f2f5;
    min-width: 0;
}

.tabbar {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 6px 8px 0;
    background-color: #ffffff;
    border-bottom: 1px solid #e4e7ed;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 0 0 auto;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 8px 0 10px;
    border: 1px solid #e4e7ed;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background-color: #f5f7fa;
    font-size: 13px;
    color: #606266;
    cursor: pointer;
    white-space: nowrap;
    flex: 0 0 auto;
}

.tab-item:hover {
    color: #409eff;
}

.tab-item.active {
    background-color: #ffffff;
    color: #409eff;
    font-weight: 500;
}

.tab-icon {
    font-size: 13px;
}

.tab-sub {
    font-size: 11px;
    color: #c0c4cc;
}

.tab-close {
    font-size: 12px;
    color: #c0c4cc;
    border-radius: 50%;
    padding: 1px;
}

.tab-close:hover {
    color: #ffffff;
    background-color: #f56c6c;
}

.tabbar-actions {
    margin-left: auto;
    padding-bottom: 6px;
    flex: 0 0 auto;
}

.tab-body {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.tab-body>* {
    flex: 1;
    min-width: 0;
    min-height: 0;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #a8abb2;
    padding: 24px;
    text-align: center;
}

.empty-icon {
    font-size: 52px;
    color: #dcdfe6;
    margin-bottom: 14px;
}

.empty-title {
    margin: 0 0 6px;
    font-size: 15px;
    color: #909399;
}

.empty-desc {
    margin: 0;
    font-size: 13px;
    max-width: 460px;
    line-height: 1.8;
}

/* ==========================================================================
   通用工具条 / 元信息
   ========================================================================== */

.grid-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex: 0 0 auto;
    flex-wrap: wrap;
}

.grid-meta {
    font-size: 12px;
    color: #909399;
}

/* ==========================================================================
   数据网格
   ========================================================================== */

.grid-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px 12px 0;
    box-sizing: border-box;
}

.grid-table {
    flex: 1;
    min-height: 0;
}

.grid-cell {
    min-height: 24px;
    line-height: 24px;
    cursor: cell;
}

.cell-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.null-cell {
    color: #c0c4cc;
    font-style: italic;
    font-size: 12px;
}

.cell-editing input {
    height: 24px;
    padding: 0 6px;
    font-size: 12px;
}

.grid-head {
    display: flex;
    align-items: center;
    gap: 4px;
}

.grid-head-name {
    font-weight: 600;
}

.grid-head-type {
    font-size: 10px;
    font-weight: 400;
    color: #a8abb2;
}

.pk-icon {
    color: #e6a23c;
    font-size: 12px;
}

.grid-footer {
    display: flex;
    align-items: center;
    padding: 6px 0;
    flex: 0 0 auto;
}

.grid-sql {
    flex: 0 0 auto;
    max-height: 64px;
    overflow: auto;
    padding: 6px 10px;
    border-top: 1px solid #ebeef5;
    background-color: #fafafa;
    font-size: 12px;
    color: #606266;
    word-break: break-all;
}

.grid-sql code {
    font-family: Consolas, Monaco, monospace;
}

.filter-bar {
    background-color: #fafafa;
    border: 1px solid #ebeef5;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    flex: 0 0 auto;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 6px;
    border-top: 1px dashed #ebeef5;
    flex-wrap: wrap;
}

.insert-form .el-form-item {
    margin-bottom: 12px;
}

.insert-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

/* ==========================================================================
   表结构
   ========================================================================== */

.struct-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px 12px 0;
    box-sizing: border-box;
}

.struct-scroll {
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

.struct-section {
    margin-bottom: 18px;
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: #606266;
    margin: 4px 0 8px;
}

.ddl-box {
    margin: 0;
    padding: 14px 16px;
    background-color: #f8f8f9;
    border-radius: 6px;
    font-family: Consolas, Monaco, monospace;
    font-size: 12.5px;
    line-height: 1.7;
    color: #303133;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 60vh;
    overflow: auto;
}

.position-row {
    display: flex;
    align-items: center;
}

.form-hint {
    margin-left: 10px;
    font-size: 12px;
    color: #909399;
}

/* ==========================================================================
   新建表设计器（工作区标签页）
   ========================================================================== */

.designer-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px 12px 12px;
    box-sizing: border-box;
    gap: 8px;
}

.designer-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.designer-bar .db-name-input {
    width: 240px;
}

.designer-bar .db-comment-input {
    width: 190px;
}

.designer-bar .db-opt-select {
    width: 110px;
}

.designer-bar .db-opt-select.wide {
    width: 190px;
}

.designer-grid {
    flex: 1;
    min-height: 0;
}

.designer-grid .el-input__inner,
.designer-grid .el-select__wrapper {
    font-size: 12px;
}

.designer-grid .row-seq {
    font-size: 12px;
    color: #909399;
}

.designer-grid .cell-dash {
    color: #c0c4cc;
}

.designer-grid .len-cell {
    display: flex;
    gap: 4px;
}

.designer-grid .len-input {
    width: 100%;
}

.designer-foot {
    display: flex;
    align-items: center;
    gap: 12px;
}

.designer-tip {
    font-size: 12px;
    color: #909399;
}

/* ==========================================================================
   SQL 控制台
   ========================================================================== */

.sql-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px 12px 12px;
    box-sizing: border-box;
    gap: 8px;
}

.sql-editor {
    flex: 0 0 190px;
    width: 100%;
    resize: vertical;
    padding: 10px 12px;
    border: 1px solid #dcdfe6;
    border-radius: 6px;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.65;
    color: #303133;
    background-color: #fafafa;
    outline: none;
    box-sizing: border-box;
}

.sql-editor:focus {
    border-color: #409eff;
    background-color: #ffffff;
}

.sql-limit-label {
    font-size: 12px;
    color: #909399;
}

.sql-results {
    flex: 1;
    min-height: 0;
    display: flex;
}

.result-tabs {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.result-tabs .el-tabs__header {
    margin-bottom: 0;
}

.result-tabs .el-tabs__content {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.result-tabs .el-tab-pane {
    height: 100%;
}

.result-body {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: 6px;
    box-sizing: border-box;
}

.result-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 2px 6px;
    font-size: 12px;
    color: #909399;
    flex: 0 0 auto;
}

.result-grid-wrap {
    flex: 1;
    min-height: 0;
}

.result-error {
    margin-top: 4px;
}

.sql-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #c0c4cc;
    font-size: 13px;
}

.sql-empty .el-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.history-item {
    display: inline-block;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
}

/* ==========================================================================
   右键菜单
   ========================================================================== */

.ctx-menu {
    position: fixed;
    z-index: 3000;
    min-width: 176px;
    padding: 4px 0;
    background-color: #ffffff;
    border: 1px solid #e4e7ed;
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 21, 41, 0.12);
}

.ctx-item {
    padding: 7px 14px;
    font-size: 13px;
    color: #303133;
    cursor: pointer;
    white-space: nowrap;
}

.ctx-item:hover {
    background-color: #f5f7fa;
}

.ctx-item.danger {
    color: #f56c6c;
}

.ctx-item.danger:hover {
    background-color: #fef0f0;
}

.ctx-item.disabled {
    color: #c0c4cc;
    cursor: not-allowed;
}

.ctx-item.disabled:hover {
    background-color: transparent;
}

/* ==========================================================================
   抽屉 / 弹窗
   ========================================================================== */

.drawer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.divider-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #606266;
}

.ssh-tip {
    margin-bottom: 8px;
}

.el-scrollbar__thumb {
    background-color: #dcdfe6;
}

/* ==========================================================================
   登录页
   ========================================================================== */

.login-body {
    background: linear-gradient(135deg, #e9f1fe 0%, #f5f7fa 45%, #eef2f8 100%);
}

.login-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    box-sizing: border-box;
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 36px 32px 24px;
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 21, 41, 0.08);
    box-sizing: border-box;
}

.login-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.login-sub {
    margin: 0 0 26px;
    font-size: 13px;
    color: #909399;
}

.login-btn {
    width: 100%;
    letter-spacing: 2px;
}

.login-tip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin: 2px 0 0;
    font-size: 12px;
    color: #c0c4cc;
}

.login-footer {
    margin-top: 20px;
    font-size: 12px;
    color: #a8abb2;
}

.login-set {
    margin: 14px 0 0;
    text-align: center;
    font-size: 12px;
}

.login-set .el-link {
    font-size: 12px;
}

.set-icon {
    margin-right: 3px;
    font-size: 12px;
}

.server-hint {
    margin: 0;
    font-size: 12px;
    line-height: 1.7;
    color: #909399;
}

.server-hint code {
    padding: 1px 4px;
    border-radius: 3px;
    background-color: #f5f7fa;
    font-family: Consolas, Monaco, monospace;
    color: #e6a23c;
}

/* ============================== 导入导出 SQL ============================== */

.export-scope {
    width: 100%;
    border: 1px solid var(--el-border-color-lighter);
    border-radius: 6px;
    overflow: hidden;
}

.export-scope-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    border-bottom: 1px solid var(--el-border-color-lighter);
    background-color: #f5f7fa;
}

.export-scope-head .el-checkbox {
    height: auto;
}

.export-scope-meta {
    font-size: 12px;
    color: #909399;
}

.export-tables {
    display: flex;
    flex-direction: column;
    max-height: 200px;
    padding: 4px 0;
    overflow-y: auto;
}

.export-tables .el-checkbox {
    display: flex;
    height: 30px;
    margin-right: 0;
    padding: 0 12px;
}

.export-tables .el-checkbox:hover {
    background-color: #f5f7fa;
}

.export-tables .el-checkbox__label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
}

.view-tag {
    flex-shrink: 0;
    transform: scale(0.9);
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.export-options .el-checkbox {
    height: auto;
    margin-right: 0;
}

.import-upload {
    width: 100%;
}

.import-upload .el-upload-dragger {
    width: 100%;
    padding: 18px 0;
}

.import-upload .el-icon--upload {
    font-size: 36px;
    margin-bottom: 8px;
}

.import-result {
    width: 100%;
}

.import-error-item {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.6;
}

.import-error-item code {
    display: block;
    padding: 3px 6px;
    border-radius: 3px;
    background-color: rgba(0, 0, 0, 0.06);
    font-family: Consolas, Monaco, monospace;
    word-break: break-all;
}
