:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --ok: #10b981;
  --warn: #f59e0b;
  --soon: #f97316;
  --urgent: #ef4444;
  --expired: #94a3b8;
  --used: #cbd5e1;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --tap: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

/* ---------------- 顶栏 ---------------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: 54px; padding: 0 12px;
  background: #0f172a; color: #fff;
  box-shadow: 0 1px 6px rgba(15, 23, 42, .18);
}
#topbar h1 { flex: 1; font-size: 17px; font-weight: 600; margin: 0; }
.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.12); color: #fff;
  font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.24); }

.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: rgba(255,255,255,.14); color: #e2e8f0; white-space: nowrap;
}
.badge.ok      { background: rgba(16,185,129,.22); color: #6ee7b7; }
.badge.offline { background: rgba(245,158,11,.22); color: #fcd34d; }
.badge.error   { background: rgba(239,68,68,.25);  color: #fca5a5; }

/* ---------------- 主区 ---------------- */
#view { padding: 12px; max-width: 900px; margin: 0 auto; }

.section-title {
  display: flex; align-items: baseline; gap: 8px;
  margin: 18px 4px 8px; font-size: 13px; font-weight: 700;
  color: var(--muted); letter-spacing: .04em;
}
.section-title:first-child { margin-top: 4px; }
.section-title .count { font-weight: 500; color: var(--muted); }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px;
}
.card.tappable { cursor: pointer; }
.card.tappable:active { transform: scale(.995); }

.empty {
  text-align: center; color: var(--muted); padding: 44px 20px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* ---------------- 位置看板 ---------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 14px; cursor: pointer; position: relative; overflow: hidden;
  border-left: 4px solid var(--line);
}
.tile:active { transform: scale(.98); }
.tile .t-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.tile .t-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.tile .t-flags { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 5px; }
.tile.lv0 { border-left-color: var(--line); }

.pill {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: #f1f5f9; color: var(--muted); font-weight: 600;
}
.pill.urgent  { background: #fee2e2; color: #b91c1c; }
.pill.soon    { background: #ffedd5; color: #c2410c; }
.pill.warn    { background: #fef3c7; color: #b45309; }
.pill.expired { background: #e2e8f0; color: #475569; }
.pill.ok      { background: #d1fae5; color: #047857; }

/* ---------------- 批次行 ---------------- */
.batch {
  display: flex; align-items: center; gap: 11px;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px 12px; margin-bottom: 8px;
}
.batch .thumb {
  width: 52px; height: 52px; border-radius: 11px; flex: none;
  background: #f8fafc center/contain no-repeat; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; overflow: hidden;
}
.batch .thumb img { width: 100%; height: 100%; object-fit: contain; }
.batch .mid { flex: 1; min-width: 0; }
.batch .b-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.batch .b-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.batch .right { text-align: right; flex: none; }
.batch .days { font-size: 19px; font-weight: 700; line-height: 1.1; }
.batch .days small { font-size: 11px; font-weight: 600; }
.batch .qty { font-size: 12px; color: var(--muted); margin-top: 2px; }

.d-ok      { color: var(--ok); }
.d-warn    { color: var(--warn); }
.d-soon    { color: var(--soon); }
.d-urgent  { color: var(--urgent); }
.d-expired { color: var(--expired); }
.batch.is-expired { background: #f8fafc; }
.batch.is-done { opacity: .55; }

/* ---------------- 按钮 ---------------- */
button { font: inherit; }

.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  font-weight: 600; cursor: pointer;
}
.btn:active { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger  { background: #fff; border-color: #fecaca; color: #b91c1c; }
.btn.ghost   { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm      { min-height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 9px; }
.btn.block   { width: 100%; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: #fff; color: var(--text); font: inherit;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,.14);
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-height: 38px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  font-weight: 600; font-size: 13.5px; cursor: pointer;
}
.seg button.on { background: #e0f2fe; border-color: var(--primary); color: var(--primary-dark); }

.photo-box {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius); background: #fff;
}
.photo-preview {
  width: 84px; height: 84px; border-radius: 12px; flex: none;
  background: repeating-conic-gradient(#f1f5f9 0% 25%, #fff 0% 50%) 50% / 16px 16px;
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-size: 28px; overflow: hidden;
}
.photo-preview img { width: 100%; height: 100%; object-fit: contain; }

/* ---------------- 分类 / 位置的图标 ----------------
   三档尺寸是定死的，不要随手改：列表 36、卡片 44、编辑预览 120。
   没有图片时显示原来的 emoji，不留空白框。 */
.icbox {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; overflow: hidden;
  background: #f8fafc; border: 1px solid var(--line);
}
.icbox img { width: 100%; height: 100%; object-fit: contain; }
.icbox.ic36 { width: 36px; height: 36px; font-size: 20px; }
.icbox.ic44 { width: 44px; height: 44px; font-size: 24px; }
.icbox.ic120 { width: 120px; height: 120px; border-radius: 14px; font-size: 54px; }
/* emoji 不套壳 —— 它自己就有留白，再套个方框会显得没对齐 */
.icbox.plain { background: transparent; border-color: transparent; }

.section-title .icbox { align-self: center; }
.tile .t-name .icbox { margin-right: 2px; }

.iconrow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.iconrow:last-of-type { border-bottom: 0; }
.iconrow .iconrow-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card > .iconedit { display: none; }
.card > .iconedit.open {
  display: flex; align-items: center; gap: 14px;
  margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--line);
}

/* ---------------- 版本提示条 ---------------- */
#updatebar {
  position: sticky; top: 54px; z-index: 19;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #e0f2fe; color: #075985;
  border-bottom: 1px solid #bae6fd; font-size: 13.5px;
}
#updatebar[hidden] { display: none; }
#updatebar .ub-text { flex: 1; min-width: 0; }
#updatebar .btn { background: var(--primary); border-color: var(--primary); color: #fff; flex: none; }
#updatebar .ub-close {
  flex: none; border: 0; background: transparent; color: #075985;
  font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 6px;
}

/* ---------------- 会话日志 ---------------- */
.logview {
  max-height: 260px; overflow: auto; margin: 10px 0 0;
  padding: 10px 12px; border-radius: 11px; background: #0f172a; color: #cbd5e1;
  font: 12px/1.5 ui-monospace, Consolas, "Courier New", monospace;
  white-space: pre-wrap; word-break: break-all;
}

/* ---------------- 底栏 ---------------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(58px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11px; color: var(--muted); padding: 6px 0;
}
.tab span { font-size: 19px; line-height: 1; }
.tab.on { color: var(--primary); font-weight: 700; }
.tab-add {
  flex: none; width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 30px;
  margin-top: -22px; box-shadow: 0 6px 16px rgba(14,165,233,.42);
  justify-content: center;
}
.tab-add span { font-size: 30px; }

/* ---------------- 提示 ---------------- */
#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  max-width: 88vw; text-align: center; z-index: 40;
}
#toast.show { opacity: .95; transform: translateX(-50%) translateY(0); }

.banner {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px; border-radius: 11px; font-size: 13px; margin-bottom: 10px;
}
.banner.offline { background: #fef3c7; color: #92400e; }
.banner.error   { background: #fee2e2; color: #991b1b; }

.spinner { text-align: center; padding: 40px; color: var(--muted); }

.thumb-lg {
  width: 100%; max-height: 230px; object-fit: contain;
  background: repeating-conic-gradient(#f1f5f9 0% 25%, #fff 0% 50%) 50% / 18px 18px;
  border-radius: var(--radius); border: 1px solid var(--line);
}

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); flex: none; }
.kv .v { text-align: right; word-break: break-all; }

/* 提醒条里的按钮不许被文字挤扁；地址这种东西要能整段换行 */
.banner > .btn { flex: none; }
.mono { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 12.5px; word-break: break-all; }

@media (min-width: 700px) {
  #view { padding: 18px; }
  .tab { font-size: 12px; }
}
