/* ================= 可调参数 ================= */
:root {
  --col-min-width: 130px;
  --img-max-height: 220px;
}

/* ================= 基础 ================= */
* { box-sizing: border-box; }

body {
  margin: 0;
  padding-bottom: 22px; /* 给底部滚动条留位置，避免遮挡内容 */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: #f5f7fb;
  color: #1f2937;
}

/* ================= 顶栏 ================= */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: #111827;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #374151; color: #e5e7eb;
}
.badge.warn { background: #92400e; color: #fef3c7; }
.spacer { flex: 1; }
.muted { color: #6b7280; font-size: 13px; }
.topbar .muted { color: #d1d5db; }

.refresh-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #d1d5db;
}
.refresh-indicator[hidden] { display: none; }

/* ================= 客户端侧栏布局 ================= */
.app-layout {
  min-width: 0;
}

.sidebar {
  position: fixed;
  top: 80px;
  left: 0;
  z-index: 30;
  width: 220px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  transform: translateX(calc(-100% + 14px));
  transition: transform .2s ease;
  padding: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

.sidebar:hover,
.sidebar:focus-within {
  transform: translateX(0);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sidebar-nav a {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border-radius: 7px;
  color: #374151;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
}

.sidebar-nav a:hover { background: #f3f4f6; }
.sidebar-nav a[aria-current="page"] {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

/* ================= 布局容器 =================
   横向滚动能力保留，但滚动条 UI 隐藏；
   滚轮 / 触控板横滑仍可用。
   ========================================== */
.wrap,
.table-scroll {
  overflow-x: auto;
  scrollbar-width: none;         /* Firefox：隐藏滚动条 UI */
}
.wrap::-webkit-scrollbar,
.table-scroll::-webkit-scrollbar {
  height: 0;
  width: 0;                      /* Chrome / Safari：隐藏滚动条 UI */
}

.wrap {
  margin: 24px auto;
  padding: 0 16px;
  min-width: 0;
}

/* ================= 表格 ================= */
.sheet {
  width: 100%;
  min-width: calc(var(--col-min-width) * 13 + 32px);
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

.sheet.mecha-sheet {
  min-width: calc(var(--col-min-width) * 6 + 32px);
}

.sheet th,
.sheet td {
  border-bottom: 1px solid #e5e7eb;
  border-right: 1px solid #e5e7eb;
  padding: 8px;
  text-align: center;
  vertical-align: middle;
}
.sheet th:last-child,
.sheet td:last-child { border-right: 0; }

.sheet thead th {
  background: #f9fafb;
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
  padding: 12px 8px;
  min-width: var(--col-min-width);
}

.sheet tbody td { padding: 10px 8px; }

/* ================= 图片预览（自适应列宽） ================= */
.preview {
  max-width: 100%;
  max-height: var(--img-max-height);
  width: auto;
  height: auto;
  object-fit: contain;

  border-radius: 6px;
  border: 1px solid #e5e7eb;
  cursor: zoom-in;
  background: #fff;
  display: block;
  margin: 0 auto;
}

.empty { color: #9ca3af; font-size: 12px; }

.empty-row {
  text-align: center;
  color: #9ca3af;
  padding: 32px 12px !important;
  height: auto !important;
}

/* ================= 图片 + 文件名 ================= */
.pic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pic-name {
  max-width: 100%;
  font-size: 12px;
  color: #4b5563;
  text-align: center;
  line-height: 1.3;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

/* ================= 后台单元格 ================= */
.admin-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.admin-cell .preview {
  max-width: 100%;
  max-height: 160px;
}

.admin-ops {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.upload-btn {
  display: inline-block;
  padding: 4px 12px;
  font-size: 12px;
  background: #2563eb;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.upload-btn:hover { filter: brightness(1.05); }

button.tiny {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}
button.danger { background: #dc2626; color: #fff; }
button.danger:hover { filter: brightness(1.1); }

.ops-cell {
  width: 76px;
  background: #fafafa;
}

/* ================= 分支序号输入框 ================= */
.branch-input {
  width: 108px;
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
  background: #fff;
}
.branch-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}

.plain-text-input {
  width: 126px;
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
}

.plain-text-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}

/* ================= 客户端文本值（分支序号） ================= */
.text-value {
  display: inline-block;
  padding: 6px 12px;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 6px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.multiline-text-value {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.multiline-input {
  width: 126px;
  min-height: 56px;
  max-width: 240px;
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  resize: vertical;
}

.multiline-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}

/* ================= 图片下拉框 ================= */
.pic-select {
  width: 126px;
  padding: 4px 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
  cursor: pointer;
}
.pic-select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}

/* ================= 面板 / 登录 / 工具栏 ================= */
.panel {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 18px;
}
.panel h2 { font-size: 16px; margin: 0 0 12px; }

.login-row { display: flex; gap: 10px; flex-wrap: wrap; }

input[type=text],
input[type=password],
input:not([type]) {
  padding: 9px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  min-width: 180px;
}

button {
  padding: 9px 14px;
  border: 0;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button.secondary { background: #e5e7eb; color: #111827; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.admin-page-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.admin-page-nav a {
  padding: 8px 12px;
  border-radius: 7px;
  color: #374151;
  font-size: 13px;
  text-decoration: none;
  background: #f3f4f6;
}

.admin-page-nav a[aria-current="page"] {
  color: #1d4ed8;
  background: #eff6ff;
  font-weight: 600;
}

/* ================= 底部固定横向滚动条 ================= */
.bottom-scroll {
  position: fixed;
  left: 0;
  right: auto;
  bottom: 0;
  height: 18px;
  overflow-x: auto;
  overflow-y: hidden;
  background: #f5f7fb;
  border-top: 1px solid #e5e7eb;
  z-index: 20;
}
.bottom-scroll[hidden] { display: none; }

.bottom-scroll-inner {
  height: 1px;
}

/* ================= 灯箱（图片放大） ================= */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
  cursor: zoom-out;
  overflow: auto;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  border-radius: 8px;
  background: #fff;
}

/* ================= 加载动画 ================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 247, 251, .92);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity .3s ease;
}
.loading-overlay.fade-out { opacity: 0; }
.loading-overlay[hidden] { display: none; }

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 40px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .08);
}

.loading-text {
  margin: 0;
  color: #374151;
  font-size: 14px;
  text-align: center;
}

.spinner {
  border-radius: 50%;
  border-style: solid;
  border-color: #e5e7eb;
  border-top-color: #2563eb;
  animation: spin .9s linear infinite;
}
.spinner.big { width: 44px; height: 44px; border-width: 4px; }
.spinner.small {
  width: 14px; height: 14px; border-width: 2px;
  display: inline-block; vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ================= 响应式 ================= */
@media (max-width: 640px) {
  :root {
    --col-min-width: 110px;
    --img-max-height: 160px;
  }
  .app-layout {
    display: block;
  }
  .sidebar {
    padding: 6px;
  }
  .wrap { margin-top: 12px; padding: 0 10px; }
  .loading-box { padding: 24px 28px; }
}

/* ================= 修改密码面板 ================= */
.pwd-panel {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.pwd-panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #374151;
}

.pwd-panel .login-row {
  margin-bottom: 6px;
}

.pwd-panel #pwdMsg {
  margin: 0;
  min-height: 18px;
}

/* ================= 备份设置面板 ================= */
.bk-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: #374151;
}

.bk-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

.bk-label {
  font-weight: 500;
  color: #111827;
}

.bk-row input[type=number] {
  width: 100px;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
}

.bk-hint {
  color: #9ca3af;
  font-size: 12px;
}

#bkMsg {
  margin: 6px 0 0;
  min-height: 18px;
}

#bkCount {
  font-size: 12px;
}

/* ================= 页脚备案信息 ================= */
.site-footer {
  max-width: 980px;
  margin: 8px auto 24px;
  padding: 16px 16px 8px;
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
}

.site-footer a {
  color: #9ca3af;
  text-decoration: none;
  transition: color .15s ease;
}

.site-footer a:hover {
  color: #2563eb;
  text-decoration: underline;
}
