:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --border: #e2e6ea;
  --accent: #1a73e8;
  --accent-hover: #1560c4;
  --error: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 20px;
}

.auth-card { max-width: 380px; margin: 8vh auto; }

h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

label { display: block; margin-bottom: 12px; font-size: 0.9rem; color: var(--muted); }
input, textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem;
  color: var(--text); background: #fff;
}

button {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 9px 16px; font-size: 0.95rem; cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.ghost:hover { background: #eef4fd; }

.muted { color: var(--muted); font-size: 0.88rem; }
.error { color: var(--error); font-weight: 600; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.row-between { display: flex; justify-content: space-between; align-items: center; }
.videos-toolbar { display: flex; gap: 10px; align-items: center; }
.folder-picker { display: flex; gap: 6px; align-items: center; margin: 0; font-size: 0.85rem; white-space: nowrap; }
.folder-picker select { width: auto; min-width: 160px; max-width: 320px; margin: 0; }
/* 一覧の「字幕焼込」チェック、アップロードフォームのインラインチェック */
.cap-check { display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; font-size: 0.85rem; margin: 0; }
.cap-check input { width: auto; margin: 0; }
.check-inline { display: flex; gap: 6px; align-items: center; font-weight: normal; }
.check-inline input { width: auto; margin: 0; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.8rem; background: #eee; color: var(--muted);
}
.pill.ok { background: #e3f5e9; color: #1b7a3d; }
.pill.ng { background: #fde8e6; color: var(--error); }

/* 2ペインのレイアウト */
.app-shell { display: flex; flex-direction: column; }
.brand { font-size: 1.3rem; font-weight: 700; }
.layout { display: flex; gap: 18px; align-items: flex-start; }

.sidebar {
  flex: 0 0 180px; position: sticky; top: 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; display: flex; flex-direction: column; gap: 4px;
}
.nav-item {
  display: block; padding: 9px 12px; border-radius: 6px; text-decoration: none;
  color: var(--text); font-size: 0.95rem;
}
.nav-item:hover { background: #eef4fd; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-group {
  font-size: 0.72rem; color: var(--muted); margin: 12px 10px 2px; letter-spacing: 0.03em;
  border-top: 1px solid var(--border); padding-top: 10px;
}
.nav-sub { padding-left: 22px; font-size: 0.9rem; }

/* 統計のタイル・テーブル・ダウンロード */
.stat-tiles { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tile {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; min-width: 120px;
}
.tile .num { font-size: 1.5rem; font-weight: 700; }
.tile .lbl { font-size: 0.8rem; color: var(--muted); }

table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data th, table.data td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 600; }
table.data tbody tr:hover { background: #f7f9fb; }

.matrix-controls { font-size: 0.88rem; color: var(--muted); margin-bottom: 12px; display: flex; gap: 14px; align-items: center; }
.matrix-controls label { display: inline; margin: 0; }
.matrix-controls input { display: inline; width: auto; margin: 0 4px 0 0; }

.dl-links { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.dl-filter {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px;
  padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel, transparent);
}
.dl-filter > strong { align-self: center; }
.dl-filter label { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 0.82rem; color: var(--muted); }
.dl-filter select, .dl-filter input { margin: 0; }
.dl-filter #dlf-value { min-width: 240px; }
.dl-filter-hint { flex-basis: 100%; font-size: 0.8rem; line-height: 1.5; }
.dl-table { border-collapse: collapse; font-size: 0.9rem; }
.dl-table th, .dl-table td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.dl-table th { color: var(--muted); font-weight: 600; }
.dl-table .btn-like { padding: 5px 14px; font-size: 0.85rem; }
.btn-like {
  display: inline-block; background: var(--accent); color: #fff; text-decoration: none;
  padding: 9px 16px; border-radius: 6px; font-size: 0.95rem;
}
.btn-like:hover { background: var(--accent-hover); }

.content { flex: 1 1 auto; min-width: 0; }
.view { }

/* 動画一覧（1動画=4行のコンパクト表示） */
.video-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  margin-bottom: 10px; display: grid; grid-template-columns: 16px 120px 1fr; gap: 12px;
  align-items: start;
}
.video-item img { width: 120px; height: 68px; object-fit: cover; border-radius: 4px; background: #ddd; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; align-self: center; font-size: 1.05rem; }
.drag-handle:active { cursor: grabbing; }
.video-item.dragging { opacity: 0.5; outline: 2px dashed var(--accent); }
.vi-thumb { cursor: pointer; transition: opacity 0.15s, outline-color 0.15s; outline: 2px solid transparent; }
.vi-thumb:hover { opacity: 0.85; outline-color: var(--accent); }
.vi-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.vi-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.vi-title { font-weight: 600; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vi-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.vi-meta { font-size: 0.82rem; color: var(--muted); }
.vi-meta .dim { opacity: 0.7; }
.vi-url { font-size: 0.82rem; display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.vi-url-label { flex: 0 0 auto; }
.vi-url a { color: var(--accent); text-decoration: none; }
.vi-url a:hover { text-decoration: underline; }
.vi-url-link { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy-btn, .embed-btn { flex: 0 0 auto; font-size: 0.75rem; padding: 2px 8px; }
.copy-msg { flex: 0 0 auto; font-size: 0.78rem; white-space: nowrap; }
.vimeo-link { color: inherit; text-decoration: underline; text-decoration-style: dotted; }
.vimeo-link:hover { color: var(--accent); }
.vi-constraints { display: flex; gap: 8px; align-items: center; }
.vi-constraints input {
  margin: 0; padding: 5px 8px; font-size: 0.82rem; flex: 1 1 0; min-width: 0;
}
.vi-constraints select {
  display: inline-block; width: auto; margin: 0; padding: 5px 8px;
  font-size: 0.82rem; flex: 0 0 auto;
}
.vi-msg { flex: 0 0 auto; font-size: 0.8rem; }

/* 状態ラベルと行内アクションは同じ小さめフォントに揃える */
.sel-label { font-size: 0.8rem; color: var(--muted); }
.sel-label.on { color: #1b7a3d; font-weight: 600; }
.sel-label.warn { color: #b26b00; font-weight: 600; }
.sel-label.err { color: var(--error); font-weight: 600; }
.vi-actions button { font-size: 0.8rem; padding: 4px 10px; }

button.danger { color: var(--error); }
button.danger:hover { background: #fde8e6; }

.content-id { font-family: ui-monospace, monospace; background: #f0f3f6; padding: 1px 6px; border-radius: 4px; }

/* トグルスイッチ */
.switch { position: relative; display: inline-block; width: 42px; height: 23px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: #ccd2d8;
  border-radius: 999px; transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute; height: 17px; width: 17px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: #1b7a3d; }
.switch input:checked + .slider::before { transform: translateX(19px); }

code { font-family: ui-monospace, monospace; background: #f0f3f6; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }

/* アップロードのドラッグ&ドロップ */
.dropzone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 26px 16px;
  text-align: center; cursor: pointer; color: var(--muted); background: #fafbfc;
  transition: border-color 0.15s, background 0.15s, color 0.15s; margin-bottom: 12px;
}
.dropzone:hover { border-color: var(--accent); background: #f2f7fe; }
.dropzone.dragover { border-color: var(--accent); background: #e6f0fe; color: var(--accent); }
.dz-input { display: none; }
.dz-text { font-size: 0.95rem; line-height: 1.5; }
.dz-file { margin-top: 8px; font-weight: 600; color: var(--text); }

/* 字幕編集モーダル */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 1000; overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 12px; width: 100%; max-width: 760px;
  border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head strong { font-size: 1.05rem; }
.modal-close { font-size: 1.1rem; line-height: 1; padding: 4px 10px; }
.modal-body { padding: 16px 18px; max-height: 78vh; overflow-y: auto; }
.modal-body h3 { font-size: 1rem; margin: 6px 0 10px; }
.cc-form-title { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.cc-form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.cc-form-row label { flex: 1 1 130px; margin-bottom: 8px; }
.cc-inline { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.cc-inline input { width: auto; margin: 0; }
.cc-content { font-family: ui-monospace, monospace; font-size: 0.85rem; }
.cc-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.tt-ops { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.tt-ops button, .btn-mini { font-size: 0.78rem; padding: 3px 8px; }
.btn-mini {
  display: inline-block; border: 1px solid var(--border); border-radius: 6px;
  color: var(--accent); text-decoration: none;
}
.btn-mini:hover { background: #eef4fd; }

/* 視聴ページ（青山学院大学のシンボルカラー=濃緑） */
.watch-body { background: #0b5c39; }
.player-wrap { max-width: 1080px; margin: 0 auto; padding: 16px; }
.watch-title { color: #ffffff; font-size: 1.15rem; margin: 8px 4px 14px; }

/* 動画枠。まず16:9でスペースを確保し、読み込み後に動画の実比率へ合わせて
   比率違いの黒い余白(レターボックス)を無くす。背景も濃緑にして黒を出さない。
   スマホ横向きなど高さが足りない画面では、幅を比率に合わせて縮めて
   動画全体(下端の字幕まで)が見えている高さ(dvh)に収まるようにする。
   --arw/--arh: 動画の実比率(JSが更新) / --above: 枠より上にある高さ(JSが実測)。 */
.video-box {
  width: 100%;              /* dvh/min() 非対応ブラウザ向けフォールバック */
  max-height: 80vh;         /* 同フォールバック(下の width が効けば実質無効) */
  width: min(100%, calc((100dvh - var(--above, 130px)) * var(--arw, 16) / var(--arh, 9)));
  max-width: 1020px; margin: 0 auto; aspect-ratio: 16 / 9;
  background: #0b5c39; border-radius: 10px; overflow: hidden;
  border: 1px solid #12855a;
}
.video-box #player, .video-box iframe { width: 100%; height: 100%; border: 0; }

.watch-desc {
  max-width: 1020px; margin: 16px auto 4px; padding: 14px 16px; color: #eaf5ee;
  background: #083f28; border: 1px solid #12855a; border-radius: 8px;
  font-size: 0.92rem; line-height: 1.7; white-space: normal; word-break: break-word;
}
.watch-desc .ts-link { color: #8fe8b8; text-decoration: none; font-weight: 600; }
.watch-desc .ts-link:hover { text-decoration: underline; }

/* 埋め込みモード(/watch?embed=1): タイトル・説明・余白なしで動画をiframe全面に表示 */
.watch-body.embed { margin: 0; }
.embed .player-wrap { max-width: none; padding: 0; }
.embed .video-box {
  width: 100%; max-width: none; aspect-ratio: auto;
  height: 100vh; height: 100dvh; max-height: none;
  border: 0; border-radius: 0;
}

/* マニュアル表示（/admin/manual, docs/マニュアル.md のHTML化） */
.manual-doc { max-width: 860px; margin: 24px auto; line-height: 1.8; }
.manual-doc h1 { font-size: 1.5rem; margin-bottom: 14px; }
.manual-doc h2 { font-size: 1.15rem; margin: 26px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.manual-doc table { border-collapse: collapse; margin: 10px 0; font-size: 0.92rem; }
.manual-doc th, .manual-doc td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.manual-doc th { background: #f2f6fb; }
.manual-doc code { background: #f2f4f8; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.manual-doc li { margin: 3px 0; }

