/* 文件路径: frontend/style.css
 * 创建时间: 2026-08-27
 * 上次修改时间: 2026-08-27
 * 开发者: aidaox
 * 说明: AI漫剧 NAS 工具界面样式（含手机端适配、浅色/深色主题）
 */

/* 默认浅色 */
:root,
html[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-glow-1: #d7e6f7;
  --bg-glow-2: #d9efe6;
  --panel: #ffffff;
  --panel-end: #f7f9fc;
  --panel2: #eef2f7;
  --panel-deep: #e8edf4;
  --text: #1a2332;
  --muted: #5c6b80;
  --accent: #2b7fd6;
  --accent2: #1fa87a;
  --danger: #d6456a;
  --warn: #c99212;
  --border: #d0dae8;
  --border-strong: #b8c5d8;
  --btn-secondary: #5a6d86;
  --btn-secondary-text: #fff;
  --shadow: 0 8px 24px rgba(30, 50, 80, 0.08);
  --top-progress-bg: rgba(255, 255, 255, 0.96);
  --login-shadow: 0 16px 40px rgba(30, 50, 80, 0.12);
  --radius: 12px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

/* 深色 */
html[data-theme="dark"] {
  --bg: #0f1419;
  --bg-glow-1: #1c3a5a;
  --bg-glow-2: #163528;
  --panel: #1a2332;
  --panel-end: #15202c;
  --panel2: #243044;
  --panel-deep: #121a24;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3d9cf0;
  --accent2: #2ecc9a;
  --danger: #e74c6f;
  --warn: #f0b429;
  --border: #2a3a50;
  --border-strong: #334860;
  --btn-secondary: #3a4d66;
  --btn-secondary-text: #fff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --top-progress-bg: rgba(26, 35, 50, 0.96);
  --login-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 10% -10%, var(--bg-glow-1) 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, var(--bg-glow-2) 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

header.hero {
  margin-bottom: 1.5rem;
}
header.hero h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  letter-spacing: 0.02em;
}
header.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.grid {
  display: grid;
  gap: 1rem;
}
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1.2fr 0.8fr; }
}

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-end) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 600;
}

label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

textarea, input[type="text"], input[type="password"], select {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  outline: none;
}
textarea { min-height: 88px; resize: vertical; }
textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.75rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--btn-secondary); color: var(--btn-secondary-text); }
.btn.success { background: var(--accent2); color: #062418; }
.btn.danger { background: var(--danger); }

.preview {
  margin-top: 0.85rem;
  padding: 0.75rem;
  background: var(--panel-deep);
  border-radius: 8px;
  border: 1px dashed var(--border-strong);
  font-size: 0.9rem;
  color: var(--muted);
}
.preview strong { color: var(--text); }

/* 解析结果：封面 + 文案横排 */
.preview-result {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}
.preview-result .cover {
  flex: 0 0 96px;
  width: 96px;
  height: 128px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-deep);
  border: 1px solid var(--border);
}
.preview-result .meta {
  flex: 1;
  min-width: 0;
}
.preview-result .meta .title {
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.4;
  margin: 0 0 0.35rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.preview-result .meta .line {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0.15rem 0;
  word-break: break-all;
}
@media (max-width: 560px) {
  .preview-result { flex-direction: row; }
  .preview-result .cover { flex-basis: 72px; width: 72px; height: 96px; }
}

.cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cat-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.cat-list li:last-child { border-bottom: none; }

.pan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.65rem;
}
.pan-card {
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}
.pan-card .name { font-weight: 600; margin-bottom: 0.25rem; }
.pan-card .st {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
  min-height: 1.1em;
}
.pan-card .st.on { color: var(--accent2); }
.pan-card .st.off { color: var(--warn); }
.pan-card .st.warn { color: var(--danger); }
.pan-card .meta {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0.55rem;
  min-height: 3.2em;
  word-break: break-all;
}
.pan-card .acts { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.pan-card .btn { padding: 0.35rem 0.55rem; font-size: 0.78rem; }

.inline-radio {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}
.inline-radio input { margin: 0; }

.share-box {
  margin-top: 0.85rem;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.share-empty {
  color: var(--muted);
  font-size: 0.88rem;
}
.share-item {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  gap: 0.55rem;
  align-items: start;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.share-item:last-child { border-bottom: none; }
.share-item .drive {
  font-weight: 600;
  font-size: 0.9rem;
  padding-top: 0.15rem;
}
.share-item .body {
  font-size: 0.85rem;
  line-height: 1.45;
  word-break: break-all;
  color: var(--text);
}
.share-item .body.err { color: var(--danger); }
.share-item .btn { padding: 0.3rem 0.55rem; font-size: 0.78rem; }

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 0.55rem;
  margin-top: 0.75rem;
  max-height: 420px;
  overflow: auto;
  padding: 0.15rem;
}
.post-card {
  position: relative;
  background: var(--panel-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}
.post-card.selected {
  border-color: var(--accent2);
  box-shadow: 0 0 0 1px var(--accent2);
}
.post-card img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--panel-deep);
}
.post-card .cap {
  font-size: 0.72rem;
  line-height: 1.35;
  padding: 0.35rem 0.4rem 0.45rem;
  color: var(--muted);
  min-height: 2.4em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-card .tick {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.55);
  background: rgba(0,0,0,.35);
}
.post-card.selected .tick {
  background: var(--accent2);
  border-color: var(--accent2);
}
.post-card.selected .tick::after {
  content: "";
  position: absolute;
  left: 0.28rem;
  top: 0.08rem;
  width: 0.28rem;
  height: 0.55rem;
  border: solid #062418;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.video-list, .job-list, .queue-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  max-height: 280px;
  overflow: auto;
}
.video-list li, .job-list li, .queue-list li {
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.queue-list li .q-meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}
.queue-list li .q-acts {
  margin-top: 0.35rem;
}
.queue-list .st-queued { color: var(--warn); }
.queue-list .st-running { color: var(--accent); }
.queue-list .st-ok { color: var(--accent2); }
.queue-list .st-partial { color: var(--warn); }
.queue-list .st-fail, .queue-list .st-cancelled { color: var(--danger); }
.checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  margin: 0.5rem 0 0.75rem;
  font-size: 0.88rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal.show { display: flex; }
.modal-box {
  background: var(--panel);
  border-radius: 14px;
  padding: 1.25rem;
  width: min(360px, 100%);
  text-align: center;
  border: 1px solid var(--border-strong);
}
.modal-box img, .modal-box #qrBox {
  width: 220px;
  height: 220px;
  background: #fff;
  border-radius: 8px;
  margin: 0.75rem auto;
  display: block;
}
.modal-box #qrBox img {
  margin: 0;
}
.modal-box p { color: var(--muted); font-size: 0.88rem; }
.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel2);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  display: none;
  z-index: 60;
  max-width: 90vw;
}
.toast.show { display: block; }
.pwd-bar {
  display: none;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #fff8e8;
  border: 1px solid #e0c878;
  border-radius: 8px;
}
html[data-theme="dark"] .pwd-bar {
  background: #2a2210;
  border-color: #6a5520;
}
.pwd-bar.show { display: block; }

.job-list li .job-drives {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}
.job-list li .ok { color: var(--accent2); }
.job-list li .bad { color: var(--danger); }

.dl-progress {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--panel2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.dl-bar {
  height: 8px;
  background: var(--panel-deep);
  border-radius: 999px;
  overflow: hidden;
}
.dl-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.25s ease;
}
.dl-text {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.pwd-input {
  flex: 1;
  max-width: 240px;
  min-width: 0;
}

/* 启动时先隐藏，避免未登录闪一下主界面 */
body.booting .login-gate,
body.booting .app-main {
  display: none !important;
}

/* ========== 登录门禁：未口令只显示这一屏 ========== */
.login-gate {
  display: none; /* 默认隐藏；仅 body.locked 时显示，避免 hidden 被 display:flex 顶掉 */
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0));
}
body.locked .login-gate {
  display: flex;
}
.login-gate[hidden] {
  display: none !important;
}
.app-main[hidden] {
  display: none !important;
}
.login-card {
  /* 手机上尽量拉宽，桌面也更大一点 */
  width: min(520px, 100%);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-end) 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem 1.5rem 1.75rem;
  box-shadow: var(--login-shadow);
  position: relative;
}
.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.02em;
}
.login-desc {
  margin: 0 0 1.35rem;
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
  line-height: 1.45;
}
.login-card label {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}
.login-card .pwd-input {
  max-width: none;
  width: 100%;
  min-height: 52px;
  font-size: 18px;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  /* 避免手机浏览器自动填成白底 */
  background: var(--panel2);
  color: var(--text);
  -webkit-text-fill-color: var(--text);
}
.login-card .pwd-input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}
.login-card .pwd-input:-webkit-autofill,
.login-card .pwd-input:-webkit-autofill:hover,
.login-card .pwd-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--panel2) inset;
  transition: background-color 99999s ease-out;
}
.login-card .btn {
  min-height: 52px;
  font-size: 1.05rem;
  border-radius: 12px;
  margin-top: 1rem !important;
}
.login-hint {
  margin: 0.85rem 0 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.95rem;
  text-align: center;
}

.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  flex-shrink: 0;
}
.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.theme-toggle {
  min-width: 2.4rem;
}

/* 顶部固定进度：下载/上传时不用往下翻 */
.top-progress {
  position: sticky;
  top: 0;
  z-index: 40;
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.85rem;
  background: var(--top-progress-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.top-progress .dl-bar {
  height: 10px;
}
.top-progress .dl-text {
  font-size: 0.88rem;
  color: var(--text);
}

/* ========== 手机端优先适配 ========== */
@media (max-width: 720px) {
  html {
    /* 减少双击缩放；触控更顺 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  body {
    /* 底部安全区，避免被 Home 条挡住 */
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .wrap {
    padding: 0.85rem 0.75rem calc(1.5rem + env(safe-area-inset-bottom, 0));
    max-width: 100%;
  }
  header.hero {
    margin-bottom: 1rem;
  }
  header.hero h1 {
    font-size: 1.45rem;
  }
  header.hero p {
    font-size: 0.82rem;
    line-height: 1.45;
  }

  .card {
    padding: 0.95rem 0.9rem;
    border-radius: 10px;
  }
  .card h2 {
    font-size: 1rem;
  }

  /* iOS 输入框字号 <16px 会强制放大页面，统一 16px */
  textarea,
  input[type="text"],
  select {
    font-size: 16px;
    padding: 0.75rem 0.8rem;
    border-radius: 10px;
  }
  textarea {
    min-height: 110px;
  }

  .pwd-input {
    max-width: none;
    width: 100%;
  }
  .pwd-bar .row {
    flex-direction: column;
    align-items: stretch;
  }
  .pwd-bar .btn {
    width: 100%;
  }

  /* 主操作按钮拉满、加大点击区域 */
  .row {
    gap: 0.5rem;
  }
  .btn {
    min-height: 44px;
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
  }
  #btnParse,
  #btnDownload,
  #btnQueueAdd,
  #btnSync,
  #btnShareAllCopy,
  #btnShareAllFetch,
  #btnAddCat,
  #btnRefreshPans {
    flex: 1 1 auto;
    min-width: calc(50% - 0.3rem);
  }
  #btnDownload,
  #btnQueueAdd,
  #btnSync,
  #btnShareAllCopy {
    min-width: 100%;
  }

  /* 分类添加：输入 + 按钮竖排 */
  #catName {
    flex: 1 1 100%;
  }
  #btnAddCat {
    min-width: 100%;
  }

  /* 网盘卡片：两列更易点 */
  .pan-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.55rem;
  }
  .pan-card {
    padding: 0.7rem 0.6rem;
  }
  .pan-card .name {
    font-size: 0.92rem;
  }
  .pan-card .acts {
    flex-direction: column;
  }
  .pan-card .btn {
    width: 100%;
    min-height: 40px;
    font-size: 0.85rem;
    padding: 0.45rem 0.5rem;
  }

  /* 分享区：手机上竖排 */
  .share-item {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .share-item .btn {
    width: 100%;
    min-height: 40px;
  }
  .share-box {
    padding: 0.75rem;
  }

  /* 单选/复选加大命中 */
  .inline-radio,
  .inline-check {
    min-height: 40px;
    padding: 0.25rem 0;
  }
  .inline-radio input,
  .checkboxes input,
  .inline-check input {
    width: 1.15rem;
    height: 1.15rem;
  }
  .checkboxes {
    gap: 0.65rem 0.85rem;
    font-size: 0.95rem;
  }
  .checkboxes label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 40px;
  }

  /* 网盘分享选项换行 */
  .share-box + .row,
  section.card > .row {
    align-items: stretch;
  }

  .preview-result {
    gap: 0.65rem;
  }
  .preview-result .cover {
    flex-basis: 64px;
    width: 64px;
    height: 86px;
  }
  .preview-result .meta .title {
    font-size: 0.9rem;
    -webkit-line-clamp: 4;
  }

  .video-list,
  .job-list {
    max-height: 220px;
    -webkit-overflow-scrolling: touch;
  }
  .video-list li,
  .job-list li {
    padding: 0.65rem 0.35rem;
    font-size: 0.9rem;
  }

  /* 扫码弹层：贴近底部，拇指好关 */
  .modal {
    align-items: flex-end;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .modal-box {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom, 0));
  }
  .modal-box #qrClose {
    width: 100%;
    min-height: 46px;
    margin-top: 0.35rem;
  }

  .toast {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    left: 0.75rem;
    right: 0.75rem;
    transform: none;
    max-width: none;
    text-align: center;
    font-size: 0.9rem;
  }

  .dl-bar {
    height: 10px;
  }
  .dl-text {
    font-size: 0.88rem;
  }

  .share-actions {
    flex-direction: column;
    align-items: stretch !important;
  }
  .share-actions .inline-radio {
    width: 100%;
  }

  .hero-row {
    flex-wrap: wrap;
  }
  .login-card {
    padding: 1.25rem 1rem 1.15rem;
  }
  .top-progress {
    margin-left: -0.15rem;
    margin-right: -0.15rem;
    border-radius: 8px;
  }
}

/* 超窄屏：网盘一列，避免挤 */
@media (max-width: 380px) {
  .pan-grid {
    grid-template-columns: 1fr;
  }
  #btnParse,
  #btnDownload {
    min-width: 100%;
  }
}
