.te-root {
  --te-accent: #B45309;
  --te-accent-soft: rgba(180, 83, 9, .14);
  --te-bg: #111827;
  --te-panel: #FFFFFF;
  --te-panel-muted: #F6F7F9;
  --te-line: #D9DCE2;
  --te-ink: #1F2937;
  --te-muted: #6B7280;
  --te-danger: #DC2626;
  --te-ok: #16845B;
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  color: var(--te-ink);
  background: var(--te-bg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

.te-root, .te-root * { box-sizing: border-box; }
body { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
.te-root button, .te-root input, .te-root select, .te-root textarea { font: inherit; }
.te-root button { color: inherit; }
.te-root button:focus-visible, .te-root input:focus-visible,
.te-root select:focus-visible, .te-root textarea:focus-visible {
  outline: 3px solid #60A5FA;
  outline-offset: 2px;
}

.te-topbar {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 7px 10px;
  color: #F9FAFB;
  background: #202936;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.te-topbar-group { display: flex; align-items: center; gap: 5px; }
.te-spacer { flex: 1; min-width: 8px; }
.te-title-input {
  width: min(260px, 24vw);
  min-width: 120px;
  height: 44px;
  padding: 0 10px;
  color: #FFFFFF;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
}

.te-btn, .te-icon-btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.te-btn { padding: 0 12px; }
.te-icon-btn { width: 44px; padding: 0; flex: none; }
.te-icon-btn > span { display: none; }
.te-btn svg, .te-icon-btn svg { width: 17px; height: 17px; flex: none; }
.te-btn:hover, .te-icon-btn:hover { background: rgba(255,255,255,.1); }
.te-btn:disabled, .te-icon-btn:disabled { opacity: .38; cursor: default; }
.te-btn.te-primary { color: #FFFFFF; background: var(--te-accent); }
.te-btn.te-primary:hover { background: #92400E; }
.te-btn.te-light { color: var(--te-ink); background: #FFFFFF; border-color: var(--te-line); }
.te-btn.te-danger { color: var(--te-danger); background: #FEF2F2; border-color: #FECACA; }
.te-btn.te-on, .te-icon-btn.te-on { color: #FED7AA; background: rgba(180, 83, 9, .34); }
.te-top-label { display:flex; align-items:center; gap:5px; font-size:12px; color:#D1D5DB; }
.te-top-label input { width: 16px; height: 16px; accent-color: var(--te-accent); }

.te-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 62px minmax(260px, 1fr) 330px;
}

.te-toolbar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 8px 6px;
  color: #E5E7EB;
  background: #1A2230;
  border-right: 1px solid rgba(255,255,255,.08);
  overflow-y: auto;
}
.te-tool {
  min-height: 50px;
  padding: 5px 2px;
  border: 0;
  border-radius: 9px;
  color: #D1D5DB;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-size: 10px;
  line-height: 1.15;
}
.te-tool svg { width: 20px; height: 20px; }
.te-tool:hover, .te-tool.te-on { color: #FFFFFF; background: rgba(255,255,255,.10); }
.te-tool.te-on { box-shadow: inset 3px 0 var(--te-accent); }
.te-tool-divider { height: 1px; margin: 4px 2px; background: rgba(255,255,255,.1); }

.te-workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: #161E2A;
  background-image: radial-gradient(rgba(255,255,255,.08) 1px, transparent 1px);
  background-size: 18px 18px;
}
.te-workspace.te-panning { cursor: grabbing; }
.te-stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.te-card-product-pane { display:flex; flex-direction:column; gap:8px; width:220px; min-width:180px; padding:12px; background:#f8fafc; border-right:1px solid #e5e7eb; }
.te-card-product-title { font-weight:700; font-size:13px; }
.te-card-product-view { flex:1; display:flex; align-items:center; justify-content:center; background:#fff; border:1px solid #e5e7eb; border-radius:10px; overflow:hidden; }
.te-card-product-view img { display:block; width:auto; height:auto; max-width:100%; max-height:100%; object-fit:contain; }
.te-card-product-hint { color:#6b7280; font-size:11px; line-height:1.45; }
.te-workspace.te-dual-mode { display:grid; grid-template-columns:minmax(220px, .8fr) minmax(0, 1.2fr); grid-template-rows:minmax(0,1fr) auto auto; }
.te-dual-mode .te-card-product-pane { grid-column:1; grid-row:1 / 4; width:auto; min-width:0; height:100%; box-sizing:border-box; }
.te-dual-mode .te-warning, .te-dual-mode .te-stage, .te-dual-mode .te-zoom, .te-dual-mode .te-statusbar { grid-column:2; }
.te-dual-mode .te-warning { grid-row:1; z-index:3; }
.te-dual-mode .te-stage { grid-row:1; position:relative; left:auto; top:auto; min-width:0; min-height:0; overflow:visible; display:flex; align-items:center; justify-content:center; }
.te-dual-mode .te-zoom { grid-row:2; }
.te-dual-mode .te-statusbar { grid-row:3; }
.te-canvas {
  position: relative;
  overflow: hidden;
  background: #FFFFFF;
  box-shadow: 0 18px 55px rgba(0,0,0,.42);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.te-canvas.te-grid {
  background-image:
    linear-gradient(rgba(37,99,235,.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37,99,235,.13) 1px, transparent 1px);
  background-size: 5% 5%;
}
.te-canvas img { -webkit-user-drag: none; user-select: none; }

.te-element {
  position: absolute;
  transform-origin: center center;
  touch-action: none;
}
.te-element[data-hidden="true"] { display: none; }
.te-element.te-background, .te-element.te-foreground { inset: 0; }
.te-element.te-background, .te-element.te-foreground { pointer-events: none; }
.te-element.te-background img, .te-element.te-foreground img { width: 100%; height: 100%; display: block; object-fit: fill; pointer-events: none; }
.te-element.te-image img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: none; }
.te-element.te-filter {
  border-radius: 2px;
  pointer-events: auto !important;
  cursor: move;
  isolation: isolate;
  overflow: hidden;
  box-shadow: inset 0 0 42px rgba(255,255,255,.18);
  will-change: backdrop-filter, transform;
}
.te-element.te-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(30,64,175,.88);
  background:
    linear-gradient(135deg, rgba(219,234,254,.80), rgba(239,246,255,.64));
  border: 1px dashed rgba(37,99,235,.70);
  overflow: hidden;
}
.te-element.te-frame.te-test-filled {
  background: #161616;
  border: 0;
}
.te-canvas .te-test-photo {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center;
  pointer-events: auto;
  cursor: grab;
  -webkit-user-drag: element;
}
.te-canvas .te-test-photo:active { cursor: grabbing; }
.te-element.te-frame.te-photo-drag-source { opacity: .5; }
.te-element.te-frame.te-photo-drop-target {
  border: 4px solid #16A34A;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.92), 0 0 0 5px rgba(22,163,74,.30) !important;
}
.te-test-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 2;
  padding: 3px 6px;
  color: #ECFDF5;
  background: rgba(6, 78, 59, .72);
  border: 1px solid rgba(167, 243, 208, .48);
  border-radius: 999px;
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
}
.te-frame-label {
  padding: 2px 5px;
  max-width: 90%;
  overflow: hidden;
  color: #1E3A8A;
  background: rgba(255,255,255,.76);
  border-radius: 5px;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.te-element.te-text {
  min-width: 24px;
  min-height: 20px;
  display: flex;
  align-items: center;
  white-space: pre-wrap;
  line-height: 1.16;
  overflow: visible;
}
.te-element.te-text > span { width: 100%; display:block; pointer-events:none; }
.te-text-empty { color: rgba(107,114,128,.82) !important; font-style: italic; }
.te-element.te-locked { cursor: not-allowed !important; }
.te-element.te-selected::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid #2563EB;
  box-shadow: 0 0 0 1px rgba(255,255,255,.9);
  pointer-events: none;
}
.te-element.te-unsafe::after { border-color: var(--te-danger); }

.te-handle {
  position: absolute;
  z-index: 100;
  width: 15px;
  height: 15px;
  border: 2px solid #2563EB;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 4px rgba(0,0,0,.26);
  touch-action: none;
}
.te-selection-box {
  position: absolute;
  z-index: 99997;
  transform-origin: center center;
  border: 2px solid #2563EB;
  box-shadow: 0 0 0 1px rgba(255,255,255,.9);
  pointer-events: none;
  touch-action: none;
}
.te-selection-box.te-unsafe { border-color: var(--te-danger); }
.te-selection-box .te-handle { pointer-events: auto; }
.te-selection-box .te-handle::before { content:""; position:absolute; inset:-12px; }
.te-handle-scale-nw { left: -9px; top: -9px; cursor: nwse-resize; }
.te-handle-scale-ne { right: -9px; top: -9px; cursor: nesw-resize; }
.te-handle-scale-sw { left: -9px; bottom: -9px; cursor: nesw-resize; }
.te-handle-scale-se { right: -9px; bottom: -9px; cursor: nwse-resize; }
.te-handle-rotate { left: 50%; top: -31px; transform: translateX(-50%); cursor: grab; }
.te-selection-box.te-handle-below .te-handle-rotate { top:auto; bottom:-31px; }
.te-handle-rotate::after {
  content: "";
  position:absolute;
  left:50%;
  top:13px;
  width:1px;
  height:16px;
  background:#2563EB;
}

.te-safe-line {
  position: absolute;
  z-index: 99990;
  border: 1px dashed rgba(220,38,38,.88);
  pointer-events: none;
  display: none;
}
.te-safe-line::before {
  content: attr(data-label);
  position: absolute;
  left: 3px;
  top: 3px;
  padding: 1px 4px;
  color: #991B1B;
  background: rgba(254,242,242,.88);
  border-radius: 3px;
  font-size: 9px;
}
.te-guide {
  position: absolute;
  z-index: 99999;
  display: none;
  pointer-events: none;
  background: #EC4899;
  box-shadow: 0 0 0 1px rgba(255,255,255,.55);
}
.te-guide-x { top: 0; bottom: 0; width: 1px; }
.te-guide-y { left: 0; right: 0; height: 1px; }

.te-zoom {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  color: #E5E7EB;
  background: rgba(17,24,39,.88);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px;
  backdrop-filter: blur(8px);
}
.te-zoom .te-icon-btn { min-height: 32px; width: 32px; }
.te-zoom-value { min-width: 50px; text-align: center; font-variant-numeric: tabular-nums; }

.te-warning {
  position:absolute;
  top:10px;
  left:50%;
  z-index:6;
  max-width:min(560px, calc(100% - 30px));
  transform:translateX(-50%);
  padding:8px 12px;
  color:#991B1B;
  background:rgba(254,242,242,.96);
  border:1px solid #FCA5A5;
  border-radius:9px;
  box-shadow:0 6px 20px rgba(0,0,0,.18);
  display:none;
}

.te-sidebar {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--te-panel);
  border-left: 1px solid var(--te-line);
}
.te-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--te-line); }
.te-tab {
  min-height: 44px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: #FFFFFF;
  cursor: pointer;
  font-weight: 650;
}
.te-tab.te-on { color: var(--te-accent); border-bottom-color: var(--te-accent); background: #FFFBEB; }
.te-panel { min-height: 0; overflow-y: auto; padding: 12px; }
.te-panel[hidden] { display:none; }
.te-section { padding: 0 0 14px; margin-bottom: 14px; border-bottom: 1px solid var(--te-line); }
.te-section:last-child { border-bottom: 0; }
.te-section-title { margin: 0 0 9px; color: var(--te-muted); font-size: 11px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.te-layer-heading { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.te-layer-heading .te-layer-delete-selected { min-height:30px; padding:0 8px; font-size:11px; }
.te-layer-check { display:flex; align-items:center; justify-content:center; width:28px; min-height:32px; cursor:pointer; }
.te-layer-check input { width:16px; height:16px; accent-color:var(--te-accent); }
.te-field { display: grid; gap: 5px; margin-bottom: 9px; }
.te-field > label, .te-inline-label { color: var(--te-muted); font-size: 11px; }
.te-field input, .te-field select, .te-field textarea,
.te-number-grid input, .te-layer-name {
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  color: var(--te-ink);
  background: #FFFFFF;
  border: 1px solid var(--te-line);
  border-radius: 7px;
}
.te-field textarea { min-height: 76px; resize: vertical; }
.te-number-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.te-number { position: relative; }
.te-number label { position:absolute; left:8px; top:50%; transform:translateY(-50%); color:var(--te-muted); font-size:10px; pointer-events:none; }
.te-number input { padding-left: 25px; font-variant-numeric: tabular-nums; }
.te-row { display: flex; align-items: center; gap: 7px; }
.te-row > * { min-width: 0; }
.te-row .te-btn { flex:1; min-height:36px; padding:0 8px; }
.te-color { width: 42px !important; min-width:42px; padding: 2px !important; }
.te-range { flex:1; accent-color:var(--te-accent); }
.te-help { color: var(--te-muted); font-size: 11px; line-height: 1.5; }
.te-empty { padding: 28px 12px; color: var(--te-muted); text-align:center; line-height:1.7; }
.te-link-box { margin-top:14px; padding:12px; border:1px solid var(--te-line); border-radius:10px; background:var(--te-panel-muted); }
.te-link-members { display:flex; flex-direction:column; gap:6px; margin-bottom:10px; }
.te-link-member { display:flex; align-items:center; justify-content:space-between; min-height:36px; padding:5px 8px; border-radius:7px; background:#fff; }
.te-link-remove { border:0; color:var(--te-danger); background:transparent; cursor:pointer; }
.te-link-empty { margin:6px 0 10px; color:var(--te-muted); font-size:11px; }
.te-link-add { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; }
.te-link-add select { min-width:0; }

.te-align-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:5px; }
.te-align-grid .te-icon-btn { width:100%; min-height:34px; border:1px solid var(--te-line); }
.te-align-grid .te-icon-btn:hover { background:var(--te-panel-muted); }

.te-layer-list { display:flex; flex-direction:column; gap:5px; }
.te-layer-row {
  display:grid;
  grid-template-columns: 28px 36px 36px minmax(0,1fr) 36px 36px;
  gap:3px;
  align-items:center;
  min-height:40px;
  padding:4px;
  border:1px solid transparent;
  border-radius:8px;
}
.te-layer-row:hover { background:var(--te-panel-muted); }
.te-layer-row.te-on { background:var(--te-accent-soft); border-color:rgba(180,83,9,.32); }
.te-layer-row.te-unsafe { border-color:#FCA5A5; }
.te-layer-row .te-icon-btn { width:36px; min-height:36px; }
.te-layer-row .te-icon-btn:hover { background:rgba(0,0,0,.06); }
.te-layer-name { min-height:30px; padding:4px 6px; border-color:transparent; background:transparent; }
.te-layer-name:focus { background:#FFFFFF; border-color:var(--te-line); }
.te-layer-kind { color:var(--te-muted); font-size:9px; line-height:1; padding-left:7px; }

.te-statusbar {
  position:absolute;
  right:12px;
  bottom:12px;
  z-index:5;
  padding:6px 9px;
  color:#D1D5DB;
  background:rgba(17,24,39,.82);
  border-radius:7px;
  pointer-events:none;
  font-size:11px;
}
.te-root.te-saving .te-body,
.te-root.te-saving .te-title-input,
.te-root.te-saving [data-role="publish"],
.te-root.te-saving .te-topbar button:not([data-action="close"]),
.te-root.te-saving .te-topbar select { pointer-events:none; opacity:.72; }
.te-sr-only {
  position:absolute !important;
  width:1px !important;
  height:1px !important;
  padding:0 !important;
  margin:-1px !important;
  overflow:hidden !important;
  clip:rect(0,0,0,0) !important;
  white-space:nowrap !important;
  border:0 !important;
}

/* 13~14 英寸笔记本即使是桌面布局，顶栏文字全部展开也会把“保存”挤出屏幕。 */
@media (max-width: 1500px) and (min-width: 901px) {
  .te-topbar .te-btn:not(.te-primary) span { display: none; }
  .te-title-input { width: min(220px, 20vw); }
}

@media (max-width: 900px) {
  .te-root { grid-template-rows: auto minmax(0, 1fr); }
  .te-topbar { min-height:58px; overflow-x:auto; }
  .te-topbar .te-btn span { display:none; }
  .te-title-input { min-width:150px; width:180px; }
  .te-body { grid-template-columns: 54px minmax(0,1fr); grid-template-rows:minmax(0,1fr) minmax(210px,38vh); }
  .te-toolbar { grid-row:1 / 3; }
  .te-sidebar { grid-column:2; grid-row:2; border-left:0; border-top:1px solid var(--te-line); }
  .te-workspace { grid-column:2; grid-row:1; }
  .te-workspace.te-dual-mode { grid-template-columns:minmax(170px,.75fr) minmax(0,1.25fr); }
  .te-panel { padding:10px; }
  .te-layer-list { display:grid; grid-template-columns:repeat(auto-fill,minmax(230px,1fr)); }
  .te-topbar [data-action="close"] { order:-3; }
  .te-topbar [data-action="save"] { order:-2; }
  .te-title-input { order:-1; }
}

@media (max-width: 560px) {
  .te-topbar { padding:6px; gap:4px; }
  .te-topbar-group { gap:2px; }
  .te-title-input { min-width:120px; width:140px; }
  .te-topbar .te-btn, .te-topbar .te-icon-btn { min-height:44px; }
  .te-body { grid-template-columns: 48px minmax(0,1fr); grid-template-rows:minmax(0,1fr) minmax(220px,42vh); }
  .te-toolbar { padding:5px 3px; }
  .te-tool { min-height:46px; font-size:9px; }
  .te-warning { font-size:11px; }
  .te-statusbar { display:none; }
  .te-zoom { left:7px; bottom:7px; }
}

@media (max-width: 900px) and (max-height: 500px) {
  .te-body { grid-template-rows:minmax(0,1fr) minmax(140px,34vh); }
}

@media (prefers-reduced-motion: reduce) {
  .te-root *, .te-root *::before, .te-root *::after { scroll-behavior:auto !important; transition:none !important; }
}
