* { box-sizing: border-box; }
body {
  font-family: -apple-system, "Helvetica Neue", Arial, "PingFang SC", sans-serif;
  margin: 0;
  background: #f6f7f9;
  color: #222;
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: #1f2937; color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
header h1 { font-size: 20px; margin: 0; }
.header-right {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
#hub-status { font-size: 13px; color: #d1d5db; }
.hub-ok  { color: #34d399; font-weight: 700; }
.hub-err { color: #f87171; font-weight: 700; }

.user-pill {
  font-size: 13px; color: #1f2937; background: #fef3c7;
  padding: 5px 12px; border-radius: 12px; cursor: pointer;
}
.user-pill:hover { background: #fde68a; }
.version-tag {
  font-size: 12px; color: #9ca3af; font-family: "SF Mono", Menlo, monospace;
}

/* Header account picker — widened so long names like
   "墨西哥测试-3-zxlu5 (1580697601·Mexico)" are fully visible instead
   of being truncated to the first few characters. */
.header-right label {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
}
#account {
  min-width: 320px;
  max-width: 500px;
  padding: 6px 10px; font-size: 13px;
  border-radius: 6px; border: 1px solid #4b5563;
  background: #fff; color: #1f2937;
}
header button {
  padding: 6px 12px; font-size: 13px;
}

#upload-app-log {
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  border-radius: 6px; font-size: 12px; cursor: pointer;
}
#upload-app-log:hover:not(:disabled) { background: #fde68a; }
#upload-app-log:disabled { opacity: 0.6; cursor: default; }

main {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  padding: 16px 24px;
}
section {
  background: #fff; border-radius: 8px; padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
h2 { font-size: 14px; margin: 0 0 10px; color: #374151; }
h3 { font-size: 13px; margin: 10px 0 6px; color: #4b5563; font-weight: 600; }

#pane-submit, #pane-tasks, #pane-params, #pane-overview { grid-column: 1 / -1; }

/* Overview */
#overview-card {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.ov-cell {
  padding: 10px; border-radius: 6px; background: #f9fafb; text-align: center;
}
.ov-num { font-size: 22px; font-weight: 700; color: #1f2937; }
.ov-label { font-size: 11px; color: #6b7280; margin-top: 4px; }
#overview-bar {
  margin-top: 10px; height: 18px; background: #e5e7eb; border-radius: 4px;
  overflow: hidden; position: relative;
}
#overview-bar-fill {
  height: 100%; width: 0%; background: #10b981; transition: width 0.4s ease;
  color: #fff; font-size: 12px; text-align: center; line-height: 18px;
}

/* Per-account table */
#accounts-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
#accounts-table th, #accounts-table td {
  padding: 6px 10px; text-align: left; border-bottom: 1px solid #eee;
}
#accounts-table th { background: #f9fafb; font-weight: 600; color: #374151; }
.acct-row { cursor: pointer; }
.acct-row:hover { background: #f3f4f6; }
.cell-alert { color: #b91c1c; font-weight: 700; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-stuck   { background: #fee2e2; color: #b91c1c; }
.badge-needs   { background: #fef3c7; color: #b45309; }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-pending { background: #f3e8ff; color: #6b21a8; }
.badge-done    { background: #d1fae5; color: #065f46; }
.badge-idle    { background: #f3f4f6; color: #6b7280; }

/* Per-failure-category mini-badges inside account rows. Colors tied
   to severity: red = user action needed, yellow = usually retryable,
   grey = unknown. Hover tooltip explains what each means. */
.fail-cats {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px;
}
.fail-cat {
  display: inline-block; padding: 1px 6px; border-radius: 8px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
  cursor: help; line-height: 1.6;
}
.fail-cat-red    { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.fail-cat-yellow { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.fail-cat-grey   { background: #f3f4f6; color: #4b5563; border: 1px solid #d1d5db; }

.batches-detail td { background: #fafafa; padding: 10px 16px; }
/* Fixed layout keeps the 操作 column at a predictable width so the
   long batch_id (last column) can wrap without pushing action buttons
   off-screen to the right. Priority order in terms of width: actions
   stay visible first, batch_id is last. */
.batches-tbl { width: 100%; border-collapse: collapse; font-size: 12px;
               table-layout: fixed; }
.batches-tbl th, .batches-tbl td { padding: 4px 8px; text-align: left;
                                    border-bottom: 1px solid #f0f0f0;
                                    vertical-align: top; }
.batches-tbl th { background: #f3f4f6; }
.batches-tbl .col-actions { width: 180px; }
.batch-id-cell {
  word-break: break-all;       /* wrap long Chinese+underscore ids */
  font-family: "SF Mono", Menlo, monospace;
  font-size: 11px; color: #4b5563;
}

/* ── v0.1.25 tree view (date > account > batch > video) ── */
#date-tree { font-size: 13px; }
#date-tree details { margin: 4px 0; }
#date-tree summary {
  cursor: pointer; padding: 6px 8px; border-radius: 4px;
  list-style: none; user-select: none;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
#date-tree summary::-webkit-details-marker { display: none; }
#date-tree summary::before {
  content: "▸"; color: #9ca3af; display: inline-block;
  width: 12px; transition: transform 0.15s;
}
#date-tree details[open] > summary::before { transform: rotate(90deg); }

/* Level-specific styling */
.date-node > summary {
  background: #eef2ff; font-weight: 600; color: #3730a3;
}
.date-node > summary:hover { background: #e0e7ff; }
.date-body { padding-left: 20px; }

.acct-node > summary {
  background: #f9fafb; font-weight: 500; color: #1f2937;
  margin-top: 2px;
}
.acct-node > summary:hover { background: #f3f4f6; }
.acct-body { padding-left: 24px; }

.batch-node > summary {
  background: transparent; font-weight: normal; color: #4b5563;
  font-size: 12px; padding-top: 4px; padding-bottom: 4px;
}
.batch-node > summary:hover { background: #f3f4f6; }
.batch-body { padding: 6px 0 10px 28px; }
.batch-actions-row { margin-bottom: 6px; display: flex; gap: 6px; }
.batch-actions-row button, .batch-actions-row a {
  font-size: 11px; padding: 2px 8px; border-radius: 3px;
  text-decoration: none; border: 1px solid #d1d5db;
  background: #fff; color: #1f2937; cursor: pointer;
}

/* Count chips used at each level */
.date-counts, .acct-counts, .batch-counts {
  display: inline-flex; gap: 8px; font-size: 11px;
}
.c-done { color: #059669; }
.c-fail { color: #b91c1c; font-weight: 600; }
.c-run  { color: #1d4ed8; }
.c-pend { color: #6b21a8; }

/* Per-video row inside a batch */
.video-list {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 12px;
}
.video-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 3px 8px; border-radius: 4px;
}
.video-row:hover { background: #f9fafb; }
.vrow-icon { width: 16px; display: inline-block; text-align: center; }
.vrow-icon.status-done    { color: #059669; }
.vrow-icon.status-failed  { color: #b91c1c; }
.vrow-icon.status-running { color: #1d4ed8; }
.vrow-icon.status-pending { color: #6b21a8; }
.vrow-name {
  font-family: "SF Mono", Menlo, monospace; font-size: 11px;
  color: #374151; word-break: break-all;
}
.vrow-link, .vrow-shot {
  text-decoration: none; cursor: pointer; padding: 0 4px;
  border-radius: 3px; font-size: 13px;
}
.vrow-link:hover, .vrow-shot:hover { background: #e5e7eb; }

.fail-cats-inline { display: inline-flex; gap: 4px; flex-wrap: wrap; }

.row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.row.right { justify-content: flex-end; }
.row input[type="text"] { flex: 1; padding: 6px 8px; }
button { cursor: pointer; padding: 6px 12px; border: 1px solid #d1d5db;
         border-radius: 4px; background: #fff; }
button:hover { background: #f3f4f6; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }

.muted { color: #6b7280; font-size: 12px; }
.group-count { margin-left: 4px; }

/* Scan groups */
#scan-groups { max-height: 560px; overflow-y: auto; }
.scan-group { margin-top: 6px; padding-bottom: 6px; border-bottom: 1px solid #f0f0f0; }
.video-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px; padding: 4px 0;
}
.video-card {
  position: relative; display: flex; flex-direction: column; align-items: stretch;
  border: 1px solid #e5e7eb; border-radius: 6px; padding: 6px; background: #fafafa;
}
.video-card input[type="checkbox"] {
  position: absolute; top: 8px; left: 8px; z-index: 2; width: 18px; height: 18px;
}
.video-thumb { width: 100%; height: 180px; object-fit: cover; background: #000;
               border-radius: 4px; }
.video-label {
  font-size: 11px; color: #4b5563; margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Selected list */
#selected-list { max-height: 560px; overflow-y: auto; padding: 0; margin: 0; list-style: none; }
.selected-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px; margin-bottom: 6px;
  border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;
  cursor: grab; user-select: none;
}
.selected-item.dragging { opacity: 0.4; }
.selected-item.over { outline: 2px dashed #2563eb; }
.selected-pos {
  width: 28px; text-align: center; font-weight: 700; color: #6b7280;
}
.selected-thumb {
  width: 100px; height: 72px; object-fit: cover; background: #000; border-radius: 4px;
}
.selected-meta { flex: 1; font-size: 12px; overflow: hidden; }
.selected-meta .fname {
  font-family: "SF Mono", Menlo, monospace; font-size: 11px;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}
.selected-del {
  width: 30px; height: 30px; border-radius: 50%; padding: 0; font-size: 14px;
  color: #b91c1c; border-color: #fca5a5;
}

/* Params */
.param-row { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.param-label { min-width: 120px; font-size: 13px; color: #374151; padding-top: 6px; }
.radio-inline { font-size: 13px; margin-right: 16px; cursor: pointer; }
.radio-inline input { margin-right: 4px; }
#shared-caption {
  flex: 1; font-family: inherit; font-size: 13px; padding: 8px; border-radius: 4px;
  border: 1px solid #d1d5db; resize: vertical;
}
#music-name {
  min-width: 320px; padding: 6px 10px; font-size: 13px;
  border: 1px solid #d1d5db; border-radius: 4px;
}
#music-name:disabled { background: #f3f4f6; color: #9ca3af; }
.checkbox-inline { font-size: 13px; margin-left: 16px; cursor: pointer; }
.checkbox-inline input { margin-right: 4px; vertical-align: middle; }
/* Inline red warning — deliberately big + red so operators can't
   miss the "music must be in account's Favoritos first" requirement
   (the one thing that turns music_not_found failures into no-ops). */
.param-row-warn { margin-top: -4px; }
.warn-red {
  color: #dc2626; font-size: 15px; font-weight: 600;
  padding: 4px 0;
}
#schedule-preview { font-size: 13px; padding-left: 22px; margin: 6px 0 0; }
#schedule-preview li { padding: 2px 0; font-family: "SF Mono", Menlo, monospace; }
#interval-hint { font-size: 12px; margin-left: 8px; }
details { margin-top: 8px; }
details summary { cursor: pointer; font-size: 13px; color: #374151; }

/* Submit */
#submit-btn {
  background: #059669; color: #fff; border-color: #059669;
  padding: 8px 18px; font-size: 14px;
}
#submit-btn:hover:enabled { background: #047857; }
#submit-result { margin-top: 8px; font-size: 13px; }
#submit-result.ok { color: #065f46; }
#submit-result.err { color: #991b1b; }

/* Tasks table */
#tasks-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
#tasks-table th, #tasks-table td {
  padding: 6px 8px; text-align: left; border-bottom: 1px solid #eee;
}
#tasks-table th { background: #f9fafb; font-weight: 600; color: #374151; }
.status-pending   { color: #b45309; }
.status-running   { color: #1d4ed8; }
.status-done      { color: #059669; }
.status-failed    { color: #b91c1c; }
.status-cancelled      { color: #6b7280; font-style: italic; }
.status-source_missing { color: #b91c1c; font-weight: 600; }

.warn-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-left-width: 4px;
  color: #7c2d12;
  padding: 8px 12px;
  margin: 8px 0 10px;
  font-size: 13px;
  line-height: 1.55;
  border-radius: 4px;
}
.warn-banner code {
  background: #fde68a;
  padding: 1px 4px;
  border-radius: 2px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
}

.batch-actions { white-space: nowrap; }
.batch-actions button, .batch-actions a {
  font-size: 11px; padding: 2px 8px; margin-right: 4px;
  border-radius: 3px; text-decoration: none; border: 1px solid #d1d5db;
  background: #fff; color: #1f2937; cursor: pointer;
}
.batch-cancel { color: #b91c1c; border-color: #fca5a5; }
.batch-cancel:hover { background: #fee2e2; }
.batch-dl-log { color: #374151; }
.batch-dl-log:hover { background: #f3f4f6; }

/* Folder picker modal */
#folder-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
#folder-modal.modal-hidden { display: none; }
.modal-content {
  background: #fff; border-radius: 8px; padding: 16px; width: 560px; max-height: 80vh;
  display: flex; flex-direction: column;
}
.modal-content h3 { margin-top: 0; }
#folder-list {
  list-style: none; padding: 0; margin: 8px 0; overflow-y: auto;
  max-height: 400px; border: 1px solid #eee; border-radius: 4px;
}
#folder-list li {
  padding: 6px 12px; cursor: pointer; border-bottom: 1px solid #f0f0f0;
}
#folder-list li:hover { background: #f3f4f6; }
