/* ==========================================================================
   app.css — the workspace chrome: title bar, docks, tabs, status bar,
   welcome screen, command palette.
   ========================================================================== */

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* the editor pane scrolls, never the page */
}

body {
  background: var(--bg-window);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--ui-size);
  line-height: var(--ui-line);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-ligatures: none; /* TX-02 ligatures are for code, not chrome */
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

:focus-visible {
  outline: 1px solid var(--text-accent);
  outline-offset: -1px;
  border-radius: var(--radius);
}

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

/* Screen-reader-only, for live-region announcements. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Workspace shell ----------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-rows: var(--title-bar-h) minmax(0, 1fr) var(--status-bar-h);
  height: 100dvh;
}

/* Flex, not grid: a hidden dock is `display: none` and would drop out of a
   grid's column flow, pushing the pane into the dock's column. */
.workspace__body {
  display: flex;
  min-height: 0;
}

/* ---- Title bar ----------------------------------------------------------- */

.title-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--bg-window);
  border-bottom: 1px solid var(--border);
  font-size: var(--ui-size-sm);
  color: var(--text-muted);
  user-select: none;
}

.title-bar__project {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: var(--radius);
  color: var(--text);
}
.title-bar__project:hover {
  background: var(--element-hover);
}

.title-bar__spacer {
  flex: 1;
}

/* ---- Docks --------------------------------------------------------------- */

.dock {
  display: flex;
  flex-direction: column;
  flex: none;
  width: var(--dock-w);
  min-width: 0;
  background: var(--bg-panel);
  overflow: hidden;
}

.dock--left {
  border-right: 1px solid var(--border);
}

.dock[hidden] {
  display: none;
}

.dock__header {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--tab-h);
  flex: none;
  padding: 0 10px;
  font-size: var(--ui-size-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-variant);
  user-select: none;
}

.dock__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 0 12px;
}

/* Resize handle on the dock's inner edge, exactly like Zed's. */
.dock__resize {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 5;
}
.dock--left .dock__resize {
  right: -3px;
}
.dock__resize:hover,
.dock__resize[data-dragging] {
  background: var(--border-focused);
}

.dock--left {
  position: relative;
}

/* ---- Panel entries (project tree + outline share this) ------------------- */

.entry {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: var(--row-h);
  padding: 0 10px 0 var(--indent, 10px);
  text-align: left;
  color: var(--text);
  white-space: nowrap;
  user-select: none;
}

.entry:hover {
  background: var(--element-hover);
}

.entry[aria-selected="true"],
.entry[aria-current="true"] {
  background: var(--element-selected);
}

.entry__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The glyph points right; rotate it down when the directory is open. */
.entry__chevron {
  transition: transform 0.12s ease;
}
.entry[aria-expanded="true"] .entry__chevron {
  transform: rotate(90deg);
}

.entry--dir > .entry__label {
  color: var(--text);
}
.entry--file .icon {
  color: var(--text-muted);
}

/* Outline rows indent by heading depth and shade by level, so the document
   structure is legible without drawing tree lines. */
.entry--outline {
  height: 24px;
  font-size: var(--ui-size-sm);
}
.entry--outline[data-depth="1"] {
  color: var(--text);
  font-weight: 600;
}
.entry--outline[data-depth="2"] {
  color: var(--text);
}
.entry--outline[data-depth="3"],
.entry--outline[data-depth="4"],
.entry--outline[data-depth="5"],
.entry--outline[data-depth="6"] {
  color: var(--text-muted);
}

.dock__empty {
  padding: 12px;
  font-size: var(--ui-size-sm);
  color: var(--text-placeholder);
  white-space: pre-wrap;
}

/* ---- Pane (tabs + editor) ------------------------------------------------ */

.pane {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-editor);
}

.tab-bar {
  display: flex;
  align-items: stretch;
  height: var(--tab-h);
  flex: none;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  user-select: none;
}
.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab-bar:empty {
  display: none;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  max-width: 240px;
  font-size: var(--ui-size-sm);
  color: var(--text-muted);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  background: var(--bg-editor);
  color: var(--text);
}

.tab:hover {
  background: var(--element-hover);
}
.tab[aria-selected="true"]:hover {
  background: var(--bg-editor);
}

.tab__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab__close {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  color: var(--text-placeholder);
  opacity: 0;
}
.tab:hover .tab__close,
.tab[aria-selected="true"] .tab__close {
  opacity: 1;
}
.tab__close:hover {
  background: var(--element-active);
  color: var(--text);
}
.tab__close .icon {
  width: 10px;
  height: 10px;
}

/* Breadcrumb toolbar, the strip Zed puts under the tab bar. */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  height: 28px;
  padding: 0 16px;
  font-size: var(--ui-size-sm);
  color: var(--text-muted);
  background: var(--bg-editor);
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}
.breadcrumb:empty {
  display: none;
}
.breadcrumb__sep {
  color: var(--text-placeholder);
}
.breadcrumb__crumb:last-child {
  color: var(--text);
}

.pane__content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

/* ---- Scrollbars: Zed's are thin, translucent, and unobtrusive ------------ */

.dock__body,
.pane__content,
.palette__list {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.dock__body::-webkit-scrollbar,
.pane__content::-webkit-scrollbar,
.palette__list::-webkit-scrollbar {
  width: 12px;
}
.dock__body::-webkit-scrollbar-thumb,
.pane__content::-webkit-scrollbar-thumb,
.palette__list::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border: 4px solid transparent;
  background-clip: content-box;
  border-radius: 6px;
}
.dock__body::-webkit-scrollbar-track,
.pane__content::-webkit-scrollbar-track,
.palette__list::-webkit-scrollbar-track {
  background: transparent;
}

/* ---- Status bar ---------------------------------------------------------- */

.status-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  background: var(--bg-window);
  border-top: 1px solid var(--border);
  font-size: var(--ui-size-sm);
  color: var(--text-muted);
  user-select: none;
}

.status-bar__spacer {
  flex: 1;
}

.status-bar__item {
  padding: 0 6px;
  color: var(--text-muted);
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  border-radius: var(--radius);
  color: var(--text-muted);
}
.icon-btn:hover {
  background: var(--element-hover);
  color: var(--text);
}
.icon-btn[aria-pressed="true"] {
  background: var(--element-active);
  color: var(--text);
}

/* Native tooltip replacement — Zed's little dark-on-light label. */
.icon-btn {
  position: relative;
}
.icon-btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px #5c616626;
  color: var(--text);
  font-size: var(--ui-size-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: 40;
}

/* Status-bar buttons sit at the window edges, where a centred tooltip would
   be clipped. Anchor to the button's near edge instead. */
.status-bar .icon-btn[data-tip]:hover::after {
  left: 0;
  transform: none;
}
.status-bar .icon-btn:last-child[data-tip]:hover::after {
  left: auto;
  right: 0;
}

/* ---- Keybinding chips ---------------------------------------------------- */

.kbd {
  color: var(--text-placeholder);
  font-size: var(--ui-size-sm);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ---- Welcome screen ------------------------------------------------------ */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 40px 24px 80px;
}

.welcome__inner {
  width: 100%;
  max-width: 520px;
}

.welcome__masthead {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 44px;
}

.welcome__mark {
  width: 52px;
  height: 52px;
  flex: none;
  color: var(--text-muted);
}

.welcome__title {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text);
}

.welcome__tagline {
  margin: 2px 0 0;
  font-size: var(--ui-size);
  font-style: italic;
  color: var(--text-muted);
}

.welcome__section {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
  font-size: var(--ui-size-sm);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* The rule that runs from the label to the right edge. */
.welcome__section::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.welcome__section:not(:first-of-type) {
  margin-top: 30px;
}

.welcome__row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
}
.welcome__row:hover {
  background: var(--element-hover);
  text-decoration: none;
}
.welcome__row .icon {
  color: var(--text-muted);
}

.welcome__row-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* "12 min in" style reading-position hint on recent pages. */
.welcome__progress {
  font-size: var(--ui-size-sm);
  color: var(--text-placeholder);
  font-variant-numeric: tabular-nums;
}

/* ---- Command palette ----------------------------------------------------- */

.palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  padding-top: 12vh;
  background: #5c616614;
}
.palette-backdrop[hidden] {
  display: none;
}

.palette {
  width: min(640px, calc(100vw - 32px));
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 40px #5c61662e;
  overflow: hidden;
}

.palette__input {
  flex: none;
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: var(--ui-size);
  color: var(--text);
  background: var(--bg-editor);
  border: 0;
  border-bottom: 1px solid var(--border-variant);
  outline: none;
}
.palette__input::placeholder {
  color: var(--text-placeholder);
}

.palette__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px;
  margin: 0;
  list-style: none;
}

.palette__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 5px 8px;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.palette__item[aria-selected="true"] {
  background: var(--element-selected);
}

.palette__item .icon {
  color: var(--text-muted);
}

.palette__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette__path {
  font-size: var(--ui-size-sm);
  color: var(--text-placeholder);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Fuzzy-match highlight, using Zed's accent. */
.palette__match {
  color: var(--text-accent);
  font-weight: 600;
}

.palette__snippet {
  display: block;
  font-size: var(--ui-size-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette__snippet mark {
  background: var(--search-match);
  color: inherit;
  border-radius: 2px;
}

.palette__empty {
  padding: 14px 12px;
  font-size: var(--ui-size-sm);
  color: var(--text-placeholder);
}

/* ---- Narrow viewports ---------------------------------------------------- */

@media (max-width: 720px) {
  :root {
    --dock-w: 78vw;
  }

  /* The dock overlays the pane rather than squeezing it. */
  .dock--left {
    position: absolute;
    top: var(--title-bar-h);
    bottom: var(--status-bar-h);
    left: 0;
    z-index: 30;
    box-shadow: 0 0 24px #5c616626;
  }

  .workspace__body {
    position: relative;
  }

  .dock__resize {
    display: none;
  }
}
