/* Shared platform page shell (upload / review / train / db) — U1 */

:root {
  color-scheme: dark;
  --bg: #090d13;
  --sidebar: #0d121a;
  --panel: #111821;
  --surface-2: #151e29;
  --surface-3: #1a2533;
  --line: #253142;
  --line-soft: #1b2634;
  --text: #f3f6fb;
  --muted: #8d9aae;
  --accent: #7795ff;
  --accent-bright: #9aacff;
  --accent-dim: rgba(119, 149, 255, 0.12);
  --ok: #59d39b;
  --warn: #f2b45f;
  --bad: #f06f75;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.18);
}

body.has-platform-sidebar {
  background:
    radial-gradient(circle at 78% -15%, rgba(81, 104, 190, 0.15), transparent 30%),
    var(--bg);
}

header.topbar {
  min-height: 66px;
  padding: 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(9, 13, 19, 0.76);
  backdrop-filter: blur(12px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.lang-btn {
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-xs, 0.6875rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  cursor: pointer;
}

.lang-btn + .lang-btn {
  border-left: 1px solid var(--line);
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.active {
  color: var(--text);
  background: var(--accent-dim);
}

.crumbs {
  color: #78869a;
  font-size: var(--text-sm, 0.75rem);
}

.crumbs b {
  color: #dbe3ef;
  font-weight: 550;
}

main.platform-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 34px 52px;
  display: grid;
  gap: 18px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 4px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent-bright);
  font-size: var(--text-xs, 0.6875rem);
  font-weight: var(--weight-semibold, 600);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-head h1 {
  margin: 0;
  font-size: var(--text-2xl, 1.5rem);
  line-height: var(--leading-tight, 1.25);
  letter-spacing: -0.02em;
}

.page-head p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: var(--text-base, 0.8125rem);
  line-height: var(--leading-normal, 1.5);
  max-width: 44rem;
}

.page-head p a {
  color: var(--accent-bright);
}

.page-alert {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid rgba(119, 149, 255, 0.28);
  border-radius: 12px;
  background: rgba(26, 47, 69, 0.55);
  color: var(--muted);
  font-size: var(--text-sm, 0.75rem);
  line-height: 1.45;
}

.page-alert[hidden] {
  display: none !important;
}

.page-alert a {
  color: var(--accent-bright);
}

.card {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(19, 27, 38, 0.98), rgba(15, 22, 31, 0.98));
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: var(--text-md, 0.875rem);
  font-weight: var(--weight-semibold, 600);
  letter-spacing: -0.01em;
}

.card-head h2 .count {
  color: var(--muted);
  font-weight: var(--weight-normal, 400);
  font-size: var(--text-sm, 0.75rem);
}

.card-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: var(--text-sm, 0.75rem);
  line-height: 1.45;
}

.card-sub a {
  color: var(--accent-bright);
}

.infer-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: fit-content;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #0d131b;
}

.infer-tabs button {
  min-width: 108px;
  padding: 8px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm, 0.75rem);
  cursor: pointer;
}

.infer-tabs button.active {
  background: var(--surface-3);
  color: #eef2ff;
  box-shadow: inset 0 0 0 1px rgba(119, 149, 255, 0.2);
}

.infer-pane[hidden] {
  display: none !important;
}

.infer-pane .panel-section {
  padding-top: 4px;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: flex-end;
  margin: 12px 0;
}

.toolbar-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.toolbar-field label {
  font-size: var(--text-xs, 0.6875rem);
  color: var(--muted);
  letter-spacing: 0.02em;
}

.toolbar-field select,
.toolbar-field input[type="text"] {
  min-width: 200px;
  min-height: 40px;
  margin: 0;
  padding: 8px 10px;
  color: var(--text);
  background: #0d131b;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit;
  font-size: var(--text-sm, 0.75rem);
}

.toolbar-status {
  color: var(--muted);
  font-size: var(--text-sm, 0.75rem);
  align-self: center;
}

button.secondary,
.ghost-button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(21, 30, 41, 0.78);
  color: #b8c3d2;
  font-size: var(--text-sm, 0.75rem);
  cursor: pointer;
  font: inherit;
}

button.secondary:hover {
  border-color: #3a6fa8;
}

button.btn-mark {
  padding: 9px 14px;
  border: 1px solid rgba(119, 149, 255, 0.35);
  border-radius: 9px;
  background: var(--accent-dim);
  color: #eef2ff;
  font-size: var(--text-sm, 0.75rem);
  font-weight: var(--weight-medium, 500);
  cursor: pointer;
  font: inherit;
}

button.btn-mark:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 900px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  main.platform-main {
    padding: 24px 16px 40px;
  }

  header.topbar {
    padding: 0 16px;
  }
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 14px;
}

.stat .k {
  color: var(--muted);
  font-size: var(--text-xs, 0.6875rem);
  margin-bottom: 6px;
}

.stat .v {
  font-size: clamp(0.85rem, 2.5vw, 1.35rem);
  font-weight: 700;
  line-height: 1.2;
}

.stat.review .v { color: var(--warn); }
.stat.active .v { color: var(--accent-bright); }
.stat.failed .v { color: var(--bad); }

.hint {
  color: var(--muted);
  font-size: var(--text-sm, 0.75rem);
  margin: 0 0 12px;
  line-height: 1.45;
}

.meta-list {
  color: var(--muted);
  font-size: var(--text-sm, 0.75rem);
  line-height: 1.5;
}

/* M11b — inline media preview modal */
.media-preview-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 8, 14, 0.78);
  backdrop-filter: blur(6px);
}
.media-preview-backdrop.open { display: flex; }
.media-preview-modal {
  width: min(920px, 96vw);
  max-height: 92vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.media-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.media-preview-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.media-preview-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.media-preview-body {
  padding: 12px;
  background: #080c12;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  max-height: calc(92vh - 120px);
  overflow: auto;
}
.media-preview-body video,
.media-preview-body img {
  max-width: 100%;
  max-height: calc(92vh - 160px);
  border-radius: 8px;
  background: #000;
}
.media-preview-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--line-soft);
}
.media-preview-foot a { font-size: 0.82rem; }
button.media-preview-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* M12 — shared ingest / review library tables */
.tabs-filter {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px;
}
.tabs-filter button {
  background: #121820;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.tabs-filter button.active {
  color: #dff0ff;
  border-color: #3d7fbf;
  background: var(--accent-dim);
}
.tabs-filter button .n {
  margin-left: 4px;
  opacity: 0.8;
  font-size: 0.78rem;
}
.scene-progress {
  margin: 6px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}
.scene-progress-track {
  height: 5px;
  width: 90px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.scene-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}
.scene-threshold {
  margin: 6px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.scene-threshold label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.scene-threshold-slider {
  width: 110px;
  accent-color: var(--accent);
}
.scene-threshold-value {
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  color: var(--text);
}
.scene-threshold-default {
  font-size: 0.72rem;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.scene-threshold-default:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.scene-priority-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0 6px 0 0;
  line-height: 1;
  width: 22px;
  text-align: left;
  display: inline-block;
}
.scene-priority-btn.active {
  color: #f5b301;
}
.scene-priority-btn:hover {
  color: #f5b301;
}
.library-table-wrap {
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #0d131b;
}
.library-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.library-table th,
.library-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}
.library-table th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  background: #111821;
  white-space: nowrap;
}
.library-table tbody tr:last-child td { border-bottom: 0; }
.library-table tbody tr:hover td { background: rgba(21, 30, 41, 0.55); }
.library-table .col-thumb { width: 84px; }
.library-table .col-actions { width: 120px; white-space: nowrap; }
.library-table .col-time { width: 150px; white-space: nowrap; color: var(--muted); font-size: 0.76rem; }
.library-thumb,
.library-thumb-empty {
  width: 72px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0d1014;
  display: block;
}
.library-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.62rem;
}
.library-name {
  margin: 0;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.library-id {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.library-kw {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.library-kw label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  color: #dce4ef;
  cursor: pointer;
}
.library-kw input { accent-color: var(--accent); }
.library-kw-empty {
  color: var(--muted);
  font-size: 0.74rem;
}
.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.library-actions button {
  background: transparent;
  border: 0;
  color: var(--accent);
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.76rem;
}
/* Download list (ingest library): render action buttons as buttons */
#ingestLibraryRoot .library-actions button {
  background: #1e3a5f;
  border: 1px solid #2f6fad;
  color: #dce4ef;
  border-radius: 7px;
  padding: 5px 9px;
  text-decoration: none;
}
#ingestLibraryRoot .library-actions button.btn-delete-link {
  color: #fca5a5;
  border-color: #7f1d1d;
  background: #2a1212;
}
.library-actions button.btn-save-kw {
  color: #dce4ef;
  border: 1px solid #2f6fad;
  border-radius: 7px;
  padding: 5px 9px;
  background: #1e3a5f;
}
.library-actions button.btn-save-kw:disabled { opacity: 0.45; cursor: not-allowed; }
.library-actions button.btn-delete-link {
  color: #fca5a5;
}
.library-yt-link {
  color: var(--accent);
  text-decoration: none;
}
.library-yt-link:hover {
  text-decoration: underline;
}
/* Ingest review table: render all row actions as buttons (預覽/儲存/刪除) */
#ingestReviewRoot .library-actions button {
  border: 1px solid #2f6fad;
  border-radius: 7px;
  padding: 5px 9px;
  background: #1e3a5f;
  color: #dce4ef;
  text-decoration: none;
}
#ingestReviewRoot .library-actions button.btn-delete-link {
  color: #fca5a5;
  border-color: #7f1d1d;
  background: #2a1212;
}
.library-empty {
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}
.library-empty strong {
  display: block;
  margin-bottom: 6px;
  color: #dbe3ef;
  font-size: 0.92rem;
}
.kw-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #2a3a4d;
  background: #151e29;
  color: #c5d0de;
  font-size: 0.72rem;
}
.kw-chip.reviewed {
  color: var(--ok);
  border-color: #1f5a3d;
  background: #143528;
}

/* M21 — database library page */
.stats.stats-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
@media (max-width: 1100px) {
  .stats.stats-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 640px) {
  .stats.stats-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.stats.stats-6 .stat {
  cursor: pointer;
}
.stats.stats-6 .stat:focus-visible,
.stats.stats-6 .stat.selected {
  box-shadow: inset 0 0 0 1px rgba(119, 149, 255, 0.35);
}
.stat .v.mono {
  font-size: clamp(0.7rem, 1.6vw, 0.95rem);
  font-weight: 650;
  word-break: break-all;
}
.library-table .col-pipeline { min-width: 168px; }
.library-table .col-status { width: 92px; }
.library-kw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.pipeline-steps {
  display: flex;
  align-items: center;
  gap: 0;
}
.pipeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 36px;
}
.pipeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2a3544;
  border: 1px solid var(--line);
}
.pipeline-step.done .pipeline-dot {
  background: var(--ok);
  border-color: #1f5a3d;
}
.pipeline-step.ready .pipeline-dot {
  background: var(--warn);
  border-color: #6a4a1e;
}
.pipeline-step.active .pipeline-dot {
  background: var(--accent);
  border-color: #3a6fa8;
}
.pipeline-step.fail .pipeline-dot {
  background: var(--bad);
  border-color: #6a2a2a;
}
.pipeline-label {
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.pipeline-line {
  width: 10px;
  height: 1px;
  background: var(--line);
  margin: 0 2px 12px;
}
.source-meta {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 2px;
}
tr.db-detail-row {
  display: none;
}
tr.expanded + tr.db-detail-row {
  display: table-row;
}
tr.expanded td {
  background: rgba(119, 149, 255, 0.08);
}
.db-detail {
  padding: 4px 0 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 16px;
  color: var(--muted);
  font-size: 0.74rem;
}
.db-detail .k {
  color: var(--muted);
  font-size: 0.65rem;
  margin-bottom: 2px;
}
.db-detail .v {
  color: var(--text);
  word-break: break-all;
}
.db-detail .v.err { color: var(--bad); }
.version-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 4px;
}
.version-card {
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 14px 16px;
  background: #0d131b;
}
.version-card.active {
  border-color: rgba(89, 211, 155, 0.45);
}
.version-card h3 {
  margin: 0 0 8px;
  font-size: 0.88rem;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.version-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 8px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}
.version-metrics b { color: var(--text); font-weight: 650; }
.db-advanced {
  margin-top: 4px;
}
.db-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.74rem;
}
.library-table tbody tr.db-job-row { cursor: pointer; }
.db-library .btn-delete {
  background: transparent;
  border: 0;
  color: #f6b4b4;
  cursor: pointer;
  font: inherit;
  font-size: 0.76rem;
  padding: 0;
}
.db-library .btn-delete:hover { color: var(--bad); }
.db-library .btn-delete:disabled { opacity: 0.5; cursor: not-allowed; }
.db-library .badge.ingested,
.db-library .badge.done { color: var(--ok); }
.db-library .badge.failed { color: var(--bad); }
.db-library .badge.running,
.db-library .badge.queued,
.db-library .badge.downloading,
.db-library .badge.preparing,
.db-library .badge.candidate {
  color: var(--warn);
}
