/* 管理端样式（桌面端） */
* {
  margin: 0; padding: 0; box-sizing: border-box;
}
:root {
  --bg: #fdf6e9;
  --card: #ffffff;
  --module: #fff4dc;
  --accent: #88c9a1;
  --accent-deep: #5fa37a;
  --pink-deep: #e88ba0;
  --text: #4a3f35;
  --text-light: #9a8b7a;
  --border: #ece1c8;
  --warn: #f4a261;
  --shadow: 0 4px 16px rgba(150, 120, 90, 0.12);
  --radius: 14px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.admin-app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 2px dashed var(--border);
  margin-bottom: 20px;
}
.admin-header h1 {
  font-size: 22px; color: var(--accent-deep); font-weight: 600;
}
.back-link {
  color: var(--accent-deep); text-decoration: none;
  font-size: 13px; padding: 6px 14px;
  border: 1px solid var(--accent); border-radius: 10px;
  transition: background 0.2s;
}
.back-link:hover { background: var(--accent); color: white; }

/* ============================================================
   v11.0：返回使用端 —— 常驻 tab 栏右端 + 每个面板内底部
   ============================================================ */
/* tab 栏内的返回链接：推到最右，与 tab 按钮同一行 */
.back-link--tab {
  margin-left: auto;
  align-self: center;
  white-space: nowrap;
}
/* 面板内底部返回链接 */
.panel-back {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
  text-align: right;
}
.panel-back .back-link {
  display: inline-block;
}

/* v6: 管理端 tab 切换 */
.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  padding-bottom: 0;
}
.admin-tab {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  position: relative;
  top: 1px;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.tab-panel.hidden { display: none; }
.tab-panel { animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

.toolbar {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 16px;
}
.add-btn {
  background: var(--accent); color: white; border: none;
  border-radius: 12px; padding: 10px 20px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(95, 163, 122, 0.3);
  transition: transform 0.15s, background 0.2s;
}
.add-btn:hover { background: var(--accent-deep); }
.add-btn:active { transform: scale(0.96); }
.hint {
  color: var(--text-light); font-size: 12px;
}

/* v7: 顶部分类管理条 */
.category-bar {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 8px;
  background: var(--card);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.cat-bar-label {
  font-size: 12px; color: var(--text-light); font-weight: 600;
  margin-right: 4px;
}
.cat-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  flex: 1;
}
.cat-chip {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--module);
  border-radius: 18px;
  padding: 3px 4px 3px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.cat-chip-name { margin-right: 4px; }
.cat-chip-btn {
  background: transparent;
  border: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-light);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.cat-chip-btn:hover:not(:disabled) {
  background: var(--accent);
  color: white;
}
.cat-chip-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.cat-chip-del:hover:not(:disabled) {
  background: var(--pink-deep);
  color: white;
}
.cat-add-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 18px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.cat-add-btn:hover { background: var(--accent-deep); }
.cat-hint { color: var(--text-light); font-size: 12px; font-style: italic; }

/* v7: 按分类分块 */
.cat-block {
  margin-bottom: 20px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cat-block-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  background: var(--module);
  border-bottom: 1px solid var(--border);
}
.cat-block-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-deep);
}
.cat-block-count {
  font-size: 11px;
  color: var(--text-light);
  background: var(--card);
  padding: 2px 8px;
  border-radius: 8px;
}
.cat-block-grid { padding: 0; }
.cat-block-grid .table-row {
  /* v10.2: 7 列对齐（原 6 列遗漏“计时”项目 · 补充“显示上次时间”列）*/
  grid-template-columns: 28px 50px 1fr 50px 90px 110px 70px;
}
.cat-block-grid .table-row-head {
  background: rgba(255, 244, 220, 0.4);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-light);
}
.cat-block-grid .row-actions {
  display: flex; gap: 4px;
  justify-content: flex-end;
}

/* v7: 分类编辑弹层 */
.cat-edit-overlay {
  position: fixed; inset: 0;
  background: rgba(74, 63, 53, 0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 1000;
}
.cat-edit-overlay.show { display: flex; }
.cat-edit-card {
  background: var(--card);
  border-radius: 16px;
  padding: 18px 22px;
  min-width: 280px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.cat-edit-card h3 {
  font-size: 15px;
  color: var(--accent-deep);
  margin-bottom: 12px;
}
.cat-edit-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 14px;
}
.cat-edit-cancel, .cat-edit-save,
.cat-new-cancel, .cat-new-save {
  border: none;
  border-radius: 10px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.cat-edit-cancel, .cat-new-cancel {
  background: var(--module); color: var(--text);
}
.cat-edit-save, .cat-new-save {
  background: var(--accent); color: white;
}
.cat-edit-save:hover, .cat-new-save:hover {
  background: var(--accent-deep);
}
.row-btn.move { background: var(--bg); color: var(--text); }
.row-btn.move:disabled { opacity: 0.3; cursor: not-allowed; }

/* 表格 */
.items-table {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-header, .table-row {
  display: grid;
  grid-template-columns: 28px 60px 1fr 120px 120px 160px 100px;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
}
.table-header {
  background: var(--module);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
}
.table-row {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.table-row:hover { background: var(--bg); }
.table-row:last-child { border-bottom: none; }

.row-icon { font-size: 26px; text-align: center; }
.row-name { font-weight: 600; font-size: 14px; }

/* v8: 轮值模式行内 badge */
.rotation-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  background: linear-gradient(135deg, #c084fc, #a855f7);
  color: white;
  border-radius: 10px;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
.row-category {
  display: inline-block;
  background: var(--module);
  padding: 2px 10px;
  border-radius: 8px;
  font-size: 12px;
}
.row-interval {
  font-size: 13px;
  color: var(--text);
}
.row-interval.none { color: var(--text-light); font-style: italic; }

.row-last-done {
  font-size: 12px; color: var(--text);
  background: var(--module);
  padding: 2px 8px;
  border-radius: 8px;
  display: inline-block;
}
.row-last-done.none {
  color: var(--text-light);
  font-style: italic;
  background: transparent;
}
.row-actions {
  display: flex; gap: 6px;
  justify-content: flex-end;
}
.row-btn {
  border: none;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.row-btn:hover { opacity: 0.8; }
.row-btn.edit {
  background: var(--accent); color: white;
}
.row-btn.delete {
  background: var(--pink-deep); color: white;
}

.loading {
  text-align: center; color: var(--text-light);
  padding: 30px; font-size: 13px;
}

/* ========= 拖拽手柄与拖拽状态 ========= */
.drag-handle {
  cursor: grab;
  user-select: none;
  color: var(--text-light);
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 4px 2px;
  transition: background 0.15s, color 0.15s;
}
.drag-handle:hover {
  background: var(--bg);
  color: var(--accent-deep);
}
.drag-handle:active { cursor: grabbing; }
.col-handle { display: inline-block; } /* 表头占位列 */

/* 表头手柄列不再重渲染于每一行；这里让 head 行的手柄列隐藏 */
.table-row-head .col-handle { visibility: hidden; }

/* 分类块头部可拖 */
.cat-block-header { cursor: grab; }
.cat-block-header:active { cursor: grabbing; }

/* 拖动中的鬼影（鼠标下随动的影子） */
.sortable-ghost {
  opacity: 0.4;
  background: var(--module) !important;
  border: 2px dashed var(--accent) !important;
}
/* 拖动中“鼠标抓住”的源行 */
.sortable-chosen {
  background: var(--bg);
}
/* 拖动中跟随鼠标的元素 */
.sortable-drag {
  opacity: 0.95;
  box-shadow: 0 8px 24px rgba(95, 163, 122, 0.25);
  background: var(--card);
  border-radius: 10px;
  cursor: grabbing;
}

/* 弹层 */
.edit-overlay, .del-overlay {
  position: fixed; inset: 0;
  background: rgba(74, 63, 53, 0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 1000;
}
.edit-overlay.show, .del-overlay.show { display: flex; }

.edit-card, .del-card {
  background: var(--card);
  border-radius: 20px;
  padding: 22px 26px;
  min-width: 360px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.edit-card h2 {
  font-size: 18px; color: var(--accent-deep);
  margin-bottom: 16px;
}
.field {
  display: block;
  margin-bottom: 14px;
}
.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 4px;
  font-weight: 500;
}
.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus { border-color: var(--accent); }

.icon-picker {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  padding: 8px;
  background: var(--module);
  border-radius: 10px;
  max-height: 160px;
  overflow-y: auto;
}
.icon-cell {
  font-size: 22px;
  text-align: center;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  background: white;
}
.icon-cell:hover { background: var(--bg); }
.icon-cell:active { transform: scale(0.9); }
.icon-cell.selected {
  background: var(--accent);
  transform: scale(1.1);
}

.quick-pick {
  display: flex; gap: 6px; margin-top: 6px;
  flex-wrap: wrap;
}
.quick-pick button {
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.quick-pick button:hover {
  background: var(--accent); color: white;
  border-color: var(--accent);
}
.quick-pick button.clear {
  border-color: var(--text-light);
  color: var(--text-light);
}

.field-hint {
  font-size: 11px; color: var(--text-light);
  margin-top: 4px; line-height: 1.5;
}

/* v8: 轮值开关（iOS 风滑动开关） */
.rotation-row {
  display: flex; align-items: center; gap: 12px;
}
.field-rotation { margin-top: 4px; }
.rotation-last-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--module);
  border-radius: 8px;
}
.rotation-last-row select {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
}
.switch {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0;
}
.switch input { display: none; }
.switch .slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.2s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .slider {
  background: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.edit-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 20px;
}
.edit-cancel, .edit-save {
  border: none; border-radius: 10px;
  padding: 8px 20px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.edit-cancel {
  background: var(--module); color: var(--text);
}
.edit-save {
  background: var(--accent); color: white;
}
.edit-save:hover { background: var(--accent-deep); }

/* 删除确认 */
.del-title { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.del-text {
  font-size: 13px; color: var(--text-light);
  margin-bottom: 16px; line-height: 1.5;
}
.del-actions {
  display: flex; gap: 8px; justify-content: center;
}
.del-cancel, .del-confirm {
  border: none; border-radius: 10px;
  padding: 7px 18px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.del-cancel { background: var(--module); color: var(--text); }
.del-confirm { background: var(--pink-deep); color: white; }

/* v9: 消耗品表格样式 */
.consumables-head {
  grid-template-columns: 28px 60px 1fr 160px 100px 1.5fr auto;
}
.row-price {
  font-size: 13px;
  color: var(--text);
}
.row-price.none {
  color: var(--text-light);
  font-style: italic;
}
.row-note {
  font-size: 12px;
  color: var(--text-light);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.row-note.none {
  font-style: italic;
}

/* 移动端适配 */
@media (max-width: 700px) {
  .admin-app { padding: 12px; }
  .admin-header h1 { font-size: 18px; }
  .table-header { display: none; }
  .table-row {
    grid-template-columns: 24px 50px 1fr auto;
    grid-template-areas:
      "handle icon name actions"
      "handle icon meta meta"
      "handle icon last last";
    padding: 10px 12px;
    gap: 8px;
  }
  .row-handle { grid-area: handle; font-size: 14px; }
  .row-icon { grid-area: icon; }
  .row-name { grid-area: name; }
  .row-actions { grid-area: actions; }
  .row-meta {
    grid-area: meta;
    display: flex; gap: 8px; font-size: 12px;
    color: var(--text-light);
  }
  .row-last-done-cell { grid-area: last; font-size: 12px; }
  .row-category { padding: 1px 8px; }
  .edit-card { min-width: 0; width: 90vw; }
  .icon-picker { grid-template-columns: repeat(8, 1fr); }
}