.app-layout {
  display: grid;
  grid-template-columns: 220px 1fr 340px;
  grid-template-rows: 38px calc(100vh - 38px);
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease, grid-template-rows 0.25s ease;
}

/* ─── Focus / distraction-free mode ───────────────────────────── */
.app-layout[data-focus='on'] {
  grid-template-columns: 0 1fr 0;
  grid-template-rows: 0 100vh;
}

.app-layout[data-focus='on'] .app-titlebar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 38px;
  overflow: visible;
  border: none;
  border-bottom: 1px solid var(--border);
  z-index: 200;
  transform: translateY(-100%);
  transition: transform 0.2s ease;
}

.app-layout[data-focus='on'] .toolbar {
  display: flex;
  position: fixed;
  top: 38px;
  left: 0;
  right: 0;
  z-index: 199;
  transform: translateY(-100%);
  transition: transform 0.2s ease;
}

.app-layout[data-focus='on'][data-peek='on'] .app-titlebar,
.app-layout[data-focus='on'][data-peek='on'] .toolbar {
  transform: translateY(0);
}

.focus-exit-btn {
  position: fixed;
  top: 10px;
  right: 14px;
  z-index: 9999;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.12;
  transition: opacity 0.2s;
  -webkit-app-region: no-drag;
}

.focus-exit-btn:hover {
  opacity: 0.6;
  color: var(--text-primary);
}

.app-layout[data-sidebar='closed'] {
  grid-template-columns: 0 1fr 340px;
}

.app-layout[data-chat='closed'] {
  grid-template-columns: 220px 1fr 0;
}

.app-layout[data-sidebar='closed'][data-chat='closed'] {
  grid-template-columns: 0 1fr 0;
}

.app-titlebar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
  user-select: none;
  position: relative;
}

.app-titlebar-title {
  font-size: 12px;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ─── Three-segment layout toggle ─────────────────────────────── */
.app-layout-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  -webkit-app-region: no-drag;
}

.app-layout-toggle-seg {
  width: 16px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
}

.app-layout-toggle-seg:hover {
  border-color: var(--text-muted);
}

.app-layout-toggle-seg.active {
  background: var(--text-muted);
  border-color: var(--text-muted);
}

/* Middle segment: wider, non-interactive, always "on" */
.app-layout-toggle-seg--mid {
  width: 22px;
  cursor: default;
  background: var(--text-muted);
  border-color: var(--text-muted);
  opacity: 0.35;
}

/* ─── Right-side controls cluster ─────────────────────────────── */
.app-titlebar-right {
  position: absolute;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-app-region: no-drag;
}

/* ─── Theme toggle button ──────────────────────────────────────── */
.app-titlebar-theme-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  -webkit-app-region: no-drag;
  transition: color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-titlebar-theme-btn:hover {
  color: var(--text-primary);
}

.app-titlebar-theme-btn.active {
  color: var(--accent);
}

.app-titlebar-icon-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* ─── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── Editor area ──────────────────────────────────────────────── */
.editor-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--editor-bg);
}

/* Flex row containing the optional outline panel + the CodeMirror editor */
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* ─── Chat area ────────────────────────────────────────────────── */
.chat-area {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
