/* AI-Tutor PWA - 極簡風格 CSS */
:root {
  --primary: #3B82F6;
  --primary-dark: #2563EB;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --bg: #FFFFFF;
  --surface: #F9FAFB;
  --text: #111827;
  --muted: #6B7280;
  --border: #E5E7EB;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --radius: 0;
  --font: Inter, system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* 導航列 */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.navbar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lesson-badge {
  background: var(--surface);
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
}

.plan-badge {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 2px;
}
.plan-badge.free { background: #E0E7FF; color: #3730A3; }
.plan-badge.premium { background: #FEF3C7; color: #92400E; }

/* 主內容 */
.main-content {
  padding-top: 56px;
  min-height: 100vh;
}

/* 頁面容器 */
.page {
  display: none;
  padding: 24px 16px;
  max-width: 800px;
  margin: 0 auto;
}
.page.active { display: block; }

/* 卡片 */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

/* 按鈕 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  font-family: var(--font);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* 表單 */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--font);
  transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* 課程卡片 */
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.course-card {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 20px;
  transition: box-shadow 0.2s;
}
.course-card:hover { box-shadow: var(--shadow-md); }
.course-card h3 { font-size: 16px; margin-bottom: 8px; }
.course-card p { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.course-meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }

/* 教室 */
.classroom-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  height: calc(100vh - 56px - 48px);
}
@media (max-width: 768px) {
  .classroom-layout { grid-template-columns: 1fr; }
}

.classroom-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.message {
  margin-bottom: 16px;
  max-width: 85%;
}
.message.user { margin-left: auto; }
.message.ai { margin-right: auto; }
.message-bubble {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
}
.message.user .message-bubble {
  background: var(--primary);
  color: white;
}
.message.ai .message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
}

.reading-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* 語音控制 */
.voice-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.voice-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}
.voice-btn:hover { transform: scale(1.05); }
.voice-btn.recording {
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.voice-status {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.waveform {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.waveform span {
  width: 3px;
  background: var(--primary);
  animation: wave 1s ease-in-out infinite;
}
.waveform span:nth-child(2) { animation-delay: 0.1s; }
.waveform span:nth-child(3) { animation-delay: 0.2s; }
.waveform span:nth-child(4) { animation-delay: 0.3s; }
.waveform span:nth-child(5) { animation-delay: 0.4s; }
@keyframes wave {
  0%, 100% { height: 10px; }
  50% { height: 30px; }
}

/* Markdown 渲染 */
.markdown-content h1 { font-size: 24px; margin: 24px 0 16px; }
.markdown-content h2 { font-size: 20px; margin: 20px 0 12px; }
.markdown-content h3 { font-size: 16px; margin: 16px 0 8px; }
.markdown-content p { margin-bottom: 12px; }
.markdown-content ul, .markdown-content ol { margin: 12px 0; padding-left: 24px; }
.markdown-content li { margin-bottom: 6px; }
.markdown-content code {
  background: var(--surface);
  padding: 2px 6px;
  font-size: 13px;
  font-family: monospace;
}
.markdown-content pre {
  background: #1F2937;
  color: #F9FAFB;
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
}
.markdown-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* 代碼預覽 */
.code-preview-btn {
  background: var(--success);
  color: white;
  border: none;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
}

/* 打字指示器 */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* 進度條 */
.progress-bar {
  height: 6px;
  background: var(--border);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}

/* 升級按鈕 */
.upgrade-banner {
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: white;
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
}
.upgrade-banner h2 { font-size: 20px; margin-bottom: 8px; }
.upgrade-banner p { font-size: 14px; opacity: 0.9; margin-bottom: 12px; }
.upgrade-btn {
  background: white;
  color: var(--primary);
  padding: 10px 24px;
  font-weight: 700;
  text-decoration: none;
  display: inline-block;
}

/* 管理員面板 */
.admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.admin-tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.admin-section { display: none; }
.admin-section.active { display: block; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th, .data-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { font-weight: 600; background: var(--surface); }
.data-table tr:hover { background: var(--surface); }

/* 安裝提示 */
.install-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--text);
  color: white;
  padding: 16px;
  display: none;
  align-items: center;
  justify-content: space-between;
  z-index: 200;
}
.install-prompt.show { display: flex; }

/* 載入狀態 */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  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: 60px 20px;
  color: var(--muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; }

/* 響應式 */
@media (max-width: 640px) {
  .navbar { padding: 0 12px; }
  .page { padding: 16px 12px; }
  .card { padding: 16px; }
  .classroom-layout { height: auto; }
}

/* PWA 安裝橫幅 */
.pwa-install-banner {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: none;
  align-items: center;
  justify-content: space-between;
}
.pwa-install-banner.show { display: flex; }
.pwa-install-banner button {
  background: white;
  color: var(--primary);
  border: none;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
}
