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

:root {
  --bg: #1e1e1e;
  --surface: #252526;
  --border: #3c3c3c;
  --tab-bg: #2d2d2d;
  --tab-active: #1e1e1e;
  --text: #d4d4d4;
  --text-muted: #858585;
  --accent: #569cd6;
  --line-num: #4a4a4a;
  --toolbar: #333333;
  --statusbar: #007acc;
  --icon-filter: invert(1);
}

body.light-mode {
  --bg: #ffffff;
  --surface: #f3f3f3;
  --border: #d0d0d0;
  --tab-bg: #ececec;
  --tab-active: #ffffff;
  --text: #1e1e1e;
  --text-muted: #6e6e6e;
  --accent: #0078d4;
  --line-num: #aaaaaa;
  --toolbar: #dddddd;
  --statusbar: #007acc;
  --icon-filter: none;
}

body {
  font-family: 'Consolas', 'Menlo', 'Monaco', monospace;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Toolbar */
#toolbar {
  background: var(--toolbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  flex-shrink: 0;
}

#toolbar button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s;
}

#toolbar button:hover { background: var(--border); }
#toolbar button.active { background: var(--accent); border-color: var(--accent); color: #1e1e1e; }

#toolbar .sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

#title {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: auto;
}

#font-size-display {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 20px;
  text-align: center;
  user-select: none;
}

#btn-light-mode {
  padding: 2px 6px !important;
  line-height: 0;
}

#btn-light-mode img {
  width: 14px;
  height: 14px;
  display: block;
  opacity: 0.75;
  filter: var(--icon-filter);
}

#btn-light-mode:hover img { opacity: 1; }

#btn-info {
  width: 22px;
  height: 22px;
  border-radius: 50% !important;
  padding: 0 !important;
  font-size: 12px !important;
  font-style: italic;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Tab size segmented control */
.tab-size-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.tab-size-group button {
  border: none !important;
  border-radius: 0 !important;
  border-right: 1px solid var(--border) !important;
}

.tab-size-group button:last-child {
  border-right: none !important;
}

/* Find bar */
#find-bar {
  background: var(--toolbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#find-bar.hidden { display: none; }

#find-bar input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 3px;
  outline: none;
  width: 180px;
}

#find-bar input:focus { border-color: var(--accent); }

#find-count {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 70px;
}

#find-bar button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 3px;
}

#find-bar button:hover { background: var(--border); }

#replace-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

#replace-row.hidden { display: none; }

/* Info modal */
#info-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#info-overlay.open { display: flex; }

#info-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px 28px;
  max-width: 480px;
  width: 90%;
  position: relative;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  max-height: 85vh;
  overflow-y: auto;
}

#info-modal h2 {
  font-size: 15px;
  color: var(--accent);
  margin-bottom: 16px;
  font-style: normal;
}

#info-modal ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#info-modal li {
  display: flex;
  gap: 10px;
}

#info-modal .info-key {
  color: var(--accent);
  min-width: 130px;
  flex-shrink: 0;
}

#info-modal .info-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
}

#info-modal .info-close:hover { color: var(--text); background: var(--border); }

/* Font picker */
#font-picker-wrap { position: relative; }

#font-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 180px;
  z-index: 100;
  display: none;
  padding: 4px 0;
}

#font-dropdown.open { display: block; }

.font-option {
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.font-option:hover { background: var(--border); }

.font-option.active-font::before { content: '✓'; color: var(--accent); font-size: 11px; min-width: 12px; }
.font-option:not(.active-font)::before { content: ''; min-width: 12px; }

#font-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

#font-upload-label {
  display: block;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--accent);
}

#font-upload-label:hover { background: var(--border); }
#font-file-input { display: none; }

/* Tabs */
#tabs-bar {
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  gap: 2px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 14px;
  background: var(--tab-bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-muted);
  position: relative;
  top: 1px;
  transition: color 0.1s;
  user-select: none;
}

.tab.active {
  background: var(--tab-active);
  color: var(--text);
  border-color: var(--border);
  border-bottom-color: var(--tab-active);
}

.tab:hover:not(.active) { color: var(--text); }

.tab .tab-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab .tab-name[contenteditable="true"] {
  outline: none;
  border-bottom: 1px solid var(--accent);
}

.tab .close-btn {
  font-size: 14px;
  line-height: 1;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.1s, background 0.1s;
}

.tab:hover .close-btn,
.tab.active .close-btn { opacity: 1; }
.tab .close-btn:hover { background: #c53030; color: white; }

/* Pinned tabs */
.tab.pinned .close-btn { display: none; }

.tab-pin-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.tab:not(.pinned) .tab-pin-dot { display: none; }

/* Drag reorder */
.tab.drag-over { border-color: var(--accent); opacity: 0.7; }

#new-tab-btn {
  padding: 4px 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 1;
  align-self: center;
  transition: color 0.1s;
}

#new-tab-btn:hover { color: var(--text); }

/* Editor area */
#editor-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

#line-numbers {
  padding: 12px 10px 12px 14px;
  background: var(--bg);
  color: var(--line-num);
  font-size: 14px;
  line-height: 1.6;
  text-align: right;
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
  min-width: 48px;
  border-right: 1px solid var(--border);
  white-space: pre;
}

#line-numbers.hidden { display: none; }

/* Editor wrap: positions editor + highlight overlay */
#editor-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
}

#editor {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 16px;
  border: none;
  outline: none;
  resize: none;
  overflow-y: auto;
  overflow-x: auto;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  position: relative;
  z-index: 1;
}

#editor-highlight-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 16px;
  color: transparent;
  white-space: pre;
  overflow-wrap: normal;
  overflow: hidden;
  tab-size: 4;
  z-index: 2;
  word-break: normal;
}

#editor-highlight-overlay mark {
  background: rgba(255, 200, 0, 0.35);
  color: transparent;
  border-radius: 2px;
}

#editor-highlight-overlay mark.current-match {
  background: rgba(255, 140, 0, 0.6);
}

/* Drop overlay */
#drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(86, 156, 214, 0.15);
  border: 2px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  pointer-events: none;
  z-index: 10;
}

#drop-overlay.visible { display: flex; }

/* Main area wrapper */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Vertical tab bar */
body.vertical-tabs #main-area { flex-direction: row; }

body.vertical-tabs #tabs-bar {
  flex-direction: column;
  align-items: stretch;
  border-bottom: none;
  border-right: 1px solid var(--border);
  padding: 6px 0;
  overflow-y: auto;
  overflow-x: hidden;
  width: 168px;
  flex-shrink: 0;
}

body.vertical-tabs #new-tab-btn {
  align-self: flex-start;
  padding: 6px 14px;
}

body.vertical-tabs .tab {
  border-radius: 0;
  border-left: 2px solid transparent;
  border-right: none;
  border-top: none;
  border-bottom: none;
  top: 0;
  width: 100%;
  padding: 7px 10px 7px 12px;
}

body.vertical-tabs .tab.active {
  border-left-color: var(--accent);
  border-bottom-color: transparent;
  background: var(--tab-active);
}

body.vertical-tabs .tab .tab-name { flex: 1; max-width: none; }

body.vertical-tabs .tab .close-btn { opacity: 0; }

body.vertical-tabs .tab:hover .close-btn,
body.vertical-tabs .tab.active .close-btn { opacity: 1; }

/* Tab context menu */
#tab-context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  z-index: 300;
  padding: 4px 0;
  min-width: 120px;
}

#tab-context-menu.hidden { display: none; }

#tab-context-menu button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 14px;
  cursor: pointer;
  text-align: left;
}

#tab-context-menu button:hover { background: var(--border); }

/* Search all overlay */
#search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#search-overlay.open { display: flex; }

#search-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px 28px;
  max-width: 540px;
  width: 90%;
  position: relative;
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 70vh;
}

#search-modal h2 { font-size: 15px; color: var(--accent); font-style: normal; }

#search-modal .info-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
}

#search-modal .info-close:hover { color: var(--text); background: var(--border); }

#search-all-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 3px;
  outline: none;
}

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

#search-all-results { overflow-y: auto; flex: 1; }

.search-result-group { margin-bottom: 12px; }

.search-result-tab-name {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.search-result-line {
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

.search-result-line:hover { background: var(--border); color: var(--text); }
.search-result-line .line-num { color: var(--line-num); min-width: 30px; flex-shrink: 0; }
.search-result-line .line-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-line .line-text mark { background: rgba(255,200,0,0.4); color: var(--text); border-radius: 1px; }

/* Status bar */
#statusbar {
  background: var(--statusbar);
  color: rgba(255,255,255,0.85);
  font-size: 11px;
  padding: 2px 14px;
  display: flex;
  gap: 16px;
  flex-shrink: 0;
  user-select: none;
}

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; pointer-events: none; }
.toast { background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 12px; padding: 8px 14px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.4); opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; max-width: 300px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.fade-out { opacity: 0; transform: translateY(-4px); }

/* Plugin Manager Modal */
#plugin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
#plugin-overlay.open { display: flex; }

#plugin-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#plugin-modal h2 { font-size: 15px; color: var(--accent); font-style: normal; }

#plugin-modal .info-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
}
#plugin-modal .info-close:hover { color: var(--text); background: var(--border); }

#plugin-list { display: flex; flex-direction: column; gap: 6px; }

.plugin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}
.plugin-row-name { flex: 1; font-size: 13px; }
.plugin-row-status { font-size: 11px; color: var(--text-muted); }
.plugin-row button { font-size: 11px; padding: 2px 8px; }

.plugin-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}
.plugin-toolbar button {
  font-size: 12px;
  padding: 4px 12px;
}

#plugin-guide {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12px;
}
#plugin-guide.hidden { display: none; }
#plugin-guide > p { color: var(--text-muted); line-height: 1.5; }
#plugin-guide code, #plugin-guide kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 11px;
  font-family: inherit;
}

.plugin-api-section { display: flex; flex-direction: column; gap: 4px; }
.plugin-api-heading { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); font-weight: bold; }
.plugin-api-section dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; }
.plugin-api-section dt { color: var(--text); font-family: inherit; white-space: nowrap; }
.plugin-api-section dd { color: var(--text-muted); }

#plugin-editor-section { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
#plugin-editor-section.hidden { display: none; }

#plugin-editor-name {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 3px;
  outline: none;
}
#plugin-editor-name:focus { border-color: var(--accent); }

#plugin-editor-code {
  width: 100%;
  height: 220px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Consolas', 'Menlo', 'Monaco', monospace;
  font-size: 12px;
  padding: 8px;
  border-radius: 3px;
  outline: none;
  tab-size: 2;
}
#plugin-editor-code:focus { border-color: var(--accent); }

.plugin-editor-actions { display: flex; gap: 8px; }
.plugin-editor-actions button { font-size: 12px; padding: 4px 12px; }

/* Command Palette */
#command-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
#command-overlay.open { display: flex; }

#command-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 480px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  overflow: hidden;
}

#command-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 12px 16px;
  outline: none;
}

#command-list { max-height: 300px; overflow-y: auto; }

.command-item {
  padding: 9px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.command-item:hover, .command-item.selected { background: var(--border); }
