/* ==========================================================================
   网页缩放预览器 —— 样式
   布局完全由 <html> 上的 data-ui / data-panel 驱动（而不是媒体查询），
   这样"界面布局：电脑 / 移动"可以脱离真实设备强制切换。
   ========================================================================== */

:root {
  --bg:        #0e1016;
  --stage-bg:  #14161d;
  --panel:     #161a23;
  --panel-2:   #1c212c;
  --panel-3:   #232936;
  --line:      #272e3d;
  --txt:       #e7eaf1;
  --muted:     #8b93a7;
  --accent:    #3b82f6;
  --accent-2:  #007acc;
  --ok:        #10b981;
  --warn:      #f59e0b;
  --radius:    10px;
  --topbar-h:  52px;
}

* { box-sizing: border-box; }

/* 本项目用 .hidden / [hidden] 控制显隐，需要压过 .field{display:flex} 之类的规则 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============================ 骨架 ============================ */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 30;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.topbar::-webkit-scrollbar { display: none; }

.topbar__spacer { flex: 1 1 auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, .15);
  flex: 0 0 auto;
}

.brand__name { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand__sub  { color: var(--muted); font-size: 12px; white-space: nowrap; }

.body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ============================ 输入面板 ============================ */

.panel {
  flex: 0 0 auto;
  width: 340px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  transition: width .2s ease, transform .2s ease;
}

.panel__head {
  flex: 0 0 auto;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--line);
}

.panel__title {
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--muted);
  text-transform: uppercase;
  flex: 1 1 auto;
}

.panel__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel__body::-webkit-scrollbar { width: 8px; }
.panel__body::-webkit-scrollbar-thumb { background: #2c3444; border-radius: 8px; }

/* 折叠后的竖条 */
.rail {
  display: none;
  flex: 0 0 auto;
  width: 34px;
  border: none;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.rail:hover { background: var(--panel-2); color: var(--txt); }

.rail__text {
  writing-mode: vertical-rl;
  letter-spacing: .3em;
  font-size: 12px;
  user-select: none;
}

.app.is-panel-collapsed .panel { display: none; }
.app.is-panel-collapsed .rail  { display: flex; }

/* ============================ 表单元素 ============================ */

.field { display: flex; flex-direction: column; gap: 8px; }

.field__label {
  font-size: 12px;
  font-weight: 600;
  color: #aab3c6;
  letter-spacing: .02em;
}

.field__label em {
  font-style: normal;
  font-weight: 400;
  color: var(--muted);
  font-size: 11px;
  margin-left: 4px;
}

.field__hint {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

.field__hint code {
  background: var(--panel-3);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 11px;
}

/* 代理自检结果 */
.proxy-status {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  line-height: 1.6;
}

.proxy-status--pending { background: rgba(148, 163, 184, .12); color: #cbd5e1; }
.proxy-status--ok      { background: rgba(16, 185, 129, .12); border-color: rgba(16, 185, 129, .4); color: #b6f0d8; }
.proxy-status--warn    { background: rgba(245, 158, 11, .13); border-color: rgba(245, 158, 11, .45); color: #ffe0a3; }
.proxy-status--err     { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .42); color: #ffc9c9; }
.proxy-status--err code,
.proxy-status--ok code,
.proxy-status--warn code { background: rgba(0, 0, 0, .3); color: inherit; }

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--txt);
  padding: 9px 11px;
  font: inherit;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

input::placeholder, textarea::placeholder { color: #5d6679; }

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}

/* 缩放行 */
.zoomline { display: flex; gap: 8px; align-items: center; }

.zoomline__input {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
}

.zoomline__input input { padding-right: 30px; }
.zoomline__input span {
  position: absolute;
  right: 11px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.zoomline__quick { display: flex; gap: 6px; flex: 0 0 auto; }

.zoomline__quick button {
  background: var(--panel-3);
  border: 1px solid var(--line);
  color: #b9c1d1;
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 11.5px;
  cursor: pointer;
  transition: all .14s ease;
}

.zoomline__quick button:hover { background: #2b3444; color: #fff; }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--panel-3);
  outline: none;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0e1016;
  cursor: pointer;
}

.range::-moz-range-thumb {
  width: 14px; height: 14px;
  border: 2px solid #0e1016;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* 芯片按钮组 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chips button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: #b9c1d1;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .14s ease;
}

.chips button:hover { background: var(--panel-3); color: #fff; }

.chips button.is-active {
  background: rgba(59, 130, 246, .16);
  border-color: var(--accent);
  color: #cfe0ff;
}

/* 自定义尺寸 */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.mini--full { margin-top: 10px; }

/* 动作按钮 */
.actions { display: flex; gap: 8px; }

.btn {
  flex: 1 1 auto;
  background: var(--panel-3);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all .16s ease;
  white-space: nowrap;
}

.btn:hover { background: #2b3444; }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(0, 122, 204, .28);
}

.btn--primary:hover { filter: brightness(1.08); }

.btn--block { width: 100%; }

/* 高级区 */
.adv {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .015);
  padding: 10px 12px;
}

.adv > summary {
  cursor: pointer;
  font-size: 12.5px;
  color: #aab3c6;
  list-style: none;
  user-select: none;
}

.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: "▸ "; color: var(--muted); }
.adv[open] > summary::before { content: "▾ "; }
.adv > *:not(summary) { margin-top: 12px; }

.switch {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: #b9c1d1;
  cursor: pointer;
  line-height: 1.45;
}

.switch input { margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto; }

.hr { border: none; border-top: 1px solid var(--line); margin: 14px 0 !important; }

/* ============================ 预览区 ============================ */

.stage {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  background:
    radial-gradient(1200px 600px at 70% 0%, #1b2030 0%, transparent 60%),
    var(--stage-bg);
  overflow: hidden;
}

.stage__scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  padding: 18px;
}

.stage__scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.stage__scroll::-webkit-scrollbar-thumb {
  background: #2c3444;
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.sizer {
  margin: auto;
  flex: 0 0 auto;
  position: relative;
}

.frame {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .07);
}

.frame[data-kind="mobile"] { border-radius: 26px; }
.frame[data-kind="tablet"] { border-radius: 16px; }

.frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

/* 空状态 */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

.empty__inner { max-width: 460px; }
.empty__icon { font-size: 44px; margin-bottom: 6px; }
.empty h2 { margin: 0 0 10px; font-size: 19px; }
.empty p  { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.empty__tips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.empty__tips span {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--muted);
}

.empty__tips b { color: var(--txt); font-weight: 600; }

/* 底部状态条 */
.stagebar {
  position: absolute;
  left: 12px;
  bottom: 12px;
  right: 96px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.stagebar__spacer { flex: 1 1 auto; }

.pill {
  pointer-events: auto;
  background: rgba(17, 24, 39, .78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .08);
  color: #cbd3e1;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11.5px;
  white-space: nowrap;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill i { font-style: normal; color: var(--muted); }

.pill--btn { cursor: pointer; background: rgba(245, 158, 11, .9); color: #1b1300; font-weight: 600; border-color: transparent; }
.pill--btn:hover { filter: brightness(1.06); }

.pill--ok { color: #b6f0d8; }

/* ============================ 分页模式 ============================ */

.tabbar {
  display: none;
  flex: 0 0 auto;
  height: 54px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
  flex: 1 1 0;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  position: relative;
}

.tabbar button.is-active { color: var(--txt); font-weight: 600; }

.tabbar button.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  width: 22px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
}

html[data-panel="tabs"] .tabbar { display: flex; }

html[data-panel="tabs"] .body { display: block; }

html[data-panel="tabs"] .rail { display: none !important; }

html[data-panel="tabs"] .panel {
  width: 100%;
  height: 100%;
  border-right: none;
}

html[data-panel="tabs"] .panel__head { display: none; }

html[data-panel="tabs"] .stage {
  position: absolute;
  inset: 0;
  height: 100%;
}

html[data-panel="tabs"] .panel:not(.is-active),
html[data-panel="tabs"] .stage:not(.is-active) { display: none; }

/* ============================ 紧凑（移动）界面 ============================ */

html[data-ui="mobile"] .brand__sub { display: none; }
html[data-ui="mobile"] .brand__name { font-size: 13.5px; }
html[data-ui="mobile"] .seg__label { display: none; }

html[data-ui="mobile"] .topbar {
  gap: 6px;
  padding: 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

html[data-ui="mobile"] .topbar::-webkit-scrollbar { display: none; }

html[data-ui="mobile"] .seg button { padding: 5px 8px; font-size: 11.5px; }

html[data-ui="mobile"] .panel__body { padding: 12px; gap: 14px; }

html[data-ui="mobile"] .stagebar { right: 12px; bottom: 10px; }

html[data-ui="mobile"] .pill { font-size: 11px; padding: 4px 9px; max-width: 60vw; }

html[data-ui="mobile"] .empty h2 { font-size: 17px; }

/* 强制桌面布局但真实屏幕很窄时：
   · 顶栏省掉次要文字
   · 输入区改成"浮层抽屉"，展开时覆盖在预览之上，而不是把预览挤窄
   注意：这里刻意不用 CSS zoom —— 它会让 position:fixed 的元素（比如右下角
   缩放工具栏）错位甚至跑到屏幕外。 */
html[data-forced="true"] .brand__sub,
html[data-forced="true"] .seg__label { display: none; }

html[data-forced="true"] .topbar { gap: 6px; padding: 0 8px; }

html[data-forced="true"] .panel {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  z-index: 25;
  width: min(340px, 84vw);
  box-shadow: 14px 0 40px rgba(0, 0, 0, .55);
}

html[data-forced="true"] .stage { flex: 1 1 auto; }

/* ============================ 顶栏按钮 / 分段控件 ============================ */

.icon-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: #aab3c6;
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}

.icon-btn:hover { background: var(--panel-3); color: #fff; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn--sm { width: 28px; height: 28px; }
.icon-btn--sm svg { width: 15px; height: 15px; }

.seg {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  flex: 0 0 auto;
}

.seg__label {
  font-size: 11px;
  color: var(--muted);
  padding: 0 6px 0 8px;
  white-space: nowrap;
}

.seg button {
  background: transparent;
  border: none;
  color: #a8b0c2;
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .16s ease;
}

.seg button:hover { color: #fff; }

.seg button.is-active {
  background: rgba(59, 130, 246, .2);
  color: #dbe8ff;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, .45);
}

/* ============================ Toast ============================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 10px);
  background: rgba(17, 24, 39, .95);
  border: 1px solid rgba(255, 255, 255, .1);
  color: #fff;
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 2147482000;
  max-width: 80vw;
  text-align: center;
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
