:root {
  --bg: #14161a;
  --panel: #1d2128;
  --panel2: #252b34;
  --fg: #e6e8eb;
  --muted: #97a0ad;
  --accent: #4f8cff;
  --accent2: #2f6fe0;
  --error: #ff6b6b;
  --border: #2e3540;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  font-size: 16px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0 0 10px; }

a { color: var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 18px;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--error); font-size: 13px; }

input[type="text"], input[type="number"], textarea, select {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}
textarea { width: 100%; resize: vertical; }

button, .btn {
  background: var(--accent2);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--accent); }
button:disabled { background: #3a414c; cursor: not-allowed; color: var(--muted); }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); }

.tbl { width: 100%; border-collapse: collapse; margin-top: 8px; }
.tbl th, .tbl td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.tbl td.cell-nowrap { white-space: nowrap; }

.status-pending { color: var(--muted); }
.status-analyzing { color: #ffd166; }
.status-done { color: #4ade80; }
.status-error { color: var(--error); }

.progress-box { margin: 10px 0; }
.progress { height: 10px; background: var(--panel2); border-radius: 5px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.segments { margin-top: 10px; max-height: 360px; overflow-y: auto; }
.seg {
  display: flex; align-items: center; gap: 8px;
  padding: 6px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.seg:hover { background: var(--panel2); }
.time { color: var(--muted); width: 48px; flex: none; font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; flex: none; }
.badge.sp { background: #2f4a8a; }
.badge.sc { background: #3a6a3a; }
.thumb { width: 80px; height: 45px; object-fit: cover; border-radius: 4px; flex: none; }
.txt { flex: 1; }

/* 素材一覧: サムネイル(ホバースクラブ)・インサート用 */
.ta-center { text-align: center; }
.v-scrub {
  position: relative; width: 160px; aspect-ratio: 16 / 9;
  background: #000; border-radius: 4px; overflow: hidden; cursor: ew-resize;
}
.v-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.v-scrub-bar {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 0;
  background: #e23b3b; pointer-events: none;
}
.badge-insert {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: #8a4a2f; color: #fff; vertical-align: middle;
}
tr.row-insert > td { background: rgba(138, 74, 47, 0.12); }
.auto-badge {
  display: inline-block; margin-left: 4px; font-size: 9px; padding: 1px 4px;
  border-radius: 3px; background: #4a7a3f; color: #fff; vertical-align: middle;
  cursor: help;
}
.v-tags { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 3px; }
.tag-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: #2f5a8a; color: #fff;
}
.btn-sm { font-size: 12px; padding: 3px 8px; white-space: nowrap; }
.v-reanalyze-prog { font-size: 11px; margin-top: 4px; max-width: 160px; }

/* timeline layout */
.tl-layout { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.tl-main, .tl-chat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px;
}
@media (max-width: 900px) { .tl-layout { grid-template-columns: 1fr; } }

.clips .num { width: 70px; }
.num-wide { width: 140px; padding: 4px 6px; }
.clips .note { width: 100%; min-width: 120px; }
.clips .handle { cursor: grab; color: var(--muted); }
.dirty { color: #ffd166; font-size: 13px; margin-right: 8px; }

.chat-history { max-height: 420px; overflow-y: auto; margin-bottom: 10px; }
.msg { padding: 8px 10px; border-radius: 6px; margin-bottom: 6px; white-space: pre-wrap; }
.msg.user { background: var(--panel2); }
.msg.assistant { background: #233040; }

/* ============ NLE タイムライン編集UI ============ */
.nle { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.nle-top { display: grid; grid-template-columns: 1fr 320px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .nle-top { grid-template-columns: 1fr; } }
.nle-preview { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.preview-stage { position: relative; width: 100%; }
.preview-stage #preview { width: 100%; max-height: 360px; background: #000; border-radius: 6px; display: block; }
/* オーバーレイ用の上層動画。メインの上に被せる(音声なし) */
.preview-stage #preview-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: transparent; border-radius: 6px;
  pointer-events: none; z-index: 2;
}
.nle-top .tl-chat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px;
}

/* ツールバー */
.nle-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
}
.nle-toolbar .tl-time { font-variant-numeric: tabular-nums; }
.nle-toolbar .tl-sep { width: 1px; height: 22px; background: var(--border); }
.zoom-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.zoom-label input[type="range"] { width: 140px; }
.toggle-btn { background: #3a414c; }
.toggle-btn:hover { background: #4a525e; }
.toggle-btn.active { background: var(--accent2); }
.toggle-btn.active:hover { background: var(--accent); }

/* 下段: 素材パネル + タイムライン */
.nle-body { display: grid; grid-template-columns: 240px 1fr; gap: 10px; align-items: stretch; min-height: 220px; }
@media (max-width: 900px) { .nle-body { grid-template-columns: 1fr; } }

.nle-sources {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; max-height: 360px; overflow-y: auto;
}
.source-list { display: flex; flex-direction: column; gap: 6px; }
.source-item { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.source-head {
  display: flex; gap: 8px; align-items: center; padding: 6px;
  cursor: pointer; background: var(--panel2);
}
.source-head:hover { background: #2c333d; }
.source-thumb {
  position: relative; width: 56px; height: 32px; flex: none; border-radius: 4px;
  background: #000; overflow: hidden; cursor: ew-resize;
}
.source-thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.source-thumb-bar {
  position: absolute; left: 0; bottom: 0; height: 2px; width: 0;
  background: #e23b3b; pointer-events: none;
}
.source-insert-badge {
  display: inline-block; font-size: 9px; padding: 0 4px; border-radius: 3px;
  background: #8a4a2f; color: #fff; vertical-align: middle;
}
.source-insert .source-head { background: rgba(138, 74, 47, 0.18); }
.source-meta { min-width: 0; flex: 1; }
.source-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-fn { font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-dur { font-size: 11px; }
.source-segs { padding: 4px 6px; background: var(--bg); }
.source-seg {
  display: flex; align-items: center; gap: 6px; padding: 4px 2px;
  font-size: 11px; cursor: grab; border-bottom: 1px solid var(--border);
}
.source-seg:last-child { border-bottom: none; }
.source-seg .seg-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }

/* タイムライン本体 */
.nle-timeline {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; overflow-x: auto; overflow-y: hidden; position: relative;
}
.tl-inner { position: relative; min-width: 100%; }
/* 左ラベル列の幅。ルーラーもこの分だけ左にパディングして揃える */
:root { --tl-label-w: 56px; }
.tl-ruler {
  position: relative; height: 24px; border-bottom: 1px solid var(--border);
  background: var(--panel2); cursor: pointer; user-select: none;
  margin-left: var(--tl-label-w);
}
.tl-tick { position: absolute; top: 0; height: 100%; border-left: 1px solid var(--border); }
.tl-tick-label {
  position: absolute; left: 3px; top: 4px; font-size: 10px;
  color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none;
}
/* レーン群 + 左ラベル列 */
.tl-stage { position: relative; display: flex; align-items: flex-start; }
.tl-labels {
  position: sticky; left: 0; z-index: 7;
  width: var(--tl-label-w); flex: 0 0 var(--tl-label-w);
  background: var(--panel);
}
.tl-label {
  display: flex; flex-direction: column; justify-content: center;
  align-items: center; gap: 2px;
  border-bottom: 1px solid var(--border); background: var(--panel2);
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.tl-label.main { background: #2a3340; color: var(--fg); }
.tl-label-tag { font-size: 9px; font-weight: 400; color: var(--muted); }
.tl-lanes { position: relative; flex: 1; }
.tl-lanes-content { position: relative; }
.tl-lane {
  position: relative; border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(90deg, transparent, transparent 49px, rgba(255,255,255,0.03) 49px, rgba(255,255,255,0.03) 50px);
}
.tl-lane.main { background-color: rgba(79,140,255,0.05); }
.tl-clip {
  position: absolute; top: 4px; height: 64px; overflow: hidden;
  background: #2f4a8a;
  border: 1px solid #3a5aa8; border-radius: 5px;
  color: #fff; cursor: grab; user-select: none; touch-action: none;
}
/* オーバーレイ(V2以上)クリップは色分け */
.tl-clip.overlay { background: #6a4a2f; border-color: #8a6238; }
.tl-clip.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); z-index: 2; }
.tl-clip.ghost { opacity: 0.6; pointer-events: none; z-index: 5; cursor: grabbing; }
/* フィルムストリップ: フレームサムネイルを横に敷き詰める */
.tl-strip {
  position: absolute; inset: 0; display: flex; align-items: stretch;
  pointer-events: none;
}
.tl-tile {
  width: 80px; height: 100%; flex: 0 0 80px;
  object-fit: cover; pointer-events: none; display: block;
  background: #233; user-select: none; -webkit-user-drag: none;
}
/* ラベルを読みやすくするグラデーションオーバーレイ */
.tl-clip-overlay {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 38%);
}
.tl-clip-name {
  position: relative; z-index: 1;
  font-size: 11px; padding: 4px 6px 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px #000, 0 0 3px #000;
}
.tl-clip-dur {
  position: relative; z-index: 1;
  font-size: 10px; padding: 0 6px; color: #eef3fa;
  font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px #000, 0 0 3px #000;
}
.tl-trim {
  position: absolute; top: 0; width: 8px; height: 100%;
  cursor: ew-resize; z-index: 3;
}
.tl-trim-l { left: 0; }
.tl-trim-r { right: 0; }
.tl-trim:hover { background: rgba(79,140,255,0.4); }
.tl-playhead {
  position: absolute; top: -24px; left: 0; width: 2px; height: calc(100% + 24px);
  background: #ff4040; z-index: 8; pointer-events: none;
}
.tl-insert {
  position: absolute; top: 0; left: 0; width: 2px; height: 100%;
  background: #ffd166; z-index: 6; pointer-events: none;
}

/* インスペクタ */
.nle-inspector {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; min-height: 44px;
  display: flex; align-items: center;
}
#insp-fields { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; width: 100%; }
.nle-inspector label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.nle-inspector .num { width: 80px; }
.nle-inspector .insp-name { font-weight: 600; }
.insp-track-badge { font-size: 12px; color: var(--muted); background: var(--panel2);
  border: 1px solid var(--border); border-radius: 4px; padding: 2px 8px; }
.insp-note-wrap { flex: 1; min-width: 160px; }
.insp-note { flex: 1; width: 100%; }
.del-btn { background: #8a2f2f; }
.del-btn:hover { background: #b33b3b; }

/* セマンティック検索(E)UI */
.src-search { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.src-search input { flex: 1; min-width: 120px; }
.src-search .error { width: 100%; margin: 0; }
.search-results { display: flex; flex-direction: column; gap: 6px; }
.search-result {
  display: flex; gap: 8px; align-items: flex-start; padding: 6px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel2);
  cursor: pointer;
}
.search-result:hover { background: #2c333d; }
.search-thumb { width: 72px; height: 40px; object-fit: cover; border-radius: 4px; flex: none; }
.search-meta { flex: 1; min-width: 0; }
.search-top { display: flex; gap: 8px; align-items: baseline; }
.search-name { font-weight: 600; font-size: 13px; }
.search-time { font-size: 12px; }
.search-score { margin-left: auto; font-size: 12px; color: var(--accent); }
.search-txt {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---- 素材詳細ページ(video_detail) ---- */
.vd-meta { display: flex; flex-direction: column; gap: 8px; max-width: 720px; }
.vd-field { display: block; }
.vd-field input[type="text"], .vd-field textarea { width: 100%; box-sizing: border-box; }
.vd-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.vd-left, .vd-right { min-width: 0; }
.vd-strip {
  position: relative; width: 100%; height: 64px;
  background: #000; border-radius: 4px; cursor: pointer; margin-top: 6px;
  touch-action: none;
}
.vd-strip-tiles {
  display: flex; width: 100%; height: 100%;
  overflow: hidden; border-radius: 4px;
}
.vd-strip-tiles img {
  flex: 1 1 0; min-width: 0; height: 100%;
  object-fit: cover; display: block; pointer-events: none;
}
.vd-strip-bar {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 0;
  background: #e23b3b; pointer-events: none;
}
.vd-strip-hover {
  position: absolute; bottom: calc(100% + 6px); transform: translateX(-50%);
  pointer-events: none; background: #11151c; border: 1px solid #3a4150;
  border-radius: 4px; padding: 3px 3px 1px; text-align: center; z-index: 5;
}
.vd-strip-hover img {
  width: 160px; aspect-ratio: 16 / 9; object-fit: cover;
  display: block; border-radius: 2px; background: #000;
}
.vd-strip-hover span { font-size: 11px; color: #cfd6e4; }
.vd-chapter {
  font-weight: bold; margin: 8px 0 4px; padding: 3px 6px;
  background: #2a2f3a; border-radius: 4px; font-size: 13px;
}
.vd-tag-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: #5a4a8a; color: #fff; flex: none;
}
.vd-ann-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.vd-ann-list { display: flex; flex-direction: column; gap: 6px; }
.vd-ann-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: #20242c; border-radius: 4px;
}
.vd-ann-item.editing { gap: 6px; }
.vd-ann-text { flex: 1; word-break: break-word; }
.vd-ann-kind-badge {
  font-size: 11px; padding: 1px 6px; border-radius: 4px; flex: none; color: #fff;
}
.vd-ann-kind-badge.note { background: #2f5a8a; }
.vd-ann-kind-badge.action { background: #8a652f; }
.vd-ann-auto {
  font-size: 9px; padding: 1px 4px; border-radius: 3px; background: #4a7a3f;
  color: #fff; flex: none;
}
.source-detail-link { text-decoration: none; font-size: 13px; color: #8ab4ff; }
.source-detail-link:hover { color: #b8d0ff; }

/* 素材一覧: 要約は列ではなく素材ごとの全幅行で表示する */
.v-main-row td { border-bottom: none; }
.v-summary-row td {
  padding-top: 0; font-size: 13px; color: var(--muted); line-height: 1.5;
}

/* タイムライン動画書き出しの進捗表示 */
.render-status {
  display: flex; align-items: center; gap: 12px;
  margin: 10px 0; padding: 10px 12px;
  background: var(--panel, #1b1b1f); border-radius: 6px;
}
.render-bar {
  flex: 1; height: 8px; min-width: 120px; max-width: 320px;
  background: #333; border-radius: 4px; overflow: hidden;
}
.render-bar-fill {
  height: 100%; width: 0; background: #4caf50;
  transition: width 0.3s ease;
}

/* ログイン画面 */
.login-wrap {
  max-width: 360px; margin: 8vh auto 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 28px 28px 32px;
}
.login-title { margin: 0 0 20px; font-size: 20px; }
.login-error { color: var(--error); margin: 0 0 16px; }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { color: var(--muted); font-size: 13px; margin-top: 10px; }
.login-form input[type="text"],
.login-form input[type="password"] {
  padding: 9px 11px; font-size: 14px;
  background: var(--panel2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
}
.login-form .btn-primary, .login-form button {
  margin-top: 20px; background: var(--accent2);
}

/* ヘッダのユーザー情報・ログアウト */
.topbar-user {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 13px;
}
.logout-form { margin: 0; }
.logout-btn {
  padding: 5px 10px; font-size: 12px;
  background: var(--panel2); border: 1px solid var(--border);
}
