:root {
  color-scheme: light;
  --app-bg: #f4f5f7;
  --panel: #ffffff;
  --panel-alt: #fafafa;
  --line: #dcdfe4;
  --line-soft: #eceff3;
  --text: #1f2328;
  --muted: #68707a;
  --accent: #0f7f80;
  --accent-strong: #0b6f70;
  --selected: #e7f2f2;
  --top: #1f2933;
  --top-2: #26323e;
  --top-text: #e8edf2;
  --top-muted: #aeb8c3;
  --font-ui: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
  --font-size: 14px;
  --sidebar-width: 360px;
  --find-highlight: rgba(255, 213, 79, 0.45);
  --find-highlight-active: rgba(15, 127, 128, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--app-bg);
  color: var(--text);
  font: 13px/1.45 var(--font-ui);
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: transparent;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(260px, var(--sidebar-width)) 6px minmax(0, 1fr);
  grid-template-rows: 48px 1fr;
}

.app.find-open {
  grid-template-rows: 48px 38px 1fr;
}

.authGate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(31, 41, 51, 0.94), rgba(31, 41, 51, 0.9)),
    radial-gradient(circle at top right, rgba(15, 127, 128, 0.16), transparent 32%);
}

.authGate[hidden] {
  display: none;
}

#authConfirmRow[hidden] {
  display: none;
}

.authCard {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.28);
}

.authBrand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.authBrand h1 {
  margin: 0;
  font-size: 20px;
}

.authFolderLabel,
.authDescription,
.authHint,
.authStatusMessage {
  margin: 0;
  color: var(--muted);
}

.authForm {
  display: grid;
  gap: 12px;
}

.authForm label {
  display: grid;
  gap: 6px;
  color: #42505d;
}

.authForm input {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
}

.authStatusMessage {
  min-height: 1.45em;
}

.authStatusMessage.error {
  color: #b02e2e;
}

.authStatusMessage.success {
  color: #0b6f70;
}

.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--top);
  color: var(--top-text);
  border-bottom: 1px solid #141c24;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  font-weight: 600;
}

.brandMark {
  width: 25px;
  height: 25px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}

.brandName {
  letter-spacing: 0.01em;
}

.folderSelect {
  height: 31px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background: var(--top-2);
  color: var(--top-text);
  padding: 0 7px;
  outline: 0;
  min-width: 0;
}

.folderSummary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.folderCount {
  color: var(--top-muted);
  font-size: 12px;
  white-space: nowrap;
}

.folderSelect:disabled {
  opacity: 1;
  cursor: default;
}

.searchWrap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.searchWrap svg,
.findInputWrap svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
}

.searchWrap svg {
  color: var(--muted);
}

#search {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  outline: 0;
  padding: 0 12px 0 34px;
}

#search::placeholder {
  color: var(--muted);
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 127, 128, 0.12);
}

.clearSearchButton {
  display: none;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.toolBtn {
  height: 31px;
  padding: 0 10px;
  border-radius: 4px;
  color: var(--top-text);
  white-space: nowrap;
}

.toolBtn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
}

.toolBtn.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.toolBtn.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.toolBtn:disabled {
  opacity: 0.55;
  cursor: default;
}

.spacer {
  flex: 1;
}

.buildLabel {
  color: var(--top-muted);
  font-size: 12px;
  white-space: nowrap;
}

.findbar {
  grid-column: 1 / -1;
  grid-row: 2;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: #eef2f4;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  z-index: 3;
}

.app.find-open .findbar {
  display: flex;
}

.findbarLabel {
  font-weight: 600;
  color: #38424d;
  white-space: nowrap;
}

.findInputWrap {
  position: relative;
  flex: 1 1 440px;
  max-width: 560px;
  min-width: 130px;
}

.findInputWrap svg {
  color: var(--muted);
}

#findInput {
  width: 100%;
  height: 28px;
  border: 1px solid #c9d0d7;
  border-radius: 4px;
  background: #fff;
  outline: 0;
  padding: 0 8px 0 30px;
}

#findInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 127, 128, 0.12);
}

.findCount {
  min-width: 72px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.findNav {
  height: 28px;
  min-width: 32px;
  border: 1px solid #c9d0d7;
  border-radius: 4px;
  background: #fff;
  color: #33404d;
}

.findNav:hover:not(:disabled),
.ghost:hover,
.close:hover {
  background: #e9ecef;
}

.findNav:disabled {
  opacity: 0.45;
  cursor: default;
}

.findClose {
  height: 28px;
  border-radius: 4px;
  padding: 0 8px;
  color: #4d5660;
}

.findClose:hover {
  background: #dde4e8;
}

.highlightToggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid #c9d0d7;
  border-radius: 4px;
  background: #fff;
  color: #33404d;
  white-space: nowrap;
  font-size: 12px;
}

.highlightToggle input {
  margin: 0;
  accent-color: var(--accent);
}

.app.find-open .noteListPane,
.app.find-open .splitter,
.app.find-open .editorPane {
  grid-row: 3;
}

.noteListPane {
  grid-column: 1;
  grid-row: 2;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: 52px 1fr;
  min-width: 0;
  min-height: 0;
}

.searchRow {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.notes {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
}

.notes li {
  border-bottom: 1px solid var(--line-soft);
  padding: 10px 12px;
  min-height: 76px;
  cursor: pointer;
  background: #fff;
}

.notes li:hover {
  background: #f1f3f5;
}

.notes li.active {
  background: var(--selected);
  box-shadow: inset 3px 0 0 var(--accent);
}

.noteRowHeader {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.noteRowTitle {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

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

.noteRowMeta {
  margin-top: 5px;
  color: #5d6670;
  font-size: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.splitter {
  grid-column: 2;
  grid-row: 2;
  background: #d8dce1;
  cursor: col-resize;
  position: relative;
}

.splitter:hover {
  background: #b9c3cc;
}

.splitter::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  width: 2px;
  height: 50px;
  border-radius: 9px;
  background: #8b97a4;
  transform: translateY(-50%);
  opacity: 0.55;
}

.editorPane {
  grid-column: 3;
  grid-row: 2;
  background: var(--panel);
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
}

.noteTitleBar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

#noteTitle {
  border: 0;
  background: #fff;
  outline: 0;
  padding: 0 14px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

#noteTitle:disabled {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  opacity: 1;
}

.editorWrap {
  position: relative;
  min-height: 0;
  background: #fff;
}

.editorWrap.closed::before {
  content: attr(data-placeholder);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

#editor {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  outline: 0;
  background: transparent;
  color: #23272c;
  font: var(--font-size) / 1.7 var(--font-body);
  padding: 18px 22px 70px;
  tab-size: 2;
}

#editor:disabled {
  color: transparent;
  caret-color: transparent;
  -webkit-text-fill-color: transparent;
}

.highlightLayer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: transparent;
  font: var(--font-size) / 1.7 var(--font-body);
  padding: 18px 22px 70px;
  tab-size: 2;
  pointer-events: none;
}

.highlightLayer mark {
  border-radius: 2px;
  background: var(--find-highlight);
  color: transparent;
}

.highlightLayer mark.active {
  background: var(--find-highlight-active);
  box-shadow: 0 0 0 1px rgba(15, 127, 128, 0.35);
}

.editorWrap.highlighting .highlightLayer {
  color: transparent;
}

.editorWrap.highlighting #editor {
  color: #23272c;
  caret-color: var(--text);
  -webkit-text-fill-color: currentColor;
}

.editorWrap.closed .highlightLayer,
.editorWrap:not(.highlighting) .highlightLayer {
  display: none;
}

.bottomBar {
  position: absolute;
  right: 12px;
  bottom: 10px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
  padding: 0;
}

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

.preferencesForm {
  width: min(430px, calc(100vw - 44px));
  display: grid;
  gap: 12px;
  padding: 16px;
}

.preferencesForm h2 {
  margin: 0 0 4px;
  font-size: 17px;
}

.preferencesForm label {
  display: grid;
  gap: 6px;
  color: #4d5660;
}

.preferencesForm input {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 9px;
  background: #fff;
}

.checkboxRow {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkboxRow input {
  height: auto;
}

.statusRow input:disabled {
  opacity: 1;
  cursor: default;
}

.dialogActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  background: #f8f9fa;
  margin: 0;
}

.ghost {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  padding: 7px 12px;
}

.primaryButton {
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  padding: 7px 12px;
  font-weight: 600;
}

.primaryButton:hover {
  background: var(--accent-strong);
}

.historyDialogShell {
  min-width: min(920px, calc(100vw - 44px));
  max-width: 920px;
  display: grid;
  grid-template-rows: 46px 1fr 52px;
}

.dialogHeader {
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #f8f9fa;
}

.dialogHeader h2 {
  font-size: 16px;
  margin: 0;
}

.close {
  margin-left: auto;
  border-radius: 4px;
  padding: 6px 10px;
}

.historyContent {
  height: min(560px, calc(100vh - 170px));
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 0;
}

.historySidebar {
  border-right: 1px solid var(--line);
  overflow: auto;
  background: #fbfbfc;
}

#historyList {
  list-style: none;
  padding: 0;
  margin: 0;
}

#historyList li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}

#historyList li:hover {
  background: #f1f3f5;
}

#historyList li.active {
  background: var(--selected);
  box-shadow: inset 3px 0 0 var(--accent);
}

.historyRevisionDate {
  font-weight: 600;
}

.historyRevisionMessage {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.historyPreviewPane {
  display: grid;
  grid-template-rows: 44px 1fr;
  min-width: 0;
}

.historyRevisionLabel {
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  background: #fff;
}

.historyBody {
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  outline: 0;
  padding: 14px;
  background: transparent;
  color: var(--text);
  font: var(--font-size) / 1.65 var(--font-body);
  overflow: auto;
}

@media (max-width: 820px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    background: #fff;
  }

  .app {
    height: 100dvh;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
  }

  .app.find-open {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .topbar {
    grid-column: 1;
    grid-row: 1;
    flex-wrap: wrap;
    align-content: start;
    gap: 6px;
    padding: 7px 8px;
    z-index: 5;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  }

  .brand {
    min-width: auto;
  }

  .brandName {
    display: none;
  }

  .brandMark {
    width: 28px;
    height: 28px;
  }

  .folderSelect {
    max-width: 110px;
  }

  .folderSummary {
    flex: 1 1 auto;
  }

  .toolbar {
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolBtn {
    height: 29px;
    padding: 0 8px;
  }

  .searchWrap #search {
    height: 30px;
    font-size: 16px;
    padding-right: 60px;
  }

  .clearSearchButton {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--top-text);
    font-size: 13px;
    line-height: 1;
  }

  .clearSearchButton:hover {
    background: rgba(255, 255, 255, 0.18);
  }

  .clearSearchButton[hidden] {
    display: none;
  }

  .buildLabel {
    order: 10;
    flex: 1 0 100%;
    padding: 0 2px 2px;
  }

  .splitter {
    display: none;
  }

  .findbar {
    grid-column: 1;
    grid-row: 2;
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 6px;
  }

  .findbarLabel {
    display: none;
  }

  .findInputWrap {
    flex: 1 1 calc(100% - 170px);
    max-width: none;
  }

  #findInput,
  .folderSelect,
  .preferencesForm input,
  .historyBody {
    font-size: 16px;
  }

  .findCount {
    min-width: 58px;
  }

  .findNav {
    min-width: 30px;
  }

  .highlightToggle {
    height: 26px;
  }

  .findClose {
    padding: 0 6px;
  }

  .noteListPane {
    grid-column: 1;
    grid-row: 2;
    grid-template-rows: 46px auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    min-height: 0;
    max-height: 230px;
    z-index: 4;
  }

  .app.find-open .noteListPane {
    display: none;
  }

  .searchRow {
    padding: 8px;
  }

  .notes {
    overflow: auto;
    background: #fff;
    max-height: 162px;
    -webkit-overflow-scrolling: touch;
  }

  .notes li {
    min-height: 54px;
    padding: 7px 10px;
  }

  .noteRowHeader {
    display: block;
  }

  .noteRowTitle {
    display: block;
    font-size: 13px;
    line-height: 1.25;
  }

  .noteRowDate {
    display: none;
  }

  .noteRowMeta {
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.25;
    -webkit-line-clamp: 1;
    color: #66717c;
  }

  .editorPane {
    grid-column: 1;
    grid-row: 3;
    grid-template-rows: 40px minmax(0, 1fr);
    min-height: 0;
    border-top: 0;
  }

  .app.find-open .editorPane {
    grid-row: 3;
  }

  #noteTitle {
    font-size: 16px;
    padding: 0 10px;
  }

  .editorWrap {
    min-height: 0;
    overflow: hidden;
  }

  #editor,
  .highlightLayer {
    padding: 12px 12px 58px;
    font-size: 16px;
    line-height: 1.62;
  }

  #editor {
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .bottomBar {
    right: 8px;
    bottom: 8px;
    font-size: 11px;
    background: rgba(255, 255, 255, 0.94);
  }

  .historyContent {
    grid-template-columns: 1fr;
    height: min(78dvh, 620px);
  }

  .historySidebar {
    max-height: 190px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
