:root {
  --bg: #1f2329;
  --panel: #272c33;
  --panel-alt: #2d333b;
  --panel-soft: #343b45;
  --line: #3d4652;
  --text: #d8dee9;
  --muted: #8b99ad;
  --accent: #ff9800;
  --accent-soft: rgba(255, 152, 0, 0.18);
  --danger: #ff6b6b;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 152, 0, 0.08), transparent 30%),
    linear-gradient(160deg, #161a1f 0%, #1b2026 50%, #15191e 100%);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "PingFang SC", sans-serif;
}

body {
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, var(--sidebar-width, 280px)) 12px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar,
.editor-panel,
.preview-panel {
  backdrop-filter: blur(16px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: rgba(31, 35, 41, 0.92);
  border-right: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  overflow: visible;
  position: relative;
  z-index: 30;
}

.sidebar-resizer,
.panel-resizer {
  position: relative;
  cursor: col-resize;
  background:
    linear-gradient(180deg, transparent, rgba(255, 152, 0, 0.2), transparent),
    #242931;
  border-left: 1px solid rgba(255, 255, 255, 0.04);
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.main-panel {
  display: grid;
  grid-template-columns: minmax(320px, var(--editor-width, 50%)) 12px minmax(320px, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.editor-panel,
.preview-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: rgba(39, 44, 51, 0.88);
}

.editor-panel {
  border-right: 1px solid var(--line);
}

.sidebar-resizer::after,
.panel-resizer::after {
  content: "";
  position: absolute;
  inset: 50% 2px auto;
  height: 42px;
  transform: translateY(-50%);
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(255, 184, 77, 0.95) 1px, transparent 1px) center / 8px 8px repeat-y;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head h1,
.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-btn,
.secondary-btn,
.danger-btn,
.editor-toolbar button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-soft);
  transition: 120ms ease;
}

.icon-btn:hover,
.secondary-btn:hover,
.danger-btn:hover,
.editor-toolbar button:hover,
.tree-row:hover {
  border-color: #546171;
  background: #3a4450;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.2rem;
}

.sidebar-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.head-actions {
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 80;
}

.workspace-anchor {
  position: relative;
  width: auto;
  z-index: 81;
}

#workspace-menu-btn {
  position: relative;
  z-index: 82;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  cursor: pointer;
}

.workspace-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 90;
  width: min(360px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  gap: 8px;
  overflow: auto;
}

.workspace-menu-head,
.workspace-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.workspace-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.workspace-list {
  display: flex;
  max-height: 280px;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.workspace-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(52, 59, 69, 0.46);
  cursor: pointer;
  transition: 120ms ease;
}

.workspace-entry.is-current {
  border-color: rgba(255, 152, 0, 0.32);
  background: rgba(255, 152, 0, 0.08);
}

.workspace-entry:hover {
  border-color: #546171;
  background: #3a4450;
}

.workspace-entry.is-current:hover {
  border-color: rgba(255, 152, 0, 0.4);
  background: rgba(255, 152, 0, 0.12);
}

.workspace-entry-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}

.workspace-entry-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-entry-copy span {
  color: var(--muted);
  font-size: 0.78rem;
}

.workspace-entry-actions {
  display: flex;
  gap: 6px;
}

.workspace-chip {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.workspace-chip:hover {
  border-color: #546171;
  background: #3a4450;
}

.workspace-chip:disabled {
  opacity: 0.55;
  cursor: default;
}

.menu-anchor {
  position: relative;
}

.full-width {
  width: 100%;
}

.secondary-btn,
.danger-btn {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.danger-btn {
  color: #ffd3d3;
}

.workspace-hint {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.floating-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  display: flex;
  min-width: 148px;
  flex-direction: column;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(36, 41, 49, 0.98);
  box-shadow: var(--shadow);
}

.floating-menu-wide {
  left: 0;
  right: auto;
  width: 100%;
}

.floating-menu-item {
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.floating-menu-item:hover {
  background: #3a4450;
}

.floating-menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: transparent;
}

.context-menu {
  position: fixed;
  top: 0;
  left: 0;
  min-width: 132px;
  width: max-content;
}

.danger-text {
  color: #ffb1b1;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding-right: 4px;
  padding-bottom: 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

.tree-node {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tree-children {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tree-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: max-content;
  min-width: 100%;
  padding: 10px 12px;
  padding-left: calc(12px + var(--depth, 0) * 16px);
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.tree-folder,
.tree-file,
.tree-toggle,
.tree-label {
  cursor: pointer;
}

.tree-file.is-active {
  background: var(--accent-soft);
  border-color: rgba(255, 152, 0, 0.36);
  box-shadow: inset 0 0 0 1px rgba(255, 152, 0, 0.08);
}

.tree-folder.is-active {
  background: rgba(255, 152, 0, 0.08);
  border-color: rgba(255, 152, 0, 0.24);
}

.tree-file.is-context {
  border-color: rgba(255, 184, 77, 0.35);
  background: rgba(255, 184, 77, 0.1);
}

.tree-folder.is-context {
  border-color: rgba(255, 184, 77, 0.35);
  background: rgba(255, 184, 77, 0.1);
}

.tree-toggle,
.tree-label,
.tree-file {
  border: 0;
  color: inherit;
  background: transparent;
}

.tree-toggle {
  padding: 0;
  width: 20px;
  color: var(--muted);
}

.tree-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  padding: 0;
}

.tree-icon {
  color: #ffb84d;
}

.tree-file-mark {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffb74d, var(--accent));
  margin-left: 6px;
}

.tree-label,
.tree-meta,
.title-input,
.editor {
  font-family: "SFMono-Regular", "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

.tree-meta {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.title-input {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  outline: none;
}

.meta-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(98, 114, 131, 0.18);
  color: var(--muted);
  font-size: 0.8rem;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.editor-toolbar button {
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.editor {
  flex: 1;
  width: 100%;
  padding: 20px;
  border: 0;
  resize: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    #20252c;
  background-size: 100% 32px, 28px 100%, auto;
  color: var(--text);
  line-height: 1.8;
  outline: none;
}

.preview {
  flex: 1;
  overflow: auto;
  padding: 20px 24px 48px;
  background:
    linear-gradient(180deg, rgba(255, 152, 0, 0.03) 0%, transparent 14%),
    #262b32;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 14, 17, 0.58);
}

.modal-card {
  width: min(460px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #252b32;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-copy {
  margin: 14px 0 18px;
  color: var(--muted);
}

.modal-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.modal-select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #1e2329;
  color: var(--text);
}

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

.markdown-body {
  line-height: 1.78;
  word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 1.4em 0 0.7em;
  color: #f3f6fb;
}

.markdown-body h1 {
  font-size: 2rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.35em;
}

.markdown-body h2 {
  font-size: 1.45rem;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre {
  margin: 0 0 1em;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.4em;
}

.markdown-body a {
  color: #ffb84d;
}

.markdown-body blockquote {
  margin-left: 0;
  padding: 0.2em 1em;
  border-left: 4px solid rgba(255, 152, 0, 0.45);
  background: rgba(255, 152, 0, 0.08);
  color: #f0d9b0;
}

.markdown-body code {
  padding: 0.2em 0.38em;
  border-radius: 6px;
  background: #1d2228;
  color: #ffd28c;
  font-family: "SFMono-Regular", "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

.markdown-body pre {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  background: #1b1f25;
  box-shadow: var(--shadow);
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.8em 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1em;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-resizer {
    display: none;
  }

  .workspace-menu {
    width: min(360px, calc(100vw - 24px));
  }
}

@media (max-width: 800px) {
  .main-panel {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panel-resizer {
    display: none;
  }
}
