:root {
  --bg: #0b0d12;
  --bg-elev: #141821;
  --bg-elev-2: #1b2130;
  --line: #262d3b;
  --text: #e8ecf3;
  --text-dim: #8b93a7;
  --text-mute: #5f677a;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --green: #35c880;
  --green-soft: rgba(53, 200, 128, 0.16);
  --red: #ff6b6b;
  --red-soft: rgba(255, 107, 107, 0.16);
  --amber: #f2b64c;
  --radius: 16px;
  --radius-sm: 11px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Author display:flex on .login-view / .app-view would otherwise override the
   UA [hidden] rule and leave both screens stacked after login. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { overflow: hidden; }

button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(79, 140, 255, 0.18), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 24px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.login-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #7db0ff);
  box-shadow: 0 8px 24px rgba(79, 140, 255, 0.4);
  margin-bottom: 18px;
}
.login-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0.5px; }
.login-sub { margin: 6px 0 22px; color: var(--text-dim); font-size: 14px; }
.login-input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%;
  height: 50px;
  margin-top: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.05s;
}
.login-btn:active { transform: scale(0.98); }
.login-btn:disabled { opacity: 0.6; }
.login-error {
  margin: 14px 0 0;
  color: var(--red);
  font-size: 13px;
  text-align: center;
}

/* ---------- App shell ---------- */
.app-view {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(10px + var(--safe-top)) 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(11, 13, 18, 0.86);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.top-title { margin: 0; font-size: 18px; font-weight: 700; }
.top-action {
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}
.top-action:active { background: var(--bg-elev); }

.screen {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
}
.loading, .empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 60px 20px;
  font-size: 14px;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(15, 18, 25, 0.94);
  backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-mute);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 0;
}
.tab-ico { font-size: 19px; line-height: 1; }
.tab-lbl { font-size: 11px; }
.tab.is-active { color: var(--accent); }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.4px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-cell {
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
}
.stat-num { font-size: 26px; font-weight: 700; letter-spacing: 0.5px; }
.stat-lbl { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat-cell.green .stat-num { color: var(--green); }
.stat-cell.red .stat-num { color: var(--red); }

.delta-row {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  justify-content: center;
}
.pill.join { background: var(--green-soft); color: var(--green); }
.pill.leave { background: var(--red-soft); color: var(--red); }

.meta-line { color: var(--text-mute); font-size: 12px; margin-top: 4px; }

/* ---------- List rows ---------- */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row:active { background: rgba(255, 255, 255, 0.03); }
.row-main { flex: 1; min-width: 0; }
.row-name { font-size: 15px; font-weight: 500; }
.row-sub {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.avatar {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}
.avatar.leave { background: var(--red-soft); color: var(--red); }
.avatar.join { background: var(--green-soft); color: var(--green); }
.tag {
  flex: none;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.tag.resigned { color: var(--red); border-color: rgba(255,107,107,0.4); }

/* ---------- Org tree ---------- */
.tree-node { }
.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}
.tree-row:active { background: rgba(255, 255, 255, 0.03); }
.twisty {
  width: 26px;
  height: 26px;
  flex: none;
  border: none;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border-radius: 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.twisty.leaf { background: transparent; color: var(--text-mute); }
.tree-name { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-name.user { font-weight: 400; }
.tree-name.resigned { color: var(--text-mute); text-decoration: line-through; }
.tree-count { flex: none; font-size: 12px; color: var(--text-mute); }
.tree-children { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 2px; }
.tree-children.collapsed { display: none; }

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar.wrap { flex-wrap: wrap; }
.source-row {
  display: flex;
  gap: 8px;
}
.source-select {
  flex: 1;
  width: 100%;
  height: 46px;
  padding: 0 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.source-select:focus { border-color: var(--accent); }
.source-select:disabled { opacity: 0.6; }
.search-box {
  flex: 1;
  height: 44px;
  padding: 0 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.search-box:focus { border-color: var(--accent); }
.chip {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- Detail sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 80dvh;
  background: var(--bg-elev);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 8px 18px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  animation: sheetUp 0.22s ease;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line);
  margin: 8px auto 4px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-title { margin: 6px 0 10px; font-size: 18px; font-weight: 700; }
.sheet-close {
  border: none; background: var(--bg-elev-2); color: var(--text-dim);
  width: 30px; height: 30px; border-radius: 50%; font-size: 20px; line-height: 1;
}
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.kv { display: flex; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv-k { width: 92px; flex: none; color: var(--text-dim); }
.kv-v { flex: 1; word-break: break-all; }

.section-label {
  margin: 18px 2px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.section-label:first-child { margin-top: 2px; }
