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

:root {
  --bg: #1e1e2e;
  --surface: #2a2a3d;
  --surface2: #33334d;
  --border: #444466;
  --text: #e0e0f0;
  --text-dim: #9999bb;
  --accent: #7c6ff7;
  --accent-hover: #9588ff;
  --danger: #e05577;
  --success: #55cc88;
  --win-title: #333355;
  --win-title-active: #444477;
  --cell-edit: #3a3a5a;
  --menu-bg: #2a2a44;
  --scrollbar: #555577;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

/* ---- Menubar ---- */
#menubar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 30px;
  user-select: none;
  z-index: 1000;
  position: relative;
}

.menu-item {
  position: relative;
  line-height: 30px;
  cursor: pointer;
  font-size: 12px;
}

.menu-label {
  display: block;
  padding: 0 14px;
}

.menu-item:hover {
  background: var(--surface2);
}

.menu-dropdown {
  display: none;
  position: absolute;
  top: 30px;
  left: 0;
  background: var(--menu-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 260px;
  padding: 4px 0;
  z-index: 1001;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.menu-item.open .menu-dropdown {
  display: block;
}

.menu-dropdown button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 6px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.menu-dropdown button .shortcut {
  color: var(--text-dim);
  font-size: 11px;
  margin-left: 24px;
}

.menu-dropdown button:disabled {
  color: var(--text-dim);
  cursor: default;
}

.menu-dropdown button:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
}

.menu-dropdown button:hover:not(:disabled) .shortcut {
  color: rgba(255,255,255,0.7);
}

.menu-dropdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
.menu-hint {
  display: block;
  padding: 4px 12px;
  color: #888;
  font-size: 12px;
  font-style: italic;
}

button.plugin-entry {
  gap: 6px;
  padding-top: 4px;
  padding-bottom: 4px;
}

.plugin-unload {
  color: var(--text-dim);
  font-size: 11px;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 3px;
}

.plugin-entry:hover .plugin-unload:hover {
  background: var(--danger);
  color: #fff;
}

.plugin-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plugin-popover-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
  line-height: 1.6;
}

.plugin-popover-desc {
  margin-bottom: 8px;
  line-height: 1.4;
}

.plugin-popover-section {
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.plugin-popover-section code {
  background: var(--surface2);
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 11px;
}

.plugin-popover-rules {
  margin-top: 4px;
}

.plugin-popover-rule {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 11px;
}

.plugin-popover-rule code {
  background: var(--surface2);
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 10px;
  word-break: break-all;
}

.plugin-rule-arrow {
  color: var(--text-dim);
  flex-shrink: 0;
}

.plugin-rule-match {
  flex-shrink: 0;
}

.plugin-rule-display {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.plugin-about-buttons {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.plugin-about-unload {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
}

.plugin-about-unload:hover {
  background: var(--danger);
  color: #fff;
}

/* ---- Workspace ---- */
#workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

#window-area {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* ---- Subwindows ---- */
.subwindow {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-width: 280px;
  min-height: 160px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  transition: box-shadow 0.15s;
}

.subwindow.active {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(124,111,247,0.25);
}

.subwindow.minimized {
  display: none;
}

.win-titlebar {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  background: var(--win-title);
  border-radius: 6px 6px 0 0;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.subwindow.active .win-titlebar {
  background: var(--win-title-active);
}

.win-titlebar .win-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

.win-titlebar .win-title .inline-rename,
.dock-tab-title .inline-rename {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  padding: 0 4px;
  border-radius: 3px;
  outline: none;
}

.win-titlebar .win-modified {
  color: var(--danger);
  margin-left: 4px;
}

.win-controls button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 26px;
  text-align: center;
}

.win-controls button:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.win-controls .btn-close:hover {
  background: var(--danger);
  color: #fff;
}

.win-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

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

.win-toolbar input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  flex: 1;
}

.win-toolbar input:focus {
  border-color: var(--accent);
}

.win-toolbar input.filter-error {
  border-color: #c33;
  color: #f99;
}

.win-toolbar label {
  font-size: 11px;
  color: var(--text-dim);
}

.win-toolbar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-family: inherit;
  outline: none;
}

.win-toolbar button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}

.win-toolbar button:hover {
  background: var(--accent);
  border-color: var(--accent);
}

/* ---- Table ---- */
.table-container {
  flex: 1;
  overflow: auto;
}

.table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--bg);
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

.data-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

.data-table.fixed-layout {
  table-layout: fixed;
  min-width: 0;
}

.data-table.fixed-layout th,
.data-table.fixed-layout td {
  max-width: none;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 3px 8px;
  text-align: left;
  white-space: nowrap;
  font-size: 12px;
  max-width: 300px;
}

.data-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th {
  background: var(--surface2);
  position: sticky;
  top: 0;
  z-index: 2;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  transition: background 0.1s;
}

.th-inner {
  display: flex;
  align-items: center;
}

.data-table th:hover {
  background: #3d3d5c;
}

.data-table th.sorted {
  background: #2e2e4a;
  border-bottom: 2px solid var(--accent);
}

.data-table th.sorted:hover {
  background: #3d3d5c;
}

.data-table th .inline-rename {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  padding: 0 4px;
  border-radius: 3px;
  outline: none;
}

.data-table th .sort-arrow {
  margin-left: 4px;
  font-size: 10px;
  line-height: 1;
  color: var(--accent-hover);
}

.data-table th.col-dragging {
  opacity: 0.35;
}

.data-table th.col-drop-left {
  border-left: 2px solid var(--accent-hover);
}

.data-table th.col-drop-right {
  border-right: 2px solid var(--accent-hover);
}

.data-table th.col-selected {
  box-shadow: inset 0 -2px 0 var(--accent-hover);
}

.col-drag-ghost {
  position: fixed;
  transform: translateX(-50%) translateY(-50%);
  background: var(--accent);
  color: var(--text);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100000;
  opacity: 0.9;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.col-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-filter-btn {
  margin-left: 4px;
  padding: 0 3px 0 4px;
  font-size: 14px;
  color: var(--text-dim);
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
  line-height: 1;
  border-radius: 2px;
}

.data-table th:hover .col-filter-btn,
.col-filter-btn.active {
  opacity: 1;
}

.col-filter-btn:hover {
  color: var(--accent-hover);
  background: rgba(124,111,247,0.15);
}

.col-filter-btn.active {
  color: var(--accent);
}

.data-table th.sorted {
  border-left: 2px solid var(--accent);
}

.data-table th.col-filtered {
  border-left: 2px solid var(--success);
}

.data-table th.col-linked {
  border-left: 2px solid #55aadd;
}

.data-table th.col-transformed {
  border-left: 2px solid #dd88cc;
}

.data-table th.sorted.col-filtered {
  border-left: 2px solid var(--success);
  box-shadow: inset 2px 0 0 var(--accent);
}

.data-table th.sorted.col-linked {
  border-left: 2px solid #55aadd;
  box-shadow: inset 2px 0 0 var(--accent);
}

.data-table th.feature-disabled {
  border-left-style: dashed;
  opacity: 0.6;
}

.col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}

.col-resize-handle.col-resize-left {
  right: auto;
  left: -2px;
}

.col-resize-handle:hover,
.col-resize-handle.active {
  background: var(--accent);
  opacity: 0.4;
}

/* ---- AutoFilter Dropdown ---- */
.autofilter-dropdown {
  position: fixed;
  background: var(--menu-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 240px;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  z-index: 3000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  font-size: 12px;
}

.autofilter-search-wrap {
  padding: 8px 8px 4px;
}

.autofilter-search {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}

.autofilter-search:focus {
  border-color: var(--accent);
}

.autofilter-controls {
  padding: 2px 0;
  border-bottom: 1px solid var(--border);
}

.autofilter-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  max-height: 240px;
}

.autofilter-list::-webkit-scrollbar {
  width: 6px;
}

.autofilter-list::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

.autofilter-item,
.autofilter-select-all {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.autofilter-item:hover {
  background: rgba(124,111,247,0.1);
}

.autofilter-select-all {
  font-weight: 600;
  color: var(--text-dim);
}

.autofilter-item input[type="checkbox"],
.autofilter-select-all input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.autofilter-buttons {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}

.autofilter-buttons button {
  padding: 4px 12px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

.autofilter-buttons button.autofilter-apply {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.autofilter-buttons button:hover {
  opacity: 0.85;
}

.data-table th.row-num-header {
  background: var(--surface);
  cursor: pointer;
  color: var(--text-dim);
  text-align: center;
  width: 50px;
  min-width: 30px;
}

.data-table th.row-num-header:hover {
  background: var(--surface2);
}

.data-table td.row-num {
  background: var(--surface);
  color: var(--text-dim);
  text-align: center;
  font-size: 11px;
  user-select: none;
  cursor: pointer;
}

.data-table td.data-cell {
  cursor: cell;
  outline: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.data-table td.data-cell[contenteditable="true"] {
  cursor: text;
  background: var(--cell-edit);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.data-table tbody tr {
  height: 26px;
}

.data-table .virtual-pad td {
  padding: 0;
  border: none;
}

.data-table tr:hover td:not(.row-num) {
  background: rgba(124,111,247,0.06);
}

.data-table td.modified {
  background: rgba(85,204,136,0.1) !important;
}

.data-table tr.row-highlight td:not(.row-num) {
  background: rgba(124,111,247,0.10);
}
.data-table tr.row-highlight td.row-num {
  background: rgba(124,111,247,0.25);
  color: var(--text);
}
.data-table td.col-highlight {
  background: rgba(124,111,247,0.10);
}
.data-table tr.row-highlight td.col-highlight {
  background: rgba(124,111,247,0.20);
}
.data-table th.col-highlight {
  background: rgba(124,111,247,0.25);
}
.data-table td.cell-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.data-table.drag-selecting, .data-table.drag-selecting td {
  user-select: none;
  -webkit-user-select: none;
}

.win-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface2);
  border-radius: 0 0 6px 6px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}


.status-center {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.status-chip {
  cursor: pointer;
  font-size: 10px;
  user-select: none;
  padding: 0 5px;
  border-radius: 3px;
  line-height: 18px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: opacity 0.15s, background 0.15s;
}

.status-chip:hover {
  filter: brightness(1.2);
}

.status-chip-sort {
  color: var(--accent);
  background: rgba(124, 111, 247, 0.15);
}

.status-chip-filter {
  color: var(--success);
  background: rgba(85, 204, 136, 0.15);
}

.status-chip-link {
  color: #55cccc;
  background: rgba(85, 204, 204, 0.15);
}

.status-chip-link-source {
  color: #55aadd;
  background: rgba(85, 170, 221, 0.15);
}

.status-chip-format {
  color: #dd88cc;
  background: rgba(221, 136, 204, 0.15);
}

.status-chip.off {
  opacity: 0.4;
  text-decoration: line-through;
}

.status-chip.off:hover {
  opacity: 0.7;
}

/* ---- Resize handles ---- */
.resize-handle {
  position: absolute;
  z-index: 5;
}

.resize-handle.rh-top {
  top: -3px; left: 10px; right: 10px; height: 6px;
  cursor: ns-resize;
}

.resize-handle.rh-bottom {
  bottom: -3px; left: 10px; right: 10px; height: 6px;
  cursor: ns-resize;
}

.resize-handle.rh-left {
  top: 10px; left: -3px; width: 6px; bottom: 10px;
  cursor: ew-resize;
}

.resize-handle.rh-right {
  top: 10px; right: -3px; width: 6px; bottom: 10px;
  cursor: ew-resize;
}

.resize-handle.rh-tl {
  top: -3px; left: -3px; width: 12px; height: 12px;
  cursor: nwse-resize;
}

.resize-handle.rh-tr {
  top: -3px; right: -3px; width: 12px; height: 12px;
  cursor: nesw-resize;
}

.resize-handle.rh-bl {
  bottom: -3px; left: -3px; width: 12px; height: 12px;
  cursor: nesw-resize;
}

.resize-handle.rh-br {
  bottom: -3px; right: -3px; width: 12px; height: 12px;
  cursor: nwse-resize;
}

/* ---- Snap guides ---- */
.snap-guide { position: absolute; }
.snap-guide-x { width: 1px; top: 0; bottom: 0; background: rgba(0, 150, 255, 0.6); }
.snap-guide-y { height: 1px; left: 0; right: 0; background: rgba(0, 150, 255, 0.6); }

/* ---- Dock Containers ---- */
.dock-container {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-width: 280px;
  min-height: 160px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  transition: box-shadow 0.15s;
}
.dock-container.active {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(124,111,247,0.25);
}
.dock-container.minimized { display: none; }
.dock-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Dock Splits ---- */
.dock-split {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.dock-split-horizontal { flex-direction: row; }
.dock-split-vertical { flex-direction: column; }

.dock-splitter {
  flex-shrink: 0;
  background: var(--border);
  position: relative;
  z-index: 2;
}
.dock-splitter-horizontal { width: 4px; cursor: ew-resize; }
.dock-splitter-vertical { height: 4px; cursor: ns-resize; }
.dock-splitter:hover, .dock-splitter.active { background: var(--accent); }

/* ---- Dock Leaves / Tabs ---- */
.dock-leaf {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 100px;
  min-height: 80px;
}
.dock-leaf-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.dock-tab-bar {
  display: flex;
  align-items: flex-end;
  height: 32px;
  background: var(--win-title);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  user-select: none;
  flex-shrink: 0;
  cursor: grab;
}
.dock-tab-bar::-webkit-scrollbar { display: none; }
.dock-tab-bar::after { content: ''; min-width: 40px; flex-shrink: 0; }

.dock-leaf:first-child > .dock-tab-bar {
  border-radius: 6px 0 0 0;
}
.dock-leaf:last-child > .dock-tab-bar {
  border-radius: 0 6px 0 0;
}
.dock-leaf:only-child > .dock-tab-bar {
  border-radius: 6px 6px 0 0;
}
.dock-root > .dock-leaf > .dock-tab-bar {
  border-radius: 6px 6px 0 0;
}

.dock-container.active .dock-tab-bar { background: var(--win-title-active); }

.dock-tab {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 4px 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  flex: 0 1 auto;
  min-width: 0;
  gap: 4px;
  border-right: 1px solid rgba(255,255,255,0.06);
  margin-top: 4px;
  position: relative;
}
.dock-tab:last-of-type { border-right: none; }

.dock-tab:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

.dock-tab.active {
  color: var(--text);
  background: var(--surface);
  border-radius: 6px 6px 0 0;
  margin-bottom: -1px;
  height: 29px;
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.dock-tab.active:first-of-type { border-left: none; }

.dock-container.active .dock-tab.active {
  border-top-color: var(--accent);
}

.dock-tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.dock-tab-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  width: 18px;
  height: 18px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 18px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
}
.dock-tab:hover .dock-tab-close,
.dock-tab.active .dock-tab-close { opacity: 1; }
.dock-tab-close:hover { background: var(--danger); color: #fff; }
.dock-tab.dock-tab-dragging { opacity: 0.35; cursor: grabbing; }
.dock-tab.dock-tab-drop-left { border-left: 2px solid var(--accent-hover); }
.dock-tab.dock-tab-drop-right { border-right: 2px solid var(--accent-hover); }

.dock-controls {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 10;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 4px;
}
.dock-controls button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 26px;
  text-align: center;
}
.dock-controls button:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}
.dock-controls .btn-close:hover { background: var(--danger); color: #fff; }
.dock-tab-bar.has-controls { padding-right: 84px; }
.dock-tab-bar.single-tab:not(.has-controls) { cursor: default; }
.dock-tab-bar.single-tab:not(.has-controls) .dock-tab { cursor: default; }

/* ---- Dock Drop Overlay ---- */
.dock-drop-overlay {
  position: absolute;
  z-index: 999999;
  pointer-events: none;
}
.dock-drop-zone {
  position: absolute;
  transition: background 0.15s;
}
.dock-drop-zone.active {
  background: rgba(124, 111, 247, 0.2);
}

/* ---- Docked Window (hidden) ---- */
.subwindow.docked { display: none !important; }

/* ---- Console ---- */
#console-panel {
  height: 260px;
  min-height: 60px;
  max-height: 50vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  flex-shrink: 0;
}

#console-resize-handle {
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 9px;
  cursor: ns-resize;
  z-index: 10;
}

#console-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.15s;
}

#console-resize-handle:hover::after {
  background: var(--accent);
}

#console-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 6px 12px 0;
  background: var(--surface2);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

#console-tabs {
  display: flex;
  gap: 2px;
  position: relative;
  z-index: 1;
}

.console-tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  padding: 4px 14px 5px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  position: relative;
}

.console-tab:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

.console-tab.active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--border);
  border-bottom: none;
  margin-bottom: -1px;
  padding-bottom: 6px;
}

.console-tab.active::before,
.console-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 6px;
  height: 6px;
}

.console-tab.active::before {
  left: -6px;
  border-bottom-right-radius: 6px;
  box-shadow: 0 0 0 6px var(--bg);
  background: var(--surface2);
  clip-path: inset(0 0 0 50%);
}

.console-tab.active::after {
  right: -6px;
  border-bottom-left-radius: 6px;
  box-shadow: 0 0 0 6px var(--bg);
  background: var(--surface2);
  clip-path: inset(0 50% 0 0);
}

#console-actions {
  display: flex;
  gap: 6px;
  padding-bottom: 4px;
}

#console-actions button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 2px 12px;
  border-radius: 3px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}

#console-actions button:hover {
  background: var(--accent-hover);
}

#btn-interrupt {
  background: #c33 !important;
}
#btn-interrupt:hover {
  background: #e44 !important;
}

#console-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--border);
}

#sql-highlight-wrap {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
  background: var(--bg);
}

#sql-highlight {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  line-height: normal;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: auto;
  pointer-events: none;
  z-index: 0;
}

#sql-input {
  flex: 1;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  border: none;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  outline: none;
  position: relative;
  z-index: 1;
}

#sql-input::selection {
  background: rgba(124,111,247,0.3);
}

/* SQL syntax highlighting tokens */
.sql-kw  { color: #9588ff; }
.sql-str { color: #55cc88; }
.sql-num { color: #f0c674; }
.sql-cmt { color: #9999bb; font-style: italic; }
.sql-brk { color: #cc99ff; }
.sql-op  { color: #e0e0f0; }

/* Filter input highlight overlay */
.filter-highlight-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.filter-highlight {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 12px;
  line-height: normal;
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  border: 1px solid transparent;
  border-radius: 3px;
}

.filter-highlight-wrap .filter-input {
  position: relative;
  z-index: 1;
  color: transparent !important;
  caret-color: var(--text);
  background: transparent !important;
  width: 100%;
}

.filter-highlight-wrap .filter-input::selection {
  background: rgba(124,111,247,0.3);
}

#console-status {
  padding: 3px 12px;
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

#console-status.error {
  color: var(--danger);
}

#console-status.success {
  color: var(--success);
}

#console-status.working {
  color: var(--accent);
}

#console-status.working::after {
  content: '';
  display: inline-block;
  width: 3px;
  height: 10px;
  background: var(--accent);
  margin-left: 4px;
  vertical-align: middle;
  animation: blink 0.6s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ---- AI Panel ---- */
#ai-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--border);
}

#ai-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#ai-table-label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

#ai-table-select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  padding: 2px 4px;
  border-radius: 3px;
  min-height: 24px;
  max-height: 60px;
  outline: none;
}

#ai-table-select:focus {
  border-color: var(--accent);
}

#ai-settings-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  cursor: pointer;
  line-height: 24px;
  text-align: center;
}

#ai-settings-btn:hover {
  background: var(--surface);
  color: var(--text);
}

#ai-provider-badge {
  font-size: 10px;
  color: var(--text-dim);
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg);
  white-space: nowrap;
}

#ai-response {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

#ai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#ai-input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  outline: none;
  line-height: 1.4;
  overflow-y: auto;
  field-sizing: content;
  min-height: 2lh;
  max-height: 6lh;
}

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

#ai-send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  line-height: 30px;
  text-align: center;
  flex-shrink: 0;
}

#ai-send-btn:hover {
  background: var(--accent-hover);
}

#ai-response::-webkit-scrollbar {
  width: 6px;
}

#ai-response::-webkit-scrollbar-track {
  background: var(--bg);
}

#ai-response::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

.ai-msg {
  margin-bottom: 10px;
}

.ai-msg-user {
  display: flex;
  justify-content: flex-end;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--accent);
  color: #fff;
  padding: 5px 10px;
  border-radius: 10px 10px 2px 10px;
  max-width: 85%;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 12px;
  line-height: 1.5;
}

.ai-msg-ai {
  display: flex;
  justify-content: flex-start;
}

.ai-msg-ai .ai-msg-bubble {
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px 10px 10px 2px;
  max-width: 95%;
  word-wrap: break-word;
  font-size: 12px;
  line-height: 1.6;
}

.ai-msg-ai .ai-msg-bubble strong {
  color: var(--accent-hover);
}

#ai-response pre {
  background: var(--surface);
  padding: 6px 8px;
  border-radius: 4px;
  margin: 4px 0;
  overflow-x: auto;
  font-size: 12px;
}

#ai-response code {
  background: var(--surface);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

/* ---- AI Rich Blocks (charts, tables, PDF) ---- */
#ai-response pre.ai-block-chart,
#ai-response pre.ai-block-table,
#ai-response pre.ai-block-pdf {
  border-left: 3px solid var(--accent);
}

.ai-chart-container {
  background: var(--surface);
  border-radius: 6px;
  padding: 10px;
  margin: 6px 0;
  max-height: 300px;
  position: relative;
}

.ai-chart-container canvas {
  max-height: 280px;
  width: 100% !important;
}

.ai-inline-table {
  border-collapse: collapse;
  margin: 6px 0;
  width: 100%;
  font-size: 12px;
}

.ai-inline-table th,
.ai-inline-table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}

.ai-inline-table th {
  background: var(--surface2);
  color: var(--accent-hover);
  font-weight: 600;
}

.ai-inline-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.03);
}

.ai-inline-table tbody tr:hover {
  background: rgba(124,111,247,0.1);
}

.ai-pdf-download {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 6px 14px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 12px;
  margin: 6px 0;
  cursor: pointer;
}

.ai-pdf-download:hover {
  background: var(--accent-hover);
}

/* ---- AI Image Thumbnails ---- */
#ai-image-strip {
  display: flex;
  gap: 6px;
  padding: 4px 8px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.ai-image-thumb {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  flex-shrink: 0;
}

.ai-image-thumb img {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 2px;
}

.ai-image-name {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-image-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.ai-image-remove:hover {
  color: var(--danger);
}

#ai-body.ai-drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

#ai-response .ai-setup-help {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.8;
}

#ai-response .ai-setup-help code {
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 3px;
}

#ai-response .ai-setup-help a {
  color: var(--accent-hover);
}

/* ---- New Table Dialog ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 20px 12px;
  min-width: 340px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  border-radius: 3px;
  line-height: 26px;
  text-align: center;
}

.modal-close:hover {
  background: var(--danger);
  color: #fff;
}

.modal h3 {
  margin-bottom: 12px;
  font-size: 14px;
}

.modal input,
.modal textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 10px;
  outline: none;
}

.modal input:focus,
.modal textarea:focus {
  border-color: var(--accent);
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-buttons button {
  padding: 6px 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.modal-buttons button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.modal-buttons button:hover {
  opacity: 0.9;
}

/* ---- Context menu for rows ---- */
.context-menu {
  position: fixed;
  background: var(--menu-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 0;
  z-index: 3000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-width: 150px;
}

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

.context-menu button:hover {
  background: var(--accent);
  color: #fff;
}

.context-menu button:disabled {
  color: var(--text-dim);
  cursor: default;
}
.context-menu button:disabled:hover {
  background: none;
  color: var(--text-dim);
}

/* ---- Drop overlay ---- */
#drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(124,111,247,0.15);
  border: 3px dashed var(--accent);
  z-index: 5000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}

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

#drop-hint {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.7;
}

#drop-overlay.shift #drop-label { display: none; }
#drop-overlay.shift #drop-hint { display: none; }
#drop-overlay.shift::after {
  content: 'Drop files here (no headers)';
  font-size: 24px;
  font-weight: 600;
}

/* ---- Help window body ---- */
.help-body {
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  padding: 12px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.help-body::-webkit-scrollbar {
  width: 6px;
}

.help-body::-webkit-scrollbar-track {
  background: var(--bg);
}

.help-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

.help-body h4 {
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--accent-hover);
}

.help-body h4:first-child {
  margin-top: 0;
}

.help-body p {
  margin: 4px 0;
}

.help-body code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.help-body pre {
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 4px;
  margin: 6px 0;
  overflow-x: auto;
  font-size: 12px;
  flex-shrink: 0;
}

.help-body ul,
.help-body dl {
  margin: 4px 0 4px 18px;
}

.help-body li {
  margin: 2px 0;
}

.help-body dt {
  font-weight: 600;
  margin-top: 4px;
}

.help-body dd {
  margin-left: 16px;
}

.help-body table {
  border-collapse: collapse;
  margin: 6px 0;
  width: 100%;
}

.help-body table th,
.help-body table td {
  border: 1px solid var(--border);
  padding: 3px 8px;
  text-align: left;
  font-size: 12px;
}

.help-body table th {
  background: var(--surface2);
}

.help-body .about-text {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
}

body.col-resizing,
body.col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

/* ---- Toast Notifications ---- */
.toast {
  position: fixed;
  right: 12px;
  min-width: 200px;
  max-width: 420px;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: #fff;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: toast-slide-in 0.25s ease-out;
  word-break: break-word;
}

.toast-success {
  background: var(--success);
  color: #1a1a2e;
}

.toast-error {
  background: var(--danger);
}

.toast-fade-out {
  animation: toast-fade-out 0.3s ease-in forwards;
}

@keyframes toast-slide-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-fade-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}
