/* HUB 檔案中心 */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --side-bg: #0f172a;
  --side-text: #cbd5e1;
  --side-hover: #1e293b;
  --side-active: #2563eb;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --radius: 12px;
  --side-w: 232px;
  --cat-archive: #a16207;
  --cat-video: #7c3aed;
  --cat-image: #059669;
  --cat-pdf: #dc2626;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --panel: #111827; --panel-2: #0f172a; --line: #1f2937;
    --text: #e5e7eb; --muted: #94a3b8; --primary: #3b82f6; --primary-soft: #1e3a8a;
    --side-bg: #020617; --side-hover: #111827; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --cat-archive: #eab308; --cat-video: #a78bfa; --cat-image: #34d399; --cat-pdf: #f87171;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --panel: #111827; --panel-2: #0f172a; --line: #1f2937;
  --text: #e5e7eb; --muted: #94a3b8; --primary: #3b82f6; --primary-soft: #1e3a8a;
  --side-bg: #020617; --side-hover: #111827; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --cat-archive: #eab308; --cat-video: #a78bfa; --cat-image: #34d399; --cat-pdf: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; vertical-align: middle; }

/* ---------- 按鈕/表單 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap; min-height: 36px; text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 3px 10px; min-height: 28px; font-size: 13px; }
.btn.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 8px; display: inline-flex; }
.icon-btn:hover { background: var(--panel-2); }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=date],
input[type=datetime-local], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.msg { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.msg-error { background: #fee2e2; color: #991b1b; }
.msg-ok { background: #dcfce7; color: #166534; }

/* ---------- 版面 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--side-bg); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: width .2s ease;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 12px 13px; height: 60px; }
.logo-btn { border: 0; background: transparent; padding: 0; cursor: pointer; border-radius: 8px; display: flex; }
.logo-btn:focus-visible { outline: 2px solid #93c5fd; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: 2px; color: #fff; }
.side-nav { padding: 4px 8px 20px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; background: transparent; color: var(--side-text);
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-item:hover { background: var(--side-hover); color: #fff; }
.nav-item.active { background: var(--side-active); color: #fff; }
.nav-item .chev { margin-left: auto; transition: transform .2s; opacity: .7; }
.nav-group.open .chev { transform: rotate(90deg); }
.nav-sub { display: none; padding: 2px 0 6px 20px; }
.nav-group.open .nav-sub { display: block; }
.nav-sub .nav-item { font-size: 13px; padding: 7px 12px; }
.nav-sep { height: 1px; background: #1e293b; margin: 8px 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* 收合工具列：只留左上角 HUB 圖示 */
.app.side-collapsed .sidebar { width: 56px; }
.app.side-collapsed .brand, .app.side-collapsed .side-nav { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-x: clip; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px;
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.search { flex: 1; min-width: 0; max-width: 640px; margin: 0 auto; display: flex; gap: 8px; position: relative; }
.search input { padding-left: 34px; flex: 1; min-width: 0; }
.search-ico { position: absolute; left: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.user-menu { position: relative; }
.user-chip { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; cursor: pointer; padding: 4px; border-radius: 24px; }
.user-chip:hover { background: var(--panel); }
.user-name { font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { border-radius: 50%; object-fit: cover; background: var(--line); border: 2px solid var(--panel); box-shadow: var(--shadow); }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
}
.dropdown .dd-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dropdown .dd-head small { color: var(--muted); display: block; }
.dd-item { display: flex; gap: 10px; align-items: center; width: 100%; padding: 8px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; text-align: left; text-decoration: none; color: var(--text); }
.dd-item:hover { background: var(--panel-2); }

.content { padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.results, .display, .admin { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.results { padding: 16px; }
.results-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.results-head h2 { margin: 0; font-size: 18px; }
.count { color: var(--muted); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }

/* ---------- 縮圖格 ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel);
  display: flex; flex-direction: column; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--primary); }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.thumb {
  aspect-ratio: 4 / 3; background: var(--panel-2); display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; border: 0; padding: 0; width: 100%;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .big-ico svg { width: 52px; height: 52px; }
.badge { position: absolute; top: 6px; left: 6px; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: rgba(15,23,42,.72); color: #fff; }
.badge.vis { left: auto; right: 6px; }
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.card-name {
  border: 0; background: none; padding: 0; text-align: left; cursor: pointer; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-name:hover { color: var(--primary); text-decoration: underline; }
.card-meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.card-link { font-size: 12px; display: flex; gap: 4px; }
.card-link input { font-size: 12px; padding: 3px 6px; }
.card-actions { display: flex; gap: 6px; }
.card-actions .btn { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty svg { width: 44px; height: 44px; opacity: .5; }
.pager { display: flex; justify-content: center; gap: 6px; margin-top: 14px; }
.cat-archive { color: var(--cat-archive); } .cat-video { color: var(--cat-video); }
.cat-image { color: var(--cat-image); } .cat-pdf { color: var(--cat-pdf); }

/* ---------- 顯示區 ---------- */
.display { padding: 16px; min-height: 260px; }
.display-empty { color: var(--muted); text-align: center; padding: 60px 10px; }
.detail { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 20px; }
.preview { background: var(--panel-2); border-radius: 10px; min-height: 240px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.preview img, .preview video { max-width: 100%; max-height: 70vh; display: block; }
.preview iframe { width: 100%; height: 70vh; border: 0; background: #fff; }
.preview .big-ico svg { width: 96px; height: 96px; }
.info h3 { margin: 0 0 6px; font-size: 18px; word-break: break-all; }
.info .name-btn { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.info .name-btn:hover { color: var(--primary); text-decoration: underline; }
.link-box { display: flex; gap: 6px; margin: 8px 0 12px; }
.link-box input { font-size: 12px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin: 12px 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-all; }
.desc { white-space: pre-wrap; background: var(--panel-2); padding: 10px; border-radius: 8px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.tag-btn.on.like { background: #dcfce7; border-color: var(--ok); color: #166534; }
.tag-btn.on.dislike { background: #fee2e2; border-color: var(--danger); color: #991b1b; }

/* ---------- 管理頁 ---------- */
.admin { padding: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { border: 0; background: none; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tab.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: var(--panel-2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.tbl td.nowrap { white-space: nowrap; }
.tbl .acts { display: flex; gap: 4px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.warn { background: #fef3c7; color: #92400e; }
.pill.bad { background: #fee2e2; color: #991b1b; }
.pill.role-super { background: #ede9fe; color: #5b21b6; }
.pill.role-admin { background: #dbeafe; color: #1e40af; }
.pill.role-user { background: #f1f5f9; color: #334155; }
.mini-avatar { width: 26px; height: 26px; border-radius: 50%; vertical-align: middle; margin-right: 6px; object-fit: cover; }

/* ---------- 視窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer;
}
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop svg { width: 36px; height: 36px; }
.up-list { margin: 12px 0; display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow: auto; }
.up-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.up-item .top { display: flex; justify-content: space-between; gap: 8px; }
.up-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-item .st { color: var(--muted); flex: none; }
.up-item.err .st { color: var(--danger); }
.up-item.done .st { color: var(--ok); }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.radio-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; color: var(--text); }
.radio-row label { display: flex; align-items: center; gap: 4px; color: var(--text); font-size: 14px; cursor: pointer; }
.hint { font-size: 12px; color: var(--muted); }
.avatar-edit { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar-edit img { width: 72px; height: 72px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); }

/* ---------- 獨立頁（登入/註冊） ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 800; font-size: 20px; letter-spacing: 2px; }
.auth-card h1 { font-size: 20px; margin: 18px 0; }
.auth-form label { margin-bottom: 12px; }
.auth-form .btn { width: 100%; margin-top: 6px; }
.auth-foot { font-size: 13px; color: var(--muted); text-align: center; margin: 18px 0 0; }

/* ---------- 畫面尺寸 ----------
 * 首頁固定以 1024×768 為最小版面：
 *   Windows 電腦：視窗小於 1024×768 時出現捲軸，版面不會被擠壓
 *   手機/平板：index.php 把 viewport 設為 1024 寬，瀏覽器會把整個版面自動縮小到符合螢幕
 */
.app { min-width: 1024px; min-height: 768px; }
.sidebar { min-height: 768px; }
.side-scrim { display: none; }
