/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4F7FFF;
  --primary-light: #EEF3FF;
  --secondary: #6BCB77;
  --danger: #FF6B6B;
  --warning: #FFA500;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text: #1A1A2E;
  --subtext: #6B7280;
  --border: #E5E7EB;
  --nav-height: 60px;
  --header-height: 56px;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* ── App Shell ──────────────────────────────────────────────────── */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

#page-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--nav-height);
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ── Bottom Navigation ──────────────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  background: var(--card);
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  gap: 2px;
  color: var(--subtext);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 500; }

/* ── Page Layout ────────────────────────────────────────────────── */
.page {
  min-height: calc(100vh - var(--nav-height));
  padding: 16px 16px 24px;
}

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

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

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

/* ── Typography ─────────────────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--subtext);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 18px 0 10px;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { opacity: 0.85; transform: scale(0.98); }

.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--primary-light); color: var(--primary); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ── Progress Bar ───────────────────────────────────────────────── */
.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ── Page Transitions ───────────────────────────────────────────── */
.page-enter {
  animation: fadeSlideIn 0.25s ease forwards;
}
.page-exit {
  animation: fadeSlideOut 0.15s ease forwards;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeSlideOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}

/* ── Modals ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 36px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.modal-fullscreen {
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 90vh;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

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

.modal-title { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg);
  border: none;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.modal-section { margin-bottom: 18px; }
.modal-label { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.modal-hint { font-size: 12px; color: var(--subtext); margin-bottom: 8px; }
.modal-input {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--bg);
  outline: none;
}
.modal-input:focus { border-color: var(--primary); }

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.modal-actions .btn { flex: 1; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); } to { transform: translateY(0); } }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,30,0.9);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 300;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Loading ────────────────────────────────────────────────────── */
.loading-card {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  font-size: 18px;
  color: var(--subtext);
}

.empty-state {
  text-align: center;
  color: var(--subtext);
  padding: 32px;
  font-size: 15px;
}

/* ── Safe area / notch support ──────────────────────────────────── */
@supports(padding-bottom: env(safe-area-inset-bottom)) {
  #bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  }
}
