:root {
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e5e9f2;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
  --radius: 14px;
}

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

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

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #2563eb 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 18px;
  padding: 40px 34px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
}
.login-logo {
  font-size: 40px;
  text-align: center;
  margin-bottom: 8px;
}
.login-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  background: var(--primary);
  color: #fff;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn.full { width: 100%; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #dc2626; }
.btn.sm { padding: 6px 12px; font-size: 13px; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 8px;
}

.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--text-muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.btn.feishu { background: #3370ff; margin-top: 4px; }
.btn.feishu:hover { background: #245bdb; }

/* 门户使用次数角标 */
.app-card { position: relative; }
.clicks-badge {
  position: absolute; top: 10px; right: 12px;
  font-size: 11px; color: var(--text-muted);
  background: #f1f5f9; padding: 1px 8px; border-radius: 20px;
}

/* 拖拽排序 */
.drag-handle { cursor: grab; color: #cbd5e1; user-select: none; font-size: 16px; }
tr.dragging { opacity: .4; }
tr.drag-over td { border-top: 2px solid var(--primary); }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 62px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.topbar .brand .logo { font-size: 24px; }
.topbar .spacer { flex: 1; }
.topbar .search {
  width: 280px;
  max-width: 36vw;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #f8fafc;
}
.topbar .search:focus { outline: none; border-color: var(--primary); background: #fff; }

.user-menu { position: relative; margin-left: 16px; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; padding: 6px 8px; border-radius: 10px;
}
.user-btn:hover { background: #f1f5f9; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
}
.dropdown {
  position: absolute; right: 0; top: 48px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  min-width: 170px; padding: 6px; display: none;
}
.dropdown.open { display: block; }
.dropdown a, .dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border-radius: 8px; font-size: 14px;
  background: none; border: none; color: var(--text);
}
.dropdown a:hover, .dropdown button:hover { background: #f1f5f9; }

/* ---------- 门户主体 ---------- */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { margin-bottom: 24px; }
.page-head h2 { font-size: 24px; }
.page-head p { color: var(--text-muted); font-size: 14px; }

.category { margin-bottom: 34px; }
.category-title {
  font-size: 15px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px;
}
.category-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.app-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  cursor: pointer;
}
.app-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: transparent;
}
.app-icon {
  width: 46px; height: 46px; flex-shrink: 0;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #fff;
}
.app-icon img { width: 28px; height: 28px; object-fit: contain; }
.app-info { min-width: 0; }
.app-info .name { font-weight: 600; font-size: 15px; margin-bottom: 3px; }
.app-info .desc {
  font-size: 13px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

.empty {
  text-align: center; color: var(--text-muted);
  padding: 60px 20px; font-size: 15px;
}

/* ---------- 管理后台 ---------- */
.admin-tabs {
  display: flex; gap: 6px; margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.admin-tabs button {
  background: none; border: none; padding: 10px 16px;
  font-size: 15px; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.admin-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.toolbar { display: flex; align-items: center; margin-bottom: 16px; gap: 12px; }
.toolbar .spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; color: var(--text-muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: none; }
td .mini-icon {
  width: 30px; height: 30px; border-radius: 8px; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; background: #eef2ff; color: var(--primary); }
.tag.gray { background: #f1f5f9; color: var(--text-muted); }
.tag.role-admin { background: #fef3c7; color: #b45309; }
.row-actions { display: flex; gap: 6px; }
.link-btn { background: none; border: none; color: var(--primary); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: #eef2ff; }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: #fee2e2; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-mask.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 480px;
  padding: 26px; box-shadow: 0 20px 60px rgba(15,23,42,.3);
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-size: 18px; margin-bottom: 18px; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.icon-preview {
  display: flex; align-items: center; gap: 10px; margin-top: 6px;
}
.icon-preview .box {
  width: 40px; height: 40px; border-radius: 10px; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; z-index: 100;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.err { background: var(--danger); }

@media (max-width: 640px) {
  .topbar .search { display: none; }
  .grid { grid-template-columns: 1fr 1fr; }
  .modal .row2 { grid-template-columns: 1fr; }
  th.hide-sm, td.hide-sm { display: none; }
}
