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

:root {
  --c-primary: #6366f1;
  --c-primary-dark: #4f46e5;
  --c-computer: #3b82f6;
  --c-english: #10b981;
  --c-fitness: #f97316;
  --c-danger: #ef4444;
  --c-bg: #f0f2f5;
  --c-card: #ffffff;
  --c-sidebar: #1e293b;
  --c-sidebar-hover: #334155;
  --c-sidebar-active: #6366f1;
  --c-text: #1e293b;
  --c-text-muted: #64748b;
  --c-text-light: #94a3b8;
  --c-border: #e2e8f0;
  --c-border-light: #f1f5f9;
  --c-success: #10b981;
  --c-warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.06), 0 4px 6px rgba(0,0,0,0.04);
  --sidebar-w: 220px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ===== App Layout ===== */
#app { display: flex; height: 100vh; height: 100dvh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--c-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--c-primary), #818cf8);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--c-text-light);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  width: 100%;
  font-family: inherit;
}

.nav-item:hover { background: var(--c-sidebar-hover); color: #cbd5e1; }

.nav-item.active {
  background: var(--c-sidebar-active);
  color: #fff;
  font-weight: 600;
}

.nav-item .nav-icon { font-size: 1.2rem; width: 24px; text-align: center; flex-shrink: 0; }

.nav-item .nav-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
  color: var(--c-text-light);
  font-size: 0.75rem;
}

.sidebar-footer .date-text { display: block; margin-bottom: 4px; font-weight: 500; color: #cbd5e1; }
.sidebar-footer .day-count { color: var(--c-text-light); }

/* ===== Content Area ===== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  -webkit-overflow-scrolling: touch;
}

/* ===== Views ===== */
.view { max-width: 960px; margin: 0 auto; animation: fadeIn 0.3s ease; }

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

.view-header { margin-bottom: 24px; }

.view-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.view-subtitle { color: var(--c-text-muted); font-size: 0.875rem; }

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

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

.card-title { font-size: 1rem; font-weight: 600; }

.card-subtitle { font-size: 0.8rem; color: var(--c-text-muted); }

/* ===== Countdown Banner ===== */
.countdown-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-radius: var(--radius);
  color: #fff;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.countdown-banner.computer { background: linear-gradient(135deg, #3b82f6, #6366f1); }
.countdown-banner.english { background: linear-gradient(135deg, #059669, #10b981); }
.countdown-banner.fitness { background: linear-gradient(135deg, #ea580c, #f97316); }
.countdown-banner.dashboard { background: linear-gradient(135deg, #4f46e5, #7c3aed); }

.countdown-icon { font-size: 2rem; }

.countdown-info { flex: 1; }
.countdown-label { font-size: 0.8rem; opacity: 0.85; }
.countdown-target { font-size: 0.95rem; font-weight: 500; margin-top: 2px; }

.countdown-number {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
}

.countdown-unit { font-size: 0.85rem; font-weight: 500; opacity: 0.85; margin-left: 2px; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}

.stat-icon { font-size: 1.5rem; margin-bottom: 8px; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--c-text-muted); margin-top: 2px; }

/* ===== Progress Bar ===== */
.progress-container { margin-bottom: 6px; }

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.progress-label { font-weight: 500; }
.progress-percent { color: var(--c-text-muted); font-weight: 600; }

.progress-bar {
  height: 8px;
  background: var(--c-border-light);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-fill.computer { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.progress-fill.english { background: linear-gradient(90deg, #10b981, #34d399); }
.progress-fill.fitness { background: linear-gradient(90deg, #f97316, #fb923c); }

/* ===== Task List ===== */
.task-list { display: flex; flex-direction: column; gap: 8px; }

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--c-border-light);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
  user-select: none;
}

.task-item:hover { background: #e8edf3; }
.task-item.done { opacity: 0.5; }
.task-item.done .task-text { text-decoration: line-through; }

.task-checkbox {
  width: 22px; height: 22px;
  border: 2px solid var(--c-border);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
  background: #fff;
}

.task-item.done .task-checkbox {
  background: var(--c-primary);
  border-color: var(--c-primary);
}

.task-checkbox svg { width: 14px; height: 14px; color: #fff; opacity: 0; transition: var(--transition); }
.task-item.done .task-checkbox svg { opacity: 1; }

.task-text { font-size: 0.9rem; flex: 1; line-height: 1.4; }

.task-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  flex-shrink: 0;
}

.task-tag.study { background: #dbeafe; color: #1d4ed8; }
.task-tag.practice { background: #fef3c7; color: #b45309; }
.task-tag.review { background: #e0e7ff; color: #4338ca; }
.task-tag.exam { background: #fee2e2; color: #b91c1c; }
.task-tag.cardio { background: #ffedd5; color: #c2410c; }
.task-tag.strength { background: #dbeafe; color: #1d4ed8; }
.task-tag.flexibility { background: #dcfce7; color: #15803d; }

/* ===== Section Tabs ===== */
.section-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.section-tab {
  padding: 8px 16px;
  border: 1px solid var(--c-border);
  border-radius: 20px;
  background: var(--c-card);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.section-tab.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* ===== Weight Input ===== */
.weight-input-area {
  display: flex;
  gap: 8px;
  align-items: center;
}

.weight-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition);
}

.weight-input:focus { outline: none; border-color: var(--c-fitness); }

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-fitness { background: var(--c-fitness); color: #fff; }
.btn-fitness:hover { background: #ea580c; }

/* ===== Weight Chart ===== */
.weight-chart-container {
  position: relative;
  width: 100%;
  overflow-x: auto;
}

.weight-chart-svg { display: block; width: 100%; height: auto; }

/* ===== Food Log ===== */
.food-input-area { display: flex; flex-direction: column; gap: 8px; }

.food-textarea {
  width: 100%;
  min-height: 80px;
  padding: 12px 14px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  transition: var(--transition);
}

.food-textarea:focus { outline: none; border-color: var(--c-fitness); }

.food-result {
  margin-top: 12px;
  padding: 14px;
  background: #fff7ed;
  border-radius: var(--radius-sm);
  border: 1px solid #fed7aa;
}

.food-result-total {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.food-result-total .calorie-number { font-size: 1.5rem; font-weight: 700; color: var(--c-fitness); }
.food-result-total .calorie-unit { font-size: 0.8rem; color: var(--c-text-muted); }

.food-result-items { display: flex; flex-direction: column; gap: 4px; }

.food-result-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 4px 0;
  border-bottom: 1px solid #ffedd5;
}

.food-result-item:last-child { border-bottom: none; }

.food-result-advice {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
}

.food-result-advice.good { background: #dcfce7; color: #15803d; }
.food-result-advice.warning { background: #fef3c7; color: #b45309; }
.food-result-advice.danger { background: #fee2e2; color: #b91c1c; }

/* ===== Food History ===== */
.food-history { display: flex; flex-direction: column; gap: 8px; }

.food-history-item {
  padding: 10px 12px;
  background: var(--c-border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.food-history-item .food-time { font-size: 0.75rem; color: var(--c-text-muted); margin-bottom: 4px; }
.food-history-item .food-desc { color: var(--c-text); }
.food-history-item .food-cal { color: var(--c-fitness); font-weight: 600; margin-top: 2px; }

/* ===== Exercise Plan ===== */
.exercise-plan-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.exercise-day-badge {
  background: var(--c-fitness);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.exercise-type-badge {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 600;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--c-text-light);
  font-size: 0.9rem;
}

/* ===== Dashboard Overview ===== */
.overview-section {
  background: var(--c-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: var(--transition);
  border-left: 4px solid transparent;
}

.overview-section:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.overview-section.computer { border-left-color: var(--c-computer); }
.overview-section.english { border-left-color: var(--c-english); }
.overview-section.fitness { border-left-color: var(--c-fitness); }

.overview-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.overview-section-icon { font-size: 1.5rem; }
.overview-section-title { font-size: 1.1rem; font-weight: 600; flex: 1; }
.overview-section-arrow { color: var(--c-text-light); }

.overview-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.overview-stat { font-size: 0.85rem; }
.overview-stat .num { font-weight: 700; font-size: 1.1rem; }
.overview-stat .label { color: var(--c-text-muted); }

/* ===== Knowledge Points ===== */
.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.knowledge-card {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--c-border-light);
  border: 1px solid var(--c-border);
}

.knowledge-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.knowledge-card-content {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  line-height: 1.5;
}

.knowledge-card-points {
  margin-top: 6px;
  padding-left: 16px;
  font-size: 0.78rem;
  color: var(--c-text-muted);
}

.knowledge-card-points li { margin-bottom: 2px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  #app { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    padding: 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .sidebar-header { display: none; }
  .sidebar-footer { display: none; }

  .sidebar-nav {
    flex-direction: row;
    padding: 6px;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    justify-content: space-around;
  }

  .nav-item {
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    font-size: 0.7rem;
    flex: 1;
    min-width: 0;
    text-align: center;
    justify-content: center;
  }

  .nav-item .nav-icon { font-size: 1.3rem; }
  .nav-item .nav-badge { display: none; }
  .nav-item span:not(.nav-icon):not(.nav-badge) {
    font-size: 0.68rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .content { padding: 16px; padding-bottom: 80px; }

  .view-title { font-size: 1.25rem; }
  .countdown-number { font-size: 2rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .knowledge-grid { grid-template-columns: 1fr; }

  .task-text { font-size: 0.85rem; }
  .card { padding: 16px; }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .nav-item { padding: 6px 8px; }
}

/* ===== Scrollbar ===== */
.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.content::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Exercise Items (Listening/Reading) ===== */
.exercise-item:hover { background: #e8edf3 !important; box-shadow: var(--shadow-sm); }

.exercise-item[style*="border-left"] { transition: all 0.2s ease; }

/* ===== Flashcard ===== */
#flashcard { transition: transform 0.3s ease, box-shadow 0.3s ease; }
#flashcard:hover { box-shadow: 0 4px 12px rgba(16,185,129,0.15); }

/* ===== Listening/Reading Detail ===== */
.listening-option:hover, .reading-option:hover { background: #e8edf3 !important; }

/* ===== Spelling Input ===== */
#spellingInput:focus { border-color: var(--c-english); box-shadow: 0 0 0 3px rgba(16,185,129,0.1); }

/* ===== Section Tabs English variant ===== */
.section-tab[data-subtab].active { background: var(--c-english); border-color: var(--c-english); }

/* ===== Utility ===== */
.text-muted { color: var(--c-text-muted); }
.text-sm { font-size: 0.8rem; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
