/* X Live Server — デスクトップ版コンソールの世界観を Web に移したもの */
:root {
  --bg: #1c1c1e;
  --sidebar: #232324;
  --card: #2c2c2e;
  --control: #3a3a3c;
  --control-hover: #48484a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f5f5f7;
  --sub: #a1a1a6;
  --faint: #98989d;
  --blue: #0a84ff;
  --blue-btn: #0071e3;
  --blue-btn-hover: #0066d6;
  --green: #30d158;
  --red: #ff453a;
  --yellow: #ffd60a;
  --sel: #5a5a61;
  --hover: rgba(255, 255, 255, 0.06);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* display を持つ要素でも hidden 属性を必ず効かせる */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(10, 132, 255, 0.45); }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: #48484a; border-radius: 5px;
  border: 2px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 共通部品 ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: var(--control);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--control-hover); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: var(--control); }
.btn.primary { background: var(--blue-btn); color: #fff; }
.btn.primary:hover { background: var(--blue-btn-hover); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger-ghost { background: transparent; color: var(--red); }
.btn.danger-ghost:hover { background: rgba(255, 69, 58, 0.12); }
.btn.ghost { background: transparent; color: var(--sub); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.small { font-size: 12px; padding: 4px 10px; }
.btn.block { width: 100%; padding: 9px 14px; font-size: 14px; }

.avatar {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 16px;
  user-select: none;
}
.avatar.small { width: 26px; height: 26px; font-size: 12px; }
.avatar.row { width: 28px; height: 28px; font-size: 13px; }

.chip {
  flex: none;
  font-size: 12px;
  color: var(--sub);
  background: var(--card);
  border-radius: 7px;
  padding: 4px 10px;
}

.dot {
  flex: none;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--faint);
}
.dot.starting, .dot.stopping { background: var(--yellow); }
.dot.live { background: var(--green); }
.dot.error { background: var(--red); }

.badge {
  font-size: 11px; font-weight: 600;
  color: #1c1c1e; background: var(--yellow);
  border-radius: 5px; padding: 1px 6px;
}

/* トグルスイッチ（デスクトップ版と同じ見た目） */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 13px;
  background: #48484a; transition: background 0.18s ease;
  cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: transform 0.18s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--blue); outline-offset: 1px; }

/* セグメント切替（iOS版 / Web版） */
.segmented {
  display: inline-flex;
  background: var(--control);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  border: 0; background: transparent; color: var(--sub);
  font-size: 12.5px; font-weight: 500;
  padding: 4px 14px; border-radius: 6px; cursor: pointer;
}
.segmented button.active { background: #63636b; color: var(--text); }

/* ---------- ログイン ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 320px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px 26px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.login-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.login-sub { margin: 4px 0 20px; color: var(--sub); font-size: 12.5px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--sub); margin-bottom: 5px; }
.field input {
  width: 100%;
  background: var(--control);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
}
.field input:focus { outline: none; border-color: var(--blue); }
.form-error { color: var(--red); font-size: 12.5px; margin: 0 0 12px; }
.login-card .btn { margin-top: 4px; }

/* ---------- アプリ枠 ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100dvh;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 14px 12px 12px;
  min-height: 0;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 8px 14px;
}
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }

.side-nav {
  appearance: none; border: 0; cursor: pointer;
  background: var(--card); color: var(--text);
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  padding: 7px 10px;
  text-align: center;
  width: 100%;
}
.side-nav:hover { background: var(--control); }
.side-nav.active { background: var(--sel); }

.side-section {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 8px 6px;
  font-size: 12px; font-weight: 600; color: var(--sub);
}
.add-menu {
  position: absolute;
  top: calc(100% + 2px);
  right: 0;
  z-index: 20;
  min-width: 184px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.add-menu button {
  display: block; width: 100%;
  appearance: none; border: 0; cursor: pointer;
  background: transparent; color: var(--text);
  font-size: 13px; font-weight: 400;
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
}
.add-menu button:hover { background: var(--hover); }
.icon-btn {
  appearance: none; border: 0; cursor: pointer;
  background: transparent; color: var(--sub);
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.account-list { overflow-y: auto; min-height: 0; }
.account-row {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 8px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--text);
  cursor: pointer; text-align: left;
  margin-bottom: 2px;
}
.account-row:hover { background: var(--hover); }
.account-row.selected { background: var(--sel); }
.account-row-text { min-width: 0; flex: 1; }
.account-row-name {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-row-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: #d1d1d6;
}
.side-empty { color: var(--faint); font-size: 12px; padding: 4px 8px; line-height: 1.6; }
.side-spacer { flex: 1; }

.side-total {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 8px 10px;
  font-size: 12px; color: var(--sub);
}
.side-total-value {
  font-size: 13px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
}

.sub-warn { color: var(--yellow); }
.sub-error { color: var(--red); }

/* 管理画面 */
.admin-user { margin-top: 16px; padding: 4px 0; }
.admin-account-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  font-size: 12.5px;
}
.admin-account-row + .admin-account-row { border-top: 1px solid var(--line); }
.admin-account-name { flex: 1; min-width: 0; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-total { font-variant-numeric: tabular-nums; font-weight: 600; }

.side-user {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px; margin-top: 10px;
}
.side-user-name {
  flex: 1; min-width: 0;
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.main { min-width: 0; overflow-y: auto; padding: 18px 22px 26px; }

/* ---------- 空状態 ---------- */
.empty-view { padding: 15dvh 20px 0; text-align: center; }
.empty-title { font-size: 17px; font-weight: 700; margin: 0 0 8px; }
.empty-text { color: var(--sub); font-size: 13px; margin: 0 auto 18px; max-width: 420px; }

/* ---------- 詳細 ---------- */
.detail-head {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.detail-head-text { flex: 1; min-width: 0; }
.detail-name {
  font-size: 19px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.detail-sub { color: var(--sub); font-size: 12px; }
.detail-status { display: flex; align-items: center; gap: 8px; }

.detail-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 232px;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  min-height: 48px;
}
.card-row + .card-row { border-top: 1px solid var(--line); }
.card-label { flex: none; width: 64px; font-size: 13px; color: var(--text); }
.card-row-main { flex: 1; min-width: 0; }
.card-row-title { font-size: 13px; font-weight: 600; }
.card-row-sub { font-size: 12px; color: var(--sub); margin-top: 1px; }
.card-row-sub.warn { color: var(--yellow); }

.text-input {
  flex: 1; min-width: 0;
  background: var(--control);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
}
.text-input:focus { outline: none; border-color: var(--blue); }
.text-input::placeholder { color: var(--faint); }

.video-name {
  flex: 1; min-width: 0;
  font-size: 12.5px; color: var(--sub);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.progress {
  height: 4px; border-radius: 2px;
  background: var(--control);
  overflow: hidden; margin-top: 6px;
}
.progress > div {
  height: 100%; background: var(--blue); width: 100%;
  transform-origin: left; transform: scaleX(0);
  transition: transform 0.15s;
}

/* プレビュー */
.preview-col { width: 232px; }
.preview-box {
  width: 232px; height: 232px;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.preview-box video { width: 100%; height: 100%; object-fit: contain; display: block; }
.preview-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-size: 12px; text-align: center; padding: 12px;
}
.preview-caption {
  margin-top: 7px; font-size: 12px; color: var(--sub);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preview-caption.live { color: var(--red); font-weight: 600; }
.preview-actions { display: flex; gap: 8px; margin-top: 12px; }
.preview-actions .btn { flex: 1; padding: 8px 10px; }

/* ログ */
.log-card { margin-top: 18px; }
.log-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px 6px;
  font-size: 12px; font-weight: 600; color: var(--sub);
}
.log-body {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: #d1d1d6;
  padding: 4px 14px 12px;
  height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-body .log-line { display: block; }

/* ---------- モニター ---------- */
.monitor-head {
  display: flex; align-items: baseline; gap: 12px;
  padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.monitor-head h1 { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.monitor-summary { color: var(--sub); font-size: 12.5px; }
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 216px);
  gap: 16px;
  margin-top: 18px;
}
.tile {
  display: block;
  width: 216px;
  border: 0; background: transparent; color: var(--text);
  padding: 0; cursor: pointer; text-align: left;
  font-family: inherit;
}
.tile-video {
  display: block;
  width: 216px; height: 216px;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden; position: relative;
}
.tile-video video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile:hover .tile-video { border-color: rgba(255, 255, 255, 0.22); }
.tile-name {
  display: block;
  margin-top: 7px; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-status { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--sub); }
.tile-status.live { color: var(--red); font-weight: 600; }

/* ---------- API ---------- */
.api-card { margin-top: 18px; padding: 4px 0; }
.api-list-head {
  font-size: 12px; font-weight: 600; color: var(--sub);
  padding: 10px 14px 4px;
}
.api-endpoint {
  display: flex; gap: 12px; align-items: baseline;
  padding: 7px 14px;
  font-size: 12.5px;
}
.api-endpoint + .api-endpoint { border-top: 1px solid var(--line); }
.api-method {
  flex: none; width: 52px;
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  color: var(--blue);
}
.api-method.post { color: var(--green); }
.api-method.delete { color: var(--red); }
.api-method.put { color: var(--yellow); }
.api-path { font-family: var(--mono); font-size: 12px; flex: none; }
.api-desc { color: var(--sub); }
.token-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.token-line code {
  flex: 1; min-width: 0;
  font-family: var(--mono); font-size: 12px;
  background: var(--control); border-radius: 7px; padding: 7px 9px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.code-block {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.7;
  color: #d1d1d6;
  padding: 6px 14px 14px; margin: 0;
  white-space: pre-wrap; word-break: break-all;
}

/* ---------- その他 ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 10, 12, 0.72);
  display: flex; align-items: center; justify-content: center;
}
.drop-box {
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  padding: 42px 54px;
  font-size: 15px; font-weight: 600;
  background: rgba(44, 44, 46, 0.9);
}
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 50;
  background: #3a3a3c; color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  max-width: min(560px, 90vw);
}
.toast.error { background: #5a2320; }

.elapsed { font-variant-numeric: tabular-nums; color: var(--sub); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .detail-body { grid-template-columns: 1fr; }
  .preview-col { width: 100%; }
  .preview-box { width: 100%; height: auto; aspect-ratio: 1; }
}
