* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  touch-action: manipulation;
}

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

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background: linear-gradient(135deg, #1a73e8, #1557b0);
  color: white;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 10;
}

header h1 {
  font-size: 20px;
  font-weight: 600;
}

header .header-info {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
}

header .header-info button {
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  background: transparent;
  color: white;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}

header .header-info button:hover {
  background: rgba(255,255,255,0.15);
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.connection-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.connection-status .dot.connected {
  background: #4caf50;
}

.connection-status .dot.disconnected {
  background: #f44336;
}

main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  background: white;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar section {
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.sidebar section h3 {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #1a73e8;
}

.add-student-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.add-student-form input,
.add-student-form select {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.add-student-form input:focus,
.add-student-form select:focus {
  border-color: #1a73e8;
}

.add-student-form input {
  flex: 1;
}

.add-student-form button {
  padding: 6px 14px;
  background: #1a73e8;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.2s;
}

.add-student-form button:hover {
  background: #1557b0;
}

.student-list {
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
}

.student-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}

.student-list li:hover {
  background: #f5f7fa;
}

.student-list li.selected {
  background: #e3f2fd;
  border: 1px solid #1a73e8;
}

.student-list li .student-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.student-list li .student-gender {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
}

.student-gender.male {
  background: #e3f2fd;
  color: #1565c0;
}

.student-gender.female {
  background: #fce4ec;
  color: #c62828;
}

.student-role {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 600;
}

.role-student {
  background: #e8f5e9;
  color: #2e7d32;
}

.role-teacher {
  background: #fff3e0;
  color: #e65100;
}

.student-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.student-list li button {
  padding: 2px 8px;
  background: transparent;
  border: 1px solid #e0e0e0;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  color: #999;
  transition: all 0.2s;
}

.student-list li .btn-call {
  border-color: #e0e0e0;
  color: #666;
  font-size: 14px;
  padding: 2px 6px;
}

.student-list li .btn-call:hover {
  background: #e3f2fd;
  border-color: #1a73e8;
  color: #1a73e8;
}

.student-list li .btn-del:hover {
  background: #ffebee;
  border-color: #ef9a9a;
  color: #c62828;
}

.layout-controls label {
  font-size: 13px;
  color: #555;
}

.layout-controls input[type="number"] {
  width: 50px;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 13px;
  text-align: center;
}

.layout-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.layout-actions button,
.layout-controls .btn {
  padding: 5px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.layout-actions button:hover,
.layout-controls .btn:hover {
  background: #f5f5f5;
  border-color: #bbb;
}

.layout-actions button.active {
  background: #1a73e8;
  color: white;
  border-color: #1a73e8;
}

.cell-legend {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: #666;
}

.cell-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cell-legend .swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid #ddd;
}

.hint {
  font-size: 11px;
  color: #999;
  margin-top: 8px;
  line-height: 1.5;
}

.hint.call-flash {
  color: #e65100;
  font-weight: 600;
  font-size: 13px;
  transition: none;
}

/* ---- Seat Area ---- */
.seat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  overflow: auto;
}

.podium {
  width: 60%;
  max-width: 400px;
  padding: 10px;
  background: linear-gradient(135deg, #e8eaf6, #c5cae9);
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: #3949ab;
  border-radius: 4px;
  margin-bottom: 24px;
  letter-spacing: 8px;
}

#seat-map {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 900px;
  aspect-ratio: auto;
}

.seat-cell {
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  font-size: 13px;
  font-weight: 500;
  cursor: default;
  transition: all 0.15s;
  position: relative;
  user-select: none;
}

.seat-cell.seat-empty {
  background: #f1f8e9;
  border: 2px dashed #c8e6c9;
  color: #81c784;
  cursor: pointer;
}

.seat-cell.seat-empty:hover {
  background: #e8f5e9;
  border-color: #66bb6a;
}

.seat-cell.seat-occupied {
  background: #fff8e1;
  border: 2px solid #ffe082;
  cursor: pointer;
}

.seat-cell.seat-occupied:hover {
  background: #fff3e0;
  border-color: #ffb74d;
}

.seat-cell.seat-occupied .student-name {
  font-size: 14px;
  font-weight: 600;
  color: #e65100;
}

.seat-cell.seat-aisle {
  background: transparent;
  border: none;
  min-height: 30px;
}

.seat-cell.seat-empty-space {
  background: #fafafa;
  border: 1px dashed #e0e0e0;
  min-height: 30px;
}

.seat-cell .seat-label {
  font-size: 11px;
  color: #a5d6a7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  padding: 0 2px;
}

.seat-cell.seat-occupied .student-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  padding: 0 2px;
}

.seat-cell .action-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #1a73e8;
  color: white;
  font-size: 11px;
  display: none;
  align-items: center;
  justify-content: center;
}

.seat-cell.show-badge .action-badge {
  display: flex;
}

/* Teacher mode - cell toolbar */
.cell-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.cell-toolbar button {
  padding: 6px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.cell-toolbar button:hover {
  border-color: #bbb;
  background: #fafafa;
}

.cell-toolbar button.active {
  border-color: #1a73e8;
  background: #e3f2fd;
  color: #1a73e8;
  font-weight: 600;
}

/* Call notification */
.notification-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.notification-overlay.show {
  display: flex;
}

.notification-box {
  background: white;
  border-radius: 16px;
  padding: 40px 60px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.notification-box .icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.notification-box h2 {
  font-size: 28px;
  color: #333;
  margin-bottom: 12px;
}

.notification-box .student-name-big {
  font-size: 52px;
  font-weight: 700;
  color: #1a73e8;
  margin: 16px 0;
  letter-spacing: 4px;
}

.notification-box .sub-text {
  font-size: 16px;
  color: #666;
  margin-bottom: 24px;
}

.notification-box button {
  padding: 10px 32px;
  background: #1a73e8;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.notification-box button:hover {
  background: #1557b0;
}

/* ---- Landing Page ---- */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.landing h1 {
  font-size: 36px;
  margin-bottom: 8px;
}

.landing p {
  font-size: 16px;
  opacity: 0.85;
  margin-bottom: 40px;
}

.landing .cards {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.landing .card {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  padding: 32px 40px;
  width: 260px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  color: white;
  text-decoration: none;
}

.landing .card:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.landing .card .card-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.landing .card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.landing .card p {
  font-size: 13px;
  opacity: 0.8;
  margin-bottom: 0;
}

.landing .server-info {
  margin-top: 32px;
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  font-size: 13px;
  font-family: monospace;
}

/* ---- Classroom mode specific ---- */
.classroom-mode .seat-area {
  padding: 10px 40px;
}

.classroom-mode #seat-map {
  max-width: 1000px;
}

.classroom-mode .seat-cell.seat-occupied .student-name {
  font-size: 18px;
}

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
}

.modal-box {
  background: white;
  border-radius: 12px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

.modal-header h3 {
  font-size: 16px;
  color: #333;
  margin: 0;
  border: none;
  padding: 0;
}

.modal-close {
  font-size: 22px;
  color: #999;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #333;
}

.modal-body {
  padding: 20px;
}

.modal-field {
  margin-bottom: 16px;
}

.modal-field:last-child {
  margin-bottom: 0;
}

.modal-field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
}

.modal-field input,
.modal-field select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.modal-field input:focus,
.modal-field select:focus {
  border-color: #1a73e8;
}

.modal-field input.error {
  border-color: #e53935;
  background: #fff5f5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #eee;
}

.modal-footer button {
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-cancel {
  background: #f5f5f5;
  color: #666;
}

.btn-cancel:hover {
  background: #eee;
}

.btn-confirm {
  background: #1a73e8;
  color: white;
}

.btn-confirm:hover {
  background: #1557b0;
}

.btn-add {
  float: right;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #1a73e8;
  color: white;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-add:hover {
  background: #1557b0;
}

.btn-import {
  float: right;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #1a73e8;
  background: white;
  color: #1a73e8;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-right: 6px;
}

.btn-import:hover {
  background: #e3f2fd;
}

.btn-template {
  float: right;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #ccc;
  background: white;
  color: #666;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-right: 6px;
}

.btn-template:hover {
  background: #f5f5f5;
  border-color: #999;
}

/* ---- Mobile Header Buttons ---- */
.hamburger {
  display: none;
  font-size: 22px;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 19;
}

.sidebar-close-btn {
  display: none;
  float: right;
  background: none;
  border: none;
  font-size: 22px;
  color: #999;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.hide-phone {
  display: inline;
}

/* ---- Tablet (max-width: 1024px) ---- */
@media (max-width: 1024px) {
  .sidebar {
    width: 260px;
  }
  #seat-map {
    max-width: 100%;
  }
  .seat-cell {
    min-height: 42px;
    font-size: 12px;
  }
  .seat-cell.seat-occupied .student-name {
    font-size: 12px;
  }
}

/* ---- Phone (max-width: 768px) ---- */
@media (max-width: 768px) {
  body {
    font-size: 14px;
  }

  header {
    padding: 10px 14px;
    flex-wrap: nowrap;
  }
  header h1 {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-info {
    gap: 8px;
    font-size: 12px;
    flex-shrink: 0;
  }
  .header-info button {
    padding: 4px 10px;
    font-size: 12px;
  }
  .connection-status {
    font-size: 11px;
  }

  .hide-phone {
    display: none !important;
  }
  .hamburger {
    display: inline-block;
  }
  .sidebar-close-btn {
    display: inline-block;
  }

  main {
    flex-direction: column;
    position: relative;
  }

  /* Sidebar: off-screen overlay on mobile */
  .sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    max-height: 100vh;
    z-index: 20;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
    transition: left 0.3s ease;
    overflow-y: auto;
    border-right: none;
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-backdrop.open {
    display: block;
  }

  .sidebar section {
    padding: 12px 14px;
  }
  .sidebar section h3 {
    font-size: 13px;
    margin-bottom: 10px;
  }

  /* Seat area */
  .seat-area {
    flex: 1;
    padding: 10px 8px;
    overflow: auto;
  }
  .podium {
    width: 80%;
    font-size: 14px;
    padding: 8px;
    margin-bottom: 14px;
  }
  #seat-map {
    gap: 4px;
    max-width: 100%;
  }
  .seat-cell {
    min-height: 40px;
    font-size: 11px;
    border-radius: 4px;
  }
  .seat-cell.seat-occupied .student-name {
    font-size: 12px;
  }
  .seat-cell.seat-aisle {
    min-height: 24px;
  }
  .seat-cell.seat-empty-space {
    min-height: 24px;
  }

  /* Cell toolbar */
  .cell-toolbar {
    gap: 4px;
  }
  .cell-toolbar button {
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    min-width: 44px;
    min-height: 44px;
    flex: 1;
  }
  .layout-actions {
    gap: 4px;
  }
  .layout-actions button,
  .layout-controls .btn {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Student list */
  .student-list li {
    padding: 10px 8px;
    font-size: 13px;
    min-height: 44px;
  }
  .student-list li button {
    padding: 6px 12px;
    font-size: 14px;
    min-width: 40px;
    min-height: 40px;
  }
  .student-list li .btn-call {
    font-size: 16px;
  }
  .btn-add {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  /* Layout input */
  .layout-controls input[type="number"] {
    width: 44px;
    padding: 6px 6px;
    font-size: 14px;
  }

  /* Hint */
  .hint {
    font-size: 12px;
  }

  /* Notification */
  .notification-box {
    padding: 24px 20px;
    border-radius: 12px;
    width: 90vw;
    max-width: 360px;
  }
  .notification-box .icon {
    font-size: 42px;
    margin-bottom: 12px;
  }
  .notification-box h2 {
    font-size: 22px;
    margin-bottom: 8px;
  }
  .notification-box .student-name-big {
    font-size: 36px;
    margin: 10px 0;
    letter-spacing: 3px;
  }
  .notification-box .sub-text {
    font-size: 14px;
    margin-bottom: 20px;
  }
  .notification-box button {
    padding: 12px 36px;
    font-size: 16px;
    min-height: 48px;
    min-width: 120px;
  }

  /* Modal */
  .modal-box {
    width: 92vw;
    max-width: 400px;
    border-radius: 10px;
  }
  .modal-header {
    padding: 14px 16px;
  }
  .modal-header h3 {
    font-size: 15px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-field label {
    font-size: 13px;
  }
  .modal-field input,
  .modal-field select {
    padding: 10px 12px;
    font-size: 16px;
  }
  .modal-footer {
    padding: 10px 16px;
  }
  .modal-footer button {
    padding: 10px 24px;
    font-size: 15px;
    min-height: 44px;
  }

  /* Landing page */
  .landing {
    padding: 40px 20px;
    justify-content: flex-start;
  }
  .landing h1 {
    font-size: 24px;
    text-align: center;
  }
  .landing p {
    font-size: 14px;
    text-align: center;
    margin-bottom: 28px;
  }
  .landing .cards {
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
  }
  .landing .card {
    width: 100%;
    max-width: 320px;
    padding: 24px 28px;
  }
  .landing .card .card-icon {
    font-size: 40px;
    margin-bottom: 12px;
  }
  .landing .card h2 {
    font-size: 18px;
  }
  .landing .card p {
    font-size: 13px;
  }
  .landing .server-info {
    margin-top: 24px;
    padding: 10px 16px;
    font-size: 12px;
    width: 100%;
    max-width: 320px;
    text-align: center;
    word-break: break-all;
    margin-bottom: 20px;
  }

  /* Classroom mode */
  .classroom-mode .seat-area {
    padding: 8px 10px;
  }
  .classroom-mode #seat-map {
    max-width: 100%;
  }
  .classroom-mode .seat-cell.seat-occupied .student-name {
    font-size: 14px;
  }
}

/* ---- Small Phone (max-width: 480px) ---- */
@media (max-width: 480px) {
  header {
    padding: 8px 10px;
  }
  header h1 {
    font-size: 14px;
  }
  .header-info {
    gap: 4px;
    font-size: 10px;
  }
  .header-info button {
    padding: 3px 8px;
    font-size: 11px;
  }

  .sidebar {
    left: -280px;
    width: 260px;
    max-width: 85vw;
  }

  .seat-area {
    padding: 6px 4px;
  }
  .podium {
    width: 90%;
    font-size: 13px;
    padding: 6px;
    margin-bottom: 10px;
    letter-spacing: 4px;
  }
  #seat-map {
    gap: 3px;
  }
  .seat-cell {
    min-height: 34px;
    font-size: 10px;
    border-radius: 3px;
  }
  .seat-cell.seat-occupied .student-name {
    font-size: 10px;
  }
  .seat-cell.seat-aisle,
  .seat-cell.seat-empty-space {
    min-height: 20px;
  }

  .cell-toolbar button {
    padding: 6px 8px;
    font-size: 11px;
    min-width: 38px;
    min-height: 38px;
  }

  .cell-legend {
    gap: 6px;
    font-size: 10px;
    flex-wrap: wrap;
  }

  .notification-box {
    padding: 20px 14px;
    width: 95vw;
  }
  .notification-box .icon {
    font-size: 36px;
  }
  .notification-box h2 {
    font-size: 20px;
  }
  .notification-box .student-name-big {
    font-size: 28px;
    letter-spacing: 2px;
  }
  .notification-box .sub-text {
    font-size: 13px;
  }
  .notification-box button {
    padding: 10px 30px;
    font-size: 15px;
  }

  .landing h1 {
    font-size: 20px;
  }
  .landing .card {
    padding: 20px 20px;
  }
  .landing .card .card-icon {
    font-size: 34px;
  }
  .landing .card h2 {
    font-size: 16px;
  }
}
