:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-hover: #f0f2f5;
  --fg: #1f2328;
  --fg-muted: #6b7280;
  --border: #e3e6ea;
  --border-strong: #d0d5dc;
  --link: #2563eb;
  --link-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --radius: 6px;
  --row-h: 36px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --bg-soft: #1b1e22;
  --bg-hover: #22262b;
  --fg: #e6e8eb;
  --fg-muted: #9aa3ad;
  --border: #2a2f36;
  --border-strong: #3a4048;
  --link: #6ea8fe;
  --link-hover: #9dc1ff;
  --danger: #f87171;
  --danger-soft: #2a1a1a;
  --ok: #4ade80;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --bg-soft: #1b1e22;
    --bg-hover: #22262b;
    --fg: #e6e8eb;
    --fg-muted: #9aa3ad;
    --border: #2a2f36;
    --border-strong: #3a4048;
    --link: #6ea8fe;
    --link-hover: #9dc1ff;
    --danger: #f87171;
    --danger-soft: #2a1a1a;
    --ok: #4ade80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  height: 52px;
  min-width: 0;
}

.brand {
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--fg); }

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  color: var(--fg-muted);
  font-size: 13px;
}
.crumbs .sep { color: var(--border-strong); }
.crumbs .current { color: var(--fg); }

.spacer { flex: 1; }

.search input {
  width: 180px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}
.search input:focus {
  outline: none;
  border-color: var(--link);
  background: var(--bg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.btn-primary {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}
.btn-primary:hover { background: var(--fg); color: var(--bg); opacity: .85; }

.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }

.inline { display: inline; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.page-head h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.muted { color: var(--fg-muted); font-size: 13px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--bg);
}

table.listing {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.listing thead th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  height: 34px;
  white-space: nowrap;
}
.listing thead th a { color: inherit; }
.listing thead th a:hover { color: var(--fg); text-decoration: none; }

.listing tbody td {
  padding: 0 12px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.listing tbody tr:last-child td { border-bottom: none; }
.listing tbody tr:hover { background: var(--bg-hover); }
.listing tbody tr.selected { background: var(--bg-hover); }

.col-check { width: 36px; padding-right: 0 !important; }
.col-check input { accent-color: var(--link); }
.col-size { width: 110px; text-align: right; color: var(--fg-muted); white-space: nowrap; }
.col-time { width: 150px; color: var(--fg-muted); white-space: nowrap; }
.col-name { min-width: 200px; }

.col-name .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  margin-right: 6px;
  color: var(--fg-muted);
  vertical-align: -3px;
}
.col-name .icon .ico { width: 16px; height: 16px; }
tr[data-dir="1"] .col-name .icon { color: var(--link); }

.row-up a { color: var(--fg-muted); }

td.empty {
  text-align: center;
  color: var(--fg-muted);
  padding: 40px 12px !important;
  height: auto !important;
}

.path-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  background: var(--bg-soft);
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.badge-ok { color: var(--ok); border-color: currentColor; }
.badge-denied, .badge-error { color: var(--danger); border-color: currentColor; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.filters {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-muted);
}
.filters input, .filters select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  min-width: 130px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.stack input {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
.stack input:focus { outline: none; border-color: var(--link); }

.form-error {
  margin: 0 0 14px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

.login-card {
  max-width: 340px;
  margin: 8vh auto 0;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.login-card h1 { margin: 0 0 20px; font-size: 17px; font-weight: 600; text-align: center; }

.preview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.preview-head h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  overflow-wrap: anywhere;
  min-width: 0;
}
.preview-head .actions { margin-left: auto; display: flex; gap: 8px; }

.back-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-size: 12.5px;
  line-height: 1;
}
.back-inline:hover {
  background: var(--bg-hover);
  color: var(--fg);
  text-decoration: none;
}
.back-inline:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.office-frame {
  width: 100%;
  height: 78vh;
  border: none;
  background: var(--bg);
  border-radius: var(--radius);
}

.muted.small { font-size: 12px; max-width: 520px; }

.preview-loading {
  padding: 40px 20px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 13px;
}
.preview-loading[hidden] { display: none; }

.preview-body {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  min-height: 240px;
  display: flex;
  flex-direction: column;
}

.media-box {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 240px;
}
.media-box img, .media-box video {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 4px;
  background: #000;
}
.media-box.audio { min-height: 120px; }
.media-box audio { width: min(560px, 100%); }

.pdf-frame {
  width: 100%;
  height: 76vh;
  border: none;
  background: var(--bg);
  border-radius: var(--radius);
}

.md-switch {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.md-switch .is-active { background: var(--bg-hover); font-weight: 500; }

article.markdown {
  padding: 24px 28px;
  background: var(--bg);
  overflow-wrap: anywhere;
}
article.markdown h1, article.markdown h2, article.markdown h3 { line-height: 1.3; }
article.markdown pre {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
}
article.markdown code { font-family: var(--mono); font-size: 12.5px; }
article.markdown img { max-width: 100%; }
article.markdown table { border-collapse: collapse; }
article.markdown th, article.markdown td {
  border: 1px solid var(--border);
  padding: 6px 10px;
}
article.markdown blockquote {
  margin: 0;
  padding-left: 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--fg-muted);
}

pre.code {
  margin: 0;
  padding: 16px 20px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  tab-size: 4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.no-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
}

.meta {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px 16px;
  margin: 18px 0 0;
  font-size: 13px;
}
.meta dt { color: var(--fg-muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; }

.error-page {
  text-align: center;
  padding: 12vh 20px;
}
.error-page h1 {
  font-size: 56px;
  margin: 0 0 8px;
  color: var(--fg-muted);
  font-weight: 600;
}
.error-page p { margin: 0 0 20px; }

.dropzone-hint {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.dropzone-hint[hidden] { display: none; }
.dropzone-inner {
  padding: 40px 60px;
  border: 2px dashed var(--link);
  border-radius: 12px;
  color: var(--link);
  font-size: 16px;
  background: var(--bg);
}

.upload-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 70;
  width: min(360px, calc(100vw - 40px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14);
  overflow: hidden;
}
.upload-panel[hidden] { display: none; }
.upload-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.upload-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  max-height: 260px;
  overflow-y: auto;
}
.upload-list li {
  padding: 8px 14px;
  font-size: 12.5px;
}
.upload-name {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}
.upload-name span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-name .pct { color: var(--fg-muted); flex-shrink: 0; }
.upload-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-hover);
  overflow: hidden;
}
.upload-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--link);
  transition: width .15s linear;
}
.upload-list li.is-error .upload-bar > i { background: var(--danger); }
.upload-list li.is-done .upload-bar > i { background: var(--ok); }

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  background: var(--bg);
  color: var(--fg);
  min-width: 300px;
  max-width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
dialog input[type="text"] {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
dialog .dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
dialog .dialog-text { margin: 0 0 4px; font-size: 13.5px; overflow-wrap: anywhere; }

.context-menu {
  position: fixed;
  z-index: 80;
  min-width: 150px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
}
.context-menu button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.context-menu button:hover { background: var(--bg-hover); }
.context-menu button.danger { color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 90;
  padding: 9px 18px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.toast[hidden] { display: none; }

@media (max-width: 720px) {
  .topbar-inner { padding: 0 14px; gap: 8px; height: 50px; }
  .crumbs { display: none; }
  .search input { width: 120px; }
  .container { padding: 14px; }
  .col-time { display: none; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .meta { grid-template-columns: 72px 1fr; }
}
