:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --text: #182230;
  --text-muted: #667085;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --amber-bg: #fff7ed;
  --amber-border: #fdba74;
  --amber-text: #c2410c;
  --blue-bg: #eff6ff;
  --blue-text: #1d4ed8;
  --teal-bg: #f0fdfa;
  --teal-text: #0f766e;
  --green-bg: #ecfdf3;
  --green-text: #027a48;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(16, 24, 40, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --surface: #18202c;
    --surface-2: #222c3c;
    --border: #2c384a;
    --text: #f2f4f7;
    --text-muted: #98a2b3;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --amber-bg: #2e1d10;
    --amber-border: #9a3412;
    --amber-text: #fdba74;
    --blue-bg: #172554;
    --blue-text: #93c5fd;
    --teal-bg: #134e4a;
    --teal-text: #5eead4;
    --green-bg: #064e3b;
    --green-text: #6ee7b7;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* 登录页 */
.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--blue-bg);
  color: var(--blue-text);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-desc {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 顶部栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.back-home-btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 26px;
  line-height: 1;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* 容器 */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* 统计卡 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.stat-card:hover {
  transform: translateY(-1px);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-num {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-arrived {
  background: var(--amber-bg);
  border-color: var(--amber-border);
}

.stat-arrived .stat-label,
.stat-arrived .stat-num {
  color: var(--amber-text);
}

.stat-delivering .stat-num {
  color: var(--blue-text);
}

.stat-transit .stat-num {
  color: var(--teal-text);
}

.stat-picked .stat-num {
  color: var(--green-text);
}

/* 工具条 */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

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

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.search-box {
  flex: 1 1 220px;
  max-width: 340px;
}

input[type="text"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-color: var(--primary);
}

.owner-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.chip-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.12s ease, background 0.12s ease;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

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

.btn-success {
  background: var(--green-bg);
  color: var(--green-text);
  border-color: color-mix(in srgb, var(--green-text) 25%, transparent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* 包裹卡片列表 */
.parcel-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.parcel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.parcel-card.status-arrived {
  border-color: var(--amber-border);
}

.parcel-card.status-picked_up {
  opacity: 0.72;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.tag-owner {
  background: var(--surface-2);
  color: var(--text);
}

.tag-platform {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.tag-status-arrived {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.tag-status-delivering {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.tag-status-in_transit {
  background: var(--teal-bg);
  color: var(--teal-text);
}

.tag-status-picked_up {
  background: var(--green-bg);
  color: var(--green-text);
}

.card-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* 取件码醒目区 */
.pickup-banner {
  background: var(--amber-bg);
  border: 1px dashed var(--amber-border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pickup-meta {
  min-width: 0;
}

.pickup-label {
  font-size: 12px;
  color: var(--amber-text);
  font-weight: 600;
}

.pickup-code {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--amber-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  word-break: break-all;
}

.pickup-station {
  font-size: 13px;
  color: var(--text);
  margin-top: 2px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.card-meta-line {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tracking-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text);
}

.card-summary {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 8px 10px;
  border-radius: 10px;
  word-break: break-word;
}

.card-actions {
  margin-top: auto;
  padding-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 17px;
}

.empty-state p {
  margin: 0 auto 18px;
  max-width: 420px;
  font-size: 14px;
  color: var(--text-muted);
}

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

/* 弹窗 */
dialog.modal {
  padding: 0;
  border: none;
  border-radius: 18px;
  background: transparent;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  color: var(--text);
}

dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
  overflow: hidden;
}

.modal-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.icon-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

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

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-footer-split {
  justify-content: space-between;
}

.modal-footer-right {
  display: flex;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.field-full {
  grid-column: 1 / -1;
}

.manual-more summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}

.info-box {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 14px;
}

.info-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-row code {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
  white-space: nowrap;
}

.info-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.sample-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.test-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.test-result {
  font-size: 13px;
  color: var(--green-text);
  font-weight: 600;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #182230;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 100;
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .field-grid {
    grid-template-columns: 1fr;
  }
  .brand-sub {
    display: none;
  }
  .parcel-list {
    grid-template-columns: 1fr;
  }
}
