/* Minimal LaTeX editor styles */

:root {
  --bg: #0b0c10;
  --surface: #121419;
  --surface-2: #181b22;
  --border: #252a34;
  --text: #e6e9ef;
  --muted: #a1a7b3;
  --accent: #4f8cff;
  --accent-2: #3da57a;
  --danger: #ff5c6c;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}

#app { height: 100vh; display: flex; flex-direction: column; }

.toolbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.toolbar-left { display: flex; align-items: center; gap: 10px; }

.status { font-size: 12px; color: var(--muted); }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary { border-color: transparent; background: var(--accent); color: white; }
.btn:disabled { opacity: 0.6; cursor: default; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  user-select: none;
}
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.main {
  flex: 1;
  min-height: 0; /* for proper flexbox scrolling */
  display: grid;
  grid-template-columns: 260px 1fr 1fr;
  gap: 0;
}
.main.files-collapsed { grid-template-columns: 0 1fr 1fr; }

.pane { display: flex; flex-direction: column; min-height: 0; }
.pane + .pane { border-left: 1px solid var(--border); }

.pane-header {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Editor */
.files-pane { background: var(--surface-2); overflow: auto; }
.files-toolbar { display:flex; gap:8px; padding:8px 8px; border-bottom:1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 2; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.files-list { list-style: none; margin:0; padding: 6px; font-size: 13px; transition: background 0.15s ease; min-height: 200px; }
/* Use outline instead of border/padding to avoid layout shifts while dragging */
/* Make root drop indicator slimmer and unobtrusive */
.files-list.drag-over-root { background: transparent; outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 6px; }
.file-item, .folder-item { display:flex; align-items:center; justify-content: space-between; gap:8px; padding:6px 8px; border-radius:6px; cursor: pointer; transition: background 0.15s ease; outline: none; }
.file-item:hover, .folder-item:hover { background: rgba(255,255,255,0.04); }
.file-item.active { background: rgba(79,140,255,0.15); }
.file-item.selected, .folder-item.selected { background: rgba(255,255,255,0.08); outline: 1px solid rgba(79,140,255,0.4); }
.file-item.dragging, .folder-item.dragging { opacity: 0.4; }
.folder-item.drag-over { background: rgba(79,140,255,0.25); border: 2px dashed var(--accent); }
.file-path, .folder-path { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.rename-input {
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: inherit;
  padding: 2px 4px;
  outline: none;
  flex: 1;
  min-width: 0;
}
.folder-arrow {
  font-size: 10px;
  display: inline-block;
  width: 12px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease;
  opacity: 0.7;
}
.folder-arrow:hover { opacity: 1; }
.folder-item.collapsed .folder-arrow { transform: rotate(0deg); }
.file-actions { display:flex; gap:6px; flex-shrink: 0; }
.file-actions button { padding:2px 6px; font-size:11px; }
.badge-main { background: var(--accent-2); color:#01220f; padding:0 6px; border-radius:10px; font-size:10px; text-transform: uppercase; }
.hidden { display:none; }
.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
}
.context-menu-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  transition: background 0.15s ease;
}
.context-menu-item:hover {
  background: rgba(255,255,255,0.08);
}
.context-menu-item.danger {
  color: var(--danger);
}
.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.editor-pane { background: var(--surface-2); }

.editor-stack { position: relative; flex: 1; min-height: 0; overflow: hidden; }

.editor-stack #editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.6;
  color: transparent;         /* overlay shows colors */
  caret-color: var(--text);   /* keep caret visible */
  background: transparent;
  overflow: auto;
  white-space: pre;           /* match overlay measurements */
  z-index: 1;
}

.highlight-layer {
  position: absolute;
  top: 0;
  left: 0;
  padding: 14px;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre;           /* keep in sync with textarea */
  pointer-events: none;
  /* Allow horizontal overflow so long lines remain visible when scrolled */
  overflow-y: hidden;
  overflow-x: visible;
  will-change: transform, width, height;
  z-index: 0;
}

/* Word wrap mode */
.editor-stack.wrap #editor,
.editor-stack.wrap .highlight-layer {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Token colors */
.tok-command { color: #79a8ff; }
.tok-env { color: #56d4a2; }
.tok-comment { color: #7fbf7f; }
.tok-math { color: #e6c07b; }
.tok-brace { color: #b8c0cc; }

/* Preview */
.preview-pane { background: var(--surface-2); }

.pdf-preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

.pdf-frame,
.pdf-object {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

.log-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.log-panel > summary {
  cursor: pointer;
  padding: 6px 12px;
  color: var(--muted);
  outline: none;
}
.compile-log {
  margin: 0;
  padding: 10px 12px;
  color: #d0d4dc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

/* Status colors */
.status.is-busy { color: #d6e3ff; }
.status.is-ok { color: #a4e6c8; }
.status.is-error { color: #ffc6cc; }

/* Responsive: stack panes on small widths */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .pane + .pane { border-left: none; border-top: 1px solid var(--border); }
  .pdf-page { width: 100%; }
  .files-pane { display:none; }
}
