:root {
  --bg: #f5f3ef;
  --panel: #fffdf8;
  --line: #e2ddd4;
  --ink: #1a1917;
  --muted: #6e665b;
  --accent: #0f6c7a;
  --accent-hover: #0a4f5a;
  --success: #2d8a4e;
  --warn: #b8860b;
  --error: #c0392b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Inter", "IBM Plex Sans", "Segoe UI", sans-serif;
  background: linear-gradient(155deg, #faf6ef, var(--bg));
}

.hidden { display: none !important; }

/* ---------- Eyebrow ---------- */
.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.hero-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(53, 38, 18, 0.08);
  padding: 36px 32px;
}

.hero-card h1 {
  margin: 10px 0 8px;
  font-size: 36px;
  line-height: 1.1;
  font-weight: 700;
}

.hero-card p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.login-message {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid #e6c89a;
  border-radius: var(--radius);
  background: #fff5df;
  color: #6a4d1f;
  font-size: 14px;
  line-height: 1.45;
}

.primary-btn,
.action-btn,
.toolbar-actions button,
.modal-head button,
.modal-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent-hover);
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}

.primary-btn:hover,
.action-btn:hover,
.toolbar-actions button:hover { background: var(--accent-hover); }

.toolbar-actions button:disabled,
.modal-head button:disabled,
.modal-actions button:disabled,
.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Workspace ---------- */
.workspace {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(12px);
}

.topbar-left h1 { margin: 3px 0 0; font-size: 20px; font-weight: 700; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: #f4eee4;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
}

.logout-link {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
}

/* ---------- Tab bar ---------- */
.tab-bar {
  display: flex;
  gap: 4px;
  background: #eae5dc;
  border-radius: var(--radius);
  padding: 3px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

/* ---------- Manage layout ---------- */
.shell {
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 1fr 280px;
}

.sidebar,
.editor-pane,
.history-pane {
  min-height: 0;
  background: rgba(255, 253, 248, 0.88);
}

.sidebar { border-right: 1px solid var(--line); }
.history-pane { border-left: 1px solid var(--line); }

.pane-title {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Search ---------- */
.search-box {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  background: white;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 108, 122, 0.12);
}

.search-results {
  padding: 8px;
  overflow: auto;
  max-height: calc(100vh - 200px);
}

.search-result-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
}

.search-result-item:hover { background: #f0e9dd; }

.search-result-item .sr-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

.search-result-item .sr-path {
  color: var(--muted);
  font-size: 11px;
}

.search-result-item .sr-snippet {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  line-height: 1.35;
}

.search-back {
  display: block;
  padding: 6px 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: none;
  margin-bottom: 4px;
}

/* ---------- Tree ---------- */
.tree {
  padding: 8px;
  overflow: auto;
  height: calc(100vh - 160px);
}

.tree-node {
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}

.tree-node:hover { background: #f0e9dd; }
.tree-node.active { background: #dff2f5; color: #0a4650; }

.tree-children {
  margin-left: 12px;
  padding-left: 8px;
  border-left: 1px dashed #dccfbb;
}

.tree-children.collapsed { display: none; }

/* ---------- Editor toolbar ---------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.meta { min-width: 0; }
#current-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
#current-meta { color: var(--muted); font-size: 12px; }
.toolbar-actions { display: flex; gap: 6px; }

/* ---------- Validation status ---------- */
.validation-status {
  padding: 8px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  line-height: 1.4;
}

.validation-status.pass { background: #eaf7ef; color: var(--success); }
.validation-status.fail { background: #fdecea; color: var(--error); }
.validation-status.warn { background: #fff8e6; color: var(--warn); }

/* ---------- History ---------- */
.history-list {
  padding: 10px;
  overflow: auto;
  height: calc(100vh - 110px);
  font-size: 13px;
  color: var(--muted);
}

.history-item {
  border: 1px solid #eadfcd;
  background: #fffaf2;
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 6px;
}

.history-item .when { font-weight: 600; margin-bottom: 3px; font-size: 12px; }
.history-item .who { color: var(--muted); font-size: 12px; }

/* ---------- Chat layout ---------- */
.chat-shell {
  padding: 32px;
  overflow: auto;
  max-height: calc(100vh - 60px);
}

.chat-container {
  max-width: 720px;
  margin: 0 auto;
}

.chat-query-box h2 {
  font-size: 22px;
  margin: 0 0 14px;
  font-weight: 700;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 108, 122, 0.12);
}

.chat-input-row button {
  border: 1px solid var(--accent-hover);
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.chat-result {
  margin-top: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}

.chat-hit-info {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.chat-hit-info strong { color: var(--ink); }

.chat-summary h3 {
  font-size: 16px;
  margin: 0 0 6px;
  font-weight: 700;
}

.chat-summary .section-line {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.5;
}

.chat-summary ul {
  margin: 0;
  padding-left: 18px;
}

.chat-summary li {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 4px;
}

.chat-no-result {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Customize ---------- */
.customize-section {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
}

.customize-section summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  background: #faf6ef;
}

.customize-form {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.customize-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.customize-form input,
.customize-form button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.customize-form button {
  background: var(--accent);
  color: white;
  border-color: var(--accent-hover);
  font-weight: 600;
  cursor: pointer;
}

.cust-output {
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #fafaf7;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* ---------- Context menu ---------- */
.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 36px rgba(39, 26, 12, 0.14);
  padding: 4px;
}

.context-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

.context-item:hover { background: #f2ebe0; }

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 18, 12, 0.4);
  z-index: 2000;
}

.modal-card {
  width: min(560px, 100%);
  background: white;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 26px 60px rgba(31, 20, 10, 0.2);
}

.modal-card-wide { width: min(680px, 100%); }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 16px; margin: 0; }

.modal-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.modal-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.modal-form input,
.modal-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.ghost-btn {
  background: #f5eee2;
  color: #4d4337;
  border-color: #d8cdba;
}

/* ---------- Check modal body ---------- */
.check-modal-body {
  padding: 16px;
  max-height: 400px;
  overflow: auto;
}

.check-file-row {
  padding: 8px 0;
  border-bottom: 1px solid #f0ebe3;
}

.check-file-row:last-child { border-bottom: none; }

.check-file-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 3px;
}

.check-file-path {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.check-pass { color: var(--success); font-size: 12px; }
.check-error { color: var(--error); font-size: 12px; }
.check-warn { color: var(--warn); font-size: 12px; }

/* ---------- EasyMDE ---------- */
.EasyMDEContainer {
  height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.EasyMDEContainer .CodeMirror,
.EasyMDEContainer .editor-preview {
  flex: 1;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 260px 1fr;
    grid-template-rows: 1fr 220px;
  }
  .history-pane {
    grid-column: 1 / span 2;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .history-list { height: auto; }
}

@media (max-width: 780px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 200px 1fr 180px;
  }
  .sidebar, .editor-pane, .history-pane {
    border: 0;
    border-bottom: 1px solid var(--line);
  }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
