/* =========================================================
 * 物流查询 · 样式(黑白灰 · 跟随系统自动切换浅色/深色)
 * ========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ---------- 主题变量:浅色(默认) ---------- */
:root {
  color-scheme: light;

  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --surface-3: #ededed;

  --border: #e4e4e4;
  --border-strong: #d4d4d4;

  --text: #181818;
  --muted: #717171;
  --faint: #a1a1a1;

  --accent: #181818;
  --accent-contrast: #ffffff;

  --ring: rgba(24, 24, 27, 0.12);

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;

  --shadow: 0 8px 24px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.1);
}

/* ---------- 主题变量:深色(跟随系统) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0b0b0b;
    --surface: #161616;
    --surface-2: #1d1d1d;
    --surface-3: #262626;

    --border: #2a2a2a;
    --border-strong: #3a3a3a;

    --text: #fafafa;
    --muted: #a1a1a1;
    --faint: #717171;

    --accent: #fafafa;
    --accent-contrast: #181818;

    --ring: rgba(250, 250, 250, 0.18);

    --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);
  }
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  padding: 2.5rem 1rem 3rem;
  display: flex;
  justify-content: center;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============ 主面板 ============ */
.app {
  position: relative;
  width: min(100%, 760px);
  padding: 1.9rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app__header {
  margin-bottom: 1.5rem;
}

.app__title {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.app__subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* ============ 搜索区 ============ */
.search {
  display: grid;
  grid-template-columns: 1.5fr 0.9fr auto auto;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.search__field {
  position: relative;
  min-width: 0;
}

.search__icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search__input,
.search__select,
.search__phone {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.95rem;
  min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.search__input {
  width: 100%;
  padding-left: 2.4rem;
}

.search__input::placeholder,
.search__phone::placeholder {
  color: var(--faint);
}

.search__input:focus,
.search__select:focus,
.search__phone:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--ring);
}

.search__select {
  cursor: pointer;
}

.search__select option {
  background: var(--surface);
  color: var(--text);
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.3rem;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.12s ease, background 0.15s ease;
}

.btn__icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.btn--search {
  color: var(--accent-contrast);
  background: var(--accent);
  white-space: nowrap;
}

.btn--search:hover {
  opacity: 0.88;
}

.btn--search:active {
  transform: scale(0.98);
}

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

.hint {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  animation: fadeUp 0.25s ease both;
}

.hint.is-muted {
  color: var(--faint);
}

/* ============ 初始引导 ============ */
.empty-state {
  text-align: center;
  padding: 2rem 1rem 1rem;
  animation: fadeUp 0.35s ease both;
}

.empty-state__badge {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  border: 1px solid var(--border);
}

.empty-state__badge svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--text);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state__title {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  font-weight: 600;
}

.empty-state__desc {
  margin: 0 auto 0.9rem;
  max-width: 32rem;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--muted);
}

.empty-state__tips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: inline-flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.empty-state__tips li {
  position: relative;
  padding-left: 1.1rem;
  font-size: 0.8rem;
  color: var(--faint);
}

.empty-state__tips li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--faint);
}

/* ============ 骨架屏 ============ */
.skeleton {
  padding-top: 0.3rem;
}

.sk {
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 37%,
    var(--surface-2) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}

.sk--card { height: 78px; margin-bottom: 1rem; }
.sk--steps { height: 44px; margin-bottom: 1.2rem; }
.sk--row { height: 50px; margin-bottom: 0.6rem; }
.sk--row:last-child { margin-bottom: 0; }

@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ============ 结果区 ============ */
.result {
  animation: fadeUp 0.35s ease both;
}

/* ============ 状态卡 ============ */
.status-card {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  margin-bottom: 1.2rem;
}

/* 已签收:实心强调 */
.status-card.state--delivered {
  border-left-color: var(--text);
}

/* 异常/退回:虚线边框 + 反色图标,黑白灰下也能一眼区分 */
.status-card.state--problem,
.status-card.state--returned {
  border-left-style: dashed;
  border-left-color: var(--muted);
}

.status-card__icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text);
}

.status-card.state--problem .status-card__icon,
.status-card.state--returned .status-card__icon {
  background: var(--accent);
  color: var(--accent-contrast);
}

.status-card__icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-card__main {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-width: 0;
  flex: 1;
}

.status-card__state {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.status-card.state--unknown .status-card__state {
  color: var(--muted);
}

.status-card__meta {
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-all;
}

.copy {
  flex: 0 0 auto;
  align-self: flex-start;
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.copy:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ============ 进度条 ============ */
.stepper {
  display: flex;
  list-style: none;
  margin: 0 0 1.3rem;
  padding: 0.3rem 0 0;
}

.stepper__item {
  position: relative;
  flex: 1;
  text-align: center;
}

.stepper__item:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  width: 100%;
  height: 1px;
  background: var(--border-strong);
  transition: background 0.3s ease;
}

.stepper__item.is-done:not(.is-current):not(:last-child)::after {
  background: var(--accent);
}

.stepper__dot {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  transition: background 0.25s ease, border-color 0.25s ease;
}

.stepper__dot::after {
  content: "✓";
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-contrast);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.stepper__item.is-done .stepper__dot {
  background: var(--accent);
  border-color: var(--accent);
}

.stepper__item.is-done .stepper__dot::after {
  opacity: 1;
  transform: scale(1);
}

.stepper__item.is-current .stepper__dot {
  box-shadow: 0 0 0 4px var(--ring);
}

.stepper__label {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--faint);
  transition: color 0.25s ease;
}

.stepper__item.is-done .stepper__label {
  color: var(--text);
}

.stepper.is-error .stepper__dot {
  background: var(--surface-3);
  border-style: dashed;
  border-color: var(--muted);
}

.stepper.is-error .stepper__dot::after {
  content: "!";
  opacity: 1;
  transform: scale(1);
  color: var(--muted);
}

.stepper.is-error .stepper__item.is-done .stepper__dot {
  background: var(--surface-3);
  border-color: var(--muted);
}

/* ============ 视图切换 ============ */
.view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.views {
  display: inline-flex;
  padding: 0.2rem;
  gap: 0.2rem;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
}

.view {
  font: inherit;
  font-size: 0.84rem;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  transition: color 0.15s ease, background 0.2s ease;
}

.view:hover {
  color: var(--text);
}

.view.is-active {
  color: var(--accent-contrast);
  background: var(--accent);
}

.view-bar__count {
  font-size: 0.78rem;
  color: var(--faint);
}

/* ============ 时间线 ============ */
.timeline {
  display: flex;
  flex-direction: column;
  max-height: min(56vh, 520px);
  overflow-y: auto;
  padding-right: 0.3rem;
}

.timeline::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }

.timeline::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.trace {
  position: relative;
  padding: 0.3rem 0.6rem 1rem 1.6rem;
  border-radius: 8px;
  animation: traceIn 0.35s ease both;
  transition: background 0.15s ease;
}

.trace:hover {
  background: var(--surface-2);
}

.trace::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 15px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.trace:last-child::before {
  display: none;
}

.trace__dot {
  position: absolute;
  left: 0;
  top: 7px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
}

.trace.is-latest .trace__dot {
  background: var(--accent);
  border-color: var(--accent);
}

.trace__desc {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--muted);
  word-break: break-word;
}

.trace.is-latest .trace__desc {
  font-weight: 600;
  color: var(--text);
}

.trace__time {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.74rem;
  color: var(--faint);
}

/* ============ 表格 ============ */
.table-wrap {
  max-height: min(56vh, 520px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  animation: fadeUp 0.3s ease both;
}

.trace-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.trace-table th,
.trace-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.trace-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}

.trace-table tbody tr:hover {
  background: var(--surface-2);
}

.trace-table tbody tr:last-child td {
  border-bottom: none;
}

.trace-table td:first-child {
  white-space: nowrap;
  color: var(--faint);
  font-size: 0.78rem;
}

/* ============ 更多按钮 ============ */
.btn--more {
  width: 100%;
  margin-top: 0.8rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.btn--more:hover {
  border-color: var(--border-strong);
  opacity: 1;
}

/* ============ 最近查询 ============ */
.history {
  margin-top: 1.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  animation: fadeUp 0.3s ease both;
}

.history__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.history__title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.btn-clear {
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-clear:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.history__item {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
  animation: fadeUp 0.25s ease both;
}

.history__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.history__main:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.history__num {
  font-weight: 600;
  font-size: 0.86rem;
  word-break: break-all;
}

.history__sub {
  font-size: 0.73rem;
  color: var(--faint);
}

.history__del {
  flex: 0 0 auto;
  width: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--faint);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.history__del:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ============ 反馈 ============ */
.feedback {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: fadeUp 0.25s ease both;
}

/* 出错:反色,黑白灰下最醒目 */
.feedback.is-error {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.feedback__icon {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============ 通用动画 ============ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ============ 响应式 ============ */
@media (max-width: 620px) {
  body { padding: 1rem 0.7rem 2rem; }
  .app { padding: 1.25rem; }

  .search { grid-template-columns: 1fr 1fr; }
  .search__field { grid-column: 1 / -1; }
  .btn--search { grid-column: 1 / -1; }
  .search__phone:not([hidden]) { grid-column: 1 / -1; }

  .status-card { flex-wrap: wrap; }
  .copy { align-self: center; }

  .empty-state { padding-top: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
