:root {
  --bg: #fbfaf8;
  --panel: #ffffff;
  --ink: #1c1b19;
  --muted: #6f6b64;
  --line: #e6e2db;
  --hover: #f3f0ea;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, #2f6f4f 9%, transparent);
  --danger: #a33a2c;
  --warn: #9a6a12;
  --shadow: 0 1px 2px rgb(28 27 25 / 6%), 0 8px 24px rgb(28 27 25 / 6%);
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #16161a;
  --panel: #1d1d22;
  --ink: #e9e6e0;
  --muted: #9a958c;
  --line: #2c2c33;
  --hover: #24242b;
  --accent: #6fbf94;
  --accent-ink: #10231a;
  --accent-soft: color-mix(in srgb, #6fbf94 14%, transparent);
  --danger: #e07a6a;
  --warn: #d9a648;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #16161a;
    --panel: #1d1d22;
    --ink: #e9e6e0;
    --muted: #9a958c;
    --line: #2c2c33;
    --hover: #24242b;
    --accent: #6fbf94;
    --accent-ink: #10231a;
    --accent-soft: color-mix(in srgb, #6fbf94 14%, transparent);
    --danger: #e07a6a;
    --warn: #d9a648;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/* .app, .login and the views set their own display, which would otherwise win
   over the user agent's [hidden] rule. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}

/* buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, filter 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--hover);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.07);
  background: var(--accent);
}

.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 28%, var(--line));
  background: transparent;
}

.btn.danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 9%, transparent);
}

.btn.subtle {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.subtle:hover:not(:disabled) {
  background: var(--hover);
  color: var(--ink);
}

.btn.block {
  width: 100%;
  height: 38px;
  justify-content: center;
}

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

.btn.primary:disabled {
  background: var(--hover);
  border-color: var(--line);
  color: var(--muted);
  opacity: 1;
}

/* login */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 30px 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-mark {
  width: 34px;
  height: 34px;
  color: var(--accent);
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.login-hint {
  margin: -8px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg);
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* layout */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 264px 1fr;
}

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

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.brand .icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
  opacity: 1;
}

.tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px 8px 14px;
}

.row {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 0.12s, color 0.12s;
}

.row:hover {
  background: var(--hover);
}

.row.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.row.active {
  color: var(--accent);
}

.caret {
  width: 11px;
  flex: none;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  cursor: pointer;
}

.label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

/* main */

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

.list-view {
  padding: 28px 36px 32px;
  overflow: auto;
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  max-width: 760px;
  margin: 0 auto 18px;
}

.breadcrumb {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.view-head h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.view-actions {
  display: flex;
  gap: 8px;
}

.children {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 760px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}

.item:hover {
  background: var(--hover);
}

.item[data-kind='folder'] .item-name {
  font-weight: 600;
}

.item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  flex: none;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 24px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  text-align: center;
}

.empty-title {
  margin: 0 0 4px;
  font-size: 14px;
}

.empty-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.create-row {
  padding: 0;
}

.create-input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--panel);
  outline: none;
  font-size: 14px;
}

/* editor */

.editor-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 24px 36px 18px;
  gap: 10px;
}

.editor-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}

.note-name {
  width: 100%;
  padding: 2px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.025em;
  outline: none;
  transition: border-color 0.15s;
}

.note-name:hover {
  border-bottom-color: var(--line);
}

.note-name:focus {
  border-bottom-color: var(--accent);
}

.note-content {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  resize: none;
  border: 0;
  background: transparent;
  outline: none;
  font: 15px/1.7 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  tab-size: 2;
}

.note-content::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 12px;
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
}

.status[data-state='idle']::before {
  content: none;
}

.status[data-state='saved'] {
  color: var(--accent);
}

.status[data-state='dirty'] {
  color: var(--warn);
}

.status[data-state='error'] {
  color: var(--danger);
}

.editor-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.move-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--muted);
}

.move-field select {
  max-width: 180px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 38vh;
  }

  .list-view,
  .editor-view {
    padding: 20px 16px;
  }

  .view-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .editor-actions {
    justify-content: flex-start;
  }

  .editor-foot {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none;
  }
}
