/* =========================
   Box-sizing reset
   ========================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

/* =========================
   Theme tokens (Light — default)
   ========================= */
:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --fg: #1e2430;
  --muted: #5e6877;
  --row-hover: #eef1f8;
  --rule: #d7dde6;
  --accent: #2d6cdf;
  --accent-contrast: #ffffff;
  --focus: 0 0 0 3px rgba(45, 108, 223, 0.25);
  --link: var(--accent);
  --clear-link: var(--muted);
  --input-border: var(--rule);
  --focus-border: var(--accent);
  --table-shadow: 0 18px 38px rgba(15, 30, 55, 0.08);
  --td-border: rgba(0, 0, 0, 0.05);
  --parent-hover: #1b1f2a;
  --toggle-bg: #e8ecf6;
  --toggle-fg: #1e2430;
  --toggle-border: rgba(30, 36, 48, 0.1);
  --toggle-hover-bg: #dbe3f5;
}

/* =========================
   Theme tokens (Dark)
   ========================= */
body.theme-dark {
  --bg: #2f343f;
  --bg-elev: #262a32;
  --fg: #ffffff;
  --muted: #9099a3;
  --row-hover: #3d4351;
  --rule: #3c404a;
  --accent: #cfd6df;
  --accent-contrast: #1e2430;
  --focus: 0 0 0 3px rgba(255, 255, 255, 0.25);
  --link: #ffffff;
  --clear-link: #cbd3dc;
  --input-border: #3c404a;
  --focus-border: #cfd6df;
  --table-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  --td-border: rgba(255, 255, 255, 0.07);
  --parent-hover: #2a2a2a;
  --toggle-bg: #1f222b;
  --toggle-fg: #ffffff;
  --toggle-border: rgba(255, 255, 255, 0.12);
  --toggle-hover-bg: #2a2f3a;
}

/* =========================
   Global typography
   https://css-tricks.com/snippets/css/system-font-stack/
   ========================= */
html {
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Ubuntu,
    Cantarell,
    "Noto Sans",
    sans-serif,
    "Apple Color Emoji",
    "Segoe UI Emoji";
  color: var(--muted);
  font-weight: 300;
  font-size: clamp(14px, 1.2vw, 16px);
  line-height: 1.6;
  text-size-adjust: 100%;
  background-color: var(--bg);
}

body {
  margin: 0;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: clamp(12px, 2.5vw, 24px);
  color: var(--fg);
  background-color: var(--bg);
  transition:
    background-color 150ms ease-in,
    color 150ms ease-in;
}

/* =========================
   Headings and table headers
   ========================= */
h1 {
  font-weight: 300;
  text-align: center;
  font-size: clamp(1.5rem, 2vw + 1rem, 2.4rem);
  line-height: 1.4;
  margin-bottom: 1.25rem;
}

thead {
  font-weight: 200;
  font-size: 1.2em;
}

/* =========================
   Directory controls: search + theme toggle
   ========================= */
.directory-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  scroll-behavior: smooth;
}

@media (min-width: 720px) {
  .directory-controls {
    flex-direction: row;
    justify-content: center;
  }
}

/* =========================
   Links
   ========================= */
a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Subtle action links (e.g. reset search) */
a.clear,
a.clear:link,
a.clear:visited {
  color: var(--clear-link);
  padding: 2px 0;
  font-weight: 400;
  font-size: 1rem;
  margin-left: 1rem;
  line-height: 1;
  display: inline-block;
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease-in;
}

a.clear:hover {
  border-bottom-color: currentColor;
}

/* =========================
   Theme toggle button
   ========================= */
.theme-toggle {
  appearance: none;
  border-radius: 999px;
  border: 1px solid var(--toggle-border);
  background: var(--toggle-bg);
  color: var(--toggle-fg);
  padding: 0.35rem 1.2rem;
  font:
    500 0.9rem/1.2 "Roboto",
    system-ui,
    sans-serif;
  cursor: pointer;
  transition:
    background-color 150ms ease-in,
    transform 150ms ease-in;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.theme-toggle:hover {
  background: var(--toggle-hover-bg);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.theme-toggle[aria-pressed="true"] {
  font-weight: 600;
}

/* =========================
   Search input
   ========================= */
input {
  display: block;
  margin: 0 auto;
  width: clamp(16rem, 60vw, 32rem);
  height: 2.25rem;
  padding: 0 0.75rem;
  color: var(--fg);
  background-color: var(--bg-elev);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font:
    300 0.95rem/1.2 "Roboto",
    system-ui,
    sans-serif;
  transition:
    border-color 150ms ease-in,
    box-shadow 150ms ease-in;
}

input:focus-visible {
  outline: 0;
  border-color: var(--focus-border);
  box-shadow: var(--focus);
}

#search {
  color: var(--fg);
  background-color: var(--bg-elev);
  display: block;
  margin-inline: auto;
  width: min(100%, 320px);
  margin-top: 0;
  appearance: textfield;
}

.results-status {
  min-height: 1.5em;
  margin: -0.75rem 0 0.75rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

/* =========================
   Table
   ========================= */
table {
  border-collapse: collapse;
  font-size: 0.95em;
  width: 100%;
  margin: 24px 0 0;
  background: var(--bg-elev);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--table-shadow);
}

tr {
  outline: 0;
  border: 0;
}

tr:hover td {
  color: var(--fg);
  background: var(--row-hover);
}

tr td:first-of-type {
  padding-left: 10px;
  padding-right: 10px;
}

tr.parent a {
  color: var(--muted);
}

th {
  text-align: left;
  font-size: 0.75em;
  padding: 12px 20px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7a8597;
  background: #e3e8f1;
}

body.theme-dark th {
  color: #8a94a6;
  background: #1f222b;
}

th + th {
  width: 25%;
}

th + th + th + th {
  width: 5%;
}

td {
  padding: 14px 20px;
  outline: 0;
  border: 0;
  border-bottom: 1px solid var(--td-border);
  vertical-align: middle;
  text-align: left;
  transition: background 300ms ease-in;
}

td:last-child,
th:last-child {
  text-align: right;
  padding-right: 10px;
}

td a {
  display: block;
}

/* =========================
   File-type emoji icons via ::before
   https://stackoverflow.com/a/60198998
   ========================= */

/* Default: generic file */
#list tbody tr td:first-child a::before {
  content: "📄";
  margin-right: 0.5rem;
  display: inline-block;
  font-style: normal;
}

/* Directory */
#list tbody tr td:first-child a[href$="/"]::before {
  content: "📁";
}

/* Parent directory */
#list tbody tr.parent td:first-child a::before {
  content: "⬆️";
}

/* Images */
#list tbody tr td:first-child a[href$=".jpg"]::before,
#list tbody tr td:first-child a[href$=".jpeg"]::before,
#list tbody tr td:first-child a[href$=".png"]::before,
#list tbody tr td:first-child a[href$=".gif"]::before,
#list tbody tr td:first-child a[href$=".svg"]::before,
#list tbody tr td:first-child a[href$=".webp"]::before,
#list tbody tr td:first-child a[href$=".ico"]::before,
#list tbody tr td:first-child a[href$=".bmp"]::before {
  content: "🖼️";
}

/* Video */
#list tbody tr td:first-child a[href$=".mp4"]::before,
#list tbody tr td:first-child a[href$=".avi"]::before,
#list tbody tr td:first-child a[href$=".mov"]::before,
#list tbody tr td:first-child a[href$=".wmv"]::before,
#list tbody tr td:first-child a[href$=".flv"]::before,
#list tbody tr td:first-child a[href$=".webm"]::before,
#list tbody tr td:first-child a[href$=".mkv"]::before {
  content: "🎬";
}

/* Audio */
#list tbody tr td:first-child a[href$=".mp3"]::before,
#list tbody tr td:first-child a[href$=".wav"]::before,
#list tbody tr td:first-child a[href$=".flac"]::before,
#list tbody tr td:first-child a[href$=".aac"]::before,
#list tbody tr td:first-child a[href$=".ogg"]::before,
#list tbody tr td:first-child a[href$=".m4a"]::before {
  content: "🎵";
}

/* Archives */
#list tbody tr td:first-child a[href$=".zip"]::before,
#list tbody tr td:first-child a[href$=".rar"]::before,
#list tbody tr td:first-child a[href$=".tar"]::before,
#list tbody tr td:first-child a[href$=".gz"]::before,
#list tbody tr td:first-child a[href$=".7z"]::before,
#list tbody tr td:first-child a[href$=".bz2"]::before,
#list tbody tr td:first-child a[href$=".xz"]::before {
  content: "📦";
}

/* Documents */
#list tbody tr td:first-child a[href$=".pdf"]::before {
  content: "📕";
}

#list tbody tr td:first-child a[href$=".doc"]::before,
#list tbody tr td:first-child a[href$=".docx"]::before {
  content: "📘";
}

#list tbody tr td:first-child a[href$=".xls"]::before,
#list tbody tr td:first-child a[href$=".xlsx"]::before,
#list tbody tr td:first-child a[href$=".csv"]::before {
  content: "📊";
}

#list tbody tr td:first-child a[href$=".ppt"]::before,
#list tbody tr td:first-child a[href$=".pptx"]::before {
  content: "📙";
}

#list tbody tr td:first-child a[href$=".txt"]::before,
#list tbody tr td:first-child a[href$=".md"]::before,
#list tbody tr td:first-child a[href$=".markdown"]::before {
  content: "📝";
}

/* Code */
#list tbody tr td:first-child a[href$=".html"]::before,
#list tbody tr td:first-child a[href$=".htm"]::before,
#list tbody tr td:first-child a[href$=".css"]::before,
#list tbody tr td:first-child a[href$=".js"]::before,
#list tbody tr td:first-child a[href$=".json"]::before,
#list tbody tr td:first-child a[href$=".xml"]::before,
#list tbody tr td:first-child a[href$=".php"]::before,
#list tbody tr td:first-child a[href$=".py"]::before,
#list tbody tr td:first-child a[href$=".java"]::before,
#list tbody tr td:first-child a[href$=".c"]::before,
#list tbody tr td:first-child a[href$=".cpp"]::before,
#list tbody tr td:first-child a[href$=".h"]::before,
#list tbody tr td:first-child a[href$=".sh"]::before,
#list tbody tr td:first-child a[href$=".rb"]::before,
#list tbody tr td:first-child a[href$=".go"]::before,
#list tbody tr td:first-child a[href$=".rs"]::before,
#list tbody tr td:first-child a[href$=".ts"]::before,
#list tbody tr td:first-child a[href$=".tsx"]::before,
#list tbody tr td:first-child a[href$=".jsx"]::before {
  content: "💻";
}

/* Executables */
#list tbody tr td:first-child a[href$=".exe"]::before,
#list tbody tr td:first-child a[href$=".app"]::before,
#list tbody tr td:first-child a[href$=".dmg"]::before,
#list tbody tr td:first-child a[href$=".iso"]::before {
  content: "⚙️";
}

/* Configuration */
#list tbody tr td:first-child a[href$=".ini"]::before,
#list tbody tr td:first-child a[href$=".cfg"]::before,
#list tbody tr td:first-child a[href$=".conf"]::before,
#list tbody tr td:first-child a[href$=".yaml"]::before,
#list tbody tr td:first-child a[href$=".yml"]::before,
#list tbody tr td:first-child a[href$=".toml"]::before {
  content: "🔧";
}

/* =========================
   Parent directory hover
   ========================= */
.parent a:hover {
  color: var(--parent-hover);
}

/* =========================
   Footer
   ========================= */
footer {
  font-size: 15px;
  text-align: center;
}

footer a {
  text-decoration: underline;
  color: var(--link);
}

/* =========================
   Breadcrumb navigation
   ========================= */
.breadcrumb-nav {
  margin: 1rem 0 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elev);
  border-radius: 8px;
  border: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.breadcrumb {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0;
  padding: 0;
  font-size: 0.95rem;
}

.breadcrumb li {
  display: flex;
  align-items: center;
}

.breadcrumb li:not(:last-child)::after {
  content: "/";
  margin-left: 0.5rem;
  color: var(--muted);
}

.breadcrumb a {
  color: var(--link);
  text-decoration: none;
  transition: color 150ms ease;
}

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

.breadcrumb-current {
  color: var(--fg);
  font-weight: 500;
}

/* =========================
   Copy page URL button
   ========================= */
.copy-page-url-btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--fg);
  padding: 0.5rem 1rem;
  margin-left: 1rem;
  border-radius: 6px;
  font:
    400 0.85rem system-ui,
    sans-serif;
  cursor: pointer;
  transition: all 150ms ease-in;
}

.copy-page-url-btn:hover {
  background: var(--row-hover);
  border-color: var(--accent);
}

.copy-page-url-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* =========================
   Pagination controls
   ========================= */
.pagination {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0;
  padding: 1rem;
}

.pagination-info {
  color: var(--muted);
  font-size: 0.9rem;
}

.pagination-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

.pagination-btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font:
    400 0.9rem system-ui,
    sans-serif;
  cursor: pointer;
  transition: all 150ms ease-in;
  min-width: 2.5rem;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--row-hover);
  border-color: var(--accent);
}

.pagination-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.pagination-ellipsis {
  color: var(--muted);
  padding: 0 0.25rem;
}

/* =========================
   Responsive: mobile (≤ 720px)
   ========================= */
@media (max-width: 720px) {
  body {
    padding: clamp(16px, 4vw, 32px);
    box-shadow: none;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
    width: 100%;
  }

  table {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 16px;
    border: 1px solid var(--td-border);
    border-radius: 12px;
    box-shadow: var(--table-shadow);
    overflow: hidden;
    background: var(--bg-elev);
  }

  body.theme-dark tr {
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
  }

  td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--td-border);
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }

  td:last-child {
    border-bottom: none;
    text-align: left;
  }

  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: rgba(27, 31, 42, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  body.theme-dark td::before {
    color: rgba(255, 255, 255, 0.65);
  }

  /* Fallback labels when data-label is absent */
  td:nth-of-type(1):not([data-label])::before {
    content: "Name";
  }
  td:nth-of-type(2):not([data-label])::before {
    content: "Size";
  }
  td:nth-of-type(3):not([data-label])::before {
    content: "Last modified";
  }
  td:nth-of-type(4):not([data-label])::before {
    content: "Description";
  }

  .breadcrumb {
    font-size: 0.85rem;
  }

  .breadcrumb-nav {
    padding: 0.5rem 0.75rem;
  }

  .pagination-btn {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    min-width: 2.25rem;
  }

  .pagination-info {
    font-size: 0.85rem;
  }

  .copy-page-url-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
    margin-left: 0;
    margin-top: 0.5rem;
  }
}
