:root {
  --bg: #0e1320;
  --panel: #171f31;
  --panel-2: #1e2941;
  --panel-3: #253351;
  --line: #33415f;
  --text: #eef2fb;
  --muted: #aab4ca;
  --accent: #6289ff;
  --accent-strong: #4775ff;
  --success: #47d39b;
  --danger: #f0645b;
  --warning: #f0b429;
  --focus: #a9c0ff;
  --shadow: 0 18px 48px rgb(0 0 0 / 28%);
}

* { box-sizing: border-box; }
html { min-width: 280px; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; }
button, input, select, textarea { color-scheme: dark; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 1000;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }
.boot-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: radial-gradient(ellipse at top, #1b2a52, var(--bg) 70%);
}

/* ---------- 通用表单 ---------- */
input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}
textarea { min-height: 84px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #8490aa; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid transparent;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgb(98 137 255 / 20%);
}
.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}
.field > span, .channel-picker legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.check-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  color: var(--muted);
  white-space: nowrap;
}
.check-field input, .chks input { width: auto; min-height: auto; accent-color: var(--accent); }
.btn {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background-color .15s, filter .15s, transform .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); background: var(--panel-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, .tabs-mini button:focus-visible, .sidebar nav button:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.btn:disabled { cursor: not-allowed; opacity: .5; }
.btn.primary { border-color: var(--accent-strong); background: var(--accent-strong); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.14); background: var(--accent-strong); }
.btn.danger { border-color: var(--danger); background: #6c2c2b; color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 9px; font-size: 12px; }
.btn.ghost { margin: 14px; background: transparent; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.msg { min-height: 1.5em; margin: 8px 0 0; color: var(--warning); overflow-wrap: anywhere; }

/* ---------- 登录页 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #1b2a52, var(--bg) 70%);
}
.auth-card {
  width: min(100%, 410px);
  min-width: 0;
  max-width: 100%;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 21px; line-height: 1.35; }
.auth-card p { margin: 0; }
.tabs-mini { display: flex; gap: 6px; margin: 20px 0; }
.tabs-mini button {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.tabs-mini button.active { border-color: var(--accent); background: #293b6a; color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 11px; }
.auth-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- 主布局 ---------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  width: 220px;
  height: 100vh;
  flex: 0 0 220px;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.brand { padding: 20px 16px; font-size: 18px; font-weight: 750; white-space: nowrap; }
.brand span { color: var(--accent); }
.sidebar nav { display: flex; min-height: 0; flex: 1; flex-direction: column; overflow-y: auto; }
.sidebar nav button {
  width: 100%;
  min-height: 43px;
  padding: 10px 18px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}
.sidebar nav button:hover { background: var(--panel-2); color: var(--text); }
.sidebar nav button.active { border-left-color: var(--accent); background: var(--panel-2); color: #fff; }
.main {
  min-width: 0;
  max-width: calc(100vw - 220px);
  flex: 1;
  padding: 24px 32px 48px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.topbar h2 { margin: 0; font-size: 23px; }
#user-badge { text-align: right; overflow-wrap: anywhere; }
.page { min-width: 0; }

/* ---------- 卡片与面板 ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.card .num { color: var(--accent); font-size: 28px; font-weight: 750; }
.card.green .num { color: var(--success); }
.card.red .num { color: var(--danger); }
.card .lbl { color: var(--muted); font-size: 13px; }
.queue-overview-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: -10px 0 24px;
}
.queue-overview-card {
  display: flex;
  min-height: 132px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.queue-overview-card:hover { border-color: var(--accent); background: var(--panel-2); }
.queue-overview-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.queue-overview-card .num { line-height: 1.2; }
.card-hint { margin-top: 8px; color: var(--focus); font-size: 12px; }
.panel {
  padding: 18px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.form-row { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; margin-bottom: 14px; }
.form-row > .field { flex: 0 1 220px; }
.form-row > .channel-picker { flex: 1 1 420px; }
.form-col { display: flex; flex-direction: column; gap: 11px; }
.form-col.narrow { max-width: 460px; }
.form-col > .btn { align-self: flex-start; }
.form-help { margin: -8px 0 13px; }
.filters { align-items: end; }
.filters > .field { flex: 0 1 210px; }
.channel-picker {
  min-width: 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.picker-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 10px; }
.channel-unavailable { opacity: .65; }
.channel-unavailable .config-missing { font-size: 11px; }
.chks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.chks label { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.default-mark {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 12px;
  background: #284a3d;
  color: var(--success);
  font-size: 11px;
  white-space: nowrap;
}
.config-missing { color: var(--warning); }
h3 { margin: 20px 0 10px; }
hr { width: 100%; border: 0; border-top: 1px solid var(--line); }

/* ---------- 表格 ---------- */
.table-scroll {
  width: 100%;
  margin-bottom: 22px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  scrollbar-color: var(--line) transparent;
}
table { width: 100%; min-width: 720px; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; text-align: left; vertical-align: middle; }
th { background: var(--panel-2); color: var(--muted); font-weight: 650; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgb(255 255 255 / 1.5%); }
.empty-cell { height: 70px; text-align: center; }
.actions { min-width: 150px; white-space: nowrap; }
.actions .btn { margin: 2px 3px 2px 0; }
.status-detail { display: block; max-width: 260px; margin-top: 3px; white-space: normal; overflow-wrap: anywhere; }
.error-detail { max-width: 340px; white-space: normal; overflow-wrap: anywhere; }
.attachment { color: var(--focus); text-decoration: none; }
.attachment:hover { text-decoration: underline; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin: -8px 0 22px; color: var(--muted); }

/* ---------- 状态与通知 ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 18px; font-size: 12px; white-space: nowrap; }
.badge.ok, .badge.active, .badge.published, .badge.info { background: #1d4435; color: var(--success); }
.badge.error, .badge.failed, .badge.api_error { background: #4d2524; color: #ff8a82; }
.badge.unknown, .badge.waiting, .badge.paused { background: #353d52; color: #c0c8d9; }
.badge.queued, .badge.publishing, .badge.canceling { background: #283f70; color: #9ab7ff; }
.badge.warn { background: #4a3a16; color: #ffd166; }
#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  display: flex;
  max-width: min(390px, calc(100vw - 32px));
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--panel-2);
  box-shadow: 0 8px 28px rgb(0 0 0 / 45%);
  overflow-wrap: anywhere;
  animation: slide-in .22s ease-out;
}
.toast.err { border-color: var(--danger); }
@keyframes slide-in { from { transform: translateX(25px); opacity: 0; } }

/* ---------- 上传与编辑器 ---------- */
.media-toolbar { display: grid; gap: 12px; }
.media-toolbar .tabs-mini { width: min(100%, 340px); margin: 0; }
.media-upload-form, .media-filters { margin: 0; }
.media-upload-form .file-field { flex: 1 1 440px; margin: 0; }
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.media-grid.compact { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-top: 14px; }
.media-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.media-preview {
  display: grid;
  width: 100%;
  aspect-ratio: 16 / 10;
  place-items: center;
  overflow: hidden;
  background: #080b12;
  color: var(--muted);
  text-decoration: none;
}
.media-preview img, .media-preview video { width: 100%; height: 100%; object-fit: contain; }
.media-card-body { display: flex; min-width: 0; flex-direction: column; gap: 8px; padding: 12px; }
.media-card-body strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card-body .form-actions { align-items: stretch; }
.media-placeholder { color: var(--muted); }
.empty-state { grid-column: 1 / -1; padding: 54px 18px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; }
.publish-channels { margin-bottom: 14px; }
.publish-basics { align-items: end; }
.publish-basics .media-select-field { flex: 1 1 320px; }
.publish-basics .media-select-field .btn { width: 100%; }
.selected-media-preview {
  display: flex;
  min-height: 76px;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
}
.selected-media-thumb { width: 92px; height: 58px; flex: 0 0 92px; overflow: hidden; border-radius: 7px; background: #080b12; }
.selected-media-thumb img, .selected-media-thumb video { width: 100%; height: 100%; object-fit: contain; }
.platform-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin: 14px 0; }
.platform-option { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: rgb(0 0 0 / 10%); }
.platform-option h4 { margin: 0 0 10px; }
.platform-option .form-row { margin: 0; }
.wide-dialog { width: min(1100px, calc(100vw - 28px)); }
.file-field { max-width: 560px; margin-bottom: 12px; }
.schedule-field { max-width: 320px; margin-bottom: 14px; }
#upload-rows { margin: 14px 0; }
.upload-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 9px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgb(0 0 0 / 10%);
}
.publish-copy-row { grid-template-columns: minmax(0, 1fr); }
.publish-copy-row .field:nth-child(2) { grid-column: auto; }
.publish-copy-row .first-comment-field { grid-column: 1 / -1; }
.publish-copy-row textarea[name="descriptions"] { min-height: 190px; }
.publish-copy-row textarea[name="notes"] { min-height: 100px; }
.upload-row .fname { grid-column: 1 / -1; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.upload-row textarea { min-height: 70px; }
.upload-row .remove-row { align-self: end; margin-bottom: 5px; }
.editor-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 32px);
  padding: 22px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
.editor-dialog::backdrop { background: rgb(2 6 14 / 72%); backdrop-filter: blur(2px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-heading h2 { margin: 0; font-size: 21px; }
.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- 平板与手机 ---------- */
@media (max-width: 1050px) {
  .upload-row { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .upload-row .remove-row { justify-self: start; }
}

@media (max-width: 820px) {
  #app-view { display: block; }
  .sidebar {
    z-index: 50;
    display: flex;
    width: 100%;
    height: auto;
    max-height: none;
    flex-direction: row;
    align-items: stretch;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { display: none; }
  .sidebar nav { flex: 1; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .sidebar nav button {
    width: auto;
    min-width: max-content;
    border-left: 0;
    border-bottom: 3px solid transparent;
    text-align: center;
  }
  .sidebar nav button.active { border-bottom-color: var(--accent); border-left-color: transparent; }
  .sidebar .btn.ghost { min-width: max-content; margin: 5px 7px; padding-inline: 11px; }
  .main { max-width: 100%; padding: 22px 20px 44px; }
}

@media (max-width: 620px) {
  .auth-wrap { padding: 14px; }
  .auth-card { padding: 22px 18px; }
  .auth-form .row { grid-template-columns: 1fr; }
  .tabs-mini button { padding-inline: 5px; font-size: 13px; }
  .main { padding: 18px 12px 40px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 3px; }
  #user-badge { text-align: left; }
  .form-row { display: grid; grid-template-columns: 1fr; align-items: stretch; }
  .form-row > .field, .form-row > .channel-picker { width: 100%; flex-basis: auto; }
  .panel { padding: 14px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .queue-overview-cards { grid-template-columns: 1fr; gap: 9px; }
  .card { padding: 13px; }
  .card .num { font-size: 24px; }
  .upload-row { grid-template-columns: 1fr; }
  .publish-copy-row .field:nth-child(2), .publish-copy-row .first-comment-field { grid-column: auto; }
  .media-grid, .media-grid.compact { grid-template-columns: 1fr; }
  .platform-options { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .btn { width: 100%; }
  .pager { justify-content: space-between; gap: 7px; }
  #toast { right: 16px; bottom: 16px; left: 16px; max-width: none; }
  .editor-dialog { padding: 17px; }
}

@media (max-width: 390px) {
  .cards { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
