:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --panel-soft: #f7f8fa;
  --text: #1d2129;
  --text-2: #4e5969;
  --muted: #86909c;
  --line: #e5e6eb;
  --brand: #2a7cf0;
  --brand-soft: #e8f1fe;
  --danger: #f53f3f;
  --ok: #00b42a;
  --radius: 10px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #232427;
    --panel-soft: #2a2b2f;
    --text: #e8e8ea;
    --text-2: #c0c3c9;
    --muted: #8b8f97;
    --line: #34363b;
    --brand: #4c9bff;
    --brand-soft: #1e2c44;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.6 -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--panel);
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

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

.logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  flex: 0 0 auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 13px;
}

.brand-text span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 4px;
  vertical-align: 1px;
}

.status-dot.live {
  background: var(--ok);
}

.status-dot.demo {
  background: #ff9a00;
}

.status-dot.err {
  background: var(--danger);
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 14px;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: var(--panel-soft);
}

/* ---------- 搜索 ---------- */
.searchbar {
  position: relative;
  padding: 8px 12px 4px;
  flex: 0 0 auto;
}

.searchbar input {
  width: 100%;
  height: 30px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.searchbar input:focus {
  border-color: var(--brand);
  background: var(--panel);
}

.searchbar .icon-btn {
  position: absolute;
  right: 14px;
  top: 9px;
  width: 24px;
  height: 24px;
  font-size: 11px;
}

/* ---------- 分组折叠列表（千牛式：竖排分组，逐组展开） ---------- */
.list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 12px 12px;
}

.sect {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 8px;
  overflow: hidden;
}

.sect-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  cursor: pointer;
  user-select: none;
  background: var(--panel-soft);
}

.sect-head:hover .sect-name {
  color: var(--brand);
}

.sect-name {
  font-size: 12.5px;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sect-count {
  font-size: 11px;
  color: var(--muted);
  flex: 0 0 auto;
}

.sect-arrow {
  font-size: 9px;
  color: var(--muted);
  transition: transform 0.15s;
  flex: 0 0 auto;
}

.sect.open .sect-arrow {
  transform: rotate(180deg);
}

.sect-body {
  padding: 0 0 2px;
}

/* ---------- 话术行：短标签 + 内容预览 ---------- */
.row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 10px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}

.row:hover,
.row:focus {
  background: var(--panel-soft);
  outline: none;
}

.row:first-child {
  border-top: none;
}

.row-label {
  flex: 0 0 76px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-label .star {
  color: #ff9a00;
  margin-right: 2px;
}

.row-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.row-shots {
  display: flex;
  gap: 3px;
  flex: 0 0 auto;
  align-items: center;
}

.row-shots img {
  width: 30px;
  height: 30px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  cursor: zoom-in;
}

.row-more {
  font-size: 10px;
  color: var(--muted);
}

/* 行内操作：悬停浮现，触屏常显 */
.row-ops {
  position: absolute;
  right: 6px;
  top: 5px;
  display: flex;
  gap: 1px;
  padding: 1px 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  opacity: 0;
  transition: opacity 0.12s;
}

.row:hover .row-ops,
.row:focus-within .row-ops {
  opacity: 1;
}

@media (hover: none) {
  .row-ops {
    opacity: 1;
  }
}

.mini-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 5px;
}

.mini-btn:hover {
  background: var(--panel-soft);
  color: var(--brand);
}

.mini-btn.danger:hover {
  color: var(--danger);
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 40px 12px;
}

/* ---------- 底栏 ---------- */
.bottombar {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.primary {
  flex: 1 1 auto;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
}

.primary:hover {
  filter: brightness(1.06);
}

.ghost {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text-2);
  font-size: 12px;
}

.ghost:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.sheet {
  width: 100%;
  max-width: 360px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.sheet h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.field input[type='text'],
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 7px 9px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  background: var(--panel);
}

.field textarea {
  min-height: 96px;
  line-height: 1.6;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.var-hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ---------- 图片编辑区 ---------- */
.shots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  gap: 6px;
  margin-bottom: 6px;
}

.shots[hidden] {
  display: none;
}

.shot {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  cursor: grab;
}

.shot.dragging {
  opacity: 0.4;
}

.shot.drop-target {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft);
}

.shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.shot .shot-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 17px;
  height: 17px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}

.shot .shot-del:hover {
  background: var(--danger);
}

.shot-badge {
  position: absolute;
  left: 2px;
  bottom: 2px;
  max-width: calc(100% - 4px);
  font-size: 9px;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 0 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shot-drop {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
  text-align: left;
}

.shot-drop:hover,
.shot-drop.hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.shot-plus {
  font-size: 18px;
  line-height: 1;
}

.shot-hint {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 4px;
}

.shot-hint.busy {
  color: var(--brand);
}

.var-shots {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.var-shots[hidden] {
  display: none;
}

.var-shots img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

/* 图片灯箱 */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: grid;
  place-items: center;
  z-index: 120;
  padding: 20px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 8px;
}

.preview-box {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 8px;
  z-index: 99;
  max-width: 88%;
  text-align: center;
}

.toast[hidden] {
  display: none;
}

.mode-banner {
  margin: 0 12px 8px;
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11.5px;
  line-height: 1.5;
}

.mode-banner[hidden] {
  display: none;
}
