:root {
  /* TDesign-like primitives (approx) */
  --td-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji",
    "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
  --td-font-family-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;

  --td-text-color-primary: rgba(0, 0, 0, 0.9);
  --td-text-color-secondary: rgba(0, 0, 0, 0.6);
  --td-text-color-placeholder: rgba(0, 0, 0, 0.4);

  --td-bg-color-page: #f5f7fa;
  --td-bg-color-container: #ffffff;
  --td-bg-color-container-hover: #f2f3f5;

  --td-border-level-1-color: rgba(0, 0, 0, 0.08);
  --td-border-level-2-color: rgba(0, 0, 0, 0.12);

  --td-brand-color: #0052d9;
  --td-brand-color-hover: #003cab;
  --td-brand-color-active: #002a7c;

  --td-radius-default: 6px;
  --td-shadow-1: 0 2px 6px rgba(0, 0, 0, 0.08);

  --td-space-1: 4px;
  --td-space-2: 8px;
  --td-space-3: 12px;
  --td-space-4: 16px;
  --td-space-5: 24px;

  --sidebar-width: 165px;
  --topbar-height: 56px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--td-font-family);
  color: var(--td-text-color-primary);
  background: var(--td-bg-color-page);
}

.app {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--td-bg-color-container);
  border-right: 1px solid var(--td-border-level-1-color);
  display: flex;
  flex-direction: column;
}

.sidebar__title {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--td-space-4);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--td-border-level-1-color);
}

.sidebar__actions {
  padding: var(--td-space-3) var(--td-space-4);
  border-bottom: 1px solid var(--td-border-level-1-color);
}

.sidebar__list {
  padding: var(--td-space-2);
  overflow-y: auto;
}

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--td-space-2);
  padding: 8px 10px;
  border-radius: var(--td-radius-default);
  cursor: pointer;
  user-select: none;
}

.history-item:hover {
  background: var(--td-bg-color-container-hover);
}

.history-item.is-active {
  background: rgba(0, 82, 217, 0.12);
}

.history-item__title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.history-item__delete {
  opacity: 0;
  pointer-events: none;
}

.history-item:hover .history-item__delete {
  opacity: 1;
  pointer-events: auto;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-height);
  background: var(--td-bg-color-container);
  border-bottom: 1px solid var(--td-border-level-1-color);
  display: flex;
  align-items: center;
  padding: 0 var(--td-space-4);
  justify-content: space-between;
  gap: var(--td-space-4);
}

.topbar__title {
  font-size: 16px;
  font-weight: 600;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--td-space-3);
}

.select select {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--td-radius-default);
  border: 1px solid var(--td-border-level-2-color);
  background: var(--td-bg-color-container);
  color: var(--td-text-color-primary);
  outline: none;
}

.select select:focus {
  border-color: rgba(0, 82, 217, 0.6);
  box-shadow: 0 0 0 3px rgba(0, 82, 217, 0.15);
}

.button {
  height: 32px;
  padding: 0 14px;
  border-radius: var(--td-radius-default);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
}


.button--outline-primary {
  width: 100%;
  background: transparent;
  color: var(--td-brand-color);
  border-color: rgba(0, 82, 217, 0.45);
}

.button--outline-primary:hover {
  background: rgba(0, 82, 217, 0.08);
  border-color: rgba(0, 82, 217, 0.6);
}

.button--outline-primary:active {
  background: rgba(0, 82, 217, 0.14);
  border-color: rgba(0, 82, 217, 0.75);
}

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

.button--primary {
  background: var(--td-brand-color);
  color: #fff;
}

.button--primary:hover {
  background: var(--td-brand-color-hover);
}

.button--primary:active {
  background: var(--td-brand-color-active);
}

.content {
  padding: var(--td-space-4);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--td-space-4);
  align-items: start;
}

.panel {
  background: var(--td-bg-color-container);
  border: 1px solid var(--td-border-level-1-color);
  border-radius: var(--td-radius-default);
  box-shadow: var(--td-shadow-1);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel__header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--td-space-3);
  padding: 10px var(--td-space-4);
  border-bottom: 1px solid var(--td-border-level-1-color);
  background: var(--td-bg-color-container);
}

.panel__title {
  font-size: 14px;
  font-weight: 600;
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--td-radius-default);
  background: transparent;
  color: var(--td-text-color-secondary);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--td-bg-color-container-hover);
  color: var(--td-text-color-primary);
}

.icon-btn:active {
  background: rgba(0, 0, 0, 0.06);
}

.editor {
  display: grid;
  grid-template-columns: 46px 1fr;
}

.editor__stack {
  position: relative;
  min-width: 0;
}

.editor__gutter {
  padding: 10px 0;
  border-right: 1px solid var(--td-border-level-1-color);
  background: #fafafa;
  color: rgba(0, 0, 0, 0.45);
  font-family: var(--td-font-family-mono);
  font-size: 12px;
  line-height: 20px;
  text-align: right;
  overflow: hidden;
}

.editor__gutter .ln {
  height: 20px;
  padding-right: 10px;
}

.editor__gutter .ln.is-active {
  color: rgb(0, 82, 217);
  font-weight: 700;
}

.editor__textarea {
  width: 100%;
  height: 240px;
  min-height: 240px;
  border: 0;
  outline: none;
  resize: none;
  padding: 10px 12px;
  font-family: var(--td-font-family-mono);
  font-size: 12px;
  line-height: 20px;
  background: transparent;
  color: transparent;
  caret-color: var(--td-text-color-primary);
  -webkit-text-fill-color: transparent;
  overflow: hidden;
}

.editor__textarea::placeholder {
  color: var(--td-text-color-placeholder);
  -webkit-text-fill-color: var(--td-text-color-placeholder);
}

.editor__textarea::selection {
  background: rgba(0, 82, 217, 0.2);
}

.editor__highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px 12px;
  overflow: hidden;
  font-family: var(--td-font-family-mono);
  font-size: 12px;
  line-height: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--td-text-color-primary);
  pointer-events: none;
}

.editor__lineHighlight {
  position: absolute;
  left: 0;
  right: 0;
  top: 10px;
  height: 20px;
  background: rgb(255, 240, 237);
  pointer-events: none;
  display: none;
}

.md-h1,
.md-h2,
.md-h3,
.md-h4,
.md-h5,
.md-h6 {
  color: var(--td-brand-color);
  font-weight: 700;
}

.md-codefence,
.md-code {
  color: var(--td-text-color-secondary);
}

.md-inlinecode {
  color: var(--td-text-color-secondary);
}

.md-blockquote {
  color: var(--td-text-color-secondary);
}

.dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.dialog__panel {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--td-bg-color-container);
  border: 1px solid var(--td-border-level-1-color);
  border-radius: var(--td-radius-default);
  box-shadow: var(--td-shadow-1);
  padding: var(--td-space-4);
}

.dialog__title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--td-space-3);
}

.dialog__body {
  display: grid;
  gap: var(--td-space-3);
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--td-brand-color);
  width: 0%;
  transition: width 160ms ease;
}

.dialog__hint {
  font-size: 12px;
  color: var(--td-text-color-secondary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--td-radius-default);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.toast.is-show {
  opacity: 1;
}

@media (max-width: 980px) {
  .split {
    grid-template-columns: 1fr;
  }
}
