:root {
  --bg: linear-gradient(145deg, #e8f0fe 0%, #f1f5f9 45%, #e2e8f0 100%);
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --th-bg: linear-gradient(180deg, #1e3a5f 0%, #1e40af 100%);
  --th-text: #f8fafc;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --success: #059669;
  --danger: #dc2626;
  --row-alt: #f8fafc;
  --row-hover: #eff6ff;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.page {
  max-width: 100%;
  padding: 28px 20px 48px;
}

/* Header */
.header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  padding: 20px 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

@media (max-width: 900px) {
  .header {
    grid-template-columns: 1fr;
  }
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.header-meta {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  background: #eff6ff;
  padding: 6px 14px;
  border-radius: 999px;
}

.lock-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  background: #fef3c7;
  color: #92400e;
}

.lock-badge.unlocked {
  background: #d1fae5;
  color: #065f46;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-icon {
  font-size: 1rem;
  line-height: 1;
}

.btn-primary {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-dark);
}

.btn-secondary:hover:not(:disabled) {
  background: #f8fafc;
  border-color: var(--primary);
  color: var(--primary);
}

.btn-accent {
  background: linear-gradient(180deg, #14b8a6, #0d9488);
  color: #fff;
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.35);
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(180deg, #0d9488, #0f766e);
}

.btn-accent-outline {
  background: #fff;
  color: #0d9488;
  border: 1px solid #5eead4;
  box-shadow: none;
}

.btn-accent-outline:hover:not(:disabled) {
  background: #f0fdfa;
  border-color: #0d9488;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.btn-ghost {
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 6px;
}

.btn-ghost:hover:not(:disabled) {
  background: #fef2f2;
}

/* Card & table */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-toolbar {
  padding: 12px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.toolbar-hint {
  font-size: 0.78rem;
  color: var(--muted);
}

.form-sheet {
  overflow: auto;
  max-height: calc(100vh - 280px);
  min-height: 200px;
  scrollbar-gutter: stable;
}

.form-table {
  width: 100%;
  min-width: 1520px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

/* 列宽由 colgroup 统一控制，表头与数据行对齐 */
.form-table .w-no { width: 48px; }
.form-table .w-vin { width: 120px; }
.form-table .w-dest { width: 90px; }
.form-table .w-customs { width: 110px; }
.form-table .w-progress { width: 100px; }
.form-table .w-video { width: 120px; }
.form-table .w-cmr { width: 120px; }
.form-table .w-transit { width: 120px; }
.form-table .w-location { width: 100px; }
.form-table .w-driver { width: 120px; }
.form-table .w-action { width: 72px; }

.form-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.form-table thead th {
  background: var(--th-bg);
  color: var(--th-text);
  border: 1px solid #1e3a8a;
  padding: 12px 8px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-table tbody td {
  border: 1px solid var(--border);
  padding: 8px;
  vertical-align: middle;
  background: #fff;
  overflow: hidden;
  text-align: center;
}

.form-table tbody tr.data-row:nth-child(even) td {
  background: var(--row-alt);
}

.form-table tbody tr.data-row:hover td {
  background: var(--row-hover);
}

.form-table .col-no {
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  background: #f1f5f9 !important;
}

.form-table .col-action {
  text-align: center;
}

.data-row .field-input {
  width: 100%;
  max-width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8125rem;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
  text-align: center;
}

.data-row .field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.data-row .field-input:read-only {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  cursor: default;
  color: var(--text);
}

.cell-file {
  overflow: hidden;
  text-align: center;
  vertical-align: middle !important;
}

.cell-file-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
}

/* 编辑时才显示「选择文件」 */
body:not(.is-editing) .cell-file .file-picker {
  display: none;
}

.file-picker {
  display: inline-flex;
  flex-shrink: 0;
  cursor: pointer;
}

.file-picker .file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

.file-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  background: #f8fafc;
  border: 1px solid var(--border-dark);
  border-radius: 6px;
  transition: border-color 0.15s, background 0.15s;
}

.file-picker:hover .file-picker-btn {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}

.cell-meta {
  margin-top: 4px;
}

.file-meta {
  font-size: 0.72rem;
  color: var(--muted);
  word-break: break-all;
}

.file-meta.pending {
  color: #b45309;
  font-weight: 500;
}

.file-meta.empty {
  color: #cbd5e1;
}

.cell-file .file-meta-wrap {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
}

.btn-view {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(180deg, #6366f1, #4f46e5);
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.3);
  transition: background 0.15s;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  box-sizing: border-box;
}

.btn-view:hover {
  background: linear-gradient(180deg, #4f46e5, #4338ca);
}

.btn-view--disabled {
  background: #e2e8f0;
  color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-view--pending {
  background: #fef3c7;
  color: #b45309;
  box-shadow: none;
  cursor: default;
  font-size: 0.7rem;
}

/* 当前位置 - 地图按钮（flex 放在 td 内部 div，避免破坏表格列对齐） */
.cell-location {
  text-align: center;
  padding: 8px 4px !important;
}

.location-inner {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 100%;
}

body.is-editing .location-inner {
  flex-wrap: wrap;
}

body.is-editing .cell-location .loc-url-input {
  flex: 1 1 100%;
  min-width: 80px;
}

.cell-location .loc-url-input {
  width: 100%;
  max-width: 100%;
  font-size: 0.7rem;
  padding: 4px 6px;
  box-sizing: border-box;
}

body:not(.is-editing) .cell-location .loc-url-input {
  display: none;
}

.loc-meta-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.btn-map {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: auto;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
  transition: background 0.15s;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  box-sizing: border-box;
}

.btn-map:hover {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.45);
  transform: translateY(-1px);
}

.btn-map--disabled {
  background: #e2e8f0;
  color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.loading-row td,
.empty-row td {
  text-align: center;
  padding: 48px 20px !important;
  color: var(--muted);
  font-size: 0.9rem;
  background: #fafbfc !important;
}

.form-footer {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
  border-top: 1px solid var(--border);
}

.footer-hint {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Toast & modal */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  padding: 14px 22px;
  border-radius: 10px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.modal h2 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.modal p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 1rem;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-actions .btn {
  flex: 1;
}

.modal-wide {
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
}

.modal-wide .modal-icon {
  text-align: center;
}

.modal-wide h2 {
  text-align: center;
}

.batch-section h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
  color: var(--text);
}

.modal-desc {
  font-size: 0.8rem !important;
  color: var(--muted) !important;
  margin-bottom: 12px !important;
  text-align: left;
}

.batch-row-count {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.batch-row-count label {
  font-size: 0.875rem;
  font-weight: 600;
}

.batch-row-count input[type="number"] {
  width: 80px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  text-align: center;
  margin-bottom: 0;
}

.batch-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-preset {
  padding: 6px 12px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  cursor: pointer;
  color: var(--text);
}

.btn-preset:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.batch-divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.batch-divider::before,
.batch-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.batch-divider span {
  padding: 0 12px;
}

.batch-paste {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  line-height: 1.4;
  resize: vertical;
  margin-bottom: 4px;
}

.batch-paste:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.modal-wide .modal-actions {
  margin-top: 16px;
}
