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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
}

/* ===== 登录 ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
  background: #fff;
  padding: 48px 40px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  text-align: center;
  width: 380px;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: #333;
}

.login-desc {
  color: #888;
  font-size: 14px;
  margin-bottom: 28px;
}

.login-card input {
  width: 100%;
  height: 44px;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0 16px;
  font-size: 15px;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}

.login-card input:focus {
  outline: none;
  border-color: #667eea;
}

.login-card button {
  width: 100%;
  height: 44px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-card button:hover { opacity: 0.9; }

.error-text {
  color: #e53935;
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

/* ===== 主界面 ===== */
.main-screen {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
}

header h1 {
  font-size: 22px;
  color: #333;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.count-badge {
  font-size: 13px;
  color: #666;
  background: #e8eaf6;
  padding: 4px 12px;
  border-radius: 20px;
}

.btn-text {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
}

.btn-text:hover { color: #333; }

/* ===== 区块 ===== */
.section {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.section h2 {
  font-size: 16px;
  color: #333;
  margin-bottom: 16px;
}

/* ===== 上传区域 ===== */
.upload-area {
  border: 2px dashed #d0d5dd;
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-area:hover, .upload-area.drag-over {
  border-color: #667eea;
  background: #f8f9ff;
}

.upload-icon { font-size: 40px; margin-bottom: 12px; }
.upload-text { font-size: 15px; color: #333; margin-bottom: 6px; }
.upload-hint { font-size: 13px; color: #aaa; margin-top: 4px; }

.upload-result {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
}

.upload-result.success { background: #e8f5e9; color: #2e7d32; }
.upload-result.error { background: #ffebee; color: #c62828; }

/* ===== 工具栏 ===== */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.filters {
  display: flex;
  gap: 10px;
}

.filters select {
  height: 36px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  color: #333;
  background: #fff;
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 10px;
}

.btn-primary {
  height: 36px;
  padding: 0 20px;
  background: #1976d2;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-primary:hover { background: #1565c0; }

.btn-danger {
  height: 36px;
  padding: 0 20px;
  background: #fff;
  color: #e53935;
  border: 1px solid #e53935;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover { background: #ffebee; }

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-sm:hover { opacity: 0.8; }

.btn-gen { background: #e3f2fd; color: #1565c0; }
.btn-del { background: #ffebee; color: #c62828; }

.pinyin-input {
  width: 100%;
  min-width: 100px;
  max-width: 160px;
  padding: 2px 0;
  font-size: 15px;
  border: none;
  border-bottom: 1px solid transparent;
  background: transparent;
  box-sizing: border-box;
  color: #555;
  transition: border-color 0.3s;
}
.pinyin-input:focus {
  outline: none;
  border-bottom-color: #1976d2;
}

/* ===== 表格 ===== */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: #f5f5f5;
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  color: #666;
  font-weight: 600;
  border-bottom: 1px solid #eee;
}

td {
  padding: 10px 12px;
  font-size: 14px;
  border-bottom: 1px solid #f5f5f5;
  vertical-align: middle;
}

tr:hover td { background: #fafbfc; }

.empty-row {
  text-align: center;
  padding: 40px !important;
  color: #bbb;
}

.qr-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.2s;
  border: 1px solid #eee;
}

.qr-thumb:hover { transform: scale(1.1); }

.qr-pending {
  font-size: 12px;
  color: #bbb;
  background: #f5f5f5;
  padding: 4px 10px;
  border-radius: 4px;
}

.cell-actions {
  display: flex;
  gap: 6px;
}

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-content img {
  width: 240px;
  height: 240px;
  border-radius: 12px;
}

.modal-content p {
  margin: 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.td-mono { font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12px; color: #666; }
.td-time { font-size: 12px; color: #888; white-space: nowrap; }
.td-wrap { max-width: 400px; word-break: break-all; white-space: pre-wrap; font-size: 12px; }
.score-pos { color: #2e7d32; font-weight: 600; }
.score-neg { color: #c62828; font-weight: 600; }

/* ===== Tab 导航 ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: #fff;
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.tab {
  flex: 1;
  height: 42px;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-active {
  background: #1976d2;
  color: #fff;
  font-weight: 600;
}

.table-section { overflow: hidden; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 1000px; }

/* ===== 座位工具栏 ===== */
.seat-toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.seat-toolbar select {
  height: 38px;
  padding: 0 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
}

/* ===== 座位主布局 ===== */
.seat-main {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  align-items: flex-start;
}

.seat-placeholder {
  text-align: center;
  padding: 80px 20px;
  color: #bbb;
  font-size: 16px;
}

/* 未安排学生面板 */
.unassigned-panel {
  width: 220px;
  flex-shrink: 0;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  max-height: 600px;
  overflow-y: auto;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: #666;
  margin-bottom: 12px;
  text-align: center;
}

.unassigned-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-height: 40px;
}

/* 学生名字标签 */
.stu-tag {
  padding: 10px 6px;
  font-size: 15px;
  text-align: center;
  background: #e3f2fd;
  color: #1565c0;
  border-radius: 8px;
  cursor: grab;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s;
  border: 2px solid transparent;
}

.stu-tag:hover { background: #bbdefb; }
.stu-tag.dragging { opacity: 0.4; }

/* 教室区域 */
.classroom-area {
  flex: 1;
  min-width: 0;
}

.podium {
  background: #fce4ec;
  color: #c62828;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 12px;
  margin-bottom: 14px;
}

.groups-row {
  display: flex;
  flex-direction: row-reverse;
  gap: 14px;
  justify-content: center;
}

/* 大组 */
.group {
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  padding: 8px 6px;
  transition: all 0.2s;
}

.group.drag-over-group {
  border-color: #ff9800;
  background: #fff8e1;
}

.group-header {
  text-align: center;
  font-size: 14px;
  color: #999;
  margin-bottom: 8px;
  cursor: grab;
  padding: 4px 0;
  user-select: none;
  font-weight: 600;
}

.group-header:hover { color: #ff9800; }

.group-cols {
  display: flex;
  flex-direction: row-reverse;
  gap: 4px;
}

/* 小组（列） */
.subgroup {
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 4px;
}

.subgroup.drag-over-subgroup {
  border-color: #4caf50;
  background: #e8f5e9;
}

.subgroup-header {
  text-align: center;
  font-size: 13px;
  color: #bbb;
  cursor: grab;
  user-select: none;
  padding: 4px 0;
  font-weight: 500;
}

.subgroup-header:hover { color: #4caf50; }

/* 座位格 */
.seat-cell {
  width: 90px;
  height: 42px;
  border: 1.5px dashed #ddd;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: #ccc;
  transition: all 0.15s;
  background: #fff;
}

.seat-cell.occupied {
  border-style: solid;
  border-color: #90caf9;
  background: #e3f2fd;
  color: #1565c0;
  font-weight: 600;
  cursor: grab;
}

.seat-cell.drag-over-seat {
  border-color: #1976d2;
  background: #bbdefb;
  border-style: solid;
}

/* ===== 实验室布局 ===== */
.lab-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  direction: rtl;
}

.lab-table {
  direction: ltr;
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 8px;
  transition: all 0.2s;
}

.lab-table.drag-over-group {
  border-color: #ff9800;
  background: #fff8e1;
}

.lab-seats {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  align-items: center;
  justify-items: center;
}

.lab-table-label {
  grid-row: 1 / 3;
  grid-column: 2;
  width: 68px;
  height: 68px;
  background: #fff3e0;
  border: 2px solid #ffcc80;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #e65100;
  cursor: grab;
  user-select: none;
}

.lab-table-label:hover { background: #ffe0b2; }

.lab-s-tl { grid-column: 1; grid-row: 1; }
.lab-s-tr { grid-column: 3; grid-row: 1; }
.lab-s-bl { grid-column: 1; grid-row: 2; }
.lab-s-br { grid-column: 3; grid-row: 2; }

.lab-grid .seat-cell {
  width: 72px;
  height: 38px;
  font-size: 14px;
}

/* ===== 四路路队布局 ===== */
.queue-row {
  display: flex;
  flex-direction: row-reverse;
  gap: 20px;
  justify-content: center;
}

.queue-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  padding: 10px 12px;
  transition: all 0.2s;
}

.queue-col.drag-over-subgroup {
  border-color: #4caf50;
  background: #e8f5e9;
}

.queue-col-header {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  cursor: grab;
  user-select: none;
  padding: 6px 0;
  background: #e8eaf6;
  border-radius: 6px;
  margin-bottom: 4px;
}

.queue-col-header:hover { background: #c5cae9; }

.queue-row .seat-cell {
  width: 90px;
  height: 38px;
  font-size: 14px;
}

/* 右侧按钮 */
.seat-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
  padding-top: 40px;
}

.seat-btn {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 2px;
}

.seat-btn-clear {
  background: #fff3e0;
  color: #e65100;
  border: 2px solid #ffcc80;
}

.seat-btn-clear:hover { background: #ffe0b2; }

.seat-btn-submit {
  background: #e8f5e9;
  color: #2e7d32;
  border: 2px solid #a5d6a7;
}

.seat-btn-submit:hover { background: #c8e6c9; }

/* ===== 自定义确认弹窗 ===== */
.confirm-mask {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.confirm-card {
  background: linear-gradient(145deg, #ffffff, #f0f4ff);
  border-radius: 24px;
  padding: 40px 36px 32px;
  text-align: center;
  width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  animation: confirmPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes confirmPop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.confirm-emoji { font-size: 56px; margin-bottom: 12px; }

.confirm-title {
  font-size: 20px;
  font-weight: 700;
  color: #333;
  margin-bottom: 8px;
}

.confirm-desc {
  font-size: 14px;
  color: #888;
  margin-bottom: 28px;
}

.confirm-btns {
  display: flex;
  gap: 12px;
}

.confirm-btn-yes {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, #43a047, #66bb6a);
  color: #fff;
  transition: opacity 0.2s;
}

.confirm-btn-yes:hover { opacity: 0.9; }

.confirm-btn-no {
  flex: 1;
  height: 44px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: #888;
  transition: all 0.2s;
}

.confirm-btn-no:hover { border-color: #bbb; color: #555; }

/* ===== 全局触摸优化 ===== */
.stu-tag, .seat-cell.occupied, .group-header, .subgroup-header,
.lab-table-label, .queue-col-header {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .login-card { width: 90%; padding: 36px 24px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .filters, .actions { flex-wrap: wrap; }
  .main-screen { padding: 10px; }
  .section { padding: 14px; }

  header h1 { font-size: 18px; }
  .tabs { gap: 2px; }
  .tab { font-size: 14px; height: 38px; }

  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; }
  th, td { padding: 6px 5px; white-space: nowrap; }

  .seat-toolbar { flex-direction: column; gap: 8px; }
  .seat-toolbar select { width: 100%; }

  .seat-main {
    flex-direction: column;
    gap: 12px;
  }

  .unassigned-panel {
    width: 100%;
    max-height: 180px;
    order: -1;
  }

  .unassigned-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .classroom-area {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
  }

  .groups-row {
    min-width: 680px;
  }

  .seat-actions {
    flex-direction: row;
    justify-content: center;
    padding-top: 0;
  }

  .seat-btn {
    width: auto;
    height: 48px;
    padding: 0 28px;
    flex: 1;
  }

  .podium {
    font-size: 14px;
    padding: 8px;
    letter-spacing: 8px;
  }

  .seat-cell {
    width: 70px;
    height: 36px;
    font-size: 13px;
  }

  .stu-tag {
    padding: 8px 4px;
    font-size: 13px;
  }

  .group-header { font-size: 12px; }
  .subgroup-header { font-size: 11px; }

  /* 实验室手机 */
  .lab-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .lab-table-label {
    width: 54px;
    height: 54px;
    font-size: 13px;
  }

  .lab-grid .seat-cell {
    width: 58px;
    height: 32px;
    font-size: 12px;
  }

  /* 路队手机 */
  .queue-row {
    gap: 10px;
  }

  .queue-row .seat-cell {
    width: 70px;
    height: 34px;
    font-size: 13px;
  }

  .queue-col-header {
    font-size: 13px;
    padding: 4px 0;
  }

  /* 确认弹窗 */
  .confirm-card {
    width: 85%;
    padding: 32px 24px 24px;
  }
}

/* ===================== 打印码模块 ===================== */

.print-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.print-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.print-controls label {
  font-weight: 600;
  color: #555;
}

.print-controls button:not(.btn-primary) {
  width: 30px;
  height: 30px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: background 0.15s;
}

.print-controls button:not(.btn-primary):hover {
  background: #eef2ff;
}

.print-controls span {
  display: inline-block;
  width: 24px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

.print-preview {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.a4-page {
  width: 794px;
  height: 1123px;
  background: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  display: grid;
  padding: 16px;
  box-sizing: border-box;
}

.qr-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.qr-cell img {
  max-width: 90%;
  max-height: calc(100% - 22px);
  object-fit: contain;
  border-radius: 4px;
}

.qr-cell span {
  font-size: 11px;
  color: #444;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

.qr-cell-empty {
  visibility: hidden;
}

@media (max-width: 860px) {
  .a4-page {
    width: 100%;
    height: auto;
    aspect-ratio: 210 / 297;
  }
  .print-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
