/*
 * 通用工作台 · 数据库页手动排版样式（T49）
 * =================================================
 * 只作用于「数据库」页（#t30Root / #page-products）与 .t49-* 元素。
 * 无草稿且不在编辑态时不改变原有视觉：.t49-grid 仅在有布局时存在。
 * 颜色全部沿用工作台主题变量，不新增配色体系。
 */

/* ---------------- 工具栏 ---------------- */

.t49-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  min-width: 0;
}

.t49-toolbar-title {
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--text-2);
}

.t49-toolbar-state {
  font-size: 12px;
  color: var(--text-2);
  overflow-wrap: anywhere;
  min-width: 0;
}

.t49-toolbar-state[data-kind="ok"] { color: var(--success, var(--text-2)); }
.t49-toolbar-state[data-kind="dirty"] { color: var(--accent); }
.t49-toolbar-state[data-kind="warn"] { color: var(--warning, var(--accent)); }
.t49-toolbar-state[data-kind="error"] { color: var(--danger); }

.t49-toolbar-spacer { flex: 1 1 auto; }

.t49-toolbar [hidden] { display: none !important; }

.t49-btn {
  min-height: 32px;
  height: auto;
  padding: 4px 12px;
  font-size: 12px;
  line-height: 1.6;
}

.t49-btn:focus-visible,
.t49-block-handle:focus-visible,
.t49-card-grip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------- 12 列网格 ---------------- */

.t49-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  min-width: 0;
}

.t49-block {
  position: relative;
  min-width: 0;
}

/* 网格 gap 负责间距，块内元素原来的外边距归零，避免双重间距。 */
.t49-block > .t49-block-body > * {
  margin-top: 0;
  margin-bottom: 0;
}

.t49-block[hidden] { display: none !important; }

/* ---------------- 编辑态 ---------------- */

.t49-block-bar { display: none; }

#t30Root[data-t49-edit="on"] .t49-block-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 6px;
  min-width: 0;
}

#t30Root[data-t49-edit="on"] .t49-block {
  outline: 1px dashed var(--border);
  outline-offset: 3px;
  border-radius: 10px;
}

#t30Root[data-t49-edit="on"] .t49-block:hover {
  outline-color: var(--accent);
}

.t49-block-handle {
  min-height: 28px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-hover, var(--bg-elev));
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
  cursor: grab;
  touch-action: none;
}

.t49-block-handle:active { cursor: grabbing; }

.t49-size {
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* 右边缘加宽、底边加高：只在编辑态显示，不遮挡内容。 */
.t49-grip { position: absolute; display: none; z-index: 4; }

#t30Root[data-t49-edit="on"] .t49-grip { display: block; }

.t49-grip-w {
  top: 0;
  bottom: 0;
  right: -5px;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
}

.t49-grip-w::after {
  content: '';
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 4px;
  border-radius: 2px;
  background: var(--accent);
  opacity: .28;
}

.t49-grip-h {
  left: 0;
  right: 0;
  bottom: -5px;
  height: 10px;
  cursor: row-resize;
  touch-action: none;
}

.t49-grip-h::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  top: 3px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  opacity: .28;
}

.t49-grip-w:hover::after,
.t49-grip-h:hover::after { opacity: .6; }

/* 拖动插入位置提示 */
.t49-drop-before { box-shadow: 0 -3px 0 0 var(--accent); }
.t49-drop-after { box-shadow: 0 3px 0 0 var(--accent); }
.t49-dragging-source { opacity: .55; }

body.t49-dragging {
  user-select: none;
  cursor: grabbing;
}

/* ---------------- 统计卡片 ---------------- */

article.t49-card-editable { position: relative; }

.t49-card-grip {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-hover, var(--bg-elev));
  color: var(--text-2);
  font-size: 11px;
  line-height: 1;
  cursor: grab;
  z-index: 4;
  touch-action: none;
}

.t49-card-grip:active { cursor: grabbing; }
.t49-card-grip:hover { border-color: var(--accent); color: var(--text); }

.t49-card-grip-w {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -5px;
  width: 10px;
  cursor: col-resize;
  z-index: 4;
  touch-action: none;
}

.t49-card-grip-h {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 10px;
  cursor: row-resize;
  z-index: 4;
  touch-action: none;
}

.t49-card-grip-w::after,
.t49-card-grip-h::after {
  content: '';
  position: absolute;
  background: var(--accent);
  opacity: .26;
  border-radius: 2px;
}

.t49-card-grip-w::after {
  top: 6px;
  bottom: 6px;
  left: 3px;
  width: 4px;
}

.t49-card-grip-h::after {
  left: 6px;
  right: 6px;
  top: 3px;
  height: 4px;
}

/* ---------------- 窄屏 ---------------- */

#t30Root[data-t49-narrow="on"] .t49-grip,
#t30Root[data-t49-narrow="on"] .t49-card-grip-w,
#t30Root[data-t49-narrow="on"] .t49-card-grip-h { display: none; }

@media (max-width: 760px) {
  .t49-toolbar { padding: 8px 10px; gap: 6px; }
  .t49-btn { min-height: 36px; padding: 4px 10px; }
  .t49-grid { gap: 12px; }
  .t49-block-handle { min-height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .t49-grid, .t49-block, .t49-card-grip { transition: none !important; }
}

/* T49 v2: measured free positions; content keeps its natural height. */
[data-t49-free] { display: block !important; position: relative; min-width: 0; }
[data-t49-free] > .t49-block,
[data-t49-free] > article.t30-card { box-sizing: border-box; margin: 0; }
.t49-placeholder { position: absolute; box-sizing: border-box; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; z-index: 8; pointer-events: none; }

/* T68: inline layout settings, preserving original toolbar state/actions. */
#t30Root .t68-layout-menu{position:relative;z-index:20;flex-shrink:0;margin-top:2px}
#t30Root .t68-layout-toggle{list-style:none;display:flex;align-items:center;justify-content:center;width:36px;height:36px;border:1px solid var(--border);border-radius:7px;background:var(--bg-elev);color:var(--text-2);cursor:pointer}
#t30Root .t68-layout-toggle::-webkit-details-marker{display:none}
#t30Root .t68-layout-toggle:hover{background:var(--accent-soft,var(--bg-hover));color:var(--text)}
#t30Root .t68-layout-toggle:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
#t30Root .t68-layout-menu .t49-toolbar{position:absolute;right:0;top:44px;width:286px;max-width:calc(100vw - 28px);display:flex;flex-direction:column;align-items:stretch;gap:8px;padding:14px;margin:0;border:1px solid var(--border);border-radius:9px;background:var(--bg-elev);box-shadow:0 8px 24px #0002}
#t30Root .t68-layout-menu .t49-toolbar-title{font-size:14px;font-weight:600;letter-spacing:0}
#t30Root .t68-layout-menu .t49-toolbar-state{margin-bottom:4px}
#t30Root .t68-layout-menu .t49-toolbar-spacer{display:none}
