/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 14px; background: #f0f2f5; color: #1d2129; }

/* ── Activity bar & views ─────────────────────────────────── */
.activity-bar {
  position: fixed; inset: 0 auto 0 0; width: 48px; z-index: 120;
  background: #0b1f33; border-right: 1px solid rgba(255,255,255,.08);
  display: flex; flex-direction: column; align-items: center; padding-top: 10px; gap: 4px;
}
.activity-button {
  width: 48px; height: 44px; border: 0; border-left: 2px solid transparent;
  background: transparent; color: rgba(255,255,255,.56); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.activity-button:hover { color: #fff; background: rgba(255,255,255,.07); }
.activity-button.active { color: #fff; border-left-color: #4096ff; background: rgba(255,255,255,.1); }
.dashboard-shell { min-width: 0; margin-left: 48px; }
.dashboard-view[hidden] { display: none !important; }

/* ── Login ────────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #0d1b4b 0%, #1677ff 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: #fff; border-radius: 16px;
  padding: 48px 44px 40px;
  width: 400px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  text-align: center;
}
.login-logo { margin-bottom: 16px; display: flex; justify-content: center; }
.login-title { font-size: 22px; font-weight: 700; color: #1d2129; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: #86909c; margin-bottom: 28px; }
.login-form { text-align: left; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 13px; color: #4e5969; margin-bottom: 6px; font-weight: 500; }
.login-field input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid #e5e6eb; border-radius: 8px;
  font-size: 14px; outline: none; transition: border-color .2s;
}
.login-field input:focus { border-color: #1677ff; box-shadow: 0 0 0 3px rgba(22,119,255,.12); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; }
.toggle-pw {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: #86909c; padding: 2px;
}
.toggle-pw:hover { color: #1677ff; }
.login-error { color: #f53f3f; font-size: 13px; margin-bottom: 12px; padding: 8px 12px; background: #fff2f0; border-radius: 6px; border: 1px solid #ffccc7; }
.login-btn {
  width: 100%; height: 44px; background: #1677ff; color: #fff;
  border: none; border-radius: 8px; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: background .2s; margin-top: 4px;
}
.login-btn:hover { background: #0958d9; }
.login-btn:active { background: #003eb3; }

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
  height: 56px; background: #001529;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.navbar-left { display: flex; align-items: center; gap: 12px; }
.navbar-title { font-size: 18px; font-weight: 700; color: #fff; }
.navbar-tag {
  font-size: 12px; color: rgba(255,255,255,.65);
  background: rgba(255,255,255,.1); border-radius: 4px;
  padding: 2px 8px; margin-left: 4px;
}
.navbar-right { display: flex; align-items: center; gap: 12px; }
.navbar-user { font-size: 13px; color: rgba(255,255,255,.8); }
.btn-logout {
  height: 30px; padding: 0 14px; font-size: 13px;
  background: rgba(255,255,255,.12); color: rgba(255,255,255,.9);
  border: 1px solid rgba(255,255,255,.2); border-radius: 6px;
  cursor: pointer; transition: background .2s;
}
.btn-logout:hover { background: rgba(255,255,255,.22); }

/* ── User menu (avatar + dropdown) ──────────────────────────── */
.user-menu { position: relative; display: flex; align-items: center; gap: 8px; cursor: pointer; }

.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #1677ff, #69b1ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  cursor: pointer; user-select: none; flex-shrink: 0;
  transition: opacity .2s;
}
.user-avatar:hover { opacity: .85; }
.user-avatar.user-avatar-lg {
  width: 44px; height: 44px; font-size: 18px;
}

.user-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 10px);
  width: 200px; background: #fff; border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,21,41,.18), 0 2px 8px rgba(0,0,0,.08);
  z-index: 2000; overflow: hidden;
}
.user-dropdown.show { display: block; }

.user-dropdown-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 12px;
}
.user-dropdown-name {
  font-size: 14px; font-weight: 600; color: #1d2129;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-dropdown-divider { height: 1px; background: #f2f3f5; margin: 0 12px; }

.user-dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 16px; font-size: 13px; color: #4e5969;
  cursor: pointer; transition: background .15s;
}
.user-dropdown-item:hover { background: #f5f7fa; color: #1677ff; }
.user-dropdown-item svg { flex-shrink: 0; color: inherit; }

/* ── Filter bar ───────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  background: #fff; padding: 16px 24px;
  border-bottom: 1px solid #e5e6eb;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  position: sticky; top: 56px; z-index: 90;
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group label { font-size: 13px; color: #4e5969; font-weight: 500; white-space: nowrap; }
.filter-input {
  height: 34px; padding: 0 10px; border: 1px solid #e5e6eb;
  border-radius: 6px; font-size: 13px; outline: none;
  color: #1d2129; transition: border-color .2s;
}
.filter-input:focus { border-color: #1677ff; }
.filter-sep { color: #86909c; font-size: 13px; }
.quick-btns { display: flex; gap: 4px; }
.quick-btn {
  height: 30px; padding: 0 12px; font-size: 13px;
  background: #f2f3f5; color: #4e5969; border: 1px solid #e5e6eb;
  border-radius: 6px; cursor: pointer; transition: all .2s;
}
.quick-btn:hover { color: #1677ff; border-color: #1677ff; background: #e8f3ff; }
.quick-btn.active { color: #1677ff; border-color: #1677ff; background: #e8f3ff; font-weight: 600; }
.btn-query {
  height: 34px; padding: 0 20px; font-size: 14px; font-weight: 600;
  background: #1677ff; color: #fff; border: none;
  border-radius: 6px; cursor: pointer; transition: background .2s;
  margin-left: auto;
}
.btn-query:hover { background: #0958d9; }
.btn-query:disabled { cursor: wait; opacity: .68; }

/* ── Export menu ───────────────────────────────────────────── */
.export-wrap {
  position: relative;
  display: inline-block;
  margin-left: 12px;
}
.btn-export {
  height: 34px; padding: 0 16px; font-size: 14px; font-weight: 500;
  background: #fff; color: #1677ff; border: 1px solid #1677ff;
  border-radius: 6px; cursor: pointer; transition: all .2s;
  display: flex; align-items: center; gap: 6px;
}
.btn-export:hover {
  background: #e8f3ff;
  border-color: #0958d9;
  color: #0958d9;
}
.export-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 999;
  min-width: 160px;
  background: #fff;
  border: 1px solid #e5e6eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: 4px 0;
}
.export-item {
  padding: 10px 16px;
  font-size: 13px;
  color: #1d2129;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s;
}
.export-item:hover {
  background: #f7f8fa;
  color: #1677ff;
}
.export-item svg {
  flex-shrink: 0;
}

/* ── KPI cards ────────────────────────────────────────────── */
.kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  padding: 20px 24px 0;
}
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  background: #fff; border-radius: 10px;
  padding: 20px 20px 18px;
  display: flex; gap: 16px; align-items: flex-start;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  transition: box-shadow .2s;
}
.kpi-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.kpi-icon {
  width: 48px; height: 48px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon-blue   { background: #e8f3ff; color: #1677ff; }
.kpi-icon-green  { background: #e8ffea; color: #00b42a; }
.kpi-icon-orange { background: #fff7e8; color: #ff7d00; }
.kpi-icon-purple { background: #f0e8ff; color: #7816ff; }
.kpi-body { flex: 1; min-width: 0; }
.kpi-label { font-size: 13px; color: #86909c; margin-bottom: 6px; }
.kpi-value { font-size: 28px; font-weight: 700; color: #1d2129; line-height: 1.1; }
.kpi-sub { font-size: 12px; color: #86909c; margin-top: 4px; }

/* ── Chart grid ───────────────────────────────────────────── */
.chart-row {
  display: flex; gap: 16px; padding: 16px 24px 0;
  flex-wrap: wrap;
}
.chart-row-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
}
.chart-card {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow: hidden;
}
.chart-card-half { flex: 1 1 calc(50% - 8px); min-width: 320px; }
.chart-card-quarter { flex: 1 1 calc(25% - 12px); min-width: 240px; }
.chart-card-calendar { flex: 2 1 calc(50% - 8px); min-width: 520px; }
.chart-row-grid .chart-card { min-width: 0; }
.chart-row-grid .chart-card-calendar { grid-column: span 2; }
.chart-header {
  padding: 16px 20px 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.chart-title { font-size: 15px; font-weight: 600; color: #1d2129; }
.chart-subtitle { font-size: 12px; color: #86909c; font-weight: 400; }
.chart-body { height: 280px; padding: 8px 4px 4px; }
.chart-card-calendar .chart-body { height: 280px; padding: 4px 12px 8px; }
.latest-users-body {
  height: 280px;
  padding: 10px 10px 12px 16px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}
.latest-users-body::-webkit-scrollbar { width: 6px; }
.latest-users-body::-webkit-scrollbar-track { background: transparent; }
.latest-users-body::-webkit-scrollbar-thumb { background: #c9cdd4; border-radius: 3px; }
.latest-users-body::-webkit-scrollbar-thumb:hover { background: #a9aeb8; }
.latest-user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid #f2f3f5;
}
.latest-user-row:last-child { border-bottom: none; }
.latest-rank {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #f2f3f5; color: #86909c; font-size: 12px; font-weight: 600;
}
.latest-user-row:nth-child(1) .latest-rank { background: #fff7e8; color: #ff7d00; }
.latest-user-row:nth-child(2) .latest-rank { background: #e8f3ff; color: #1677ff; }
.latest-user-row:nth-child(3) .latest-rank { background: #e8ffea; color: #00b42a; }
.latest-main { min-width: 0; flex: 1; }
.latest-name { font-size: 13px; color: #1d2129; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.latest-time { font-size: 11px; color: #86909c; margin-top: 2px; }
.latest-tokens { flex-shrink: 0; font-size: 13px; font-weight: 600; color: #1677ff; }
.latest-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: #86909c; font-size: 13px; line-height: 1.6; padding: 0 8px;
}
.latest-empty-sub { font-size: 12px; color: #c9cdd4; margin-top: 4px; }

/* ── Skill analytics ──────────────────────────────────────── */
.skill-chart-row { display: grid; grid-template-columns: minmax(0, 1fr); }
.skill-trend-card { min-width: 0; }
.skill-chart-body { height: 330px; }
.skill-chart-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-bottom: 24px;
}
.skill-chart-grid .chart-card { min-width: 0; }
.skill-chart-grid .chart-body { height: 310px; }
@media (max-width: 1000px) {
  .skill-chart-row, .skill-chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .activity-bar { width: 42px; }
  .activity-button { width: 42px; }
  .dashboard-shell { margin-left: 42px; }
  .navbar { padding: 0 12px; }
  .navbar-tag { display: none; }
  .filter-bar { padding: 12px; gap: 12px; }
  .kpi-row, .chart-row { padding-left: 12px; padding-right: 12px; }
  .table-card { margin-left: 12px; margin-right: 12px; }
  .chart-header { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 1100px) {
  .chart-row-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-row-grid .chart-card-calendar { grid-column: span 2; }
}
@media (max-width: 640px) {
  .chart-row-grid { grid-template-columns: 1fr; }
  .chart-row-grid .chart-card-calendar { grid-column: span 1; }
}

/* ── Table ────────────────────────────────────────────────── */
.table-card {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  margin: 16px 24px 24px; overflow: hidden;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { background: #f7f8fa; }
th {
  padding: 12px 16px; text-align: left;
  font-size: 13px; font-weight: 600; color: #4e5969;
  border-bottom: 1px solid #e5e6eb; white-space: nowrap;
}
td {
  padding: 12px 16px; font-size: 13px; color: #1d2129;
  border-bottom: 1px solid #f2f3f5;
}
tbody tr:hover { background: #f7f8fa; }
tbody tr:last-child td { border-bottom: none; }
.table-empty { text-align: center; color: #86909c; padding: 32px; }

/* ── Org tree dropdown ───────────────────────────────────────── */
.org-select-wrap {
  position: relative;
  display: inline-block;
}
.org-select-btn {
  height: 32px;
  min-width: 96px;
  max-width: 180px;
  padding: 0 10px;
  border: 1px solid #e5e6eb;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  color: #1d2129;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color .15s;
}
.org-select-btn:hover { border-color: #1677ff; color: #1677ff; }
.org-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 999;
  min-width: 200px;
  max-width: 280px;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e6eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  padding: 4px 0;
}
/* Tree list reset */
.org-tree-ul, .org-tree-li { list-style: none; margin: 0; padding: 0; }
.org-tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  cursor: pointer;
  font-size: 13px;
  color: #1d2129;
  user-select: none;
  border-radius: 4px;
  margin: 0 4px;
  transition: background .1s;
}
.org-tree-row:hover { background: #f2f3f5; }
.org-tree-row.selected { background: #e8f3ff; color: #1677ff; }
.org-all-row {
  font-size: 13px;
  color: #86909c;
  padding: 0 8px;
  height: 32px;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-radius: 4px;
  margin: 0 4px 2px;
  border-bottom: 1px solid #f2f3f5;
}
.org-all-row:hover { background: #f2f3f5; color: #1d2129; }
.org-tree-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  font-size: 10px;
  color: #86909c;
  flex-shrink: 0;
  cursor: pointer;
  transition: color .1s;
}
.org-tree-arrow:hover { color: #1677ff; }
.org-tree-arrow-leaf { visibility: hidden; }
.org-tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
