:root {
    color-scheme: light;
    --bg: #f2f5f8;
    --surface: #fff;
    --surface2: #f7f9fa;
    --border: #e7edf2;
    --text: #26384b;
    --text2: #8292a0;
    --accent: #34566f;
    --accent2: #42657c;
    --green: #368368;
    --orange: #9a744c;
    --red: #bd5b5b;
    --blue: #517994;
    --radius: 10px;
    --shadow: 0 12px 35px rgba(30, 53, 74, .055);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.admin-header { height: 72px; position: sticky; top: 0; z-index: 70; background: rgba(255,255,255,.96); border-bottom: 1px solid #e8edf1; box-shadow: 0 3px 18px rgba(20,38,53,.035); backdrop-filter: blur(18px); }
.header-inner { max-width: 1680px; height: 100%; margin: auto; padding: 0 38px; display: flex; align-items: center; gap: 24px; }
.admin-brand { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; color: var(--text); text-decoration: none; font-size: 22px; font-weight: 750; letter-spacing: -.055em; }
.admin-brand strong { font-weight: 750; }
.brand-icon { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 11px; background: linear-gradient(145deg, #293f54, #57758a); color: white; font-size: 24px; line-height: 1; letter-spacing: 0; box-shadow: 0 5px 12px rgba(39,66,87,.15); }
.header-location { display: inline-flex; align-items: center; gap: 20px; color: #8794a1; font-size: 13px; font-weight: 600; white-space: nowrap; }
.location-divider { width: 1px; height: 22px; background: #dce3e9; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.header-link { padding: 10px 14px; border-radius: 9px; text-decoration: none; color: #607184; font-size: 13px; font-weight: 600; transition: background .18s, color .18s; white-space: nowrap; }
.header-link:hover { background: #f1f5f8; color: var(--text); }
.header-link-strong { color: var(--accent); background: #edf3f7; }
.header-link-strong:hover { background: #e3edf3; }

.visualizer-layout { max-width: 1680px; min-height: calc(100vh - 72px); margin: auto; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 72px; height: calc(100vh - 72px); min-width: 0; display: flex; flex-direction: column; padding: 28px 18px 24px; background: var(--surface); border-right: 1px solid var(--border); }
.sidebar-header { padding: 0 12px 18px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { margin: 0; color: #334a5d; font-size: 13px; font-weight: 750; }
.sidebar-header small { display: block; margin-top: 5px; color: #9aa8b4; font-size: 11px; }
.table-list { min-height: 0; overflow-y: auto; padding: 15px 0; scrollbar-color: #cddae3 transparent; }
.table-item { width: 100%; min-height: 47px; display: flex; align-items: center; gap: 10px; padding: 7px 11px; margin-bottom: 4px; border-radius: 10px; color: #65778a; cursor: pointer; transition: background .18s, color .18s, transform .18s; }
.table-item:hover { color: var(--text); background: #f2f6f8; transform: translateX(2px); }
.table-item.active { color: #263f54; background: #eaf1f5; box-shadow: inset 3px 0 #3d6078; }
.table-item .icon { width: 29px; height: 29px; flex: 0 0 29px; display: grid; place-items: center; border-radius: 7px; font-size: 12px; font-weight: 750; }
.table-item .info { min-width: 0; flex: 1; }
.table-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 700; }
.table-item .meta { margin-top: 3px; color: #9aa8b4; font-size: 10px; }
.table-item .badge { padding: 2px 6px; border-radius: 6px; background: #edf1f4; color: #83909d; font-size: 10px; font-variant-numeric: tabular-nums; }
.table-item.active .badge { background: #d9e5ed; color: #34556b; }

.main { min-width: 0; padding: 32px clamp(24px, 4vw, 56px) 68px; }
.page-heading { margin-bottom: 21px; }
.page-heading h1 { margin: 0; color: #25394b; font-size: 23px; letter-spacing: -.04em; }
.stats-bar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { min-width: 0; min-height: 91px; padding: 16px 18px; display: flex; align-items: center; gap: 13px; border: 1px solid #e9edf1; border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.stat-icon { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border-radius: 10px; background: #edf3f7; color: #51748c; font-size: 21px; font-weight: 600; }
.stat-num { color: #344e62; font-size: 25px; font-weight: 750; line-height: 1.1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 5px; color: #91a0ac; font-size: 11px; }
.visualizer-surface { min-width: 0; min-height: 590px; overflow: hidden; border: 1px solid #e9edf1; border-radius: 17px; background: var(--surface); box-shadow: var(--shadow); }
.tabs { display: flex; align-items: stretch; gap: 7px; padding: 11px 20px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { min-height: 46px; padding: 0 17px; flex: 0 0 auto; border: 0; border-bottom: 3px solid transparent; background: transparent; color: #7d8da0; font-size: 12px; font-weight: 650; white-space: nowrap; transition: color .18s, border-color .18s, background .18s; }
.tab:hover { color: var(--text); background: #f8fafb; }
.tab.active { color: #304e63; border-bottom-color: #3d6078; font-weight: 750; }
.content { min-width: 0; padding: 24px 26px 30px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.er-wrapper { position: relative; min-height: 560px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: #fbfcfd; }
.er-toolbar { position: absolute; top: 13px; right: 13px; z-index: 10; display: flex; align-items: center; gap: 3px; padding: 4px; border: 1px solid #dce6ed; border-radius: 8px; background: rgba(255,255,255,.96); box-shadow: 0 4px 14px rgba(30,53,74,.08); }
.er-toolbar button { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 5px; background: transparent; color: #52697b; font-size: 17px; }
.er-toolbar button:hover { background: #edf3f7; color: var(--accent); }
.er-toolbar .zoom-level { min-width: 42px; color: #738697; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; }
.er-toolbar .divider { width: 1px; height: 18px; margin: 0 3px; background: var(--border); }
.er-canvas { position: relative; width: 100%; height: 600px; overflow: hidden; cursor: grab; }
.er-canvas:active { cursor: grabbing; }
.er-canvas > .loading { position: absolute; inset: 0; z-index: 1; padding: 20px; }
.er-canvas > .loading .empty-state { width: min(100%, 360px); }
.er-canvas .mermaid { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.er-canvas .mermaid svg { min-width: 1200px; height: auto; }

.struct-card { margin-bottom: 20px; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.struct-card-header { min-height: 53px; padding: 13px 17px; display: flex; align-items: center; flex-wrap: wrap; gap: 9px; border-bottom: 1px solid var(--border); color: #344e62; background: #f8fafb; font-size: 13px; font-weight: 750; }
.struct-card-header .badge { padding: 3px 7px; border-radius: 6px; background: #eaf1f5; color: #52718a; font-size: 10px; font-weight: 700; }
.data-table { width: 100%; border-spacing: 0; border-collapse: separate; font-size: 12px; }
.data-table th, .data-table td { padding: 12px 13px; border-bottom: 1px solid #edf1f3; text-align: left; white-space: nowrap; vertical-align: middle; }
.data-table th { color: #82909e; background: #f7f9fa; font-size: 11px; font-weight: 750; }
.data-table td { color: #4b5c6e; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #f8fbfc; }
.data-table .pk { color: var(--orange); font-weight: 700; }
.data-table .fk { color: var(--accent); font-weight: 700; }
.data-table .type-tag { display: inline-block; padding: 3px 7px; border-radius: 5px; background: #edf3f7; color: #51748c; font-size: 10px; font-family: Consolas, monospace; }
.data-table .null-yes { color: var(--red); }
.data-table .null-no { color: var(--green); }
.fk-link { display: inline-flex; align-items: center; gap: 4px; padding: 3px 7px; border-radius: 5px; background: #edf3f7; color: var(--accent); font-size: 11px; }
.rel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.rel-card { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 13px 14px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafb; color: #465b6c; font-size: 12px; }
.rel-card .arrow { color: #50738b; font-size: 17px; }
.rel-card .from, .rel-card .to { font-family: Consolas, monospace; }
.rel-card .col { color: var(--text2); font-size: 11px; }

.browser-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-bottom: 20px; }
.browser-toolbar select, .pagination select { min-height: 39px; padding: 0 12px; border: 1px solid #dfe7ec; border-radius: 8px; outline: none; background: #f8fafb; color: var(--text); font-size: 12px; }
.browser-toolbar select { min-width: 200px; max-width: 100%; }
.browser-toolbar select:focus, .pagination select:focus, .edit-input:focus { border-color: #7290a4; box-shadow: 0 0 0 3px rgba(91,124,145,.12); background: #fff; }
.btn { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; border: 1px solid transparent; border-radius: 8px; font-size: 12px; font-weight: 650; white-space: nowrap; transition: background .18s, border-color .18s, transform .18s; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary { color: #fff; background: #304b60; border-color: #304b60; }
.btn-primary:hover:not(:disabled) { background: #42657c; border-color: #42657c; }
.btn-outline { color: #526b7f; background: #fff; border-color: #dce5eb; }
.btn-outline:hover:not(:disabled) { background: #f3f7f9; border-color: #bfcfd9; }
.btn:disabled { opacity: .52; cursor: not-allowed; }
.table-wrapper { width: 100%; overflow-x: auto; border: 1px solid #e9edf0; border-radius: 10px; scrollbar-color: #cddae3 transparent; }
.table-wrapper .data-table td { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.editable-cell { display: inline-block; padding: 2px 4px; margin: -2px -4px; border-radius: 4px; cursor: pointer; }
.editable-cell:hover { background: #edf3f7; outline: 1px dashed #92acbd; }
.edit-input { width: 100%; min-width: 80px; padding: 5px 8px; border: 1px solid #7290a4; border-radius: 6px; outline: none; color: var(--text); background: #fff; font-size: 12px; }
.pagination { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 9px; margin-top: 24px; }
.pagination span { color: #92a0ab; font-size: 11px; font-variant-numeric: tabular-nums; }
.pagination select { min-height: 34px; }
.empty-state { min-height: 195px; display: grid; place-items: center; padding: 32px; border: 1px dashed #dce6ed; border-radius: 10px; background: #fafcfd; color: #96a5b1; text-align: center; font-size: 13px; }
.empty-state p { margin: 0; }
.empty-state .empty-icon { font-size: 28px; margin-bottom: 8px; }
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text2); font-size: 12px; }
.spinner { width: 23px; height: 23px; flex: 0 0 23px; margin-right: 10px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast-container { position: fixed; top: 86px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { max-width: 380px; padding: 12px 18px; border-radius: 8px; color: #fff; font-size: 12px; box-shadow: 0 8px 24px rgba(23,40,53,.18); animation: toastIn .3s ease, toastOut .3s ease 2.2s forwards; }
.toast.success { background: #368368; }
.toast.error { background: #bd5b5b; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(30px); } }

@media (max-width: 1150px) {
    .visualizer-layout { grid-template-columns: 204px minmax(0, 1fr); }
    .main { padding: 26px 26px 54px; }
    .stats-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
    .admin-header { height: 64px; }
    .header-inner { padding: 0 18px; }
    .header-location { display: none; }
    .visualizer-layout { display: block; }
    .sidebar { position: sticky; top: 64px; z-index: 60; width: 100%; height: auto; padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar-header { display: none; }
    .table-list { display: flex; gap: 4px; overflow-x: auto; padding: 0 0 2px; scrollbar-width: none; }
    .table-list::-webkit-scrollbar { display: none; }
    .table-item { width: auto; min-width: max-content; min-height: 43px; margin: 0; padding: 5px 11px; gap: 7px; }
    .table-item.active { box-shadow: inset 0 -3px #3d6078; }
    .table-item .icon, .table-item .meta, .table-item .badge { display: none; }
    .table-item .name { font-size: 11px; }
    .main { padding: 22px 20px 46px; }
}
@media (max-width: 600px) {
    .admin-brand { font-size: 18px; }
    .brand-icon { width: 29px; height: 29px; font-size: 21px; }
    .header-actions { gap: 3px; }
    .header-link { padding: 8px; font-size: 11px; }
    .main { padding: 16px 12px 35px; }
    .page-heading { margin-bottom: 16px; }
    .page-heading h1 { font-size: 20px; }
    .stats-bar { gap: 8px; margin-bottom: 12px; }
    .stat-card { min-height: 72px; padding: 10px; gap: 8px; }
    .stat-icon { width: 29px; height: 29px; flex-basis: 29px; font-size: 16px; }
    .stat-num { font-size: 19px; }
    .stat-label { font-size: 10px; }
    .visualizer-surface { border-radius: 12px; }
    .tabs { padding: 6px 8px 0; gap: 0; }
    .tab { min-height: 42px; padding: 0 11px; font-size: 11px; }
    .content { padding: 14px 12px 20px; }
    .er-wrapper { min-height: 480px; }
    .er-canvas { height: 480px; }
    .er-toolbar { top: 8px; right: 8px; }
    .browser-toolbar select { width: 100%; }
    .rel-grid { grid-template-columns: 1fr; }
    .toast-container { top: 73px; right: 12px; left: 12px; }
}
