:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-2: #f2f3f5;
  --border: #d9dde3;
  --border-strong: #a7adb7;
  --text: #20242a;
  --muted: #66707c;
  --accent: #4b5563;
  --accent-strong: #242a32;
  --accent-soft: #eceff3;
  --danger: #b42318;
  --danger-soft: #fff1ef;
  --focus: #6b7280;
  --code-bg: #f0f2f4;
  --shadow: 0 12px 30px rgba(32, 36, 42, 0.08);
  --header-height: 76px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  height: 100dvh;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

button svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

button img {
  display: block;
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  padding: 0;
}

button:hover {
  border-color: var(--border-strong);
  background: #fbfcfc;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

body[data-sidebar="hidden"] .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body[data-sidebar="hidden"] .notes-panel {
  display: none;
}

.sidebar-reveal-button {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 20;
  display: none;
  box-shadow: 0 4px 14px rgba(32, 36, 42, 0.12);
}

body[data-sidebar="hidden"] .sidebar-reveal-button {
  display: inline-flex;
}

body[data-sidebar="hidden"] .topbar {
  padding-left: 58px;
}

.notes-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: #fafbfc;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--header-height);
  min-height: var(--header-height);
  padding: 10px 12px 9px 14px;
  border-bottom: 1px solid var(--border);
  background: #242a32;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.brand-mark img {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.brand-title {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.brand-row .sidebar-collapse-button {
  color: #fff;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.brand-row .sidebar-collapse-button:hover,
.brand-row .sidebar-collapse-button:focus-visible {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent-strong);
  color: #fff;
}

.primary-button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.search-box {
  position: relative;
  display: block;
  margin: 12px 12px 0;
  padding: 9px 8px 5px;
  border-radius: 10px 10px 0 0;
  background: #f1f3f6;
  color: var(--muted);
  font-size: 12px;
}

.search-box input {
  width: 100%;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 34px 0 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: none;
}

.search-box input:hover,
.search-box input:focus {
  border-color: transparent;
  background: #fff;
  box-shadow: none;
}

.search-icon {
  position: absolute;
  right: 22px;
  top: 50%;
  width: 16px;
  height: 16px;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  transform: translateY(-50%);
}

.sidebar-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px 0;
}

.sidebar-actions .icon-button {
  width: 100%;
  border-color: transparent;
  background: #f0f2f5;
}

.sidebar-actions .icon-button:hover,
.sidebar-actions .icon-button:focus-visible {
  border-color: var(--border);
  background: #fff;
}

.sidebar-actions .primary-button,
.sidebar-actions .primary-button:hover,
.sidebar-actions .primary-button:focus-visible {
  border-color: transparent;
  background: var(--accent-strong);
  color: #fff;
}

.note-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: auto;
  margin: 0 12px 12px;
  padding: 3px 8px 10px;
  border-radius: 0 0 10px 10px;
  background: #f1f3f6;
}

.note-tab {
  position: relative;
  display: grid;
  gap: 0;
  width: 100%;
  min-height: 62px;
  border: 0;
  border-radius: 7px;
  background: transparent;
}

.note-tab:hover,
.note-tab:focus-within {
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(75, 85, 99, 0.08);
}

.note-tab.active {
  background: #dfe4eb;
  box-shadow: inset 3px 0 0 #4b5563;
}

.note-tab.active:hover,
.note-tab.active:focus-within {
  background: #d8dee7;
}

.note-tab-main {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
}

.note-tab-main:hover {
  background: transparent;
}

.note-tab-actions {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 2;
}

.note-tab:hover .note-tab-actions,
.note-tab:focus-within .note-tab-actions {
  opacity: 1;
  pointer-events: auto;
}

.note-tab:hover .note-tab-meta span:last-child,
.note-tab:focus-within .note-tab-meta span:last-child {
  opacity: 0;
}

.note-action-button {
  width: 28px;
  min-height: 26px;
  border: 0;
  background: rgba(255, 255, 255, 0.28);
  padding: 0;
  font-size: 12px;
  box-shadow: none;
}

.note-action-button:hover,
.note-action-button:focus-visible {
  border: 0;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: none;
}

.note-action-button.danger-button {
  border: 0;
  color: var(--danger);
  background: rgba(180, 35, 24, 0.07);
}

.note-action-button.danger-button:hover,
.note-action-button.danger-button:focus-visible {
  border: 0;
  background: rgba(180, 35, 24, 0.12);
}

.note-tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.note-tab-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.note-tab-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr);
  align-items: center;
  gap: 14px;
  height: var(--header-height);
  min-height: var(--header-height);
  padding: 10px 14px 9px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.title-area {
  min-width: 0;
}

.note-title-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
}

.note-title-input:hover,
.note-title-input:focus {
  border-color: var(--border);
  background: #fff;
}

.status-line {
  min-height: 18px;
  padding-left: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-undo {
  margin: 0 0 0 2px;
  border: 1px solid transparent;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 6px;
  padding: 1px 8px;
  min-height: 22px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.status-undo:hover,
.status-undo:focus-visible {
  border-color: var(--danger);
  background: #ffe7e3;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  max-width: 940px;
}

.danger-button {
  border-color: #f0b8b3;
  color: var(--danger);
  background: var(--danger-soft);
}

.pane-viewbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.preview-viewbar {
  position: relative;
}

.pane-viewbar-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.pane-actions .icon-button {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.58);
}

.pane-actions .icon-button:hover,
.pane-actions .icon-button:focus-visible {
  border-color: transparent;
  background: #fff;
  box-shadow: 0 1px 6px rgba(32, 36, 42, 0.1);
}

.icon-button.active-toggle {
  border-color: transparent;
  background: var(--accent-soft);
}

.pane-actions .theme-picker .icon-button.active-toggle,
.pane-actions .theme-picker .icon-button:active {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: none;
}

.pane-actions .theme-picker .icon-button.active-toggle:hover,
.pane-actions .theme-picker .icon-button.active-toggle:focus-visible {
  background: #fff;
  box-shadow: 0 1px 6px rgba(32, 36, 42, 0.1);
}

.icon-button.scroll-lock-on {
  border-color: transparent;
  color: #b42318;
  background: #fff1ef;
}

.icon-button.scroll-lock-off {
  border-color: transparent;
  color: #15803d;
  background: #f0fdf4;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  white-space: nowrap;
}

.toggle-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.select-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  white-space: nowrap;
}

.select-label select {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 28px 0 10px;
  color: var(--text);
  background: #fff;
}

.theme-picker {
  position: relative;
  display: inline-flex;
}

.theme-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: -42px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(2, minmax(84px, 1fr));
  gap: 5px;
  width: 186px;
  padding: 8px;
  border: 1px solid rgba(75, 85, 99, 0.14);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(32, 36, 42, 0.16);
}

.theme-popover[hidden] {
  display: none;
}

.theme-option {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  color: #3f4854;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
}

.theme-option:hover,
.theme-option:focus-visible {
  border: 0;
  background: #f1f3f6;
}

.theme-option.active {
  color: #fff;
  background: var(--accent-strong);
}

.stats {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.workspace-body {
  display: grid;
  grid-template-columns: minmax(220px, var(--editor-width, 50%)) 7px minmax(220px, 1fr);
  min-height: 0;
  flex: 1;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.editor-pane {
  border-right: 0;
}

#editor {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding: 24px;
  background: #fff;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.58;
  tab-size: 2;
}

#editor::placeholder {
  color: #97a09d;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-frame {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  border: 0;
  background: #fff;
}

.splitter {
  position: relative;
  z-index: 2;
  cursor: col-resize;
  background: linear-gradient(to right, transparent 0, transparent 2px, var(--border) 2px, var(--border) 5px, transparent 5px);
}

.splitter:hover,
.splitter:focus-visible,
.splitter.dragging {
  background: var(--border-strong);
}

.markdown-body {
  height: 100%;
  overflow: auto;
  padding: 24px 30px 80px;
  line-height: 1.65;
  color: var(--text);
  overflow-wrap: anywhere;
}

body[data-view="edit"] .workspace-body,
body[data-view="preview"] .workspace-body {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="edit"] .preview-pane,
body[data-view="edit"] .splitter,
body[data-view="preview"] .splitter,
body[data-view="preview"] .editor-pane {
  display: none;
}

body[data-view="preview"] .preview-pane {
  display: flex;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  line-height: 1.24;
  margin: 1.5em 0 0.55em;
}

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

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

.markdown-body h3 {
  font-size: 1.15rem;
}

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

.markdown-body a {
  color: var(--accent-strong);
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  padding: 0.1em 0 0.1em 1em;
  color: #4b5563;
  background: #f7f8fa;
}

.markdown-body code {
  border-radius: 5px;
  padding: 0.12em 0.36em;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.92em;
}

.markdown-body pre {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 14px;
  background: #f7f8f9;
}

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

.markdown-body table {
  display: block;
  width: 100%;
  overflow: auto;
  border-collapse: collapse;
}

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

.markdown-body th {
  background: #eef0f3;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
}

body[data-theme="paper"] .preview-pane {
  background: #ece8dd;
}

body[data-theme="paper"] .markdown-body {
  max-width: 820px;
  height: calc(100% - 40px);
  margin: 20px auto;
  border: 1px solid #ded7c8;
  background: #fffdf7;
  box-shadow: var(--shadow);
  color: #27221b;
}

body[data-theme="paper"] .markdown-body blockquote {
  background: #faf4e7;
}

body[data-theme="compact"] .markdown-body {
  padding: 16px 20px 64px;
  font-size: 13px;
  line-height: 1.48;
}

body[data-theme="compact"] .markdown-body h1 {
  font-size: 1.55rem;
}

body[data-theme="compact"] .markdown-body h2 {
  font-size: 1.22rem;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  body[data-sidebar="hidden"] .app-shell {
    grid-template-rows: minmax(0, 1fr);
  }

  .notes-panel {
    max-height: 40dvh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .note-tabs {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 10px 10px;
  }

  .note-tab {
    min-width: 190px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    justify-content: flex-start;
    max-width: none;
  }
}

@media (max-width: 720px) {
  .pane-viewbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .theme-popover {
    right: 0;
  }

  .stats {
    width: 100%;
    margin-left: 0;
  }

  .workspace-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  body[data-view="edit"] .workspace-body,
  body[data-view="preview"] .workspace-body {
    grid-template-rows: minmax(0, 1fr);
  }

  .editor-pane {
    border-bottom: 1px solid var(--border);
  }

  .splitter {
    display: none;
  }

  #editor,
  .markdown-body {
    padding: 18px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .notes-panel,
  .topbar,
  .pane-viewbar,
  .editor-pane,
  .splitter {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .workspace-body,
  .preview-pane,
  .markdown-body {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .markdown-body {
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    color: #000 !important;
    background: #fff !important;
  }
}
