/* ========== 基础重置 ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f5f7fa;
  color: #1f2937;
  line-height: 1.6;
  min-height: 100vh;
}

/* ========== 顶部导航 ========== */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: #fff; border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  height: 56px; display: flex; align-items: center; justify-content: space-between;
}
.logo { font-size: 18px; font-weight: 700; color: #111827; display: flex; align-items: center; gap: 8px; }
.logo-img { height: 32px; width: auto; flex-shrink: 0; }
.login-logo { display: block; height: 40px; width: auto; margin: 0 auto 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right .nickname { font-size: 14px; color: #555; }


/* ========== 按钮 ========== */
.btn {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid #e5e7eb; background: #fff;
  color: #374151; transition: all .15s; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: #c7d2fe; color: #4f46e5; background: #fafbff; }
.btn-primary { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; color: #fff; }
.btn-primary:disabled { background: #a5b4fc; border-color: #a5b4fc; cursor: not-allowed; }
.btn-outline { background: #fff; color: #4f46e5; border: 1px solid #4f46e5; }
.btn-outline:hover { background: #fafbff; }
.btn-danger { background: #ef4444; border-color: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-success { background: #10b981; border-color: #10b981; color: #fff; }
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* ========== 页面容器 ========== */
.container { max-width: 1200px; margin: 0 auto; padding: 32px 24px 64px; }
.container-narrow { max-width: 480px; margin: 0 auto; padding: 40px 20px; }

/* ========== 卡片 ========== */
.card {
  background: #fff; border-radius: 12px; padding: 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid #e5e7eb;
}
.card h2 { font-size: 22px; margin-bottom: 8px; color: #111827; }
.card .subtitle { font-size: 14px; color: #9ca3af; margin-bottom: 24px; }

/* ========== 表单 ========== */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 14px; border: 1px solid #d1d5db;
  border-radius: 8px; font-size: 14px; outline: none; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus {
  border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-row { display: flex; gap: 10px; }
.form-row .form-group:first-child { flex: 1; }
.form-row .form-group:last-child { flex-shrink: 0; }

/* ========== 密码显隐切换 ========== */
.pwd-group { position: relative; }
.pwd-group input { padding-right: 44px !important; }
.pwd-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: none; cursor: pointer; font-size: 18px;
  color: #9ca3af; padding: 6px 8px; line-height: 1; border-radius: 6px;
  transition: color .15s, background .15s; user-select: none;
}
.pwd-toggle:hover { color: #4f46e5; background: #f3f4f6; }

/* ========== 消息提示 ========== */
.msg { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; display: none; }
.msg-error { background: #fef2f2; color: #ef4444; border: 1px solid #fecaca; }
.msg-success { background: #ecfdf5; color: #10b981; border: 1px solid #a7f3d0; }
.msg-info { background: #eff6ff; color: #3b82f6; border: 1px solid #bfdbfe; }

/* ========== Tab 切换 ========== */
.tab-switch { text-align: center; margin-top: 20px; font-size: 14px; color: #9ca3af; }
.tab-switch a { color: #4f46e5; cursor: pointer; text-decoration: none; }
.tab-switch a:hover { text-decoration: underline; }

/* ========== 页面头部 ========== */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 24px; font-weight: 700; color: #111827; margin-bottom: 6px; }
.page-header p { font-size: 14px; color: #6b7280; }

/* ========== 分类标签栏 ========== */
.category-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; padding-bottom: 4px; overflow-x: auto; scrollbar-width: none; }
.category-bar::-webkit-scrollbar { display: none; }
.cat-btn {
  padding: 6px 16px; border-radius: 20px; border: 1px solid #e5e7eb;
  background: #fff; font-size: 13px; color: #4b5563; cursor: pointer;
  transition: all .15s; white-space: nowrap; flex-shrink: 0;
}
.cat-btn:hover { border-color: #c7d2fe; color: #4f46e5; }
.cat-btn.active { background: #4f46e5; border-color: #4f46e5; color: #fff; font-weight: 600; }
.cat-quick-link {
  background: #fefce8; border-color: #fde68a; color: #a16207;
  font-weight: 500; margin-left: 8px;
}
.cat-quick-link:hover { background: #fef3c7; border-color: #fbbf24; color: #92400e; }

/* ========== 应用卡片网格 ========== */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.app-card {
  background: #fff; border-radius: 12px; border: 1px solid #e5e7eb;
  transition: all .2s; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.app-card:hover { border-color: #c7d2fe; box-shadow: 0 4px 12px rgba(79,70,229,.08); transform: translateY(-2px); }
.card-header { padding: 18px 20px 0; }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.app-icon {
  width: 44px; height: 44px; border-radius: 10px; display: flex;
  align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0;
}
.app-info { flex: 1; min-width: 0; }
.app-name { font-size: 15px; font-weight: 600; color: #111827; margin-bottom: 4px; }
.app-desc {
  font-size: 13px; color: #6b7280; line-height: 1.5; display: -webkit-box;
  -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  line-clamp: 2;
}
.app-tag {
  font-size: 11px; padding: 3px 8px; border-radius: 10px;
  background: #f3f4f6; color: #6b7280; flex-shrink: 0; white-space: nowrap;
}
.card-body { padding: 12px 20px 0; flex: 1; }
.app-meta { display: flex; gap: 16px; font-size: 12px; color: #9ca3af; }
.card-footer {
  padding: 14px 20px 16px; display: flex; gap: 8px;
  border-top: 1px solid #f3f4f6; margin-top: 12px;
}
.card-footer .btn { flex: 1; }
.empty-state { text-align: center; padding: 60px 20px; color: #9ca3af; }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* ========== 模态框（iframe 应用） ========== */
.modal-overlay { display: none; position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.5); align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: 14px; width: 100%; max-width: 95vw; height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-box.fullscreen { max-width: 100vw; width: 100vw; height: 100vh; border-radius: 0; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid #f3f4f6; flex-shrink: 0; }
.modal-maximize { background: none; border: none; cursor: pointer; font-size: 18px; padding: 2px 6px; color: #6b7280; border-radius: 4px; line-height: 1; }
.modal-maximize:hover { background: #f3f4f6; color: #111827; }
.modal-title { font-size: 16px; font-weight: 700; color: #111827; }
.modal-close { width: 32px; height: 32px; border-radius: 8px; border: none; background: #f3f4f6; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #6b7280; transition: all .15s; }
.modal-close:hover { background: #e5e7eb; color: #111827; }
.modal-body { flex: 1; overflow: hidden; position: relative; }

/* ========== Emoji & 颜色选择器 ========== */
.emoji-btn { width: 36px; height: 36px; border: 2px solid #e5e7eb; border-radius: 8px; background: #fff; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all .15s; }
.emoji-btn:hover { border-color: #4f46e5; background: #fafbff; }
.emoji-btn.active { border-color: #4f46e5; background: #eef2ff; }
.color-dot { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: all .15s; display: inline-block; }
.color-dot:hover { transform: scale(1.15); }
.color-dot.active { border-color: #4f46e5; box-shadow: 0 0 0 2px rgba(79,70,229,.3); }

/* ========== 页脚 ========== */
.footer { text-align: center; padding: 24px; font-size: 12px; color: #9ca3af; border-top: 1px solid #f3f4f6; margin-top: 40px; }

/* ========== 管理员面板 - 侧边栏布局 ========== */
.admin-layout { display: flex; gap: 0; min-height: calc(100vh - 56px); }
.admin-sidebar {
  width: 220px; min-width: 220px; background: #fff;
  border-right: 1px solid #e5e7eb; padding: 16px 0;
  overflow-y: auto; flex-shrink: 0;
  position: sticky; top: 56px; height: calc(100vh - 56px);
}
.admin-sidebar h3 {
  font-size: 13px; color: #9ca3af; padding: 0 16px 12px;
  text-transform: uppercase; letter-spacing: 1px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; font-size: 14px; color: #6b7280;
  cursor: pointer; transition: all .15s; border-left: 3px solid transparent;
  margin: 2px 0;
}
.sidebar-item:hover { background: #f9fafb; color: #4f46e5; }
.sidebar-item.active {
  background: #eef2ff; color: #4f46e5; font-weight: 600;
  border-left-color: #4f46e5;
}
.sidebar-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.admin-content {
  flex: 1; padding: 24px; overflow-y: auto; background: #f5f7fa;
}
.admin-content .card { max-width: 100%; }

/* 保留旧样式（兼容） */
.admin-tabs { display: flex; gap: 0; border-bottom: 2px solid #f3f4f6; margin-bottom: 20px; }
.admin-tab-btn { padding: 10px 20px; border: none; background: none; font-size: 14px; color: #9ca3af; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.admin-tab-btn.active { color: #4f46e5; border-bottom-color: #4f46e5; font-weight: 500; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 12px; background: #f9fafb; color: #6b7280; font-weight: 500; border-bottom: 1px solid #f3f4f6; }
td { padding: 10px 12px; border-bottom: 1px solid #f3f4f6; color: #374151; }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .topbar-inner { padding: 0 16px; height: 52px; }
  .logo { font-size: 16px; }
  .container { padding: 20px 16px 48px; }
  .container-narrow { padding: 20px 12px; }
  .page-header h1 { font-size: 20px; }
  .app-grid { grid-template-columns: 1fr; gap: 14px; }
  .app-card { border-radius: 10px; }
  .card-header { padding: 14px 16px 0; }
  .card-body { padding: 12px 16px 0; }
  .card-footer { padding: 12px 16px 14px; gap: 8px; }
  .card-footer .btn { padding: 8px 10px; font-size: 12px; }
  .modal-box { max-height: 95vh; border-radius: 10px; }
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; min-width: 100%; border-right: none; border-bottom: 1px solid #e5e7eb; padding: 8px 0; display: flex; flex-wrap: wrap; gap: 4px; }
  .admin-sidebar h3 { display: none; }
  .sidebar-item { border-left: none; border-bottom: 2px solid transparent; padding: 8px 12px; font-size: 13px; margin: 0; }
  .sidebar-item.active { border-left-color: transparent; border-bottom-color: #4f46e5; }
  .admin-content { padding: 16px; }
}
@media (max-width: 480px) {
  .card { padding: 24px; }
  .card-footer { flex-direction: column; }
  .card-footer .btn { width: 100%; }
}

/* ========== 前端仪表盘拖动排序 ========== */
.app-card[draggable="true"] {
  cursor: grab;
}
.app-card[draggable="true"]:active {
  cursor: grabbing;
}
.app-card.grid-dragging {
  opacity: 0.4;
  transform: scale(0.95);
}
.app-card.grid-drag-over {
  outline: 2px dashed #4f46e5;
  outline-offset: -2px;
  background: #eef2ff;
}