/* HCloud 欣雲圖床 — 管理介面
   色彩與字體參考 www.hhgalaxy.com 與 HHG 設計系統 v1.6 */

:root {
  --brand: #E78703;
  --brand-hover: #E07C00;
  --brand-press: #9B5F17;
  --brand-wash: #FDF4EB;
  --brand-text: #9B5F17;          /* 小字橘色系用古銅棕（對比足夠） */

  --ink: #1B2228;
  --text: #2B3238;
  --muted: #595757;
  --subtle: #8A9096;
  --line: #E4E7EB;
  --line-strong: #CDD2D8;
  --page: #F6F8FA;
  --card: #FFFFFF;
  --sunken: #EEF1F4;

  --danger: #D64545;
  --danger-wash: #FCEFEF;
  --ok: #1E9E62;
  --ok-wash: #E7F5EE;
  --info: #3269EE;

  --radius: 10px;
  --radius-lg: 14px;
  --pill: 999px;
  --shadow-sm: 0 1px 2px rgba(39, 49, 59, .06);
  --shadow: 0 4px 10px rgba(39, 49, 59, .08);
  --shadow-lg: 0 12px 32px rgba(39, 49, 59, .16);
  --focus: 0 0 0 3px rgba(231, 135, 3, .30);

  --font: "Montserrat", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --gutter: clamp(16px, 3vw, 32px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page);
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }

/* ── 頂部列 ───────────────────────────── */
/* 固定區（頂部列＋路徑＋工具列）：毛玻璃，捲動時內容從下方透過 */
.head {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246, 248, 250, .55);
  -webkit-backdrop-filter: blur(20px) saturate(1.7);
  backdrop-filter: blur(20px) saturate(1.7);
  border-bottom: 1px solid rgba(205, 210, 216, .55);
  transition: box-shadow .2s, background .2s;
}
.head.scrolled { box-shadow: 0 8px 24px rgba(39, 49, 59, .08); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .head { background: rgba(246, 248, 250, .97); }
}
.topbar { border-bottom: 1px solid rgba(205, 210, 216, .45); }
.subhead-inner { max-width: 1320px; margin: 0 auto; padding: 14px var(--gutter) 14px; transition: padding .3s ease; }

/* 收合表頭：上方兩區往上收，只留工具列 */
.fold { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .32s ease, opacity .22s ease; }
.fold-in { min-height: 0; overflow: hidden; }
.fold-sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 2px; }
.fold-btn .icon { transition: transform .32s ease; }
.mini-path {
  display: none; align-items: center; gap: 6px; max-width: 220px;
  padding: 0 6px 0 4px; font-size: 14px; font-weight: 600; color: var(--ink);
}
.mini-path .icon { color: var(--brand); }
.mini-path span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 641px) {
  .head.collapsed .fold { grid-template-rows: 0fr; opacity: 0; }
  .head.collapsed .fold-in { visibility: hidden; transition: visibility 0s .32s; }
  .head.collapsed .subhead-inner { padding-top: 8px; padding-bottom: 8px; }
  .head.collapsed .topbar { border-bottom-color: transparent; }
  .head.collapsed .fold-btn .icon { transform: rotate(180deg); }
  .head.collapsed .mini-path { display: inline-flex; }
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { height: 34px; width: auto; }
.brand .app-name {
  padding-left: 14px; border-left: 1px solid var(--line);
  font-weight: 600; color: var(--ink); white-space: nowrap;
}
.brand .app-name small { display: block; font-size: 11px; font-weight: 500; letter-spacing: .14em; color: var(--subtle); text-transform: uppercase; }
.topbar .spacer { flex: 1; }

.identity { display: flex; align-items: center; gap: 8px; }
.identity label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.select {
  appearance: none;
  height: 36px; padding: 0 34px 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--pill);
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23595757' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  max-width: 280px; text-overflow: ellipsis;
  cursor: pointer;
}
.select:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }

.user { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.user .email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 版面 ───────────────────────────── */
.wrap { max-width: 1320px; margin: 0 auto; padding: 20px var(--gutter) 80px; }

.pathbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 12px; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 14px; color: var(--muted); }
.crumbs a { padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--sunken); color: var(--ink); }
.crumbs .icon { width: 14px; height: 14px; color: var(--subtle); }
.folder-title { margin: 2px 0 0; font-size: 24px; font-weight: 700; color: var(--ink); letter-spacing: -.01em; word-break: break-all; }
.counts { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ── 工具列 ───────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .62); border: 1px solid rgba(205, 210, 216, .7); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.toolbar .grow { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 18px;
  border: 1px solid var(--line-strong); border-radius: var(--pill);
  background: var(--card); color: var(--ink);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, transform .15s, box-shadow .15s;
}
.btn:hover { background: var(--sunken); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); box-shadow: 0 6px 16px rgba(231, 135, 3, .25); }
.btn-primary:active { background: var(--brand-press); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #BF3A3A; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--sunken); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: var(--pill); background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-btn.danger:hover { background: var(--danger-wash); color: var(--danger); }

.search { position: relative; min-width: 220px; flex: 0 1 300px; }
.search .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--subtle); }
.search input {
  width: 100%; height: 38px; padding: 0 14px 0 38px;
  border: 1px solid var(--line-strong); border-radius: var(--pill); background: var(--card);
}
.search input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.search input::placeholder { color: var(--subtle); }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--sunken); border-radius: var(--pill); }
.seg button { display: grid; place-items: center; width: 32px; height: 30px; border: 0; border-radius: var(--pill); background: transparent; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ── 提示列 ───────────────────────────── */
.notice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; margin-bottom: 16px;
  border-radius: var(--radius); font-size: 14px;
  background: var(--brand-wash); color: var(--brand-text);
}
.notice .icon { margin-top: 2px; }
.notice.error { background: var(--danger-wash); color: #8E2B2B; }

/* ── 區塊標題 ───────────────────────────── */
.section-label {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 10px; font-size: 12px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--subtle);
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ── 資料夾 ───────────────────────────── */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 28px; }
.folder {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 12px 8px 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
.folder:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.folder > a { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; color: var(--ink); font-weight: 500; }
.folder > a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.folder .folder-icon { color: var(--brand); }
.folder .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .icon-btn { position: relative; z-index: 1; opacity: 0; }
.folder:hover .icon-btn, .folder .icon-btn:focus-visible { opacity: 1; }
.folder.up .folder-icon { color: var(--subtle); }

/* ── 檔案：格狀 ───────────────────────────── */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.file {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.file:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.thumb {
  position: relative; aspect-ratio: 4 / 3;
  display: grid; place-items: center;
  background: var(--sunken);
  background-image: linear-gradient(45deg, #E9ECEF 25%, transparent 25%, transparent 75%, #E9ECEF 75%),
                    linear-gradient(45deg, #E9ECEF 25%, transparent 25%, transparent 75%, #E9ECEF 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
.thumb { overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.thumb .type-icon { width: 40px; height: 40px; color: var(--subtle); stroke-width: 1.5; }
.thumb .ext {
  position: absolute; left: 8px; top: 8px;
  padding: 1px 8px; border-radius: var(--pill);
  background: rgba(27, 34, 40, .72); color: #fff;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
}
.file-body { padding: 10px 12px 4px; min-width: 0; }
.file-name { font-size: 14px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { margin-top: 2px; font-size: 12px; color: var(--subtle); }
.file-actions { display: flex; align-items: center; gap: 2px; padding: 6px 6px 8px 8px; margin-top: auto; }
.file-actions .copy {
  flex: 1; justify-content: flex-start; height: 32px; padding: 0 10px;
  border: 0; font-size: 13px; color: var(--muted); background: transparent;
}
.file-actions .copy:hover { background: var(--brand-wash); color: var(--brand-text); }
.file-actions .copy.done { color: var(--ok); background: var(--ok-wash); }

/* ── 檔案：清單 ───────────────────────────── */
.files.list { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.files.list .file {
  flex-direction: row; align-items: center; gap: 12px;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none;
  padding: 8px 8px 8px 10px;
}
.files.list .file:last-child { border-bottom: 0; }
.files.list .file:hover { background: #FAFBFC; }
.files.list .thumb { width: 56px; height: 42px; aspect-ratio: auto; flex: none; border-radius: 6px; }
.files.list .thumb .type-icon { width: 22px; height: 22px; }
.files.list .thumb .ext { display: none; }
.files.list .file-body { flex: 1; padding: 0; display: grid; grid-template-columns: 1fr 120px 150px; align-items: center; gap: 12px; }
.files.list .file-meta { margin: 0; display: contents; }
.files.list .file-meta span { font-size: 13px; color: var(--muted); }
.files.list .file-actions { padding: 0; margin: 0; }
.files.list .file-actions .copy { flex: none; }

/* ── 無限捲動 ───────────────────────────── */
.more { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 28px 0 8px; font-size: 13px; color: var(--muted); }
.more button { margin-left: 4px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.more.idle .spinner, .more.failed .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 空狀態 ───────────────────────────── */
.empty {
  padding: 56px 24px; text-align: center; color: var(--muted);
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--card);
}
.empty .icon { width: 36px; height: 36px; margin: 0 auto 10px; color: var(--subtle); stroke-width: 1.5; }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ── 拖曳上傳覆蓋層 ───────────────────────────── */
.dropzone {
  position: fixed; inset: 0; z-index: 50; display: none;
  place-items: center; padding: 24px;
  background: rgba(246, 248, 250, .88);
}
.dropzone.on { display: grid; }
.dropzone-box {
  width: min(560px, 100%); padding: 48px 24px; text-align: center;
  border: 2px dashed var(--brand); border-radius: 18px; background: var(--card);
  color: var(--ink); font-size: 17px; font-weight: 600;
}
.dropzone-box .icon { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--brand); }
.dropzone-box small { display: block; margin-top: 6px; font-size: 13px; font-weight: 400; color: var(--muted); word-break: break-all; }

/* ── 上傳進度面板 ───────────────────────────── */
.upload-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 40;
  width: min(400px, calc(100vw - 32px));
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.upload-panel[hidden] { display: none; }
.upload-head { display: flex; align-items: center; gap: 10px; padding: 12px 8px 12px 16px; border-bottom: 1px solid var(--line); }
.upload-head strong { flex: 1; font-size: 14px; color: var(--ink); }
.upload-bar { height: 3px; background: var(--sunken); }
.upload-bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.upload-list { list-style: none; margin: 0; padding: 6px 0; max-height: 280px; overflow: auto; font-size: 13px; }
.upload-list li { display: flex; align-items: center; gap: 10px; padding: 6px 16px; }
.upload-list .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-list .s { color: var(--subtle); white-space: nowrap; }
.upload-list .ok .s { color: var(--ok); }
.upload-list .bad .s { color: var(--danger); }
.upload-list .reason { display: block; color: var(--danger); font-size: 12px; white-space: normal; }

/* ── 對話框 ───────────────────────────── */
dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0;
  border: 0; border-radius: 16px; box-shadow: var(--shadow-lg); color: var(--text);
}
dialog::backdrop { background: rgba(27, 34, 40, .45); }
.dlg-body { padding: 22px 22px 8px; }
.dlg-body h2 { margin: 0 0 8px; font-size: 18px; color: var(--ink); }
.dlg-body p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.dlg-body .field { display: block; width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); }
.dlg-body .field:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.dlg-body .hint { margin-top: 8px; font-size: 13px; color: var(--brand-text); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 20px; }
.help ol { margin: 0; padding-left: 20px; font-size: 14px; color: var(--text); }
.help li { margin-bottom: 8px; }
.help code { padding: 1px 6px; border-radius: 4px; background: var(--sunken); font-size: 13px; }

/* ── 提示訊息 ───────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: var(--pill);
  background: var(--ink); color: #fff; font-size: 14px; box-shadow: var(--shadow-lg);
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ── 登入頁 ───────────────────────────── */
.login {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  background: var(--card);
}
.login-main { display: flex; flex-direction: column; padding: 32px clamp(24px, 6vw, 72px); }
.login-main .brand img { height: 40px; }
.login-form { margin: auto 0; max-width: 380px; padding: 40px 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--brand); }
.rule { width: 56px; height: 4px; margin: 10px 0 18px; background: var(--brand); border-radius: 2px; }
.login-form h1 { margin: 0 0 10px; font-size: 32px; line-height: 1.2; color: var(--ink); letter-spacing: -.01em; }
.login-form p { margin: 0 0 28px; color: var(--muted); }
.login-form .note { margin-top: 18px; font-size: 13px; color: var(--subtle); }
.login-foot { font-size: 12px; color: var(--subtle); }
.login-side {
  position: relative; overflow: hidden;
  background: var(--page); border-left: 1px solid var(--line);
  display: grid; place-items: center; padding: 48px;
}
.login-side .tiles { display: grid; grid-template-columns: repeat(3, 120px); gap: 14px; transform: rotate(-6deg); opacity: .9; }
.login-side .tile { height: 120px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-sm); display: grid; place-items: center; color: var(--line-strong); }
.login-side .tile .icon { width: 30px; height: 30px; stroke-width: 1.5; }
.login-side .tile.hl { background: var(--brand-wash); border-color: #F6DDBF; color: var(--brand); }
.login-side .tile.star img { width: 52px; }

/* ── RWD ───────────────────────────── */
@media (max-width: 900px) {
  .brand .app-name { display: none; }
  .user .email { display: none; }
  .files.list .file-body { grid-template-columns: 1fr; gap: 0; }
  .files.list .file-meta { display: flex; gap: 10px; }
  .files.list .file-meta span { font-size: 12px; }
  .login { grid-template-columns: 1fr; }
  .login-side { display: none; }
}
@media (max-width: 640px) {
  /* 手機：只固定工具列，其餘正常捲動 */
  .head, .subhead, .subhead-inner { display: contents; }
  .topbar { background: var(--card); border-bottom: 1px solid var(--line); }
  .pathbar { padding: 16px var(--gutter) 0; }
  .toolbar {
    position: sticky; top: 8px; z-index: 20;
    margin: 0 var(--gutter);
    background: rgba(255, 255, 255, .72);
    -webkit-backdrop-filter: blur(16px) saturate(1.6);
    backdrop-filter: blur(16px) saturate(1.6);
    box-shadow: 0 6px 18px rgba(39, 49, 59, .10);
  }
  .topbar-inner { flex-wrap: wrap; gap: 10px; }
  .brand img { height: 28px; }
  .identity { order: 3; width: 100%; }
  .identity label { display: none; }
  .identity form { flex: 1; }
  .select { width: 100%; max-width: none; }
  .wrap { padding-top: 16px; }
  .folder-title { font-size: 21px; }
  .toolbar { padding: 10px; gap: 8px; }
  .toolbar .btn { flex: 1 1 auto; padding: 0 12px; }
  .toolbar .btn .lbl-long { display: none; }
  .search { flex: 1 1 100%; order: 10; min-width: 0; }
  .toolbar .grow { display: none; }
  .folders { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .counts { white-space: normal; }
  .seg, .fold-sep, .fold-btn, .mini-path { display: none !important; }
  .toolbar .btn { min-width: 0; }
  .folder .icon-btn { opacity: 1; }
  .files { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .files.list .file-body { min-width: 0; }
  .file-actions .copy span { display: none; }
  .file-actions .copy { flex: none; }
  .file-actions { justify-content: space-between; }
  .upload-panel { right: 16px; bottom: 16px; }
}
@media (hover: none) {
  .folder .icon-btn { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
