/* ============ 设计基调：白色简约 ============ */
:root {
  --primary: #2563eb;          /* 主色：克制的蓝，仅用于按钮/激活态/链接 */
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.08);

  --bg: #f6f8fa;               /* 页面底色 */
  --surface: #ffffff;          /* 卡片/面板底色 */
  --surface-2: #f1f5f9;        /* 次要面（表头、交替行） */

  --text: #0f172a;             /* 正文/标题 */
  --text-2: #475569;           /* 次要文字 */
  --text-3: #94a3b8;           /* 占位/提示文字 */

  --border: #e2e8f0;           /* 常规边框 */
  --border-strong: #cbd5e1;    /* 强调边框 */

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* 去掉原玻璃拟态的背景光斑 */
.bg-orbs { display: none; }

/* 面板/卡片：白底 + 细边框 + 轻阴影 */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.card { border-radius: var(--radius); }

[hidden] { display: none !important; }

/* ============ 登录页 ============ */
.login-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  padding: 32px 28px;
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand-logo { font-size: 32px; }
.brand h1 { font-size: 20px; margin: 0; font-weight: 600; }
.brand p { margin: 4px 0 0; color: var(--text-3); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
label small { color: var(--text-3); }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
select option { background: #fff; color: var(--text); }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.form-row .col-port { flex: 0 0 110px; }
.login-hint { text-align: center; color: var(--text-3); font-size: 12px; margin: 14px 0 0; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface);
  transition: background .15s, border-color .15s, color .15s, transform .08s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-danger-ghost { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }
.btn-danger-ghost:hover { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 6px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text-2); width: 36px; height: 36px; border-radius: var(--radius-sm);
  font-size: 16px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.btn .spinner, #login-btn.loading .btn-label { display: none; }
#login-btn.loading .spinner { display: inline-block; }
.spinner {
  width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 主框架 ============ */
#app-view { position: relative; z-index: 1; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.topbar-meta {
  flex: 1; text-align: right; color: var(--text-3);
  font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#sidebar-toggle { display: none; }

.layout { display: flex; align-items: flex-start; }

.sidebar {
  width: 250px; flex-shrink: 0;
  margin: 14px 0 14px 14px;
  border-radius: var(--radius);
  position: sticky; top: 72px;
  max-height: calc(100vh - 88px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; }
.sidebar-head #table-filter { margin-top: 0; }
.sidebar-refresh { flex-shrink: 0; }
.db-tree { overflow-y: auto; padding: 8px; flex: 1; }

.db-group > .db-name {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  background: none; border: none; color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer; text-align: left;
  border-radius: var(--radius-sm);
}
.db-group > .db-name:hover { background: var(--surface-2); }
.db-name .arrow { transition: transform .15s; font-size: 10px; color: var(--text-3); width: 10px; display: inline-block; }
.db-group.open > .db-name .arrow { transform: rotate(90deg); }
.db-name .sys-tag {
  margin-left: auto; font-size: 10px; color: var(--warning);
  background: var(--warning-soft); padding: 1px 7px; border-radius: 20px;
}
.table-list { margin: 2px 0 6px 22px; }
.table-item {
  display: flex; align-items: center; gap: 7px;
  width: 100%; padding: 7px 10px;
  background: none; border: none; color: var(--text-2);
  font-size: 13px; cursor: pointer; text-align: left; border-radius: var(--radius-sm);
}
.table-item:hover { background: var(--surface-2); color: var(--text); }
.table-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 500;
}
.table-item .view-tag { font-size: 10px; color: #0891b2; }
.sidebar-mask { display: none; }

.content { flex: 1; min-width: 0; padding: 14px 18px 40px; }

/* ============ Tabs ============ */
.tabs {
  display: flex; gap: 4px; padding: 6px;
  border-radius: var(--radius); margin-bottom: 14px;
}
.tab {
  flex: 1; padding: 9px 12px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2); font-size: 13.5px;
  cursor: pointer; transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* ============ 数据浏览 ============ */
.empty { border-radius: var(--radius); padding: 60px 20px; text-align: center; color: var(--text-3); }
.panel-head {
  border-radius: var(--radius); padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.panel-title h2 { margin: 0; font-size: 16px; font-weight: 600; word-break: break-all; }
.chip {
  font-size: 12px; color: var(--text-2);
  background: var(--surface-2); padding: 3px 10px; border-radius: 20px; white-space: nowrap;
}
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.subtabs { display: flex; gap: 4px; margin-bottom: 10px; }
.subtab {
  padding: 7px 14px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
  background: transparent; color: var(--text-2);
  border: 1px solid transparent;
}
.subtab:hover { background: var(--surface-2); }
.subtab.active { background: var(--surface); color: var(--primary); border-color: var(--border); font-weight: 500; }

.table-wrap { border-radius: var(--radius); overflow: auto; margin-bottom: 12px; }
.block-title { margin: 0; padding: 14px 16px 4px; font-size: 13px; color: var(--text-2); font-weight: 600; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: max-content; }
.data-table th, .data-table td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  max-width: 340px;
}
.data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  color: var(--text-2); font-weight: 600; white-space: nowrap;
  cursor: default;
}
.data-table thead th.sortable { cursor: pointer; user-select: none; }
.data-table thead th.sortable:hover { color: var(--primary); }
.data-table tbody tr:hover { background: var(--primary-soft); }
.cell-null { color: var(--text-3); font-style: italic; }
.cell-bin { color: var(--warning); font-family: ui-monospace, monospace; }
.cell-text {
  white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
}
.row-actions { display: flex; gap: 6px; }
.mini-btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-2); border-radius: var(--radius-sm); padding: 4px 10px;
  font-size: 12px; cursor: pointer;
}
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.mini-btn.del { color: var(--danger); border-color: #fecaca; }
.mini-btn.del:hover { background: var(--danger-soft); }
.pk-badge { font-size: 10px; color: var(--warning); margin-left: 4px; }

.pager {
  border-radius: var(--radius); padding: 10px 14px;
  display: flex; align-items: center; gap: 12px; justify-content: center;
}
.pager #page-info { font-size: 13px; color: var(--text-2); }
.select-sm {
  width: auto; margin: 0; padding: 6px 8px; font-size: 13px; border-radius: var(--radius-sm);
}

.meta-table td, .meta-table th { max-width: 420px; }
.tag-yes { color: var(--success); }
.tag-no { color: var(--text-3); }
.mono { font-family: ui-monospace, monospace; }

/* ============ SQL 控制台 ============ */
.query-editor { border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.query-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.query-toolbar .select-sm { flex: 0 0 auto; max-width: 220px; }
#query-run { margin-left: auto; }
kbd {
  font-size: 11px; background: var(--surface-2); border-radius: 4px;
  padding: 1px 6px; font-family: inherit; color: var(--text-2);
}
#query-sql {
  min-height: 160px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px;
  line-height: 1.6;
}
.result-meta { font-size: 13px; color: var(--text-2); margin: 0 0 10px 4px; }
.result-meta .ok { color: var(--success); font-weight: 500; }
.result-meta .warn { color: var(--warning); font-weight: 500; }

/* ============ 服务器状态 ============ */
.metric-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 14px;
}
.metric {
  border-radius: var(--radius); padding: 16px;
}
.metric .label { font-size: 12px; color: var(--text-3); margin-bottom: 8px; }
.metric .value { font-size: 22px; font-weight: 600; word-break: break-all; }
.metric .value.small { font-size: 14px; font-weight: 500; }
.metric-clickable { cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .08s; }
.metric-clickable:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.metric-clickable:active { transform: scale(.98); }
.metric-more { color: var(--primary); font-size: 11px; font-weight: 400; opacity: 0; transition: opacity .15s; }
.metric-clickable:hover .metric-more { opacity: 1; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: grid; place-items: center; padding: 18px;
}
.modal {
  width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface);
}
.modal-sm { max-width: 400px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.form-field { margin-bottom: 14px; }
.form-field .field-head { display: flex; align-items: center; justify-content: space-between; }
.form-field .null-toggle { font-size: 12px; color: var(--text-2); display: flex; gap: 5px; align-items: center; }
.form-field .null-toggle input { width: auto; margin: 0; }
.form-field textarea { min-height: 74px; resize: vertical; font-family: ui-monospace, monospace; }
.form-field .temporal-row { display: flex; gap: 8px; align-items: stretch; }
.form-field .temporal-row input { flex: 1; min-width: 0; }
.form-field .temporal-row .now-btn { white-space: nowrap; }
.field-type { color: var(--text-3); font-size: 11px; font-weight: 400; margin-left: 6px; }

/* ============ Toast ============ */
.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(92vw, 380px);
}
.toast {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  animation: toastIn .25s ease;
  word-break: break-word;
  color: var(--text);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }
.toast.hide { opacity: 0; transform: translateX(20px); transition: all .25s; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }

/* ============ 移动端适配 ============ */
@media (max-width: 860px) {
  #sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar-title strong { display: none; }
  .topbar-meta { font-size: 11.5px; }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    margin: 0; z-index: 60;
    width: min(82vw, 300px);
    max-height: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-105%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(15, 23, 42, 0.4);
    opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  .sidebar-mask.show { opacity: 1; pointer-events: auto; }

  .content { padding: 12px 10px 36px; }
  .panel-head { padding: 10px 12px; }
  .panel-actions { width: 100%; }
  .panel-actions .btn { flex: 1; }
  .data-table th, .data-table td { padding: 8px 10px; max-width: 240px; }
  .tabs { overflow-x: auto; }
  .tab { flex: 0 0 auto; font-size: 12.5px; padding: 9px 14px; }
  .query-toolbar { flex-wrap: wrap; }
  #query-run { margin-left: 0; width: 100%; }
  .toasts { left: 12px; right: 12px; top: 12px; max-width: none; }
  .login-card { padding: 26px 20px; }
  .metric .value { font-size: 19px; }
}
