/* ── File Editor ── */

.file-editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #000;
  overflow: hidden;
}

/* Top toolbar */
.file-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border, #30363d);
  flex-shrink: 0;
  min-height: 48px;
}

.file-editor-btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-dim, #8b949e);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.file-editor-btn-back:active {
  background: rgba(255, 255, 255, 0.06);
}

.file-editor-path {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text, #e6edf3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Menlo', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
}

.file-editor-btn-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border, #30363d);
  background: transparent;
  color: var(--text-dim, #8b949e);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.file-editor-btn-save:disabled {
  opacity: 0.5;
  cursor: default;
}

.file-editor-btn-save.dirty {
  border-color: #238636;
  background: rgba(35, 134, 54, 0.15);
  color: #3fb950;
}

.file-editor-btn-save.dirty:active:not(:disabled) {
  background: rgba(35, 134, 54, 0.3);
}

/* Dirty indicator dot */
.file-editor-dirty-dot {
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3fb950;
  flex-shrink: 0;
}

.file-editor-btn-save.dirty .file-editor-dirty-dot {
  display: block;
}

/* Editor area */
.file-editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.file-editor-textarea {
  flex: 1;
  width: 100%;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: #000;
  color: #e0e0e0;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Menlo', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  -moz-tab-size: 2;
  white-space: pre;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.file-editor-textarea::placeholder {
  color: #484f58;
}

.file-editor-textarea::selection {
  background: rgba(88, 166, 255, 0.3);
}

/* Loading state */
.file-editor-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-dim, #8b949e);
  font-size: 14px;
  gap: 8px;
}

.file-editor-loading .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent, #58a6ff);
  border-radius: 50%;
  animation: fe-spin 0.6s linear infinite;
}

@keyframes fe-spin {
  to { transform: rotate(360deg); }
}

/* Error state */
.file-editor-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px;
  text-align: center;
  gap: 12px;
}

.file-editor-error-icon {
  color: #f85149;
}

.file-editor-error-msg {
  color: var(--text-dim, #8b949e);
  font-size: 14px;
  max-width: 320px;
  word-break: break-word;
}

.file-editor-btn-retry {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--border, #30363d);
  background: transparent;
  color: var(--accent, #58a6ff);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.file-editor-btn-retry:active {
  background: rgba(88, 166, 255, 0.1);
}

/* Status bar */
.file-editor-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border, #30363d);
  font-size: 11px;
  color: var(--text-dim, #8b949e);
  flex-shrink: 0;
  min-height: 28px;
}

.file-editor-status-size {
  opacity: 0.7;
}

.file-editor-status-saved {
  color: #3fb950;
  opacity: 0;
  transition: opacity 0.3s;
}

.file-editor-status-saved.visible {
  opacity: 1;
}

/* Conflict dialog */
.file-editor-conflict {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}

.file-editor-conflict-card {
  background: var(--surface, #161b22);
  border: 1px solid var(--border, #30363d);
  border-radius: 12px;
  padding: 20px;
  max-width: 340px;
  width: 100%;
}

.file-editor-conflict-title {
  font-size: 15px;
  font-weight: 600;
  color: #f0883e;
  margin-bottom: 8px;
}

.file-editor-conflict-msg {
  font-size: 13px;
  color: var(--text-dim, #8b949e);
  margin-bottom: 16px;
  line-height: 1.5;
}

.file-editor-conflict-actions {
  display: flex;
  gap: 8px;
}

.file-editor-conflict-actions button {
  flex: 1;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border, #30363d);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.file-editor-conflict-btn-reload {
  color: var(--accent, #58a6ff);
  border-color: var(--accent, #58a6ff) !important;
}

.file-editor-conflict-btn-reload:active {
  background: rgba(88, 166, 255, 0.1);
}

.file-editor-conflict-btn-overwrite {
  color: #f0883e;
  border-color: #f0883e !important;
}

.file-editor-conflict-btn-overwrite:active {
  background: rgba(240, 136, 62, 0.1);
}

.file-editor-conflict-btn-cancel {
  color: var(--text-dim, #8b949e);
}

.file-editor-conflict-btn-cancel:active {
  background: rgba(255, 255, 255, 0.06);
}

/* Find + Download buttons in toolbar */
.file-editor-btn-find,
.file-editor-btn-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-dim, #8b949e);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.file-editor-btn-find:active,
.file-editor-btn-download:active {
  background: rgba(255, 255, 255, 0.06);
}

/* Find bar */
.fe-find-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border, #30363d);
  background: var(--surface, #0d1117);
  flex-shrink: 0;
}

.fe-find-input-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border, #30363d);
  border-radius: 6px;
  padding: 0 8px;
  gap: 6px;
  color: var(--text-dim, #8b949e);
}

.fe-find-input-wrap:focus-within {
  border-color: var(--accent, #58a6ff);
}

.fe-find-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text, #e6edf3);
  font-size: 13px;
  font-family: 'Menlo', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
  padding: 6px 0;
  height: 32px;
}

.fe-find-input::placeholder {
  color: var(--text-dim, #484f58);
}

.fe-find-count {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dim, #8b949e);
  white-space: nowrap;
}

.fe-find-count.no-match {
  color: #f85149;
}

.fe-find-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-dim, #8b949e);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.fe-find-btn:active {
  background: rgba(255, 255, 255, 0.06);
}

/* ── Media Preview ── */

.file-editor-media-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  background: #000;
}

.file-editor-media-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  /* Allow pinch-to-zoom on mobile */
  touch-action: pinch-zoom;
}

.file-editor-media-video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  background: #000;
}

.file-editor-media-audio-wrap {
  gap: 24px;
}

.file-editor-media-audio-icon {
  color: var(--text-dim, #8b949e);
  opacity: 0.5;
}

.file-editor-media-audio {
  width: 100%;
  max-width: 400px;
}

.file-editor-media-pdf {
  width: 100%;
  flex: 1;
  border: none;
  border-radius: 4px;
  background: #1a1a1a;
  min-height: 300px;
}

.file-editor-media-pdf-fallback {
  margin-top: 12px;
  text-align: center;
}

.file-editor-media-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 8px;
  border: 1px solid var(--accent, #58a6ff);
  color: var(--accent, #58a6ff);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.file-editor-media-download:active {
  background: rgba(88, 166, 255, 0.1);
}

/* ── Desktop Split Panel ── */

/* Hidden by default on all viewports */
.fe-split-panel {
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: #000;
  min-width: 0;
}

.fe-split-divider {
  display: none;
}

@media (min-width: 768px) {
  /* When split is active: wrapper becomes a row */
  #view-session-wrapper.fe-split-active {
    flex-direction: row !important;
  }

  /* Show the panel */
  #view-session-wrapper.fe-split-active .fe-split-panel {
    display: flex;
    width: var(--fe-split-width, 50%);
    min-width: 280px;
    max-width: 60%;
    flex-shrink: 0;
    border-right: none; /* divider provides the border */
  }

  /* The resizable divider strip */
  #view-session-wrapper.fe-split-active .fe-split-divider {
    display: block;
    width: 4px;
    min-width: 4px;
    flex-shrink: 0;
    background: var(--border, #30363d);
    cursor: col-resize;
    transition: background 0.15s;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    z-index: 1;
  }

  .fe-split-divider:hover,
  .fe-split-divider.dragging {
    background: var(--accent, #58a6ff);
  }

  /* Session takes the remaining space */
  #view-session-wrapper.fe-split-active #view-session {
    flex: 1 1 0;
    min-width: 280px;
  }

  /* Embedded close button (replaces back chevron label on desktop split) */
  .fe-split-panel .file-editor-btn-back {
    /* Keep existing styles; label comes from aria-label */
  }
}
