﻿:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #0f172a;
  background: #f1f5f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #0f172a;
  --primary-contrast: #ffffff;
  --success: #059669;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
body.resizing-panes { cursor: col-resize; user-select: none; }
body.resizing-editor { cursor: row-resize; user-select: none; }
a { color: inherit; text-decoration: none; }
button, select, textarea { font: inherit; }

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

.brand, .topbar nav, .resume-switcher, .pane-head, .patch-actions { display: flex; align-items: center; }
.brand { gap: 10px; font-weight: 900; }
.brand span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: var(--primary-contrast);
  font-size: 12px;
}
.topbar nav { gap: 8px; }
.resume-switcher {
  min-width: 0;
  flex: 1;
  justify-content: center;
  gap: 8px;
}

.resume-switcher select {
  width: min(260px, 100%);
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-weight: 800;
}

button, .topbar a {
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 13px;
  font-weight: 850;
  cursor: pointer;
}
button:hover, .topbar a:hover { background: var(--surface-muted); }
.primary {
  border-color: var(--primary);
  background: var(--primary) !important;
  color: var(--primary-contrast) !important;
}
button:disabled, a[aria-disabled="true"] { opacity: .55; pointer-events: none; cursor: not-allowed; }

.workspace {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(360px, var(--preview-width, 62.5%)) 8px minmax(360px, 1fr);
  gap: 0;
  background: var(--border);
}

.preview-pane, .editor-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-muted);
}

.editor-pane {
  --code-height: 42%;
  background: var(--surface);
  display: grid;
  grid-template-rows: minmax(160px, var(--code-height)) 8px minmax(220px, 1fr);
  min-height: 0;
}

.pane-divider,
.editor-splitter {
  position: relative;
  z-index: 2;
  background: var(--border);
}

.pane-divider { cursor: col-resize; }
.editor-splitter { cursor: row-resize; }

.pane-divider::before,
.editor-splitter::before {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: var(--border-strong);
  opacity: 0;
}

.pane-divider::before { inset: 0 2px; }
.editor-splitter::before { inset: 2px 0; }

.pane-divider:hover::before,
.pane-divider:focus-visible::before,
.editor-splitter:hover::before,
.editor-splitter:focus-visible::before {
  opacity: 1;
}

.pane-head {
  min-height: 72px;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 18px;
}

.pane-head.compact {
  min-height: 64px;
  padding: 12px 16px;
}

.pane-head h1 { margin: 0; font-size: 18px; line-height: 1.2; }
.pane-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; font-weight: 700; }
.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-actions button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}
#previewBadge {
  border-radius: 8px;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 900;
}

.code-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-muted);
}

.chat-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.chat-body {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.pane-tabs {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 10px;
}

.code-toolbar {
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.pane-tabs button {
  min-height: 30px;
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-contrast);
  padding: 0 12px;
  font-size: 13px;
}

.pane-tabs .tool-button {
  min-width: 30px;
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 0 8px;
  font-weight: 850;
}

.pane-tabs .tool-button:hover {
  background: var(--surface-muted);
}

.pane-tabs .tool-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.pane-tabs .text-tool {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
}

.pane-tabs .italic {
  font-style: italic;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 180px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 40px rgba(15, 23, 42, .18);
  padding: 6px;
}

.context-menu button {
  width: 100%;
  min-height: 32px;
  display: block;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 750;
}

.context-menu button:hover {
  background: var(--surface-muted);
}

.context-menu-divider {
  display: block;
  height: 1px;
  margin: 5px 4px;
  background: var(--border);
}

.pane-tabs span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
}

.code-editor-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  overflow: hidden;
  background: #111827;
  border-top: 1px solid #1f2937;
}

#lineNumbers {
  margin: 0;
  overflow: hidden;
  border-right: 1px solid #263244;
  background: #0b1220;
  color: #64748b;
  padding: 14px 10px 14px 0;
  text-align: right;
  user-select: none;
  font: 12px/1.55 Consolas, "Liberation Mono", monospace;
  white-space: pre;
}

#latexEditor {
  flex: 1;
  min-height: 0;
  border: 0;
  border-radius: 0;
  resize: none;
  background: #111827;
  color: #e5e7eb;
  padding: 14px;
  font: 12px/1.55 Consolas, "Liberation Mono", monospace;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  caret-color: #93c5fd;
}

#latexEditor:focus {
  box-shadow: inset 0 0 0 2px #2563eb;
}

#pdfFrame {
  width: 100%;
  flex: 1;
  border: 0;
  background: #475569;
}
#latexFallback {
  flex: 1;
  margin: 0;
  overflow: auto;
  background: #111827;
  color: #e5e7eb;
  padding: 18px;
  font: 12px/1.55 Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.messages {
  flex: 1;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 16px;
}
.message {
  width: fit-content;
  max-width: 92%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
.message.user { justify-self: end; background: #eff6ff; border-color: #bfdbfe; }
.message.system { color: var(--text-muted); }
.message.error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }

.prompt-form {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 14px;
  background: var(--surface);
}
textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
.prompt-form button { justify-self: end; }

.patch-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 14px;
}
.patch-head {
  display: grid;
  gap: 4px;
  margin-bottom: 9px;
}
.patch-head strong { font-size: 14px; }
.patch-head span { color: var(--text-muted); font-size: 12px; font-weight: 700; }
#patchText { min-height: 210px; font: 12px/1.5 Consolas, "Liberation Mono", monospace; }
.patch-actions { justify-content: flex-end; gap: 8px; margin-top: 10px; }

.editor-pane.chat-minimized {
  grid-template-rows: minmax(0, 1fr) 0 64px;
}

.editor-pane.chat-minimized .editor-splitter,
.editor-pane.chat-minimized .chat-body {
  display: none;
}

.editor-pane.chat-maximized {
  grid-template-rows: 44px 0 minmax(0, 1fr);
}

.editor-pane.chat-maximized .editor-splitter,
.editor-pane.chat-maximized .code-editor-shell {
  display: none;
}

@media (max-width: 900px) {
  .topbar { height: auto; align-items: flex-start; flex-direction: column; padding: 12px; }
  .resume-switcher { width: 100%; display: grid; grid-template-columns: 1fr repeat(2, auto); justify-content: stretch; }
  .resume-switcher select { width: 100%; grid-column: 1 / -1; }
  .topbar nav { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace { height: auto; min-height: calc(100vh - 98px); grid-template-columns: 1fr; }
  .pane-divider, .editor-splitter { display: none; }
  .preview-pane { min-height: 70vh; }
  .editor-pane {
    min-height: 70vh;
    display: flex;
    flex-direction: column;
  }
  .code-panel { min-height: 420px; }
  .chat-panel { min-height: 420px; }
  .editor-pane.chat-minimized .chat-panel { min-height: 64px; }
  .editor-pane.chat-maximized .code-panel { min-height: 44px; }
}
