:root {
  --bg: #f6f7fb;
  --card-bg: #ffffff;
  --text: #0f172a;
  --muted: #8b7364;
  --primary: #e3610a;
  --primary-weak: #e8f0ff;
  --border: #e5e7eb;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft Yahei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.app {
  max-width: 1080px;
  margin: 0 auto;
}

.header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(to bottom, var(--bg) 70%, rgba(246, 247, 251, 0));
  padding: 16px 0 8px;
  backdrop-filter: saturate(1.2) blur(2px);
}

h2 {
  margin: 0 0 12px;
  font-size: clamp(20px, 3.4vw, 28px);
  letter-spacing: 0.4px;
}

.search {
  position: relative;
}

.search input {
  width: 100%;
  padding: 14px 44px 14px 44px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
  appearance: none;
  -webkit-appearance: none;
}

.search input::placeholder {
  color: #94a3b8;
}

.search input:focus {
  border-color: var(--primary);
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.12);
}

.search .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: #94a3b8;
  pointer-events: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  padding: 14px 0 24px;
}

.item {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.item:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  border-color: #dbe3ef;
}

.pos-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: linear-gradient(135deg, var(--primary), #f6673b);
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(235, 119, 37, 0.35);
  min-width: 56px;
  text-align: center;
}

.name {
  font-weight: 700;
  font-size: 18px;
  line-height: 1.3;
  padding-right: 80px;
  /* 避让角标 */
}

.meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  word-break: break-word;
}

.label {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--primary-weak);
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 8px 24px;
  font-size: 14px;
}

/* 关键词高亮 */
mark {
  background: #fde68a;
  /* amber-200 */
  color: #7c2d12;
  /* amber-900 */
  padding: 0 0px;
  border-radius: 3px;
}

.pos-badge mark {
  background: rgba(255, 255, 255, 0.92);
  color: #8a491e;
  /* blue-900 */
  border-radius: 4px;
  padding: 0 3px;
}

@media (hover: none) {
  .item:hover {
    transform: none;
  }
}

/* Cabinet (中药柜) 暂时隐藏*/
.cabinet-wrap {
  display: none;
  margin-top: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  overflow: auto;
}

.cabinet {
  display: grid;
  grid-template-columns: 44px repeat(11, minmax(82px, 1fr));
  gap: 8px;
  min-width: 900px;
  /* 允许窄屏横向滚动 */
}

.cabinet .head {
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  padding: 6px 4px;
}

.cabinet .row-head {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--muted);
}

.drawer {
  position: relative;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  padding: 6px;
}

.drawer .drawer-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 12px;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 2px 6px;
  border-radius: 6px;
}

.slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
}

.slot {
  position: relative;
  border: 1px dashed #dbe3ef;
  border-radius: 8px;
  padding: 6px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #1f2937;
  background: #f9fafb;
}

/* 槽位与编号的空间映射：1=左上，2=左下，3=右上，4=右下 */
.slots .slot:nth-child(1) {
  grid-column: 1;
  grid-row: 1;
}

.slots .slot:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}

.slots .slot:nth-child(3) {
  grid-column: 2;
  grid-row: 1;
}

.slots .slot:nth-child(4) {
  grid-column: 2;
  grid-row: 2;
}

.slot .slot-pos {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  color: #94a3b8;
}

.slot .slot-name {
  font-size: 13px;
  line-height: 1.2;
  word-break: break-word;
}

.slot-full {
  grid-column: 1 / span 2;
  grid-row: 1 / span 2;
  border-style: solid;
  background: #f8fafc;
}

.slot.matched {
  border-color: #f97103;
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(250, 155, 96, 0.3) inset;
}

.slot.dim {
  opacity: 0.45;
}