:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --ok: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --transition: color 0.2s, background-color 0.2s, border-color 0.2s, opacity 0.2s;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Noto Sans CJK SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* ======== 导航栏 ======== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.navbar-inner {
  max-width: 1100px;
  height: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.brand-icon { font-size: 1.25rem; }
.brand-text { font-size: 1.2rem; font-weight: 700; color: var(--primary); }

.nav-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.25rem 0;
  position: relative;
  transition: var(--transition);
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--primary);
  transition: var(--transition);
}

.nav-link:hover,
.nav-link.active { color: var(--primary); }

.nav-link:hover::after,
.nav-link.active::after { width: 100%; }

.btn-logout {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-logout:hover {
  background: #fef2f2;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-logout svg { flex-shrink: 0; width: 14px; height: 14px; }

#currentUser {
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ======== 布局 ======== */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
}

.view { display: none; }
.view.active { display: block; }

/* ======== 模态框基础 ======== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.active { display: flex; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  -webkit-overflow-scrolling: touch;
}

.modal-detail { max-width: 680px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 { font-size: 1rem; color: var(--text); }

.modal-close {
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { background: #f3f4f6; color: var(--text); }

/* ======== 表单基础 ======== */
.form-group { margin-bottom: 0.75rem; }

.form-group label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text);
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-group textarea { resize: vertical; min-height: 60px; }

.form-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.btn-primary,
.btn-secondary {
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(37,99,235,0.3); }

.btn-secondary { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-secondary:hover { background: #f3f4f6; color: var(--text); }

/* ======== Toast 提示 ======== */
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 0.6rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 50px;
  color: var(--text);
  font-size: 0.8rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2000;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--ok); }

/* ======== 登录页面 ======== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}

.login-container {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.login-header { text-align: center; margin-bottom: 1.5rem; }
.login-icon { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; }
.login-header h1 { font-size: 1.75rem; font-weight: 700; color: var(--primary); margin-bottom: 0.25rem; }
.login-header p { color: var(--muted); font-size: 0.85rem; }

.login-form .form-group { margin-bottom: 0.85rem; }
.login-form .form-group label { display: block; margin-bottom: 0.3rem; font-size: 0.8rem; color: var(--muted); }

.login-form .form-group input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  transition: var(--transition);
}

.login-form .form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
  background: var(--card);
}

.remember-row {
  display: flex;
  justify-content: flex-start;
  margin: 0.2rem 0 0.55rem;
}

.remember-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.remember-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
}

@keyframes autofillDetect { from {} to {} }
input:-webkit-autofill { animation-name: autofillDetect; animation-duration: 1ms; }

.btn-login { width: 100%; padding: 0.65rem; margin-top: 0.25rem; }

.login-divider { display: flex; align-items: center; margin: 1rem 0; color: var(--muted); }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.login-divider span { padding: 0 0.75rem; font-size: 0.75rem; }

.btn-register { width: 100%; padding: 0.65rem; }

/* ======== 加载/空状态 ======== */
.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--text); }
.empty-state p { color: var(--muted); font-size: 0.85rem; }

/* ======== 响应式 ======== */
@media (max-width: 768px) {
  .navbar { height: 50px; }
  .navbar-inner { padding: 0 1rem; }
  .nav-main { gap: 1.5rem; }
  .main-content { padding: 0.75rem; }
  .form-row { grid-template-columns: 1fr; }
  .modal-content { max-width: 95%; max-height: 90vh; }
  .btn-logout span { display: none; }
  .btn-logout { padding: 0.5rem; }
}

@media (max-width: 480px) {
  .brand-text { font-size: 1rem; }
  .nav-link { font-size: 0.7rem; }
  .login-container { padding: 1.5rem 1rem; }
  .login-header h1 { font-size: 1.5rem; }
}
