/* The frame around every page (frame.js, telos/design ticket 03): a top bar, an icon rail down
   the left, the folder tree as a panel the rail opens, and the page's own column. Linked after
   tokens.css, before the page's own stylesheet (trove.css or admin.css). Works without script:
   the phone menu and the folder tree are checkboxes, the account menu a <details>. */

:root {
  --bar: 56px;
  --rail: 72px;
  --gutter: var(--space-5);
}

/* Read out, not shown */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- The bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--bar);
  box-sizing: border-box;
  padding: 0 var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.bar .brand {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font: 700 var(--text-xl) / 1 var(--font-reading);
  text-decoration: none;
}

.bar .chest-icon {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

/* A share's title, for its visitors */
.bar .bar-title {
  overflow: hidden;
  color: var(--neutral);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tabs {
  display: flex;
  gap: var(--space-1);
  min-width: 0;
  margin-left: var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs a {
  flex: none;
  padding: var(--space-2) var(--space-3);
  border-radius: 999px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.tabs a:hover {
  background: var(--secondary);
}

.tabs a[aria-current] {
  background: var(--primary);
  color: var(--on-primary);
}

.bar .spacer {
  flex: 1;
}

/* Something the integrity check found, waiting for a keeper (integrity.js) */
.bar .alert {
  flex: none;
  color: var(--warning);
  font-weight: 600;
}

/* Upload: the bar's primary button */
.bar .upload {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  box-sizing: border-box;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  text-decoration: none;
}

.bar .upload:hover {
  background: color-mix(in srgb, var(--primary) 85%, var(--surface));
}

.bar .upload .icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.bar .login {
  flex: none;
  font-weight: 600;
}

/* How full the chest is, in the bar when there are no accounts (and so no account menu) */
.bar > .usage {
  margin: 0;
  color: var(--neutral);
  font-size: var(--text-sm);
}

/* ---------- The account menu ---------- */
.account {
  position: relative;
  flex: none;
}

.account summary {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--secondary);
  color: var(--text);
  font-weight: 700;
  list-style: none;
  cursor: pointer;
}

.account summary::-webkit-details-marker {
  display: none;
}

.account[open] summary,
.account summary:hover {
  border-color: var(--field);
}

.account-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  display: grid;
  min-width: 15rem;
  padding: var(--space-2) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.account-menu .who {
  display: grid;
  margin: 0;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.account-menu .who small {
  color: var(--neutral);
  font-size: var(--text-sm);
  font-weight: 400;
}

.account-menu a,
.account-menu button {
  display: block;
  width: 100%;
  min-height: 40px;
  box-sizing: border-box;
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.account-menu a:hover,
.account-menu button:hover {
  background: var(--secondary);
}

.account-menu form {
  margin: 0;
}

.account-menu .usage {
  margin: var(--space-2) 0 0;
  padding: var(--space-3) var(--space-4) var(--space-2);
  border-top: 1px solid var(--border);
  color: var(--neutral);
  font-size: var(--text-sm);
}

/* ---------- The rail ---------- */
.rail {
  position: fixed;
  top: var(--bar);
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  width: var(--rail);
  box-sizing: border-box;
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.rail > a,
.rail > label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.rail > a:hover,
.rail > label:hover {
  background: var(--secondary);
}

/* The page's own place: a 3px edge, and a tint */
.rail > [aria-current] {
  background: var(--secondary);
  box-shadow: inset 3px 0 0 var(--primary);
}

/* Names are the tooltips on a wide screen; the phone menu shows them */
.rail > * > span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.rail hr {
  width: 100%;
  margin: var(--space-2) 0;
  border: 0;
  border-top: 1px solid var(--border);
}

/* The checkboxes behind the phone menu and the folder tree: invisible but focusable, so a
   keyboard can toggle them; their labels show the focus ring */
.menu-toggle,
.tree-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.menu-toggle:focus-visible ~ .bar .menu-button,
.tree-toggle:focus-visible ~ .rail .tree-label {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

/* The folder tree open: its rail button pressed */
.tree-toggle:checked ~ .rail .tree-label {
  background: var(--secondary);
  box-shadow: inset 3px 0 0 var(--primary);
}

/* The phone menu: nothing to see or focus on a wide screen */
.menu-button {
  display: none;
}

.menu-toggle {
  visibility: hidden;
}

/* ---------- The folder tree, a panel beside the rail ---------- */
.tree {
  position: fixed;
  top: var(--bar);
  bottom: 0;
  left: var(--rail);
  z-index: 15;
  width: 18rem;
  max-width: calc(100vw - var(--rail));
  box-sizing: border-box;
  padding: var(--space-4) var(--space-3);
  overflow: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
  translate: -100% 0;
  visibility: hidden;
  transition:
    translate 150ms ease-out,
    visibility 150ms;
}

.tree-toggle:checked ~ .tree {
  translate: 0 0;
  visibility: visible;
}

.tree ul {
  margin: 2px 0;
  padding-left: 14px;
  list-style: none;
}

.tree > ul {
  padding-left: 0;
}

/* Line up folders without subfolders with the names after a disclosure triangle */
.tree li > a {
  margin-left: 1.1em;
}

.tree summary {
  cursor: pointer;
}

.tree a {
  display: inline-block;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  color: inherit;
  text-decoration: none;
}

.tree a:hover {
  text-decoration: underline;
}

.tree a[aria-current] {
  font-weight: 600;
  background: var(--secondary);
  box-shadow: inset 2px 0 0 var(--primary);
}

/* ---------- The page's own column ---------- */
.main {
  display: block;
  margin-left: var(--rail);
  padding: var(--gutter);
}

/* A share's visitors have no rail */
.bar:first-child + .main {
  margin-left: 0;
}

/* ---------- Phones: the rail is a menu ---------- */
@media (max-width: 800px) {
  :root {
    --gutter: var(--space-4);
  }

  .bar {
    gap: var(--space-3);
    padding: 0 var(--space-2) 0 var(--space-3);
  }

  .bar .brand {
    font-size: var(--text-lg);
  }

  .tabs {
    margin-left: 0;
  }

  .tabs a {
    padding: var(--space-2);
  }

  .menu-toggle {
    visibility: visible;
  }

  .menu-button {
    display: grid;
    flex: none;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
  }

  /* Upload, its icon alone */
  .bar .upload {
    width: 40px;
    padding: 0;
    justify-content: center;
  }

  .bar .upload span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .rail {
    display: none;
    width: min(18rem, 85vw);
  }

  .menu-toggle:checked ~ .rail {
    display: flex;
  }

  .rail > a,
  .rail > label {
    justify-content: flex-start;
    gap: var(--space-3);
    padding: 0 var(--space-3);
  }

  .rail > * > span {
    position: static;
    width: auto;
    height: auto;
    clip-path: none;
  }

  /* Its button is in the closed menu: nothing to focus, and no panel, until the menu opens */
  .menu-toggle:not(:checked) ~ :is(.tree-toggle, .tree) {
    visibility: hidden;
  }

  .menu-toggle:not(:checked) ~ .tree {
    translate: -100% 0;
  }

  /* With the folder tree open, the menu is the icon rail again and the tree is beside it, so
     its button stays in reach */
  .tree-toggle:checked ~ .rail {
    width: var(--rail);
  }

  .tree-toggle:checked ~ .rail > :is(a, label) {
    justify-content: center;
    padding: 0;
  }

  .tree-toggle:checked ~ .rail > * > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .tree {
    width: min(20rem, calc(100vw - var(--rail)));
    max-width: none;
  }

  .main {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tree {
    transition: none;
  }
}
