@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --paper: #eef1ec;
  --paper-alt: #e3e9e0;
  --card: #f7f8f4;
  --ink: #16231f;
  --ink-soft: #536358;
  --ink-faint: #8a998e;
  --vault: #1f4b3f;
  --vault-deep: #12332a;
  --vault-tint: #dce8e1;
  --brass: #b9822f;
  --brass-soft: #efdcb2;
  --brass-deep: #8a5f20;
  --danger: #a8452f;
  --danger-tint: #f3ddd5;
  --line: #cdd6cb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 35, 31, 0.06), 0 6px 20px rgba(22, 35, 31, 0.06);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(22,35,31,0.05) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }
a { color: inherit; }
button { font-family: inherit; }
::selection { background: var(--brass-soft); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 20px 14px;
}
.brand-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand .mark {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: var(--vault);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand .mark svg { width: 16px; height: 16px; }
.brand small {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 400;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
  display: block;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.admin-link {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 999px;
  transition: 0.15s;
}
.admin-link:hover { color: var(--vault); border-color: var(--vault); }

/* Ticket-stub breadcrumb */
.breadcrumb {
  margin-top: 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
}
.crumb {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 5px 11px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--ink-soft);
  position: relative;
  white-space: nowrap;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crumb:hover { border-color: var(--vault); color: var(--vault); }
.crumb.current { background: var(--vault); border-color: var(--vault); color: #fff; font-weight: 500; }
.crumb-sep { color: var(--ink-faint); padding: 0 1px; font-size: 0.7rem; }

/* Toolbar */
.toolbar {
  max-width: 1080px;
  margin: 18px auto 0;
  padding: 0 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 9px 15px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.15s;
}
.btn:hover { border-color: var(--vault); color: var(--vault); }
.btn svg { width: 15px; height: 15px; }
.btn-primary {
  background: var(--vault);
  border-color: var(--vault);
  color: #fff;
}
.btn-primary:hover { background: var(--vault-deep); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Main / grid ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 20px; padding-bottom: 80px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 6px;
}

.item-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px 13px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  text-align: left;
  overflow: hidden;
}
.item-card::before {
  content: '';
  position: absolute;
  top: 0; left: 14px;
  width: 26px; height: 5px;
  background: var(--vault-tint);
  border-radius: 0 0 4px 4px;
}
.item-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--vault); }
.item-card .icon {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
  color: var(--vault);
}
.item-card .icon svg { width: 30px; height: 30px; }
.item-card.is-file .icon { color: var(--ink-soft); }
.item-name {
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-word;
  line-height: 1.3;
  margin-bottom: 4px;
}
.item-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}
.lock-badge {
  position: absolute;
  top: 8px; right: 8px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--brass);
  border: 2px solid var(--brass-soft);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 5px rgba(138,95,32,0.4);
}
.lock-badge svg { width: 12px; height: 12px; color: #fff; }
.item-card .row-actions {
  position: absolute;
  bottom: 8px; right: 8px;
  display: none;
  gap: 4px;
}
.item-card:hover .row-actions { display: flex; }
.icon-btn {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--ink-soft);
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.icon-btn svg { width: 12px; height: 12px; }

.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--ink-faint);
}
.empty-state .stamp {
  font-family: 'Fraunces', serif;
  font-size: 1.3rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.empty-state p { font-size: 0.85rem; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(18, 30, 26, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--paper);
  border-radius: 14px;
  padding: 28px 26px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(18,30,26,0.35);
  border: 1px solid var(--line);
  position: relative;
}
.modal .seal {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--brass);
  border: 3px solid var(--brass-soft);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.modal .seal svg { width: 22px; height: 22px; color: #fff; }
.modal h3 {
  font-family: 'Fraunces', serif;
  text-align: center;
  margin: 0 0 4px;
  font-size: 1.2rem;
}
.modal .sub {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 18px;
  word-break: break-all;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 600;
}
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--ink);
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--vault);
  outline-offset: 1px;
  border-color: var(--vault);
}
.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin: -6px 0 12px;
  min-height: 1em;
}
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; justify-content: center; }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--vault-deep);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}
.toast.err { background: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

/* ---------- Progress ---------- */
.upload-bar {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  min-width: 200px;
  z-index: 90;
}
.upload-bar .track {
  height: 5px; border-radius: 3px; background: var(--paper-alt);
  margin-top: 8px; overflow: hidden;
}
.upload-bar .fill { height: 100%; background: var(--vault); width: 0%; transition: width 0.15s; }

/* ---------- Dropzone ---------- */
.dropzone-active::after {
  content: '松开以上传到此目录';
  position: fixed; inset: 0;
  background: rgba(31,75,63,0.9);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif;
  font-size: 1.4rem;
  z-index: 150;
}

/* ---------- Loading ---------- */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--vault);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Admin specific ---------- */
.admin-shell { max-width: 760px; margin: 0 auto; padding: 20px; }
.login-card {
  max-width: 360px; margin: 12vh auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px 26px;
  box-shadow: var(--shadow);
}
.tree {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}
.tree-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
}
.tree-row:hover { background: var(--paper-alt); }
.tree-row .indent { flex-shrink: 0; }
.tree-row .fname {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}
.tree-row .fname span.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.policy-pill {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.66rem;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.policy-pill.password { background: var(--brass-soft); color: var(--brass-deep); }
.policy-pill.none { background: var(--vault-tint); color: var(--vault-deep); }
.policy-pill.inherit { background: var(--paper-alt); color: var(--ink-faint); }
.tree-row .set-btn {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--vault);
  background: none; border: none; cursor: pointer;
  padding: 4px 6px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stat-row { display: flex; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 120px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.stat-card .num { font-family: 'Fraunces', serif; font-size: 1.6rem; color: var(--vault); }
.stat-card .lbl { font-size: 0.72rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.section-title {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  margin: 28px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.section-title .tab {
  width: 5px; height: 16px; background: var(--brass); border-radius: 3px;
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  :root { font-size: 15px; }
  .topbar-inner { padding: 14px 14px 12px; }
  .brand { font-size: 1.25rem; }
  main, .toolbar, .admin-shell { padding-left: 14px; padding-right: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .item-card { padding: 13px 11px 11px; }
  .toolbar .btn span.label { display: none; }
  .toolbar .btn { padding: 10px; }
  .admin-link span.label { display: none; }
  .upload-bar { left: 14px; right: 14px; bottom: 14px; min-width: 0; }
  .crumb { max-width: 32vw; }
  .stat-row { gap: 8px; }
}


/* ---------- Media thumbs & file detail panel ---------- */
.item-card.is-image .thumb,
.item-card.is-video .thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper-alt, #f0ebe0);
  margin-bottom: 8px;
}
.item-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.item-card.is-image .icon,
.item-card.is-video .icon { color: var(--vault); }

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(12, 20, 17, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  backdrop-filter: blur(3px);
}
.detail-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: var(--paper, #f7f2e8);
  border: 1px solid var(--line, #d9d0bd);
  border-radius: 16px;
  box-shadow: 0 22px 70px rgba(12, 20, 17, 0.35);
}
.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line, #d9d0bd);
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--ink-soft, #5a655f);
}
.detail-close:hover { color: var(--danger, #b33); }

.detail-preview {
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  max-height: 42vh;
  overflow: hidden;
}
.detail-preview img,
.detail-preview video {
  display: block;
  max-width: 100%;
  max-height: 42vh;
  object-fit: contain;
  background: #000;
}
.detail-preview video {
  width: 100%;
}
.detail-preview-fallback {
  color: rgba(255,255,255,0.75);
  padding: 36px 16px;
  text-align: center;
  font-size: 0.9rem;
}

.detail-body {
  padding: 20px 22px 22px;
}
.detail-name {
  margin: 0 0 14px;
  font-family: 'Fraunces', serif;
  font-size: 1.25rem;
  line-height: 1.3;
  word-break: break-word;
  padding-right: 28px;
}
.detail-meta {
  margin: 0 0 18px;
  display: grid;
  gap: 10px;
}
.detail-meta > div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 0.88rem;
}
.detail-meta dt {
  margin: 0;
  color: var(--ink-faint, #8a9088);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  padding-top: 2px;
}
.detail-meta dd {
  margin: 0;
  color: var(--ink, #1c2420);
  word-break: break-word;
}
.detail-meta dd.mono {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--ink-soft, #5a655f);
}
.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.detail-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.detail-actions .btn svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 640px) {
  .detail-panel { width: 100%; border-radius: 14px; }
  .detail-body { padding: 16px; }
  .detail-name { font-size: 1.1rem; }
}
