/*
  Custom Dufs web UI — "flat ops-surface" theme.

  Base file: dufs v0.46.0 assets/index.css
  (https://github.com/sigoden/dufs/blob/v0.46.0/assets/index.css)

  Visual contract (adapted from the strlt / Dynacat ops-surface theme):
    · No cards, no boxes, no shadows. Everything sits on the page background;
      structure comes from hairline dividers, alignment and type hierarchy.
      => the toolbar buttons, the search field and the listing rows carry no
         chrome of their own. Hover is a wash, not a border.
    · Red #e81a13 carries meaning, never decoration:
        - active/location  -> the current breadcrumb's underline
        - arrows            -> the breadcrumb "/" separators, the download
                              icon on row hover
        - activity          -> upload status, the failed-upload glyph, retry
        - selection, focus  -> ::selection and every :focus-visible ring
    · Inter for UI text at 14px/450, JetBrains Mono + tabular numerals for
      telemetry (size, modified time, transfer speed).
    · 4px radius, 120ms hover motion, hairline scrollbar, reduced-motion
      honoured.

  Two things this file must keep working, because the DOM contract with
  index.js depends on them: the class/id names, and the layout behaviour
  (full-width sticky header, full-width listing, >=44px tap targets, and the
  phone restack) implemented in the previous revision of this file. Every
  structural rule below is preserved; only the surface treatment changed.

  Dark is the primary palette. Light is the same design re-seeded from the
  variable block at the bottom, so both schemes come from one set of rules.
*/


/* ============================================================
   1. Colour + type tokens
   ============================================================ */

:root {
  color-scheme: dark;

  /* Warm-neutral near-black, not pure #000 — same intent as the
     ops-surface palette's hsl(240 6% ~7%). */
  --bg: #0d0d0f;
  --text-highlight: #f3f2ef;
  --text-base: #c6c5c0;
  --text-subdue: #8b8a85;
  --separator: rgba(255, 255, 255, 0.09);
  --hover-wash: hsla(0, 0%, 100%, 0.04);
  --active-wash: hsla(0, 0%, 100%, 0.07);
  --brand-red: #e81a13;

  --radius: 4px;
  --radius-focus: 2px;
  --motion: 120ms;

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-base: 0.875rem;   /* 14px */
  --fs-small: 0.8125rem; /* 13px */
  --fs-tiny: 0.75rem;    /* 12px */
  --fs-h: 1rem;          /* 16px */
}

/* Self-hosted fonts: InterVariable.woff2 and JetBrainsMonoVariable.woff2
   ship in assets/fonts/, picked up via the relative urls below. If a file is
   absent dufs answers 404 and the system-ui / ui-monospace fallback applies
   silently.

   The url is relative on purpose: this stylesheet is served from
   /__dufs_v<version>__/index.css, so a relative path resolves inside the
   assets directory and keeps working behind dufs' --path-prefix. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/InterVariable.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('fonts/JetBrainsMonoVariable.woff2') format('woff2');
}

html {
  font-family: var(--font-ui);
  font-size: 100%;
  line-height: 1.45;
  letter-spacing: -0.005em;
  color: var(--text-base);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 450;
  /* upstream had `min-width: 538px` here to stop the breadcrumb wrapping early.
     That made every viewport under 538px scroll horizontally, so width
     adaptation is handled by the flex/grid rules below instead. */
  -webkit-text-size-adjust: 100%;
}

.hidden {
  display: none !important;
}

a {
  color: var(--text-highlight);
  text-decoration: none;
  transition: color var(--motion) ease;
}

a:hover {
  color: var(--text-highlight);
  text-decoration: underline;
  text-underline-offset: 2px;
}


/* ============================================================
   2. Header — full-width sticky bar, hairline underneath
   ============================================================ */

.head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.2rem;
  padding: 0.7rem clamp(0.9rem, 2vw, 2rem);
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: var(--bg);
  border-bottom: 1px solid var(--separator);
  /* no `width: 100%`: this is a block-level box and already fills the body,
     and width + horizontal padding on a content-box element pushes the page
     sideways by the padding amount. */
  box-sizing: border-box;
}

.breadcrumb {
  font-size: var(--fs-h);
  font-weight: 500;
  letter-spacing: -0.01em;
  /* take the leftover width on wide screens, stay shrinkable on phones */
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-all;
}

.breadcrumb a {
  color: var(--text-base);
}

.breadcrumb a:hover {
  color: var(--text-highlight);
}

/* The current location: the "active page" marker, and the strongest red
   element in the chrome - same role as the nav's current-page underline. */
.breadcrumb b {
  color: var(--text-highlight);
  font-weight: 600;
  border-bottom: 2px solid var(--brand-red);
  padding-bottom: 1px;
}

/* Arrows are red. */
.breadcrumb .separator {
  color: var(--brand-red);
  padding: 0 0.3em;
  opacity: 0.75;
}

.breadcrumb svg {
  height: 1em;
  width: 1em;
  fill: currentColor;
  opacity: 0.8;
  vertical-align: -0.1em;
}

.breadcrumb a:hover svg {
  opacity: 1;
}


/* ============================================================
   3. Toolbar — flat text buttons, hover wash instead of boxes
   ============================================================ */

.toolbox,
.toolbox-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
}

.toolbox {
  margin-right: 0.5rem;
}

.toolbox-right {
  margin-left: auto;
  margin-right: 0.5rem;
}

.toolbox>a,
.toolbox>div {
  height: auto;
}

/* Upstream sized these by their 16px icons alone
   (`.toolbox>a, .toolbox>div { height: 1.1rem }`), far below a usable touch
   target. Size and labels stay; the box, border and fill do not. */
.control,
.login-btn,
.logout-btn,
.save-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  min-height: 44px;
  padding: 0 0.9rem;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-base);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 450;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  /* no 300ms tap delay, no double-tap zoom on touch devices */
  touch-action: manipulation;
  transition: background var(--motion) ease, color var(--motion) ease;
}

.control:hover,
.login-btn:hover,
.logout-btn:hover,
.save-btn:hover {
  background: var(--hover-wash);
  color: var(--text-highlight);
}

.control:active,
.login-btn:active,
.logout-btn:active,
.save-btn:active {
  background: var(--active-wash);
}

.control svg,
.login-btn svg,
.logout-btn svg,
.save-btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: currentColor;
  opacity: 0.8;
  transition: opacity var(--motion) ease;
}

.control:hover svg,
.login-btn:hover svg,
.logout-btn:hover svg,
.save-btn:hover svg {
  opacity: 1;
}

.save-btn svg {
  width: 18px;
  height: 18px;
  /* the upstream save glyph ships a hard-coded dark fill */
  fill: currentColor !important;
}

/* the visible text label that makes each action self-describing */
.control-label {
  white-space: nowrap;
}

.upload-file input {
  display: none;
}

.upload-file label {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  cursor: pointer;
}

.logout-btn {
  display: inline-flex;
}

.user-name {
  color: var(--text-highlight);
  max-width: 12em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* ============================================================
   4. Search — a hairline field, not a pill
   ============================================================ */

.searchbar {
  display: flex;
  flex-wrap: nowrap;
  /* grow/shrink with the viewport instead of a fixed 246px */
  flex: 0 1 280px;
  min-width: 170px;
  max-width: 100%;
  height: 34px;
  align-items: center;
  background: transparent;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  transition: border-color var(--motion) ease, background var(--motion) ease;
}

.searchbar:focus-within {
  border-color: var(--brand-red);
  background: var(--hover-wash);
}

.searchbar .icon {
  color: var(--text-subdue);
  display: flex;
  align-items: center;
  padding: 0 0.1rem 0 0.6rem;
}

.searchbar .icon svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.searchbar #search {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 0 0.6rem 0 0.5rem;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text-highlight);
  font-family: inherit;
  font-size: var(--fs-base);
}

.searchbar #search::placeholder {
  color: var(--text-subdue);
}


/* ============================================================
   5. Listing — hairline rows, full width, no boxes
   ============================================================ */

.main {
  padding: 0 clamp(0.9rem, 2vw, 2rem);
}

.empty-folder,
.not-editable {
  color: var(--text-subdue);
  font-style: italic;
}

.editor {
  width: 100%;
  /* the header is taller than upstream's 5rem allowance */
  height: calc(100vh - 10rem);
  padding: 0.75rem;
  background: transparent;
  color: var(--text-highlight);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  outline: none;
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: 1.5;
  resize: vertical;
}

/* full width, and the Name column absorbs the leftover space instead of the
   table hugging its content.

   `table-layout: fixed` is what makes that safe: under the default auto
   layout a single long file name widens the table and the page scrolls
   sideways. Fixed layout resolves column widths from the first row (the
   <thead>, which index.js renders one <th> per column) and lets the name
   cell clip. */
.paths-table,
.uploaders-table {
  width: 100%;
}

.paths-table {
  table-layout: fixed;
  border-collapse: collapse;
}

.paths-table .cell-icon {
  width: 30px;
}

.paths-table .cell-name {
  width: auto;
}

.paths-table .cell-mtime {
  width: 132px;
  padding-left: 0.6em;
}

.paths-table .cell-size {
  text-align: right;
  width: 86px;
  padding-left: 0.6em;
}

.paths-table th,
.uploaders-table th {
  text-align: left;
  font-size: var(--fs-small);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-subdue);
  white-space: nowrap;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--separator);
}

/* sort links are quiet; the row they sort carries the weight */
.paths-table thead a {
  color: inherit;
  text-decoration: none;
  transition: color var(--motion) ease;
}

.paths-table thead a:hover {
  color: var(--text-highlight);
  text-decoration: none;
}

.paths-table thead a>span {
  display: inline-block;
  padding-left: 4px;
  vertical-align: -1px;
  opacity: 0.6;
}

.paths-table thead a:hover>span {
  opacity: 1;
}

.paths-table td,
.uploaders-table td {
  white-space: nowrap;
  padding: 0.15rem 0;
}

.paths-table tbody tr {
  transition: background var(--motion) ease;
}

.paths-table tbody tr:hover {
  background: var(--hover-wash);
}

.path svg {
  width: 14px;
  height: 16px;
  fill: var(--text-subdue);
  opacity: 0.8;
}

.paths-table tbody tr:hover .path svg {
  opacity: 1;
}

.path {
  list-style: none;
}

.path a {
  display: block;
  width: 100%;
  min-width: 0;
  color: var(--text-highlight);
  font-weight: 450;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  /* replaces upstream `max-width: calc(100vw - 375px); min-width: 170px`.
     The name cell is a fixed-layout column, so width + clipping is enough to
     truncate a long name instead of widening the page. */
  text-decoration: none;
}

.path a:hover {
  text-decoration: none;
}

/* Telemetry: mono, tabular, quiet. */
.cell-mtime,
.cell-size,
.cell-status {
  color: var(--text-subdue);
  font-family: var(--font-mono);
  font-size: var(--fs-tiny);
  font-variant-numeric: tabular-nums;
}

.uploaders-table {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--separator);
}

.uploader {
  color: var(--text-subdue);
  padding-right: 1em;
}

.uploaders-table .cell-status {
  width: 190px;
  padding-left: 0.6em;
}

.cell-status span {
  display: inline-block;
}

/* a finished upload is quiet; a failed one is the down-state, so it is red */
.upload-status:has(> span:first-child) {
  color: var(--text-subdue);
}

.retry-btn {
  color: var(--text-subdue);
  cursor: pointer;
  transition: color var(--motion) ease;
}

.retry-btn:hover {
  color: var(--brand-red);
}


/* ============================================================
   6. Row actions — icon-only on narrow screens, labelled on wide
   ============================================================ */

.paths-table .cell-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
  width: 210px;
  padding-left: 0.6em;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  min-width: 40px;
  min-height: 40px;
  padding: 0 0.4em;
  color: var(--text-subdue);
  text-decoration: none;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  transition: background var(--motion) ease, color var(--motion) ease;
}

.action-btn:hover {
  background: var(--active-wash);
  color: var(--text-highlight);
}

.action-btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: currentColor;
  transition: opacity var(--motion) ease, fill var(--motion) ease;
}

/* Arrows are red — and they stay quiet until the row is engaged, exactly
   like the bookmark arrows in the source theme. */
.action-btn:hover svg,
.paths-table tbody tr:hover .action-btn svg {
  opacity: 1;
}

.action-btn[title="Delete"]:hover,
.action-btn[aria-label="Delete"]:hover {
  color: var(--brand-red);
}

/* Row action labels need horizontal room, so they appear on wide screens
   only; the toolbar buttons stay labelled at every size. */
.action-label {
  display: none;
  font-size: var(--fs-small);
  white-space: nowrap;
}


/* ============================================================
   7. Page details
   ============================================================ */

::selection {
  background: rgba(232, 26, 19, 0.3);
  color: var(--text-highlight);
}

/* Focus is a semantic signal, so the ring is red. */
*:focus-visible {
  outline: 1px solid var(--brand-red);
  outline-offset: 2px;
  border-radius: var(--radius-focus);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--separator);
  border-radius: var(--radius);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-subdue);
}

::-webkit-scrollbar-track {
  background: transparent;
}


/* ============================================================
   8. Breakpoints
   ============================================================ */

/* wide desktop: room for labelled row actions */
@media (min-width: 1024px) {
  .action-label {
    display: inline;
  }

  .paths-table .cell-actions {
    width: 470px;
  }

  .control,
  .login-btn,
  .logout-btn,
  .save-btn {
    min-height: 46px;
  }

  .action-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* tablet: keep the table, tighten the fixed columns so the name survives */
@media (min-width: 641px) and (max-width: 1023px) {
  .paths-table .cell-mtime {
    width: 116px;
  }

  .paths-table .cell-size {
    width: 72px;
  }

  .paths-table .cell-actions {
    /* 4 icon buttons of 40px + gaps, so a file row keeps one action line */
    width: 180px;
  }
}

/* phone: restack each listing row as
   [icon | name | size] / [last modified] / [action buttons] */
@media (max-width: 640px) {
  .head {
    padding: 0.6rem 0.9rem;
  }

  .toolbox,
  .toolbox-right {
    /* an auto-fit grid packs the labelled buttons into even columns instead
       of letting flex-wrap leave one button stretched across the row */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
    margin: 0;
    width: 100%;
  }

  .searchbar {
    flex: 1 1 100%;
    max-width: 100%;
  }

  .control,
  .login-btn,
  .logout-btn,
  .save-btn {
    justify-content: center;
    padding: 0 0.6rem;
  }

  .paths-table thead,
  .paths-table tbody {
    display: block;
  }

  .paths-table thead tr,
  .paths-table tbody tr {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto;
    column-gap: 0.5em;
    row-gap: 0.15em;
    align-items: center;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--separator);
  }

  .paths-table .cell-icon {
    grid-column: 1;
    grid-row: 1;
    width: auto;
    padding-left: 0;
  }

  .paths-table .cell-name {
    grid-column: 2;
    grid-row: 1;
  }

  .paths-table .cell-size {
    grid-column: 3;
    grid-row: 1;
    width: auto;
  }

  .paths-table .cell-mtime {
    grid-column: 2 / -1;
    grid-row: 2;
    width: auto;
    padding-left: 0;
  }

  .paths-table .cell-actions {
    grid-column: 1 / -1;
    grid-row: 3;
    width: auto;
    padding-left: 0;
    justify-content: flex-start;
  }

  /* the header row mirrors the body layout, so the sort links stay available */
  .paths-table thead th {
    border-bottom: 0;
  }

  .paths-table thead tr {
    border-bottom: 1px solid var(--separator);
  }

  .paths-table thead th.cell-name {
    grid-column: 1 / 3;
    grid-row: 1;
  }

  .paths-table thead th.cell-size {
    grid-column: 3;
    grid-row: 1;
  }

  .paths-table thead th.cell-mtime {
    grid-column: 2 / -1;
    grid-row: 2;
  }

  .paths-table thead th.cell-actions {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .uploaders-table thead,
  .uploaders-table tbody,
  .uploaders-table tr,
  .uploaders-table th,
  .uploaders-table td {
    display: block;
  }

  .uploaders-table .cell-status {
    width: auto;
    padding-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}


/* ============================================================
   9. Light mode — the same design, re-seeded.

   Dufs has no theme layer of its own, so rather than a second set of
   component rules this block only re-seeds the tokens from section 1.
   (The source theme keeps this parked because it still needed an eyeball
   pass; both color schemes are covered here.)
   ============================================================ */

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f7f6;
    --text-highlight: #14141a;
    --text-base: #33343a;
    --text-subdue: #6a6b72;
    --separator: rgba(0, 0, 0, 0.1);
    --hover-wash: hsla(0, 0%, 0%, 0.04);
    --active-wash: hsla(0, 0%, 0%, 0.07);
  }

  /* red keeps its meaning; on light it is a touch deeper for the underline
     and the focus ring, which are hairlines against a light page */
  :root {
    --brand-red: #cf160f;
  }

  /* wash flips from white-on-dark to black-on-light */
  .searchbar:focus-within {
    background: var(--hover-wash);
  }

  ::selection {
    background: rgba(232, 26, 19, 0.22);
  }

  ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
  }

  ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.32);
  }
}
