* {
  box-sizing: border-box;
}

@media (min-width: 641px) {
  #chart-fullscreen-btn {
    display: none;
  }
}

body {
  margin: 0;
  padding: 0;
  touch-action: pan-x pan-y pinch-zoom;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: #f5f7fb;
  color: #1f2933;
}

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

h1 {
  margin: 0 0 16px;
  font-size: 26px;
  color: #111827;
}

h3 {
  margin: 0 0 4px;
}

p {
  margin: 4px 0;
  color: #4b5563;
}

.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
  padding: 18px;
  margin-bottom: 18px;
  border: 1px solid #e5e7eb;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 12px;
  align-items: center;
}

label {
  color: #374151;
}

input,
select {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
}

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

.form-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
}

button {
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.05s ease, box-shadow 0.1s ease;
}

button:hover {
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

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

button.ghost {
  background: #eef2ff;
  color: #1d4ed8;
  border: 1px solid #dbeafe;
  box-shadow: none;
}

button.danger {
  background: #f43f5e;
  border: 1px solid #fecdd3;
}

.hidden {
  display: none;
}

.tabs {
  display: inline-flex;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
}

.tabs button {
  border: none;
  border-right: 1px solid #e5e7eb;
  background: #f9fafb;
  color: #4b5563;
}

.tabs button:last-child {
  border-right: none;
}

.tabs button.active {
  background: #2563eb;
  color: #fff;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  background: #f59e0b;
  color: #fff;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  margin-left: 8px;
}

.table-wrapper {
  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;
  margin-top: 12px;
}

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

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid #e5e7eb;
  padding: 8px 6px;
  text-align: left;
}

th {
  background: #f9fafb;
  color: #4b5563;
}

td input {
  width: 100%;
  padding: 6px 8px;
  touch-action: pan-x pan-y pinch-zoom;
}

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

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

.baseline-value {
  min-width: 72px;
  font-variant-numeric: tabular-nums;
  color: #475569;
}

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.row-actions button {
  padding: 7px 9px;
}

.chart-wrapper {
  margin-top: 18px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-header h4 {
  margin: 0;
}

button.small {
  padding: 8px 10px;
  font-size: 13px;
}

#profile-chart {
  width: 100%;
  height: 420px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.chart-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.chart-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.65);
}

.chart-modal__panel {
  position: absolute;
  inset: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.chart-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
}

.chart-modal__title {
  font-size: 14px;
  color: #111827;
  font-weight: 600;
}

.chart-modal__body {
  flex: 1;
  min-height: 0;
  padding: 10px;
}

.chart-modal #profile-chart {
  height: 100% !important;
  min-height: 0;
  max-height: none;
}

.chart-modal--open {
  overflow: hidden;
}

.chart-modal--open body {
  overflow: hidden;
}

@media (max-width: 640px) {
  .container {
    margin: 12px auto 24px;
    padding: 0 10px;
  }

  h1 {
    font-size: 20px;
    margin-bottom: 12px;
  }

  .card {
    padding: 12px;
    margin-bottom: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

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

  button {
    font-size: 16px;
    padding: 12px 14px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions button {
    width: 100%;
  }

  .top-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .top-actions button {
    flex: 1 1 auto;
  }

  .inline-actions {
    width: 100%;
  }

  .inline-actions button {
    flex: 1 1 auto;
  }

  table {
    font-size: 12px;
  }

  #measurement-tbody,
  #measurement-tbody tr,
  #measurement-tbody td,
  #measurement-tbody input {
    touch-action: pan-x pan-y pinch-zoom;
  }

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

  .table-wrapper.table-fit-active table {
    min-width: 535px;
    table-layout: fixed;
  }

  .table-wrapper.table-fit-active th,
  .table-wrapper.table-fit-active td {
    min-width: 0;
    padding: 6px 2px;
    font-size: 19px;
    line-height: 1.15;
    text-align: center;
    vertical-align: middle;
    overflow-wrap: anywhere;
  }

  .table-wrapper {
    margin-top: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
  }

  .table-wrapper.table-fit-active {
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  }

  .table-wrapper.table-fit-active tbody tr:nth-child(even) {
    background: #f8fafc;
  }

  .table-wrapper.table-fit-active th:nth-child(1),
  .table-wrapper.table-fit-active td:nth-child(1) {
    width: 11%;
  }

  .table-wrapper.table-fit-active th:nth-child(2),
  .table-wrapper.table-fit-active td:nth-child(2),
  .table-wrapper.table-fit-active th:nth-child(3),
  .table-wrapper.table-fit-active td:nth-child(3),
  .table-wrapper.table-fit-active th:nth-child(4),
  .table-wrapper.table-fit-active td:nth-child(4) {
    width: 12%;
  }

  .table-wrapper.table-fit-active th:nth-child(5),
  .table-wrapper.table-fit-active td:nth-child(5) {
    width: 15%;
  }

  .table-wrapper.table-fit-active th:nth-child(6),
  .table-wrapper.table-fit-active td:nth-child(6) {
    width: 13%;
  }

  .table-wrapper.table-fit-active th:nth-child(7),
  .table-wrapper.table-fit-active td:nth-child(7) {
    width: 25%;
  }

  th,
  td {
    padding: 6px 4px;
  }

  td input {
    padding: 8px 8px;
    min-height: 42px;
    font-size: 16px;
  }

  .table-wrapper.table-fit-active td input {
    min-height: 36px;
    padding: 5px 3px;
    border-color: #dbe3ee;
    border-radius: 7px;
    background: #fff;
    font-size: 19px;
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  .table-wrapper.table-fit-active .baseline-value {
    min-width: 0;
  }

  .table-wrapper.table-fit-active .row-actions {
    gap: 3px;
  }

  .table-wrapper.table-fit-active .row-actions button {
    min-height: 34px;
    padding: 5px 7px;
    border-radius: 7px;
    font-size: 15px;
  }

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

  .table-touch-hint {
    margin: 0;
    color: #64748b;
    font-size: 12px;
    line-height: 1.45;
  }

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

  #add-row-btn,
  #chart-fullscreen-btn {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 14px;
  }

  .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;
  }

  .chart-wrapper {
    margin-top: 14px;
  }

  .chart-wrapper h4 {
    margin: 6px 0 10px;
    font-size: 14px;
  }

  #chart-fullscreen-btn {
    display: inline-flex;
  }

  #profile-chart {
    height: 52vh !important;
    min-height: 260px;
    max-height: 420px;
  }

.toast {
  right: 10px;
  bottom: 10px;
  max-width: calc(100vw - 20px);
  }
}

/* 竖屏手机中将全屏断面图旋转为横向画布；已横屏时保持正常布局。 */
@media (max-width: 640px) and (orientation: portrait) {
  .chart-modal__panel {
    inset: auto;
    top: 50%;
    left: 50%;
    width: 100vh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
  }

  .chart-modal__header {
    padding: 6px 10px;
  }

  .chart-modal__body {
    padding: 4px;
  }
}

/* 清单容器：文件较多时内部滚动，避免把下方内容顶出屏幕 */
#uploaded-stations-list {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 340px;
  margin-top: 6px;
}

/* 与测流助手“已上传布设表”清单保持一致的表格密度 */
#uploaded-stations-list table {
  min-width: 660px;
  font-size: 15px;
}

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

/* 断面文件名称列：逐行展示来源 Excel 完整文件名 */
#uploaded-stations-list .station-section-cell {
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
  min-width: 280px;
}

#uploaded-stations-list .station-section-item {
  display: block;
  word-break: break-all;
}

#uploaded-stations-list .station-section-item + .station-section-item {
  margin-top: 6px;
}

#uploaded-stations-list .station-section-file {
  display: block;
  color: var(--text, #1f2937);
  font-size: 15px;
  line-height: 1.5;
}

#uploaded-stations-list .station-section-file-missing,
#uploaded-stations-list .station-section-more,
#uploaded-stations-list .station-section-empty {
  color: #64748b;
  font-size: 13px;
}

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

/* 移动端：云端导出文件/已上传测站断面清单改为卡片式展示，避免表格过宽 */
@media (max-width: 600px) {
  #exports-list table,
  #uploaded-stations-list table {
    min-width: 0 !important;
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
  }
  #exports-list thead,
  #uploaded-stations-list thead {
    display: none;
  }
  #exports-list tbody,
  #uploaded-stations-list tbody {
    display: block;
  }
  #exports-list tr,
  #uploaded-stations-list tr {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid #eef2f7;
  }
  #exports-list tr:last-child,
  #uploaded-stations-list tr:last-child {
    border-bottom: none;
  }
#exports-list td,
#uploaded-stations-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-stations-list td::before {
    content: attr(data-label);
    color: #94a3b8;
    font-size: 12px;
    flex: none;
  }
  #exports-list td[data-label="文件名"],
  #uploaded-stations-list td[data-label="测站"],
  #uploaded-stations-list td[data-label="断面文件名称"] {
    display: block;
    text-align: left;
    margin-top: 4px;
  }
  #exports-list td[data-label="文件名"]::before,
  #uploaded-stations-list td[data-label="测站"]::before,
  #uploaded-stations-list td[data-label="断面文件名称"]::before {
    display: block;
    margin-bottom: 4px;
  }
  #uploaded-stations-list .station-section-cell {
    min-width: 0;
  }
}

