/* =====================================================
   Layout Styles v4.1 - 彻底修复Tab栏定位 + Slogan增强
   ===================================================== */

/* ===== App Header（固定顶部）===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
}

[data-theme="dark"] .app-header {
  background: rgba(24,24,27,0.92);
  border-bottom-color: rgba(255,255,255,0.06);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #18181B, #3F3F46);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
}

.header-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

/* ===== Slogan - 激励性标语 ===== */
.header-slogan {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, #F59E0B, #D97706);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.3;
}

.header-date {}
.header-divider { opacity: 0.35; }
.header-level { font-weight: 600; color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-streak {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.04);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

[data-theme="dark"] .header-streak {
  background: rgba(255,255,255,0.08);
}

.streak-fire { font-size: 14px; line-height: 1; }
.streak-num {}

/* ===== Tab Bar（与内容等宽 + 居中）===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-sticky);
  width: 100%;
  max-width: 480px;
  height: 60px;
  display: flex;
  align-items: stretch;
  justify-content: space-evenly;
  background: rgba(255,255,255,0.96);
  border-top: 1px solid rgba(0,0,0,0.05);
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  padding-bottom: env(safe-area-inset-bottom, 0);
  transition: all 0.3s ease;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.04);
}

[data-theme="dark"] .tab-bar {
  background: rgba(24,24,27,0.96);
  border-top-color: rgba(255,255,255,0.06);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  padding: 8px 0 6px;
  border-radius: 12px 12px 0 0;
  margin: 0 2px;
}

.tab-icon {
  font-size: 22px;
  line-height: 1;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.tab-label {
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: all 0.25s ease;
}

/* 激活态 */
.tab-item.active {
  color: var(--primary);
}

.tab-item.active .tab-icon {
  transform: translateY(-2px) scale(1.1);
}

.tab-item.active .tab-label {
  font-weight: 700;
}

.tab-item:hover:not(.active) {
  color: var(--text-secondary);
  background: rgba(0,0,0,0.03);
}

[data-theme="dark"] .tab-item:hover:not(.active) {
  background: rgba(255,255,255,0.05);
}

.tab-item:active {
  transform: scale(0.9);
  opacity: 0.8;
}

/* 激活指示器 - 顶部圆点 */
.tab-item.active::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(248,113,113,0.5);
}

/* 徽章红点 */
.tab-badge {
  position: absolute;
  top: 3px;
  right: 50%;
  margin-right: -18px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  background: linear-gradient(135deg, #EF4444, #DC2626);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(239,68,68,0.4);
  animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* 桌面端Tab栏跟随内容宽度 */
@media (min-width: 768px) {
  .tab-bar {
    max-width: 520px;
    border-radius: 16px 16px 0 0;
    border: 1px solid rgba(0,0,0,0.06);
    border-bottom: none;
    margin-bottom: 0;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.08);
  }
  
  [data-theme="dark"] .tab-bar {
    border-color: rgba(255,255,255,0.08);
  }
}

/* ===== XP Bar Container (below header) ===== */
.xp-bar-container {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid rgba(0,0,0,0.04);
}

.xp-bar-container .xp-bar {
  flex: 1;
  height: 6px;
}

.xp-bar-text {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 600;
  white-space: nowrap;
  min-width: fit-content;
}

/* ===== Page Content ===== */
.page-content {
  padding: 16px;
  padding-bottom: calc(70px + 16px + env(safe-area-inset-bottom, 0));
  min-height: calc(100vh - 60px);
  animation: fadeInUp 0.25s ease;
}

/* ===== Section ===== */
.section {
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 2px;
}

.section-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.section-action {
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: var(--transition-fast);
}
.section-action:hover {
  background: var(--bg-secondary);
}

/* ===== Grid Layouts ===== */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

/* ===== Card Grid（自适应）===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

/* ===== Stack（垂直排列）===== */
.stack > * + * { margin-top: 12px; }
.stack-sm > * + * { margin-top: 8px; }
.stack-lg > * + * { margin-top: 16px; }

/* ===== Divider ===== */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.divider-vertical {
  width: 1px;
  background: var(--border);
  margin: 0 12px;
  align-self: stretch;
}

/* ===== Overlay（模态框背景）===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  padding: 16px;
}

@media (min-width: 640px) {
  .overlay { align-items: center; }
}

/* ===== Modal / Sheet ===== */
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

@media (min-width: 640px) {
  .sheet {
    border-radius: 16px;
    max-height: 80vh;
  }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
}

.sheet-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-tertiary);
  transition: var(--transition-fast);
}
.sheet-close:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: calc(var(--header-height, 56px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 24px);
  max-width: 400px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
  animation: fadeInUp 0.25s ease;
  pointer-events: auto;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--info); }

.toast-icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
.toast-message { flex: 1; font-weight: 500; }

.toast-close {
  flex-shrink: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  transition: var(--transition-fast);
}
.toast-close:hover { color: var(--text); }

/* ===== XP Popup ===== */
.xp-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-toast);
  background: var(--card);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow-xl);
  border: 2px solid var(--accent);
  animation: bounceIn 0.4s ease;
  min-width: 200px;
}

.xp-popup .xp-amount {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.2;
}

.xp-popup .xp-label {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.xp-popup .xp-breakdown {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
  .page-content {
    padding: 24px;
    padding-bottom: calc(76px + 24px);
  }

  .grid-4 {
    grid-template-columns: repeat(8, 1fr);
  }

  .section-title {
    font-size: 19px;
  }
  
  .app-header {
    padding: 14px 24px;
  }
  
  .xp-bar-container {
    padding: 10px 24px;
  }
}

@media (min-width: 1024px) {
  .page-content {
    padding: 28px;
  }
}
