/* Lister - Directory Listing Styles */
/* Based on jonplummer.com design system */

:root {
  /* Layout */
  --gutter: 2rem;
  --max-width: 66rem;
  --breakpoint-mobile: 54rem;

  /* Typography */
  --font-family: system-ui, sans-serif;
  --text-size: 16px;
  --line-height: 1.5;
  --font-size-xxs: 0.875rem;  --line-height-xxs: 1.715;
  --font-size-xs: 1rem; --line-height-xs: 1.5;
  --font-size-sm: 1.125rem; --line-height-sm: 1.3334;
  --font-size-md: 1.25rem; --line-height-md: 1.2;
  --font-size-lg: 1.5rem; --line-height-lg: 1;
  --font-size-xl: 2rem; --line-height-xl: 1;
  --font-size-2xl: 2.5rem; --line-height-2xl: 1.2;
  --font-size-3xl: 4rem; --line-height-3xl: 1;
  --line-height-tight: 1.1;

  /* Font weights */
  --font-weight-thin: 100;
  --font-weight-bold: 700;
  --font-weight-black: 900;

  /* Letter spacing */
  --letter-spacing-tight: -0.025em;
  --letter-spacing-normal: normal;
  --letter-spacing-loose: 0.025em;

  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.25rem;
  --spacing-lg: 2rem;
  --spacing-xl: 2.25rem;
  --spacing-ex: 5ex;

  /* Colors from jonplummer.com */
  --text-color: #404040;
  --text-color-light: #707070;
  --background-color: #dadccf;
  --content-background-color: #fff;
  --link-color: #bf1b1b;
  --link-hover-color: #ed3f1c;
  --link-visited-color: #736b1e;
  --link-active-color: #ed8008;
  
  /* Additional colors for Lister */
  --border-color: #e2e8f0;
  --hover-color: #f1f5f9;
  --error-color: #dc2626;
  --success-color: #16a34a;
  
  /* Indentation system */
  --indent-base: 2rem;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --text-color: #e0e0e0;
    --text-color-light: #b0b0b0;
    --background-color: #1a1a1a;
    --content-background-color: #2d2d2d;
    --link-color: #ff6b6b;
    --link-hover-color: #ff8e8e;
    --link-visited-color: #c4a484;
    --link-active-color: #ffa500;
    --border-color: #334155;
    --hover-color: #1e293b;
  }
  
  /* Dark mode triangle color */
  .directory-toggle .toggle-icon::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 2l6 4l-6 4z' fill='%23ff6b6b'/%3E%3C/svg%3E");
  }
}

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

/* Prevent font size inflation */
html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

/* Remove default margin in favour of better control in authored CSS */
body, h1, h2, h3, h4, p,
figure, blockquote, dl, dd, section {
  margin-block-end: 0;
}

/* Take up the entire height of the viewport */
body {
  min-height: 100vh;
  margin: 0; 
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--text-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing-loose);
  color: var(--text-color);
  background-color: var(--background-color);
}

/* Main layout containers */
body>header, body>main, body>footer {
  margin: 0 auto;
  padding: var(--gutter);
  max-width: var(--max-width);
  background-color: var(--content-background-color);
}

body>footer {
  padding-top: 0;
}

/* Header layout */
header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  padding-bottom: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
}

h1 {
  margin: var(--spacing-md) 0 0.25rem 0;
  font-size: var(--font-size-2xl);
  line-height: var(--line-height-2xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--link-color);
}

/* Hgroup layout and typography */
hgroup {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

hgroup h1 {
  font-size: var(--font-size-3xl);
  line-height: var(--line-height-3xl);
  font-weight: var(--font-weight-thin);
  margin: 0;
}

hgroup p {
  margin: 0;
  font-size: var(--font-size-xs);
  line-height: var(--line-height-xs);
  font-style: italic;
}

hgroup h1 a {
  text-decoration: none;
  color: var(--link-color);
}

hgroup h1 a:hover {
  text-decoration: underline;
}

hgroup h1 a:visited {
  color: var(--link-color); /* Keep hgroup as link-color even when visited */
}

.breadcrumbs {
  font-size: var(--font-size-xxs);
  line-height: var(--line-height-xxs);
  color: var(--text-color-light);
}

.breadcrumbs a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.3s ease;
}

.breadcrumbs a:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

.breadcrumbs a:visited {
  color: var(--link-visited-color);
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* Article layout */
article {
  margin: 0;
  padding-bottom: var(--spacing-lg);
}

/* Article grid areas */
article header {
  margin-bottom: var(--spacing-lg);
}

article section {
  width: 100%;
}

article footer {
  margin-top: var(--spacing-lg);
}

/* Article headings */
article h1 {
  margin: 0 0 var(--spacing-sm) 0;
  font-size: var(--font-size-2xl);
  line-height: var(--line-height-2xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--link-color);
}

/* Mobile responsive layout */
@media all and (max-width: 54rem) {
  /* Stack header elements vertically on mobile */
  header {
    flex-direction: column;
    align-items: flex-start;
  }
}

.error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: var(--spacing-lg);
  margin: var(--spacing-lg) 0;
  color: var(--error-color);
}

.directory-listing {
  margin-top: var(--spacing-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: var(--spacing-xs) 0;
  text-align: left;
}

th {
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xxs);
  line-height: var(--line-height-xxs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-color-light);
}

/* Main table hover - only apply to direct children of main tbody, not nested tables */
.directory-listing > table > tbody > tr:hover {
  background-color: var(--hover-color);
}

.directory-link, .file-link {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  color: var(--text-color);
  text-decoration: none;
  font-weight: var(--font-weight-bold);
  font-size: inherit;
  transition: color 0.3s ease;
}


.directory-link:hover, .file-link:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

.directory-link:visited, .file-link:visited {
  color: var(--link-visited-color);
}

.icon {
  font-size: var(--font-size-sm);
  width: 20px;
  text-align: center;
}

.empty {
  text-align: center;
  padding: var(--spacing-xl) var(--spacing-lg);
  color: var(--text-color-light);
}

footer {
  margin-top: var(--spacing-lg);
  text-align: right;
  font-style: italic;
  color: var(--link-visited-color);
  font-size: var(--font-size-xxs);
  line-height: var(--line-height-xxs);
  font-weight: 300;
}

footer p {
  margin: 0;
}

/* Expandable directory styles */
.directory-toggle {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  color: var(--text-color);
  text-decoration: none;
  font-weight: var(--font-weight-bold);
  font-size: inherit;
  transition: color 0.3s ease;
  width: 100%;
  text-align: left;
}


.directory-toggle:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

.directory-toggle:visited {
  color: var(--link-visited-color);
}

.toggle-icon {
  font-size: var(--font-size-xxs);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}


/* Change folder emoji when expanded */
.item-row.expanded .directory-toggle .icon.folder::before {
  content: '📂';
}

.item-row:not(.expanded) .directory-toggle .icon.folder::before {
  content: '📁';
}

/* Expanded content styling removed - indentation provides visual hierarchy */

/* Reserve space for caret on all items (files and folders) */
.directory-toggle,
.file-link {
  padding-left: 0;
  display: flex;
  align-items: center;
}

/* Caret space - always reserve space for caret even on files */
.directory-toggle .toggle-icon {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
  display: inline-block;
  transition: transform 0.2s ease;
}

/* Default state - right-pointing triangle */
.directory-toggle .toggle-icon::before {
  content: '';
  display: block;
  width: 12px;
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 2l6 4l-6 4z' fill='%23bf1b1b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  margin: 0 auto;
  transition: transform 0.2s ease;
}

/* Expanded state - down-pointing triangle */
.item-row.expanded .directory-toggle .toggle-icon::before {
  transform: rotate(90deg);
}

/* Reserve same space for files as directories have for toggle icon */
.file-link::before {
  content: '';
  width: 16px;
  flex-shrink: 0;
}

/* Icon alignment - all icons align in strict column */
.directory-toggle .icon,
.file-link .icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* Progressive indentation for expanded content */
.expanded-content[data-nesting-level="1"] .directory-toggle,
.expanded-content[data-nesting-level="1"] .file-link,
.expanded-content[data-nesting-level="1"] .empty-folder {
  padding-left: var(--indent-base);
}

.expanded-content[data-nesting-level="2"] .directory-toggle,
.expanded-content[data-nesting-level="2"] .file-link,
.expanded-content[data-nesting-level="2"] .empty-folder {
  padding-left: calc(var(--indent-base) * 2);
}

.expanded-content[data-nesting-level="3"] .directory-toggle,
.expanded-content[data-nesting-level="3"] .file-link,
.expanded-content[data-nesting-level="3"] .empty-folder {
  padding-left: calc(var(--indent-base) * 3);
}

.expanded-content[data-nesting-level="4"] .directory-toggle,
.expanded-content[data-nesting-level="4"] .file-link,
.expanded-content[data-nesting-level="4"] .empty-folder {
  padding-left: calc(var(--indent-base) * 4);
}

.expanded-content[data-nesting-level="5"] .directory-toggle,
.expanded-content[data-nesting-level="5"] .file-link,
.expanded-content[data-nesting-level="5"] .empty-folder {
  padding-left: calc(var(--indent-base) * 5);
}

/* Empty folder styling */
.empty-folder {
  display: flex;
  align-items: center;
  color: var(--text-color-light);
  font-style: italic;
  cursor: default;
  padding: var(--spacing-xs) 0;
}

.empty-folder .icon {
  margin-right: var(--spacing-xs);
  opacity: 0.7;
}


/* Loading state */
.directory-toggle.loading .toggle-icon {
  animation: spin 1s linear infinite;
}

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

/* Responsive design */
@media all and (max-width: 54rem) {
  /* Stack header elements vertically on mobile */
  header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  h1 {
    font-size: var(--font-size-xl);
    line-height: var(--line-height-xl);
  }
  
  table {
    font-size: var(--font-size-xxs);
  }
  
  th, td {
    padding: var(--spacing-xs) var(--spacing-sm);
  }
  
  .breadcrumbs {
    font-size: var(--font-size-xxs);
  }
}

/* Print styles */
@media print {
  body {
    background: white;
    color: black;
  }
  
  .breadcrumbs {
    display: none;
  }
  
  table {
    border: 1px solid #000;
  }
  
  th, td {
    border: 1px solid #000;
  }
}
