/* Tailwind CSS CDN */
@import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css');

/* ================= 设计变量 ================= */
:root {
  --primary: #2563EB;
  --primary-2: #3B82F6;
  --primary-3: #60A5FA;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --text: #1F2937;
  --text-2: #6B7280;
  --border: #E5E9F0;
  --green: #10B981;
  --red: #EF4444;
  --amber: #F59E0B;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 32px rgba(37, 99, 235, .16);
  --font: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1420;
    --card: #171E2E;
    --text: #E5E9F0;
    --text-2: #8B93A7;
    --border: #232B3E;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; }
::selection { background: rgba(59, 130, 246, .2); }

/* ================= 通用控件 ================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37, 99, 235, .45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; justify-content: center; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s ease;
  flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: rgba(59, 130, 246, .1); color: var(--primary); }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.icon-btn.danger:hover { background: rgba(239, 68, 68, .1); color: var(--red); }

/* ================= 登录视图 ================= */
.login-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #EFF6FF 0%, #E0ECFF 45%, #DBEAFE 100%);
  overflow: hidden;
}
@media (prefers-color-scheme: dark) {
  .login-view { background: linear-gradient(160deg, #0B1226 0%, #101B36 50%, #0D1730 100%); }
}
.login-decor {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .55;
  animation: float 9s ease-in-out infinite;
}
.login-decor-1 { width: 420px; height: 420px; background: #93C5FD; top: -120px; left: -100px; }
.login-decor-2 { width: 360px; height: 360px; background: #BFDBFE; bottom: -120px; right: -80px; animation-delay: -4.5s; }
@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(30px) scale(1.06); }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  padding: 44px 36px 32px;
  text-align: center;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(37, 99, 235, .18);
  animation: cardIn .5s cubic-bezier(.2, .9, .3, 1.2);
}
@media (prefers-color-scheme: dark) {
  .login-card { background: rgba(23, 30, 46, .8); border-color: rgba(255, 255, 255, .08); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(.96); }
  to { opacity: 1; transform: none; }
}
.login-logo {
  width: 68px; height: 68px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-3));
  color: #fff;
  box-shadow: 0 10px 26px rgba(37, 99, 235, .4);
}
.login-logo svg { width: 36px; height: 36px; }
.login-title { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: .5px; }
.login-sub { margin: 8px 0 28px; color: var(--text-2); font-size: 13px; }

.login-field {
  position: relative;
  margin-bottom: 16px;
}
.field-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--text-2);
}
.login-field input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all .18s ease;
}
.login-field input:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, .15);
}
.login-error { min-height: 20px; margin: 12px 0 0; color: var(--red); font-size: 13px; }
.login-hint { margin: 18px 0 0; color: var(--text-2); font-size: 12px; opacity: .8; }

/* ================= 应用布局 ================= */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 62px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex: none;
  z-index: 20;
}
.menu-btn { display: none; }
.brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 17px; font-weight: 600; color: var(--primary);
  user-select: none;
}
.brand svg { width: 26px; height: 26px; }

.search-box {
  position: relative;
  flex: 1;
  max-width: 420px;
  margin-left: 8px;
}
.search-box svg {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--text-2);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid transparent;
  border-radius: 999px;
  outline: none;
  transition: all .18s ease;
}
.search-box input:focus {
  background: var(--card);
  border-color: var(--primary-2);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, .12);
}

.usage {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  user-select: none;
}
.usage-bar {
  width: 120px;
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary-2), var(--primary-3));
  transition: width .6s cubic-bezier(.2, .8, .3, 1);
}
.usage-fill.warn { background: linear-gradient(90deg, var(--amber), #FBBF24); }
.usage-fill.full { background: linear-gradient(90deg, var(--red), #F87171); }
.usage-text { font-size: 12px; color: var(--text-2); white-space: nowrap; }

.layout { display: flex; flex: 1; min-height: 0; }

/* ================= 侧边栏 ================= */
.sidebar {
  width: 224px;
  flex: none;
  padding: 18px 12px;
  background: var(--card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 1px;
}
.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  transition: all .15s ease;
  border: none;
  background: none;
  font-size: 14px;
  text-align: left;
  width: 100%;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
}
.cat-item:focus-visible { outline: 2px solid var(--primary-2); outline-offset: -2px; }
.cat-item svg { width: 17px; height: 17px; color: var(--text-2); flex: none; transition: color .15s; }
.cat-item:hover { background: rgba(59, 130, 246, .08); }
.cat-item:hover svg { color: var(--primary); }
.cat-item.active {
  background: linear-gradient(135deg, rgba(37, 99, 235, .12), rgba(96, 165, 250, .1));
  color: var(--primary);
  font-weight: 500;
}
.cat-item.active svg { color: var(--primary); }
.cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count {
  font-size: 12px;
  color: var(--text-2);
  background: var(--bg);
  padding: 1px 8px;
  border-radius: 99px;
  flex: none;
}
.cat-item.active .cat-count { background: rgba(37, 99, 235, .15); color: var(--primary); }
.cat-ops {
  display: none;
  align-items: center;
  gap: 2px;
  flex: none;
}
.cat-item:hover .cat-ops,
.cat-item:focus-within .cat-ops { display: inline-flex; }
.cat-item:hover .cat-count,
.cat-item:focus-within .cat-count { display: none; }
.cat-ops .icon-btn { width: 24px; height: 24px; border-radius: 7px; }
.cat-ops .icon-btn svg { width: 14px; height: 14px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 62px 0 0 0;
  background: rgba(15, 23, 42, .45);
  z-index: 29;
}

/* ================= 内容区 ================= */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 20px 24px 28px;
  overflow-y: auto;
}
.content-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.breadcrumb { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.breadcrumb .crumb-sep { color: var(--text-2); font-weight: 400; font-size: 13px; }
.breadcrumb .crumb-cur { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumb .crumb-link { color: var(--text-2); cursor: pointer; font-weight: 400; transition: color .15s; }
.breadcrumb .crumb-link:hover { color: var(--primary); }
.head-actions { display: flex; align-items: center; gap: 12px; }

.view-toggle {
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--border);
  border-radius: var(--radius-sm);
}
.vt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 30px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s ease;
}
.vt-btn svg { width: 17px; height: 17px; }
.vt-btn.active { background: var(--card); color: var(--primary); box-shadow: 0 1px 4px rgba(16, 24, 40, .12); }

/* ---- 文件列表 ---- */
.file-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.file-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.file-table th.sortable { cursor: pointer; transition: color .15s; }
.file-table th.sortable:hover { color: var(--primary); }
.file-table th .sort-arrow { font-size: 10px; margin-left: 3px; }
.file-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.file-table tbody tr { transition: background .15s ease; }
.file-table tbody tr:hover { background: rgba(59, 130, 246, .045); }
.file-table tbody tr:last-child td { border-bottom: none; }

.file-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.file-icon {
  width: 40px; height: 40px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  font-size: 10.5px;
  font-weight: 600;
  color: #fff;
}
.file-icon svg { width: 20px; height: 20px; }
.file-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 480px;
}
.file-meta-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.cell-dim { color: var(--text-2); font-size: 13px; white-space: nowrap; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---- 网格视图 ---- */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.grid-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 14px 14px;
  text-align: center;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}
.grid-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.grid-card .file-icon { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 14px; }
.grid-card .file-icon svg { width: 26px; height: 26px; }
.grid-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grid-sub { font-size: 11.5px; color: var(--text-2); margin-top: 4px; }
.grid-actions {
  position: absolute;
  top: 8px; right: 8px;
  display: none;
  gap: 2px;
  padding: 3px;
  background: var(--card);
  border-radius: 9px;
  box-shadow: var(--shadow);
}
.grid-card:hover .grid-actions { display: inline-flex; }

/* ---- 空状态 ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 70px 20px;
  color: var(--text-2);
}
.empty-state svg { width: 90px; height: 90px; color: var(--primary-3); opacity: .5; margin-bottom: 18px; }
.empty-state p { margin: 4px 0; font-size: 14px; }
.empty-state .empty-hint { font-size: 12.5px; opacity: .75; }

/* ================= 拖拽热区 ================= */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, .12);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
}
.drop-inner {
  padding: 44px 64px;
  text-align: center;
  color: var(--primary);
  background: var(--card);
  border: 2px dashed var(--primary-2);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  animation: cardIn .25s ease;
}
.drop-inner svg { width: 56px; height: 56px; }
.drop-inner p { margin: 12px 0 0; font-size: 16px; font-weight: 600; }

/* ================= 上传面板 ================= */
.upload-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  width: 340px;
  max-width: calc(100vw - 32px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(16, 24, 40, .18);
  overflow: hidden;
  animation: cardIn .3s ease;
}
.up-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 10px 16px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.up-head > div { display: flex; gap: 2px; }
.up-list { max-height: 260px; overflow-y: auto; padding: 6px 10px 10px; }
.upload-panel.collapsed .up-list { display: none; }

.up-item { padding: 8px 6px; }
.up-info { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.up-name {
  flex: 1;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.up-status { font-size: 11.5px; color: var(--text-2); flex: none; }
.up-status.ok { color: var(--green); }
.up-status.err { color: var(--red); }
.up-bar {
  height: 5px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
.up-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary-2), var(--primary-3));
  transition: width .25s ease;
}
.up-fill.err { background: var(--red); }
.up-fill.ok { background: var(--green); }

/* ================= Toast ================= */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 20px;
  font-size: 13.5px;
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .25);
  animation: toastIn .3s cubic-bezier(.2, .9, .3, 1.2);
  max-width: 90vw;
}
.toast.ok { background: linear-gradient(135deg, #059669, var(--green)); }
.toast.err { background: linear-gradient(135deg, #DC2626, var(--red)); }
.toast.info { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.toast.out { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px) scale(.95); } }

/* ================= 弹窗 ================= */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .3);
  padding: 24px;
  animation: cardIn .25s cubic-bezier(.2, .9, .3, 1.15);
}
.modal h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.modal .modal-desc { margin: 0 0 16px; color: var(--text-2); font-size: 13px; line-height: 1.6; }
.modal input[type=text], .modal select {
  width: 100%;
  padding: 10px 13px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all .15s ease;
}
.modal input[type=text]:focus, .modal select:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, .13);
  background: var(--card);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.btn-ghost {
  background: transparent;
  color: var(--text-2);
  padding: 9px 16px;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger {
  background: linear-gradient(135deg, #DC2626, var(--red));
  color: #fff;
  box-shadow: 0 4px 14px rgba(239, 68, 68, .35);
}
.btn-danger:hover { transform: translateY(-1px); }

/* ================= 灯箱 ================= */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 24, .88);
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.lb-body { max-width: 88vw; max-height: 86vh; text-align: center; }
.lb-body img {
  max-width: 88vw;
  max-height: 78vh;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  animation: cardIn .25s ease;
}
.lb-name { color: rgba(255, 255, 255, .85); font-size: 13px; margin: 14px 0 0; }
.lb-btn {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  transition: all .15s ease;
}
.lb-btn svg { width: 24px; height: 24px; }
.lb-btn:hover { background: rgba(255, 255, 255, .25); }
.lb-close { top: 20px; right: 20px; }
.lb-prev { left: 20px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 20px; top: 50%; transform: translateY(-50%); }

/* ================= 响应式 ================= */
@media (max-width: 900px) {
  .usage-text { display: none; }
  .usage-bar { width: 70px; }
}
@media (max-width: 768px) {
  .topbar { padding: 0 12px; gap: 8px; height: 56px; }
  .menu-btn { display: inline-flex; }
  .brand span { display: none; }
  .search-box { max-width: none; }
  .content { padding: 14px 14px 24px; }
  .content-head { margin-bottom: 12px; }

  .sidebar {
    position: fixed;
    top: 56px; bottom: 0; left: 0;
    z-index: 30;
    width: 250px;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.2, .8, .3, 1);
    box-shadow: none;
  }
  .sidebar.open { transform: none; box-shadow: 20px 0 50px rgba(16, 24, 40, .18); }
  .sidebar-backdrop.show { display: block; }

  .file-table .hide-sm { display: none; }
  .file-name { max-width: 46vw; }

  .upload-panel { right: 12px; bottom: 12px; }
  .lb-prev { left: 8px; } .lb-next { right: 8px; }
  .lb-btn { width: 40px; height: 40px; }
}
@media (max-width: 480px) {
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  #uploadBtn span { display: none; }
  #uploadBtn { padding: 9px 12px; }
}
