/* ===========================================================================
   外壳共享面板：系统连接、UI 设计（shell-tools.js）
   ---------------------------------------------------------------------------
   这两个面板原先只在文件页有，用的是 Element 的 <el-popover> 与 $alert。
   提到顶栏后四个分区页共用，而只有文件页加载 Element，所以改成了不依赖
   Vue / Element 的原生浮层，样式跟着搬到这里。

   取值全部引用 theme.css 的 --ui-* token，因此夜间模式自动跟随，
   本文件不含任何 html[data-theme="dark"] 覆盖块（加了反而说明这里该
   引用 token 而非硬编码）。

   类名前缀是 .shell- 而不是 .workspace-：app-shell-contract 那组测试
   禁止 app-shell.css 以外的样式表改动外壳选择器（.workspace-*），面板是
   挂在 body 上的浮层、不是顶栏的一部分，不属于那个范围。

   加载位置：四个页面都在 app-shell.css 之后、页面私有样式之前。
   ========================================================================= */

.shell-popover {
  position: fixed;
  /* 顶层工具浮层，压在吸顶栏之上、模态之下。原先写死 1200，
     与 index.css 的 .compress-confirm-modal 同值、靠加载顺序分胜负。 */
  z-index: var(--ui-z-dropdown);
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
  min-width: 260px;
  /* 宽度上限用 100% 而不是 100vw：vw 量的是**含滚动条沟槽**的视口宽
     （根元素写了 overflow-y:scroll），而 100% 是文档的可用宽度。按 vw 算
     的窄屏浮层实测右边缘会压进沟槽、并导致横向溢出。真正的边界由
     shell-tools.js 的 position() 按 clientWidth 夹，这里只是别把它顶出
     CSS 的上限。 */
  max-width: min(420px, 100%);
  padding: 14px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* 面板本体跟随「卡片透明度/模糊强度」旋钮：--card-bg 是 theme-effects.js
     写出的 color-mix 版（JS 未执行时回退 var(--ui-surface)，零回归）。
     面板内的小控件（.shell-panel-input / .shell-panel-btn /
     .shell-segmented）保持实色 —— 与 workbench --wb-subtle 同一决策：
     嵌套面再叠一层透明会双重 mix，透出率失真。 */
  background: var(--card-bg);
  backdrop-filter: var(--ui-card-backdrop-filter);
  -webkit-backdrop-filter: var(--ui-card-backdrop-filter);
  border: 1px solid var(--ui-line-strong);
  border-radius: var(--ui-radius-lg);
  box-shadow: var(--ui-shadow-soft);
  color: var(--ui-ink);
  /* 字体栈跟 body 共用同一个 token（原先此处是第四份私有栈）。 */
  font-family: var(--ui-font-body);
  font-size: 14px;
  line-height: 1.6;
}

.shell-panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ui-ink);
}

.shell-panel-sub,
.shell-panel-tip {
  margin: 0;
  color: var(--ui-ink-muted);
  font-size: 12px;
}

.shell-panel-loading {
  margin: 0;
  color: var(--ui-ink-muted);
}

/* --- 系统连接 ------------------------------------------------------------ */

.shell-connection-panel {
  max-width: 340px;
}

.shell-connection-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.shell-connection-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.shell-connection-state {
  color: var(--ui-danger);
  text-align: right;
  overflow-wrap: anywhere;
}

.shell-connection-state.is-connected {
  color: var(--ui-ink-secondary);
}

.shell-connection-list li[aria-busy] {
  opacity: 0.6;
}

.shell-connection-error .shell-connection-state,
.shell-connection-error span:last-child {
  color: var(--ui-danger);
}

/* --- UI 设计面板 --------------------------------------------------------- */

.shell-design-panel {
  width: min(420px, 100%);
}

.shell-panel-section {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--surface-3);
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-md);
}

.shell-panel-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ui-ink-secondary);
}

.shell-panel-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.shell-panel-inline.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.shell-panel-input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 8px 10px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line-strong);
  border-radius: var(--ui-radius-sm);
  color: var(--ui-ink);
  font: inherit;
  font-size: 13px;
}

.shell-panel-input:focus-visible {
  outline: 2px solid var(--ui-brand);
  outline-offset: 1px;
}

.shell-hidden-input {
  display: none;
}

.shell-panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 5px 12px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line-strong);
  border-radius: var(--ui-radius-control);
  color: var(--ui-ink-secondary);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.shell-panel-btn:hover:not(:disabled) {
  background: var(--ui-surface-hover);
  color: var(--ui-ink);
}

.shell-panel-btn.is-primary {
  background: var(--ui-brand);
  border-color: var(--ui-brand);
  color: var(--ui-brand-ink);
}

.shell-panel-btn.is-primary:hover:not(:disabled) {
  background: var(--ui-brand-hover);
  color: var(--ui-brand-ink);
}

.shell-panel-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.shell-segmented {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-control);
}

.shell-segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.shell-segment span {
  display: inline-block;
  padding: 5px 10px;
  border-radius: var(--ui-radius-sm);
  color: var(--ui-ink-secondary);
  font-size: 13px;
  cursor: pointer;
}

.shell-segment input:checked + span {
  background: var(--ui-brand-soft);
  color: var(--ui-brand);
  font-weight: 600;
}

.shell-segment input:focus-visible + span {
  outline: 2px solid var(--ui-brand);
  outline-offset: 1px;
}

.shell-panel-range {
  display: grid;
  gap: 4px;
}

.shell-panel-range-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ui-ink-muted);
}

.shell-panel-value {
  color: var(--ui-ink-secondary);
  font-variant-numeric: tabular-nums;
}

.shell-panel-slider {
  width: 100%;
  accent-color: var(--ui-brand);
}

.shell-panel-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ui-ink-secondary);
  cursor: pointer;
}

.shell-panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 2px;
}

.shell-panel-spacer {
  flex: 1 1 auto;
}

.shell-panel-status {
  font-size: 12px;
  color: var(--ui-ink-muted);
  overflow-wrap: anywhere;
}

.shell-panel-status[data-state="saving"] {
  color: var(--ui-ink-secondary);
}

.shell-panel-status[data-state="success"] {
  color: var(--ui-ink-secondary);
}

.shell-panel-status[data-state="warning"] {
  color: var(--ui-danger);
}

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

@media (max-width: 480px) {
  .shell-popover {
    max-width: 100%;
  }

  .shell-design-panel {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shell-panel-btn,
  .shell-segment span {
    transition: none;
  }
}