/* Studio 深色工作台主题。
   规则：本文件是 vendor/drawflow.min.css 之上的一层覆盖（不改动库核心）；
   不在 html/body 上使用 overflow-x:hidden —— 那会掩盖溢出而不是防止溢出。 */

:root {
  --bg: #0b0f15;
  --bg-1: #111823;
  --bg-2: #18212e;
  --bg-3: #1f2b3a;
  --line: #27364a;
  --line-2: #33475f;
  --text: #e6edf5;
  --muted: #90a0b3;
  --accent: #4c8dff;
  --accent-2: #2f6fe4;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f2555a;
  --radius: 8px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  min-width: 0;
}

img,
video,
audio,
canvas { max-width: 100%; }

/* ---------- 顶栏 ---------- */
body.workbench {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand {
  font-weight: 700;
  font-size: 15px;
  flex: 0 0 auto;
}

.group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.grow { flex: 1 1 0; min-width: 0; }

.whoami { color: var(--muted); font-size: 12px; }

/* ---------- 控件 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 10px;
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  max-width: 100%;
}

.btn:hover { background: var(--bg-3); }
.btn-primary { background: var(--accent-2); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); }
.btn-danger { color: var(--danger); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 8px;
  max-width: 100%;
  min-width: 0;
}

textarea { resize: vertical; min-height: 60px; }

/* ---------- 三栏布局（桌面优先，窄屏逐级降为单列） ---------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 320px;
  grid-template-areas: "palette stage inspector";
  min-height: 0;
  min-width: 0;
}

.palette { grid-area: palette; }
.stage { grid-area: stage; }
.inspector { grid-area: inspector; }

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas: "palette palette" "stage inspector";
  }
}

@media (max-width: 700px) {
  body.workbench { height: auto; min-height: 100%; }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "palette" "stage" "inspector";
    grid-template-rows: auto minmax(260px, 55vh) auto;
  }
}

/* ---------- 节点面板 ---------- */
.palette {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.pal {
  text-align: left;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: inherit;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.pal:hover { background: var(--bg-3); }

@media (max-width: 1080px) {
  .palette {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .pal { flex: 0 0 auto; }
}

/* ---------- 画布 ---------- */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, #1b2635 1px, transparent 0);
  background-size: 24px 24px;
}

.canvas { position: absolute; inset: 0; }

.pal-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--accent-2);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  opacity: .9;
}

/* ---------- 节点与连线（覆盖 drawflow 亮色默认） ---------- */
.drawflow .drawflow-node {
  width: 220px;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

.drawflow .drawflow-node.selected {
  background: var(--bg-3);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(76, 141, 255, .35);
}

.drawflow .drawflow-node .input {
  background: var(--bg-3);
  border: 2px solid var(--line-2);
  left: -24px;
}

.drawflow .drawflow-node .output {
  background: var(--accent);
  border: 2px solid var(--bg-1);
  right: -12px;
}

.drawflow .connection .main-path { stroke: var(--accent); stroke-width: 3; }
.drawflow .connection .main-path:hover { stroke: var(--accent-2); }
.drawflow .connection .main-path.selected { stroke: var(--ok); }

.n-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.n-title { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }

.n-state {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--muted);
  white-space: nowrap;
}

.n-state[data-s="success"] { color: var(--ok); border-color: var(--ok); }
.n-state[data-s="failed"] { color: var(--danger); border-color: var(--danger); }
.n-state[data-s="running"],
.n-state[data-s="queued"] { color: var(--warn); border-color: var(--warn); }

.n-ports { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; min-width: 0; }

.n-chip {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  white-space: nowrap;
}

.n-summary {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.n-out { margin-top: 6px; min-width: 0; }
.n-out img,
.n-out video { display: block; width: 100%; border-radius: 6px; background: var(--bg); }
.n-out audio { width: 100%; }

.n-expired {
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line-2);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
}

/* ---------- 参数面板 ---------- */
.inspector {
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  padding: 10px;
  overflow-y: auto;
  min-width: 0;
}

.insp-title { font-weight: 600; margin: 0 0 8px; font-size: 14px; overflow-wrap: anywhere; }
.insp-empty { color: var(--muted); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > label { font-size: 12px; color: var(--muted); }
.field input,
.field select,
.field textarea { width: 100%; }

.row { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.row > * { flex: 1 1 0; min-width: 0; }

.insp-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

.thumb {
  width: 100%;
  border-radius: 6px;
  display: block;
  background: var(--bg);
  border: 1px solid var(--line);
}

/* ---------- 状态栏 ---------- */
.statusbar {
  border-top: 1px solid var(--line);
  background: var(--bg-1);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}

#statusText { display: block; overflow-wrap: anywhere; }
#statusText[data-kind="error"] { color: var(--danger); }
#statusText[data-kind="ok"] { color: var(--ok); }

/* ---------- 对话框 ---------- */
.dlg-mask {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 10, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.dlg-mask[hidden] { display: none; }

.dlg {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 16px;
  width: 100%;
  max-width: 360px;
  min-width: 0;
}

.dlg h2 { margin: 0 0 8px; font-size: 15px; overflow-wrap: anywhere; }
.dlg p { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.dlg p[hidden] { display: none; }
.dlg input { width: 100%; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-box {
  width: 100%;
  max-width: 340px;
  min-width: 0;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}

.login-box h1 { font-size: 18px; margin: 0 0 14px; }
.login-err { color: var(--danger); font-size: 13px; margin: 10px 0 0; overflow-wrap: anywhere; }
.login-err[hidden] { display: none; }

/* ---------- 素材库 ---------- */
.page-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px;
  min-width: 0;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
  min-width: 0;
}

.filters label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  gap: 12px;
}

.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.card img,
.card video { width: 100%; border-radius: 6px; display: block; background: var(--bg); }
.card audio { width: 100%; }
.card-media { min-width: 0; }
.card-meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.empty[hidden] { display: none; }
