* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --card: #ffffff;
  --text: #1f2328;
  --text-2: #59606a;
  --text-3: #8b919c;
  --border: #e5e7eb;
  --border-strong: #d0d5dd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --shadow: rgba(22, 24, 29, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --card: #191c22;
  --text: #f0f2f5;
  --text-2: #b1b6bf;
  --text-3: #7f8792;
  --border: #2a2f38;
  --border-strong: #3b424d;
  --accent: #6695ff;
  --accent-hover: #82a8ff;
  --accent-soft: #1c2942;
  --danger: #ff7b72;
  --shadow: rgba(0, 0, 0, 0.35);
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  color: inherit;
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

.progress {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--accent);
  transition: width 100ms linear;
}

.top {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  transition: box-shadow 160ms ease;
}

.top.scrolled {
  box-shadow: 0 4px 12px -4px var(--shadow);
}

.top-inner,
.crumbs,
.main {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 20px;
}

.top-inner {
  display: flex;
  min-height: 57px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-block: 10px;
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  border-radius: 7px;
}

.mark {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
}

.mark svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand .name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.top-tools {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.search {
  position: relative;
  display: block;
}

.search svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--text-3);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search input {
  width: 280px;
  height: 36px;
  border: 1px solid var(--border-strong);
  outline: none;
  padding: 8px 12px 8px 34px;
  border-radius: 6px;
  color: var(--text);
  background: var(--card);
  font-size: 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search input::placeholder {
  color: var(--text-3);
}

.tool-button {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text-2);
  background: var(--card);
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.tool-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.tool-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.moon-icon,
:root[data-theme="dark"] .sun-icon {
  display: none;
}

:root[data-theme="dark"] .moon-icon {
  display: block;
}

.brand:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 26%, transparent);
  outline-offset: 2px;
}

.crumbs {
  display: flex;
  min-height: 24px;
  align-items: center;
  gap: 0;
  margin-top: 18px;
  overflow-x: auto;
  color: var(--text-3);
  font-size: 13px;
  scrollbar-width: none;
}

.crumbs::-webkit-scrollbar {
  display: none;
}

.crumb {
  display: inline-block;
  max-width: 240px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 0;
  padding: 0;
  color: var(--text-3);
  background: transparent;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.crumb:hover {
  color: var(--accent);
}

.crumb.current {
  color: var(--text-2);
}

.crumb-separator {
  flex: 0 0 auto;
  margin: 0 7px;
  color: var(--border-strong);
}

.main {
  padding-top: 14px;
  padding-bottom: 52px;
}

.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.head-row h1 {
  overflow: hidden;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.head-right {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.count {
  margin-right: 4px;
  color: var(--text-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.view-toggle {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--card);
}

.view-button {
  display: grid;
  width: 32px;
  height: 30px;
  place-items: center;
  border: 0;
  color: var(--text-3);
  background: var(--card);
  transition: color 120ms ease, background 120ms ease;
}

.view-button + .view-button {
  border-left: 1px solid var(--border-strong);
}

.view-button:hover {
  color: var(--text-2);
}

.view-button.active {
  color: #fff;
  background: var(--accent);
}

.view-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.refresh-button {
  width: 32px;
  height: 32px;
  flex-basis: 32px;
}

.refresh-button.loading svg {
  animation: spin 700ms linear infinite;
}

.files.list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.files.list .list-head,
.files.list .item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 88px 108px;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
}

.files.list .list-head {
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  background: var(--bg);
  font-size: 12px;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  border: 0;
  padding: 0;
  color: inherit;
  background: none;
  font-size: inherit;
}

.sort-button.right {
  justify-content: flex-end;
}

.sort-button:hover {
  color: var(--text-2);
}

.sort-button.active {
  color: var(--accent);
  font-weight: 600;
}

.sort-arrow {
  font-size: 9px;
  line-height: 1;
}

.sort-button[data-dir="asc"] .sort-arrow::after {
  content: "▲";
}

.sort-button[data-dir="desc"] .sort-arrow::after {
  content: "▼";
}

.item {
  width: 100%;
  border: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.files.list .item + .item {
  border-top: 1px solid var(--border);
}

.files.list .item {
  transition: background 120ms ease;
}

.files.list .item:hover {
  background: var(--accent-soft);
}

.item .item-icon {
  display: grid;
  place-items: center;
}

.files.list .item-icon svg {
  width: 24px;
  height: 24px;
}

.item-icon svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.item .item-name {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item:hover .item-name {
  color: var(--accent);
}

.files.list .item-meta {
  display: contents;
}

.files.list .item-size,
.files.list .item-date {
  color: var(--text-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.files.list .item-size:not(.muted) {
  color: var(--text-2);
}

.files.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.files.grid .list-head {
  display: none;
}

.files.grid #file-list {
  display: contents;
}

.files.grid .item {
  display: flex;
  min-width: 0;
  min-height: 142px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  padding: 20px 16px;
  border-radius: 8px;
  background: var(--card);
  text-align: center;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.files.grid .item:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 26%, transparent);
}

.files.grid .item-icon {
  height: 40px;
}

.files.grid .item-icon svg {
  width: 38px;
  height: 38px;
}

.files.grid .item-name {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  line-height: 1.4;
  white-space: normal;
  word-break: break-all;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.files.grid .item-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 12px;
}

.files.grid .item-size::after {
  content: "·";
  margin: 0 6px;
}

.state-card {
  padding: 80px 20px;
  color: var(--text-3);
  text-align: center;
}

.state-card > svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  color: var(--border-strong);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.state-card p {
  color: var(--text-2);
  font-size: 15px;
  font-weight: 600;
}

.state-card span {
  font-size: 13px;
}

.spinner {
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.error-state > svg {
  color: var(--danger);
}

.retry-button {
  margin-top: 16px;
  border: 1px solid var(--accent);
  padding: 7px 14px;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.retry-button:hover {
  background: var(--accent-hover);
}

.to-top {
  position: fixed;
  z-index: 30;
  right: 24px;
  bottom: 24px;
  display: grid;
  width: 40px;
  height: 40px;
  transform: translateY(8px);
  place-items: center;
  visibility: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text-2);
  background: var(--card);
  box-shadow: 0 4px 14px var(--shadow);
  opacity: 0;
  transition: opacity 200ms ease, visibility 200ms ease, transform 200ms ease, color 150ms ease, border-color 150ms ease;
}

.to-top:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.to-top.show {
  transform: translateY(0);
  visibility: visible;
  opacity: 1;
}

.to-top svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (min-width: 1600px) {
  .top-inner,
  .crumbs,
  .main {
    max-width: 1360px;
  }
}

@media (max-width: 860px) {
  .search input {
    width: 220px;
  }

  .files.list .list-head,
  .files.list .item {
    grid-template-columns: 36px minmax(0, 1fr) 84px;
  }

  .files.list .date-column,
  .files.list .item-date {
    display: none;
  }
}

@media (max-width: 680px) {
  .top-inner {
    flex-wrap: wrap;
  }

  .top-tools {
    width: 100%;
  }

  .search {
    flex: 1;
  }

  .search input {
    width: 100%;
  }

  .head-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .head-right {
    width: 100%;
  }

  .count {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .top-inner,
  .crumbs,
  .main {
    padding-inline: 12px;
  }

  .crumbs {
    margin-top: 14px;
  }

  .files.list .list-head,
  .files.list .item {
    grid-template-columns: 32px minmax(0, 1fr) 76px;
    gap: 8px;
    padding: 9px 12px;
  }

  .files.grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  .files.grid .item {
    min-height: 130px;
    padding: 16px 12px;
  }

  .to-top {
    right: 14px;
    bottom: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
