/* ==========================================================================
   theEdito — IDE chrome components. One section per UI area; every color
   references a token from index.css (playbook §3 — no hard-coded hex).
   Layout: viewport-filling grid → titlebar / activity+sidebar+main / status.
   ========================================================================== */

/* ---------- App shell grid ---------- */

.shell {
  display: grid;
  grid-template-rows: 38px 1fr 24px;
  height: 100vh;
  height: 100dvh;
}

.shell-mid {
  display: grid;
  grid-template-columns: 48px auto 1fr;
  min-height: 0;
}

/* Pin each child to its column explicitly. This is what actually made the
   sidebar-collapse bug (editor/tabs going blank, not just failing to widen):
   .sidebar has display:none applied when hidden, which removes it from grid
   auto-placement ENTIRELY — with only 2 remaining items (activity bar, main
   column) and no explicit placement, auto-placement packs them into columns
   1 and 2, leaving .main-col stuck in the (now 0-width) middle column while
   column 3 sits empty. Explicit grid-column keeps every child in its own
   column regardless of which siblings are present. */
.shell-mid > .activitybar { grid-column: 1; }
.shell-mid > .sidebar { grid-column: 2; }
.shell-mid > .main-col { grid-column: 3; }

/* The sidebar's own column must be forced to exactly 0 — an "auto" grid
   track doesn't reliably collapse just because its one child becomes
   display:none, so the editor next to it wouldn't actually gain the width.
   Scoped to min-width so it can NEVER win a specificity fight against the
   narrow-screen drawer rules below (body.sidebar-hidden .shell-mid has
   higher specificity than a plain .shell-mid override, so without this
   guard it would keep applying its 3-column value even under 760px,
   racing the drawer layout depending on which selector happens to be more
   specific rather than which one is actually meant for this viewport). */
@media (min-width: 761px) {
  body.sidebar-hidden .shell-mid {
    grid-template-columns: 48px 0 1fr;
  }

  body.sidebar-hidden .sidebar {
    display: none;
  }
}

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

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--titlebar-bg);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.titlebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text-1);
  margin-right: 10px;
  text-decoration: none;
}

.titlebar .brand img {
  width: 22px;
  height: 22px;
  border-radius: 5px;
}

.titlebar .brand .brand-word b {
  color: var(--accent-ink);
  font-weight: 800;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tb-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-1);
}

.tb-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tb-btn.primary {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.tb-btn.primary:hover:not(:disabled) {
  background: var(--accent-dim);
}

.accent-swatch {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 3px var(--border);
}

.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* Titlebar/status-bar "More" overflow buttons — only meaningful on narrow
   screens (see the mobile media query), where they take over for
   .tb-overflow-item/.sb-overflow-item. */
.tb-more,
.sb-more {
  display: none;
}

.tb-spacer {
  flex: 1;
}

.tb-select {
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-1);
  font-size: 0.76rem;
  max-width: 170px;
}

/* Workspace chip — replaces a plain muted text label (issue: unfriendly,
   overlapped other controls on narrow screens) with a proper pill that
   truncates its own name instead of pushing/overlapping its neighbors. */
.ws-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-2);
  font-size: 0.72rem;
  max-width: 220px;
  flex-shrink: 1;
  min-width: 0;
}

.ws-chip:empty {
  display: none;
}

.ws-chip i {
  color: var(--accent-ink);
  flex-shrink: 0;
}

.ws-chip .ws-name {
  color: var(--text-1);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ws-chip .ws-mode {
  flex-shrink: 0;
  opacity: 0.75;
}

/* A small "+" badge overlaid on New File/New Folder icons — reads as
   "create new" at a glance instead of a generic file/folder glyph. */
.ic-add {
  position: relative;
}

.ic-add::after {
  content: "+";
  position: absolute;
  top: 1px;
  right: 2px;
  width: 9px;
  height: 9px;
  line-height: 9px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast-text);
  font-size: 0.6rem;
  font-weight: 800;
  text-align: center;
}

/* Hide button labels (keep icons) when the window gets narrow */
@media (max-width: 900px) {
  .tb-btn .tb-label {
    display: none;
  }

  .ws-chip .ws-mode {
    display: none;
  }
}

/* ---------- Activity bar ---------- */

.activitybar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  background: var(--activity-bg);
  border-right: 1px solid var(--border);
}

.act-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 1.15rem;
  cursor: pointer;
  border-left: 2px solid transparent;
}

.act-btn:hover {
  color: var(--text-1);
}

.act-btn.active {
  color: var(--accent-ink);
  border-left-color: var(--accent);
}

.act-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: relative; /* anchors .sidebar-resizer to this box's right edge */
  display: flex;
  flex-direction: column;
  width: 250px;
  min-width: 170px;
  max-width: 480px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* Full-height drag handle (replaces the native `resize` corner-grab, which
   is easy to miss) — mousedown/mousemove/mouseup wiring is in app.js, which
   also persists the chosen width and re-lays-out the editor as it drags. */
.sidebar-resizer {
  position: absolute;
  top: 0;
  /* Flush with the inside edge, not straddling it — .sidebar has
     overflow:hidden (so the tree/search views can scroll internally
     without spilling out), which silently clips any part of an absolutely
     positioned child that extends past the box's own edge. A handle that
     hangs half outside is invisible to hit-testing for that clipped half. */
  right: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
}

.sidebar-resizer:hover,
.sidebar-resizer.dragging {
  background: var(--accent-dim);
}

.side-view {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.side-view.active {
  display: flex;
}

.side-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.side-header .sh-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 0.82rem;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-1);
}

/* ---------- Explorer tree ---------- */

.tree {
  flex: 1;
  overflow: auto;
  padding: 2px 0 12px;
  user-select: none;
}

.tree-empty {
  padding: 14px 12px;
  color: var(--text-3);
  font-size: 0.78rem;
  line-height: 1.5;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding-right: 8px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-2);
  font-size: 0.82rem;
}

.tree-row:hover {
  background: var(--bg-elevated);
}

.tree-row.selected {
  background: var(--accent-dim);
  color: var(--text-1);
}

.tree-row .tw-chevron {
  width: 14px;
  text-align: center;
  color: var(--text-3);
  font-size: 0.65rem;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

.tree-row.expanded .tw-chevron {
  transform: rotate(90deg);
}

.tree-row .tw-icon {
  width: 15px;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.85rem;
}

.tree-row .tw-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-row.dirty .tw-name::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--warning);
  vertical-align: middle;
}

.tree-row input.tw-edit {
  flex: 1;
  min-width: 0;
  height: 20px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--input-bg);
  color: var(--text-1);
  font-size: 0.8rem;
  padding: 0 4px;
  outline: none;
}

/* file-type icon tints (folders + unrecognized files use FA glyphs) */
.ft-dir  { color: var(--accent-ink); }
.ft-file { color: var(--text-3); }
.ft-img  { color: var(--ft-img); }

/* Materialistic monogram badges for recognized languages — a small colored
   chip with a 1-3 letter code, matching the look of popular file-icon themes,
   with zero extra network requests (no icon font/sprite, just CSS). */
.file-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 2px;
  border-radius: 4px;
  font-size: 0.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.2px;
  flex-shrink: 0;
  font-family: "Inter", sans-serif;
}

.tab .file-badge,
.qo-item .file-badge {
  min-width: 15px;
  height: 15px;
  font-size: 0.48rem;
}

/* Folder rows carrying an unsaved file somewhere inside them get a subtle
   ring dot too — same signal as a tab's dirty dot, one level up the tree. */
.tree-row.has-dirty-descendant > .tw-name::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--text-3);
  vertical-align: middle;
}

/* ---------- History view ---------- */

.hist-list {
  padding: 4px 6px 12px;
}

.hist-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 7px;
}

.hist-row:hover {
  background: var(--bg-elevated);
}

.hist-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.hist-icon {
  color: var(--accent-ink);
  font-size: 0.95rem;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.hist-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.hist-name {
  color: var(--text-1);
  font-size: 0.82rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hist-meta {
  color: var(--text-3);
  font-size: 0.7rem;
}

.hist-lock {
  color: var(--warning);
  font-size: 0.72rem;
  flex-shrink: 0;
  margin-right: 4px;
}

.hist-remove {
  flex-shrink: 0;
  margin-right: 4px;
}

/* ---------- Search view ---------- */

.search-form {
  padding: 4px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-input,
.qo-input {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-1);
  font-size: 0.82rem;
}

.search-input:focus,
.qo-input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-opts {
  display: flex;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--text-2);
}

.search-opts label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.search-results {
  flex: 1;
  overflow: auto;
  font-size: 0.78rem;
}

.sr-file {
  padding: 4px 10px 2px;
  font-weight: 700;
  color: var(--accent-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 2px 10px 2px 20px;
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-hit:hover {
  background: var(--bg-elevated);
  color: var(--text-1);
}

.sr-hit mark {
  background: var(--accent-dim);
  color: var(--accent-ink);
  border-radius: 2px;
  padding: 0 1px;
}

.sr-status {
  padding: 6px 10px;
  color: var(--text-3);
  font-size: 0.74rem;
}

/* ---------- Main column: tabs + editor + problems ---------- */

.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.tabsbar {
  display: flex;
  align-items: stretch;
  background: var(--tabsbar-bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
  min-height: 34px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px 0 12px;
  border-right: 1px solid var(--border-subtle);
  background: var(--tab-bg);
  color: var(--text-2);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.tab .tw-icon {
  font-size: 0.8rem;
}

.tab.active {
  background: var(--tab-active-bg);
  color: var(--text-1);
  box-shadow: inset 0 2px 0 var(--accent);
}

.tab .tab-dirty {
  display: none;
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 2px var(--tab-bg);
}

.tab.active .tab-dirty {
  box-shadow: 0 0 0 2px var(--tab-active-bg);
}

.tab.dirty .tab-dirty {
  display: inline-block;
}

.tab .tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 0.72rem;
}

.tab .tab-close:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

.editor-host {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--editor-bg);
}

#monacoContainer {
  position: absolute;
  inset: 0;
}

/* Welcome / preview overlays sit on the editor surface */
.editor-cover {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: var(--editor-bg);
  display: none;
}

.editor-cover.active {
  display: block;
}

.welcome {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 40px;
}

.welcome .hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 4px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent-ink);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.welcome h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.3px;
  margin: 0 0 8px;
  color: var(--text-1);
}

.welcome .w-sub {
  color: var(--text-2);
  font-size: 0.9rem;
  line-height: 1.55;
  margin: 0 0 22px;
}

.w-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 26px;
}

.w-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-1);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.12s;
}

.w-action:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.w-action i {
  font-size: 1.2rem;
  color: var(--accent-ink);
  width: 22px;
  text-align: center;
}

.w-action .wa-note {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-3);
  margin-top: 2px;
}

.w-keys {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.78rem;
  color: var(--text-2);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 18px;
}

.w-keys kbd {
  font-family: "JetBrains Mono", monospace;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.72rem;
  color: var(--text-1);
}

.w-privacy {
  margin-top: 22px;
  font-size: 0.78rem;
  color: var(--text-3);
}

/* Binary / image preview */
.preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100%;
  padding: 30px;
  text-align: center;
  color: var(--text-2);
}

.preview-wrap img {
  max-width: min(90%, 900px);
  max-height: 70vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    conic-gradient(var(--bg-elevated) 90deg, transparent 90deg 180deg,
      var(--bg-elevated) 180deg 270deg, transparent 270deg) 0 0/16px 16px;
}

/* ---------- Problems panel ---------- */

.problems {
  display: none;
  flex-direction: column;
  height: 180px;
  min-height: 90px;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
}

body.problems-open .problems {
  display: flex;
}

.problems-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-subtle);
}

.problems-list {
  flex: 1;
  overflow: auto;
  font-size: 0.78rem;
}

.pb-file {
  padding: 4px 10px 2px;
  font-weight: 700;
  color: var(--text-1);
}

.pb-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 2px 10px 2px 22px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pb-item:hover {
  background: var(--bg-elevated);
}

.pb-item .pb-sev-error   { color: var(--danger); }
.pb-item .pb-sev-warning { color: var(--warning); }
.pb-item .pb-sev-info    { color: var(--accent-ink); }

.pb-item .pb-loc {
  color: var(--text-3);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
}

.pb-item .pb-source {
  color: var(--text-3);
  font-size: 0.68rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 6px;
}

.problems-empty {
  padding: 10px 12px;
  color: var(--text-3);
  font-size: 0.78rem;
}

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

.statusbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  background: var(--statusbar-bg);
  color: var(--statusbar-text);
  font-size: 0.74rem;
  user-select: none;
  overflow: hidden;
}

.sb-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 100%;
  padding: 0 7px;
  border: none;
  background: transparent;
  color: inherit;
  font-size: inherit;
  white-space: nowrap;
  cursor: default;
}

.sb-item.sb-click {
  cursor: pointer;
}

.sb-item.sb-click:hover {
  background: rgba(255, 255, 255, 0.14);
}

.sb-spacer {
  flex: 1;
}

.sb-muted {
  opacity: 0.75;
}

.sb-unsaved {
  display: none;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.sb-unsaved.show {
  display: inline-flex;
}

/* ---------- Menus (context menu + dropdowns) ---------- */

.menu {
  position: fixed;
  z-index: 1500;
  min-width: 190px;
  max-width: 320px;
  max-height: 70vh;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: none;
}

.menu.open {
  display: block;
}

.menu .menu-label {
  padding: 5px 10px 3px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.menu .menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-1);
  font-size: 0.8rem;
  padding: 6px 10px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

.menu .menu-item:hover {
  background: var(--accent-dim);
  color: var(--accent-ink);
}

.menu .menu-item.danger:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

.menu .menu-item i {
  width: 15px;
  text-align: center;
  font-size: 0.82rem;
}

.menu .menu-item .mi-check {
  margin-left: auto;
  color: var(--accent-ink);
  visibility: hidden;
}

.menu .menu-item.checked .mi-check {
  visibility: visible;
}

.menu .menu-sep {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 6px;
}

.menu .menu-filter {
  width: calc(100% - 8px);
  margin: 4px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-1);
  font-size: 0.78rem;
}

/* ---------- Quick open (Ctrl+P) ---------- */

.qo-overlay {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: none;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
  background: transparent;
}

.qo-overlay.open {
  display: flex;
}

.qo-box {
  width: min(560px, 92vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 8px;
}

.qo-list {
  max-height: 46vh;
  overflow: auto;
  margin-top: 6px;
}

.qo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-1);
  font-size: 0.82rem;
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
}

.qo-item.selected,
.qo-item:hover {
  background: var(--accent-dim);
}

.qo-item .qo-path {
  margin-left: auto;
  color: var(--text-3);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1600;
  background: var(--bg-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.app-modal {
  width: min(560px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}

.app-modal.wide {
  width: min(760px, 94vw);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  font-size: 0.95rem;
}

.modal-body {
  padding: 14px 16px;
  overflow: auto;
  font-size: 0.85rem;
  color: var(--text-2);
  line-height: 1.55;
}

.modal-body h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-1);
  margin: 18px 0 8px;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.btn {
  height: 30px;
  padding: 0 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-1);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast-text);
}

.btn.accent:hover {
  background: var(--accent-hover);
  color: var(--accent-contrast-text);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.about-feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  margin: 10px 0;
  padding: 0;
}

.about-feature-list li {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
}

.about-feature-list li i {
  color: var(--accent-ink);
  margin-right: 7px;
}

.faq-q {
  font-weight: 700;
  color: var(--text-1);
  margin: 12px 0 3px;
}

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  right: 14px;
  bottom: 34px;
  z-index: 1700;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 28px));
}

.toast {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-1);
  max-height: 260px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  animation: toast-in 0.22s ease;
}

.toast > span {
  flex: 1 1 180px;
}

.toast-action {
  flex-shrink: 0;
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent-ink);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.toast-action:hover {
  background: var(--accent);
  color: var(--accent-contrast-text);
}

@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger  { border-left-color: var(--danger); }

.toast .toast-close {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  margin-left: auto;
}

/* ---------- Busy overlay ---------- */

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 1650;
  background: var(--bg-overlay);
  display: none;
  align-items: center;
  justify-content: center;
}

.busy-overlay.active {
  display: flex;
}

.busy-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 22px 30px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-1);
}

.busy-card .spinner-ring {
  width: 34px;
  height: 34px;
  margin: 0 auto 10px;
  border: 3px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: busy-spin 0.9s linear infinite;
}

@keyframes busy-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Narrow screens (tablet/phone) ---------- */

/*
 * Below this width, a 250px in-flow sidebar next to a 48px activity bar
 * would eat almost the entire viewport — so the sidebar switches from a
 * grid COLUMN to an absolutely-positioned DRAWER that floats over the main
 * column instead. The JS is unchanged: it only ever toggles
 * body.sidebar-hidden; everything about what that class means visually is
 * redefined right here. Tapping anywhere in the main column (app.js) closes
 * the drawer, same as any mobile nav drawer.
 */
@media (max-width: 760px) {
  /* Real-device testing (not just a narrow desktop window) found the
     titlebar/statusbar packing 9+ icon-only controls into ~390px with
     nothing but an invisible horizontal scroll to reach the rest — no
     scrollbar, no affordance, so it read as broken/cut-off rather than
     "swipe for more". Below this width, secondary controls collapse into
     a single "More" button (reusing the existing Menu component) instead;
     nothing is ever unreachable, and nothing relies on discovering a
     hidden scroll area. */
  .tb-overflow-item,
  .sb-overflow-item {
    display: none !important;
  }

  .tb-more,
  .sb-more {
    display: inline-flex !important;
  }

  /* Three explicit tracks, not two: .activitybar/.sidebar/.main-col each
     have a hard grid-column: 1/2/3 pin (added to fix the desktop auto-
     placement bug), so a template with only 2 values here left column 3
     — .main-col's own column — with no explicit width at all. Grid then
     auto-generated an implicit 3rd track sized ~0 while column 2 (pinned
     to .sidebar, which is position:absolute here and needs none of it)
     silently soaked up the real "1fr" space instead. That's what was
     squeezing the editor down to a sliver on real phones. The sidebar is
     ALWAYS an overlay at this width regardless of shown/hidden state, so
     its column can just always be 0 — same trick as the desktop
     sidebar-hidden fix, just unconditional here.
   */
  .shell-mid {
    grid-template-columns: 48px 0px 1fr;
    position: relative;
  }

  /* .sidebar's own grid-column: 2 pin (set above, unconditionally) becomes
     actively harmful once .sidebar is also position:absolute here: per the
     CSS Grid spec, an absolutely-positioned item that still has an
     explicit grid-column placement is contained by THAT GRID AREA, not by
     the grid container — so "left: 48px" below was resolving against
     column 2's own left edge (itself at x=48px), landing the drawer at
     x=96 instead of x=48 and pushing ~48px of it off the right edge of a
     phone screen. Falling back to grid-column: auto here restores the
     normal "positioned relative to the nearest positioned ancestor"
     behavior the left/top/bottom values below actually assume. */
  .shell-mid > .sidebar {
    grid-column: auto;
  }

  .sidebar {
    position: absolute;
    left: 48px;
    top: 0;
    bottom: 0;
    z-index: 60;
    width: min(84vw, 320px);
    max-width: 84vw;
    box-shadow: var(--shadow-lg);
    transform: translateX(0);
    transition: transform 0.18s ease;
  }

  body.sidebar-hidden .sidebar {
    display: flex; /* stay in the flex layout so the slide-out can animate */
    /* Must clear its own width AND the 48px left offset — a plain -110%
       (of the sidebar's own width) ignored that offset and left a sliver
       up to ~16-23px wide sitting on screen (overlapping the activity bar)
       instead of fully hiding, which is what real-device testing caught. */
    transform: translateX(calc(-100% - 68px));
  }

  /* The drag-to-resize handle is a desktop affordance — the drawer's width
     is already responsive (min(84vw, 320px)) and there's no "editor next to
     it" to widen on a phone-sized screen. */
  .sidebar-resizer {
    display: none;
  }

  .ws-chip {
    max-width: 140px;
  }

  .welcome {
    padding: 26px 16px;
  }

  .w-keys {
    grid-template-columns: 1fr;
  }

  .problems {
    height: 150px;
  }

  .qo-overlay {
    padding-top: 6vh;
  }

  .app-modal {
    max-height: 92vh;
  }

  /* iOS Safari auto-zooms the whole page in when a focused input's
     computed font-size is under 16px — every text input here was smaller
     than that, so opening search, quick-open, an inline rename, or a
     menu's filter box would suddenly zoom the viewport in, which is
     itself a very plausible reading of "the editor goes off screen". */
  .search-input,
  .qo-input,
  .tree-row input.tw-edit,
  .menu .menu-filter {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: min(88vw, 280px);
  }

  .titlebar .brand-word {
    display: none; /* keep just the mark — labels already hide at 900px */
  }

  .tb-sep {
    display: none;
  }

  .sb-text,
  #sbPosition {
    display: none;
  }

  .about-feature-list {
    grid-template-columns: 1fr;
  }

  .hist-meta {
    display: block;
  }
}
