:root {
  --bg: #f7f4ef;
  --bg-card: #fffdf9;
  --bg-soft: #f2ede4;
  --line: #dfd5c5;
  --text: #2b2620;
  --text-soft: #6b6156;
  --accent: #d75a2b;
  --accent-soft: #f4b07a;
  --user: #f8efe5;
  --assistant: #fff;
  --shadow: 0 10px 30px rgba(58, 38, 15, 0.08);
}

* {
  box-sizing: border-box;
}

/* Global scrollbar override: keep only rounded thumb */
* {
  scrollbar-width: thin;
  scrollbar-color: #cf8d62 transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  -webkit-appearance: none;
}

*::-webkit-scrollbar-track {
  background: transparent !important;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #e49d6f, #cf8d62);
  border-radius: 9999px;
  min-height: 36px;
  -webkit-appearance: none;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #dd8f5c, #c7774a);
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Noto Sans SC", sans-serif;
  background: radial-gradient(circle at 20% 0%, #f3e0c8, transparent 35%),
    radial-gradient(circle at 80% 100%, #ead4c0, transparent 35%), var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.pseudo-scrollbar-dragging {
  user-select: none;
}

.pseudo-scroll-host {
  position: relative;
}

.custom-scroll-target {
  scrollbar-width: none !important;
  -ms-overflow-style: none;
}

.custom-scroll-target::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}

.pseudo-scrollbar {
  position: absolute;
  top: 6px;
  bottom: 6px;
  right: 2px;
  width: 8px;
  border-radius: 999px;
  background: rgba(171, 125, 85, 0.12);
  z-index: 5;
}

.pseudo-scrollbar.hidden {
  display: none;
}

.pseudo-scrollbar-thumb {
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg, #e49d6f, #cf8d62);
  min-height: 30px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(66, 45, 20, 0.18);
}

.pseudo-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #dd8f5c, #c7774a);
}

.bg-glow {
  position: fixed;
  border-radius: 999px;
  filter: blur(46px);
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  width: 220px;
  height: 220px;
  background: rgba(230, 123, 63, 0.14);
  top: 40px;
  left: 30px;
}

.bg-glow-2 {
  width: 300px;
  height: 300px;
  background: rgba(116, 82, 52, 0.1);
  right: 40px;
  bottom: 20px;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 220px var(--left-pane-width, 520px) 12px minmax(0, 1fr);
  gap: 8px;
  height: 100vh;
  padding: 16px;
}

.history-panel {
  min-width: 0;
}

.history-header {
  border-bottom: 1px solid rgba(162, 130, 91, 0.15);
}

.history-list {
  overflow: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  scrollbar-width: thin;
  scrollbar-color: #cf8d62 transparent;
}

.history-scroll-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.history-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  -webkit-appearance: none;
}

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #e49d6f, #cf8d62);
  border-radius: 9999px;
  min-height: 36px;
  -webkit-appearance: none;
}

.history-list::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #dd8f5c, #c7774a);
}

.history-list::-webkit-scrollbar-button {
  display: none !important;
  width: 0;
  height: 0;
  -webkit-appearance: none;
}

.history-list::-webkit-scrollbar-button:single-button,
.history-list::-webkit-scrollbar-button:double-button,
.history-list::-webkit-scrollbar-corner,
.history-list::-webkit-scrollbar-track-piece {
  display: none !important;
  background: transparent;
}

.history-item {
  border: 1px solid rgba(162, 130, 91, 0.24);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.92);
  padding: 10px;
  cursor: pointer;
}

.history-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(215, 90, 43, 0.16);
}

.history-item-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.history-item-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-soft);
}

.history-item-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.history-delete-btn {
  border: 1px solid rgba(162, 130, 91, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #8c3d1f;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
}

.history-empty {
  color: var(--text-soft);
  font-size: 12px;
  padding: 8px;
}

.pane-resizer {
  border-radius: 10px;
  background: linear-gradient(
    180deg,
    rgba(162, 130, 91, 0.18),
    rgba(162, 130, 91, 0.08)
  );
  cursor: col-resize;
  position: relative;
}

.pane-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 52px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(125, 94, 63, 0.45);
}

body.resizing-columns {
  user-select: none;
  cursor: col-resize;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(255, 251, 244, 0.98));
  border: 1px solid rgba(162, 130, 91, 0.2);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(162, 130, 91, 0.15);
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 13px;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}

.chat-tools {
  display: inline-flex;
  gap: 8px;
}

.api-config-panel {
  margin: 12px 14px 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(162, 130, 91, 0.2);
  background: rgba(255, 252, 245, 0.9);
}

.api-config-panel.hidden {
  display: none;
}

.api-config-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.api-config-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--text-soft);
}

.api-config-grid input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fffefa;
}

.api-config-actions {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-config-status {
  font-size: 12px;
  color: var(--text-soft);
}

.selected-hint {
  margin: 12px 14px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  color: var(--text-soft);
  font-size: 13px;
}

.chat-list {
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  scrollbar-width: thin;
  scrollbar-color: #cf8d62 transparent;
}

.chat-scroll-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  -webkit-appearance: none;
}

.chat-list::-webkit-scrollbar-track {
  background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #e49d6f, #cf8d62);
  border-radius: 9999px;
  min-height: 36px;
  -webkit-appearance: none;
}

.chat-list::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #dd8f5c, #c7774a);
}

.chat-list::-webkit-scrollbar-button {
  display: none !important;
  width: 0;
  height: 0;
  -webkit-appearance: none;
}

.chat-list::-webkit-scrollbar-button:single-button,
.chat-list::-webkit-scrollbar-button:double-button,
.chat-list::-webkit-scrollbar-corner,
.chat-list::-webkit-scrollbar-track-piece {
  display: none !important;
  background: transparent;
}

.msg {
  border: 1px solid rgba(162, 130, 91, 0.2);
  border-radius: 14px;
  padding: 12px;
  animation: fade-up 0.24s ease;
}

.msg.user {
  background: var(--user);
}

.msg.assistant {
  background: var(--assistant);
}

.msg .tag {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.msg .content {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14px;
}

.msg .content.markdown {
  white-space: normal;
}

.msg .content.markdown p {
  margin: 0 0 10px;
}

.msg .content.markdown p:last-child {
  margin-bottom: 0;
}

.msg .content.markdown h1,
.msg .content.markdown h2,
.msg .content.markdown h3,
.msg .content.markdown h4 {
  margin: 8px 0 8px;
  line-height: 1.35;
}

.msg .content.markdown ul,
.msg .content.markdown ol {
  margin: 8px 0 10px 20px;
  padding: 0;
}

.msg .content.markdown li {
  margin: 4px 0;
}

.msg .content.markdown blockquote {
  margin: 10px 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(215, 90, 43, 0.6);
  background: rgba(215, 90, 43, 0.06);
  border-radius: 8px;
}

.msg .content.markdown code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  background: #f2ece3;
  padding: 2px 5px;
  border-radius: 6px;
}

.msg .content.markdown pre {
  background: #2b2620;
  color: #f7f4ef;
  padding: 10px;
  border-radius: 10px;
  overflow: auto;
  margin: 10px 0;
}

.msg .content.markdown pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.msg .content.markdown a {
  color: #a6401c;
}

.chat-form {
  padding: 12px;
  border-top: 1px solid rgba(162, 130, 91, 0.15);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.input-scroll-wrap {
  position: relative;
  min-width: 0;
}

.chat-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  resize: none;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: #fffefa;
}

.chat-form textarea::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}

.chat-form button {
  border: none;
  border-radius: 12px;
  padding: 0 18px;
  background: linear-gradient(180deg, #e6743f, #d75a2b);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.tree-panel {
  min-width: 0;
}

.tree-header {
  border-bottom: 1px solid rgba(162, 130, 91, 0.15);
}

.zoom-tools {
  display: inline-flex;
  gap: 6px;
}

.zoom-tools .ghost-btn {
  min-width: 44px;
  padding: 7px 10px;
}

.tree-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  background: #faf6ef;
}

.tree-viewport.is-panning {
  cursor: grabbing;
}

.tree-canvas {
  position: absolute;
  left: 0;
  top: 0;
  --zoom: 1;
  --cam-x: 0px;
  --cam-y: 0px;
  transform: translate(var(--cam-x), var(--cam-y)) scale(var(--zoom));
  transform-origin: top left;
}

.tree-grid {
  position: absolute;
  left: -200000px;
  top: -200000px;
  width: 400000px;
  height: 400000px;
  background: repeating-linear-gradient(
      0deg,
      rgba(190, 161, 129, 0.07),
      rgba(190, 161, 129, 0.07) 1px,
      transparent 1px,
      transparent 28px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(190, 161, 129, 0.07),
      rgba(190, 161, 129, 0.07) 1px,
      transparent 1px,
      transparent 28px
    );
  pointer-events: none;
}

.tree-edges {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

.tree-nodes {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 0;
  min-height: 0;
  padding: 0;
}

.tree-node {
  position: absolute;
  width: 220px;
  background: rgba(255, 254, 250, 0.96);
  border: 1px solid rgba(162, 130, 91, 0.26);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 6px 14px rgba(66, 45, 20, 0.08);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.node-delete {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 20px;
  height: 20px;
  border: 1px solid rgba(162, 130, 91, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #8c3d1f;
  cursor: pointer;
  font-size: 13px;
  line-height: 16px;
  padding: 0;
}

.node-delete:hover {
  background: rgba(232, 91, 53, 0.12);
  border-color: rgba(215, 90, 43, 0.58);
}

.tree-node:active {
  cursor: grabbing;
}

.tree-node:hover {
  border-color: rgba(215, 90, 43, 0.52);
  box-shadow: 0 8px 16px rgba(66, 45, 20, 0.12);
}

.tree-node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(215, 90, 43, 0.2);
}

.tree-node .meta {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.tree-node .q {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
}

.tree-node .a {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.45;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .pane-resizer {
    display: none;
  }

  .panel {
    min-height: 48vh;
  }
}

/* Chromium fallback: force-hide scrollbar arrow buttons globally */
*::-webkit-scrollbar-button,
*::-webkit-scrollbar-button:single-button,
*::-webkit-scrollbar-button:double-button {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none;
}
