/* Sidebar: terminal switcher, tree rows, zones, bin, resize divider, tab drag. */


.side {
  position: relative;
  display: flex;
  flex: none;
  flex-direction: column;
  /* a fresh open takes about a sixth of the screen, as in The System; dragging the divider sets it */
  box-sizing: content-box;
  width: max(140px, 17vw);
  padding: 8px 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--sheet);
  font: 400 12px/1.7 var(--font-ui);
}

.side[hidden] { display: none; }

.splitter {
  position: relative;
  flex: none;
  width: 8px;
  cursor: col-resize;
}

.splitter[hidden] { display: none; }

.splitter::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  background: transparent;
  content: "";
}

.splitter:hover::after,
.splitter.active::after,
.splitter:focus-visible::after { background: var(--accent); }

.side-head {
  position: sticky;
  z-index: 5;
  top: -8px;
  margin-top: -8px;
  margin-bottom: 3px;
  padding-top: 8px;
  background: var(--sheet);
}

/* Terminals: their own section above "new + / select", split off by a tinted line */
.term-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--tline);
}

.term-pick {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--accent);
  border-bottom-width: 2px;
  border-radius: 2px;
  background: var(--sel-bg);
  box-shadow: var(--sel-glow);
  color: var(--fg);
  font: 500 12px/1.7 var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition: border-color .12s;
}

.term-pick:active { transform: translateY(1px); }
.term-pick .tl { flex: none; color: var(--accent); }
.term-pick .tn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-pick .car { flex: none; color: var(--muted); font-size: 10px; }

.term-nav { display: flex; flex: none; align-items: center; gap: 4px; }
.term-nav .n { min-width: 3ch; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; text-align: center; }


/* The tree: every file and directory is a small boxed tab */
.side .tree { display: flex; flex: 1; flex-direction: column; gap: 3px; }

.side .row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px 1px 10px;
  color: var(--fg);
  white-space: nowrap;
  outline: none;
  cursor: pointer;
  user-select: none;
}

.side .row.file,
.side .row.folder,
.side .row.bin {
  margin: 0 8px;
  padding: 2px 4px 2px 8px;
  border: 1px solid var(--tedge);
  border-bottom-width: 2px;
  border-radius: 2px;
  background: var(--tab);
  line-height: 1.6;
  transition: border-color .12s, box-shadow .12s, background .12s;
}

/* directories (and bin/) stand out a touch and get room above; their files sit a shade quieter */
.side .row.folder,
.side .row.bin { margin-top: 7px; background: color-mix(in srgb, var(--fg) 7%, var(--tab)); font-weight: 500; }
.side .row.folder .tw { flex: none; margin-right: 2px; color: var(--accent); }
.side .row.file.nested { margin-left: 34px; background: color-mix(in srgb, var(--tab) 45%, var(--sheet)); }
.side .row.file:focus-visible,
.side .row.folder:focus-visible,
.side .row.bin:focus-visible { border-color: var(--accent); }
.side .row.file[aria-current="true"] { border-color: var(--accent); background: var(--sel-bg); box-shadow: var(--sel-glow); color: var(--fg); }
.side .row.file.picked,
.side .row.folder.picked { border-color: var(--tline); background: var(--sel-bg); }
.side .row.file.binned { border-style: dashed; border-bottom-style: solid; }
.side .row.file.binned .nm { color: var(--muted); }
.side .row.file:active,
.side .row.folder:active,
.side .row.bin:active { transform: translateY(1px); }

@media (hover: hover) {
  .side .row.file:hover,
  .side .row.folder:hover,
  .side .row.bin:hover { border-color: var(--accent); }
}

/* thin solid lines from each file back to its directory: an elbow, and a trunk past all but the last */
.side .row.file.nested::before,
.side .row.file.nested::after,
.side .bin-group::before,
.side .bin-term::before { box-sizing: content-box; }

.side .row.file.nested::before {
  position: absolute;
  top: -4px;
  left: -15px;
  width: 14px;
  height: calc(50% + 3px);
  border-bottom: 1px solid var(--tline);
  border-left: 1px solid var(--tline);
  content: "";
  pointer-events: none;
}

.side .row.file.nested:not(.last)::after {
  position: absolute;
  top: 50%;
  bottom: -5px;
  left: -15px;
  border-left: 1px solid var(--tline);
  content: "";
  pointer-events: none;
}

.side .row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.side .row .more {
  padding: 0 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  visibility: hidden;
}

.side .row:focus-within .more,
.side .row[aria-current="true"] .more { visibility: visible; }

@media (hover: hover) {
  .side .row:hover .more { visibility: visible; }
}

@media (hover: none) {
  .side .row .more { visibility: visible; }
}

/* the select tick: an outlined square, with a squared-off tick in the accent when picked */
.side .row .mk {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  box-sizing: border-box;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  border: 2px solid var(--tline);
  border-radius: 0;
}

.side .row .mk.on,
.side .row.picked .mk { border-color: var(--accent); }

.side .row .mk.on::after,
.side .row.picked .mk::after {
  position: absolute;
  inset: 0;
  background: var(--accent);
  content: "";
  -webkit-mask: url("/img/tick-mask.svg") center / 10px no-repeat;
  mask: url("/img/tick-mask.svg") center / 10px no-repeat;
}

.side .row .mk.some { border-color: var(--accent); }
.side .row .mk.some::after { width: 6px; height: 2px; background: var(--accent); content: ""; }

.side .rename {
  flex: 1;
  min-width: 0;
  padding: 0 3px;
  border: none;
  border-radius: 2px;
  outline: 1px solid var(--accent);
  background: transparent;
  color: var(--fg);
  font: inherit;
}
/* the terminal's rename box (after .side .rename, which it builds on) */
.side .term-head > .rename { padding: 0 6px; background: var(--sheet); font: 500 12px/1.7 var(--font-ui); }

/* "new +" and "select", and the selection's buttons, are small tabs too */
.side .row.label { padding: 1px 8px 4px; color: color-mix(in srgb, var(--fg) 70%, var(--muted)); cursor: default; }
.side .row.label .gap { flex: 1; }

.side .lctl,
.term-arrow {
  padding: 0 7px;
  border: 1px solid var(--tedge);
  border-bottom-width: 2px;
  border-radius: 2px;
  background: var(--tab);
  color: color-mix(in srgb, var(--fg) 75%, var(--muted));
  font: 400 12px/1.6 var(--font-ui);
  cursor: pointer;
  transition: border-color .12s, color .12s;
}

.term-arrow { padding: 0 6px; line-height: 1.7; }
.side .lctl:active,
.term-arrow:not(:disabled):active { transform: translateY(1px); }
.term-arrow:disabled { opacity: .35; cursor: default; }

@media (hover: hover) {
  .side .lctl:hover,
  .term-arrow:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
}

.selrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 0 8px 6px;
}

.selrow .sel-top { display: flex; align-items: center; gap: 6px; width: 100%; }
.selrow .count { flex: 1; min-width: 0; color: var(--accent); font-size: 12px; }

.sec-title {
  padding: 2px 10px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sec-empty {
  margin: 2px 8px;
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: normal;
}

.side .tree-sep { margin: 10px 8px 4px; border-top: 1px solid var(--tline); }
.side .tree-sep.bin-sep { margin-top: auto; }
.side .row.note { margin-left: 34px; padding-left: 8px; color: var(--muted); cursor: default; }

/* drag and drop */
.side .row.dragging { opacity: .65; outline: 1px dashed var(--accent); outline-offset: -1px; }
.side .drop-into { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--sel-bg); box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent); }
.side .sec-title.drop-into { color: var(--accent); }
.side .term-arrow.drop-into { outline: none; border-color: var(--accent); color: var(--accent); }

.side-drop,
.tab-drop {
  position: absolute;
  z-index: 3;
  background: var(--accent);
  pointer-events: none;
}

/* the reorder bar: as bright as the tabs' one, in the gap between two rows, as wide as the row */
.side-drop { height: 4px; box-shadow: 0 0 0 1px var(--sheet), 0 0 10px var(--accent); }
.side-drop[hidden],
.tab-drop[hidden] { display: none; }

.tabrow { position: relative; }
/* the reorder bar: 4px, a sheet-coloured ring and a glow (tabs.js sets its place and height) */
.tab-drop { width: 4px; box-shadow: 0 0 0 1px var(--sheet), 0 0 10px var(--accent); }
.tab.dragging { opacity: .65; outline: 1px dashed var(--accent); }
/* [≡] lives in the header on desktop; on a phone the same tab button sits at the left of the file tabs */
.tabrow .side-btn { display: none; flex: none; height: 30px; margin-bottom: 4px; }

@media (max-width: 700px) {
  .tabrow .side-btn { display: block; padding: 0 12px; }
}

/* Touch phones only: the sidebar slides over the page, from under the tab row (side-frame.js sets
   its top) to the page's bottom edge. A narrow desktop window keeps it beside the files. */
.ws { position: relative; }
.splitter { touch-action: none; }
@media (max-width: 700px) {
  .splitter { display: none; }
}
@media (max-width: 700px) and (pointer: coarse) {
  .side {
    position: absolute;
    z-index: 40;
    top: 0;
    bottom: 0;
    left: 0;
    width: 75vw !important;
    box-shadow: 0 8px 28px rgb(0 0 0 / .3);
  }
}
/* a phone held sideways: over half the screen, full height */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  .side {
    position: absolute;
    z-index: 40;
    top: 0 !important;
    bottom: 0;
    left: 0;
    width: 50vw !important;
    box-shadow: 0 8px 28px rgb(0 0 0 / .3);
  }
  .splitter { display: none; }
}

/* while the divider is dragged, the whole page shows the resize cursor and nothing gets selected */
body.resizing,
body.resizing * { cursor: col-resize !important; user-select: none !important; }

/* The bin, one section per terminal: a trunk runs down from bin/ past each terminal's name, and
   each section's files hang off its name */
.side .bin-group { position: relative; display: flex; flex-direction: column; gap: 3px; }
.side .bin-group::before { position: absolute; top: -3px; bottom: -3px; left: 14px; border-left: 1px solid var(--tline); content: ""; pointer-events: none; }
.side .bin-group:last-child::before { bottom: auto; height: 17px; }
.side .bin-term { position: relative; display: flex; align-items: center; gap: 6px; height: 20px; margin: 4px 8px 0 26px; padding: 0 2px 0 0; color: var(--muted); font-size: 11px; line-height: 20px; letter-spacing: .04em; white-space: nowrap; }
.side .bin-term::before { position: absolute; top: 10px; left: -12px; width: 9px; border-top: 1px solid var(--tline); content: ""; pointer-events: none; }
.side .bin-term.here { color: var(--fg); font-weight: 500; }
.side .bin-term .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side .bin-term .n { font-variant-numeric: tabular-nums; }
.side .bin-term .more { visibility: visible; padding: 0 4px; border: none; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.side .row.file.binned.in-term { margin-left: 46px; }

@media (hover: hover) {
  .side .bin-term .more:hover { color: var(--accent); }
}

/* the "new + / select" row and the bin's "empty" line tint on hover, like any row in The System */
@media (hover: hover) {
  .side .row.label:hover,
  .side .row.note:hover { background: var(--tab); }
}
