:root {
  --bg: #1e1e1e;
  --fg: #d4d4d4;
  --cyan: #80e0ff;
  --purple: #b48ead;
  --blue: #3b82f6;
  --white: #ffffff;
  --dim: #6a6a6a;
  --surface: #2a2a2a;
  --border: #3a3a3a;
  --danger: #e06c75;
  --active: #3a3a5a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.toolbar button {
  background: var(--border);
  color: var(--fg);
  border: 1px solid var(--dim);
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}

.toolbar button:hover {
  background: var(--dim);
}

.toolbar button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.toolbar button.active {
  background: var(--active);
  border-color: var(--cyan);
  color: var(--cyan);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--dim);
}

.memory-control {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--dim);
}

.memory-control input[type="range"] {
  width: 120px;
  accent-color: var(--purple);
}

/* --- Search bar --- */
.search-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#search-input {
  flex: 1;
  width: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  border-radius: 3px;
  outline: none;
}

#search-input:focus {
  border-color: var(--cyan);
}

/* Invalid pattern. The border reinforces the message in #result-count; it is
   never the only signal, because colour alone fails WCAG 1.4.1. */
#search-input.invalid,
#search-input.invalid:focus {
  border-color: var(--danger);
}

#result-count.error {
  color: var(--danger);
}

#btn-scope {
  background: var(--border);
  color: var(--fg);
  border: 1px solid var(--dim);
  padding: 8px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  white-space: nowrap;
}

#btn-scope:hover:not(:disabled) {
  background: var(--dim);
}

#btn-scope:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#btn-scope.active {
  background: var(--active);
  border-color: var(--cyan);
  color: var(--cyan);
}

.search-meta {
  display: flex;
  gap: 16px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--dim);
}

/* --- Split Pane Layout --- */
.split-pane {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-left {
  width: 280px;
  min-width: 180px;
  border-right: 1px solid var(--border);
}

.pane-right {
  flex: 1;
  min-width: 200px;
}

.pane-header {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--dim);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

/* --- Draggable Divider --- */
.pane-divider {
  width: 4px;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.15s;
}

.pane-divider:hover,
.pane-divider.dragging {
  background: var(--cyan);
}

/* --- Left Pane: File List --- */
.file-entries {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
}

.file-entry {
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 3px solid transparent;
}

.file-entry:hover {
  background: var(--surface);
}

.file-entry.active {
  background: var(--active);
  border-left-color: var(--cyan);
}

.file-entry-name {
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-entry-count {
  color: var(--purple);
  font-size: 10px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* --- Right Pane: File Preview (vim-styled) --- */
.preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  font-size: 13px;
  line-height: 1.6;
}

.preview-line {
  display: flex;
  padding: 0 12px;
  align-items: flex-start;   /* keep line number pinned to top when content wraps */
}


.preview-line.has-match {
  background: rgba(128, 224, 255, 0.05);
}

.preview-line-number {
  color: var(--purple);
  min-width: 48px;
  text-align: right;
  padding-right: 16px;
  user-select: none;
}

.preview-line-content {
  white-space: pre-wrap;      /* was: pre */
  overflow-wrap: anywhere;    /* break long unbroken tokens (long strings, URLs, minified code) */
  overflow-x: visible;        /* was: auto — no longer needed */
  flex: 1;
}

/* Vim-style tilde for lines beyond EOF */
.preview-line-tilde {
  color: var(--cyan);
  min-width: 48px;
  text-align: right;
  padding-right: 16px;
  user-select: none;
}

.match-highlight {
  color: var(--cyan);
  font-weight: bold;
  text-decoration: underline;
}

/* No highlight mode */
.no-highlight .match-highlight {
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
}

/* Empty state for preview */
.preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--dim);
  font-size: 12px;
}

.file-list-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  line-height: 1.6;
  list-style: none;
}

/* --- Status bar --- */
.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 4px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--dim);
}

.status-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar-container {
  height: 5px;
  background: var(--border);
  width: 120px;
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-container.hidden {
  display: none;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--blue);
  border-radius: 3px;
  transition: width 0.1s ease-out;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  max-width: 400px;
}

.toast.hidden {
  display: none;
}

.toast button {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  font-size: 14px;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* --- Find & Replace panel --- */
.replace-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.replace-bar.hidden {
  display: none;
}

#replace-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
  border-radius: 3px;
  outline: none;
}

#replace-input:focus {
  border-color: var(--cyan);
}

.replace-bar button {
  background: var(--border);
  color: var(--fg);
  border: 1px solid var(--dim);
  padding: 5px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  white-space: nowrap;
}

.replace-bar button:hover {
  background: var(--dim);
}

.replace-bar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.replace-status {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
}

/* --- File state markers (left pane) --- */
.file-entry-state {
  flex-shrink: 0;
  margin-left: 8px;
  font-size: 10px;
  min-width: 10px;
}

.file-entry.state-modified .file-entry-state {
  color: var(--purple);
}

.file-entry.state-accepted .file-entry-state {
  color: #98c379;
}

/* --- Diff view (right pane) --- */
.diff-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.diff-actions button {
  background: var(--border);
  color: var(--fg);
  border: 1px solid var(--dim);
  padding: 2px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
}

.diff-actions button:hover {
  background: var(--dim);
}

.diff-line {
  display: flex;
  padding: 0 12px;
  align-items: flex-start;
}

.diff-line-number {
  color: var(--dim);
  min-width: 48px;
  text-align: right;
  padding-right: 16px;
  user-select: none;
}

.diff-line-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  flex: 1;
}

.diff-line.removed {
  background: rgba(224, 108, 117, 0.12);
}

.diff-line.removed .diff-line-content {
  color: var(--danger);
}

.diff-line.added {
  background: rgba(152, 195, 121, 0.12);
}

.diff-line.added .diff-line-content {
  color: #98c379;
}

/* --- Manual text edit --- */
.edit-area {
  width: 100%;
  height: 100%;
  resize: none;
  background: var(--bg);
  color: var(--fg);
  border: none;
  outline: none;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
}

