* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0d1117; --panel: #161b22; --border: #30363d;
  --text: #e6edf3; --muted: #8b949e; --accent: #2f81f7;
  --green: #3fb950; --red: #f85149; --yellow: #d29922;
}
html, body { height: 100%; max-width: 100%; overflow-x: hidden; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }

/* login */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 10; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px 22px; text-align: center; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin-bottom: 18px; }
.login-card input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px; margin-bottom: 12px; }
.login-card button { width: 100%; padding: 12px; border-radius: 10px; border: none; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; }
.error { color: var(--red); margin-top: 10px; }

/* header */
header { position: sticky; top: 0; background: rgba(13,17,23,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 14px 16px calc(14px); display: flex; align-items: center; justify-content: space-between; gap: 8px; z-index: 5; padding-top: calc(14px + env(safe-area-inset-top)); }
.header-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
header h1 { white-space: nowrap; }
.me-chip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header h1 { font-size: 17px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); display: inline-block; }
.dot.on { background: var(--green); }
.queue-info { color: var(--muted); font-size: 12px; }
.me-chip { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #1f2937; color: var(--muted); }
.me-chip.admin { background: rgba(210,153,34,.18); color: var(--yellow); }
.chip-select { padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 13px; font-weight: 600; max-width: 130px; }
.author-badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: rgba(47,129,247,.14); color: var(--accent); flex-shrink: 0; }
.users-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.user-item { display: flex; align-items: center; gap: 8px; font-size: 13px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.user-item .uname { font-weight: 600; flex: 1; }
.user-item .urole { color: var(--muted); font-size: 11px; }
.user-item button { background: none; border: none; font-size: 14px; padding: 2px 4px; }
.user-item .copy-link { color: var(--accent); font-weight: 600; }
.user-item .del-user { color: var(--red); }
#new-user-name { flex: 1; min-width: 0; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 14px; }
#add-user-btn { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap; }

.limit-banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: 12px; background: rgba(210,153,34,.12); border: 1px solid rgba(210,153,34,.4); color: var(--yellow); font-size: 13px; font-weight: 600; }

/* new job */
.new-job { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.new-job textarea, .followup textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 16px; resize: vertical; font-family: inherit;
}
.advanced summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.advanced textarea { margin-top: 8px; font-size: 14px !important; }
.ctx-state { color: var(--green); font-weight: 600; }
.ctx-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.ctx-toggle { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.ctx-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
#ctx-save { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 13px; font-weight: 600; }
.model-label { color: var(--muted); font-size: 13px; }
.model-seg { display: flex; gap: 6px; }
.advanced input { width: 100%; margin-top: 8px; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 13px; font-family: ui-monospace, monospace; }
#send-btn, #followup-btn { padding: 13px; border-radius: 12px; border: none; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; }
#send-btn:disabled { opacity: .5; }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 13px; font-weight: 600; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* config modal */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); padding: 20px; }
.modal-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.modal-card h3 { font-size: 17px; margin-bottom: 14px; }
.seg-toggle { display: flex; gap: 8px; }
.seg-toggle .seg { flex: 1; padding: 14px 8px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); font-size: 15px; font-weight: 700; }
.seg-toggle .seg.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.mode-desc { color: var(--muted); font-size: 13px; margin: 12px 2px 4px; min-height: 54px; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
.modal-actions .btn { flex: 1; padding: 12px; }
.mode-badge { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: #1f2937; color: var(--muted); flex-shrink: 0; }

/* image attachments */
.attach-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.previews { display: flex; gap: 6px; flex-wrap: wrap; }
.previews img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.detail-images { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-images img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; }

/* job list */
.job-list { padding: 0 16px 40px; display: flex; flex-direction: column; gap: 10px; }
.job-group { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.group-title { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; font-size: 13px; font-weight: 700; color: var(--accent); background: rgba(47,129,247,.08); border-bottom: 1px solid var(--border); cursor: pointer; }
.group-title .gname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-group.starred { border-color: var(--yellow); }
.gcard.starred { border-color: var(--yellow); }
.star-btn { background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; flex-shrink: 0; }
.star-btn.on { color: var(--yellow); }
.thumb .star-btn { position: absolute; top: 4px; left: 4px; z-index: 2; text-shadow: 0 1px 3px #000; }
.play-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--green); color: #04260f; font-size: 15px; font-weight: 700; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.dl-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg); color: var(--text); flex-shrink: 0; display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 16px; }
.more-row { padding: 8px 14px 8px 28px; color: var(--muted); font-size: 12px; cursor: pointer; border-top: 1px solid var(--border); }

/* grid view */
#view-toggle { margin-left: auto; }
.job-list.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-items: start; }
.gcard { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.thumb { position: relative; width: 100%; aspect-ratio: 39 / 56; overflow: hidden; background: #0a0d12; }
.thumb iframe { width: 390px; height: 560px; border: 0; transform-origin: 0 0; pointer-events: none; }
.noresult { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 30px; }
.gname2 { padding: 8px 10px 2px; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow { display: flex; align-items: center; gap: 8px; padding: 6px 10px 10px; }
.grow .dl-btn { margin-left: auto; }
.job-row { padding: 12px 14px; cursor: pointer; }
.job-row.sub { border-top: 1px solid var(--border); padding-left: 28px; position: relative; }
.job-row.sub::before { content: ''; position: absolute; left: 14px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.job-row .row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.job-row .title { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-row .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.queued { background: #1f2937; color: var(--muted); }
.badge.running { background: rgba(210,153,34,.15); color: var(--yellow); }
.badge.done { background: rgba(63,185,80,.15); color: var(--green); }
.badge.error { background: rgba(248,81,73,.15); color: var(--red); }
.badge.cancelled { background: #1f2937; color: var(--muted); }

/* detail */
.detail { position: fixed; inset: 0; background: var(--bg); z-index: 8; display: flex; flex-direction: column; }
.detail-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.detail-header button { background: none; border: none; color: var(--accent); font-size: 17px; font-weight: 600; }
.detail-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.detail-title { font-weight: 600; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { display: inline-block; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.warn { color: var(--yellow); }
.btn.danger { color: var(--red); }
.progress { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow-y: auto; }
.progress .ev { display: flex; gap: 8px; }
.progress .ev .ico { flex-shrink: 0; }
.progress .ev.tool { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.progress .ev.info { color: var(--yellow); }
.progress .ev.error { color: var(--red); font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.health { font-size: 13px; color: var(--muted); }
.health.warn { color: var(--yellow); font-weight: 600; }
.progress .ev.text { white-space: pre-wrap; word-break: break-word; }
.result-text { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; color: var(--muted); }
.followup { display: flex; flex-direction: column; gap: 8px; padding-bottom: 24px; }
