/* =========================================================================
   Shopify Boutique Mini App — style.css
   菜单/列表/按钮 UI (非聊天)。完全跟随 Telegram themeParams (var(--tg-theme-*)),
   不自带切换器。金额是中性展示色; 状态徽章用语义色 (绿=已出单/Créée, 灰=待办/Annulée)。
   ========================================================================= */

:root {
  /* Telegram 注入 --tg-theme-* CSS 变量; 这里给安全 fallback (浅色) */
  --bg:            var(--tg-theme-bg-color, #ffffff);
  --secondary-bg:  var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text:          var(--tg-theme-text-color, #1c1c1e);
  --hint:          var(--tg-theme-hint-color, #8e8e93);
  --link:          var(--tg-theme-link-color, #2481cc);
  --button:        var(--tg-theme-button-color, #2481cc);
  --button-text:   var(--tg-theme-button-text-color, #ffffff);
  --header-bg:     var(--tg-theme-header-bg-color, var(--secondary-bg));
  --section-bg:    var(--tg-theme-section-bg-color, var(--bg));

  /* 语义色 — Telegram 无, 自定义; 暗色下由 [data-scheme] 调亮度 */
  --ok:    #1f9d55;   /* 成功 / 已出单 / Créée */
  --warn:  #d6932c;   /* 提示 / 待处理 */
  --neg:   #d64545;   /* 失败 / 错误 */

  --radius: 14px;
  --gap: 10px;
}

/* 暗色方案下提高语义色亮度 (保证可读对比) */
[data-scheme="dark"] {
  --ok:   #4ad07d;
  --warn: #f0b65a;
  --neg:  #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── 顶栏 ── */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--header-bg);
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 22%, transparent);
}
.topbar-title {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 16px;
  min-width: 0;
}
.topbar-title > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-icon { font-size: 18px; }

.icon-btn {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--link);
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
}
.icon-btn:active { opacity: 0.55; }
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 视图容器 ── */
.view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.view.hidden { display: none !important; }

/* ── 工具栏 (列表过滤) ── */
.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--header-bg);
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 16%, transparent);
}
.filter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--hint);
}
.filter select {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--hint) 30%, transparent);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  padding: 6px 28px 6px 12px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'><path fill='%238e8e93' d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

/* ── 订单列表 ── */
.orders {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--hint) 12%, transparent);
}
.order-card:active { opacity: 0.7; }
.order-card .row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.order-card .order-name {
  font-weight: 700;
  font-size: 15.5px;
}
.order-card .customer {
  color: var(--hint);
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
  text-align: right;
}
.order-card .row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--hint);
}
.order-card .amount {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.order-card .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

/* ── 状态徽章 ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.ok    { background: color-mix(in srgb, var(--ok)   16%, transparent); color: var(--ok); }
.badge.warn  { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.muted { background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--hint); }
.badge.neg   { background: color-mix(in srgb, var(--neg)  16%, transparent); color: var(--neg); }

/* ── 详情 ── */
.detail {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.detail-section {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--hint) 10%, transparent);
}
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--hint);
}
.kv {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  font-size: 14px;
}
.kv .k { color: var(--hint); flex: 0 0 auto; }
.kv .v {
  text-align: right;
  overflow-wrap: anywhere;
  font-weight: 500;
}
.addr-block {
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-line;
  color: var(--text);
}
.alert-banner {
  margin-bottom: 6px;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  color: var(--ok);
}

/* ── 商品明细表 (横向滚动) ── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 9px;
  border: 1px solid color-mix(in srgb, var(--hint) 18%, transparent);
}
table.items {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
  font-size: 13px;
}
table.items thead th {
  background: color-mix(in srgb, var(--hint) 10%, transparent);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}
table.items th, table.items td {
  padding: 7px 11px;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 14%, transparent);
  white-space: nowrap;
  vertical-align: top;
}
table.items td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.items tbody tr:last-child td { border-bottom: none; }

/* ── 发票路由块 ── */
.route-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.route-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: color-mix(in srgb, var(--link) 16%, transparent);
  color: var(--link);
}
.route-pill.review { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.classif {
  font-size: 13px;
  color: var(--hint);
  margin-top: 4px;
}

/* ── 托运单历史清单 ── */
.label-item {
  padding: 9px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 14%, transparent);
}
.label-item:last-child { border-bottom: none; }
.label-item .li-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.label-item .parcel { font-weight: 600; font-size: 14px; }
.label-item .li-meta { font-size: 12.5px; color: var(--hint); margin-top: 2px; }
.label-item .li-links { display: flex; gap: 14px; margin-top: 6px; }
.label-item .li-links a { color: var(--link); text-decoration: none; font-size: 13px; font-weight: 600; }
.empty-line { color: var(--hint); font-size: 13.5px; padding: 4px 0; }

/* ── 底部动作按钮 ── */
.actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--header-bg);
  border-top: 1px solid color-mix(in srgb, var(--hint) 22%, transparent);
}
.btn {
  flex: 1 1 auto;
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-secondary {
  background: color-mix(in srgb, var(--button) 14%, transparent);
  color: var(--link);
}
.btn-danger { background: var(--neg); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--hint);
  border: 1px solid color-mix(in srgb, var(--hint) 30%, transparent);
}

/* ── 加载 / 空 / 错误态 ── */
.state {
  margin: auto;
  text-align: center;
  color: var(--hint);
  max-width: 320px;
  padding: 40px 16px;
}
.state h2 { color: var(--text); font-size: 16px; margin: 0 0 6px; }
.state p { margin: 4px 0 14px; font-size: 14px; }
.spinner {
  width: 28px; height: 28px;
  margin: 0 auto 14px;
  border: 3px solid color-mix(in srgb, var(--hint) 30%, transparent);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.skeleton {
  height: 78px;
  border-radius: var(--radius);
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--hint) 8%, transparent) 25%,
    color-mix(in srgb, var(--hint) 16%, transparent) 50%,
    color-mix(in srgb, var(--hint) 8%, transparent) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── 错误/状态横幅 ── */
.banner {
  flex: 0 0 auto;
  margin: 8px 12px 0;
  padding: 9px 13px;
  border-radius: 10px;
  font-size: 13.5px;
  background: color-mix(in srgb, var(--neg) 16%, var(--bg));
  color: var(--neg);
  border: 1px solid color-mix(in srgb, var(--neg) 35%, transparent);
}
.banner.info {
  background: color-mix(in srgb, var(--link) 14%, var(--bg));
  color: var(--link);
  border-color: color-mix(in srgb, var(--link) 35%, transparent);
}
.hidden { display: none !important; }

/* ── 模态对话框 ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  animation: slideup 0.18s ease-out;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
}
.modal-body {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.5;
}
.modal-body .route-pill { margin: 4px 0; }
.modal-body .classif { margin-top: 8px; }
.modal-body .muted { color: var(--hint); font-size: 13px; }
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-actions .btn { width: 100%; }

/* ── Toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: 90%;
  padding: 11px 18px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.toast.ok  { background: var(--ok); color: #fff; }
.toast.neg { background: var(--neg); color: #fff; }
