/* 测流助手 Cloudflare 版 —— 全局样式 */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #eef1f6;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --danger: #dc2626;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  touch-action: pan-x pan-y pinch-zoom;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 780px;
  margin: 64px auto 40px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08);
  padding: 28px 24px 32px;
}

#app h2 {
  color: var(--text);
  font-size: 21px;
  margin: 4px 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#app h2::before {
  content: "";
  width: 5px;
  height: 20px;
  border-radius: 3px;
  background: var(--primary);
  flex: none;
}

h3 {
  color: var(--text-2);
  font-size: 16px;
  margin: 0 0 8px;
}

label {
  font-size: 15px;
  color: var(--text-2);
  display: block;
  margin: 12px 0 6px;
}

input,
select {
  padding: 11px 13px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 16px;
  box-sizing: border-box;
  background: #f8fafc;
  margin: 6px 0;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input[type="radio"] {
  padding: 0;
  width: auto;
  margin: 0 5px 0 0;
  accent-color: var(--primary);
}

input[type="file"] {
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  padding: 10px;
  width: 100%;
}

select {
  width: 100%;
}

#admin-station-input {
  width: 100%;
}

button {
  padding: 12px 18px;
  margin: 8px 8px 8px 0;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  min-height: 44px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.18);
}

button:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

button:active {
  transform: translateY(1px);
}

#admin-upload-message {
  color: var(--danger);
  margin: 8px 0 0;
  font-size: 14px;
  min-height: 18px;
}

#user-form-confirm {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
  padding: 12px 14px;
  margin: 12px 0;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.7;
}

/* 标题栏帮助图标按钮 */
.help-icon-btn {
  margin: 0 0 0 auto;
  flex: none;
  width: 30px;
  height: 30px;
  min-height: 30px;
  min-width: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: var(--primary);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.help-icon-btn:hover {
  background: #dbeafe;
  box-shadow: none;
}

/* 帮助弹窗内容 */
#help-modal .help-content {
  text-align: left;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-2);
}

#help-modal .help-content h4 {
  margin: 14px 0 6px;
  font-size: 15px;
  color: var(--primary-dark);
  border-left: 3px solid var(--primary);
  padding-left: 8px;
}

#help-modal .help-content h4:first-child {
  margin-top: 4px;
}

#help-modal .help-content p {
  margin: 4px 0;
}

#help-modal .help-content ul,
#help-modal .help-content ol {
  margin: 4px 0;
  padding-left: 20px;
  line-height: 1.7;
  color: var(--text-2);
}

#help-modal .help-content li {
  margin-bottom: 4px;
}

/* 表格 */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 14px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

th,
td {
  border-bottom: 1px solid #eef2f7;
  border-right: 1px solid #eef2f7;
  padding: 10px 8px;
  text-align: center;
  font-size: 14px;
}

th {
  background: #f1f5f9;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
}

tr:last-child td {
  border-bottom: none;
}

th:last-child,
td:last-child {
  border-right: none;
}

tbody tr:nth-child(even) {
  background: #f8fafc;
}

tbody tr:hover {
  background: #eff6ff;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
  scrollbar-width: thin;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.table-scroll table {
  border: none;
  border-radius: 0;
  margin: 0;
  min-width: 640px;
}

.table-fit-surface {
  min-width: 100%;
}

.table-scroll.table-fit-active {
  overflow: hidden;
}

#data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f1f5f9;
}

#data-table td[contenteditable="true"] {
  min-width: 64px;
  touch-action: pan-x pan-y pinch-zoom;
  -webkit-user-select: auto;
  user-select: auto;
}

.table-touch-controls {
  display: none;
}

.table-drag-handle {
  display: none;
}

#data-table td[contenteditable="true"]:focus {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  background: #eff6ff;
}

#table-info {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  text-align: center;
  color: var(--text-2);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

#table-params {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

#table-params label {
  margin: 0;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#table-params input {
  width: 64px;
  padding: 6px 8px;
  font-size: 14px;
  margin: 0;
}

#table-params span {
  color: var(--text-3);
  font-size: 13px;
}

/* 小按钮 */
.mini-btn {
  font-size: 14px;
  padding: 4px 10px;
  min-width: 34px;
  min-height: 30px;
  margin: 2px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: none;
}

.mini-btn:hover {
  background: var(--primary-dark);
}

.delete-row-btn {
  border: 1px solid #fecdd3;
  background: #fff1f2;
  color: #be123c;
}

.delete-row-btn:hover {
  background: #ffe4e6;
}

.insert-row-btn {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.insert-row-btn:hover {
  background: #dbeafe;
}

.measurement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.measurement-actions button {
  margin: 0;
}

/* 管理员预览与已上传清单 */
#admin-preview-section {
  font-size: 14px;
  line-height: 1.6;
}

#admin-preview-section .file-station-input {
  flex: 1;
  min-width: 180px;
}

#uploaded-files-list {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 340px;
  margin-top: 6px;
}

#uploaded-files-list table {
  min-width: 520px;
  font-size: 15px;
}

#uploaded-files-list th,
#uploaded-files-list td {
  padding: 8px 6px;
}

#exports-list {
  overflow-y: auto;
  max-height: 60vh;
}

/* 流量计算弹窗 / 帮助弹窗（覆盖 JS 内联样式） */
#flow-modal,
#help-modal {
  background: rgba(15, 23, 42, 0.55) !important;
}

#flow-modal > div,
#help-modal > div {
  border-radius: 16px !important;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3) !important;
  padding: 22px 14px !important;
}

#flow-modal h3,
#help-modal h3 {
  color: var(--text);
}

#help-modal ol {
  line-height: 1.8;
  color: var(--text-2);
  padding-left: 20px;
}

#flow-modal table {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  width: auto;
  min-width: unset;
  table-layout: auto;
}

#flow-modal th,
#flow-modal td {
  max-width: 120px;
  min-width: 44px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 7px 6px;
  font-size: 14px;
}

#close-flow-modal,
#close-help-modal {
  width: 100%;
  font-size: 17px;
  padding: 12px 0;
  margin-top: 16px;
  border-radius: 10px;
}

/* 移动端适配 */
@media (max-width: 600px) {
  #app {
    margin: 104px 0 0;
    padding: 18px 14px 28px;
    border-radius: 0;
    box-shadow: none;
    min-height: calc(100vh - 104px);
  }

  #app h2 {
    font-size: 19px;
  }

  input,
  select {
    font-size: 16px;
    padding: 10px 11px;
  }

  button {
    font-size: 14px;
    padding: 11px 14px;
  }

  th,
  td {
    font-size: 13px;
    padding: 8px 5px;
  }

  .table-scroll table {
    min-width: 780px;
  }

  .table-scroll.table-fit-active #data-table {
    min-width: 540px;
    table-layout: fixed;
    overflow: visible;
  }

  .table-scroll.table-fit-active #data-table th,
  .table-scroll.table-fit-active #data-table td {
    min-width: 0;
    padding: 6px 2px;
    font-size: 16px;
    line-height: 1.15;
    vertical-align: middle;
    overflow-wrap: anywhere;
  }

  /* 数值完整可见：不截断、不省略，超长数字自动换行 */
  .table-scroll.table-fit-active #data-table tbody td {
    min-height: 40px;
    white-space: normal;
    word-break: break-all;
    overflow: visible;
    font-variant-numeric: tabular-nums;
  }

  .table-scroll.table-fit-active #data-table th {
    font-size: 13px;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(1),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(1),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(2),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(2) {
    width: 6.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(3),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(3),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(4),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(4),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(5),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(5),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(7),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(7) {
    width: 10%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(6),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(6) {
    width: 11.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(8),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(8) {
    width: 9%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(9),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(9),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(10),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(10) {
    width: 7.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="11"] th:nth-child(11),
  .table-scroll.table-fit-active #data-table[data-column-count="11"] td:nth-child(11) {
    width: 11.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(1),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(1),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(2),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(2) {
    width: 7%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(3),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(3),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(4),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(4),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(5),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(5),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(7),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(7) {
    width: 11%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(6),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(6) {
    width: 12.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(8),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(8),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(9),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(9) {
    width: 10%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="10"] th:nth-child(10),
  .table-scroll.table-fit-active #data-table[data-column-count="10"] td:nth-child(10) {
    width: 9.5%;
  }

  /* 12 列（双流速仪：10 数据列 + 流速仪列 + 操作列） */
  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(1),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(1),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(2),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(2) {
    width: 6%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(3),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(3) {
    width: 10%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(4),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(4),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(5),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(5),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(7),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(7),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(8),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(8) {
    width: 8.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(6),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(6) {
    width: 11%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(9),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(9),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(10),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(10) {
    width: 7%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(11),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(11) {
    width: 6.5%;
  }

  .table-scroll.table-fit-active #data-table[data-column-count="12"] th:nth-child(12),
  .table-scroll.table-fit-active #data-table[data-column-count="12"] td:nth-child(12) {
    width: 11.5%;
  }

  #data-table td[contenteditable="true"] {
    min-width: 68px;
    min-height: 42px;
    font-size: 16px;
    line-height: 1.35;
  }

  .table-scroll.table-fit-active #data-table td[contenteditable="true"] {
    min-width: 0;
    min-height: 36px;
    font-size: 16px;
  }

  .table-scroll.table-fit-active #data-table .mini-btn {
    display: block;
    min-width: 30px;
    min-height: 30px;
    margin: 2px auto;
    padding: 3px 5px;
    border-radius: 7px;
    font-size: 15px;
  }

  .table-touch-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    clear: both;
    margin: 4px 0 8px;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
  }

  .table-touch-hint {
    margin: 0;
    color: var(--text-3);
    font-size: 12px;
    line-height: 1.45;
    text-align: left;
  }

  .table-fit-toggle {
    flex: 0 0 auto;
    min-height: 34px;
    margin: 0;
    padding: 6px 10px;
    font-size: 13px;
    box-shadow: none;
  }

  .measurement-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    margin-top: 10px;
  }

  .measurement-actions button {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 9px 6px;
    font-size: 14px;
    line-height: 1.25;
  }

  .measurement-actions #back-btn {
    grid-column: 1 / -1;
  }

  .table-drag-handle:not([hidden]) {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    margin: 0 0 7px;
    border: 1px dashed #93c5fd;
    border-radius: 9px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 14px;
    font-weight: 600;
    touch-action: none;
    user-select: none;
    cursor: grab;
  }

  .table-drag-handle.is-dragging {
    background: #dbeafe;
    cursor: grabbing;
  }

  #table-info {
    font-size: 13px;
  }

  #table-params {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  #table-params label {
    justify-content: space-between;
  }

  #table-params input {
    width: 90px;
  }

  #flow-modal > div,
  #help-modal > div {
    max-width: 98vw;
    padding: 14px 6px !important;
  }

  #flow-modal table {
    font-size: 12px;
  }

  #flow-modal th,
  #flow-modal td {
    max-width: 76px;
    min-width: 34px;
    padding: 5px 2px;
  }

  #close-flow-modal,
  #close-help-modal {
    font-size: 16px;
  }
}

/* 移动端：文件/测站清单改为卡片式展示，避免表格过宽 */
@media (max-width: 600px) {
  #exports-list table,
  #uploaded-files-list table {
    min-width: 0 !important;
    display: block;
    border: 1px solid var(--border);
    border-radius: 12px;
  }
  #exports-list thead,
  #uploaded-files-list thead {
    display: none;
  }
  #exports-list tbody,
  #uploaded-files-list tbody {
    display: block;
  }
  #exports-list tr,
  #uploaded-files-list tr {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid #eef2f7;
  }
  #exports-list tr:last-child,
  #uploaded-files-list tr:last-child {
    border-bottom: none;
  }
  #exports-list td,
  #uploaded-files-list td {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 4px 8px;
    padding: 5px 0;
    border: none;
    text-align: right;
    font-size: 15px;
  }
  #exports-list td::before,
  #uploaded-files-list td::before {
    content: attr(data-label);
    color: var(--text-3);
    font-size: 12px;
    flex: none;
  }
  #exports-list td[data-label="文件名"],
  #uploaded-files-list td[data-label="文件名"] {
    display: block;
    text-align: left;
    margin-top: 4px;
  }
  #exports-list td[data-label="文件名"]::before,
  #uploaded-files-list td[data-label="文件名"]::before {
    display: block;
    margin-bottom: 4px;
  }
}
