:root {
  color: #1d2933;
  background: #f1f3f3;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  --muted: #53636d;
  --forest: #22594b;
  --line: #dce3e2;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .54; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #377b6b; outline-offset: 3px; }

.workbench { display: grid; grid-template-columns: minmax(225px, 268px) minmax(0, 1fr); min-height: 100dvh; }
.sidebar { display: flex; flex-direction: column; padding: 29px 17px 24px; border-right: 1px solid var(--line); background: #f5f7f6; }
.brand { display: flex; align-items: center; gap: 11px; margin: 0 8px 27px; }
.brand-icon { display: grid; place-items: center; width: 39px; height: 39px; border-radius: 11px; background: #d9e9e1; color: #214d40; font-size: 19px; font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; font-weight: 720; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .04em; margin-top: 3px; }
.workspace-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #e8eeeb; border-radius: 8px; padding: 4px; margin-bottom: 12px; }
.space { padding: 7px 4px; border: 1px solid transparent; border-radius: 5px; font-size: 12px; background: transparent; color: #40564f; font-weight: 650; }
.space[aria-current="true"] { background: #fff; border-color: #d3dfd9; color: var(--forest); }
.space:hover { color: #173b31; }
.nav-actions { display: flex; gap: 1px; }
.account { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: auto; padding-top: 24px; color: var(--muted); }
.account .secondary { font-size: 12px; flex-shrink: 0; }
.account span { min-width: 0; overflow-wrap: anywhere; }
.account-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.account-actions .secondary { padding-inline: 8px; }
.primary, .secondary, .icon-button { min-height: 36px; padding: 7px 13px; border-radius: 7px; font-weight: 610; }
.primary { color: #fff; background: var(--forest); border: 1px solid var(--forest); }
.primary:not(:disabled):hover { background: #164337; }
.secondary, .icon-button { color: #2e4942; background: transparent; border: 1px solid var(--line); }
.secondary:not(:disabled):hover, .icon-button:not(:disabled):hover { background: #edf3f0; }
.new { width: 100%; text-align: left; padding-left: 13px; }
.new span { margin-right: 4px; }
.navigator { margin-top: 24px; }
.drafts { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.section-heading { min-height: 28px; padding: 0 5px; display: flex; align-items: center; justify-content: space-between; }
.section-heading h2 { margin: 0; color: #445651; font-size: 12px; font-weight: 720; }
.section-heading span { color: var(--muted); font-size: 11px; }
.icon-button { min-height: 28px; min-width: 28px; padding: 0; font-size: 16px; border-color: transparent; }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 2px; margin: 7px 0; }
.breadcrumbs button { background: none; border: 0; color: var(--forest); padding: 3px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.breadcrumbs button[aria-current="location"] { font-weight: 750; }
.breadcrumbs button:hover { background: #e5eeea; }
.breadcrumbs span { align-self: center; color: var(--muted); }
.side-message { margin: 7px 5px; font-size: 12px; line-height: 1.55; color: var(--muted); overflow-wrap: anywhere; }
.entries { padding: 0; margin: 0; list-style: none; max-height: 46dvh; overflow: auto; }
.drafts .entries { max-height: 22dvh; }
.entry { min-height: 33px; width: 100%; display: flex; gap: 8px; align-items: center; color: #26383a; padding: 5px 8px; background: transparent; border: 1px solid transparent; border-radius: 6px; text-align: left; }
.entry:hover { background: #e8eeeb; }
.entry[aria-current="true"] { border-color: #ccdcd6; background: #deebe5; }
.entry-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.entry-icon { display: grid; place-items: center; flex: 0 0 17px; min-height: 15px; color: #4a6b62; font-size: 12px; font-weight: 750; }

.main { min-width: 0; min-height: 100dvh; display: flex; flex-direction: column; background: #fcfdfc; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 13px; padding: 20px clamp(16px, 4vw, 54px); border-bottom: 1px solid var(--line); min-height: 90px; }
.current-note { min-width: 0; }
.current-note p { font-size: 12px; color: var(--muted); margin: 0 0 5px; overflow-wrap: anywhere; }
.current-note h1 { font-size: clamp(17px, 2vw, 24px); line-height: 1.22; margin: 0; letter-spacing: -.018em; overflow-wrap: anywhere; }
.actions { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }
.actions .primary { min-width: 67px; }
.empty { flex: 1; margin-bottom: 9vh; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: 26px 20px; }
.empty-icon { display: grid; place-items: center; width: 56px; height: 56px; border: 1px solid #dce9e3; background: #eef5f1; color: #3d6e5f; border-radius: 16px; font-family: Consolas, monospace; font-size: 29px; }
.empty h2 { margin: 18px 0 8px; font-size: 20px; }
.empty p { margin: 0; color: var(--muted); line-height: 1.6; }
.editor-panel { display: flex; flex-direction: column; flex: 1; min-height: 330px; padding: 22px clamp(16px, 4vw, 54px) 18px; }
.editor-label, .name-row label, .compare label { font-size: 12px; font-weight: 700; color: #405750; }
.editor-label { margin: 0 0 8px; }
.markdown-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; padding: 5px; border: 1px solid var(--line); border-radius: 8px; background: #f7faf8; }
.markdown-actions, .view-modes { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.markdown-actions button, .view-modes button { border: 1px solid transparent; min-height: 29px; min-width: 28px; padding: 3px 6px; border-radius: 4px; background: transparent; color: #2e4942; font-size: 12px; }
.markdown-actions button:hover, .view-modes button:hover { background: #e6efea; }
.view-modes button[aria-pressed="true"] { background: #e0eee8; border-color: #ccdcd5; font-weight: 700; }
.editor-surface { display: flex; gap: 14px; flex: 1; min-width: 0; }
.source-pane, .preview-pane { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; }
.markdown-preview { flex: 1; min-height: 17rem; border: 1px solid #d5dfdc; border-radius: 8px; color: #24332e; background: #fff; padding: 14px 18px; overflow-wrap: anywhere; overflow: auto; line-height: 1.65; }
.markdown-preview > :first-child { margin-top: 0; }
.markdown-preview a { color: #22594b; }
.markdown-preview blockquote { border-left: 3px solid #9fbdb0; margin: 10px 0; padding-left: 12px; color: var(--muted); }
.markdown-preview code { font-family: Consolas, monospace; padding: 2px 4px; border-radius: 3px; background: #eef4f1; }
.markdown-preview pre { padding: 9px 11px; white-space: pre-wrap; border-radius: 5px; background: #eef4f1; }
.markdown-preview pre code { padding: 0; }
.markdown-preview table { width: max-content; max-width: 100%; border-collapse: collapse; }
.markdown-preview td, .markdown-preview th { border: 1px solid var(--line); padding: 5px 9px; }
.markdown-preview th { background: #edf2ef; }
.markdown-preview input[type="checkbox"] { margin: 0 3px 0 0; accent-color: var(--forest); }
.markdown-image { display: inline-block; font-size: 12px; color: var(--muted); border-radius: 4px; border: 1px solid var(--line); padding: 1px 5px; }
.frontmatter { color: var(--muted); font-size: 12px; }
.name-row { display: grid; gap: 6px; margin-bottom: 16px; max-width: 540px; }
.name-row input { min-width: 0; padding: 9px 10px; color: inherit; border: 1px solid #cdd9d6; border-radius: 6px; background: #fff; }
#editor, #compare-text { width: 100%; padding: 14px 15px; color: #24332e; background: #fff; border: 1px solid #d5dfdc; border-radius: 8px; line-height: 1.7; tab-size: 4; font-family: "Cascadia Code", Consolas, "Microsoft YaHei", "PingFang SC", monospace; }
#editor { flex: 1; min-height: 17rem; resize: vertical; }
.compare { margin: 0 clamp(16px, 4vw, 54px) 18px; padding: 13px; background: #f5f8f6; border: 1px solid var(--line); border-radius: 8px; }
.compare-header { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; }
#compare-text { min-height: 110px; resize: vertical; }
.compare p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.statusbar { display: flex; gap: 12px; align-items: center; min-height: 48px; margin-top: auto; border-top: 1px solid var(--line); padding: 5px clamp(16px, 4vw, 54px); }
.status { color: var(--muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.status[data-type="error"], .status[data-type="conflict"] { color: #982f2b; }
.status[data-type="success"] { color: #215f44; }
.status[data-type="dirty"] { color: #805219; }
.status:not(:empty)::before { content: "●"; margin-right: 7px; font-size: 8px; vertical-align: 1px; }
.compare-button { flex: 0 0 auto; padding: 4px 8px; min-height: 27px; font-size: 12px; }
.shortcut { margin-left: auto; white-space: nowrap; font-size: 11px; color: var(--muted); }

.login-page { display: grid; min-height: 100dvh; place-items: center; padding: 20px; background: linear-gradient(135deg, #edf2ee, #e3ece7); }
.login-card, dialog { width: min(100%, 390px); border: 1px solid #d6e2dc; border-radius: 15px; background: #fcfdfc; box-shadow: 0 14px 40px #1e4e3920; padding: 30px; }
.login-card h1 { margin: 0 0 26px; font-size: 27px; }
.login-brand { margin: 0 0 22px; }
.login-card form, dialog form { display: grid; gap: 14px; }
.login-card button { min-height: 41px; }
.field { display: grid; gap: 6px; font-weight: 620; }
.field input, .field select { min-width: 0; width: 100%; padding: 9px 10px; border: 1px solid #cdd9d6; border-radius: 6px; background: #fff; color: inherit; font: inherit; }
.form-message { color: #982f2b; line-height: 1.5; margin: 0; font-size: 12px; }
.form-message[data-type="success"] { color: #22594b; }
.form-message:empty { display: none; }
dialog::backdrop { background: #152d25a6; }
dialog h2 { margin: 0; font-size: 21px; }
dialog form > p:not(.form-message) { margin: 0; color: var(--muted); line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.history-dialog { width: min(100% - 24px, 760px); padding: clamp(16px, 3vw, 24px); }
.history-heading p { color: var(--muted); margin: 5px 0 16px; overflow-wrap: anywhere; }
.history-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; margin-bottom: 12px; }
.history-timeline { min-width: 0; }
.history-timeline .entries { max-height: 42vh; }
.history-timeline .entry { border: 1px solid var(--line); min-height: 42px; margin-bottom: 5px; }
.history-timeline .entry-label { white-space: normal; overflow-wrap: anywhere; }
.history-timeline .secondary { margin-top: 4px; width: 100%; }
.history-preview { display: flex; min-width: 0; flex-direction: column; }
#history-text { width: 100%; min-height: min(37vh, 310px); padding: 10px; color: #24332e; background: #fff; border: 1px solid var(--line); border-radius: 7px; resize: vertical; font-family: Consolas, "Microsoft YaHei", monospace; line-height: 1.55; }
.history-dialog .form-message { margin: 0 0 10px; color: var(--muted); }
.history-dialog .form-message[data-type="error"] { color: #982f2b; }

@media (max-width: 700px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 8px 12px; }
  .brand { margin: 0; }
  .new { width: auto; }
  .workspace-tabs { grid-column: 1 / -1; grid-row: 2; margin-bottom: 0; }
  .navigator { margin-top: 2px; grid-column: 1 / -1; }
  .drafts { margin-top: 0; padding-top: 4px; grid-column: 1 / -1; }
  .entries { max-height: 132px; }
  .drafts .entries { max-height: 72px; }
  .toolbar { min-height: 74px; padding-top: 13px; padding-bottom: 13px; }
  .main { min-height: 72dvh; }
  .shortcut { display: none; }
  .account { grid-column: 1 / -1; padding-top: 2px; }
  .editor-surface[data-mode="split"] { flex-direction: column; }
  .actions { gap: 4px; flex-wrap: wrap; justify-content: end; flex-basis: auto; }
  .actions button { min-width: 0; padding-inline: 6px; }
  .current-note { flex: 1 0 36%; }
  .history-body { grid-template-columns: minmax(0, 1fr); }
  .history-timeline .entries { max-height: 23vh; }
  #history-text { min-height: 22vh; }
}
