@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Syne:wght@400;700;800&display=swap');

/* ── VARIABLES (from DiffPad) ── */
:root {
  --bg-deep:       #0d0f11;
  --bg-panel:      #131619;
  --bg-editor:     #0f1214;
  --bg-header:     #171b1f;
  --bg-gutter:     #151821;
  --border:        #252b33;
  --border-light:  #2e3640;
  --text-main:     #cdd3db;
  --text-dim:      #5a6472;
  --text-label:    #8993a0;
  --accent-cyan:   #3ecfcf;
  --accent-orange: #f0843a;
  --add-bar:       #2ea86e;
  --del-bar:       #d95f5f;
  --mod-bar:       #c9b23a;
  --nav-active:    #1e2630;
  --editor-font-size: 13px;
}

/* ── RESET & BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  overflow: hidden;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

input[type=file] { display: none; }

/* ── APP SHELL ── */
#app {
  display: grid;
  grid-template-rows: 48px 40px 1fr 30px;
  height: 100dvh;
  grid-template-areas:
    "titlebar"
    "toolbar"
    "main"
    "status";
}

/* ── TITLE BAR ── */
#titlebar {
  grid-area: titlebar;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
}

.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.logo-icon {
  width: 24px;
  height: 24px;
  background: var(--accent-cyan);
  border-radius: 4px;
  display: grid;
  place-items: center;
  color: #0d0f11;
}
.logo-icon svg { width: 14px; height: 14px; }

.title-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }

.doc-stats { display: flex; gap: 8px; align-items: center; margin-left: auto; }

.stat-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text-label);
}
.stat-pill .dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--text-dim); }
.stat-pill.words .dot { background: var(--accent-cyan); }
.stat-pill.chars .dot { background: var(--mod-bar); }
.stat-pill.lines .dot { background: var(--add-bar); }
.stat-label { display: inline; }

/* ── TOOLBAR ── */
#toolbar {
  grid-area: toolbar;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 3px;
  overflow-x: auto;
  overflow-y: hidden;
}
#toolbar::-webkit-scrollbar { height: 0; }

.tb-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 3px;
  border: none;
  background: transparent;
  color: var(--text-label);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  transition: all 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-btn:hover { background: rgba(255,255,255,0.06); color: var(--text-main); }
.tb-btn.active { background: var(--nav-active); color: var(--accent-cyan); }
.tb-btn.flash-ok { background: rgba(46,168,110,0.15); color: var(--add-bar); }
.tb-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 3px; flex-shrink: 0; }

.font-toggle {
  margin-left: auto;
  display: flex;
  flex-shrink: 0;
  background: var(--bg-editor);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.view-btn {
  padding: 5px 11px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  transition: all 0.12s;
}
.view-btn:hover { background: var(--nav-active); color: var(--accent-cyan); }

/* ── MAIN ── */
/* Column layout: editor-pane flexes to fill, dupe panel docks at the bottom. */
#main { grid-area: main; display: flex; flex-direction: column; overflow: hidden; padding: 2px; }

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-editor);
  border: 1px solid var(--border);
  position: relative;
  min-height: 0;
}

/* CodeMirror host — fills the pane below the header */
#editor-host {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
#editor-host .cm-editor { height: 100%; }
#editor-host .cm-editor.cm-focused { outline: none; }
#editor-host .cm-scroller { -webkit-overflow-scrolling: touch; }

.pane-header {
  display: flex;
  align-items: center;
  padding: 0 10px;
  height: 34px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-label);
  gap: 8px;
  flex-shrink: 0;
}
.pane-label {
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent-cyan);
  flex-shrink: 0;
}
.pane-filename {
  color: var(--text-main);
  font-size: 11px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  cursor: pointer;
}
.rename-pencil {
  width: 11px; height: 11px;
  margin-left: 6px;
  color: var(--text-dim);
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
}
.pane-filename:hover { color: var(--accent-cyan); }
.pane-filename:hover .rename-pencil { opacity: 1; color: var(--accent-cyan); }
.dirty-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-orange);
  margin-left: 7px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.dirty-dot.on { opacity: 1; }
.pane-enc { color: var(--text-dim); font-size: 10px; flex-shrink: 0; }
.line-count { color: var(--text-dim); font-size: 10px; flex-shrink: 0; white-space: nowrap; }

/* Drag & drop overlay */
.drop-overlay {
  position: absolute;
  inset: 34px 0 0 0;
  z-index: 50;
  background: rgba(62,207,207,0.08);
  border: 2px dashed var(--accent-cyan);
  border-radius: 2px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--accent-cyan);
  font-weight: 700;
  letter-spacing: 1px;
  pointer-events: none;
}
.editor-pane.drag-over .drop-overlay { display: flex; }

/* Loading overlay (large files) — sits above drop-overlay + find-panel */
.load-overlay {
  position: absolute;
  inset: 34px 0 0 0;
  z-index: 60;
  background: rgba(13,15,17,0.82);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.load-overlay.visible { display: flex; }
.load-spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: load-spin 0.7s linear infinite;
}
@keyframes load-spin { to { transform: rotate(360deg); } }
.load-text {
  font-size: 11px;
  color: var(--text-label);
  letter-spacing: 0.5px;
}

/* ── TEXT TOOLS PANEL (find / replace / strip / split) ── */
.find-panel {
  position: absolute;
  top: 40px;
  right: 12px;
  z-index: 40;
  width: min(440px, calc(100% - 24px));
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.55);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.find-panel.hidden { display: none; }

.find-row { display: flex; align-items: center; gap: 5px; }
.find-row-area { align-items: flex-start; }   /* rows with a growing textarea */

.find-field {
  flex: 1;
  min-width: 0;
  background: var(--bg-editor);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-main);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 6px 8px;
  outline: none;
}
.find-field:focus { border-color: var(--accent-cyan); }
.find-field::placeholder { color: var(--text-dim); }

/* Auto-growing multi-line fields (Replace with, Split lines with) */
.find-area {
  resize: none;
  overflow: hidden;
  min-height: 30px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.find-count {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 34px;
  text-align: right;
  flex-shrink: 0;
}

.find-icon, .find-opt, .find-act {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text-label);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  border-radius: 4px;
  transition: all 0.12s;
}
.find-icon {
  width: 26px; height: 26px;
  font-size: 11px;
  display: grid; place-items: center;
}
.find-opt { width: 28px; height: 26px; font-size: 11px; }
.find-act { padding: 0 10px; height: 30px; font-size: 11px; }

.find-icon:hover, .find-opt:hover, .find-act:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-main);
  border-color: var(--border-light);
}
.find-opt.active {
  background: var(--nav-active);
  color: var(--accent-cyan);
  border-color: rgba(62,207,207,0.4);
}
.find-close:hover { color: var(--del-bar); border-color: rgba(217,95,95,0.4); }
.find-count.error { color: var(--del-bar); }

/* Strip / Split rows */
.find-strip, .find-split, .find-sort, .find-upper, .find-join {
  border-top: 1px solid var(--border);
  padding-top: 7px;
  margin-top: 1px;
}
.find-strip, .find-sort, .find-upper, .find-join { flex-wrap: wrap; }   /* let buttons drop below on narrow widths */
.strip-label {
  font-size: 10px;
  color: var(--accent-orange);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  flex-shrink: 0;
  cursor: help;
  padding-top: 8px;      /* align with first line of the field */
}
.strip-field { flex: 0 1 90px; }
.split-field { flex: 1; }

@media (max-width: 700px) {
  .find-panel { right: 8px; top: 38px; width: calc(100% - 16px); }
  .find-field { font-size: 14px; }
}

/* ── DUPLICATE LINES PANEL ── */
.dupe-panel {
  display: none;
  flex-direction: column;
  flex-shrink: 0;
  height: 210px;
  margin-top: 2px;
  border: 1px solid var(--border);
  border-top: 2px solid var(--border-light);
  background: var(--bg-deep);
  overflow: hidden;
}
.dupe-panel.visible { display: flex; }

/* Expanded: panel fills the whole main area (editor hidden) for easy scrolling */
#main.dupe-expanded .editor-pane { display: none; }
#main.dupe-expanded .dupe-panel {
  flex: 1;
  height: auto;
  margin-top: 0;
}
#dupe-expand.active { color: var(--accent-cyan); border-color: rgba(62,207,207,0.4); }

.dupe-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  height: 32px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dupe-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent-orange);
  flex-shrink: 0;
}
.dupe-hint {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dupe-nav, .dupe-opt, .dupe-act, .dupe-close {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text-label);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  border-radius: 4px;
  transition: all 0.12s;
}
.dupe-nav   { width: 26px; height: 26px; font-size: 11px; display: grid; place-items: center; }
.dupe-opt   { height: 26px; padding: 0 8px; font-size: 11px; }
.dupe-act   { height: 26px; padding: 0 10px; font-size: 11px; }
.dupe-close { width: 26px; height: 26px; font-size: 11px; }

.dupe-nav:hover, .dupe-opt:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-main);
  border-color: var(--border-light);
}
.dupe-opt.active {
  background: var(--nav-active);
  color: var(--accent-cyan);
  border-color: rgba(62,207,207,0.4);
}
.dupe-act:hover   { background: rgba(217,95,95,0.12); color: var(--del-bar); border-color: rgba(217,95,95,0.4); }
.dupe-close:hover { color: var(--del-bar); border-color: rgba(217,95,95,0.4); }

.dupe-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.dupe-group {
  border: 1px solid var(--border);
  border-radius: 5px;
  margin-bottom: 6px;
  background: var(--bg-panel);
  overflow: hidden;
}
.dupe-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
}
.dupe-count {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-orange);
  background: rgba(240,132,58,0.14);
  border-radius: 3px;
  padding: 1px 6px;
  flex-shrink: 0;
}
.dupe-text {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-main);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dupe-group-remove {
  flex-shrink: 0;
  font-size: 10px !important;
  padding: 0 8px !important;
  height: 22px !important;
}
.dupe-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 7px 8px;
}
.dupe-chip {
  border: 1px solid var(--border);
  background: rgba(240,132,58,0.10);
  color: var(--accent-orange);
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  border-radius: 3px;
  padding: 3px 8px;
  transition: all 0.12s;
}
.dupe-chip:hover { background: rgba(240,132,58,0.22); border-color: var(--accent-orange); }
.dupe-chip.keep {
  background: rgba(62,207,207,0.10);
  color: var(--accent-cyan);
  border-color: rgba(62,207,207,0.3);
}
.dupe-chip.keep:hover { background: rgba(62,207,207,0.2); border-color: var(--accent-cyan); }

.dupe-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
}

/* ── STATUS BAR ── */
#statusbar {
  grid-area: status;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 14px;
  font-size: 10px;
  color: var(--text-dim);
}
.status-item { display: flex; align-items: center; gap: 5px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-cyan); transition: background 0.15s; }
.status-dot.dirty { background: var(--accent-orange); }
#sel-indicator { margin-left: auto; color: var(--accent-cyan); font-size: 11px; font-weight: 500; }

/* ── MOBILE ── */
@media (max-width: 700px) {
  .stat-label { display: none; }
  .stat-pill { padding: 3px 6px; gap: 3px; }
  .doc-stats { gap: 5px; }
  .pane-enc { display: none; }
  #toolbar { padding: 0 8px; }
  .tb-btn { padding: 5px 8px; }

  .dupe-panel { height: 190px; }
  .dupe-header { overflow-x: auto; }
  .dupe-header::-webkit-scrollbar { height: 0; }
}
