:root {
  --bg: #0a0e13;
  --bg-soft: #0f151d;
  --panel: #121a24;
  --panel-2: #17212d;
  --line: #1e2b3a;
  --line-soft: #172230;
  --text: #e8eef6;
  --text-dim: #93a4b8;
  --text-mute: #61708a;
  --accent: #4a9eff;
  --accent-dim: rgba(74, 158, 255, .13);
  --green: #24d19a;
  --amber: #f0b849;
  --red: #ff6b6b;
  --radius: 10px;
  --topbar-h: 56px;
  --sidebar-w: 200px;
}

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

/* 关键：让 hidden 属性优先于各组件自己声明的 display */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Segoe UI", system-ui, -apple-system, "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
.muted { color: var(--text-dim); font-size: 13px; }
.grow { flex: 1; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(180deg, #101822, #0c121a);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-mark {
  width: 9px; height: 9px; border-radius: 2px; align-self: center;
  background: linear-gradient(135deg, var(--accent), var(--green));
  box-shadow: 0 0 12px rgba(74, 158, 255, .7);
}
/* 品牌名不换行：中文名较长，窄屏下宁可压缩副标题也不要把名字拆成两行 */
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: .3px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.corp-picker select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 13px; min-width: 180px; cursor: pointer;
  outline: none;
}
.corp-picker select:focus { border-color: var(--accent); }

.health { font-size: 12px; color: var(--green); transition: color .3s; }
.health.bad { color: var(--red); }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 13px;
  cursor: pointer; transition: .15s; font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: #2d3f54; background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600;
}
.btn-primary:hover { background: #62aaff; border-color: #62aaff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); border-color: rgba(255,107,107,.3); }
.btn-danger:hover { background: rgba(255,107,107,.1); }
.btn-icon {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text-dim); cursor: pointer; font-size: 14px; font-family: inherit;
}
.btn-icon:hover { background: var(--panel-2); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn .ico { font-size: 14px; line-height: 1; }
.spin { animation: spin .9s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 侧栏 ---------------- */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  background: var(--bg-soft); border-right: 1px solid var(--line);
  padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; z-index: 30;
}
.nav-item {
  padding: 9px 12px; border-radius: 8px; color: var(--text-dim);
  font-size: 13.5px; cursor: pointer; transition: .15s; position: relative;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 500; }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 2px; height: 16px; background: var(--accent); border-radius: 2px;
}
.sidebar-foot {
  margin-top: auto; padding: 12px; font-size: 11.5px; color: var(--text-mute);
  border-top: 1px solid var(--line-soft); line-height: 1.8;
}
.sidebar-foot b { color: var(--text-dim); font-weight: 500; }

/* ---------------- 主区 ---------------- */
.main {
  margin: calc(var(--topbar-h) + 24px) 24px 24px calc(var(--sidebar-w) + 24px);
  min-height: calc(100vh - var(--topbar-h) - 48px);
}
.view-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 18px; gap: 16px;
}
.view-head h2 { font-size: 18px; font-weight: 600; margin-bottom: 4px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.panel-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-mute); margin-bottom: 12px; font-weight: 600;
}

/* ---------------- 空态 ---------------- */
.empty-state {
  max-width: 460px; margin: 12vh auto 0; text-align: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 44px 36px;
}
.empty-icon { font-size: 34px; margin-bottom: 14px; opacity: .55; }
.empty-state h2 { font-size: 17px; margin-bottom: 10px; font-weight: 600; }
.empty-state p { color: var(--text-dim); font-size: 13.5px; margin-bottom: 22px; }
.empty-hint {
  margin-top: 20px; font-size: 12px; color: var(--amber);
  background: rgba(240,184,73,.07); border: 1px solid rgba(240,184,73,.18);
  border-radius: 8px; padding: 10px 12px; text-align: left; line-height: 1.7;
}
.empty-hint:empty { display: none; }

/* ---------------- 通讯录 ---------------- */
.contacts-layout {
  display: grid; grid-template-columns: 232px 1fr; gap: 16px;
  align-items: start; height: calc(100vh - var(--topbar-h) - 48px);
}
.dept-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 10px;
  height: 100%; overflow-y: auto;
}
.dept-tree { font-size: 13.5px; }
.dept-node {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; border-radius: 7px; cursor: pointer;
  color: var(--text-dim); transition: .12s; user-select: none;
}
.dept-node:hover { background: var(--panel-2); color: var(--text); }
.dept-node.active { background: var(--accent-dim); color: var(--accent); }
.dept-node .caret {
  width: 14px; text-align: center; font-size: 9px; color: var(--text-mute);
  transition: transform .15s; flex-shrink: 0;
}
.dept-node .caret.open { transform: rotate(90deg); }
.dept-node .caret.leaf { visibility: hidden; }
.dept-node .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dept-node .cnt { font-size: 11px; color: var(--text-mute); }

.member-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); height: 100%;
  display: flex; flex-direction: column; overflow: hidden;
}
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.count { font-size: 12.5px; color: var(--text-mute); margin-left: auto; }

.input {
  background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 8px 12px;
  font-size: 13.5px; font-family: inherit; width: 100%; outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-mute); }
.toolbar .input { max-width: 340px; }
select.input { cursor: pointer; }
textarea.input { resize: vertical; line-height: 1.6; }

.table-wrap { flex: 1; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); color: var(--text-mute);
  font-weight: 500; font-size: 12px; text-align: left;
  padding: 10px 14px; letter-spacing: .3px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  color: var(--text-dim); vertical-align: middle;
}
.data-table tbody tr { cursor: pointer; transition: background .1s; }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table tbody tr:hover td { color: var(--text); }
.data-table .name-cell { color: var(--text); font-weight: 500; }
.data-table td:last-child { white-space: nowrap; }
.data-table .col-key { color: #7e93ab; font-size: 12px; }
.data-table .col-act { display: flex; gap: 4px; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover;
  background: linear-gradient(135deg, #1e3048, #16202c);
  display: inline-grid; place-items: center; vertical-align: middle;
  font-size: 12px; color: #8fb0d4; border: 1px solid #26394f;
  flex-shrink: 0;
}
img.avatar { border: 1px solid var(--line); }
.data-table td .avatar { margin-right: 9px; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  font-size: 11.5px; background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--line); margin: 1px 3px 1px 0;
}
.tag-accent { background: var(--accent-dim); color: var(--accent); border-color: rgba(74,158,255,.25); }
.tag-green { background: rgba(36,209,154,.1); color: var(--green); border-color: rgba(36,209,154,.22); }
.tag-amber { background: rgba(240,184,73,.1); color: var(--amber); border-color: rgba(240,184,73,.22); }
.tag-mute { opacity: .6; }

.table-empty { padding: 40px; text-align: center; color: var(--text-mute); font-size: 13px; }

.pager {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--line-soft);
  font-size: 12.5px; color: var(--text-mute);
}
.pager:empty { display: none; }

/* ---------------- 抽屉 ---------------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 92vw;
  background: var(--bg-soft); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 60;
  box-shadow: -20px 0 50px rgba(0,0,0,.45);
  animation: slideIn .22s ease;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--line);
}
.drawer-user { display: flex; gap: 12px; align-items: center; }
.drawer-user .avatar { width: 44px; height: 44px; font-size: 15px; }
.drawer-user h3 { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.drawer-user .sub { font-size: 12.5px; color: var(--text-mute); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 24px; }
.drawer-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
  background: var(--panel);
}

.info-grid {
  display: grid; grid-template-columns: 84px 1fr; gap: 9px 14px;
  font-size: 13px; margin-bottom: 22px;
}
.info-grid dt { color: var(--text-mute); }
.info-grid dd { color: var(--text-dim); word-break: break-all; }

.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-mute); font-weight: 600; margin: 0 0 12px;
  padding-top: 16px; border-top: 1px solid var(--line-soft);
}

.labeled { display: block; margin-bottom: 14px; }
.labeled > span {
  display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px;
}
.labeled > span em {
  font-style: normal; color: var(--text-mute); font-size: 11.5px; margin-left: 6px;
}
.required-star { color: var(--red); margin-left: 2px; }

.check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-dim); cursor: pointer; user-select: none;
}
.check input { accent-color: var(--accent); width: 14px; height: 14px; }
.switch-row { display: flex; gap: 20px; flex-wrap: wrap; margin: 6px 0 14px; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.scrim {
  position: fixed; inset: 0; background: rgba(3, 6, 10, .6);
  backdrop-filter: blur(2px); z-index: 50; animation: fadeIn .18s;
}
@keyframes fadeIn { from { opacity: 0; } }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; display: grid; place-items: center;
  z-index: 70; background: rgba(3, 6, 10, .65); backdrop-filter: blur(3px);
  animation: fadeIn .16s;
}
.modal-box {
  width: 520px; max-width: 92vw; max-height: 88vh; overflow: auto;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}
.tip {
  font-size: 12px; color: var(--text-mute); line-height: 1.7;
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 10px 12px;
}

/* ---------------- 日志 ---------------- */
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.log-list { display: flex; flex-direction: column; gap: 1px; max-height: 60vh; overflow-y: auto; }
.log-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 7px; font-size: 12.5px;
}
.log-row:nth-child(odd) { background: var(--panel-2); }
.log-row .t { color: var(--text-dim); font-size: 11.5px; white-space: nowrap; flex-shrink: 0; }
.log-row .m { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ---------------- 接入配置 ---------------- */
.setup-card { display: flex; flex-direction: column; gap: 18px; }
.setup-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 14px; align-items: center; }
.setup-row .k { color: var(--text-dim); font-size: 13px; }
.setup-row .v {
  font-family: "Cascadia Code", Consolas, monospace; font-size: 12.5px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 12px; color: var(--accent);
  overflow-x: auto; white-space: nowrap;
}
.setup-note {
  font-size: 12.5px; color: var(--text-mute); line-height: 1.9;
  border-left: 2px solid var(--line); padding-left: 14px;
}
.setup-note code {
  background: var(--panel-2); padding: 1px 6px; border-radius: 4px;
  color: var(--text-dim); font-size: 12px;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 11px 20px; border-radius: 9px;
  font-size: 13px; z-index: 90; box-shadow: 0 10px 34px rgba(0,0,0,.5);
  animation: toastIn .2s ease; max-width: 80vw;
}
.toast.ok { border-color: rgba(36,209,154,.4); }
.toast.err { border-color: rgba(255,107,107,.45); color: #ffc9c9; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------------- 响应式 ---------------- */
@media (max-width: 980px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    top: var(--topbar-h); left: 0; right: 0; bottom: auto; width: auto;
    flex-direction: row; padding: 6px 10px; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line); gap: 4px;
  }
  .sidebar-foot { display: none; }
  .nav-item.active::before { display: none; }
  .main { margin: calc(var(--topbar-h) + 52px) 14px 20px; }
  .contacts-layout { grid-template-columns: 1fr; height: auto; }
  .dept-panel { max-height: 200px; }
  .member-panel { height: 65vh; }
  .split-2 { grid-template-columns: 1fr; }
  .setup-row { grid-template-columns: 1fr; gap: 6px; }
}

/* 顶栏在窄屏收窄：先隐藏副标题，再压缩企业下拉，最后只留同步图标 */
@media (max-width: 760px) {
  .topbar { padding: 0 12px; }
  .brand-sub { display: none; }
  .topbar-right { gap: 8px; }
  .corp-picker select { min-width: 0; max-width: 170px; }
}

@media (max-width: 520px) {
  .corp-picker select { max-width: 150px; }
  #btnSync { padding-left: 10px; padding-right: 10px; }
  .btn-label { display: none; }
}
