* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  margin: 0;
  background: #f5f6f8;
  color: #222;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: #1f2937;
  color: #fff;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar .brand { color: #fff; font-weight: bold; font-size: 18px; }
.topbar nav { display: flex; gap: 12px; align-items: center; }

.container {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
}

h1 { margin-top: 0; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  color: #374151;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; color: #fff; }
.btn-secondary { background: #fff; color: #374151; }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.link {
  background: none; border: none; color: #fff; cursor: pointer;
  text-decoration: underline; font-size: 14px;
}

/* Login */
.login-box {
  max-width: 360px;
  margin: 80px auto;
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.login-box h1 { margin-top: 0; }
.login-box label { display: block; margin-bottom: 16px; }
.login-box input {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}
.login-box .btn { width: 100%; padding: 10px; }

/* Filter */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  background: #fff;
  padding: 12px;
  border-radius: 8px;
}
.filter-bar input, .filter-bar select {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}
.filter-bar input { flex: 1; }

.count { color: #6b7280; font-size: 14px; }

/* Table */
.entry-table {
  width: 100%;
  background: #fff;
  border-collapse: collapse;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.entry-table th, .entry-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
}
.entry-table th {
  background: #f9fafb;
  font-weight: 600;
  color: #4b5563;
}
.entry-table .empty { text-align: center; padding: 40px; color: #6b7280; }
.entry-table .actions { white-space: nowrap; }
.entry-table .actions form { margin-left: 6px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.type-qa      { background: #dbeafe; color: #1e40af; }
.type-item    { background: #fef3c7; color: #92400e; }
.type-article { background: #dcfce7; color: #166534; }
.cat-badge    { background: #f3e8ff; color: #6b21a8; }

/* 提醒：需要更新的資料 */
.stale-badge {
  display: inline-block;
  padding: 2px 8px;
  margin-top: 4px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.stale-summary {
  color: #d97706;
  font-weight: 500;
  margin-left: 8px;
}

.hint {
  font-size: 12px;
  color: #9ca3af;
  margin: 4px 0 16px;
}

/* School cell */
.schools-cell { white-space: nowrap; }
.school-emoji {
  font-size: 18px;
  display: inline-block;
  cursor: help;
}

/* School field in form */
.schools-field {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}
.schools-label {
  display: block;
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 10px;
}
.schools-checkboxes {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.school-check {
  display: flex !important;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 0 !important;
  font-weight: normal !important;
  user-select: none;
  transition: background 0.15s;
}
.school-check:hover { background: #f3f4f6; }
.school-check input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
.school-check:has(input[type="checkbox"]:checked) {
  background: #eff6ff;
  border-color: #2563eb;
}
.schools-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: #6b7280;
  font-weight: normal;
}

/* Form */
.entry-form {
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  max-width: 720px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.entry-form label {
  display: block;
  margin-bottom: 16px;
  font-weight: 500;
  font-size: 14px;
}
.entry-form input[type=text],
.entry-form select,
.entry-form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.entry-form textarea { resize: vertical; }
.current-images {
  background: #f9fafb;
  padding: 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.current-images p { margin: 0 0 12px; font-weight: 500; }
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.image-tile {
  position: relative;
  display: block;
  margin: 0 !important;
  font-weight: normal !important;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: #e5e7eb;
}
.image-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-tile .remove-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 13px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.image-tile .remove-overlay input { margin: 0; cursor: pointer; }
.image-tile input[type="checkbox"]:checked ~ img,
.image-tile:has(input[type="checkbox"]:checked) img {
  opacity: 0.35;
}
.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.error {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 16px;
}
