/* ============================================================
   图库 · 深色主题 + 暖橙强调色
   零构建、纯原生 CSS
   ============================================================ */

:root {
  --bg: #15151a;
  --bg-card: #1f1f26;
  --text: #e8e6e3;
  --text-dim: #8a8784;
  --accent: #cf5b2c;
  --accent-soft: rgba(207, 91, 44, 0.15);
  --border: #2c2c34;
  --radius: 8px;
  --radius-sm: 6px;
  --github: #5b8def;        /* github 徽章蓝灰 */
  --r2: #cf5b2c;            /* r2 徽章橙（同强调色） */
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* hidden 属性优先级最高，防止 display:flex 等覆盖导致元素始终可见 */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 顶部 header ---------------- */
header {
  padding: 28px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ---------------- 登录区（header 右侧） ---------------- */
.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* R2 直链导航入口 */
.nav-link {
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, color 0.15s;
}
.nav-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* 目录下拉按来源分组：optgroup 标题加粗染色 */
#folder-select optgroup {
  font-weight: 600;
  color: var(--text);
  font-style: normal;
}
#folder-select option {
  color: var(--text-dim);
  font-weight: 400;
}
.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.login-btn:hover { border-color: var(--accent); }
.user-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.user-info img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
}
#user-name { font-size: 13px; color: var(--text-dim); }
.logout-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.logout-btn:hover { border-color: var(--accent); color: var(--accent); }

.brandmark { color: var(--text); display: inline-flex; }

.brand-text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.5px;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------------- 工具栏 ---------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  max-width: 1400px;
  margin: 0 auto;
}

/* 筛选字段容器：标签 + 控件 */
.filter-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.field-label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.search-field { flex: 1 1 200px; min-width: 160px; }
.search-field input { flex: 1; }

.source-group { display: inline-flex; gap: 4px; }

.source-btn,
.primary-btn,
.lb-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.source-btn:hover { border-color: var(--accent); }
.source-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#folder-select,
#search {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
}
#search { flex: 1 1 220px; min-width: 160px; }
#search::placeholder { color: var(--text-dim); }
#search:focus, #folder-select:focus {
  outline: none;
  border-color: var(--accent);
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------- 瀑布流 ---------------- */
.gallery {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px 64px;
  column-count: auto;
  column-width: 240px;
  column-gap: 12px;
}

/* ---------------- 卡片 ---------------- */
.card {
  break-inside: avoid;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }

.card img {
  width: 100%;
  display: block;
  background: #0e0e12;
}

.card-meta {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-meta .meta-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.card-meta .meta-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.card-meta .folder {
  color: var(--text);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-meta .time { color: var(--text-dim); font-size: 11px; }
.card-meta .size { color: var(--text-dim); }

/* 卡片快捷复制按钮 */
.card-copy {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.card-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* 来源徽章 */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
}
.badge-github { background: rgba(91, 141, 239, 0.16); color: var(--github); }
.badge-r2 { background: var(--accent-soft); color: var(--r2); }

/* ---------------- 上传区 ---------------- */
.upload-zone {
  max-width: 1400px;
  margin: 16px auto 0;
  padding: 0 24px;
}

.upload-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--text-dim);
  transition: border-color 0.15s, background 0.15s;
}
.upload-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-pick {
  display: inline-block;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  text-align: left;
  font-size: 13px;
  max-height: 180px;
  overflow: auto;
}
.file-list li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.file-list .ok { color: #6ec46e; }
.file-list .err { color: var(--accent); }

.upload-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  font-size: 13px;
}
.target-group { display: inline-flex; gap: 12px; align-items: center; }
.opt-label { color: var(--text-dim); }
.target-group label { cursor: pointer; }

.path-input {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  flex: 1 1 260px;
}
.path-input input {
  flex: 1;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
}
.path-input input:focus { outline: none; border-color: var(--accent); }

/* ---------------- 灯箱 ---------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.lb-close {
  position: absolute;
  top: 16px;
  right: 22px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
}
.lb-close:hover { opacity: 1; }

.lb-figure {
  margin: 0;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lb-figure img {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #0e0e12;
}
.lb-url {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  max-width: 80vw;
}

/* 灯箱元信息区 */
.lb-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  max-width: 80vw;
  font-size: 12px;
  color: var(--text-dim);
}
.lb-meta .lb-field { white-space: nowrap; }
.lb-meta .lb-field b {
  color: var(--text-dim);
  font-weight: 500;
  margin-right: 4px;
}
.lb-actions { display: flex; gap: 8px; justify-content: center; }
.lb-btn.danger {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.lb-btn.danger:hover { background: var(--accent-soft); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 640px) {
  header { padding: 20px 16px 12px; }
  .toolbar, .gallery, .upload-zone { padding-left: 16px; padding-right: 16px; }
  .gallery { column-width: 160px; }
  .brand-text h1 { font-size: 19px; }
}

/* 空态占位 */
.gallery:empty::after {
  content: "暂无图片";
  display: block;
  color: var(--text-dim);
  text-align: center;
  padding: 60px 0;
}
