:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --bg: #F5F5F5;
  --card: #FFFFFF;
  --text: #333333;
  --text-secondary: #999999;
  --text-light: #888888;
  --danger: #FF6B6B;
  --border: #E5E5E5;
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-top: env(safe-area-inset-top, 0px);
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-container p {
  margin-top: 16px;
  color: var(--text-secondary);
}

.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

.auth-header {
  text-align: center;
  margin-bottom: 32px;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.auth-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-switch {
  text-align: center;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.auth-switch:active {
  opacity: 0.7;
}

.auth-forgot {
  text-align: right;
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 8px;
  cursor: pointer;
}

.auth-forgot:active {
  opacity: 0.7;
}

.icp-filing {
  text-align: center;
}

.icp-filing-first {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.icp-filing-secondary {
  margin-top: 12px;
}

.icp-filing a {
  color: var(--text-light);
  font-size: 12px;
  text-decoration: none;
}

.icp-filing a:active {
  opacity: 0.7;
}

.beian-icon {
  width: 14px;
  height: 14px;
  vertical-align: middle;
  margin-right: 4px;
}

.user-menu {
  position: fixed !important;
  top: calc(var(--safe-area-top) + 4px) !important;
  left: 12px !important;
  right: auto !important;
  z-index: 100 !important;
}

.user-menu-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.user-menu-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.user-menu-content {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  background: var(--card);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  min-width: 120px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s;
}

.user-menu-content.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-menu-item {
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}

.user-menu-item:active {
  background: var(--bg);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 100%;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-area-top);
  flex-shrink: 0;
}

.header-left, .header-right {
  min-width: 80px;
}

.header-right {
  display: flex;
  justify-content: flex-end;
}

.header-center {
  flex: 1;
  text-align: center;
  font-weight: 600;
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-text:active {
  background: rgba(74, 144, 226, 0.1);
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 80px;
}

.tab-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 60px;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-area-bottom);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  overflow: visible;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.2s;
}

.tab-item.active {
  color: var(--primary);
}

.tab-item.active .tab-icon path {
  fill: var(--primary);
}

.tab-item-primary {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.tab-item-primary::before {
  content: '';
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 50%;
  z-index: -1;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.tab-item-primary .tab-icon {
  width: 24px;
  height: 24px;
  color: #FFFFFF;
  margin-bottom: 0;
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translate(-50%, 16px);
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

.tab-item-primary .tab-icon path,
.tab-item-primary.active .tab-icon path {
  fill: #FFFFFF !important;
}

.tab-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
  display: block;
}

.card {
  background: var(--card);
  border-radius: 8px;
  margin: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.record-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.record-item:active {
  background: var(--bg);
}

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

.record-info {
  flex: 1;
}

.record-subject {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}

.record-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.record-count {
  font-size: 20px;
  font-weight: 600;
  color: var(--primary);
}

.record-count-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 4px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 80px;
  height: 80px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
}

.page-header {
  padding: 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 18px;
  font-weight: 600;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.subject-selector {
  display: flex;
  gap: 8px;
}

.subject-btn {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.subject-btn.active {
  border-color: var(--primary);
  background: rgba(74, 144, 226, 0.1);
  color: var(--primary);
}

.error-input-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.error-input-item {
  display: flex;
  gap: 8px;
  align-items: center;
}

.error-input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.error-input:focus {
  border-color: var(--primary);
}

.error-input::placeholder {
  color: var(--text-secondary);
}

.btn-delete {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-delete:active {
  background: rgba(255, 107, 107, 0.2);
}

.btn-add {
  width: 100%;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: none;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.btn-add:active {
  background: rgba(74, 144, 226, 0.05);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 20px;
}

.btn-primary:active {
  background: var(--primary-light);
}

.btn-primary:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.filter-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.filter-tab.active {
  border-color: var(--primary);
  background: rgba(74, 144, 226, 0.1);
  color: var(--primary);
}

.stats-section {
  padding: 16px;
}

.stats-section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stats-section-title .view-more {
  font-size: 12px;
  color: var(--primary);
  font-weight: normal;
  cursor: pointer;
}

.stats-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.stats-item-content {
  font-size: 14px;
  color: var(--text);
}

.stats-item-count {
  font-size: 14px;
  color: var(--primary);
  font-weight: 500;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.modal.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s;
}

.modal.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.modal-body {
  padding: 16px;
}

.modal-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

.child-list {
  display: flex;
  flex-direction: column;
}

.child-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.child-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.child-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-edit-child {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.btn-edit-child:active {
  background: var(--border);
}

.child-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
}

.child-info {
  display: flex;
  flex-direction: column;
}

.child-name {
  font-size: 14px;
  font-weight: 500;
}

.child-grade {
  font-size: 12px;
  color: var(--text-secondary);
}

.child-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.btn-icon:active {
  background: var(--border);
}

.btn-icon.danger {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
}

.grade-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grade-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.grade-btn.active {
  border-color: var(--primary);
  background: rgba(74, 144, 226, 0.1);
  color: var(--primary);
}

.input-field {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.input-field:focus {
  border-color: var(--primary);
}

.btn-secondary {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.btn-danger {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--danger);
  color: #FFFFFF;
  font-size: 14px;
  cursor: pointer;
}

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0, 0, 0, 0.75);
  color: #FFFFFF;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.toast.active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.back-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.section-header {
  padding: 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.back-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-header-title {
  font-size: 16px;
  font-weight: 600;
}

/* OCR 相关样式 */
.ocr-upload-area {
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.ocr-upload-area:active {
  border-color: var(--primary);
}

.ocr-upload-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.ocr-upload-text {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 12px;
}

.ocr-upload-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.ocr-upload-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
}

.ocr-upload-btn:active {
  background: var(--primary-light);
}

.ocr-image-card {
  background: var(--card);
  border-radius: 8px;
  margin: 12px;
  padding: 12px;
}

.ocr-image-container {
  position: relative;
  display: block;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.ocr-image-container img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  pointer-events: none;
  -webkit-user-drag: none;
}

.ocr-selection-box {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(79, 70, 229, 0.1);
  pointer-events: none;
  display: none;
  border-radius: 4px;
}

.ocr-selection-box::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 2px solid rgba(79, 70, 229, 0.3);
  border-radius: 6px;
  animation: ocrSelectPulse 0.8s ease-out infinite;
}

@keyframes ocrSelectPulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.05); opacity: 0; }
}

.ocr-gesture-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 12px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

.ocr-result-list {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.ocr-result-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

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

.ocr-result-item canvas {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: contain;
  margin-right: 12px;
  background: #fafafa;
}

.ocr-result-text {
  flex: 1;
  font-size: 14px;
}

.ocr-result-remove {
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.ocr-btn {
  display: block;
  width: 100%;
  background: #10b981;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
}

.ocr-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.ocr-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.ocr-input-row:last-child {
  border-bottom: none;
}

.ocr-input-row canvas {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: #fafafa;
}

.ocr-input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}

.ocr-input-row input:focus {
  border-color: var(--primary);
}
