:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #17202b;
  --muted: #5b6878;
  --border: #e1e6ed;
  --accent: #2f5d8f;
  --accent-text: #ffffff;
  --accent-soft: #e4edf7;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 5%), 0 8px 24px rgb(16 24 40 / 6%);
  --image: #c2410c;
  --video: #7c3aed;
  --audio: #0f766e;
  --document: #2563eb;
  --archive: #a16207;
  --code: #475569;
  --subtitle: #be185d;
  --other: #64748b;
  --folder: var(--accent);
  color-scheme: light;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #161d26;
    --surface-2: #1c2530;
    --text: #e8edf3;
    --muted: #97a3b2;
    --border: #273241;
    --accent: #8fb6e8;
    --accent-text: #0d1622;
    --accent-soft: #1f3046;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    --image: #fb923c;
    --video: #a78bfa;
    --audio: #2dd4bf;
    --document: #60a5fa;
    --archive: #facc15;
    --code: #94a3b8;
    --subtitle: #f472b6;
    --other: #94a3b8;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flow-root;
}

a {
  color: var(--accent);
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header ------------------------------------------------------------------ */

.header {
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, #000) 100%);
  color: var(--accent-text);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 10px;
  background: rgb(255 255 255 / 18%) url("/favicon.svg") center / 26px no-repeat;
}

.title {
  min-width: 0;
}

.eyebrow {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.8;
}

.title h1 {
  margin: 2px 0 0;
  font-size: clamp(22px, 4vw, 30px);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* Main card --------------------------------------------------------------- */

.content {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: -32px auto 0;
  padding: 0 24px 32px;
}

.browser,
.notice,
.loading {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.loading,
.notice {
  padding: 40px 24px;
  text-align: center;
}

.notice h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.notice p,
.loading {
  margin: 0;
  color: var(--muted);
}

.crumbs {
  padding: 16px 20px 0;
}

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.crumbs li + li::before {
  content: "/";
  margin: 0 8px;
  color: var(--muted);
}

.crumbs a {
  text-decoration: none;
  overflow-wrap: anywhere;
}

.crumbs a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

/* Toolbar ----------------------------------------------------------------- */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.search {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
}

.search input[type="search"] {
  flex: 1 1 280px;
  min-width: 0;
  min-height: 42px;
  padding: 8px 14px 8px 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2) url("/assets/search.svg") 12px center / 18px no-repeat;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
}

.chip:hover {
  background: var(--surface-2);
}

.chip.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.chip .count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--other));
}

.sort-control {
  display: none;
  align-items: center;
  gap: 8px;
}

.sort-control label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.sort-control select {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.truncated {
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 13px;
}

.summary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* Table ------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
}

.files {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.files thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

th[aria-sort="ascending"] .sort,
th[aria-sort="descending"] .sort {
  color: var(--text);
}

.arrow {
  font-size: 12px;
}

.files td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.files tbody tr:last-child td {
  border-bottom: 0;
}

.files tbody tr:hover {
  background: var(--surface-2);
}

.col-name {
  width: 100%;
}

.name-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.name-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.name {
  overflow-wrap: anywhere;
  font-weight: 500;
}

a.name {
  color: var(--text);
  text-decoration: none;
}

a.name:hover {
  color: var(--accent);
  text-decoration: underline;
}

.where {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}

.col-type,
.col-size,
.col-modified {
  color: var(--muted);
  white-space: nowrap;
}

.col-size {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th.col-size .sort {
  justify-content: flex-end;
}

.col-action {
  text-align: right;
  white-space: nowrap;
}

.download,
.open {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.download {
  background: var(--accent);
  color: var(--accent-text);
}

.download:hover {
  filter: brightness(1.08);
}

.open {
  border: 1px solid var(--border);
  color: var(--text);
}

.download-icon {
  width: 14px;
  height: 14px;
  background: currentColor;
  mask: url("/assets/download.svg") center / contain no-repeat;
}

.empty {
  margin: 0;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* File type icons: pure CSS, colored by category ------------------------- */

.icon {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--c, var(--other)) 14%, transparent);
}

.icon::after {
  content: "";
  position: absolute;
  inset: 9px 10px;
  border: 2px solid var(--c, var(--other));
  border-radius: 2px 5px 2px 2px;
}

.icon.folder::after {
  inset: 11px 8px 10px;
  border-radius: 2px 3px 3px 3px;
  background: var(--c);
}

.icon.folder,
.dot.folder {
  --c: var(--folder);
}
.icon.image,
.dot.image {
  --c: var(--image);
}
.icon.video,
.dot.video {
  --c: var(--video);
}
.icon.audio,
.dot.audio {
  --c: var(--audio);
}
.icon.document,
.dot.document {
  --c: var(--document);
}
.icon.archive,
.dot.archive {
  --c: var(--archive);
}
.icon.code,
.dot.code {
  --c: var(--code);
}
.icon.subtitle,
.dot.subtitle {
  --c: var(--subtitle);
}
.icon.other,
.dot.other {
  --c: var(--other);
}

.footer {
  padding: 8px 24px 28px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* Phones: rows become cards ---------------------------------------------- */

@media (max-width: 720px) {
  .header-inner {
    padding: 20px 16px 48px;
  }
  .content {
    padding: 0 12px 24px;
  }
  .crumbs,
  .toolbar {
    padding-left: 16px;
    padding-right: 16px;
  }
  .search input[type="search"] {
    font-size: 16px; /* keeps iOS from zooming */
  }
  .files thead {
    display: none;
  }
  .sort-control {
    display: flex;
  }
  .files,
  .files tbody,
  .files tr,
  .files td {
    display: block;
  }
  .files tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "name name action"
      "size modified action";
    align-items: center;
    gap: 2px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
  }
  .files td {
    padding: 0;
    border: 0;
  }
  .files .col-name {
    grid-area: name;
  }
  .files .col-type {
    display: none;
  }
  .files .col-size,
  .files .col-modified {
    font-size: 12px;
    text-align: left;
  }
  .files .col-size {
    grid-area: size;
    padding-left: 46px;
  }
  .files .col-modified {
    grid-area: modified;
    padding-left: 12px;
  }
  .files .col-action {
    grid-area: action;
  }
  .download-label {
    display: none;
  }
  .download {
    min-width: 44px;
    justify-content: center;
  }
}

/* Touch: 44px targets and 16px controls (no iOS zoom) --------------------- */

@media (max-width: 900px), (pointer: coarse) {
  .chip {
    min-height: 44px;
    padding: 6px 14px;
  }
  .switch {
    min-height: 44px;
    font-size: 16px;
  }
  .switch input {
    width: 24px;
    height: 24px;
  }
  .download,
  .open {
    min-height: 44px;
  }
  a.name {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  .where {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
  }
}
