/* Dark Theme - Fixed App Layout (No Page Scroll) */
:root {
  --bg: #0b0f14;
  --panel: #101824;
  --text: #d7e0ea;
  --muted: #9fb0c0;
  --border: #1d2a3a;
  --accent: #5aa7ff;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui;
  background: var(--bg);
  color: var(--text);
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.appShell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

button {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  background: rgba(255, 255, 255, 0.05);
}

button:active {
  transform: translateY(0.5px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
}

.tab.active {
  background: rgba(90, 167, 255, 0.15);
  border-color: rgba(90, 167, 255, 0.35);
}

.split {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.resizer {
  display: none;
}

/* Mobile switch */
body[data-page="editor"] #viewerPane {
  display: none;
}

body[data-page="viewer"] #editorPane {
  display: none;
}

/* Pane Header - Container for plugin bar and expand button */
.paneHeader {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

/* Plugin UI */
.pluginBar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 1;
  min-width: 0;
}

/* Plugin Icon States - Clean design */
.pluginIcon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pluginIcon:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Active state - vạch ngang ở trên (plugin đang mở) */
.pluginIcon.active::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* Selected state - khung viền (plugin đang chọn) */
.pluginIcon.selected {
  border-color: var(--accent);
}

.pluginIcon.selected:hover {
  background: rgba(90, 167, 255, 0.05);
}

/* Active + Selected (plugin vừa mở vừa chọn) */
.pluginIcon.active.selected {
  border-color: var(--accent);
}

.pluginIcon.active.selected::before {
  background: var(--accent);
}

.expandBtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  display: none;
  flex-shrink: 0;
}

.expandBtn:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Expanded state - nút thu nhỏ với nền xám */
.expandBtn.expanded {
  background: var(--panel);
  border-color: var(--border);
}

.expandBtn.expanded:hover {
  background: rgba(255, 255, 255, 0.08);
}

.documentWrap {
  min-width: 0;
  display: flex;
  justify-content: center;
}

.documentSelect {
  width: 100%;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-weight: 900;
  text-align: center;
  outline: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.documentSelect:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.documentsHost {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.documentRoot {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.documentRoot.active {
  display: flex;
}

.documentRoot .split {
  flex: 1;
  min-height: 0;
}

/* Plugin Host Container */
.pluginHost {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
}

.pluginHost.active {
  display: flex;
  flex-direction: column;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modalOverlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
}

.modalContent {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Mobile: Fullscreen modal */
@media (max-width: 899px) {
  .modalContent {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
  }
  
  .modal {
    align-items: stretch;
    justify-content: stretch;
  }
}

.modalHeader {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modalHeader h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.closeBtn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.closeBtn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.modalBody {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
}

.settingSection {
  margin-bottom: 28px;
}

.settingSection:last-child {
  margin-bottom: 0;
}

.settingSection h3 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.settingBtn {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  margin-bottom: 10px;
}

.settingBtn:hover {
  opacity: 0.9;
}

.settingInfo {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.settingItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}

.settingItem:hover {
  background: rgba(255, 255, 255, 0.03);
}

.settingItem span {
  flex: 1;
  font-size: 14px;
}

.settingItem input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.settingSelect {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

/* Document Path Input */
.documentPathItem {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.documentPathInput {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  outline: none;
}

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

.documentPathInput::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

/* Vault JSON Editor */
.vaultJsonEditor {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  outline: none;
  resize: vertical;
  line-height: 1.5;
}

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

.vaultJsonEditor::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.vaultJsonEditor:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Plugin Placeholder - HIỂN THỊ LUÔN KHI KHÔNG CÓ PLUGIN */
.pluginPlaceholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}