/* ============================================================
   SerialWeb · 浮窗组件（串口终端 monitor-widget）
   - 四边/四角拖拽缩放（hover 显示 resize 光标）
   - 双击组件体最大化；双击边向外延伸
   - 最小化时内部 flex 自适应
   ============================================================ */

.workspace {
  position: relative;
}

.monitor-panel.monitor-widget {
  position: absolute;
  z-index: 40;
  display: flex;
  flex-direction: column;
  height: auto;
  min-block-size: 160px;
  min-inline-size: 240px;
  border: 2px solid var(--accent);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.26);
  background: var(--bg-panel-strong);
  border-radius: var(--radius);
  overflow: hidden;
  box-sizing: border-box;
}
.monitor-panel.monitor-widget:hover {
  border-color: var(--accent-strong);
}

.monitor-widget .monitor-toolbar {
  flex: 0 0 auto;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-panel-strong), var(--bg-panel));
}
.monitor-widget .monitor-toolbar:active { cursor: grabbing; }

.monitor-widget .monitor-body {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}
.monitor-widget .monitor-body .terminal-wrap { min-height: 0; }

/* 缩放热区：四边 + 四角 */
.w-panel .w-zone {
  position: absolute;
  z-index: 5;
  touch-action: none;
}
.w-panel .w-zone.top    { top: -3px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.w-panel .w-zone.bottom { bottom: -3px; left: 8px; right: 8px; height: 8px; cursor: ns-resize; }
.w-panel .w-zone.left   { left: -3px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.w-panel .w-zone.right  { right: -3px; top: 8px; bottom: 8px; width: 8px; cursor: ew-resize; }
.w-panel .w-zone.top-left     { top: -3px; left: -3px; width: 13px; height: 13px; cursor: nwse-resize; }
.w-panel .w-zone.top-right    { top: -3px; right: -3px; width: 13px; height: 13px; cursor: nesw-resize; }
.w-panel .w-zone.bottom-left  { bottom: -3px; left: -3px; width: 13px; height: 13px; cursor: nesw-resize; }
.w-panel .w-zone.bottom-right { bottom: -3px; right: -3px; width: 13px; height: 13px; cursor: nwse-resize; }

.w-panel .w-zone:hover { background: rgba(255, 255, 255, 0.14); }

.w-panel.w-anim {
  transition: left 0.18s ease, top 0.18s ease, width 0.18s ease, height 0.18s ease;
}

/* 容器查询：组件缩小时内部自适应 */
.monitor-widget {
  container-type: size;
}
@container (max-height: 300px) {
  .monitor-widget .monitor-live-meta { display: none; }
  .monitor-widget .monitor-body { gap: 6px; }
}
@container (max-height: 230px) {
  .monitor-widget .send-modebar { display: none; }
  .monitor-widget .send-panel { min-height: 0; }
}
@container (max-width: 420px) {
  .monitor-widget .monitor-toolbar-copy .panel-title { font-size: 12px; }
  .monitor-widget .send-mode-tile > .send-mode-switch span { font-size: 11px; }
}

/* 组件更小时：隐藏次要文字，保持整洁 */
@container (max-width: 420px) {
  .monitor-widget .send-mode-tile > .send-mode-switch span { font-size: 11px; }
}
@container (max-width: 340px) {
  .monitor-widget .send-mode-tile > .send-mode-switch span { display: none; }
  .monitor-widget .monitor-toolbar-copy .panel-title { font-size: 12px; }
}
@container (max-height: 270px) {
  .monitor-widget .monitor-live-meta { display: none; }
}
@container (max-height: 210px) {
  .monitor-widget .send-modebar { display: none; }
  .monitor-widget .send-manual-panel { display: none; }
}
@container (max-width: 340px) and (max-height: 260px) {
  .monitor-widget .monitor-toolbar-copy .panel-title { display: none; }
}

/* ============================================================
   组件自适应（仿监视组件）：非监视部件子组件随容器大小隐藏
   ============================================================ */
/* 左侧部件（连接管理） */
@container (max-height: 330px) {
  .config-panel .device-meta-line,
  .config-panel .signal-readout,
  .config-panel .layout-toggle-strip { display: none; }
}
@container (max-height: 250px) {
  .config-panel #advanced-panel,
  .config-panel .signal-config-row.secondary { display: none; }
}
@container (max-width: 380px) {
  .config-panel .connect-primary-stack .reconnect-chip { display: none; }
}

/* 解析部件 */
@container (max-height: 300px) {
  .parser-panel .parser-results-card { display: none; }
}
@container (max-height: 230px) {
  .parser-panel .parser-config-card .parser-card-head .help-icon,
  .parser-panel .parser-card-head .auto-detect-btn { display: none; }
}
@container (max-width: 400px) {
  .parser-panel .panel-title-note { display: none; }
}

/* 图表部件 */
@container (max-height: 270px) {
  .charts-panel .chart-add-copy { display: none; }
}
@container (max-width: 400px) {
  .charts-panel .chart-add-strip .panel-title { display: none; }
}

/* 锁按钮 */
.w-has-lock { position: relative; }
.w-lock-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 9;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-panel);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}
.w-lock-btn:hover { opacity: 1; }
.w-lock-btn.is-locked { color: var(--accent); border-color: var(--accent); }

/* 锁图标：无外框、默认隐藏、拖动时显示 */
.w-lock-icon {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 9;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
.w-lock-icon.w-dragging { opacity: 1; }
.w-lock-icon.is-locked { color: var(--accent); }
.w-lock-icon:hover { transform: scale(1.12); }

/* 锁图标：一直显示（便于点击），无外框 */
.w-lock-icon { opacity: 1; }


/* 锁图标动画 */
.w-lock-icon svg { transition: transform 0.2s ease; }
.w-lock-icon:not(.is-locked) svg { transform: rotate(-8deg) scale(1.08); }

/* ============================================================
   插件化面板（DeviceConfig / Parser / Charts 等）
   停靠（默认）：面板头部显示锁图标，点击解锁即浮起为可拖拽/缩放插件
   ============================================================ */
.panel .w-lock-icon {
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  opacity: 0.6;
  background: none;
  border: none;
  box-shadow: none;
  color: var(--text-soft);
  transition: opacity 0.22s ease, color 0.22s ease, transform 0.25s ease;
}
.panel .w-lock-icon:hover { opacity: 1; color: var(--text); transform: scale(1.1); }
.panel .w-lock-icon.is-locked { opacity: 1; color: var(--accent); transform: scale(1); }
.panel .w-lock-icon svg { transition: transform 0.28s ease; }
.panel .w-lock-icon.is-locked svg { transform: rotate(0deg); }
.panel .w-lock-icon:not(.is-locked) svg { transform: rotate(-12deg); }

/* 浮起态：脱离布局，可任意放置/缩放 */
.panel.w-floating {
  position: absolute;
  z-index: 40;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.26);
  border: 1px solid var(--accent);
  background: var(--bg-panel-strong);
  resize: none;
  container-type: size;      /* 内容随框自适应（仿监视部件） */
  overflow: hidden;          /* 无滚动条 */
}
.panel.w-floating .w-zone { z-index: 45; }

/* 组件内容自适应：框变小时隐藏次要元素 */
@container (max-height: 300px) {
  .w-floating .panel-title-note,
  .w-floating .device-meta-line,
  .w-floating .chart-add-copy .panel-title { display: none; }
}
@container (max-height: 220px) {
  .w-floating .parser-results-card,
  .w-floating .parser-panel .panel-head { display: none; }
}
@container (max-width: 380px) {
  .w-floating .panel-title-note,
  .w-floating .queue-send-head,
  .w-floating .preset-send-head,
  .w-floating .condition-send-head { display: none; }
}

/* 拖拽柄光标 + 拖拽中状态（所有插件共有属性） */
.w-drag-handle { cursor: grab; }
.w-drag-handle:active { cursor: grabbing; }
.w-dragging { cursor: grabbing !important; user-select: none; }
.w-dragging { z-index: 100 !important; will-change: left, top, width, height; }

/* ============================================================
   共享自动隐藏上栏（所有浮起组件的共有属性）
   仿图框 hover 工具栏：鼠标靠近顶部出现 锁 / 设置 / 关闭
   ============================================================ */
.w-has-toolbar { position: relative; }
.w-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 20;
}
.w-has-toolbar:hover .w-toolbar,
.w-toolbar:focus-within {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.w-tool-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: color 0.14s ease, transform 0.14s ease;
}
.w-tool-btn:hover, .w-tool-btn:focus-visible {
  color: var(--text);
  outline: none;
  transform: scale(1.12);
}
.w-tool-btn.is-locked { color: var(--accent); }
.w-close-btn:hover { color: var(--danger); }
.w-tool-btn svg { display: block; }
/* 锁图标在工具栏内：与 设置/关闭 一致，无外框同尺寸 */
.w-toolbar .w-lock-icon {
  position: static;
  opacity: 1;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  width: 22px;
  height: 22px;
}

/* ============================================================
   修复：监视组件关闭容器尺寸包含（contain:size）
   container-type:size 施加 contain:size，与 .monitor-widget 的
   height:auto 冲突——画布 rect 高度未严格内联时面板塌缩，
   终端只剩一行不撑满。改为 normal，面板高度由画布 rect 决定，
   终端 flex 撑满。
   ============================================================ */
.monitor-panel.monitor-widget.w-floating {
  container-type: normal;
}
