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

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Helvetica Neue", Arial, sans-serif;
  background: #f5f7fa;
  color: #1f2937;
  line-height: 1.55;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 导航 ---------- */
.navbar {
  background: #1d4ed8;
  color: white;
  padding: 10px 16px;
  /* 适配 iOS 灵动岛/状态栏：把安全区域加到顶部 padding 与左右 padding 上 */
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.navbar .title { font-size: 17px; font-weight: 600; min-width: 0; flex: 1; }
.navbar .title a {
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.navbar .title a span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.navbar-logo {
  height: 30px;
  width: auto;
  flex: 0 0 auto;
  background: white;
  border-radius: 6px;
  padding: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.navbar .user-info { font-size: 13px; flex: 0 0 auto; }
.navbar .user-info a { color: #dbeafe; margin-left: 12px; }
.navbar .user-info a:hover { color: white; }

/* ---------- 容器 ---------- */
.container {
  max-width: 980px;
  margin: 16px auto;
  padding: 0 16px 40px;
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
}

.card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  margin: 0 0 16px;
  font-size: 17px;
  color: #1f2937;
  border-left: 4px solid #1d4ed8;
  padding-left: 10px;
}
.card h3 {
  font-size: 15px;
  color: #374151;
  margin: 0 0 10px;
}

/* ---------- 首页菜单 ---------- */
.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.menu-btn {
  display: block;
  background: white;
  border: 2px solid #1d4ed8;
  color: #1d4ed8;
  padding: 22px 14px;
  text-align: center;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: all .12s;
}
.menu-btn:hover, .menu-btn:active {
  background: #1d4ed8;
  color: white;
  text-decoration: none;
}
.menu-btn .sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  margin-top: 4px;
  opacity: .8;
}

/* ---------- 表单 ---------- */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: #374151;
}
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="password"],
.form-row textarea,
.form-row select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
  background: white;
}
.form-row textarea { min-height: 80px; resize: vertical; }
.form-row .input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-row .input-wrap input { flex: 1; }
.check-status {
  font-size: 18px;
  width: 28px;
  text-align: center;
  font-weight: 700;
}
.check-status.ok { color: #059669; }
.check-status.fail { color: #dc2626; }
.check-status.checking { color: #6b7280; font-size: 14px; }

input[type="file"] {
  width: 100%;
  padding: 8px 0;
  font-size: 14px;
}

/* ---------- 按钮 ---------- */
.btn {
  background: #1d4ed8;
  color: white;
  border: none;
  padding: 11px 22px;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #1e40af; text-decoration: none; color: white; }
.btn.secondary { background: #6b7280; }
.btn.secondary:hover { background: #4b5563; }
.btn.danger { background: #dc2626; }
.btn.danger:hover { background: #b91c1c; }
.btn.success { background: #059669; }
.btn.success:hover { background: #047857; }
.btn.outline {
  background: white;
  color: #1d4ed8;
  border: 1px solid #1d4ed8;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- 提示 ---------- */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 14px;
}
.alert.error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert.success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert.info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.alert.warn    { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* ---------- 子区域 ---------- */
.sub-section {
  background: #f9fafb;
  padding: 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  border: 1px solid #e5e7eb;
}

/* ---------- 图片缩略图 ---------- */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.image-grid a {
  display: block;
  background: #f3f4f6;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}
.image-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- 指标 ---------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.metric-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 12px;
  border-radius: 6px;
}
.metric-card .label {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}
.metric-card .value {
  font-size: 22px;
  font-weight: 700;
  color: #1e3a8a;
}
.metric-card .sub {
  font-size: 12px;
  color: #4b5563;
  margin-top: 2px;
}

/* ---------- 表格 ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th, .data-table td {
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  text-align: left;
}
.data-table th {
  background: #f3f4f6;
  font-weight: 600;
}

/* ---------- 登录 ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  background: linear-gradient(135deg, #1d4ed8, #2563eb 60%, #60a5fa);
}
.login-box {
  width: 100%;
  max-width: 360px;
  background: white;
  border-radius: 12px;
  padding: 24px 24px 28px;
  box-shadow: 0 20px 40px rgba(0,0,0,.15);
}
.login-logo {
  display: block;
  margin: 0 auto 12px;
  height: 64px;
  width: auto;
  max-width: 100%;
}
.login-box h1 {
  margin: 0 0 18px;
  text-align: center;
  color: #1f2937;
  font-size: 20px;
}

/* ---------- 计数页 ---------- */
.count-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #f3f4f6;
  border-radius: 6px;
  position: sticky;
  /* 跟随 iOS 安全区动态调整，避免被灵动岛/状态栏遮挡 */
  top: calc(50px + env(safe-area-inset-top, 0px));
  z-index: 10;
}
.count-toolbar .count-box {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  background: white;
  border-radius: 4px;
  border: 1px solid #d1d5db;
}
.count-toolbar .count-num {
  font-size: 22px;
  font-weight: 700;
  color: #1d4ed8;
}
.count-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #4b5563;
}
.count-toolbar input[type="range"] {
  width: 100px;
  vertical-align: middle;
}

.count-image-area {
  max-width: 100%;
  overflow: auto;
  background: #111827;
  border-radius: 6px;
  padding: 4px;
  text-align: center;
  -webkit-overflow-scrolling: touch;
}
.count-wrapper {
  position: relative;
  display: inline-block;
  user-select: none;
  line-height: 0;
  transform-origin: top left;
  --mark-size: 22px;
  --mark-font: 11px;
  --mark-border: 2px;
  --mark-opacity: 0.9;
}
.count-image {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: crosshair;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
}
.mark {
  position: absolute;
  width: var(--mark-size);
  height: var(--mark-size);
  background: rgba(220, 38, 38, var(--mark-opacity));
  color: white;
  border: var(--mark-border) solid rgba(255, 255, 255, var(--mark-opacity));
  border-radius: 50%;
  font-size: var(--mark-font);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, calc(var(--mark-opacity) * 0.55));
  line-height: 1;
  overflow: hidden;
}
.mark.alive { background: rgba(5, 150, 105, var(--mark-opacity)); }

.count-form {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.count-form label { font-size: 13px; color: #374151; }
.count-form input { width: 100%; }

.rate-display {
  font-size: 22px;
  font-weight: 700;
  color: #047857;
}

/* ---------- 工具 ---------- */
.muted { color: #6b7280; font-size: 13px; }
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  background: #e0e7ff;
  color: #3730a3;
  font-size: 12px;
  margin-left: 6px;
}
.tag.done { background: #d1fae5; color: #065f46; }
.tag.todo { background: #fee2e2; color: #991b1b; }

/* ---------- 统计选择列表 ---------- */
.stats-image-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.stats-image-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: white;
}
.stats-image-item.todo {
  border-color: #fde68a;
  background: #fffbeb;
}
.stats-image-item.done {
  background: #f9fafb;
  opacity: .85;
}
.stats-image-item .stats-image-thumb {
  display: block;
  width: 88px;
  height: 88px;
  background: #f3f4f6;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}
.stats-image-item .stats-image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.stats-image-item .stats-image-info {
  min-width: 0;
}
.stats-image-item .stats-image-info .title {
  font-weight: 600;
  font-size: 15px;
  color: #1f2937;
  margin-bottom: 4px;
}
.stats-image-item .stats-image-info .muted {
  font-size: 12.5px;
}
.stats-image-item .stats-image-action {
  flex: 0 0 auto;
}
@media (max-width: 600px) {
  .stats-image-item {
    grid-template-columns: 64px 1fr;
    grid-template-rows: auto auto;
  }
  .stats-image-item .stats-image-thumb { width: 64px; height: 64px; }
  .stats-image-item .stats-image-action {
    grid-column: 1 / -1;
    text-align: right;
  }
  .stats-image-item .stats-image-action .btn { padding: 8px 14px; font-size: 14px; }
}

/* ---------- 分页器 ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.pager .btn.outline.disabled,
.pager .btn.disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}
.recent-table th, .recent-table td { vertical-align: middle; }
.recent-table .tag { margin-right: 4px; }

/* ---------- 异步上传横幅 ---------- */
.upload-banner {
  position: sticky;
  top: 0;
  z-index: 90;
  margin: 0;
  padding: 10px 14px;
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  font-size: 14px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
  text-align: center;
}
.upload-banner.active {
  color: #1e3a8a;
  background: #dbeafe;
  border-bottom-color: #bfdbfe;
}
.upload-banner.failed {
  color: #991b1b;
  background: #fee2e2;
  border-bottom-color: #fecaca;
}

/* ---------- 异步上传槽位 ---------- */
.async-slot { /* 留作未来钩子 */ }
.upload-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 13px;
}
.upload-item .up-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.upload-item .up-name {
  color: #1f2937;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-item .up-size {
  color: #6b7280;
  font-size: 12px;
}
.upload-item .up-status {
  flex: 0 0 auto;
  font-weight: 600;
  color: #6b7280;
  display: flex;
  align-items: center;
  gap: 6px;
}
.upload-item.uploading {
  border-color: #bfdbfe;
  background: #eff6ff;
}
.upload-item.uploading .up-status { color: #1d4ed8; }
.upload-item.done {
  border-color: #a7f3d0;
  background: #ecfdf5;
}
.upload-item.done .up-status { color: #047857; }
.upload-item.failed {
  border-color: #fecaca;
  background: #fef2f2;
}
.upload-item.failed .up-status { color: #b91c1c; }
.upload-item .up-retry {
  background: #1d4ed8;
  color: white;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.upload-item .up-retry:hover { background: #1e40af; }

.async-feedback {
  /* 复用 .alert 样式 */
}

/* ---------- 适配 ---------- */
@media (max-width: 600px) {
  .container {
    padding: 0 10px 30px;
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
    padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  }
  .card { padding: 14px; }
  .navbar .title { font-size: 15px; }
  .navbar .user-info { font-size: 12px; }
  .navbar-logo { height: 26px; }
  .menu-btn { padding: 18px 12px; font-size: 15px; }
  .count-toolbar { top: 48px; }
  .upload-banner { font-size: 13px; padding: 8px 10px; }
}
