/* The app frame: rail | sidebar | main | right rail, filling the viewport. */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--side-w) minmax(0, 1fr) var(--right-w);
  /* one row exactly as tall as the window: the columns scroll inside it instead of growing past it */
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app > *,
.doc-scroll,
.side-scroll {
  min-height: 0;
}

.app[data-right="closed"] {
  grid-template-columns: var(--rail-w) var(--side-w) minmax(0, 1fr) 0;
}

.app[data-right="closed"] .rightrail {
  visibility: hidden;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface-2);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: var(--topbar-h);
  padding: 0 var(--sp-5) 0 var(--sp-6);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  flex: 1;
  color: var(--text-3);
  font-size: var(--fs-ui);
}

.crumbs a,
.crumbs span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

.crumbs a:hover {
  color: var(--text);
  text-decoration: none;
}

.crumbs .here {
  color: var(--text);
  font-weight: 500;
}

.crumbs .sep {
  color: var(--line-strong);
  flex: none;
}

.savestate {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--text-3);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.savestate::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}

.savestate[data-state="saving"]::before {
  background: var(--warn);
}

.savestate[data-state="error"]::before {
  background: var(--danger);
}

/* editor | read-only side pane (hidden until opened) */
.panes {
  display: flex;
  flex: 1;
  min-height: 0;
}

.doc-scroll {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.beside {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.app[data-beside] .beside {
  display: flex;
}

.beside-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: 40px;
  padding: 0 var(--sp-3) 0 var(--sp-5);
  border-bottom: 1px solid var(--line);
  color: var(--text-2);
  flex: none;
}

.beside-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.beside-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.beside-doc {
  padding: var(--sp-6) var(--sp-6) var(--sp-9);
}

.beside-body .file-view {
  height: 100%;
  padding: var(--sp-5);
}

/* too narrow for two panes: the side pane takes the main area */
@media (max-width: 1100px) {
  .app[data-beside] .doc-scroll {
    display: none;
  }
}

.doc {
  padding: var(--sp-8) clamp(var(--sp-6), 4vw, var(--sp-9)) var(--sp-9);
}

/* Empty and first-run states inside the main pane. */
.empty {
  display: grid;
  align-content: center;
  justify-items: start;
  gap: var(--sp-5);
  min-height: 60vh;
  padding: var(--sp-8) clamp(var(--sp-6), 6vw, 96px);
}

.empty h1 {
  font-size: var(--fs-h1);
  letter-spacing: -0.02em;
}

.empty p {
  color: var(--text-2);
  font-size: var(--fs-body);
}

.keys {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--sp-4) var(--sp-6);
  margin-top: var(--sp-5);
  color: var(--text-2);
}

.keys dt {
  display: flex;
  gap: var(--sp-2);
}

.keys dd {
  margin: 0;
}

.crumbs .i {
  width: 12px;
  height: 12px;
  flex: none;
  color: var(--text-3);
}

/* Active engagement variables, shown while a set fills copied commands */
.vars-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 280px;
  height: 26px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font: 500 var(--fs-sm) / 1 var(--font-mono);
}

.vars-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vars-chip .i {
  flex: none;
  color: var(--accent);
}

.vars-chip:hover {
  border-color: var(--accent);
}

/* Full pages in the main area (Settings) */
.page-view {
  padding: var(--sp-8) clamp(var(--sp-6), 4vw, var(--sp-9)) var(--sp-9);
}

.settings-page {
  display: grid;
  gap: var(--sp-8);
}

.settings-page .doc-title {
  margin: 0;
}

.set-section {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, 3fr);
  gap: var(--sp-6) var(--sp-8);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--line);
}

.set-section-head h2 {
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-lg, 1.1rem);
}

.set-section-head p {
  margin: 0;
  color: var(--text-3);
  font-size: var(--fs-sm);
}

.set-rows .set-row:first-child {
  padding-top: 0;
}

.set-rows .set-row:last-child {
  border-bottom: 0;
}

@media (max-width: 900px) {
  .set-section {
    grid-template-columns: 1fr;
  }
}
