* { box-sizing: border-box; }
:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel2: #232730;
  --border: #333845;
  --text: #dfe3ea;
  --muted: #8a93a5;
  --accent: #4c9ffe;
  --sp1: #4c9ffe;
  --sp2: #ffb057;
  --danger: #e06060;
}
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", sans-serif;
  font-size: 13px; display: flex; flex-direction: column;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
.sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
header h1 { font-size: 15px; margin: 0 8px 0 0; font-weight: 600; }

button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 10px; cursor: pointer; font-size: 13px;
}
button:hover { background: #2b3140; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
select, input[type=number] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 6px; font-size: 13px;
}
input[type=number] { width: 62px; }
label { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
label.chk { gap: 3px; cursor: pointer; }

.job-status { color: var(--accent); font-variant-numeric: tabular-nums; }
.job-status.error { color: var(--danger); }
.batch-status { color: var(--sp2); font-variant-numeric: tabular-nums; font-size: 12px; }
.save-status { color: var(--muted); font-size: 12px; }

.setup-panel { padding: 40px; text-align: center; color: var(--muted); font-size: 14px; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.video-row {
  display: flex; gap: 8px; padding: 8px 12px 0; justify-content: center;
  background: var(--bg);
}
.video-box { position: relative; }
.video-box video { height: 170px; border-radius: 6px; background: #000; display: block; }
.video-box .badge {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  font-size: 11px; padding: 1px 7px; border-radius: 4px; color: #fff; opacity: .9;
}
.badge.sp1 { background: var(--sp1); }
.badge.sp2 { background: var(--sp2); }
.video-caption {
  position: absolute; left: 4px; right: 4px; bottom: 6px; text-align: center;
  color: #fff; font-size: 13px; line-height: 1.45;
  text-shadow: 0 1px 3px #000;
  background: rgba(0,0,0,.45); border-radius: 4px; padding: 2px 8px;
  pointer-events: none;
}
.video-caption:empty { display: none; }

.ctx-menu {
  position: fixed; z-index: 200; min-width: 150px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; display: flex; flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.ctx-menu button {
  background: none; border: none; text-align: left; padding: 7px 12px;
  border-radius: 5px; font-size: 13px;
}
.ctx-menu button:hover:not(:disabled) { background: var(--panel2); }
.ctx-menu button:disabled { opacity: .35; }

.transport {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex-wrap: wrap;
}
.play-btn { width: 44px; font-size: 15px; }
.time-display { font-variant-numeric: tabular-nums; min-width: 150px; }
.zoom-label {
  color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums;
  min-width: 34px; display: inline-block; text-align: center;
}
.vad-panel { position: relative; }
.vad-panel summary { cursor: pointer; color: var(--muted); user-select: none; }
.vad-controls {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; display: flex; flex-direction: column; gap: 8px; width: 240px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.vad-controls label { justify-content: space-between; }

.wave-scroll {
  position: relative; overflow-x: scroll; overflow-y: hidden;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: #101216; flex-shrink: 0;
}
.wave-spacer { height: 1px; }
#waveCanvas {
  position: sticky; left: 0; top: 0; display: block; cursor: crosshair;
}
/* 波形上のテキスト編集窓 (区間クリックで開く) */
#waveEditBox {
  position: absolute; z-index: 6; display: none;
  background: rgba(13, 16, 22, .93); color: var(--text);
  border: 1.5px solid var(--accent); border-radius: 6px;
  padding: 5px 8px; font: inherit; font-size: var(--seg-font, 13px);
  line-height: 1.5; resize: none; overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
#waveEditBox:focus { outline: none; }

/* 作業一覧の「自分の稼働状況」 */
.my-activity { margin-top: 22px; }
.my-activity summary { cursor: pointer; color: var(--muted); font-size: 13px; user-select: none; }
.my-activity .act-controls { display: flex; gap: 6px; align-items: center; margin: 10px 0; }
.my-activity .act-controls input[type="date"] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 8px; font-size: 13px;
}

/* 波形とリストの間の仕切りバー (ドラッグで高さ調整) */
.v-split {
  height: 8px; cursor: ns-resize; flex-shrink: 0;
  background: var(--bg); position: relative;
}
.v-split::after {
  content: ""; position: absolute; left: 50%; top: 3px;
  width: 48px; height: 3px; margin-left: -24px;
  border-radius: 2px; background: #3a4150;
}
.v-split:hover::after, .v-split:active::after { background: #6b7890; }

.bottom { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.seg-toolbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.sel-info { min-width: 180px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { color: #5a6272; font-size: 11px; margin-left: auto; }

.seg-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.seg-row {
  display: flex; align-items: flex-start; gap: 8px; padding: 4px 12px;
  border-left: 3px solid transparent;
}
.seg-row:hover { background: #1a1d24; }
.seg-row.playing { background: #1f1b1b; border-left-color: #ff5252; }
.seg-row.playing .seg-time { color: #ff8a8a; }
.seg-row.selected { background: #20293a; border-left-color: var(--accent); }
.seg-row .seg-time {
  font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px;
  width: 128px; flex-shrink: 0; padding-top: 5px; cursor: pointer;
}
.seg-row .seg-badge {
  flex-shrink: 0; margin-top: 4px; font-size: 11px; padding: 1px 7px;
  border-radius: 4px; color: #fff; cursor: pointer;
}
.seg-row textarea {
  flex: 1; background: transparent; color: var(--text); border: 1px solid transparent;
  border-radius: 4px; resize: none; font: inherit; padding: 4px 6px; line-height: 1.5;
  overflow: hidden;
  font-size: var(--seg-font, 13px);  /* 作業者ごとに「文字 −/＋」で変更できる */
}
.seg-row textarea:focus { background: var(--panel2); border-color: var(--border); outline: none; }
/* テキスト欄の上に重ねるレイヤー: 使用禁止文字だけを赤く表示する (それ以外は透明) */
.seg-row .ta-wrap { flex: 1; position: relative; display: flex; }
.seg-row .ta-mark {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
  padding: 4px 6px; border: 1px solid transparent; border-radius: 4px;
  font: inherit; font-size: var(--seg-font, 13px); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: break-word;
  color: transparent;
}
.seg-row .ta-mark .bad {
  font-style: normal; color: #ff5252;
  background: rgba(255, 82, 82, .16); border-radius: 2px;
}
.seg-row .row-play { flex-shrink: 0; padding: 2px 8px; }
.seg-row input.seg-done {
  flex-shrink: 0; margin-top: 7px; width: 15px; height: 15px;
  accent-color: #7fd18c; cursor: pointer;
}
.seg-row .asr-pending { color: var(--muted); font-style: italic; }

/* ---- アカウント/一覧ページ ---- */
.center-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px 40px; width: 340px;
}
.login-box h1 { font-size: 16px; margin: 0 0 20px; text-align: center; }
.login-box form { display: flex; flex-direction: column; gap: 14px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.login-box input {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 14px;
}
.login-box button { padding: 9px; font-size: 14px; }
.login-error { color: var(--danger); font-size: 12px; min-height: 16px; }

.page-wrap { padding: 14px 18px; overflow-y: auto; flex: 1; }
.list-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.list-table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 6px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--bg);
}
.list-table td { padding: 6px 10px; border-bottom: 1px solid #23262e; }
.list-table tr:hover td { background: #1a1d24; }
.inactive-row td { opacity: .45; }
.muted { color: var(--muted); font-size: 12px; }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px;
  margin-left: 6px;
}
.tag.ok { background: #1d3a24; color: #7fd18c; }
.tag.warn { background: #3a2d1d; color: #d1a97f; }
.tag.info { background: #1d2a3a; color: #7fb0d1; }
.bar {
  width: 110px; height: 8px; background: #262a33; border-radius: 4px;
  display: inline-block; margin-right: 8px; vertical-align: middle;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.btn-link {
  color: var(--accent); text-decoration: none; border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 12px;
}
.btn-link:hover { background: #2b3140; }
.filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.bulk-bar {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin-top: -4px;
}
.chk-col { width: 30px; text-align: center; }
.chk-col input { cursor: pointer; }
.filter-bar input[type=text] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 8px; width: 200px;
}
.add-user-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-user-form input {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 8px;
}
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tab { border-radius: 5px 5px 0 0; border-bottom: none; opacity: .6; }
.tab.active { opacity: 1; background: var(--panel2); border-color: var(--accent); }
.user-label { color: var(--muted); font-size: 12px; }
.memo-input {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 8px; width: 200px; font-size: 12px;
}
/* エディタ上部のメモ欄: 右下ドラッグで自由にサイズ変更できる */
.memo-area {
  resize: both; overflow: auto; flex-shrink: 0;
  height: 26px; min-height: 26px; min-width: 120px;
  max-width: 860px; max-height: 340px;
  font-family: inherit; line-height: 1.5; vertical-align: middle;
}
#memoResetBtn { padding: 2px 6px; font-size: 12px; margin-left: 2px; }
.memo-input.wide { width: 95%; min-width: 160px; }
.back-link { color: var(--muted); text-decoration: none; margin-right: 4px; }
.back-link:hover { color: var(--text); }
.pw-display {
  font-family: Consolas, monospace; font-size: 22px; letter-spacing: 2px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; text-align: center; margin: 10px 0; user-select: all;
}

/* ---- 遊び心パック ---- */
#comboBadge {
  position: fixed; right: 24px; bottom: 24px; z-index: 500;
  background: linear-gradient(135deg, #2b8a3e, #7fd18c); color: #fff;
  font-weight: 700; font-size: 15px; padding: 10px 18px; border-radius: 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4); opacity: 0; pointer-events: none;
  transform: translateY(10px) scale(.8);
}
#comboBadge.pop { animation: comboPop 1.6s ease forwards; }
@keyframes comboPop {
  0% { opacity: 0; transform: translateY(14px) scale(.6); }
  12% { opacity: 1; transform: translateY(0) scale(1.12); }
  20% { transform: translateY(0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px) scale(.95); }
}
/* 一覧の行がじんわり浮かび上がる */
@keyframes rowFadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 20px 24px; width: 420px;
}
.modal-box h2 { margin: 0 0 12px; font-size: 15px; }
#modalSteps { display: flex; flex-direction: column; gap: 6px; }
.modal .note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---------------- 行内の操作ボタン (前と結合/次と結合/削除/✓/再認識) ---------------- */
.seg-btns {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0; margin-left: 4px;
}
.row-btn {
  font-size: 11px; padding: 2px 7px; line-height: 1.5;
  background: #232833; color: #c6ccd8; border: 1px solid var(--border);
  border-radius: 5px; cursor: pointer; white-space: nowrap;
}
.row-btn:hover { background: #2d3442; }
.row-btn.danger { color: #ff8a80; }
.row-btn.danger:hover { background: #3a2426; }

/* ---------------- テキスト検索バー ---------------- */
.search-bar {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px;
  border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.search-bar input[type="text"] { width: 240px; }
.search-bar .chk { font-size: 12px; color: var(--muted); }
.seg-row.search-hit { background: #14202e; border-left-color: #4c9ffe66; }
.seg-row.search-hit.selected { background: #1a2a40; }

/* ---------------- 一括チェック (エディタ内パネル) ---------------- */
.check-panel {
  border-bottom: 1px solid var(--border); background: #14161c;
  max-height: 170px; display: flex; flex-direction: column; flex-shrink: 0;
}
.check-head {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 12px; font-weight: 700; font-size: 12px;
}
.check-head button { font-size: 11px; }
.check-head #checkClose {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 0 4px;
}
.check-list { overflow-y: auto; padding: 0 0 6px; }
.check-item {
  padding: 3px 18px; font-size: 12px; cursor: pointer; color: #ffb057;
}
.check-item:hover { background: #1e222b; }

/* ---------------- 管理画面: ボット・ルールタブ ---------------- */
.settings-grid { display: flex; flex-direction: column; gap: 16px; max-width: 920px; }
.settings-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 18px 16px;
}
.settings-box h2 { font-size: 14px; margin: 0 0 8px; }
.settings-box label { display: block; margin: 8px 0; }
.settings-box .note { color: var(--muted); font-size: 12px; line-height: 1.7; margin: 4px 0 10px; }
.settings-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.doc-edit {
  width: 100%; box-sizing: border-box; height: 340px; resize: vertical;
  background: #101216; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; font-family: Consolas, "MS Gothic", monospace;
  font-size: 12.5px; line-height: 1.6;
}

/* ---------------- 常駐マスコット (あるとぼーや) ---------------- */
#mascotDock {
  position: fixed; right: 16px; bottom: 12px; z-index: 90;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#mascotDock .hidden { display: none; }
/* 画面上半分にいるとき: 吹き出し・チャットはマスコットの下に開く */
#mascotDock.top-mode { flex-direction: column-reverse; }
#mascotDock.top-mode #mascotBubble { margin-top: 6px; }
#mascotDock.top-mode #mascotBubble::after {
  bottom: auto; top: -9px;
  border: 9px solid transparent; border-bottom-color: #2e2a26; border-top: none;
}
#mascotDock.top-mode #chatResize {
  top: auto; bottom: 0; border-radius: 0 0 0 12px; cursor: sw-resize;
}
#mascotDock.top-mode #chatResize::after {
  top: auto; bottom: 4px;
  border-top: none; border-bottom: 2px solid var(--muted);
  border-radius: 0 0 0 2px;
}
#mascotImg {
  cursor: pointer; filter: drop-shadow(0 2px 5px rgba(0,0,0,.35));
  animation: mascotIdle 1.15s ease-in-out infinite;  /* 普段からリズムに乗って小刻みにゆれる */
}
#mascotImg:hover { animation-duration: .6s; }  /* 触られるとノリノリになる */
#mascotDock.talking #mascotImg { animation: mascotTalking .38s ease-in-out infinite; }
@keyframes mascotIdle {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-2.5px) rotate(1.5deg); }
}
@keyframes mascotTalking {
  0%, 100% { transform: translateY(0) rotate(-2.5deg) scale(1); }
  50% { transform: translateY(-3.5px) rotate(2.5deg) scale(1.05); }
}
#mascotBubble {
  max-width: 230px; background: #fdfaf3; color: #2e2a26;
  border: 2px solid #2e2a26; border-radius: 12px; padding: 8px 12px;
  font-size: 13px; font-weight: 700; position: relative; margin-right: 8px;
}
#mascotBubble::after {
  content: ""; position: absolute; right: 22px; bottom: -9px;
  border: 9px solid transparent; border-top-color: #2e2a26; border-bottom: none;
}
#mascotBubble.pop { animation: bubblePop .25s ease; }
@keyframes bubblePop {
  0% { opacity: 0; transform: translateY(8px) scale(.8); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
#mascotChat {
  width: 300px; height: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  position: relative;  /* サイズ変更つまみの基準 */
}
#mascotChat.hidden { display: none; }
#chatResize {
  position: absolute; left: 0; top: 0; width: 18px; height: 18px;
  cursor: nw-resize; z-index: 2; border-radius: 12px 0 0 0;
}
#chatResize::after {
  content: ""; position: absolute; left: 4px; top: 4px;
  width: 8px; height: 8px;
  border-left: 2px solid var(--muted); border-top: 2px solid var(--muted);
  border-radius: 2px 0 0 0;
}
#chatResize:hover::after { border-color: #cfd6e4; }
#mascotChat .chat-head {
  padding: 8px 10px; font-size: 13px; font-weight: 700;
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 6px;
}
#mascotChat .chat-hint { font-weight: 400; font-size: 10px; color: var(--muted); flex: 1; }
#mascotChat #chatClose {
  background: none; border: none; color: var(--muted); font-size: 16px;
  cursor: pointer; padding: 0 4px;
}
#chatMsgs { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg {
  max-width: 85%; padding: 7px 10px; border-radius: 10px;
  font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.chat-msg.bot { align-self: flex-start; background: #fdfaf3; color: #2e2a26; border: 1px solid #d8d2c4; }
.chat-msg.user { align-self: flex-end; background: var(--accent, #4c9ffe); color: #fff; }
#chatForm { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); align-items: flex-end; }
#chatForm textarea {
  flex: 1; min-width: 0; resize: none; min-height: 30px; max-height: 110px;
  font: inherit; line-height: 1.5; padding: 5px 8px; box-sizing: border-box;
  background: #101216; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
}
#chatForm button { white-space: nowrap; }
