/* 影像筆記 — 繁中介面，亮/暗色隨系統 */
:root {
  --bg: #f6f5f3;
  --card: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --accent: #0f766e;
  --accent-2: #115e59;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0c0b;
    --card: #1c1917;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --border: #2e2a27;
    --accent: #2dd4bf;
    --accent-2: #99f6e4;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 1px 3px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "system-ui", "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; }
code, pre { font-family: Consolas, "Courier New", monospace; font-size: .92em; }
pre {
  background: rgba(127,127,127,.12);
  padding: .8rem 1rem;
  border-radius: 8px;
  overflow-x: auto;
}
code { background: rgba(127,127,127,.15); padding: .1em .35em; border-radius: 4px; }
pre code { background: none; padding: 0; }

/* ---- 頂欄 ---- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: .55rem 1.2rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; color: var(--accent); }
.usernav { display: flex; align-items: center; gap: .75rem; }
.who { color: var(--muted); font-size: .9rem; }

/* ---- 通用 ---- */
.container { max-width: 1280px; margin: 0 auto; padding: 1.1rem 1.2rem 3rem; min-height: 65vh; }
.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 1.2rem 0 2rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: .35em; justify-content: center;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .45rem .9rem; font-size: .92rem; font-family: inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: border-color .15s, background .15s, transform .05s;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04211d; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: .3rem .65rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: block; margin-bottom: .9rem; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
input[type="text"], input[type="password"], select, textarea {
  width: 100%; padding: .5rem .7rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text);
  font-family: inherit; font-size: .95rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.check { display: flex; gap: .5rem; align-items: center; margin: .8rem 0; font-size: .92rem; }

.flash {
  max-width: 1280px; margin: .8rem auto 0; padding: .6rem 1rem;
  border-radius: 8px; font-size: .92rem;
}
.flash.error { background: color-mix(in srgb, var(--danger) 12%, var(--bg)); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.flash.success { background: color-mix(in srgb, var(--ok) 12%, var(--bg)); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }

/* ---- 認證頁 ---- */
.auth-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; padding: 2rem 0; }
.auth-card {
  width: min(400px, 92vw);
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 2rem 1.8rem;
}
.auth-card.center { text-align: center; }
.auth-ico { font-size: 2.4rem; text-align: center; margin-bottom: .5rem; }

/* ---- 筆記本頁 ---- */
.album-head { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .95rem; }
.crumb { color: var(--muted); }
.crumb:hover { color: var(--accent); }
.crumb.current { color: var(--text); font-weight: 600; }
.sep { color: var(--muted); opacity: .6; }

.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; }
.sort { display: flex; flex-wrap: wrap; gap: .9rem; align-items: center; }
.sort label { display: flex; align-items: center; gap: .4rem; font-size: .88rem; color: var(--muted); }
.sort select { width: auto; padding: .35rem .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---- 分類 chips 與選擇器 ---- */
.cat-chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.cat-chips .chip {
  display: inline-flex; align-items: center; gap: .35em;
  padding: .22rem .75rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  font-size: .85rem; text-decoration: none;
  transition: border-color .15s, color .15s;
}
.cat-chips .chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.cat-chips .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .cat-chips .chip.on { color: #04211d; } }
.cat-chips .chip .n { opacity: .72; font-size: .78rem; font-variant-numeric: tabular-nums; }
.cat-sel select { width: auto; padding: .35rem .5rem; }
.meta .fpath {
  font-size: .75rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.readme {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem 1.3rem; margin-bottom: 1.4rem; box-shadow: var(--shadow);
}
.readme.empty { background: transparent; border-style: dashed; color: var(--muted); text-align: center; padding: .8rem; }
.readme h1 { font-size: 1.3rem; } .readme h2 { font-size: 1.15rem; } .readme h3 { font-size: 1.05rem; }
.readme img { max-width: 100%; border-radius: 8px; }
.readme blockquote { border-left: 3px solid var(--accent); margin: .6rem 0; padding: .1rem 1rem; color: var(--muted); }
.readme.preview { overflow: auto; min-height: 200px; max-height: 640px; }

.sec-title { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 1.2rem 0 .7rem; }

.album-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: .9rem;
  margin-bottom: 1.6rem;
}
.album-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; color: var(--text); box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.album-card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.cover { aspect-ratio: 16/10; background: rgba(127,127,127,.12); display: flex; align-items: center; justify-content: center; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-empty { font-size: 2rem; opacity: .5; }
.meta { display: flex; flex-direction: column; gap: .12rem; padding: .5rem .8rem .6rem; }
.meta .date-chip {
  font-size: .75rem; font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums; letter-spacing: .02em;
}
.meta .aname {
  font-weight: 600; font-size: .95rem; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word; overflow-wrap: anywhere;
}
.meta .count { color: var(--muted); font-size: .8rem; }

/* ---- 文件區（.md / .pdf / .docx） ---- */
.doc-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .7rem;
  margin-bottom: 1.6rem;
}
.doc-item {
  display: flex; align-items: stretch;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden;
  transition: border-color .12s;
}
.doc-item:hover { border-color: var(--accent); }
.doc-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: .7rem;
  padding: .65rem .8rem; color: var(--text); text-decoration: none;
}
.doc-main:hover { text-decoration: none; }
.doc-ico { font-size: 1.5rem; flex-shrink: 0; }
.doc-body { min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.doc-name {
  font-weight: 600; font-size: .92rem; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-meta { color: var(--muted); font-size: .76rem; }
.doc-rename, .doc-del {
  border: none; border-left: 1px solid var(--border); border-radius: 0;
  background: transparent; flex-shrink: 0;
}
.doc-rename:hover { border-color: var(--accent); }
.doc-del:hover { border-color: var(--danger); }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px;
}
.tile {
  position: relative; aspect-ratio: 1/1; border-radius: 10px; overflow: hidden;
  background: rgba(127,127,127,.12); cursor: zoom-in; outline-offset: 2px;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s ease; }
.tile:hover img, .tile:focus-visible img { transform: scale(1.05); }
.tile .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.7); pointer-events: none;
}
.tile .selbox {
  position: absolute; top: 6px; left: 6px;
  display: none; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(0,0,0,.45); backdrop-filter: blur(4px);
  cursor: pointer;
}
.tile .selbox input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
body.selecting .tile .selbox { display: flex; }
body.selecting .tile { cursor: pointer; }
body.selecting .tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }

.empty-state { text-align: center; padding: 4rem 0; color: var(--muted); }
.empty-state .big { font-size: 3rem; margin-bottom: .5rem; }

/* ---- 選取工具列 ---- */
#selbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 1.2rem; z-index: 60;
  display: flex; align-items: center; gap: .6rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: var(--shadow); padding: .5rem .9rem; font-size: .92rem;
}
#selbar[hidden] { display: none; }

/* ---- Lightbox ---- */
#lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(8,6,5,.94);
  display: flex; align-items: center; justify-content: center;
}
#lightbox[hidden] { display: none; }
.lb-stage { max-width: 94vw; max-height: 88vh; display: flex; align-items: center; justify-content: center; }
.lb-stage img, .lb-stage video {
  max-width: 94vw; max-height: 88vh; border-radius: 4px; object-fit: contain;
  box-shadow: 0 8px 60px rgba(0,0,0,.6);
}
.lb-btn {
  position: absolute; z-index: 2;
  background: rgba(255,255,255,.08); color: #fff; border: none; border-radius: 50%;
  width: 44px; height: 44px; font-size: 1.25rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lb-btn:hover { background: rgba(255,255,255,.22); }
.lb-close { top: 14px; right: 14px; }
.lb-prev { left: 10px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 10px; top: 50%; transform: translateY(-50%); }
.lb-side { position: absolute; top: 14px; right: 68px; display: flex; gap: 8px; }
.lb-side .lb-btn { position: static; }
.lb-cover.done { background: #f5b301; color: #3a2a00; }
.lb-shrink:disabled { opacity: .3; cursor: not-allowed; }
.lb-shrink.on { background: #f5b301; color: #3a2a00; }
.lb-caption {
  position: absolute; bottom: 0; left: 0; right: 0; text-align: center;
  color: rgba(255,255,255,.85); padding: .7rem 1rem; font-size: .88rem;
  background: linear-gradient(transparent, rgba(0,0,0,.55)); pointer-events: none;
}
.lb-name { font-weight: 600; }
.lb-sub { opacity: .75; font-size: .8rem; }
.lb-exif {
  position: absolute; top: 70px; right: 14px; z-index: 2;
  background: rgba(20,17,15,.92); border: 1px solid rgba(255,255,255,.12); border-radius: 10px;
  color: #e7e5e4; padding: .8rem 1rem; font-size: .82rem; min-width: 200px;
}
.lb-exif table { border-collapse: collapse; }
.lb-exif td { padding: .15rem .5rem .15rem 0; vertical-align: top; }
.lb-exif td:first-child { color: #a8a29e; white-space: nowrap; }

/* ---- PDF 檢視器（瀏覽器原生 PDF 內嵌 iframe） ---- */
#pdfview {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(8,6,5,.92);
  display: flex; flex-direction: column;
}
#pdfview[hidden] { display: none; }
.pv-bar {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 1rem; color: #fff; font-size: .92rem;
}
.pv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-frame {
  flex: 1; width: calc(100% - 2rem); margin: 0 1rem 1rem;
  border: none; border-radius: 8px; background: #fff;
}

/* ---- .md 筆記閱讀頁 ---- */
.doc-toolbar { display: flex; gap: .6rem; margin-top: .6rem; }
.readme.doc-view { max-width: 860px; }

/* ---- 對話框 ---- */
.dlg {
  border: none; border-radius: 14px; background: var(--card); color: var(--text);
  box-shadow: var(--shadow); padding: 0; width: min(440px, 92vw);
}
.dlg::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.dlg-form { padding: 1.3rem 1.4rem; }
.dlg-form h3 { margin: 0 0 1rem; font-size: 1.05rem; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.1rem; }

/* ---- 上傳頁 ---- */
.page-head { margin-bottom: 1.2rem; }
.upload-layout { display: grid; grid-template-columns: 320px 1fr; gap: 1.4rem; align-items: start; }
@media (max-width: 760px) { .upload-layout { grid-template-columns: 1fr; } }
.upload-panel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.2rem; }
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px;
  min-height: 320px; display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--bg)); }
.dz-inner { text-align: center; color: var(--muted); }
.dz-inner .big { font-size: 3rem; margin-bottom: .4rem; }
.queue { list-style: none; margin: 1.2rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.queue li {
  display: flex; align-items: center; gap: .8rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem .9rem; font-size: .9rem;
}
.queue .qname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .qstatus { color: var(--muted); }
.queue .qstatus.ok { color: var(--ok); }
.queue .qstatus.fail { color: var(--danger); }
.queue .qbar { width: 120px; height: 6px; border-radius: 3px; background: rgba(127,127,127,.2); overflow: hidden; flex-shrink: 0; }
.queue .qbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---- 批量縮小進度 ---- */
.shrink-progress { display: flex; align-items: center; gap: .8rem; margin: .6rem 0; }
.shrink-progress .qbar { height: 8px; width: auto; border-radius: 4px; background: rgba(127,127,127,.2); overflow: hidden; }
.shrink-progress .qbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-done { margin-top: 1.4rem; text-align: center; }

/* ---- README 編輯器 ---- */
.readme-editor .editor-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: stretch; }
@media (max-width: 860px) { .readme-editor .editor-cols { grid-template-columns: 1fr; } }
#readme-text { min-height: 420px; resize: vertical; font-family: Consolas, "Microsoft JhengHei", monospace; line-height: 1.55; }
.editor-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .4rem; }

/* ---- RWD ---- */
@media (max-width: 640px) {
  .container { padding: .8rem .8rem 3rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .actions { justify-content: flex-start; }
  .actions .btn { flex: 1; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
  .lb-prev { left: 4px; } .lb-next { right: 4px; }
}
