/* ============ 基础变量 ============ */
:root {
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --accent-hover: #4338ca;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.14);
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

[data-theme="light"] {
  --text-primary: #1f2430;
  --text-secondary: #5c6373;
  --text-muted: #939aa8;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --surface-hover: rgba(255, 255, 255, 0.92);
  --border: rgba(0, 0, 0, 0.08);
  --border-solid: #e8ebf0;
  --input-bg: rgba(255, 255, 255, 0.65);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.1);
  --success: #16a34a;
}

[data-theme="dark"] {
  --text-primary: #f1f3f9;
  --text-secondary: #b6bdcc;
  --text-muted: #7c8496;
  --surface: rgba(30, 34, 48, 0.66);
  --surface-solid: #222636;
  --surface-hover: rgba(40, 45, 62, 0.9);
  --border: rgba(255, 255, 255, 0.1);
  --border-solid: #343a4f;
  --input-bg: rgba(255, 255, 255, 0.06);
  --danger: #ff6369;
  --danger-soft: rgba(255, 99, 105, 0.12);
  --success: #4ade80;
}

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

html, body { min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
  position: relative;
}

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

/* 确保 hidden 属性始终生效，避免 display:flex 等规则覆盖导致弹窗误显示 */
[hidden] { display: none !important; }

/* ============ 背景 ============ */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, #a18cd1 0%, #8a9ef5 50%, #7cc3f0 100%);
  background-size: cover;
  background-position: center;
  transition: background 0.4s;
}
.bg-layer.gradient-1 { background: linear-gradient(135deg, #a18cd1 0%, #8a9ef5 50%, #7cc3f0 100%); }
.bg-layer.gradient-2 { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 50%, #3fa7ff 100%); }
.bg-layer.gradient-3 { background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fda085 100%); }
.bg-layer.gradient-4 { background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%); }
.bg-layer.solid { background: #eef1f8; }
[data-theme="dark"] .bg-layer.solid { background: #14161f; }

.bg-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 15% 20%, rgba(255,255,255,0.18), transparent 40%),
              radial-gradient(circle at 85% 80%, rgba(255,255,255,0.12), transparent 40%);
  pointer-events: none;
}

/* 数据加载失败提示横幅 */
.data-error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 150;
  background: #fff3cd;
  color: #856404;
  border-bottom: 1px solid #ffeeba;
  padding: 10px 20px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
[data-theme="dark"] .data-error-banner { background: #3a2f12; color: #f5d98a; border-color: #5a4a1c; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ============ 通用组件 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 6px 16px var(--accent-soft); }
.btn-outline { background: var(--input-bg); color: var(--text-primary); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-hover); border-color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  font-size: 18px;
  transition: var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); transform: translateY(-2px); box-shadow: var(--shadow); }

.link-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; padding: 6px; transition: var(--transition);
}
.link-btn:hover { color: var(--accent); }

input, select {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-muted); }

/* ============ 展示页 ============ */
.view { min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 40px;
  max-width: 1400px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 28px; }
.brand-name { font-size: 18px; font-weight: 700; color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,0.2); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.clock { text-align: right; color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,0.2); margin-right: 6px; }
.clock-time { display: block; font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.clock-date { display: block; font-size: 12px; opacity: 0.9; }

.home-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 40px 60px;
}

.hero { text-align: center; margin-bottom: 48px; }
.hero-greeting { color: rgba(255,255,255,0.9); font-size: 14px; font-weight: 500; margin-bottom: 8px; text-shadow: 0 1px 8px rgba(0,0,0,0.2); }
.hero-title { color: #fff; font-size: 46px; font-weight: 800; letter-spacing: -1px; text-shadow: 0 2px 20px rgba(0,0,0,0.25); }
.hero-subtitle { color: rgba(255,255,255,0.92); font-size: 15px; margin-top: 8px; text-shadow: 0 1px 8px rgba(0,0,0,0.2); }

.search-wrap { margin: 30px auto 0; max-width: 620px; }
.search-box {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.92);
  border-radius: 999px;
  padding: 6px 10px 6px 20px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  backdrop-filter: blur(20px);
  transition: var(--transition);
}
.search-box:focus-within { box-shadow: 0 14px 48px rgba(0,0,0,0.25); transform: translateY(-2px); }
.search-icon { font-size: 18px; }
.search-box input {
  flex: 1; border: none; background: transparent; box-shadow: none;
  font-size: 15px; padding: 10px 0; color: #1f2430;
}
.search-box input:focus { box-shadow: none; border: none; }
.search-box input::placeholder { color: #9aa1ad; }
.search-clear {
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: transparent; color: #9aa1ad;
  font-size: 13px; display: none; align-items: center; justify-content: center;
}
.search-clear.show { display: flex; }
.search-clear:hover { background: rgba(0,0,0,0.06); color: #333; }
.search-hint { text-align: center; color: rgba(255,255,255,0.85); font-size: 12px; margin-top: 12px; text-shadow: 0 1px 6px rgba(0,0,0,0.2); }
.search-hint kbd {
  background: rgba(255,255,255,0.25); padding: 1px 6px; border-radius: 4px;
  font-family: inherit; font-size: 11px;
}

/* 分类 */
.category-list { display: flex; flex-direction: column; gap: 34px; }
.category-block { animation: fadeUp 0.5s ease both; }
.category-head {
  display: flex; align-items: center; gap: 10px;
  color: #fff; margin-bottom: 16px; padding-left: 4px;
}
.category-icon { font-size: 20px; }
.category-name { font-size: 17px; font-weight: 700; text-shadow: 0 1px 8px rgba(0,0,0,0.2); }
.category-line { flex: 1; height: 1px; background: rgba(255,255,255,0.28); }
.category-count { font-size: 12px; opacity: 0.85; }

.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.link-card {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 20px 12px 16px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: var(--radius);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.link-card:hover {
  transform: translateY(-4px);
  background: var(--surface-hover);
  box-shadow: var(--shadow-lg);
  border-color: rgba(255,255,255,0.6);
}
.link-card-icon {
  width: 52px; height: 52px; border-radius: 15px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
  margin-bottom: 12px;
  overflow: hidden;
  transition: var(--transition);
}
.link-card:hover .link-card-icon { transform: scale(1.08); }
.link-card-icon img { width: 100%; height: 100%; object-fit: contain; }
.link-card-name { font-size: 14px; font-weight: 650; color: var(--text-primary); line-height: 1.3; word-break: break-all; }
.link-card-desc { font-size: 11px; color: var(--text-secondary); margin-top: 4px; line-height: 1.4; }

.empty-search { text-align: center; color: #fff; padding: 60px 20px; }
.empty-search .empty-icon { font-size: 48px; }
.empty-search p { margin: 12px 0 20px; font-size: 16px; }

.home-footer {
  text-align: center; color: rgba(255,255,255,0.85);
  font-size: 12px; margin-top: 50px; text-shadow: 0 1px 6px rgba(0,0,0,0.2);
}
.home-footer b { font-weight: 700; }
.footer-dot { margin: 0 8px; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 管理后台 ============ */
.admin-view {
  background: var(--input-bg);
  min-height: 100vh;
}
[data-theme="light"] .admin-view { background: #f4f6fb; }
[data-theme="dark"] .admin-view { background: #161923; }

/* 登录 */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface-solid);
  border-radius: 24px; padding: 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 12px; }
.login-card h2 { font-size: 24px; margin-bottom: 6px; }
.login-card > p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.login-card form input { margin-bottom: 12px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; text-align: left; margin-bottom: 6px; }
.login-card .link-btn { margin-top: 16px; }
.login-tip { margin-top: 18px; font-size: 12px; color: var(--text-muted); }
.login-tip b { color: var(--accent); }

/* 后台布局 */
.admin-panel { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--surface-solid);
  border-right: 1px solid var(--border-solid);
  display: flex; flex-direction: column;
  padding: 24px 16px;
  position: sticky; top: 0; height: 100vh;
}
.admin-brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 28px; }
.admin-brand > span { font-size: 28px; }
.admin-brand strong { display: block; font-size: 16px; }
.admin-brand small { display: block; font-size: 11px; color: var(--text-muted); }
.admin-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.admin-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--text-secondary);
  font-size: 14px; font-weight: 600; text-align: left;
  transition: var(--transition);
}
.admin-nav-item:hover { background: var(--accent-soft); color: var(--accent); }
.admin-nav-item.active { background: var(--accent); color: #fff; }
.admin-nav-item span { font-size: 18px; }
.admin-sidebar-bottom { border-top: 1px solid var(--border-solid); padding-top: 16px; text-align: center; }
.admin-sidebar-bottom .link-btn { margin-top: 10px; }

.admin-content { flex: 1; padding: 36px 44px; min-width: 0; max-width: 1100px; }
.admin-tab-panel { display: none; animation: fadeUp 0.3s ease; }
.admin-tab-panel.active { display: block; }
.panel-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.panel-header h2 { font-size: 24px; margin-bottom: 4px; }
.panel-header p { color: var(--text-secondary); font-size: 14px; }

.filter-bar { display: flex; gap: 12px; margin-bottom: 18px; }
.filter-bar input { flex: 1; }
.filter-bar select { width: 200px; }

/* 数据表格 */
.data-table { display: flex; flex-direction: column; gap: 10px; }
.table-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-solid);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  transition: var(--transition);
}
.table-row:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.row-icon {
  width: 42px; height: 42px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px; font-size: 22px;
  background: var(--accent-soft);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 650; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.row-badge { font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub a { color: var(--accent); }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.mini-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.mini-btn.danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.drag-handle { cursor: grab; color: var(--text-muted); font-size: 16px; padding: 4px; }
.drag-handle:active { cursor: grabbing; }
.table-row.dragging { opacity: 0.4; }
.table-row.drag-over { border-top: 3px solid var(--accent); }

.empty-table { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-table .empty-icon { font-size: 44px; margin-bottom: 10px; }

/* 设置表单 */
.settings-form {
  background: var(--surface-solid);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius);
  padding: 28px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 13px; font-weight: 650; color: var(--text-secondary); }
.required { color: var(--danger); }
.form-note { font-size: 11px; color: var(--text-muted); }
.color-input-wrap { display: flex; gap: 10px; align-items: center; }
.color-input-wrap input[type="color"] { width: 52px; height: 42px; padding: 4px; cursor: pointer; flex-shrink: 0; }
.color-input-wrap input[type="text"] { flex: 1; }

/* 数据卡片 */
.data-card-list { display: flex; flex-direction: column; gap: 14px; }
.data-card {
  display: flex; align-items: center; gap: 18px;
  background: var(--surface-solid);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius);
  padding: 22px;
}
.data-card.danger { border-color: rgba(229,72,77,0.3); }
.data-card-icon { font-size: 32px; }
.data-card-body { flex: 1; }
.data-card-body h3 { font-size: 15px; margin-bottom: 3px; }
.data-card-body p { font-size: 13px; color: var(--text-secondary); }

/* ============ 弹窗 ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 18, 30, 0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--surface-solid);
  border-radius: 20px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: popIn 0.25s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border-solid);
}
.modal-header h3 { font-size: 18px; }
.modal-form { padding: 24px; display: flex; flex-direction: column; gap: 16px; max-height: 70vh; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.confirm-modal { text-align: center; padding: 32px 28px; max-width: 380px; }
.confirm-icon { font-size: 40px; margin-bottom: 12px; }
.confirm-modal h3 { font-size: 19px; margin-bottom: 8px; }
.confirm-modal p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.confirm-modal .modal-actions { justify-content: center; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.94) translateY(10px); } to { opacity: 1; transform: none; } }

/* Toast */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text-primary); color: var(--surface-solid);
  padding: 12px 24px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-lg); z-index: 200;
  opacity: 0; transition: var(--transition); pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .admin-sidebar { width: 200px; }
  .admin-content { padding: 28px 24px; }
}
@media (max-width: 720px) {
  .topbar { padding: 16px 20px; }
  .clock { display: none; }
  .home-main { padding: 30px 20px 50px; }
  .hero-title { font-size: 34px; }
  .link-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .admin-panel { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; padding: 14px; }
  .admin-brand { padding-bottom: 14px; }
  .admin-nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .admin-nav-item { white-space: nowrap; padding: 10px 12px; font-size: 13px; }
  .admin-sidebar-bottom { display: none; }
  .admin-content { padding: 24px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; }
  .filter-bar select { width: 100%; }
  .panel-header { flex-direction: column; }
}
