/* R2 增强管理 - 样式（浅色主题） */
*,
*::before,
*::after { box-sizing: border-box; }

/* 关键：HTML 的 hidden 属性会被显式 display 声明覆盖（如 .drop-mask { display:flex }），
   导致拖拽遮罩等元素从页面加载起就一直显示、挡住整个界面。
   用 !important 强制 [hidden] 永远不显示。 */
[hidden] { display: none !important; }

:root {
  --bg: #f5f7fa;
  --bg-2: #ffffff;
  --bg-3: #eef1f6;
  --bg-hover: #e6eaf1;
  --line: #d8dee8;
  --text: #1f2733;
  --text-dim: #5b6673;
  --text-faint: #8b95a3;
  --accent: #3b6cf5;
  --accent-2: #2f5adf;
  --danger: #d63b3b;
  --ok: #1f9d55;
  --warn: #b57e16;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(31, 39, 51, .12);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* 禁止页面级横向滚动：移动端只允许上下滑动 */
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
code {
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--accent);
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: #c4ccd8; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.btn-primary:hover { background: #3f63e8; border-color: #3f63e8; }

.btn-ghost { background: transparent; }
.btn-danger {
  background: transparent;
  border-color: rgba(214, 59, 59, .45);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(214, 59, 59, .1); border-color: var(--danger); }
.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-faint);
}
.btn-danger-ghost:hover { color: var(--danger); background: rgba(214, 59, 59, .08); }

.btn-icon {
  padding: 7px 10px;
  font-size: 15px;
  line-height: 1;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-text { min-width: 0; }
.logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #f5b453, #f2793f);
  position: relative;
  flex: none;
}
.logo::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 3px solid #ffffff;
  border-bottom-color: transparent;
  border-radius: 50%;
  transform: rotate(-45deg);
}

.brand-text h1 { font-size: 15.5px; letter-spacing: .2px; }
.conn-status {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conn-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}
.conn-status.on { color: var(--ok); }
.conn-status.on::before { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.conn-status.err { color: var(--danger); }
.conn-status.err::before { background: var(--danger); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.config-switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
select {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  min-width: 140px;
  max-width: 220px;
}

/* ---------- 视图 ---------- */
.view { flex: 1; }

/* ---------- 配置页 ---------- */
.config-wrap {
  max-width: 860px;
  margin: 56px auto;
  padding: 0 20px;
}
.config-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 30px;
  box-shadow: var(--shadow);
}
.config-card h2 { font-size: 19px; margin-bottom: 12px; }
.hint { color: var(--text-dim); font-size: 13.5px; margin-bottom: 22px; }
.hint strong { color: var(--warn); }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field-row { display: flex; flex-direction: column; gap: 10px; }
.field-row.actions {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.actions-left, .actions-right { display: flex; gap: 10px; flex-wrap: wrap; }

label {
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 5px;
}
label em { color: var(--danger); font-style: normal; font-weight: 600; }
.optional { color: var(--text-faint); font-size: 11.5px; }

input[type="text"],
input[type="password"],
input[type="search"],
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 108, 245, .16);
}
input.invalid { border-color: var(--danger); }
input::placeholder { color: var(--text-faint); }

.cfg-errors {
  background: rgba(214, 59, 59, .08);
  border: 1px solid rgba(214, 59, 59, .35);
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 16px;
  font-size: 13px;
  color: #b3261e;
}
.cfg-errors li { margin-left: 18px; }

.cors-note {
  margin-top: 20px;
  padding: 12px 14px;
  background: rgba(181, 126, 22, .08);
  border: 1px solid rgba(181, 126, 22, .3);
  border-radius: 8px;
  font-size: 12.8px;
  color: var(--text-dim);
}
.cors-json {
  margin: 10px 0 2px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 12px/1.6 ui-monospace, Consolas, "Courier New", monospace;
  color: var(--text);
  overflow-x: auto;
  white-space: pre;
}
#originHere {
  color: var(--warn);
  font-weight: 600;
}

/* ---------- 环境自检 ---------- */
.env-check { margin-top: 16px; }
.env-check-result {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12.8px;
  color: var(--text);
  word-break: break-all;
}
.env-check-result ul { margin: 4px 0; padding-left: 20px; }
.env-check-result .env-bad {
  color: var(--danger);
  font-weight: 600;
  list-style: none;
  padding-left: 4px;
}

/* ---------- 粘贴导入 ---------- */
.paste-import {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.paste-import-hint { font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; }
.paste-import textarea {
  background: var(--bg-2);
  font: 12.5px/1.5 ui-monospace, Consolas, "Courier New", monospace;
  resize: vertical;
}
.paste-import-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- 分区 Tab ---------- */
.sections-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px 0;
  flex-wrap: wrap;
}
.sections {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.section-tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.section-tab:hover { background: var(--bg-3); color: var(--text); }
.section-tab.active {
  background: var(--bg-2);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(31, 39, 51, .08);
}
.view-toggle { display: flex; gap: 6px; }
.view-toggle .btn { font-size: 15px; line-height: 1; }
.view-toggle .btn.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

/* ---------- 网格视图（分区展示） ---------- */
.grid-body {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.grid-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  transition: box-shadow .15s, transform .1s;
}
.grid-card:hover { box-shadow: 0 4px 14px rgba(31, 39, 51, .14); }
.grid-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59, 108, 245, .3); }
.grid-thumb {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-3);
  overflow: hidden;
}
.grid-thumb img { width: 100%; height: 100%; object-fit: cover; }
.grid-icon { font-size: 40px; }
.grid-meta { padding: 8px 10px 6px; }
.grid-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.grid-name:hover { color: var(--accent); }
.grid-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.grid-check {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, .9);
  border-radius: 4px;
  padding: 2px;
}
.grid-actions {
  display: flex;
  gap: 2px;
  padding: 4px 8px 8px;
  flex-wrap: wrap;
}
.grid-actions .row-btn { padding: 4px 7px; font-size: 12px; }

/* ---------- 文件页 ---------- */
.crumb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 22px 0;
  flex-wrap: wrap;
}
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 13.5px;
  min-width: 0;
}
.crumb-item {
  cursor: pointer;
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 6px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb-item:hover { background: var(--bg-3); color: var(--text); }
.crumb-item.current { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--text-faint); }
.crumb-actions { display: flex; align-items: center; gap: 8px; }
.crumb-actions input[type="search"] { width: 200px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  flex-wrap: wrap;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.upload-btn { display: inline-flex; align-items: center; gap: 6px; }

.sel-info { font-size: 12.5px; color: var(--text-dim); }

/* ---------- 表格 ---------- */
.table-wrap {
  margin: 0 22px 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;   /* 窄屏时表格在容器内滚动，不撑破页面 */
  overflow-y: hidden;
  background: var(--bg-2);
  max-width: 100%;
}
.file-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.file-table th {
  text-align: left;
  padding: 11px 14px;
  background: var(--bg-3);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
.file-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(31, 39, 51, .08);
  vertical-align: middle;
}
.file-table tbody tr:hover { background: var(--bg-hover); }
.file-table tbody tr:last-child td { border-bottom: none; }
.file-table tbody tr.selected { background: rgba(59, 108, 245, .08); }

.col-check { width: 40px; }
.col-size { width: 100px; text-align: right; }
.col-date { width: 170px; color: var(--text-dim); }
.col-act { width: 150px; text-align: right; }

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent-2);
  cursor: pointer;
  vertical-align: middle;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}
.name-cell .icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--bg-3);
}
.name-cell .icon.folder { background: rgba(245, 180, 83, .2); }
.name-cell .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name-cell .sub { font-size: 11.5px; color: var(--text-faint); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12.5px;
  cursor: pointer;
}
.row-btn:hover { background: var(--bg-3); color: var(--text); border-color: var(--line); }
.row-btn.danger:hover { color: var(--danger); border-color: rgba(214, 59, 59, .45); background: rgba(214, 59, 59, .08); }

.empty-row td { text-align: center; padding: 40px; color: var(--text-faint); }

.empty-state {
  text-align: center;
  padding: 54px 20px;
  color: var(--text-dim);
}
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.muted { color: var(--text-faint); font-size: 12.5px; }

/* ---------- 预览模态框 ---------- */
.preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, .72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}
.preview-box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.preview-title {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-body {
  padding: 16px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 320px;
  min-height: 160px;
}
.preview-media {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 6px;
}
.preview-audio {
  text-align: center;
  padding: 12px 20px;
}
.preview-audio-icon { font-size: 40px; margin-bottom: 10px; }
.preview-audio audio { width: 340px; max-width: 100%; }
.preview-text {
  margin: 0;
  font: 12.5px/1.55 ui-monospace, Consolas, "Courier New", monospace;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  text-align: left;
  min-width: 360px;
  max-width: 86vw;
}

/* ---------- 拖拽遮罩 ---------- */
.drop-mask {
  position: fixed;
  inset: 0;
  background: rgba(245, 247, 250, .82);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.drop-inner {
  border: 2px dashed var(--accent);
  background: rgba(59, 108, 245, .08);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  padding: 60px 90px;
  border-radius: 18px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 200;
  max-width: 76vw;
}
.toast.ok { border-color: rgba(31, 157, 85, .5); }
.toast.err { border-color: rgba(214, 59, 59, .55); }

/* ---------- 进度 ---------- */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(31, 39, 51, .1);
  z-index: 300;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #8aa2f0);
  transition: width .2s;
}
.progress-text {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-dim);
  border: 1px solid var(--line);
}

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .config-switch label { display: none; }
  select { min-width: 110px; max-width: 150px; }
  .field-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
  .config-wrap { margin-top: 24px; }
  .config-card { padding: 20px 18px; }
  .crumb-bar, .toolbar { padding-left: 14px; padding-right: 14px; }
  .table-wrap { margin: 0 14px 20px; }
  .crumb-actions input[type="search"] { width: 130px; }
  .col-date { display: none; }
  th.col-date { display: none; }
  .col-size { width: 78px; font-size: 12.5px; }
  .col-act { width: 110px; }
  .row-btn { padding: 5px 6px; font-size: 12px; }
  .preview-text { min-width: 0; max-width: 86vw; }
  .preview-body { min-width: 0; min-height: 120px; }
  /* 分区 Tab 单行紧凑：横向滚动不换行 */
  .sections-bar { padding: 12px 14px 0; }
  .sections {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
  }
  .sections::-webkit-scrollbar { display: none; }
  .section-tab { padding: 6px 10px; font-size: 13px; }
  .view-toggle { flex: none; }
}
