/* Kairos TV - 前台样式 */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel2: #1e2530;
  --border: #2a3342;
  --text: #e8edf4;
  --muted: #8b96a8;
  --accent: #f5b731;
  --accent-dark: #d99e1b;
  --danger: #e5534b;
  --green: #3fb950;
}
html, body { height: 100%; overflow: hidden; }
body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button { cursor: pointer; border: none; font-family: inherit; }

/* ---------- 登录 ---------- */
#login-screen {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 30% -10%, #1b2434 0%, var(--bg) 60%);
}
.login-card {
  width: 360px; padding: 42px 36px 36px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.login-logo { font-size: 30px; font-weight: 700; letter-spacing: .5px; text-align: center; }
.login-logo span { color: var(--accent); }
.login-sub { color: var(--muted); text-align: center; margin: 6px 0 28px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 14px; margin-bottom: 14px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 14px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.login-card button[type=submit] {
  width: 100%; padding: 12px; border-radius: 8px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: #1a1405;
}
.login-card button[type=submit]:hover { background: var(--accent-dark); }

/* ---------- 顶部栏 ---------- */
#topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: relative; z-index: 30;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.logo { font-weight: 700; font-size: 17px; margin-right: 8px; }
.logo span { color: var(--accent); }
#topbar button {
  padding: 7px 14px; border-radius: 7px; font-size: 13px;
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
}
#topbar button:hover { border-color: var(--accent); color: var(--accent); }
.pill {
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px;
  background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
}
.pill.credits { color: var(--accent); font-weight: 600; border-color: rgba(245,183,49,.35); }
.pill.expired { color: var(--danger); border-color: rgba(229,83,75,.4); }

/* ---------- 画布 ---------- */
#viewport {
  position: absolute; top: 52px; bottom: 96px; left: 0; right: 0;
  overflow: hidden; cursor: grab;
  background:
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg);
}
#viewport.panning { cursor: grabbing; }
#world { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
#world img, #world video { pointer-events: none; display: block; }

.node {
  position: absolute; border-radius: 8px; overflow: hidden;
  border: 2px solid transparent; background: var(--panel2);
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
  cursor: move; user-select: none;
}
.node img { width: 100%; height: 100%; object-fit: cover; display: block; }
.node.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,183,49,.25), 0 6px 24px rgba(0,0,0,.45); }
.node .node-tag {
  position: absolute; top: 6px; left: 6px; padding: 2px 8px; border-radius: 5px;
  background: rgba(0,0,0,.65); color: var(--accent); font-size: 11px; font-weight: 600;
  pointer-events: none;
}
.node .node-status {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; background: rgba(14,17,22,.82);
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.node.failed .node-status { color: var(--danger); }
.node video { width: 100%; height: 100%; object-fit: contain; background: #000; }

/* 节点删除按钮与连线锚点 */
.node-del {
  position: absolute; top: -10px; right: -10px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--danger); color: #fff;
  font-size: 14px; line-height: 20px; text-align: center;
  display: none; cursor: pointer; z-index: 5;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.node:hover .node-del { display: block; }
.node-del:hover { transform: scale(1.15); }
.node-anchor {
  position: absolute; top: 50%; width: 14px; height: 14px; margin-top: -7px;
  border-radius: 50%; background: var(--panel); border: 2px solid var(--accent);
  display: none; cursor: crosshair; z-index: 6;
}
.node-anchor:hover { transform: scale(1.3); background: var(--accent); }
.anchor-left { left: -8px; }
.anchor-right { right: -8px; }
.node:hover .node-anchor { display: block; }

/* SVG 连线层（固定大坐标系，负偏移覆盖画布全域） */
#edges-svg {
  position: absolute; top: -100000px; left: -100000px;
  width: 200000px; height: 200000px;
  overflow: visible; pointer-events: none;
}
#edges-svg .edge {
  fill: none; stroke: var(--accent); stroke-width: 2;
  opacity: .75; pointer-events: stroke; cursor: pointer;
}
#edges-svg .edge:hover { opacity: 1; stroke-width: 3; }
#edges-svg .edge.temp {
  stroke-dasharray: 6 4; opacity: .9; pointer-events: none; cursor: default;
}

/* 右键菜单 */
#ctx-menu {
  position: absolute; z-index: 60; min-width: 170px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 5px; box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
.ctx-item {
  padding: 9px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
  white-space: nowrap;
}
.ctx-item:hover { background: var(--panel2); color: var(--accent); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover { background: rgba(229,83,75,.12); }

/* 预览弹窗 */
.preview-mask { z-index: 150; }
.preview-box {
  position: relative; max-width: 88vw; max-height: 88vh;
}
.preview-box img, .preview-box video {
  max-width: 88vw; max-height: 82vh; border-radius: 10px;
  background: #000; box-shadow: 0 24px 90px rgba(0,0,0,.7);
}
.preview-box img { min-width: min(720px, 80vw); object-fit: contain; }
.preview-close {
  position: absolute; top: -38px; right: -6px;
  background: none; color: #fff; font-size: 28px;
}
.preview-close:hover { color: var(--accent); }

#marquee {
  position: absolute; border: 1px solid var(--accent);
  background: rgba(245,183,49,.08); z-index: 20; pointer-events: none;
}

#zoom-ctrl {
  position: absolute; right: 14px; bottom: 14px; z-index: 25;
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
#zoom-ctrl button {
  width: 26px; height: 26px; border-radius: 6px; background: var(--panel2);
  color: var(--text); font-size: 15px; line-height: 1;
}
#zoom-ctrl button:hover { color: var(--accent); }
#zoom-level { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; }

#ref-tip {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 25;
  padding: 7px 16px; border-radius: 999px; font-size: 13px;
  background: rgba(245,183,49,.15); border: 1px solid rgba(245,183,49,.4); color: var(--accent);
}
#ref-tip b { font-size: 14px; }

/* 参考角标（节点左上角） */
.node-ref-tag {
  position: absolute; top: 6px; left: 6px; padding: 2px 8px; border-radius: 5px;
  background: var(--accent); color: #1a1405; font-size: 11px; font-weight: 700;
  pointer-events: none; z-index: 4;
}

/* 参考 chips（生成条上方） */
#ref-chips {
  position: absolute; top: -40px; left: 16px; right: 16px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.chips-label { font-size: 12px; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 4px;
  background: var(--panel2); border: 1px solid rgba(245,183,49,.4); border-radius: 8px;
  font-size: 11.5px; color: var(--accent);
}
.chip img { width: 26px; height: 20px; object-fit: cover; border-radius: 4px; }
.chip .chip-vid { font-size: 11px; }
.chip i { font-style: normal; }
.chip-x { cursor: pointer; color: var(--muted); font-weight: 700; padding: 0 2px; }
.chip-x:hover { color: var(--danger); }

/* @ 引用面板 */
#at-panel {
  position: absolute; bottom: 64px; left: 16px; width: 320px; max-height: 260px; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; z-index: 70; box-shadow: 0 12px 40px rgba(0,0,0,.55);
}
.at-item {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border-radius: 7px; cursor: pointer; font-size: 13px;
}
.at-item:hover { background: var(--panel2); color: var(--accent); }
.at-item img { width: 56px; height: 40px; object-fit: cover; border-radius: 5px; }
.at-vid { width: 56px; height: 40px; display: flex; align-items: center; justify-content: center; background: #000; border-radius: 5px; }
.at-empty { padding: 10px; color: var(--muted); font-size: 12.5px; }

/* ---------- 底部生成条 ---------- */
#genbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 96px; z-index: 30;
  background: var(--panel); border-top: 1px solid var(--border);
  padding: 12px 16px 8px;
}
.genbar-main { display: flex; align-items: flex-end; gap: 12px; height: 56px; }
#prompt {
  flex: 1; height: 52px; resize: none; padding: 10px 14px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 14px; line-height: 1.5; outline: none; font-family: inherit;
}
#prompt:focus { border-color: var(--accent); }
.genbar-opts { display: flex; gap: 10px; }
.genbar-opts label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.genbar-opts select {
  height: 36px; padding: 0 8px; background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px; font-size: 13px; outline: none;
}
#btn-generate {
  height: 52px; padding: 0 26px; border-radius: 9px;
  background: var(--accent); color: #1a1405; font-size: 15px; font-weight: 700;
  white-space: nowrap;
}
#btn-generate:hover:not(:disabled) { background: var(--accent-dark); }
#btn-generate:disabled { background: #3a4250; color: #78829a; cursor: not-allowed; }
#gen-price { font-size: 12px; font-weight: 500; opacity: .8; }
#genbar-msg { height: 22px; margin-top: 5px; font-size: 12.5px; color: var(--danger); text-align: center; }

/* ---------- 历史弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  width: min(860px, 92vw); max-height: 80vh; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 15px; }
.modal-close { background: none; color: var(--muted); font-size: 20px; }
.modal-close:hover { color: var(--text); }
.modal-body { overflow: auto; padding: 8px 18px 18px; }
table.rec { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.rec th, table.rec td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.rec th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--panel); }
.rec-prompt { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { padding: 2px 8px; border-radius: 5px; font-size: 11.5px; }
.tag.succeeded { background: rgba(63,185,80,.15); color: var(--green); }
.tag.processing { background: rgba(245,183,49,.15); color: var(--accent); }
.tag.failed { background: rgba(229,83,75,.15); color: var(--danger); }
.tag.consume { color: var(--danger); }
.tag.refund, .tag.adjust { color: var(--green); }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.pager button { padding: 5px 12px; border-radius: 6px; background: var(--panel2); color: var(--text); border: 1px solid var(--border); font-size: 12.5px; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.pager span { align-self: center; color: var(--muted); font-size: 12.5px; }
