:root {
  --bg: #f5f7fa;
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: #d1fae5;
  --primary-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.03);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.06), 0 1px 2px 0 rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -1px rgba(0,0,0,0.03);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ============ LAYOUT ============ */
.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 12px;
}

.sidebar .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
}

.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  margin: 2px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.sidebar .nav-item:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

.sidebar .nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  margin-left: 9px; /* compensate for border */
}

.sidebar .nav-item .icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: 220px;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
}

.top-bar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  text-align: center;
  margin-left: -40px;
}

.page-content {
  padding: 24px 28px;
  max-width: 1200px;
  min-width: 0;
}

/* ============ CARDS ============ */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-header .icon {
  font-size: 18px;
}

/* ============ STAT CARDS ============ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  transition: all 0.15s ease;
}

.stat-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.stat-card .stat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-card .stat-icon {
  font-size: 18px;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* ============ TIMELINE ============ */
.timeline {
  list-style: none;
}

.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  position: relative;
}

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

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 6px;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
}

.timeline-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.timeline-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.timeline-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============ BUTTONS ============ */
button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

button:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

button:active { transform: translateY(0); }

button.secondary { background: var(--text-secondary); }
button.secondary:hover { background: #4b5563; }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }

/* ============ INPUTS ============ */
input, select, textarea {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--card-bg);
  color: var(--text-primary);
  font-family: var(--font);
  transition: all 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

input[readonly] { background: var(--border-light); color: var(--text-muted); }

/* ============ TABLES ============ */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

th {
  background: var(--bg);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tr:hover td { background: var(--border-light); }
tr:last-child td { border-bottom: none; }

/* ============ DROPZONE ============ */
.dropzone {
  border: 2px dashed var(--border);
  padding: 48px 40px;
  text-align: center;
  border-radius: var(--radius);
  margin: 20px 0;
  background: var(--card-bg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
}

/* ============ CALENDAR ============ */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 20px;
}

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

.calendar-day {
  background: var(--card-bg);
  padding: 12px;
  border-radius: var(--radius-sm);
  min-height: 100px;
  border: 1px solid var(--border);
  font-size: 12px;
  transition: all 0.15s ease;
  cursor: pointer;
}

.calendar-day:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.calendar-day .day-num {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 14px;
}

/* Tags */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  margin: 2px;
}

.tag.confirmed { background: #d1fae5; color: #065f46; }  /* 有装备上课: 绿色 */
.tag.no_gear { background: #dbeafe; color: #1e40af; }  /* 无装备上课: 蓝色 */
.tag.missing { background: #fef3c7; color: #92400e; }  /* 自由飞: 黄色 */
.tag.freefly { background: #fef3c7; color: #92400e; }  /* 自由飞: 黄色 */

/* Form rows */
.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* Loading */
#loading {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 500;
}

/* Modal */
#dayModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  backdrop-filter: blur(6px);
}

#dayModal > div {
  background: var(--card-bg);
  max-width: 480px;
  margin: 60px auto;
  padding: 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

/* Notices */
.notice {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid;
}

.notice.info { background: #ecfdf5; color: #059669; border-color: #a7f3d0; }
.notice.warning { background: #fffbeb; color: #d97706; border-color: #fcd34d; }
.notice.success { background: #f0fdf4; color: #059669; border-color: #86efac; }

/* Grid layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* Mobile sidebar toggle */
.mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-primary);
  padding: 8px;
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  backdrop-filter: blur(4px);
}

.sidebar-overlay.open { display: block; }

/* Table wrap for horizontal scroll */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.table-wrap table {
  border: none;
  min-width: 500px;
}

/* Notice danger */
.notice.danger { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

/* Card overflow */
.card { overflow: hidden; }

/* Timeline wrap */
.timeline-title { word-wrap: break-word; }
.timeline-desc { word-wrap: break-word; }
.timeline-content { min-width: 0; }

/* Mobile improvements */
@media (max-width: 768px) {
  .mobile-toggle { display: block; }
  .sidebar { width: 260px; transform: translateX(-100%); transition: transform 0.3s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .card { padding: 16px; }
  .dropzone { padding: 32px 16px; }
  .calendar-day { min-height: 50px; padding: 6px 4px; overflow: hidden; }
  .calendar-day .day-num { font-size: 12px; }
  .tag { font-size: 10px; padding: 2px 6px; max-width: 100%; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #dayModal { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #dayModal > div { margin: 20px 12px; padding: 20px 16px; max-height: 85vh; overflow-y: auto; }
  .top-bar h1 { margin-left: 0; text-align: left; }
}

@media (max-width: 640px) {
  .stat-row { grid-template-columns: 1fr; }
  .top-bar h1 { font-size: 16px; }
  .card { padding: 14px 12px; border-radius: 10px; }
  .card-header { font-size: 15px; }
  table { font-size: 13px; }
  th, td { padding: 10px 8px; }
  .timeline-item { padding: 10px 0; }
  .timeline-title { font-size: 13px; }
  .timeline-desc { font-size: 12px; }
}

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

.card, .stat-card {
  animation: fadeIn 0.3s ease-out;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
